View Javadoc
1   package org.andromda.cartridges.ejb.metafacades;
2   
3   import java.text.MessageFormat;
4   import java.util.StringTokenizer;
5   import org.andromda.cartridges.ejb.EJBProfile;
6   import org.andromda.metafacades.uml.GeneralizableElementFacade;
7   import org.apache.commons.lang.StringUtils;
8   
9   /**
10   * MetafacadeLogic implementation for org.andromda.cartridges.ejb.metafacades.ValueObjectFacade.
11   *
12   * @see org.andromda.cartridges.ejb.metafacades.ValueObjectFacade
13   */
14  public class ValueObjectFacadeLogicImpl
15      extends ValueObjectFacadeLogic
16  {
17      private static final long serialVersionUID = 34L;
18      // ---------------- constructor -------------------------------
19      /**
20       * @param metaObject
21       * @param context
22       */
23      public ValueObjectFacadeLogicImpl(
24          Object metaObject,
25          String context)
26      {
27          super(metaObject, context);
28      }
29  
30      /**
31       * Using <code>/</code> in the configuredProperty <code>valueObjectPackage</code> can remove the previous package
32       * name.
33       *
34       * @see org.andromda.cartridges.ejb.metafacades.ValueObjectFacade#getPackageName()
35       */
36      public String getPackageName()
37      {
38          final String packageName =
39              MessageFormat.format(
40                  this.getConfiguredProperty("valueObjectPackage").toString(),
41                  StringUtils.trimToEmpty(super.getPackageName()));
42          StringBuilder buffer = new StringBuilder();
43          for (final StringTokenizer tokenizer = new StringTokenizer(packageName, "."); tokenizer.hasMoreTokens();)
44          {
45              String token = tokenizer.nextToken();
46              if (token.indexOf('/') < 0)
47              {
48                  buffer.append(token).append('.');
49              }
50          }
51          final String name = buffer.toString();
52          return name.endsWith(".") ? name.substring(0, name.length() - 1) : name;
53      }
54  
55      /**
56       * @see org.andromda.cartridges.ejb.metafacades.ValueObjectFacade#getName()
57       */
58      public String getName()
59      {
60          return MessageFormat.format(
61              this.getConfiguredProperty("valueObjectName").toString(),
62                  StringUtils.trimToEmpty(super.getName()));
63      }
64  
65      /**
66       * @see org.andromda.metafacades.uml.ModelElementFacade#getFullyQualifiedName()
67       */
68      public String getFullyQualifiedName()
69      {
70          final String name = this.getPackageName();
71          return name == null || "".equalsIgnoreCase(name) ? getName() : name + '.' + getName();
72      }
73  
74      /**
75       * If we're using inheritance to build up a value object with all model elements of an entity, we're returning no
76       * superclass.
77       * @return super.getGeneralization() if generalization.hasStereotype(EJBProfile.STEREOTYPE_ENTITY)
78       */
79      public GeneralizableElementFacade getGeneralization()
80      {
81          GeneralizableElementFacade generalization = super.getGeneralization();
82          return generalization == null || generalization.hasStereotype(EJBProfile.STEREOTYPE_ENTITY) ? null
83                                                                                                      : generalization;
84      }
85  }