View Javadoc
1   package org.andromda.cartridges.hibernate.metafacades;
2   
3   import org.andromda.utils.JavaTypeConverter;
4   import org.apache.commons.lang.StringUtils;
5   
6   
7   /**
8    * MetafacadeLogic implementation for
9    * org.andromda.cartridges.hibernate.metafacades.HibernateEnumeration.
10   *
11   * @see org.andromda.cartridges.hibernate.metafacades.HibernateEnumeration
12   */
13  public class HibernateEnumerationLogicImpl
14      extends HibernateEnumerationLogic
15  {
16      private static final long serialVersionUID = 34L;
17      // ---------------- constructor -------------------------------
18      /**
19       * @param metaObject
20       * @param context
21       */
22      public HibernateEnumerationLogicImpl(
23          Object metaObject,
24          String context)
25      {
26          super(metaObject, context);
27      }
28  
29      /**
30       * The pattern to use when constructing the enumeration name.
31       */
32      private static final String ENUMERATION_NAME_PATTERN = "enumerationNamePattern";
33  
34      /**
35       * Returns the value of the enumeration name pattern.
36       *
37       * @return the enumeration name pattern.
38       */
39      private String getEnumerationNamePattern()
40      {
41          return String.valueOf(this.getConfiguredProperty(ENUMERATION_NAME_PATTERN));
42      }
43  
44      /**
45       * @see org.andromda.cartridges.hibernate.metafacades.HibernateEnumeration#getFullyQualifiedHibernateType()
46       */
47      @Override
48      protected String handleGetFullyQualifiedHibernateType()
49      {
50          return JavaTypeConverter.getJavaLangTypeName(super.getFullyQualifiedName());
51      }
52  
53      /**
54       * @see org.andromda.cartridges.hibernate.metafacades.HibernateEnumeration#getEnumerationName()
55       */
56      @Override
57      protected String handleGetEnumerationName()
58      {
59          return StringUtils.trimToEmpty(this.getEnumerationNamePattern()).replaceAll(
60              "\\{0\\}",
61              super.getName());
62      }
63  
64      /**
65       * @see org.andromda.cartridges.hibernate.metafacades.HibernateEnumeration#getFullyQualifiedHibernateEnumerationType()
66       */
67      @Override
68      protected String handleGetFullyQualifiedHibernateEnumerationType()
69      {
70          return HibernateMetafacadeUtils.getFullyQualifiedName(
71              this.getHibernateEnumerationPackageName(),
72              this.getEnumerationName(),
73              null);
74      }
75  
76      /**
77       * Check for optional defined enumTypesPackage (overrides modeled package name)
78       */
79      private String getHibernateEnumerationPackageName() {
80          String enumPackageName = (String) this.getConfiguredProperty(HibernateGlobals.ENUM_TYPES_PACKAGE);
81          if (enumPackageName != null) {
82              return enumPackageName;
83          } else {
84              return super.getPackageName();
85          }
86      }
87  
88      /**
89       * @see org.andromda.cartridges.hibernate.metafacades.HibernateEnumeration#getVersion()
90       */
91      @Override
92      protected int handleGetVersion()
93      {
94          return Integer.parseInt(((String)this.getConfiguredProperty(HibernateGlobals.HIBERNATE_VERSION)).substring(0, 1));
95      }
96  }