1 package org.andromda.core.metafacade;
2
3 import java.io.Serializable;
4 import java.util.List;
5 import org.andromda.core.common.ClassUtils;
6 import org.andromda.core.common.ExceptionUtils;
7 import org.apache.commons.lang.StringUtils;
8
9
10
11
12
13
14 public class ModelValidationMessage
15 implements Serializable
16 {
17 private static final long serialVersionUID = 34L;
18
19
20
21
22
23
24
25
26
27 public ModelValidationMessage(
28 final MetafacadeBase metafacade,
29 final String message)
30 {
31 this(metafacade, null, message);
32 }
33
34
35
36
37
38
39
40
41
42
43
44 public ModelValidationMessage(
45 final MetafacadeBase metafacade,
46 final String name,
47 final String message)
48 {
49 ExceptionUtils.checkNull("metafacade", metafacade);
50 ExceptionUtils.checkEmpty("message", message);
51 this.metafacade = metafacade;
52 this.name = name;
53 this.message = message;
54 }
55
56
57
58
59 private String name;
60
61
62
63
64
65
66 public String getName()
67 {
68 return this.name;
69 }
70
71
72
73
74 private String message;
75
76
77
78
79
80
81 public String getMessage()
82 {
83 return message;
84 }
85
86
87
88
89 private MetafacadeBase metafacade;
90
91
92
93
94 private String metafacadeName = null;
95
96
97
98
99
100
101 public String getMetafacadeName()
102 {
103 if (this.metafacadeName == null)
104 {
105 final String separator = MetafacadeConstants.NAMESPACE_SCOPE_OPERATOR;
106 final StringBuilder name = new StringBuilder();
107 for (
108 MetafacadeBase metafacade = this.metafacade; metafacade != null;
109 metafacade = (MetafacadeBase)metafacade.getValidationOwner())
110 {
111 if (StringUtils.isNotBlank(metafacade.getValidationName()))
112 {
113 String validationName = metafacade.getValidationName();
114 if (metafacade.getValidationOwner() != null)
115 {
116
117 validationName = validationName.replaceAll(".*" + separator, "");
118 }
119 if (name.length()>0)
120 {
121 name.insert(0, separator);
122 }
123 name.insert(0, validationName);
124 }
125 }
126 this.metafacadeName = name.toString();
127 }
128 return metafacadeName;
129 }
130
131
132
133
134 private Class metafacadeClass = null;
135
136
137
138
139
140
141 public Class getMetafacadeClass()
142 {
143 if (metafacadeClass == null)
144 {
145 this.metafacadeClass = this.metafacade.getClass();
146 final List interfaces = ClassUtils.getAllInterfaces(this.metafacade.getClass());
147 if (interfaces != null && !interfaces.isEmpty())
148 {
149 this.metafacadeClass = (Class)interfaces.iterator().next();
150 }
151 }
152 return this.metafacadeClass;
153 }
154
155
156
157
158 public String toString()
159 {
160 final StringBuilder toString = new StringBuilder();
161 toString.append('[');
162 toString.append(this.getMetafacadeName());
163 toString.append(']');
164 toString.append(':');
165 toString.append(this.message);
166 return toString.toString();
167 }
168
169
170
171
172 public int hashCode()
173 {
174 return this.toString().hashCode();
175 }
176
177
178
179
180 @SuppressWarnings("null")
181 public boolean equals(Object object)
182 {
183 boolean equals = object != null && ModelValidationMessage.class == object.getClass();
184 if (equals)
185 {
186 final ModelValidationMessage message = (ModelValidationMessage)object;
187
188 if (message != null)
189 {
190 equals = message.toString().equals(this.toString());
191 }
192 }
193 return equals;
194 }
195 }