View Javadoc
1   package org.andromda.cartridges.hibernate.metafacades;
2   
3   import org.andromda.core.common.ExceptionRecorder;
4   import org.andromda.metafacades.uml.TypeMappings;
5   import org.andromda.utils.JavaTypeConverter;
6   import org.apache.commons.lang.StringUtils;
7   import org.apache.log4j.Logger;
8   
9   
10  /**
11   * MetafacadeLogic implementation for
12   * org.andromda.cartridges.hibernate.metafacades.HibernateType.
13   *
14   * @see org.andromda.cartridges.hibernate.metafacades.HibernateType
15   */
16  public class HibernateTypeLogicImpl
17      extends HibernateTypeLogic
18  {
19      private static final long serialVersionUID = 34L;
20      /**
21       * The logger instance.
22       */
23      private static final Logger logger = Logger.getLogger(HibernateTypeLogicImpl.class);
24  
25      // ---------------- constructor -------------------------------
26      /**
27       * @param metaObject
28       * @param context
29       */
30      public HibernateTypeLogicImpl(
31          Object metaObject,
32          String context)
33      {
34          super(metaObject, context);
35      }
36  
37      /**
38       * @see org.andromda.cartridges.hibernate.metafacades.HibernateType#getFullyQualifiedHibernateType()
39       */
40      @Override
41      protected String handleGetFullyQualifiedHibernateType()
42      {
43          String fullyQualifiedName = super.getFullyQualifiedName();
44          final TypeMappings mappings = this.getHibernateTypeMappings();
45          if (mappings != null)
46          {
47              final String fullyQualifiedModelName = super.getFullyQualifiedName(true);
48              if (mappings.getMappings().containsFrom(fullyQualifiedModelName))
49              {
50                  fullyQualifiedName = mappings.getTo(fullyQualifiedModelName);
51              }
52          }
53          fullyQualifiedName = JavaTypeConverter.getJavaLangTypeName(fullyQualifiedName);
54          return fullyQualifiedName;
55      }
56  
57      /**
58       * Gets the <code>hibernateTypeMappings</code> for this hibernate type.
59       *
60       * @return the hibernate type TypeMappings.
61       */
62      protected TypeMappings getHibernateTypeMappings()
63      {
64          TypeMappings mappings = null;
65          final String propertyName = "hibernateTypeMappingsUri";
66          if (this.isConfiguredProperty(propertyName))
67          {
68              final Object property = this.getConfiguredProperty(propertyName);
69              String uri = null;
70              if (property instanceof String)
71              {
72                  uri = (String)property;
73                  if (StringUtils.isNotBlank(uri))
74                  {
75                      try
76                      {
77                          mappings = TypeMappings.getInstance((String)property);
78                          this.setProperty(propertyName, mappings);
79                      }
80                      catch (final Throwable throwable)
81                      {
82                          final String message = "Error getting '" + propertyName + "' --> '" + uri + '\'';
83                          logger.error(message);
84  
85                          // don't throw the exception
86                          ExceptionRecorder.instance().record(message, throwable);
87                      }
88                  }
89              }
90              else
91              {
92                  mappings = (TypeMappings)property;
93              }
94          }
95          return mappings;
96      }
97  }