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