1 package org.andromda.cartridges.webservice.metafacades;
2
3 import java.util.Collection;
4 import org.andromda.cartridges.webservice.WebServiceGlobals;
5 import org.andromda.core.metafacade.MetafacadeBase;
6 import org.andromda.core.metafacade.ModelValidationMessage;
7 import org.andromda.translation.ocl.validation.OCLIntrospector;
8 import org.andromda.utils.StringUtilsHelper;
9 import org.apache.commons.lang.StringUtils;
10
11
12
13
14
15
16
17 public class WSDLTypeAttributeLogicImpl
18 extends WSDLTypeAttributeLogic
19 {
20 private static final long serialVersionUID = 34L;
21
22
23
24
25
26
27 public WSDLTypeAttributeLogicImpl(Object metaObject, String context)
28 {
29 super(metaObject, context);
30 }
31
32
33
34
35
36 protected boolean handleIsNillable()
37 {
38 return !this.isRequired();
39 }
40
41
42
43
44 private static final String PROPERTY_XML_ADAPTER = "schemaValidation";
45
46
47
48
49 @Override
50 protected String handleGetXmlAdapter()
51 {
52 String adapter = (String)this.findTaggedValue(WebServiceGlobals.XML_ADAPTER);
53 if (StringUtils.isEmpty(adapter))
54 {
55 adapter = String.valueOf(this.getConfiguredProperty(PROPERTY_XML_ADAPTER));
56 }
57 return adapter;
58 }
59
60
61
62
63 private static final String PROPERTY_XML_TYPE = "schemaValidation";
64
65
66
67
68 @Override
69 protected String handleGetXmlSchemaType()
70 {
71 String mode = (String)this.findTaggedValue(WebServiceGlobals.XML_TYPE);
72 if (StringUtils.isEmpty(mode))
73 {
74 mode = String.valueOf(this.getConfiguredProperty(PROPERTY_XML_TYPE));
75 }
76 if (StringUtils.isEmpty(mode))
77 {
78
79 }
80 return mode;
81 }
82
83
84
85
86 private static final String USE_ATTRIBUTES = "useAttributes";
87
88
89
90
91 @Override
92 protected boolean handleIsAttribute()
93 {
94 boolean isAttribute = this.hasStereotype(WebServiceGlobals.STEREOTYPE_XML_ATTRIBUTE);
95 boolean isElement = this.hasStereotype(WebServiceGlobals.STEREOTYPE_XML_ELEMENT);
96 if (isElement)
97 {
98 if (isAttribute)
99 {
100 logger.error("Attribute has both XmlAttribute and XmlElement stereotypes, it cannot be both! " + this.getFullyQualifiedName());
101
102 }
103
104 }
105 else if (!isAttribute)
106 {
107 String attributes = String.valueOf(this.getConfiguredProperty(USE_ATTRIBUTES));
108 if (StringUtils.isEmpty(attributes))
109 {
110 attributes = "true";
111 }
112 isAttribute = Boolean.parseBoolean(attributes);
113 }
114
115 return isAttribute;
116 }
117
118
119
120
121 @Override
122 protected boolean handleIsElement()
123 {
124 boolean isAttribute = this.hasStereotype(WebServiceGlobals.STEREOTYPE_XML_ELEMENT);
125 boolean isElement = this.hasStereotype(WebServiceGlobals.STEREOTYPE_XML_ELEMENT);
126 if (isElement)
127 {
128 if (isAttribute)
129 {
130 logger.error("Attribute has both XmlAttribute and XmlElement stereotypes, it cannot be both! " + this.getFullyQualifiedName());
131
132 }
133
134 }
135 else if (!isAttribute)
136 {
137 String attributes = String.valueOf(this.getConfiguredProperty(USE_ATTRIBUTES));
138 if (StringUtils.isEmpty(attributes))
139 {
140 attributes = "true";
141 }
142
143 isElement = !Boolean.parseBoolean(attributes);
144 }
145
146 return isElement;
147 }
148
149
150
151
152
153
154
155 @Override
156 public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
157 {
158 super.validateInvariants(validationMessages);
159 try
160 {
161 final Object contextElement = this.THIS();
162 final String name = (String)OCLIntrospector.invoke(contextElement,"name");
163 final boolean isStatic = this.isStatic() && this.isLeaf();
164 if (!isStatic && name != null && name.length()>0 && !StringUtilsHelper.startsWithLowercaseLetter(name))
165 {
166 validationMessages.add(
167 new ModelValidationMessage(
168 (MetafacadeBase)contextElement ,
169 "org::andromda::cartridges::webservice::metafacades::WSDLTypeAttribute::attribute must start with a lowercase letter",
170 "Attribute name must start with a lowercase letter."));
171 }
172 }
173 catch (Throwable th)
174 {
175 Throwable cause = th.getCause();
176 int depth = 0;
177 while (cause != null && depth < 7)
178 {
179 th = cause;
180 depth++;
181 }
182 logger.error("Error validating constraint 'org::andromda::cartridges::webservice::WSDLTypeAttribute::attribute must start with a lowercase letter' ON "
183 + this.THIS().toString() + ": " + th.getMessage(), th);
184 }
185 }
186 }