View Javadoc
1   package org.andromda.cartridges.jsf2.metafacades;
2   
3   import java.util.ArrayList;
4   import java.util.Collection;
5   import java.util.HashSet;
6   import java.util.Iterator;
7   import java.util.List;
8   import java.util.Set;
9   
10  import org.andromda.cartridges.jsf2.JSFGlobals;
11  import org.andromda.cartridges.jsf2.JSFUtils;
12  import org.andromda.metafacades.uml.ActionStateFacade;
13  import org.andromda.metafacades.uml.ClassifierFacade;
14  import org.andromda.metafacades.uml.DependencyFacade;
15  import org.andromda.metafacades.uml.FilteredCollection;
16  import org.andromda.metafacades.uml.FrontEndAction;
17  import org.andromda.metafacades.uml.FrontEndActionState;
18  import org.andromda.metafacades.uml.ModelElementFacade;
19  import org.andromda.metafacades.uml.OperationFacade;
20  import org.andromda.metafacades.uml.PackageFacade;
21  import org.andromda.metafacades.uml.Service;
22  import org.andromda.utils.StringUtilsHelper;
23  import org.apache.commons.lang.ObjectUtils;
24  import org.apache.commons.lang.StringUtils;
25  
26  /**
27   * MetafacadeLogic implementation for org.andromda.cartridges.jsf2.metafacades.JSFController.
28   *
29   * @see org.andromda.cartridges.jsf2.metafacades.JSFController
30   */
31  public class JSFControllerLogicImpl
32      extends JSFControllerLogic
33  {
34      private static final long serialVersionUID = 34L;
35      /**
36       * @param metaObject
37       * @param context
38       */
39      public JSFControllerLogicImpl(Object metaObject, String context)
40      {
41          super(metaObject, context);
42      }
43  
44      /**
45       * @return implementationName
46       * @see org.andromda.cartridges.jsf2.metafacades.JSFController#getImplementationName()
47       */
48      protected String handleGetImplementationName()
49      {
50          final String pattern = ObjectUtils.toString(
51              this.getConfiguredProperty(JSFGlobals.CONTROLLER_IMPLEMENTATION_PATTERN));
52          return pattern.replaceFirst("\\{0\\}", StringUtils.capitalize(this.getName()));
53      }
54  
55      /**
56       * @return fullyQualifiedImplementationName
57       * @see org.andromda.cartridges.jsf2.metafacades.JSFController#getFullyQualifiedImplementationName()
58       */
59      protected String handleGetFullyQualifiedImplementationName()
60      {
61          final StringBuilder fullyQualifiedName = new StringBuilder();
62          final String packageName = this.getPackageName();
63          if (StringUtils.isNotBlank(packageName))
64          {
65              fullyQualifiedName.append(packageName + '.');
66          }
67          return fullyQualifiedName.append(this.getImplementationName()).toString();
68      }
69  
70      /**
71       * @return getFullyQualifiedImplementationName().replace('.', '/')
72       * @see org.andromda.cartridges.jsf2.metafacades.JSFController#getFullyQualifiedImplementationPath()
73       */
74      protected String handleGetFullyQualifiedImplementationPath()
75      {
76          return this.getFullyQualifiedImplementationName().replace('.', '/');
77      }
78  
79      /**
80       * @return StringUtilsHelper.lowerCamelCaseName(this.getName())
81       * @see org.andromda.cartridges.jsf2.metafacades.JSFController#getBeanName()
82       */
83      protected String handleGetBeanName()
84      {
85          return StringUtilsHelper.lowerCamelCaseName(this.getName());
86      }
87  
88      /**
89       * @return references
90       * @see org.andromda.cartridges.jsf2.metafacades.JSFController#getSessionObjectReferences()
91       */
92      protected List<DependencyFacade> handleGetSessionObjectReferences()
93      {
94          final List<DependencyFacade> references = new ArrayList<DependencyFacade>(this.getSourceDependencies());
95          for (final Iterator<DependencyFacade> iterator = references.iterator(); iterator.hasNext();)
96          {
97              final ModelElementFacade targetElement = (iterator.next()).getTargetElement();
98              if (!(targetElement instanceof JSFSessionObject))
99              {
100                 iterator.remove();
101             }
102         }
103         return references;
104     }
105 
106     /**
107      * @return controllerSerialVersionUID
108      * @see org.andromda.cartridges.jsf2.metafacades.JSFController#getControllerSerialVersionUID()
109      */
110     protected String handleGetControllerSerialVersionUID()
111     {
112        final StringBuilder buffer = new StringBuilder();
113        buffer.append(this.getFullyQualifiedImplementationName());
114        addSerialUIDData(buffer);
115        return JSFUtils.calcSerialVersionUID(buffer);
116     }
117 
118     private void addSerialUIDData(StringBuilder buffer)
119     {
120         for (final FrontEndAction action : this.getUseCase().getActions())
121         {
122             buffer.append(action.getName());
123         }
124     }
125 
126     /**
127      * @see org.andromda.cartridges.jsf2.metafacades.JSFController#getAllServices()
128      */
129     @Override
130     protected Collection<Service> handleGetAllServices() {
131         final Set<Service> allServices=new HashSet<Service>();
132         for(final DependencyFacade dependency: this.getServiceReferences())
133         {
134             allServices.add((Service)dependency.getTargetElement());
135         }
136         for(final DependencyFacade dependency: this.getServicesPackagesReferences())
137         {
138             final PackageFacade pack=(PackageFacade)dependency.getTargetElement();
139             for(final ClassifierFacade clazz: pack.getClasses())
140             {
141                 if(clazz instanceof Service)
142                 {
143                     allServices.add((Service)clazz);
144                 }
145             }
146         }
147         for(final FrontEndAction action: getUseCase().getActions())
148         {
149             for(final FrontEndActionState as: action.getActionStates())
150             {
151                 for(final OperationFacade operation: as.getServiceCalls())
152                 {
153                     allServices.add((Service)operation.getOwner());
154                 }
155             }
156         }
157         return allServices;
158     }
159 
160     /**
161      * @see org.andromda.cartridges.jsf2.metafacades.JSFController#getServicesPackagesReferences()
162      */
163     @SuppressWarnings("unchecked")
164     @Override
165     protected List<PackageFacade> handleGetServicesPackagesReferences() {
166         return (List<PackageFacade>)new FilteredCollection(this.getSourceDependencies())
167         {
168             private static final long serialVersionUID = 134L;
169             @Override
170             public boolean evaluate(final Object object)
171             {
172                 return ((DependencyFacade)object).getTargetElement() instanceof PackageFacade;
173             }
174         };
175     }
176 }