View Javadoc
1   package org.andromda.metafacades.emf.uml22;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.List;
6   import org.andromda.metafacades.uml.ModelElementFacade;
7   import org.andromda.metafacades.uml.UMLMetafacadeProperties;
8   import org.apache.commons.collections.CollectionUtils;
9   import org.apache.commons.lang.ObjectUtils;
10  import org.apache.log4j.Logger;
11  import org.eclipse.uml2.uml.Class;
12  import org.eclipse.uml2.uml.Element;
13  import org.eclipse.uml2.uml.Package;
14  import org.eclipse.uml2.uml.internal.impl.BehaviorImpl;
15  import org.eclipse.uml2.uml.internal.impl.ClassImpl;
16  import org.eclipse.uml2.uml.internal.impl.ComponentImpl;
17  import org.eclipse.uml2.uml.internal.impl.NodeImpl;
18  import org.eclipse.uml2.uml.internal.impl.StereotypeImpl;
19  
20  /**
21   * MetafacadeLogic implementation for
22   * org.andromda.metafacades.uml.PackageFacade.
23   *
24   * @see org.andromda.metafacades.uml.PackageFacade
25   * @author Bob Fields
26   */
27  public class PackageFacadeLogicImpl
28      extends PackageFacadeLogic
29  {
30      private static final long serialVersionUID = 34L;
31      /**
32       * @param metaObject
33       * @param context
34       */
35      public PackageFacadeLogicImpl(
36          final Package metaObject,
37          final String context)
38      {
39          super(metaObject, context);
40      }
41  
42      /**
43       * The logger instance.
44       */
45      private static final Logger LOGGER = Logger.getLogger(PackageFacadeLogicImpl.class);
46  
47      /**
48       * @see org.andromda.metafacades.uml.PackageFacade#findModelElement(String)
49       */
50      @Override
51      protected ModelElementFacade handleFindModelElement(
52          final String fullyQualifiedName)
53      {
54          Object modelElement = null;
55          if (PackageFacadeLogicImpl.LOGGER.isDebugEnabled())
56          {
57              PackageFacadeLogicImpl.LOGGER.debug("Looking for >> " + fullyQualifiedName);
58          }
59          modelElement =
60              UmlUtilities.findByFullyQualifiedName(
61                  this.metaObject.eResource().getResourceSet(),
62                  fullyQualifiedName,
63                  ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR)),
64                  true);
65          if (modelElement==null)
66          {
67              // Try again with fullyQualified PSM name, this may come from a taggedValue or some freeform entry.
68              modelElement =
69                  UmlUtilities.findByFullyQualifiedName(
70                      this.metaObject.eResource().getResourceSet(),
71                      fullyQualifiedName,
72                      ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR)),
73                      false);
74          }
75          if (PackageFacadeLogicImpl.LOGGER.isDebugEnabled())
76          {
77              PackageFacadeLogicImpl.LOGGER.debug("Found: '" + modelElement + '\'');
78          }
79          return (ModelElementFacade)this.shieldedElement(modelElement);
80      }
81  
82      /**
83       * Returns Andromda class types, not necessarily all UML2 Class/Classifier type objects.
84       * Returns Classes, not UseCases, Activities, Behaviors, Components, Nodes.
85       * @see org.andromda.metafacades.uml.PackageFacade#getClasses()
86       */
87      @Override
88      protected Collection<Class> handleGetClasses()
89      {
90          final List<Class> classes = new ArrayList<Class>();
91          for (Element element : this.metaObject.getOwnedElements())
92          {
93              // Behavior Activity is mapped to EventFacade, unlike UML2 it does not inherit from Class so it must be excluded.
94              // TODO Fix inheritance hierarchy of EventFacade
95              if ((element instanceof ClassImpl)
96                  && !(element instanceof BehaviorImpl || element instanceof ComponentImpl || element instanceof NodeImpl || element instanceof StereotypeImpl))
97              {
98                  classes.add((Class)element);
99              }
100         }
101         return classes;
102     }
103 
104     /**
105      * @see org.andromda.metafacades.uml.PackageFacade#getSubPackages()
106      */
107     @Override
108     protected Collection<Package> handleGetSubPackages()
109     {
110         return this.metaObject.getNestedPackages();
111     }
112 
113     /**
114      * @see org.andromda.metafacades.uml.PackageFacade#getModelElements()
115      */
116     @Override
117     protected Collection<? extends ModelElementFacade> handleGetModelElements()
118     {
119         return CollectionUtils.collect(UmlUtilities.findModel(this.metaObject)
120                 .allOwnedElements(), UmlUtilities.ELEMENT_TRANSFORMER);
121     }
122 
123     /**
124      * @see org.andromda.metafacades.uml.PackageFacade#getOwnedElements()
125      */
126     @Override
127     protected Collection<? extends ModelElementFacade> handleGetOwnedElements()
128     {
129         return CollectionUtils.collect(
130             this.metaObject.getOwnedMembers(),
131             UmlUtilities.ELEMENT_TRANSFORMER);
132     }
133 
134     /**
135      * @see org.andromda.metafacades.emf.uml22.PackageFacadeLogic#handleGetTablePrefix()
136      */
137     @Override
138     protected String handleGetTablePrefix()
139     {
140         // TODO Auto-generated method stub
141         return "";
142     }
143 }