View Javadoc
1   package org.andromda.cartridges.jsf2.metafacades;
2   
3   import org.andromda.metafacades.uml.ClassifierFacade;
4   import org.andromda.metafacades.uml.FrontEndUseCase;
5   import org.andromda.metafacades.uml.ModelElementFacade;
6   import org.andromda.metafacades.uml.UMLProfile;
7   
8   /**
9    * MetafacadeLogic implementation for org.andromda.cartridges.jsf2.metafacades.JSFFinalState.
10   *
11   * @see org.andromda.cartridges.jsf2.metafacades.JSFFinalState
12   */
13  public class JSFFinalStateLogicImpl
14      extends JSFFinalStateLogic
15  {
16      private static final long serialVersionUID = 34L;
17      /**
18       * @param metaObject
19       * @param context
20       */
21      public JSFFinalStateLogicImpl(Object metaObject, String context)
22      {
23          super(metaObject, context);
24      }
25      
26      private JSFManageableEntity findManageableByName(String name)
27      {
28          for(ClassifierFacade clazz: getModel().getAllClasses())
29          {
30              if(clazz instanceof JSFManageableEntity && 
31                 (clazz.getName().equals(name) || clazz.getFullyQualifiedName().equals(name)))
32              {
33                  return (JSFManageableEntity)clazz;
34              }
35          }
36          return null;
37      }
38  
39      /**
40       * @return fullPath
41       * @see org.andromda.cartridges.jsf2.metafacades.JSFFinalState#getPath()
42       */
43      protected String handleGetPath()
44      {
45          String fullPath = null;
46  
47          FrontEndUseCase useCase = this.getTargetUseCase();
48          if (useCase == null)
49          {
50              // - perhaps this final state links outside of the UML model
51              final Object taggedValue = this.findTaggedValue(UMLProfile.TAGGEDVALUE_EXTERNAL_HYPERLINK);
52              if (taggedValue == null)
53              {
54                  String name = getName();
55                  if (name != null && (name.startsWith("/") || name.startsWith("http://") || name.startsWith("file:")))
56                  {
57                      fullPath = name;
58                  }
59              }
60              else
61              {
62                  fullPath = String.valueOf(taggedValue);
63              }
64              
65              if(fullPath == null && getName() != null)
66              {
67                  fullPath = ((JSFManageableEntity)getTargetElement()).getActionFullPath();
68              }
69              
70          }
71          else if (useCase instanceof JSFUseCase)
72          {
73              fullPath = ((JSFUseCase)useCase).getPath();
74          }
75  
76          return fullPath;
77      }
78  
79      /**
80       * @return the target controller
81       * @see org.andromda.cartridges.jsf2.metafacades.JSFFinalState#getTargetControllerFullyQualifiedName()
82       */
83      @Override
84      protected String handleGetTargetControllerFullyQualifiedName() {
85          String result=null;
86          
87          if(getTargetElement() instanceof JSFUseCase)
88          {
89              result=((JSFUseCase)getTargetElement()).getController().getFullyQualifiedName();
90          }
91          else if(getTargetElement() instanceof JSFManageableEntity)
92          {
93              result=((JSFManageableEntity)getTargetElement()).getControllerType();
94          }
95          
96          return result;
97      }
98  
99      /**
100      * @return the target controller bean name
101      * @see org.andromda.cartridges.jsf2.metafacades.JSFFinalState#getTargetControllerBeanName()
102      */
103     @Override
104     protected String handleGetTargetControllerBeanName() {
105         String result=null;
106         
107         if(getTargetElement() instanceof JSFUseCase)
108         {
109             result=((JSFController)((JSFUseCase)getTargetElement()).getController()).getBeanName();
110         }
111         else if(getTargetElement() instanceof JSFManageableEntity)
112         {
113             result=((JSFManageableEntity)getTargetElement()).getControllerBeanName();
114         }
115         
116         return result;
117     }
118 
119     /**
120      * @return the target element (use case or manageable class)
121      * @see org.andromda.cartridges.jsf2.metafacades.JSFFinalState#getTargetElement()
122      */
123     @Override
124     protected ModelElementFacade handleGetTargetElement() {
125         ModelElementFacade targetElement=getTargetUseCase();
126         
127         if(targetElement == null)
128         {
129             String nameParts[] = getName().split(" ");
130             if(nameParts.length >= 2 && nameParts[0].equalsIgnoreCase("Manage"))
131             {
132                 JSFManageableEntity manageable=findManageableByName(nameParts[1]);
133                 if(manageable != null)
134                 {
135                     return targetElement=manageable;
136                 }
137             }
138         }
139         
140         return targetElement;
141     }
142 }