View Javadoc
1   package org.andromda.metafacades.emf.uml22;
2   
3   import java.util.List;
4   import org.apache.commons.lang.StringUtils;
5   import org.apache.log4j.Logger;
6   import org.eclipse.uml2.uml.DirectedRelationship;
7   import org.eclipse.uml2.uml.Element;
8   
9   /**
10   * MetafacadeLogic implementation for
11   * org.andromda.metafacades.uml.DependencyFacade.
12   *
13   * @see org.andromda.metafacades.uml.DependencyFacade
14   */
15  public class DependencyFacadeLogicImpl
16      extends DependencyFacadeLogic
17  {
18      private static final long serialVersionUID = 34L;
19      /**
20       * @param metaObject
21       * @param context
22       */
23      public DependencyFacadeLogicImpl(
24          final DirectedRelationship metaObject,
25          final String context)
26      {
27          super(metaObject, context);
28      }
29  
30      /**
31       * The logger instance.
32       */
33      private static final Logger LOGGER = Logger.getLogger(DependencyFacadeLogicImpl.class);
34  
35      /**
36       * Gets the name in the following manner.
37       * <ol>
38       * <li>If the dependency has a name return it.</li>
39       * <li>If the dependency does <strong>NOT </strong> have a name, get the
40       * target element's and return its name uncapitalized.</li>
41       * </ol>
42       *
43       * @see org.andromda.metafacades.uml.ModelElementFacade#getName()
44       */
45      @Override
46      public String handleGetName()
47      {
48          String name = super.handleGetName();
49          if (StringUtils.isBlank(name) && this.getTargetElement() != null)
50          {
51              name = StringUtils.uncapitalize(this.getTargetElement().getName());
52          }
53          return name;
54      }
55  
56      /**
57       * @see org.andromda.metafacades.uml.DependencyFacade#getGetterName()
58       */
59      @Override
60      protected String handleGetGetterName()
61      {
62          return "get" + StringUtils.capitalize(this.handleGetName());
63      }
64  
65      /**
66       * @see org.andromda.metafacades.uml.DependencyFacade#getSetterName()
67       */
68      @Override
69      protected String handleGetSetterName()
70      {
71          return "set" + StringUtils.capitalize(this.handleGetName());
72      }
73  
74      /**
75       * @see org.andromda.metafacades.uml.DependencyFacade#getTargetElement()
76       */
77      @Override
78      protected Object handleGetTargetElement()
79      {
80          Object transform = null;
81          final List<Element> elist = this.metaObject.getTargets();
82          if (elist == null || elist.isEmpty())
83          {
84              DependencyFacadeLogicImpl.LOGGER.error("DependencyFacade has no targets: " + this.metaObject.getSources().toString());
85          }
86          else
87          {
88              transform = UmlUtilities.ELEMENT_TRANSFORMER.transform(this.metaObject.getTargets().toArray()[0]);
89          }
90          return transform;
91      }
92  
93      /**
94       * @see org.andromda.metafacades.uml.DependencyFacade#getSourceElement()
95       */
96      @Override
97      protected Object handleGetSourceElement()
98      {
99          return UmlUtilities.ELEMENT_TRANSFORMER.transform(this.metaObject.getSources().toArray()[0]);
100     }
101 }