View Javadoc
1   package org.andromda.cartridges.ejb.metafacades;
2   
3   import java.util.Collection;
4   import org.andromda.cartridges.ejb.EJBProfile;
5   import org.andromda.metafacades.uml.AttributeFacade;
6   
7   /**
8    * Metaclass facade implementation.
9    */
10  public class EJBPrimaryKeyFacadeLogicImpl
11          extends EJBPrimaryKeyFacadeLogic
12  {
13      private static final long serialVersionUID = 34L;
14      // ---------------- constructor -------------------------------
15  
16      /**
17       * @param metaObject
18       * @param context
19       */
20      public EJBPrimaryKeyFacadeLogicImpl(Object metaObject, String context)
21      {
22          super(metaObject, context);
23      }
24  
25      /**
26       * @see org.andromda.cartridges.ejb.metafacades.EJBPrimaryKeyFacadeLogic#handleIsComplex()
27       */
28      protected boolean handleIsComplex()
29      {
30          return getSimplePkField() == null;
31      }
32  
33      /**
34       * If this <code>object</code> does not have a complex primary key, get the (unqiue) attribute that is used as the
35       * primary key.
36       *
37       * @return the attribute used as primary key, or <code>null</code> if there is none or the class has a complex
38       *         primary key.
39       */
40      private AttributeFacade getSimplePkField()
41      {
42          AttributeFacade primaryKey = null;
43          Collection primaryKeys = ((EJBEntityFacade)this.getOwner()).getIdentifiers();
44          if (primaryKeys.size() == 1)
45          {
46              AttributeFacade pkField = (AttributeFacade)primaryKeys.iterator().next();
47              if (pkField.hasStereotype(EJBProfile.STEREOTYPE_IDENTIFIER))
48              {
49                  primaryKey = pkField;
50              }
51          }
52          return primaryKey;
53      }
54  
55      // ------------- relations ------------------
56  
57  }