001: package org.andromda.cartridges.spring.metafacades;
002:
003: import org.andromda.metafacades.uml.UMLMetafacadeProperties;
004: import org.apache.commons.lang.StringUtils;
005: import org.apache.commons.lang.ObjectUtils;
006:
007: /**
008: * MetafacadeLogic implementation for org.andromda.cartridges.spring.metafacades.SpringManageableEntity.
009: *
010: * @see org.andromda.cartridges.spring.metafacades.SpringManageableEntity
011: */
012: public class SpringManageableEntityLogicImpl extends
013: SpringManageableEntityLogic {
014:
015: public SpringManageableEntityLogicImpl(Object metaObject,
016: String context) {
017: super (metaObject, context);
018: }
019:
020: /**
021: * @return the configured property denoting the character sequence to use for the separation of namespaces
022: */
023: private String getNamespaceProperty() {
024: return (String) getConfiguredProperty(UMLMetafacadeProperties.NAMESPACE_SEPARATOR);
025: }
026:
027: protected java.lang.String handleGetDaoReferenceName() {
028: final char[] name = getName().toCharArray();
029: if (name.length > 0) {
030: name[0] = Character.toLowerCase(name[0]);
031: }
032:
033: return new String(name) + "Dao";
034: }
035:
036: protected java.lang.String handleGetManageableDaoName() {
037: return getName() + "ManageableDao";
038: }
039:
040: protected java.lang.String handleGetFullyQualifiedManageableDaoName() {
041: return getManageablePackageName() + getNamespaceProperty()
042: + getManageableDaoName();
043: }
044:
045: protected String handleGetManageableDaoFullPath() {
046: return StringUtils.replace(this
047: .getFullyQualifiedManageableDaoName(),
048: getNamespaceProperty(), "/");
049: }
050:
051: protected String handleGetManageableDaoBaseName() {
052: return getManageableDaoName() + "Base";
053: }
054:
055: protected String handleGetFullyQualifiedManageableDaoBaseName() {
056: return getManageablePackageName() + getNamespaceProperty()
057: + getManageableDaoBaseName();
058: }
059:
060: protected String handleGetManageableDaoBaseFullPath() {
061: return StringUtils.replace(this
062: .getFullyQualifiedManageableDaoBaseName(), this
063: .getNamespaceProperty(), "/");
064: }
065:
066: protected String handleGetManageableServiceBaseName() {
067: return getManageableServiceName() + "Base";
068: }
069:
070: protected String handleGetFullyQualifiedManageableServiceBaseName() {
071: return getManageablePackageName() + getNamespaceProperty()
072: + getManageableServiceBaseName();
073: }
074:
075: protected String handleGetManageableServiceBaseFullPath() {
076: return StringUtils.replace(this
077: .getFullyQualifiedManageableServiceBaseName(), this
078: .getNamespaceProperty(), "/");
079: }
080:
081: protected String handleGetManageableValueObjectFullPath() {
082: return StringUtils.replace(this
083: .getFullyQualifiedManageableValueObjectName(), this
084: .getNamespaceProperty(), "/");
085: }
086:
087: protected String handleGetManageableValueObjectClassName() {
088: return getName()
089: + this
090: .getConfiguredProperty(SpringGlobals.CRUD_VALUE_OBJECT_SUFFIX);
091: }
092:
093: protected String handleGetFullyQualifiedManageableValueObjectName() {
094: return getManageablePackageName() + getNamespaceProperty()
095: + getManageableValueObjectClassName();
096: }
097:
098: protected boolean handleIsRemotingTypeRmi() {
099: return this .getRemotingType().equalsIgnoreCase(
100: SpringGlobals.REMOTING_PROTOCOL_RMI);
101: }
102:
103: protected boolean handleIsRemotingTypeNone() {
104: return this .getRemotingType().equalsIgnoreCase(
105: SpringGlobals.REMOTING_PROTOCOL_NONE);
106: }
107:
108: protected boolean handleIsRemotingTypeHttpInvoker() {
109: return this .getRemotingType().equalsIgnoreCase(
110: SpringGlobals.REMOTING_PROTOCOL_HTTPINVOKER);
111: }
112:
113: protected boolean handleIsRemotingTypeHessian() {
114: return this .getRemotingType().equalsIgnoreCase(
115: SpringGlobals.REMOTING_PROTOCOL_HESSIAN);
116: }
117:
118: protected boolean handleIsRemotingTypeBurlap() {
119: return this .getRemotingType().equalsIgnoreCase(
120: SpringGlobals.REMOTING_PROTOCOL_BURLAP);
121: }
122:
123: protected String handleGetRemoteUrl() {
124: final StringBuffer result = new StringBuffer();
125:
126: String propertyPrefix = ObjectUtils
127: .toString(this
128: .getConfiguredProperty(SpringGlobals.CONFIG_PROPERTY_PREFIX));
129:
130: if (this .isRemotingTypeNone()) {
131: // nothing
132: } else if (this .isRemotingTypeHttpInvoker()
133: || this .isRemotingTypeHessian()
134: || this .isRemotingTypeBurlap()) {
135: // server
136: result.append("http://${");
137: result.append(propertyPrefix);
138: result.append("remoteServer}");
139:
140: // port
141: if (hasServiceRemotePort()) {
142: result.append(":${");
143: result.append(propertyPrefix);
144: result.append("remotePort}");
145: }
146:
147: // context
148: if (hasServiceRemoteContext()) {
149: result.append("/${");
150: result.append(propertyPrefix);
151: result.append("remoteContext}");
152: }
153:
154: // service name
155: result.append("/remote");
156: result.append(this .getManageableServiceName());
157: } else if (this .isRemotingTypeRmi()) {
158: // server
159: result.append("rmi://${");
160: result.append(propertyPrefix);
161: result.append("remoteServer}");
162:
163: // port
164: if (hasServiceRemotePort()) {
165: result.append(":${");
166: result.append(propertyPrefix);
167: result.append("remotePort}");
168: }
169:
170: // service name
171: result.append("/remote");
172: result.append(this .getManageableServiceName());
173: }
174:
175: return result.toString();
176: }
177:
178: protected String handleGetRemoteServer() {
179: return StringUtils
180: .trimToEmpty(String
181: .valueOf(this
182: .getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_SERVER)));
183: }
184:
185: protected String handleGetRemotePort() {
186: final String serviceRemotePort = StringUtils
187: .trimToEmpty(String
188: .valueOf(this
189: .getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_PORT)));
190: return SpringMetafacadeUtils.getServiceRemotePort(this ,
191: serviceRemotePort);
192: }
193:
194: protected String handleGetRemoteContext() {
195: return this
196: .isConfiguredProperty(SpringGlobals.SERVICE_REMOTE_CONTEXT) ? ObjectUtils
197: .toString(this
198: .getConfiguredProperty(SpringGlobals.SERVICE_REMOTE_CONTEXT))
199: : "";
200: }
201:
202: protected boolean handleIsRemotable() {
203: return !this .isRemotingTypeNone();
204: }
205:
206: /**
207: * Gets the remoting type for this service.
208: */
209: private String getRemotingType() {
210: final String serviceRemotingType = StringUtils
211: .trimToEmpty(String
212: .valueOf(this
213: .getConfiguredProperty(SpringGlobals.SERVICE_REMOTING_TYPE)));
214: return SpringMetafacadeUtils.getServiceRemotingType(this ,
215: serviceRemotingType);
216: }
217:
218: /**
219: * Checks whether this service has a remote port assigned.
220: *
221: * @return <code>true</code> if the service has a remote port, <code>false</code> otherwise.
222: */
223: private boolean hasServiceRemotePort() {
224: return StringUtils.isNotEmpty(this .getRemotePort());
225: }
226:
227: /**
228: * Checks whether the service has a remote context assigned.
229: *
230: * @return <code>true</code> if the service has a remote context, <code>false</code> otherweise.
231: */
232: private boolean hasServiceRemoteContext() {
233: return StringUtils.isNotEmpty(this.getRemoteContext());
234: }
235:
236: }
|