View Javadoc
1   package org.andromda.metafacades.uml14;
2   
3   import java.util.Collection;
4   import org.apache.commons.lang.StringUtils;
5   import org.omg.uml.foundation.core.Dependency;
6   
7   /**
8    * Metaclass facade implementation.
9    * @author Bob Fields
10   */
11  public class DependencyFacadeLogicImpl
12          extends DependencyFacadeLogic
13  {
14      private static final long serialVersionUID = 34L;
15      /**
16       * @param metaObject
17       * @param context
18       */
19      public DependencyFacadeLogicImpl(Dependency metaObject, String context)
20      {
21          super(metaObject, context);
22      }
23  
24      /**
25       * Gets the name in the following manner. <ol> <li>If the dependency has a name return it.</li> <li>If the
26       * dependency does <strong>NOT </strong> have a name, get the target element's and return its name
27       * uncapitalized.</li> </ol>
28       *
29       * @see org.andromda.metafacades.uml.ModelElementFacade#getName()
30       */
31      @Override
32      public String handleGetName()
33      {
34          String name = super.handleGetName();
35          if (StringUtils.isBlank(name) && this.getTargetElement() != null)
36          {
37              name = StringUtils.uncapitalize(this.getTargetElement().getName());
38          }
39          return name;
40      }
41  
42      /**
43       * @see org.andromda.metafacades.uml.DependencyFacade#getGetterName()
44       */
45      @Override
46      public String handleGetGetterName()
47      {
48          return "get" + StringUtils.capitalize(this.getName());
49      }
50  
51      /**
52       * @see org.andromda.metafacades.uml.DependencyFacade#getSetterName()
53       */
54      @Override
55      public String handleGetSetterName()
56      {
57          return "set" + StringUtils.capitalize(this.getName());
58      }
59  
60      /**
61       * @see org.andromda.metafacades.uml.DependencyFacade#getTargetElement()
62       */
63      @Override
64      public Object handleGetTargetElement()
65      {
66          Object targetElement = null;
67          Collection suppliers = UML14MetafacadeUtils.getCorePackage().getASupplierSupplierDependency().getSupplier(
68                  this.metaObject);
69          if (!suppliers.isEmpty())
70          {
71              targetElement = suppliers.iterator().next();
72          }
73          return targetElement;
74      }
75  
76      /**
77       * @see org.andromda.metafacades.uml.DependencyFacade#getSourceElement()
78       */
79      @Override
80      protected Object handleGetSourceElement()
81      {
82          Object sourceElement = null;
83          Collection clients = UML14MetafacadeUtils.getCorePackage().getAClientClientDependency().getClient(
84                  this.metaObject);
85          if (!clients.isEmpty())
86          {
87              sourceElement = clients.iterator().next();
88          }
89          return sourceElement;
90      }
91  
92  }