1 package org.andromda.cartridges.webservice.metafacades;
2
3 import org.andromda.cartridges.webservice.WebServiceGlobals;
4 import org.andromda.cartridges.webservice.WebServiceUtils;
5 import org.andromda.metafacades.uml.TypeMappings;
6 import org.apache.commons.lang.StringUtils;
7 import org.apache.log4j.Logger;
8
9
10
11
12
13
14
15 public class WSDLEnumerationTypeLogicImpl
16 extends WSDLEnumerationTypeLogic
17 {
18 private static final long serialVersionUID = 34L;
19
20
21
22
23
24
25 public WSDLEnumerationTypeLogicImpl(Object metaObject, String context)
26 {
27 super(metaObject, context);
28 }
29
30
31
32
33 private static final Logger logger = Logger.getLogger(WSDLEnumerationTypeLogicImpl.class);
34
35
36
37
38
39 protected String handleGetSchemaType()
40 {
41 return this.getSchemaType(true, true);
42 }
43
44
45
46
47
48 protected String handleGetQName()
49 {
50 return this.getQualfiedNameLocalPartPattern().replaceAll("\\{0\\}", StringUtils.trimToEmpty(this.getName()));
51 }
52
53
54
55
56
57 protected String handleGetNamespacePrefix()
58 {
59 return (String)this.getConfiguredProperty(WebServiceLogicImpl.NAMESPACE_PREFIX);
60 }
61
62
63
64
65
66 protected String getQualfiedNameLocalPartPattern()
67 {
68 return (String)this.getConfiguredProperty(WebServiceLogicImpl.QNAME_LOCAL_PART_PATTERN);
69 }
70
71
72
73
74
75 protected String handleGetNamespace()
76 {
77 String packageName = this.getPackageName();
78 if (this.isReverseNamespace())
79 {
80 packageName = WebServiceUtils.reversePackage(packageName);
81 }
82 return this.getNamespacePattern().replaceAll("\\{0\\}", StringUtils.trimToEmpty(packageName));
83 }
84
85
86
87
88
89 protected String getNamespacePattern()
90 {
91 return (String)this.getConfiguredProperty(WebServiceLogicImpl.NAMESPACE_PATTERN);
92 }
93
94
95
96
97
98
99 private boolean isReverseNamespace()
100 {
101 return Boolean.valueOf(String.valueOf(this.getConfiguredProperty(WebServiceLogicImpl.REVERSE_NAMESPACE)))
102 .booleanValue();
103 }
104
105
106
107
108
109
110
111
112 public String handleGetSchemaType(boolean withPrefix, boolean preserveArray)
113 {
114 return WebServiceUtils.getSchemaType(this, this.getSchemaTypeMappings(), this.getNamespacePrefix(),
115 this.getName(), this.getWsdlArrayNamePrefix(), withPrefix, preserveArray);
116 }
117
118
119
120
121
122 protected String handleGetWsdlArrayNamePrefix()
123 {
124 return String.valueOf(this.getConfiguredProperty(WebServiceGlobals.ARRAY_NAME_PREFIX));
125 }
126
127
128
129
130
131 protected String handleGetWsdlArrayName()
132 {
133 StringBuilder name = new StringBuilder(StringUtils.trimToEmpty(this.getName()).replaceAll("\\[\\]", ""));
134 name.insert(0, this.getWsdlArrayNamePrefix());
135 return name.toString();
136 }
137
138
139
140
141
142
143 private TypeMappings getSchemaTypeMappings()
144 {
145 final String propertyName = WebServiceGlobals.SCHEMA_TYPE_MAPPINGS_URI;
146 Object property = this.getConfiguredProperty(propertyName);
147 TypeMappings mappings = null;
148 String uri = null;
149 if (property != null && String.class.isAssignableFrom(property.getClass()))
150 {
151 uri = (String)property;
152 try
153 {
154 mappings = TypeMappings.getInstance((String)property);
155 this.setProperty(propertyName, mappings);
156 }
157 catch (Throwable th)
158 {
159 String errMsg = "Error getting '" + propertyName + "' --> '" + uri + '\'';
160 logger.error(errMsg, th);
161
162 }
163 }
164 else
165 {
166 mappings = (TypeMappings)property;
167 }
168 return mappings;
169 }
170
171
172
173
174
175
176 public Boolean useEnumValueInXSD()
177 {
178 final String propertyName = WebServiceGlobals.USE_ENUM_VALUE_IN_XSD;
179
180 Object property = this.getConfiguredProperty(propertyName);
181 if (property != null && String.class.isAssignableFrom(property.getClass()))
182 {
183 return Boolean.valueOf(String.valueOf(property)).booleanValue();
184 }
185 return Boolean.TRUE;
186 }
187 }