View Javadoc

1   package org.andromda.cartridges.spring.metafacades;
2   
3   import org.andromda.metafacades.uml.UMLMetafacadeProperties;
4   import org.apache.commons.lang.StringUtils;
5   import org.apache.commons.lang.ObjectUtils;
6   
7   
8   /***
9    * MetafacadeLogic implementation for org.andromda.cartridges.spring.metafacades.SpringManageableEntity.
10   *
11   * @see org.andromda.cartridges.spring.metafacades.SpringManageableEntity
12   */
13  public class SpringManageableEntityLogicImpl
14      extends SpringManageableEntityLogic
15  {
16  
17      public SpringManageableEntityLogicImpl (Object metaObject, String context)
18      {
19          super (metaObject, context);
20      }
21  
22      /***
23       * @return the configured property denoting the character sequence to use for the separation of namespaces
24       */
25      private String getNamespaceProperty()
26      {
27          return (String)getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR);
28      }
29  
30      protected java.lang.String handleGetDaoReferenceName()
31      {
32          final char[] name = getName().toCharArray();
33          if (name.length > 0)
34          {
35              name[0] = Character.toLowerCase(name[0]);
36          }
37  
38          return new String(name) + "Dao";
39      }
40  
41      protected java.lang.String handleGetManageableDaoName()
42      {
43          return getName() + "ManageableDao";
44      }
45  
46      protected java.lang.String handleGetFullyQualifiedManageableDaoName()
47      {
48          return getManageablePackageName() + getNamespaceProperty() + getManageableDaoName();
49      }
50  
51      protected String handleGetManageableDaoFullPath()
52      {
53          return StringUtils.replace(this.getFullyQualifiedManageableDaoName(), getNamespaceProperty(), "/");
54      }
55  
56      protected String handleGetManageableDaoBaseName()
57      {
58          return getManageableDaoName() + "Base";
59      }
60  
61      protected String handleGetFullyQualifiedManageableDaoBaseName()
62      {
63          return getManageablePackageName() + getNamespaceProperty() + getManageableDaoBaseName();
64      }
65  
66      protected String handleGetManageableDaoBaseFullPath()
67      {
68          return StringUtils.replace(this.getFullyQualifiedManageableDaoBaseName(), this.getNamespaceProperty(), "/");
69      }
70  
71      protected String handleGetManageableServiceBaseName()
72      {
73          return getManageableServiceName() + "Base";
74      }
75  
76      protected String handleGetFullyQualifiedManageableServiceBaseName()
77      {
78          return getManageablePackageName() + getNamespaceProperty() + getManageableServiceBaseName();
79      }
80  
81      protected String handleGetManageableServiceBaseFullPath()
82      {
83          return StringUtils.replace(this.getFullyQualifiedManageableServiceBaseName(), this.getNamespaceProperty(), "/");
84      }
85  
86      protected String handleGetManageableValueObjectFullPath()
87      {
88          return StringUtils.replace(this.getFullyQualifiedManageableValueObjectName(), this.getNamespaceProperty(), "/");
89      }
90  
91      protected String handleGetManageableValueObjectClassName()
92      {
93          return getName() + this.getConfiguredProperty(SpringGlobals.CRUD_VALUE_OBJECT_SUFFIX);
94      }
95  
96      protected String handleGetFullyQualifiedManageableValueObjectName()
97      {
98          return getManageablePackageName() + getNamespaceProperty() + getManageableValueObjectClassName();
99      }
100 
101     protected boolean handleIsRemotingTypeRmi()
102     {
103         return this.getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_RMI);
104     }
105 
106     protected boolean handleIsRemotingTypeNone()
107     {
108         return this.getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_NONE);
109     }
110 
111     protected boolean handleIsRemotingTypeHttpInvoker()
112     {
113         return this.getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_HTTPINVOKER);
114     }
115 
116     protected boolean handleIsRemotingTypeHessian()
117     {
118         return this.getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_HESSIAN);
119     }
120 
121     protected boolean handleIsRemotingTypeBurlap()
122     {
123         return this.getRemotingType().equalsIgnoreCase(SpringGlobals.REMOTING_PROTOCOL_BURLAP);
124     }
125 
126     protected String handleGetRemoteUrl()
127     {
128         final StringBuffer result = new StringBuffer();
129 
130         String propertyPrefix = ObjectUtils.toString(this.getConfiguredProperty(SpringGlobals.CONFIG_PROPERTY_PREFIX));
131 
132         if (this.isRemotingTypeNone())
133         {
134             // nothing
135         }
136         else if (this.isRemotingTypeHttpInvoker() || this.isRemotingTypeHessian() || this.isRemotingTypeBurlap())
137         {
138             // server
139             result.append("http://${");
140             result.append(propertyPrefix);
141             result.append("remoteServer}");
142 
143             // port
144             if (hasServiceRemotePort())
145             {
146                 result.append(":${");
147                 result.append(propertyPrefix);
148                 result.append("remotePort}");
149             }
150 
151             // context
152             if (hasServiceRemoteContext())
153             {
154                 result.append("/${");
155                 result.append(propertyPrefix);
156                 result.append("remoteContext}");
157             }
158 
159             // service name
160             result.append("/remote");
161             result.append(this.getManageableServiceName());
162         }
163         else if (this.isRemotingTypeRmi())
164         {
165             // server
166             result.append("rmi://${");
167             result.append(propertyPrefix);
168             result.append("remoteServer}");
169 
170             // port
171             if (hasServiceRemotePort())
172             {
173                 result.append(":${");
174                 result.append(propertyPrefix);
175                 result.append("remotePort}");
176             }
177 
178             // service name
179             result.append("/remote");
180             result.append(this.getManageableServiceName());
181         }
182 
183         return result.toString();
184     }
185 
186     protected String handleGetRemoteServer()
187     {
188         return StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_SERVER)));
189     }
190 
191     protected String handleGetRemotePort()
192     {
193         final String serviceRemotePort =
194             StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_PORT)));
195         return SpringMetafacadeUtils.getServiceRemotePort(this, serviceRemotePort);
196     }
197 
198     protected String handleGetRemoteContext()
199     {
200         return this.isConfiguredProperty(SpringGlobals.SERVICE_REMOTE_CONTEXT)
201             ? ObjectUtils.toString(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_CONTEXT)) : "";
202     }
203 
204     protected boolean handleIsRemotable()
205     {
206         return !this.isRemotingTypeNone();
207     }
208 
209     /***
210      * Gets the remoting type for this service.
211      */
212     private String getRemotingType()
213     {
214         final String serviceRemotingType =
215             StringUtils.trimToEmpty(String.valueOf(this.getConfiguredProperty(SpringGlobals.SERVICE_REMOTING_TYPE)));
216         return SpringMetafacadeUtils.getServiceRemotingType(this, serviceRemotingType);
217     }
218 
219     /***
220      * Checks whether this service has a remote port assigned.
221      *
222      * @return <code>true</code> if the service has a remote port, <code>false</code> otherwise.
223      */
224     private boolean hasServiceRemotePort()
225     {
226         return StringUtils.isNotEmpty(this.getRemotePort());
227     }
228 
229     /***
230      * Checks whether the service has a remote context assigned.
231      *
232      * @return <code>true</code> if the service has a remote context, <code>false</code> otherweise.
233      */
234     private boolean hasServiceRemoteContext()
235     {
236         return StringUtils.isNotEmpty(this.getRemoteContext());
237     }
238 
239 }