001: package org.andromda.cartridges.spring.metafacades;
002:
003: import org.andromda.cartridges.spring.SpringProfile;
004: import org.andromda.metafacades.uml.UMLProfile;
005: import org.apache.commons.lang.StringUtils;
006:
007: /**
008: * MetafacadeLogic implementation for org.andromda.cartridges.spring.metafacades.SpringServiceOperation.
009: *
010: * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation
011: */
012: public class SpringServiceOperationLogicImpl extends
013: SpringServiceOperationLogic {
014:
015: public SpringServiceOperationLogicImpl(Object metaObject,
016: String context) {
017: super (metaObject, context);
018: }
019:
020: /**
021: * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation#isWebserviceExposed()
022: */
023: protected boolean handleIsWebserviceExposed() {
024: return this
025: .hasStereotype(UMLProfile.STEREOTYPE_WEBSERVICE_OPERATION);
026: }
027:
028: /**
029: * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation#getImplementationName()
030: */
031: protected String handleGetImplementationName() {
032: return this .getImplementationOperationName(StringUtils
033: .capitalize(this .getName()));
034: }
035:
036: /**
037: * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation#getImplementationSignature()
038: */
039: protected String handleGetImplementationSignature() {
040: return this .getImplementationOperationName(StringUtils
041: .capitalize(this .getSignature()));
042: }
043:
044: /**
045: * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperationL#getImplementationCall()
046: */
047: protected String handleGetImplementationCall() {
048: return this .getImplementationOperationName(StringUtils
049: .capitalize(this .getCall()));
050: }
051:
052: /**
053: * Retrieves the implementationOperatName by replacing the <code>replacement</code> in the {@link
054: * SpringGlobals#IMPLEMENTATION_OPERATION_NAME_PATTERN}
055: *
056: * @param replacement the replacement string for the pattern.
057: * @return the operation name
058: */
059: private String getImplementationOperationName(String replacement) {
060: return StringUtils
061: .trimToEmpty(
062: String
063: .valueOf(this
064: .getConfiguredProperty(SpringGlobals.IMPLEMENTATION_OPERATION_NAME_PATTERN)))
065: .replaceAll("\\{0\\}", replacement);
066: }
067:
068: /**
069: * The transation type for Spring service operations.
070: */
071: private static final String SERVICE_OPERATION_TRANSACTION_TYPE = "serviceOperationTransactionType";
072:
073: /**
074: * @see org.andromda.metafacades.uml.ServiceOperationFacade#getTransactionType()
075: */
076: public String handleGetTransactionType() {
077: String transactionType = (String) this
078: .findTaggedValue(SpringProfile.TAGGEDVALUE_TRANSACTION_TYPE);
079: if (StringUtils.isBlank(transactionType)) {
080: transactionType = (String) this .getOwner().findTaggedValue(
081: SpringProfile.TAGGEDVALUE_TRANSACTION_TYPE);
082: }
083: if (StringUtils.isBlank(transactionType)) {
084: transactionType = String
085: .valueOf(this
086: .getConfiguredProperty(SERVICE_OPERATION_TRANSACTION_TYPE));
087: }
088: return transactionType;
089: }
090:
091: /**
092: * The transaction type for EJB wrapped service operations..
093: */
094: private static final String EJB_SERVICE_OPERATION_TRANSACTION_TYPE = "ejbServiceOperationTransactionType";
095:
096: /**
097: * @see org.andromda.metafacades.uml.ServiceOperationFacade#getEjbTransactionType()
098: */
099: protected String handleGetEjbTransactionType() {
100: String transactionType = (String) this
101: .findTaggedValue(SpringProfile.TAGGEDVALUE_EJB_TRANSACTION_TYPE);
102: if (StringUtils.isBlank(transactionType)) {
103: transactionType = (String) this .getOwner().findTaggedValue(
104: SpringProfile.TAGGEDVALUE_EJB_TRANSACTION_TYPE);
105: }
106: if (StringUtils.isBlank(transactionType)) {
107: transactionType = String
108: .valueOf(this
109: .getConfiguredProperty(EJB_SERVICE_OPERATION_TRANSACTION_TYPE));
110: }
111: return transactionType;
112: }
113:
114: /**
115: * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation#getThrowsClause()
116: */
117: protected String handleGetThrowsClause() {
118: StringBuffer throwsClause = null;
119: if (this .isExceptionsPresent()) {
120: throwsClause = new StringBuffer(this .getExceptionList());
121: }
122: if (throwsClause != null) {
123: throwsClause.insert(0, "throws ");
124: }
125: return throwsClause != null ? throwsClause.toString() : null;
126: }
127:
128: /**
129: * @see org.andromda.cartridges.spring.metafacades.SpringServiceOperation#getThrowsClause(java.lang.String)
130: */
131: protected String handleGetThrowsClause(String initialExceptions) {
132: final StringBuffer throwsClause = new StringBuffer(
133: initialExceptions);
134: if (this .getThrowsClause() != null) {
135: throwsClause.insert(0, ", ");
136: throwsClause.insert(0, this .getThrowsClause());
137: } else {
138: throwsClause.insert(0, "throws ");
139: }
140: return throwsClause.toString();
141: }
142: }
|