View Javadoc
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   * MetafacadeLogic implementation for org.andromda.cartridges.webservice.metafacades.WSDLEnumerationType.
11   *
12   * @see org.andromda.cartridges.webservice.metafacades.WSDLEnumerationType
13   * @author Bob Fields
14   */
15  public class WSDLEnumerationTypeLogicImpl
16          extends WSDLEnumerationTypeLogic
17  {
18      private static final long serialVersionUID = 34L;
19      // ---------------- constructor -------------------------------
20  
21      /**
22       * @param metaObject
23       * @param context
24       */
25      public WSDLEnumerationTypeLogicImpl(Object metaObject, String context)
26      {
27          super(metaObject, context);
28      }
29  
30      /**
31       * The logger instance.
32       */
33      private static final Logger logger = Logger.getLogger(WSDLEnumerationTypeLogicImpl.class);
34  
35      /**
36       * @return getSchemaType(true, true)
37       * @see org.andromda.cartridges.webservice.metafacades.WSDLEnumerationType#getSchemaType()
38       */
39      protected String handleGetSchemaType()
40      {
41          return this.getSchemaType(true, true);
42      }
43  
44      /**
45       * @return qualfiedNameLocalPartPattern
46       * @see org.andromda.cartridges.webservice.metafacades.WSDLEnumerationType#getQName()
47       */
48      protected String handleGetQName()
49      {
50          return this.getQualfiedNameLocalPartPattern().replaceAll("\\{0\\}", StringUtils.trimToEmpty(this.getName()));
51      }
52  
53      /**
54       * @return configuredProperty(WebServiceLogicImpl.NAMESPACE_PREFIX)
55       * @see org.andromda.cartridges.webservice.metafacades.WSDLEnumerationType#getNamespacePrefix()
56       */
57      protected String handleGetNamespacePrefix()
58      {
59          return (String)this.getConfiguredProperty(WebServiceLogicImpl.NAMESPACE_PREFIX);
60      }
61  
62      /**
63       * Gets the <code>qualifiedNameLocalPartPattern</code> for this WSDL enumeration.
64       * @return getConfiguredProperty(WebServiceLogicImpl.QNAME_LOCAL_PART_PATTERN)
65       */
66      protected String getQualfiedNameLocalPartPattern()
67      {
68          return (String)this.getConfiguredProperty(WebServiceLogicImpl.QNAME_LOCAL_PART_PATTERN);
69      }
70  
71      /**
72       * @return WebServiceUtils.reversePackage(packageName)
73       * @see org.andromda.cartridges.webservice.metafacades.WSDLEnumerationType#getNamespace()
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       * Gets the <code>namespacePattern</code> for this type.
87       * @return getConfiguredProperty(WebServiceLogicImpl.NAMESPACE_PATTERN)
88       */
89      protected String getNamespacePattern()
90      {
91          return (String)this.getConfiguredProperty(WebServiceLogicImpl.NAMESPACE_PATTERN);
92      }
93  
94      /**
95       * Gets whether or not <code>reverseNamespace</code> is true/false for this type.
96       *
97       * @return boolean true/false
98       */
99      private boolean isReverseNamespace()
100     {
101         return Boolean.valueOf(String.valueOf(this.getConfiguredProperty(WebServiceLogicImpl.REVERSE_NAMESPACE)))
102                 .booleanValue();
103     }
104 
105     /**
106      * @param withPrefix
107      * @param preserveArray
108      * @return WebServiceUtils.getSchemaType
109      * @see org.andromda.cartridges.webservice.metafacades.WSDLEnumerationType#getSchemaType(boolean, boolean)
110      * @see org.andromda.cartridges.webservice.WebServiceUtils#getSchemaType(org.andromda.metafacades.uml.ClassifierFacade, TypeMappings, String, String, String, boolean, boolean)
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      * @return getConfiguredProperty(WebServiceGlobals.ARRAY_NAME_PREFIX)
120      * @see org.andromda.cartridges.webservice.metafacades.WSDLEnumerationType#getWsdlArrayNamePrefix()
121      */
122     protected String handleGetWsdlArrayNamePrefix()
123     {
124         return String.valueOf(this.getConfiguredProperty(WebServiceGlobals.ARRAY_NAME_PREFIX));
125     }
126 
127     /**
128      * @return this.getWsdlArrayNamePrefix() + this.getName()
129      * @see org.andromda.cartridges.webservice.metafacades.WSDLEnumerationType#getWsdlArrayName()
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      * Gets the schemaType mappings that have been set for this schema type.
140      *
141      * @return the TypeMappings instance.
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                 // don't throw the exception
162             }
163         }
164         else
165         {
166             mappings = (TypeMappings)property;
167         }
168         return mappings;
169     }
170 
171     /**
172      * Used to map between XML (list of restricted strings) and Java enum (has both a name and a value).
173      *
174      * @return useEnumValueInXSD true if EnumerationLiteral.value is used instead of EnumerationLiteral.Name.
175      */
176     public Boolean useEnumValueInXSD()
177     {
178         final String propertyName = WebServiceGlobals.USE_ENUM_VALUE_IN_XSD;
179         // getConfiguredProperty is protected so we must wrap it for use in WebServiceUtils
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 }