0001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
0002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
0003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
0005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
0012: // POSSIBILITY OF SUCH DAMAGE.
0013: //
0014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
0015: package com.metaboss.sdlctools.services.codegeneration.domainsupportservicesimplementationgenerator;
0016:
0017: import java.io.File;
0018: import java.io.FileWriter;
0019: import java.io.IOException;
0020: import java.io.PrintWriter;
0021: import java.util.Collection;
0022: import java.util.HashSet;
0023: import java.util.Iterator;
0024: import java.util.List;
0025: import java.util.Properties;
0026: import java.util.Set;
0027:
0028: import org.apache.commons.logging.Log;
0029: import org.apache.commons.logging.LogFactory;
0030:
0031: import com.metaboss.enterprise.bo.BOException;
0032: import com.metaboss.enterprise.bs.BSDomainObjectInvocationException;
0033: import com.metaboss.enterprise.bs.BSException;
0034: import com.metaboss.enterprise.bs.BSServiceProviderException;
0035: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
0036: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
0037: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
0038: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
0039: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationTypeEnum;
0040: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Association;
0041: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
0042: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
0043: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotype;
0044: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotypeEnum;
0045: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
0046: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
0047: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.PrimaryKeyElement;
0048: import com.metaboss.sdlctools.services.codegeneration.CodeGenerationStylesheetAccessor;
0049: import com.metaboss.sdlctools.services.codegeneration.CommonUtil;
0050: import com.metaboss.sdlctools.services.codegeneration.CopyrightUtils;
0051: import com.metaboss.sdlctools.services.codegenerationstylesheet.STAssociationRoleStylesheet;
0052: import com.metaboss.sdlctools.services.codegenerationstylesheet.STAttributeStylesheet;
0053: import com.metaboss.sdlctools.services.codegenerationstylesheet.STDatatypeStylesheet;
0054: import com.metaboss.sdlctools.services.codegenerationstylesheet.STDomainStylesheet;
0055: import com.metaboss.sdlctools.services.codegenerationstylesheet.STEntityStylesheet;
0056: import com.metaboss.sdlctools.services.codegenerationstylesheet.STMessageStylesheet;
0057: import com.metaboss.sdlctools.services.codegenerationstylesheet.STOperationStylesheet;
0058: import com.metaboss.sdlctools.services.codegenerationstylesheet.STServiceStylesheet;
0059: import com.metaboss.sdlctools.services.codegenerationstylesheet.STServicemoduleStylesheet;
0060: import com.metaboss.sdlctools.services.codegenerationstylesheet.STStructureStylesheet;
0061: import com.metaboss.util.DirectoryUtils;
0062: import com.metaboss.util.StringUtils;
0063:
0064: public class ImplementationGenerator {
0065: // Commons Logging instance.
0066: private static final Log sLogger = LogFactory
0067: .getLog(ImplementationGenerator.class);
0068:
0069: // Returns package to use for implementation. This is the default implementation, so it does not need any subpackage
0070: public static String getImplementationJavaPackage(Domain pDomain)
0071: throws BSException, BOException {
0072: STDomainStylesheet lDomainStylesheet = CodeGenerationStylesheetAccessor
0073: .getDomainStylesheet(pDomain);
0074: Servicemodule lSupportServicemodule = pDomain
0075: .getSystem()
0076: .getServicemodule(
0077: lDomainStylesheet.getSupportServicemoduleName());
0078: Service lDataManagementService = lSupportServicemodule
0079: .getService(lDomainStylesheet
0080: .getDataManagementServiceName());
0081: STServiceStylesheet lServiceStylesheet = CodeGenerationStylesheetAccessor
0082: .getServiceStylesheet(lDataManagementService);
0083: return lServiceStylesheet
0084: .getGeneratedImplementationBasePackageName();
0085: }
0086:
0087: public static void generateImplementation(
0088: String pGenerationDirectoryPath, Domain pDomain,
0089: Service pService) throws BSException, BOException {
0090: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = pDomain
0091: .getSystem();
0092: Servicemodule lServicemodule = pService.getServicemodule();
0093:
0094: String lImplementationJavaPackage = getImplementationJavaPackage(pDomain);
0095: // Ensure that directory is available and it has no old files in it
0096: String lImplementationDir = pGenerationDirectoryPath
0097: + File.separator
0098: + StringUtils.replace(lImplementationJavaPackage, ".",
0099: File.separator);
0100: try {
0101: DirectoryUtils
0102: .ensureNewNoFilesDirectory(lImplementationDir);
0103: } catch (IOException e) {
0104: throw new BSServiceProviderException("Unable to create "
0105: + lImplementationDir + " directory", e);
0106: }
0107:
0108: // Generate factory implementation
0109: generateFactoryImplementationSource(lImplementationDir,
0110: lImplementationJavaPackage, lSystem, lServicemodule,
0111: pService, pDomain);
0112: // Generate main implementation
0113: generateMainImplementationSource(lImplementationDir,
0114: lImplementationJavaPackage, lSystem, lServicemodule,
0115: pService, pDomain);
0116: // Generate structure translators
0117: generateSourceForTranslators(lImplementationDir,
0118: lImplementationJavaPackage, lSystem, lServicemodule,
0119: pService, pDomain);
0120: }
0121:
0122: // Generates source for the translators between structures and BOs
0123: private static void generateSourceForTranslators(
0124: String pImplementationDir,
0125: String pImplementationPackage,
0126: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System pSystem,
0127: Servicemodule pServicemodule, Service pService,
0128: Domain pDomain) throws BOException, BSException {
0129: // Retrieve stylesheets for the servicemodule and service
0130: STServiceStylesheet lServiceStylesheet = CodeGenerationStylesheetAccessor
0131: .getServiceStylesheet(pService);
0132: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
0133: .getServicemoduleStylesheet(pServicemodule);
0134: STDomainStylesheet lDomainStylesheet = CodeGenerationStylesheetAccessor
0135: .getDomainStylesheet(pDomain);
0136: // Generate translators between entities and structures
0137: Collection lEntities = pDomain.getEntities();
0138: for (Iterator lEntitiesIterator = lEntities.iterator(); lEntitiesIterator
0139: .hasNext();) {
0140: Entity lEntity = (Entity) lEntitiesIterator.next();
0141: try {
0142: STEntityStylesheet lEntityStylesheet = CodeGenerationStylesheetAccessor
0143: .getEntityStylesheet(lEntity);
0144: STDatatypeStylesheet lEntityInstanceIdDatatypeStylesheet = CodeGenerationStylesheetAccessor
0145: .getDatatypeStylesheet(lEntity
0146: .getInstanceIdDataType());
0147: STStructureStylesheet lEntityDetailsStructureStylesheet = CodeGenerationStylesheetAccessor
0148: .getStructureStylesheet(pServicemodule
0149: .getStructure(lEntityStylesheet
0150: .getServiceDetailsStructureName()));
0151: STStructureStylesheet lEntityKeyStructureStylesheet = CodeGenerationStylesheetAccessor
0152: .getStructureStylesheet(pServicemodule
0153: .getStructure(lEntityStylesheet
0154: .getServiceKeyStructureName()));
0155: String lServiceDetailsStructureTranslatorFullName = pImplementationPackage
0156: + "."
0157: + lEntityStylesheet
0158: .getServiceDetailsStructureTranslatorName();
0159:
0160: // Will create the convertor between BO and details structure
0161: FileWriter lFileWriter = null;
0162: PrintWriter lWriter = null;
0163: try {
0164: String lFileName = pImplementationDir
0165: + File.separator
0166: + lEntityStylesheet
0167: .getServiceDetailsStructureTranslatorName()
0168: + ".java";
0169: lWriter = new PrintWriter(
0170: lFileWriter = new FileWriter(lFileName));
0171: CopyrightUtils
0172: .writeCopyrightToGeneratedJavaSource(lWriter);
0173: lWriter.println("package " + pImplementationPackage
0174: + ";");
0175: lWriter.println();
0176: lWriter
0177: .println("import com.metaboss.enterprise.bo.BOException;");
0178: lWriter
0179: .println("import com.metaboss.enterprise.bo.BOIllegalArgumentException;");
0180: lWriter.println();
0181: lWriter
0182: .println("/** This is the helper class used in data translation between "
0183: + lEntityDetailsStructureStylesheet
0184: .getClassFullName()
0185: + " and "
0186: + lEntityStylesheet
0187: .getDomainInterfaceFullName()
0188: + "*/");
0189: lWriter
0190: .println("public class "
0191: + lEntityStylesheet
0192: .getServiceDetailsStructureTranslatorName());
0193: lWriter.println("{");
0194: lWriter
0195: .println(" public static "
0196: + lEntityDetailsStructureStylesheet
0197: .getClassFullName()
0198: + "[] convertToDetailsStructureArray( "
0199: + lEntityStylesheet
0200: .getDomainInterfaceFullName()
0201: + "[] pDomainEntityObjectArray) throws BOException");
0202: lWriter.println(" {");
0203: lWriter
0204: .println(" if (pDomainEntityObjectArray == null)");
0205: lWriter.println(" return null;");
0206: lWriter.println(" "
0207: + lEntityDetailsStructureStylesheet
0208: .getClassFullName()
0209: + "[] lDetailsStructureArray = new "
0210: + lEntityDetailsStructureStylesheet
0211: .getClassFullName()
0212: + "[pDomainEntityObjectArray.length];");
0213: lWriter
0214: .println(" for (int i = 0; i < pDomainEntityObjectArray.length; i++)");
0215: lWriter.println(" {");
0216: lWriter
0217: .println(" lDetailsStructureArray[i] = convertToDetailsStructure(pDomainEntityObjectArray[i]);");
0218: lWriter.println(" }");
0219: lWriter
0220: .println(" return lDetailsStructureArray;");
0221: lWriter.println(" }");
0222: lWriter
0223: .println(" public static "
0224: + lEntityDetailsStructureStylesheet
0225: .getClassFullName()
0226: + " convertToDetailsStructure( "
0227: + lEntityStylesheet
0228: .getDomainInterfaceFullName()
0229: + " pDomainEntityObject) throws BOException");
0230: lWriter.println(" {");
0231: lWriter
0232: .println(" if (pDomainEntityObject == null)");
0233: lWriter.println(" return null;");
0234: lWriter.println(" "
0235: + lEntityDetailsStructureStylesheet
0236: .getClassFullName()
0237: + " lResult = new "
0238: + lEntityDetailsStructureStylesheet
0239: .getClassFullName() + "();");
0240: lWriter
0241: .println(" lResult.set"
0242: + lEntityStylesheet
0243: .getInstanceIdServiceStructureAttributeName()
0244: + "(pDomainEntityObject.get"
0245: + lEntityStylesheet
0246: .getInstanceIdDomainObjectAttributeName()
0247: + "());");
0248: if (lEntity.isModifiable())
0249: lWriter
0250: .println(" lResult.set"
0251: + lEntityStylesheet
0252: .getVersionIdServiceStructureAttributeName()
0253: + "(pDomainEntityObject.get"
0254: + lEntityStylesheet
0255: .getVersionIdDomainObjectAttributeName()
0256: + "());");
0257: if (lEntity.getStateMachine() != null)
0258: lWriter
0259: .println(" lResult.set"
0260: + lEntityStylesheet
0261: .getStateServiceStructureAttributeName()
0262: + "(pDomainEntityObject.get"
0263: + lEntityStylesheet
0264: .getStateDomainObjectAttributeName()
0265: + "());");
0266: // Now all attributes
0267: Collection lAttributes = lEntity
0268: .getCombinedAttributes();
0269: for (Iterator lAttributesIterator = lAttributes
0270: .iterator(); lAttributesIterator.hasNext();) {
0271: Attribute lAttribute = (Attribute) lAttributesIterator
0272: .next();
0273: STAttributeStylesheet lAttributeStylesheet = CodeGenerationStylesheetAccessor
0274: .getAttributeStylesheet(lAttribute);
0275: lWriter.println(" lResult.set"
0276: + lAttributeStylesheet
0277: .getNormalisedName()
0278: + "(pDomainEntityObject.get"
0279: + lAttributeStylesheet
0280: .getNormalisedName() + "());");
0281: }
0282: Collection lReferences = lEntity
0283: .getCombinedReferences();
0284: for (Iterator lReferencesIterator = lReferences
0285: .iterator(); lReferencesIterator.hasNext();) {
0286: AssociationRole lRole = (AssociationRole) lReferencesIterator
0287: .next();
0288: if (!lRole.isPlural()) {
0289: Entity lRoleEntity = lRole.getEntity();
0290: STEntityStylesheet lRoleEntityStylesheet = CodeGenerationStylesheetAccessor
0291: .getEntityStylesheet(lRoleEntity);
0292: // Singular multiplicities resolved simply by having the other entity id as the member of the structure
0293: // Not singular cardinality is resolved by having a separate service call
0294: if (!lRole.isOptional()) {
0295: // There always be reference
0296: lWriter
0297: .println(" lResult.set"
0298: + lRole.getName()
0299: + "( "
0300: + lRoleEntityStylesheet
0301: .getServiceDetailsStructureTranslatorName()
0302: + ".convertToKeyStructure(pDomainEntityObject.get"
0303: + lRole.getName()
0304: + "()));");
0305: } else {
0306: // Must test for null
0307: STStructureStylesheet lRoleEntityKeyStructureStylesheet = CodeGenerationStylesheetAccessor
0308: .getStructureStylesheet(pServicemodule
0309: .getStructure(lRoleEntityStylesheet
0310: .getServiceKeyStructureName()));
0311: lWriter
0312: .println(" "
0313: + lRoleEntityStylesheet
0314: .getDomainInterfaceFullName()
0315: + " l"
0316: + lRole.getName()
0317: + " = pDomainEntityObject.get"
0318: + lRole.getName()
0319: + "();");
0320: lWriter
0321: .println(" if (l"
0322: + lRole.getName()
0323: + " != null)");
0324: lWriter
0325: .println(" lResult.set"
0326: + lRole.getName()
0327: + "( "
0328: + lRoleEntityStylesheet
0329: .getServiceDetailsStructureTranslatorName()
0330: + ".convertToKeyStructure(l"
0331: + lRole.getName()
0332: + "));");
0333: lWriter.println(" else");
0334: lWriter
0335: .println(" lResult.set"
0336: + lRole.getName()
0337: + "(new "
0338: + lRoleEntityKeyStructureStylesheet
0339: .getClassFullName()
0340: + "());");
0341: }
0342: }
0343: }
0344: lWriter.println(" return lResult;");
0345: lWriter.println(" }");
0346: lWriter
0347: .println(" public static "
0348: + lEntityKeyStructureStylesheet
0349: .getClassFullName()
0350: + " convertToKeyStructure( "
0351: + lEntityStylesheet
0352: .getDomainInterfaceFullName()
0353: + " pDomainEntityObject) throws BOException");
0354: lWriter.println(" {");
0355: lWriter
0356: .println(" if (pDomainEntityObject == null)");
0357: lWriter.println(" return null;");
0358: lWriter.println(" "
0359: + lEntityKeyStructureStylesheet
0360: .getClassFullName()
0361: + " lResult = new "
0362: + lEntityKeyStructureStylesheet
0363: .getClassFullName() + "();");
0364: lWriter
0365: .println(" lResult.set"
0366: + lEntityStylesheet
0367: .getInstanceIdServiceStructureAttributeName()
0368: + "(pDomainEntityObject.get"
0369: + lEntityStylesheet
0370: .getInstanceIdDomainObjectAttributeName()
0371: + "());");
0372: Collection lPrimaryKeyElements = lEntity
0373: .getPrimaryKeyElements();
0374: for (Iterator lPrimaryKeyElementsIterator = lPrimaryKeyElements
0375: .iterator(); lPrimaryKeyElementsIterator
0376: .hasNext();) {
0377: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
0378: .next();
0379: if (lPrimaryKeyElement instanceof Attribute) {
0380: Attribute lAttribute = (Attribute) lPrimaryKeyElement;
0381: STAttributeStylesheet lAttributeStylesheet = CodeGenerationStylesheetAccessor
0382: .getAttributeStylesheet(lAttribute);
0383: lWriter.println(" lResult.set"
0384: + lAttributeStylesheet
0385: .getNormalisedName()
0386: + "(pDomainEntityObject.get"
0387: + lAttributeStylesheet
0388: .getNormalisedName()
0389: + "());");
0390: } else if (lPrimaryKeyElement instanceof AssociationRole) {
0391: AssociationRole lRole = (AssociationRole) lPrimaryKeyElement;
0392: STAssociationRoleStylesheet lRoleStylesheet = CodeGenerationStylesheetAccessor
0393: .getAssociationRoleStylesheet(lRole);
0394: STEntityStylesheet lRoleEntityStylesheet = CodeGenerationStylesheetAccessor
0395: .getEntityStylesheet(lRole
0396: .getEntity());
0397: lWriter
0398: .println(" lResult.set"
0399: + lRoleStylesheet
0400: .getNormalisedName()
0401: + "( "
0402: + lRoleEntityStylesheet
0403: .getServiceDetailsStructureTranslatorName()
0404: + ".convertToKeyStructure(pDomainEntityObject.get"
0405: + lRoleStylesheet
0406: .getNormalisedName()
0407: + "()));");
0408: }
0409: }
0410: lWriter.println(" return lResult;");
0411: lWriter.println(" }");
0412:
0413: // Get BO from domain object helpers
0414: {
0415: lWriter
0416: .println(" /** Helper. Gets read-only instance of the Bo from the domain using key structure */");
0417: lWriter.println(" public static "
0418: + lEntityStylesheet
0419: .getDomainInterfaceFullName()
0420: + " get"
0421: + lEntityStylesheet
0422: .getDomainInterfaceName()
0423: + "( "
0424: + lDomainStylesheet
0425: .getDomainInterfaceFullName()
0426: + " pDomain, "
0427: + lEntityKeyStructureStylesheet
0428: .getClassFullName() + " p"
0429: + lEntityStylesheet.getNormalisedName()
0430: + "Key) throws BOException");
0431: lWriter.println(" {");
0432: if (lEntity.getPrimaryKeyElements().size() > 0) {
0433: lWriter
0434: .println(" "
0435: + lEntityInstanceIdDatatypeStylesheet
0436: .getClassFullName()
0437: + " lInstanceId = p"
0438: + lEntityStylesheet
0439: .getNormalisedName()
0440: + "Key.getInstanceId();");
0441: lWriter
0442: .println(" if (lInstanceId != null)");
0443: lWriter.println(" {");
0444: lWriter
0445: .println(" if (lInstanceId.isEmpty())");
0446: lWriter
0447: .println(" throw new BOIllegalArgumentException(\""
0448: + lEntityStylesheet
0449: .getNormalisedName()
0450: + "Key.InstanceId parameter field can not be empty when invoking get"
0451: + lEntityStylesheet
0452: .getDomainInterfaceName()
0453: + "() operation with the instance identifier.\");");
0454: lWriter
0455: .println(" if (lInstanceId.isConcealed())");
0456: lWriter
0457: .println(" throw new BOIllegalArgumentException(\""
0458: + lEntityStylesheet
0459: .getNormalisedName()
0460: + "Key.InstanceId parameter field can not be concealed when invoking get"
0461: + lEntityStylesheet
0462: .getDomainInterfaceName()
0463: + "() operation with the instance identifier.\");");
0464: lWriter
0465: .println(" return pDomain.get"
0466: + lEntityStylesheet
0467: .getNormalisedName()
0468: + "(lInstanceId);");
0469: lWriter.println(" }");
0470: // At this stage we need to check that all elements of the primary key are present
0471: for (Iterator lPrimaryKeyElementsIterator = lPrimaryKeyElements
0472: .iterator(); lPrimaryKeyElementsIterator
0473: .hasNext();) {
0474: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
0475: .next();
0476: if (lPrimaryKeyElement instanceof Attribute) {
0477: Attribute lAttribute = (Attribute) lPrimaryKeyElement;
0478: STAttributeStylesheet lAttributeStylesheet = CodeGenerationStylesheetAccessor
0479: .getAttributeStylesheet(lAttribute);
0480: STDatatypeStylesheet lAttributeDatatypeStylesheet = CodeGenerationStylesheetAccessor
0481: .getDatatypeStylesheet(lAttribute
0482: .getDataType());
0483: lWriter
0484: .println(" "
0485: + lAttributeDatatypeStylesheet
0486: .getClassFullName()
0487: + " l"
0488: + lAttributeStylesheet
0489: .getNormalisedName()
0490: + " = p"
0491: + lEntityStylesheet
0492: .getNormalisedName()
0493: + "Key.get"
0494: + lAttributeStylesheet
0495: .getNormalisedName()
0496: + "();");
0497: lWriter
0498: .println(" if (l"
0499: + lAttributeStylesheet
0500: .getNormalisedName()
0501: + " == null)");
0502: lWriter
0503: .println(" throw new BOIllegalArgumentException(\""
0504: + lEntityStylesheet
0505: .getNormalisedName()
0506: + "Key."
0507: + lAttributeStylesheet
0508: .getNormalisedName()
0509: + " parameter field can not be null when invoking get"
0510: + lEntityStylesheet
0511: .getDomainInterfaceName()
0512: + "() operation with the primary key.\");");
0513: lWriter
0514: .println(" if (l"
0515: + lAttributeStylesheet
0516: .getNormalisedName()
0517: + ".isEmpty())");
0518: lWriter
0519: .println(" throw new BOIllegalArgumentException(\""
0520: + lEntityStylesheet
0521: .getNormalisedName()
0522: + "Key."
0523: + lAttributeStylesheet
0524: .getNormalisedName()
0525: + " parameter field can not be empty when invoking get"
0526: + lEntityStylesheet
0527: .getDomainInterfaceName()
0528: + "() operation with the primary key.\");");
0529: lWriter
0530: .println(" if (l"
0531: + lAttributeStylesheet
0532: .getNormalisedName()
0533: + ".isConcealed())");
0534: lWriter
0535: .println(" throw new BOIllegalArgumentException(\""
0536: + lEntityStylesheet
0537: .getNormalisedName()
0538: + "Key."
0539: + lAttributeStylesheet
0540: .getNormalisedName()
0541: + " parameter field can not be concealed when invoking get"
0542: + lEntityStylesheet
0543: .getDomainInterfaceName()
0544: + "() operation with the primary key.\");");
0545: } else if (lPrimaryKeyElement instanceof AssociationRole) {
0546: AssociationRole lRole = (AssociationRole) lPrimaryKeyElement;
0547: STAssociationRoleStylesheet lRoleStylesheet = CodeGenerationStylesheetAccessor
0548: .getAssociationRoleStylesheet(lRole);
0549: STEntityStylesheet lRoleEntityStylesheet = CodeGenerationStylesheetAccessor
0550: .getEntityStylesheet(lRole
0551: .getEntity());
0552: STStructureStylesheet lRoleEntityKeyStructureStylesheet = CodeGenerationStylesheetAccessor
0553: .getStructureStylesheet(pServicemodule
0554: .getStructure(lRoleEntityStylesheet
0555: .getServiceKeyStructureName()));
0556: lWriter
0557: .println(" "
0558: + lRoleEntityKeyStructureStylesheet
0559: .getClassFullName()
0560: + " l"
0561: + lRoleStylesheet
0562: .getNormalisedName()
0563: + "Key = p"
0564: + lEntityStylesheet
0565: .getNormalisedName()
0566: + "Key.get"
0567: + lRoleStylesheet
0568: .getNormalisedName()
0569: + "();");
0570: lWriter
0571: .println(" if (l"
0572: + lRoleStylesheet
0573: .getNormalisedName()
0574: + "Key == null)");
0575: lWriter
0576: .println(" throw new BOIllegalArgumentException(\""
0577: + lEntityStylesheet
0578: .getNormalisedName()
0579: + "Key."
0580: + lRoleStylesheet
0581: .getNormalisedName()
0582: + " parameter field can not be null when invoking get"
0583: + lEntityStylesheet
0584: .getDomainInterfaceName()
0585: + "() operation with the primary key.\");");
0586: lWriter
0587: .println(" "
0588: + lRoleEntityStylesheet
0589: .getDomainInterfaceFullName()
0590: + " l"
0591: + lRoleStylesheet
0592: .getNormalisedName()
0593: + " = "
0594: + lRoleEntityStylesheet
0595: .getServiceDetailsStructureTranslatorName()
0596: + ".get"
0597: + lRoleEntityStylesheet
0598: .getDomainInterfaceName()
0599: + "( pDomain, l"
0600: + lRoleStylesheet
0601: .getNormalisedName()
0602: + "Key);");
0603: }
0604: }
0605: lWriter.print(" return pDomain.get"
0606: + lEntityStylesheet
0607: .getNormalisedName() + "(");
0608: for (Iterator lPrimaryKeyElementsIterator = lPrimaryKeyElements
0609: .iterator(); lPrimaryKeyElementsIterator
0610: .hasNext();) {
0611: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
0612: .next();
0613: if (lPrimaryKeyElement instanceof Attribute) {
0614: Attribute lAttribute = (Attribute) lPrimaryKeyElement;
0615: STAttributeStylesheet lAttributeStylesheet = CodeGenerationStylesheetAccessor
0616: .getAttributeStylesheet(lAttribute);
0617: lWriter.print("l");
0618: lWriter.print(lAttributeStylesheet
0619: .getNormalisedName());
0620: }
0621: if (lPrimaryKeyElement instanceof AssociationRole) {
0622: AssociationRole lRole = (AssociationRole) lPrimaryKeyElement;
0623: STAssociationRoleStylesheet lRoleStylesheet = CodeGenerationStylesheetAccessor
0624: .getAssociationRoleStylesheet(lRole);
0625: lWriter.print("l");
0626: lWriter.print(lRoleStylesheet
0627: .getNormalisedName());
0628: }
0629: if (lPrimaryKeyElementsIterator
0630: .hasNext())
0631: lWriter.print(", ");
0632: else
0633: lWriter.println(");");
0634: }
0635: } else {
0636: lWriter
0637: .println(" "
0638: + lEntityInstanceIdDatatypeStylesheet
0639: .getClassFullName()
0640: + " lInstanceId = p"
0641: + lEntityStylesheet
0642: .getNormalisedName()
0643: + "Key.getInstanceId();");
0644: lWriter
0645: .println(" if (lInstanceId == null)");
0646: lWriter
0647: .println(" throw new BOIllegalArgumentException(\""
0648: + lEntityStylesheet
0649: .getNormalisedName()
0650: + "Key.InstanceId parameter field can not be null when invoking get"
0651: + lEntityStylesheet
0652: .getDomainInterfaceName()
0653: + "() operation.\");");
0654: lWriter
0655: .println(" if (lInstanceId.isEmpty())");
0656: lWriter
0657: .println(" throw new BOIllegalArgumentException(\""
0658: + lEntityStylesheet
0659: .getNormalisedName()
0660: + "Key.InstanceId parameter field can not be empty when invoking get"
0661: + lEntityStylesheet
0662: .getDomainInterfaceName()
0663: + "() operation.\");");
0664: lWriter
0665: .println(" if (lInstanceId.isConcealed())");
0666: lWriter
0667: .println(" throw new BOIllegalArgumentException(\""
0668: + lEntityStylesheet
0669: .getNormalisedName()
0670: + "Key.InstanceId parameter field can not be concealed when invoking get"
0671: + lEntityStylesheet
0672: .getDomainInterfaceName()
0673: + "() operation.\");");
0674: lWriter
0675: .println(" return pDomain.get"
0676: + lEntityStylesheet
0677: .getNormalisedName()
0678: + "(lInstanceId);");
0679: }
0680: lWriter.println(" }");
0681: lWriter.println();
0682: lWriter
0683: .println(" /** Helper. Gets read-only instance of the Bo from the domain using details structure */");
0684: lWriter.println(" public static "
0685: + lEntityStylesheet
0686: .getDomainInterfaceFullName()
0687: + " get"
0688: + lEntityStylesheet
0689: .getDomainInterfaceName()
0690: + "( "
0691: + lDomainStylesheet
0692: .getDomainInterfaceFullName()
0693: + " pDomain, "
0694: + lEntityDetailsStructureStylesheet
0695: .getClassFullName()
0696: + " pDetails) throws BOException");
0697: lWriter.println(" {");
0698: if (lEntity.getPrimaryKeyElements().size() > 0) {
0699: lWriter
0700: .println(" "
0701: + lEntityInstanceIdDatatypeStylesheet
0702: .getClassFullName()
0703: + " lInstanceId = pDetails.getInstanceId();");
0704: lWriter
0705: .println(" if (lInstanceId != null)");
0706: lWriter.println(" {");
0707: lWriter
0708: .println(" if (lInstanceId.isEmpty())");
0709: lWriter
0710: .println(" throw new BOIllegalArgumentException(\"Details.InstanceId parameter field can not be empty when invoking get"
0711: + lEntityStylesheet
0712: .getDomainInterfaceName()
0713: + "() operation with the instance identifier.\");");
0714: lWriter
0715: .println(" if (lInstanceId.isConcealed())");
0716: lWriter
0717: .println(" throw new BOIllegalArgumentException(\"Details.InstanceId parameter field can not be concealed when invoking get"
0718: + lEntityStylesheet
0719: .getDomainInterfaceName()
0720: + "() operation with the instance identifier.\");");
0721: lWriter
0722: .println(" return pDomain.get"
0723: + lEntityStylesheet
0724: .getNormalisedName()
0725: + "(lInstanceId);");
0726: lWriter.println(" }");
0727: // At this stage we need to check that all elements of the primary key are present
0728: for (Iterator lPrimaryKeyElementsIterator = lPrimaryKeyElements
0729: .iterator(); lPrimaryKeyElementsIterator
0730: .hasNext();) {
0731: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
0732: .next();
0733: if (lPrimaryKeyElement instanceof Attribute) {
0734: Attribute lAttribute = (Attribute) lPrimaryKeyElement;
0735: STAttributeStylesheet lAttributeStylesheet = CodeGenerationStylesheetAccessor
0736: .getAttributeStylesheet(lAttribute);
0737: STDatatypeStylesheet lAttributeDatatypeStylesheet = CodeGenerationStylesheetAccessor
0738: .getDatatypeStylesheet(lAttribute
0739: .getDataType());
0740: lWriter
0741: .println(" "
0742: + lAttributeDatatypeStylesheet
0743: .getClassFullName()
0744: + " l"
0745: + lAttributeStylesheet
0746: .getNormalisedName()
0747: + " = pDetails.get"
0748: + lAttributeStylesheet
0749: .getNormalisedName()
0750: + "();");
0751: lWriter
0752: .println(" if (l"
0753: + lAttributeStylesheet
0754: .getNormalisedName()
0755: + " == null)");
0756: lWriter
0757: .println(" throw new BOIllegalArgumentException(\"Details."
0758: + lAttributeStylesheet
0759: .getNormalisedName()
0760: + " parameter field can not be null when invoking get"
0761: + lEntityStylesheet
0762: .getDomainInterfaceName()
0763: + "() operation with the primary key.\");");
0764: lWriter
0765: .println(" if (l"
0766: + lAttributeStylesheet
0767: .getNormalisedName()
0768: + ".isEmpty())");
0769: lWriter
0770: .println(" throw new BOIllegalArgumentException(\"Details."
0771: + lAttributeStylesheet
0772: .getNormalisedName()
0773: + " parameter field can not be empty when invoking get"
0774: + lEntityStylesheet
0775: .getDomainInterfaceName()
0776: + "() operation with the primary key.\");");
0777: lWriter
0778: .println(" if (l"
0779: + lAttributeStylesheet
0780: .getNormalisedName()
0781: + ".isConcealed())");
0782: lWriter
0783: .println(" throw new BOIllegalArgumentException(\"Details."
0784: + lAttributeStylesheet
0785: .getNormalisedName()
0786: + " parameter field can not be concealed when invoking get"
0787: + lEntityStylesheet
0788: .getDomainInterfaceName()
0789: + "() operation with the primary key.\");");
0790: } else if (lPrimaryKeyElement instanceof AssociationRole) {
0791: AssociationRole lRole = (AssociationRole) lPrimaryKeyElement;
0792: STAssociationRoleStylesheet lRoleStylesheet = CodeGenerationStylesheetAccessor
0793: .getAssociationRoleStylesheet(lRole);
0794: STEntityStylesheet lRoleEntityStylesheet = CodeGenerationStylesheetAccessor
0795: .getEntityStylesheet(lRole
0796: .getEntity());
0797: STStructureStylesheet lRoleEntityKeyStructureStylesheet = CodeGenerationStylesheetAccessor
0798: .getStructureStylesheet(pServicemodule
0799: .getStructure(lRoleEntityStylesheet
0800: .getServiceKeyStructureName()));
0801: lWriter
0802: .println(" "
0803: + lRoleEntityKeyStructureStylesheet
0804: .getClassFullName()
0805: + " l"
0806: + lRoleStylesheet
0807: .getNormalisedName()
0808: + "Key = pDetails.get"
0809: + lRoleStylesheet
0810: .getNormalisedName()
0811: + "();");
0812: lWriter
0813: .println(" if (l"
0814: + lRoleStylesheet
0815: .getNormalisedName()
0816: + "Key == null)");
0817: lWriter
0818: .println(" throw new BOIllegalArgumentException(\"Details."
0819: + lRoleStylesheet
0820: .getNormalisedName()
0821: + " parameter field can not be null when invoking get"
0822: + lEntityStylesheet
0823: .getDomainInterfaceName()
0824: + "() operation with the primary key.\");");
0825: lWriter
0826: .println(" "
0827: + lRoleEntityStylesheet
0828: .getDomainInterfaceFullName()
0829: + " l"
0830: + lRoleStylesheet
0831: .getNormalisedName()
0832: + " = "
0833: + lRoleEntityStylesheet
0834: .getServiceDetailsStructureTranslatorName()
0835: + ".get"
0836: + lRoleEntityStylesheet
0837: .getDomainInterfaceName()
0838: + "( pDomain, l"
0839: + lRoleStylesheet
0840: .getNormalisedName()
0841: + "Key);");
0842: }
0843: }
0844: lWriter.print(" return pDomain.get"
0845: + lEntityStylesheet
0846: .getNormalisedName() + "(");
0847: for (Iterator lPrimaryKeyElementsIterator = lPrimaryKeyElements
0848: .iterator(); lPrimaryKeyElementsIterator
0849: .hasNext();) {
0850: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
0851: .next();
0852: if (lPrimaryKeyElement instanceof Attribute) {
0853: Attribute lAttribute = (Attribute) lPrimaryKeyElement;
0854: STAttributeStylesheet lAttributeStylesheet = CodeGenerationStylesheetAccessor
0855: .getAttributeStylesheet(lAttribute);
0856: lWriter.print("l");
0857: lWriter.print(lAttributeStylesheet
0858: .getNormalisedName());
0859: }
0860: if (lPrimaryKeyElement instanceof AssociationRole) {
0861: AssociationRole lRole = (AssociationRole) lPrimaryKeyElement;
0862: STAssociationRoleStylesheet lRoleStylesheet = CodeGenerationStylesheetAccessor
0863: .getAssociationRoleStylesheet(lRole);
0864: lWriter.print("l");
0865: lWriter.print(lRoleStylesheet
0866: .getNormalisedName());
0867: }
0868: if (lPrimaryKeyElementsIterator
0869: .hasNext())
0870: lWriter.print(", ");
0871: else
0872: lWriter.println(");");
0873: }
0874: } else {
0875: lWriter
0876: .println(" "
0877: + lEntityInstanceIdDatatypeStylesheet
0878: .getClassFullName()
0879: + " lInstanceId = pDetails.getInstanceId();");
0880: lWriter
0881: .println(" if (lInstanceId == null)");
0882: lWriter
0883: .println(" throw new BOIllegalArgumentException(\"InstanceId field can not be null when invoking get"
0884: + lEntityStylesheet
0885: .getDomainInterfaceName()
0886: + "() operation.\");");
0887: lWriter
0888: .println(" if (lInstanceId.isEmpty())");
0889: lWriter
0890: .println(" throw new BOIllegalArgumentException(\"InstanceId field can not be empty when invoking get"
0891: + lEntityStylesheet
0892: .getDomainInterfaceName()
0893: + "() operation.\");");
0894: lWriter
0895: .println(" if (lInstanceId.isConcealed())");
0896: lWriter
0897: .println(" throw new BOIllegalArgumentException(\"InstanceId field can not be concealed when invoking get"
0898: + lEntityStylesheet
0899: .getDomainInterfaceName()
0900: + "() operation.\");");
0901: lWriter
0902: .println(" return pDomain.get"
0903: + lEntityStylesheet
0904: .getNormalisedName()
0905: + "(lInstanceId);");
0906: }
0907: lWriter.println(" }");
0908: }
0909: lWriter.println("}");
0910: } finally {
0911: if (lWriter != null) {
0912: lWriter.flush();
0913: lWriter.close();
0914: }
0915: if (lFileWriter != null) {
0916: try {
0917: lFileWriter.flush();
0918: } catch (IOException e) {
0919: // Ignore
0920: }
0921: try {
0922: lFileWriter.close();
0923: } catch (IOException e) {
0924: // Ignore
0925: }
0926: }
0927: }
0928: } catch (IOException e) {
0929: throw new BSException(
0930: "Unable to generate translator for the entity. EntityRef "
0931: + lEntity.getRef(), e);
0932: }
0933: }
0934: }
0935:
0936: // Generates source for the main implementation class
0937: private static void generateFactoryImplementationSource(
0938: String pImplementationDir,
0939: String pImplementationPackage,
0940: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System pSystem,
0941: Servicemodule pServicemodule, Service pService,
0942: Domain pDomain) throws BOException, BSException {
0943: FileWriter lFileWriter = null;
0944: PrintWriter lWriter = null;
0945: // Generate service interface
0946: try {
0947: // Retrieve stylesheet for the servicemodule
0948: STServiceStylesheet lServiceStylesheet = CodeGenerationStylesheetAccessor
0949: .getServiceStylesheet(pService);
0950: String lFileName = pImplementationDir
0951: + File.separator
0952: + lServiceStylesheet
0953: .getImplementationFactoryClassName()
0954: + ".java";
0955: lWriter = new PrintWriter(lFileWriter = new FileWriter(
0956: lFileName));
0957: CopyrightUtils.writeCopyrightToGeneratedJavaSource(lWriter);
0958: lWriter.println("package " + pImplementationPackage + ";");
0959: lWriter.println();
0960: lWriter.println("public class "
0961: + lServiceStylesheet
0962: .getImplementationFactoryClassName()
0963: + " implements javax.naming.spi.ObjectFactory");
0964: lWriter.println("{");
0965: lWriter
0966: .println(" private static Object sImplementationCreationSemaphore = new Object();");
0967: lWriter.println(" private static "
0968: + lServiceStylesheet.getImplementationClassName()
0969: + " sImplementation = null;");
0970:
0971: lWriter
0972: .println(" /* Returns the instance of the service */");
0973: lWriter
0974: .println(" public Object getObjectInstance(Object obj, javax.naming.Name name, javax.naming.Context nameCtx, java.util.Hashtable environment) throws Exception");
0975: lWriter.println(" {");
0976: lWriter
0977: .println(" // Thread safe singleton implementaton - can create once and use all the time");
0978: lWriter.println(" if (sImplementation == null)");
0979: lWriter.println(" {");
0980: lWriter
0981: .println(" synchronized(sImplementationCreationSemaphore)");
0982: lWriter.println(" {");
0983: lWriter
0984: .println(" if (sImplementation == null)");
0985: lWriter
0986: .println(" sImplementation = new "
0987: + lServiceStylesheet
0988: .getImplementationClassName()
0989: + "();");
0990: lWriter.println(" }");
0991: lWriter.println(" }");
0992: lWriter.println(" return sImplementation;");
0993: lWriter.println(" }");
0994: lWriter.println("}");
0995: } catch (IOException e) {
0996: throw new BSException(
0997: "Unable to generate implementation for the service. ServiceRef "
0998: + pService.getRef(), e);
0999: } finally {
1000: if (lWriter != null) {
1001: lWriter.flush();
1002: lWriter.close();
1003: }
1004: if (lFileWriter != null) {
1005: try {
1006: lFileWriter.flush();
1007: } catch (IOException e) {
1008: // Ignore
1009: }
1010: try {
1011: lFileWriter.close();
1012: } catch (IOException e) {
1013: // Ignore
1014: }
1015: }
1016: }
1017: }
1018:
1019: // Generates source for the main implementation class
1020: private static void generateMainImplementationSource(
1021: String pImplementationDir,
1022: String pImplementationPackage,
1023: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System pSystem,
1024: Servicemodule pServicemodule, Service pService,
1025: Domain pDomain) throws BOException, BSException {
1026: FileWriter lFileWriter = null;
1027: PrintWriter lWriter = null;
1028: // Generate service interface
1029: try {
1030: // Retrieve stylesheet for the servicemodule
1031: STDomainStylesheet lDomainStylesheet = CodeGenerationStylesheetAccessor
1032: .getDomainStylesheet(pDomain);
1033: STServiceStylesheet lServiceStylesheet = CodeGenerationStylesheetAccessor
1034: .getServiceStylesheet(pService);
1035: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
1036: .getServicemoduleStylesheet(pServicemodule);
1037: String lServiceImplementationFullName = pImplementationPackage
1038: + "."
1039: + lServiceStylesheet.getImplementationClassName();
1040:
1041: String lFileName = pImplementationDir + File.separator
1042: + lServiceStylesheet.getImplementationClassName()
1043: + ".java";
1044: lWriter = new PrintWriter(lFileWriter = new FileWriter(
1045: lFileName));
1046: CopyrightUtils.writeCopyrightToGeneratedJavaSource(lWriter);
1047: lWriter.println("package " + pImplementationPackage + ";");
1048: lWriter.println();
1049: lWriter
1050: .println("import com.metaboss.enterprise.bo.BOException;");
1051: lWriter
1052: .println("import com.metaboss.enterprise.bo.BORecordNotFoundException;");
1053: lWriter
1054: .println("import com.metaboss.enterprise.bs.BSException;");
1055: lWriter
1056: .println("import com.metaboss.enterprise.bs.BSIllegalArgumentException;");
1057: lWriter
1058: .println("import com.metaboss.enterprise.bs.BSDomainObjectInvocationException;");
1059: lWriter
1060: .println("import com.metaboss.enterprise.bs.BSUnexpectedProgramConditionException;");
1061: lWriter
1062: .println("import com.metaboss.enterprise.bs.BSTransactionServiceInvocationException;");
1063: lWriter
1064: .println("import com.metaboss.enterprise.bs.BSNamingAndDirectoryServiceInvocationException;");
1065: lWriter
1066: .println("import com.metaboss.enterprise.bs.impl.BSTransactionUtils;");
1067: lWriter.println("import "
1068: + lServiceStylesheet.getInterfaceFullName() + ";");
1069: lWriter.println();
1070: lWriter
1071: .println("/** Implementation of the administration service for the "
1072: + pDomain.getRef() + " domain */");
1073: lWriter.println("public class "
1074: + lServiceStylesheet.getImplementationClassName()
1075: + " implements "
1076: + lServiceStylesheet.getInterfaceName());
1077: lWriter.println("{");
1078: // Iterate through entities and generate all necessary methods
1079: Collection lEntities = pDomain.getEntities();
1080: for (Iterator lEntitiesIterator = lEntities.iterator(); lEntitiesIterator
1081: .hasNext();) {
1082: Entity lEntity = (Entity) lEntitiesIterator.next();
1083: STEntityStylesheet lEntityStylesheet = CodeGenerationStylesheetAccessor
1084: .getEntityStylesheet(lEntity);
1085: AssociationRole lOwnerReference = lEntity
1086: .getOwnerReference();
1087: STAssociationRoleStylesheet lOwnerReferenceStylesheet = lOwnerReference != null ? CodeGenerationStylesheetAccessor
1088: .getAssociationRoleStylesheet(lOwnerReference)
1089: : null;
1090: STEntityStylesheet lOwnerEntityStylesheet = lOwnerReference != null ? CodeGenerationStylesheetAccessor
1091: .getEntityStylesheet(lOwnerReference
1092: .getEntity())
1093: : null;
1094: Collection lCombinedReferences = lEntity
1095: .getCombinedReferences();
1096: Collection lCombinedAttributes = lEntity
1097: .getCombinedAttributes();
1098: boolean lCanBeOrdered = lEntity
1099: .getCombinedAttributesUsedForOrdering()
1100: .isEmpty() == false;
1101: DataType lOrderingInstructionsDataType = lCanBeOrdered ? lEntity
1102: .getOrderingInstructionDataType()
1103: : null;
1104: STDatatypeStylesheet lOrderingInstructionsDataTypeStylesheet = lCanBeOrdered ? CodeGenerationStylesheetAccessor
1105: .getDatatypeStylesheet(lOrderingInstructionsDataType)
1106: : null;
1107:
1108: // When instance is being loaded (gets and delete operations) instance not found message can be returned for this entity instance
1109: // and all primary key associations entities
1110: Set lEntitiesWhichMayBeNotFoundWhenLoadingInstance = new HashSet();
1111: {
1112: lEntitiesWhichMayBeNotFoundWhenLoadingInstance
1113: .add(lEntity);
1114: collectEntitiesWhichMayBeNotFoundWhenLoadingInstance(
1115: lEntity,
1116: lEntitiesWhichMayBeNotFoundWhenLoadingInstance);
1117: }
1118: // When instance is being created (create operations) instance not found message can be returned for
1119: // and all association roles for which this entity has reference. Note that this list
1120: // excludes the entity itself (unless there is a selfrefernce, because during create we do not attempt
1121: // to load the entity first (so it is impossible for it not to be found)
1122: Set lEntitiesWhichMayBeNotFoundWhenCreatingInstance = new HashSet();
1123: {
1124: collectEntitiesWhichMayBeNotFoundWhenUpdatingOrCreatingInstance(
1125: lEntity,
1126: lEntitiesWhichMayBeNotFoundWhenCreatingInstance);
1127: }
1128:
1129: // When instance is being updated (update operations) instance not found message can be returned for this entity instance
1130: // and all primary key associations entities as well as for all association roles, which might be supplied
1131: // Note that this list includes the entity itself because during update we look for the
1132: // entity first (so it is possible for it not to be found)
1133: Set lEntitiesWhichMayBeNotFoundWhenUpdatingInstance = new HashSet();
1134: {
1135: lEntitiesWhichMayBeNotFoundWhenUpdatingInstance
1136: .add(lEntity);
1137: collectEntitiesWhichMayBeNotFoundWhenUpdatingOrCreatingInstance(
1138: lEntity,
1139: lEntitiesWhichMayBeNotFoundWhenUpdatingInstance);
1140: }
1141:
1142: // Come up with plural name
1143: String lPluralName = lEntity.getPluralName();
1144: STStructureStylesheet lEntityDetailsStructureStylesheet = CodeGenerationStylesheetAccessor
1145: .getStructureStylesheet(pServicemodule
1146: .getStructure(lEntityStylesheet
1147: .getServiceDetailsStructureName()));
1148: STStructureStylesheet lEntityKeyStructureStylesheet = CodeGenerationStylesheetAccessor
1149: .getStructureStylesheet(pServicemodule
1150: .getStructure(lEntityStylesheet
1151: .getServiceKeyStructureName()));
1152: // getAll...Count method
1153: {
1154: String lOperationName = "getAll" + lPluralName
1155: + "Count";
1156: Operation lOperation = pService
1157: .getOperation(lOperationName);
1158: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
1159: .getOperationStylesheet(lOperation);
1160:
1161: lWriter.println(" /** "
1162: + lOperation.getDescription() + " */");
1163: lWriter.print(" public ");
1164: lWriter.print(lOperationStylesheet
1165: .getResultClassFullName());
1166: lWriter.print(" ");
1167: lWriter.print(lOperationStylesheet.getMethodName());
1168: lWriter.print("(");
1169: lWriter.print(lOperationStylesheet
1170: .getInputClassFullName());
1171: lWriter.println(" pInput) throws BSException");
1172: lWriter.println(" {");
1173: lWriter.println(" "
1174: + lOperationStylesheet
1175: .getResultClassFullName()
1176: + " lOperationResult = new "
1177: + lOperationStylesheet
1178: .getResultClassFullName() + "();");
1179: lWriter.println(" try");
1180: lWriter.println(" {");
1181: lWriter
1182: .println(" javax.naming.Context lContext = new javax.naming.InitialContext();");
1183: lWriter.println(" "
1184: + lDomainStylesheet
1185: .getDomainInterfaceFullName()
1186: + " lDomain = ("
1187: + lDomainStylesheet
1188: .getDomainInterfaceFullName()
1189: + ")lContext.lookup("
1190: + lDomainStylesheet
1191: .getDomainInterfaceFullName()
1192: + ".COMPONENT_URL);");
1193: lWriter.println(" lOperationResult.set"
1194: + lPluralName + "Count(lDomain.getAll"
1195: + lPluralName + "().size());");
1196: lWriter
1197: .println(" return lOperationResult;");
1198: lWriter.println(" }");
1199: lWriter
1200: .println(" catch (javax.naming.NamingException e)");
1201: lWriter.println(" {");
1202: lWriter
1203: .println(" throw new BSNamingAndDirectoryServiceInvocationException(\"Unable to complete "
1204: + lOperationName
1205: + " operation.\", e);");
1206: lWriter.println(" }");
1207: lWriter.println(" catch (BOException e)");
1208: lWriter.println(" {");
1209: lWriter
1210: .println(" throw new BSDomainObjectInvocationException(\"Unable to complete "
1211: + lOperationName
1212: + " operation.\", e);");
1213: lWriter.println(" }");
1214: lWriter.println(" }");
1215: }
1216: // getAll... method
1217: {
1218: String lOperationName = "getAll" + lPluralName;
1219: Operation lOperation = pService
1220: .getOperation(lOperationName);
1221: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
1222: .getOperationStylesheet(lOperation);
1223: lWriter.println(" /** "
1224: + lOperation.getDescription() + " */");
1225: lWriter.write(" public ");
1226: lWriter.write(lOperationStylesheet
1227: .getResultClassFullName());
1228: lWriter.write(" ");
1229: lWriter.write(lOperationStylesheet.getMethodName());
1230: lWriter.write("(");
1231: lWriter.write(lOperationStylesheet
1232: .getInputClassFullName());
1233: lWriter.write(" pInput) throws BSException\r\n");
1234: lWriter.println(" {");
1235: lWriter.println(" "
1236: + lOperationStylesheet
1237: .getResultClassFullName()
1238: + " lOperationResult = new "
1239: + lOperationStylesheet
1240: .getResultClassFullName() + "();");
1241: lWriter.println(" try");
1242: lWriter.println(" {");
1243: lWriter
1244: .println(" javax.naming.Context lContext = new javax.naming.InitialContext();");
1245: lWriter.println(" "
1246: + lDomainStylesheet
1247: .getDomainInterfaceFullName()
1248: + " lDomain = ("
1249: + lDomainStylesheet
1250: .getDomainInterfaceFullName()
1251: + ")lContext.lookup("
1252: + lDomainStylesheet
1253: .getDomainInterfaceFullName()
1254: + ".COMPONENT_URL);");
1255: lWriter
1256: .println(" "
1257: + lEntityStylesheet
1258: .getDomainCollectionInterfaceFullName()
1259: + " lCollection = lDomain.getAll"
1260: + lPluralName + "();");
1261: // Insert ordering code if necessary
1262: if (lCanBeOrdered) {
1263: lWriter
1264: .println(" "
1265: + lOrderingInstructionsDataTypeStylesheet
1266: .getClassFullName()
1267: + "[] lOrderingInstructions = pInput.getOrderingInstructions();");
1268: lWriter
1269: .println(" if (lOrderingInstructions != null && lOrderingInstructions.length > 0)");
1270: lWriter.println(" {");
1271: lWriter
1272: .println(" for (int i = 0; i < lOrderingInstructions.length; i++)");
1273: lWriter
1274: .println(" lCollection = lCollection.sort"
1275: + lPluralName
1276: + "(lOrderingInstructions[i]);");
1277: lWriter.println(" }");
1278: }
1279: lWriter.println(" "
1280: + lEntityStylesheet
1281: .getDomainInterfaceFullName()
1282: + "[] lEntities = lCollection.to"
1283: + lPluralName + "Array();");
1284: lWriter
1285: .println(" lOperationResult.set"
1286: + lPluralName
1287: + "( "
1288: + lEntityStylesheet
1289: .getServiceDetailsStructureTranslatorName()
1290: + ".convertToDetailsStructureArray(lEntities));");
1291: lWriter
1292: .println(" return lOperationResult;");
1293: lWriter.println(" }");
1294: lWriter
1295: .println(" catch (javax.naming.NamingException e)");
1296: lWriter.println(" {");
1297: lWriter
1298: .println(" throw new BSNamingAndDirectoryServiceInvocationException(\"Unable to complete "
1299: + lOperationName
1300: + " operation.\", e);");
1301: lWriter.println(" }");
1302: lWriter.println(" catch (BOException e)");
1303: lWriter.println(" {");
1304: lWriter
1305: .println(" throw new BSDomainObjectInvocationException(\"Unable to complete "
1306: + lOperationName
1307: + " operation.\", e);");
1308: lWriter.println(" }");
1309: lWriter.println(" }");
1310: }
1311: // getSubsetOf method
1312: {
1313: String lOperationName = "getSubsetOf" + lPluralName;
1314: Operation lOperation = pService
1315: .getOperation(lOperationName);
1316: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
1317: .getOperationStylesheet(lOperation);
1318: lWriter.println(" /** "
1319: + lOperation.getDescription() + " */");
1320: lWriter.write(" public ");
1321: lWriter.write(lOperationStylesheet
1322: .getResultClassFullName());
1323: lWriter.write(" ");
1324: lWriter.write(lOperationStylesheet.getMethodName());
1325: lWriter.write("(");
1326: lWriter.write(lOperationStylesheet
1327: .getInputClassFullName());
1328: lWriter.write(" pInput) throws BSException\r\n");
1329: lWriter.println(" {");
1330: lWriter.println(" "
1331: + lOperationStylesheet
1332: .getResultClassFullName()
1333: + " lOperationResult = new "
1334: + lOperationStylesheet
1335: .getResultClassFullName() + "();");
1336: lWriter.println(" try");
1337: lWriter.println(" {");
1338: lWriter
1339: .println(" javax.naming.Context lContext = new javax.naming.InitialContext();");
1340: lWriter.println(" "
1341: + lDomainStylesheet
1342: .getDomainInterfaceFullName()
1343: + " lDomain = ("
1344: + lDomainStylesheet
1345: .getDomainInterfaceFullName()
1346: + ")lContext.lookup("
1347: + lDomainStylesheet
1348: .getDomainInterfaceFullName()
1349: + ".COMPONENT_URL);");
1350: lWriter
1351: .println(" "
1352: + lEntityStylesheet
1353: .getDomainCollectionInterfaceFullName()
1354: + " lCollection = lDomain.getAll"
1355: + lPluralName + "();");
1356: // Insert ordering code if necessary
1357: if (lCanBeOrdered) {
1358: lWriter
1359: .println(" "
1360: + lOrderingInstructionsDataTypeStylesheet
1361: .getClassFullName()
1362: + "[] lOrderingInstructions = pInput.getOrderingInstructions();");
1363: lWriter
1364: .println(" if (lOrderingInstructions != null && lOrderingInstructions.length > 0)");
1365: lWriter.println(" {");
1366: lWriter
1367: .println(" for (int i = 0; i < lOrderingInstructions.length; i++)");
1368: lWriter
1369: .println(" lCollection = lCollection.sort"
1370: + lPluralName
1371: + "(lOrderingInstructions[i]);");
1372: lWriter.println(" }");
1373: }
1374: // Apply subset instruction last
1375: lWriter
1376: .println(" lCollection = lCollection.select"
1377: + lPluralName
1378: + "(pInput.getFirstRecordOffset(),pInput.getRequiredMaxSize());");
1379: lWriter.println(" "
1380: + lEntityStylesheet
1381: .getDomainInterfaceFullName()
1382: + "[] lEntities = lCollection.to"
1383: + lPluralName + "Array();");
1384: lWriter
1385: .println(" lOperationResult.set"
1386: + lPluralName
1387: + "( "
1388: + lEntityStylesheet
1389: .getServiceDetailsStructureTranslatorName()
1390: + ".convertToDetailsStructureArray(lEntities));");
1391: lWriter
1392: .println(" return lOperationResult;");
1393: lWriter.println(" }");
1394: lWriter
1395: .println(" catch (javax.naming.NamingException e)");
1396: lWriter.println(" {");
1397: lWriter
1398: .println(" throw new BSNamingAndDirectoryServiceInvocationException(\"Unable to complete "
1399: + lOperationName
1400: + " operation.\", e);");
1401: lWriter.println(" }");
1402: lWriter.println(" catch (BOException e)");
1403: lWriter.println(" {");
1404: lWriter
1405: .println(" throw new BSDomainObjectInvocationException(\"Unable to complete "
1406: + lOperationName
1407: + " operation.\", e);");
1408: lWriter.println(" }");
1409: lWriter.println(" }");
1410: }
1411: // Single instance access method
1412: {
1413: String lOperationName = "get"
1414: + lEntityStylesheet.getNormalisedName();
1415: Operation lOperation = pService
1416: .getOperation(lOperationName);
1417: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
1418: .getOperationStylesheet(lOperation);
1419: lWriter.println(" /** "
1420: + lOperation.getDescription() + " */");
1421: lWriter.println(" public "
1422: + lOperationStylesheet
1423: .getResultClassFullName()
1424: + " "
1425: + lOperationStylesheet.getMethodName()
1426: + "( "
1427: + lOperationStylesheet
1428: .getInputClassFullName()
1429: + " pInput) throws BSException");
1430: lWriter.println(" {");
1431: lWriter.println(" "
1432: + lOperationStylesheet
1433: .getResultClassFullName()
1434: + " lOperationResult = new "
1435: + lOperationStylesheet
1436: .getResultClassFullName() + "();");
1437: lWriter.println(" "
1438: + lEntityKeyStructureStylesheet
1439: .getClassFullName() + " l"
1440: + lEntityStylesheet.getNormalisedName()
1441: + "Key = pInput.get"
1442: + lEntityStylesheet.getNormalisedName()
1443: + "Key();");
1444: lWriter.println(" try");
1445: lWriter.println(" {");
1446: lWriter
1447: .println(" javax.naming.Context lContext = new javax.naming.InitialContext();");
1448: lWriter.println(" "
1449: + lDomainStylesheet
1450: .getDomainInterfaceFullName()
1451: + " lDomain = ("
1452: + lDomainStylesheet
1453: .getDomainInterfaceFullName()
1454: + ")lContext.lookup("
1455: + lDomainStylesheet
1456: .getDomainInterfaceFullName()
1457: + ".COMPONENT_URL);");
1458: lWriter
1459: .println(" "
1460: + lEntityStylesheet
1461: .getDomainInterfaceFullName()
1462: + " lEntity = "
1463: + lEntityStylesheet
1464: .getServiceDetailsStructureTranslatorName()
1465: + ".get"
1466: + lEntityStylesheet
1467: .getDomainInterfaceName()
1468: + "( lDomain, l"
1469: + lEntityStylesheet
1470: .getNormalisedName()
1471: + "Key);");
1472: lWriter
1473: .println(" lOperationResult.set"
1474: + lEntityStylesheet
1475: .getNormalisedName()
1476: + "( "
1477: + lEntityStylesheet
1478: .getServiceDetailsStructureTranslatorName()
1479: + ".convertToDetailsStructure(lEntity));");
1480: lWriter
1481: .println(" return lOperationResult;");
1482: lWriter.println(" }");
1483: lWriter
1484: .println(" catch (javax.naming.NamingException e)");
1485: lWriter.println(" {");
1486: lWriter
1487: .println(" throw new BSNamingAndDirectoryServiceInvocationException(\"Unable to complete "
1488: + lOperationName
1489: + " operation.\", e);");
1490: lWriter.println(" }");
1491: // We may have entity instances not found error (definitely will have at least our own)
1492: lWriter
1493: .println(" catch (BORecordNotFoundException e)");
1494: lWriter.println(" {");
1495: for (Iterator lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator = lEntitiesWhichMayBeNotFoundWhenLoadingInstance
1496: .iterator(); lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator
1497: .hasNext();) {
1498: Entity lEntityWhichMayNotBeFound = (Entity) lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator
1499: .next();
1500: STEntityStylesheet lEntityWhichMayNotBeFoundStylesheet = CodeGenerationStylesheetAccessor
1501: .getEntityStylesheet(lEntityWhichMayNotBeFound);
1502: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
1503: .getMessageStylesheet(pServicemodule
1504: .getMessage(lEntityWhichMayNotBeFoundStylesheet
1505: .getServiceInstanceNotFoundMessageName()));
1506: lWriter
1507: .println(" if (e.getRecordType().equals(\""
1508: + lEntityWhichMayNotBeFound
1509: .getRef() + "\"))");
1510: lWriter.println(" {");
1511: lWriter.println(" "
1512: + lMessageStylesheet.getClassFullName()
1513: + " lErrorMessage = new "
1514: + lMessageStylesheet.getClassFullName()
1515: + "();");
1516: lWriter
1517: .println(" lOperationResult.set"
1518: + lEntityWhichMayNotBeFound
1519: .getName()
1520: + "NotFoundError(lErrorMessage);");
1521: lWriter
1522: .println(" return lOperationResult;");
1523: lWriter.println(" }");
1524: }
1525: // Caught some unexpected exception. Looks very bad
1526: lWriter
1527: .println(" throw new BSUnexpectedProgramConditionException(\"Caught unexpected exception.\",e);");
1528: lWriter.println(" }");
1529: lWriter.println(" catch (BOException e)");
1530: lWriter.println(" {");
1531: lWriter
1532: .println(" throw new BSDomainObjectInvocationException(\"Unable to complete "
1533: + lOperationName
1534: + " operation.\", e);");
1535: lWriter.println(" }");
1536: lWriter.println(" }");
1537: }
1538:
1539: // Create instance operation for non-abstract entities only
1540: if (!lEntity.isAbstract()) {
1541: String lOperationName = "create"
1542: + lEntityStylesheet.getNormalisedName();
1543: Operation lOperation = pService
1544: .getOperation(lOperationName);
1545: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
1546: .getOperationStylesheet(lOperation);
1547: lWriter.println(" /** "
1548: + lOperation.getDescription() + " */");
1549: lWriter.println(" public "
1550: + lOperationStylesheet
1551: .getResultClassFullName()
1552: + " "
1553: + lOperationStylesheet.getMethodName()
1554: + "( "
1555: + lOperationStylesheet
1556: .getInputClassFullName()
1557: + " pInput) throws BSException");
1558: lWriter.println(" {");
1559: lWriter.println(" "
1560: + lOperationStylesheet
1561: .getResultClassFullName()
1562: + " lOperationResult = new "
1563: + lOperationStylesheet
1564: .getResultClassFullName() + "();");
1565: lWriter
1566: .println(" "
1567: + lEntityDetailsStructureStylesheet
1568: .getClassFullName()
1569: + " lProposedDetails = pInput.getProposedDetails();");
1570: lWriter.println(" try");
1571: lWriter.println(" {");
1572: lWriter
1573: .println(" javax.naming.Context lContext = new javax.naming.InitialContext();");
1574: lWriter.println(" "
1575: + lDomainStylesheet
1576: .getDomainInterfaceFullName()
1577: + " lDomain = ("
1578: + lDomainStylesheet
1579: .getDomainInterfaceFullName()
1580: + ")lContext.lookup("
1581: + lDomainStylesheet
1582: .getDomainInterfaceFullName()
1583: + ".COMPONENT_URL);");
1584: lWriter.println(" lDomain.beginEdit();"); // Need to consider implicit joining of the objects to transaction (this would get rid of beginEdit())
1585: // See if we need to get an owner to create this entity
1586: if (lOwnerReference != null) {
1587: AssociationRole lChildAssociationRole = lOwnerReference
1588: .getOppositeRole();
1589: lWriter
1590: .println(" "
1591: + lOwnerEntityStylesheet
1592: .getDomainInterfaceFullName()
1593: + " lOwnerEntity = "
1594: + lOwnerEntityStylesheet
1595: .getServiceDetailsStructureTranslatorName()
1596: + ".get"
1597: + lOwnerEntityStylesheet
1598: .getDomainInterfaceName()
1599: + "( lDomain, lProposedDetails.get"
1600: + lOwnerReferenceStylesheet
1601: .getNormalisedName()
1602: + "());");
1603: // Different create method if this entity is directly owned by owner
1604: // or it is a subtype of the entity owned by owner
1605: if (lEntity.getReferences().contains(
1606: lOwnerReference))
1607: lWriter
1608: .println(" "
1609: + lEntityStylesheet
1610: .getDomainInterfaceFullName()
1611: + " lEntity = lOwnerEntity.create"
1612: + lChildAssociationRole
1613: .getName()
1614: + "("
1615: + generatePrimaryKeyArgumentsForCreateEntityMethodInvocation(lEntity)
1616: + ");");
1617: else
1618: lWriter
1619: .println(" "
1620: + lEntityStylesheet
1621: .getDomainInterfaceFullName()
1622: + " lEntity = lOwnerEntity.create"
1623: + lChildAssociationRole
1624: .getName()
1625: + "As"
1626: + lEntityStylesheet
1627: .getNormalisedName()
1628: + "("
1629: + generatePrimaryKeyArgumentsForCreateEntityMethodInvocation(lEntity)
1630: + ");");
1631: } else {
1632: lWriter
1633: .println(" "
1634: + lEntityStylesheet
1635: .getDomainInterfaceFullName()
1636: + " lEntity = lDomain.create"
1637: + lEntityStylesheet
1638: .getNormalisedName()
1639: + "("
1640: + generatePrimaryKeyArgumentsForCreateEntityMethodInvocation(lEntity)
1641: + ");");
1642: }
1643: // Now work on all attributes, which are not part of the primary key
1644: for (Iterator lCombinedAttributesIterator = lCombinedAttributes
1645: .iterator(); lCombinedAttributesIterator
1646: .hasNext();) {
1647: Attribute lAttribute = (Attribute) lCombinedAttributesIterator
1648: .next();
1649: // We can only modify attributes which are not part of system id or primary key
1650: if (!lAttribute.isPartOfPrimaryKey(lEntity)) {
1651: STAttributeStylesheet lAttributeStylesheet = CodeGenerationStylesheetAccessor
1652: .getAttributeStylesheet(lAttribute);
1653: AttributeStereotype lAttrStereotype = lAttribute
1654: .getStereotype();
1655: // Sets are only applicable to stereotypes of Mandatory and Optional
1656: if (lAttrStereotype
1657: .equals(AttributeStereotypeEnum.MANDATORY)
1658: || lAttrStereotype
1659: .equals(AttributeStereotypeEnum.OPTIONAL)) {
1660: lWriter
1661: .println(" if (lProposedDetails.get"
1662: + lAttributeStylesheet
1663: .getNormalisedName()
1664: + "() != null)");
1665: lWriter
1666: .println(" lEntity.set"
1667: + lAttributeStylesheet
1668: .getNormalisedName()
1669: + "(lProposedDetails.get"
1670: + lAttributeStylesheet
1671: .getNormalisedName()
1672: + "());");
1673: }
1674: }
1675: }
1676: for (Iterator lCombinedReferencesIterator = lCombinedReferences
1677: .iterator(); lCombinedReferencesIterator
1678: .hasNext();) {
1679: AssociationRole lReference = (AssociationRole) lCombinedReferencesIterator
1680: .next();
1681: if (lReference.equals(lOwnerReference) == false
1682: && // Not an owner
1683: lReference.isPartOfPrimaryKey(lEntity) == false
1684: && // Not a part of primary key
1685: lReference.isPlural() == false && // Singular
1686: lReference
1687: .getOppositeRole()
1688: .getAggregationType()
1689: .equals(
1690: AggregationTypeEnum.AGGREGATION) == true) // Aggregation is on our side
1691: {
1692: STAssociationRoleStylesheet lRoleStylesheet = CodeGenerationStylesheetAccessor
1693: .getAssociationRoleStylesheet(lReference);
1694: STEntityStylesheet lRoleEntityStylesheet = CodeGenerationStylesheetAccessor
1695: .getEntityStylesheet(lReference
1696: .getEntity());
1697: lWriter
1698: .println(" if (lProposedDetails.get"
1699: + lRoleStylesheet
1700: .getNormalisedName()
1701: + "() != null && lProposedDetails.get"
1702: + lRoleStylesheet
1703: .getNormalisedName()
1704: + "().isEmpty() == false)");
1705: lWriter
1706: .println(" lEntity.set"
1707: + lRoleStylesheet
1708: .getNormalisedName()
1709: + "("
1710: + lRoleEntityStylesheet
1711: .getServiceDetailsStructureTranslatorName()
1712: + ".get"
1713: + lRoleEntityStylesheet
1714: .getDomainInterfaceName()
1715: + "( lDomain, lProposedDetails.get"
1716: + lRoleStylesheet
1717: .getNormalisedName()
1718: + "()));");
1719: }
1720: }
1721: lWriter
1722: .println(" lOperationResult.setCreatedDetails( "
1723: + lEntityStylesheet
1724: .getServiceDetailsStructureTranslatorName()
1725: + ".convertToDetailsStructure(lEntity));");
1726: lWriter
1727: .println(" return lOperationResult;");
1728: lWriter.println(" }");
1729: lWriter
1730: .println(" catch (javax.naming.NamingException e)");
1731: lWriter.println(" {");
1732: lWriter
1733: .println(" throw new BSNamingAndDirectoryServiceInvocationException(\"Unable to complete "
1734: + lOperationName
1735: + " operation.\", e);");
1736: lWriter.println(" }");
1737:
1738: // We may have entity instances not found error
1739: if (!lEntitiesWhichMayBeNotFoundWhenCreatingInstance
1740: .isEmpty()) {
1741: lWriter
1742: .println(" catch (BORecordNotFoundException e)");
1743: lWriter.println(" {");
1744: for (Iterator lEntitiesWhichMayBeNotFoundWhenCreatingInstanceIterator = lEntitiesWhichMayBeNotFoundWhenCreatingInstance
1745: .iterator(); lEntitiesWhichMayBeNotFoundWhenCreatingInstanceIterator
1746: .hasNext();) {
1747: Entity lEntityWhichMayNotBeFound = (Entity) lEntitiesWhichMayBeNotFoundWhenCreatingInstanceIterator
1748: .next();
1749: STEntityStylesheet lEntityWhichMayNotBeFoundStylesheet = CodeGenerationStylesheetAccessor
1750: .getEntityStylesheet(lEntityWhichMayNotBeFound);
1751: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
1752: .getMessageStylesheet(pServicemodule
1753: .getMessage(lEntityWhichMayNotBeFoundStylesheet
1754: .getServiceInstanceNotFoundMessageName()));
1755: lWriter
1756: .println(" if (e.getRecordType().equals(\""
1757: + lEntityWhichMayNotBeFound
1758: .getRef() + "\"))");
1759: lWriter.println(" {");
1760: lWriter
1761: .println(" "
1762: + lMessageStylesheet
1763: .getClassFullName()
1764: + " lErrorMessage = new "
1765: + lMessageStylesheet
1766: .getClassFullName()
1767: + "();");
1768: lWriter
1769: .println(" lOperationResult.set"
1770: + lEntityWhichMayNotBeFound
1771: .getName()
1772: + "NotFoundError(lErrorMessage);");
1773: lWriter
1774: .println(" BSTransactionUtils.markCurrentTransactionForRollback();");
1775: lWriter
1776: .println(" return lOperationResult;");
1777: lWriter.println(" }");
1778: }
1779: // Caught some unexpected exception. Looks very bad
1780: lWriter
1781: .println(" throw new BSUnexpectedProgramConditionException(\"Caught unexpected exception.\",e);");
1782: lWriter.println(" }");
1783: }
1784: lWriter.println(" catch (BOException e)");
1785: lWriter.println(" {");
1786: lWriter
1787: .println(" throw new BSDomainObjectInvocationException(\"Unable to complete "
1788: + lOperationName
1789: + " operation.\", e);");
1790: lWriter.println(" }");
1791: lWriter.println(" }");
1792: }
1793:
1794: // Generate update operation for entities which need it
1795: if (lEntity.isModifiable()) {
1796: String lOperationName = "update"
1797: + lEntityStylesheet.getNormalisedName();
1798: Operation lOperation = pService
1799: .getOperation(lOperationName);
1800: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
1801: .getOperationStylesheet(lOperation);
1802: STMessageStylesheet lVersionMismatchMessageStylesheet = CodeGenerationStylesheetAccessor
1803: .getMessageStylesheet(pServicemodule
1804: .getMessage(lEntityStylesheet
1805: .getServiceVersionMismatchMessageName()));
1806:
1807: lWriter.println(" /** "
1808: + lOperation.getDescription() + " */");
1809: lWriter.println(" public "
1810: + lOperationStylesheet
1811: .getResultClassFullName()
1812: + " "
1813: + lOperationStylesheet.getMethodName()
1814: + "( "
1815: + lOperationStylesheet
1816: .getInputClassFullName()
1817: + " pInput) throws BSException");
1818: lWriter.println(" {");
1819: lWriter.println(" "
1820: + lOperationStylesheet
1821: .getResultClassFullName()
1822: + " lOperationResult = new "
1823: + lOperationStylesheet
1824: .getResultClassFullName() + "();");
1825: lWriter
1826: .println(" "
1827: + lEntityDetailsStructureStylesheet
1828: .getClassFullName()
1829: + " lProposedDetails = pInput.getProposedDetails();");
1830: lWriter.println(" try");
1831: lWriter.println(" {");
1832: lWriter
1833: .println(" javax.naming.Context lContext = new javax.naming.InitialContext();");
1834: lWriter.println(" "
1835: + lDomainStylesheet
1836: .getDomainInterfaceFullName()
1837: + " lDomain = ("
1838: + lDomainStylesheet
1839: .getDomainInterfaceFullName()
1840: + ")lContext.lookup("
1841: + lDomainStylesheet
1842: .getDomainInterfaceFullName()
1843: + ".COMPONENT_URL);");
1844: lWriter.println(" lDomain.beginEdit();"); // Need to consider implicit joining of the objects to transaction (this would get rid of beginEdit())
1845: lWriter
1846: .println(" "
1847: + lEntityStylesheet
1848: .getDomainInterfaceFullName()
1849: + " lEntity = "
1850: + lEntityStylesheet
1851: .getServiceDetailsStructureTranslatorName()
1852: + ".get"
1853: + lEntityStylesheet
1854: .getDomainInterfaceName()
1855: + "( lDomain, lProposedDetails);");
1856: // Check version if able to do so
1857: lWriter
1858: .println(" if (lProposedDetails.get"
1859: + lEntityStylesheet
1860: .getVersionIdServiceStructureAttributeName()
1861: + "() != null && lProposedDetails.get"
1862: + lEntityStylesheet
1863: .getVersionIdServiceStructureAttributeName()
1864: + "().equals(lEntity.get"
1865: + lEntityStylesheet
1866: .getVersionIdDomainObjectAttributeName()
1867: + "()) == false)");
1868: lWriter.println(" {");
1869: lWriter.println(" "
1870: + lVersionMismatchMessageStylesheet
1871: .getClassFullName()
1872: + " lErrorMessage = new "
1873: + lVersionMismatchMessageStylesheet
1874: .getClassFullName() + "();");
1875: lWriter
1876: .println(" lErrorMessage.setExpectedVersionId(lProposedDetails.get"
1877: + lEntityStylesheet
1878: .getVersionIdServiceStructureAttributeName()
1879: + "());");
1880: lWriter
1881: .println(" lErrorMessage.setStoredVersionId(lEntity.get"
1882: + lEntityStylesheet
1883: .getVersionIdDomainObjectAttributeName()
1884: + "());");
1885: lWriter
1886: .println(" lOperationResult.setVersionMismatchError(lErrorMessage);");
1887: lWriter
1888: .println(" BSTransactionUtils.markCurrentTransactionForRollback();");
1889: lWriter
1890: .println(" return lOperationResult;");
1891: lWriter.println(" }");
1892: lWriter.println(" lEntity.beginEdit();"); // Need to get rid of theese
1893: // Work on state if there is one
1894: if (lEntity.getStateMachine() != null) {
1895: lWriter
1896: .println(" if (lProposedDetails.get"
1897: + lEntityStylesheet
1898: .getStateServiceStructureAttributeName()
1899: + "() != null)");
1900: lWriter
1901: .println(" lEntity.set"
1902: + lEntityStylesheet
1903: .getStateDomainObjectAttributeName()
1904: + "(lProposedDetails.get"
1905: + lEntityStylesheet
1906: .getStateServiceStructureAttributeName()
1907: + "());");
1908: }
1909: // Go through all attributes and update them if necessary
1910: for (Iterator lCombinedAttributesIterator = lCombinedAttributes
1911: .iterator(); lCombinedAttributesIterator
1912: .hasNext();) {
1913: Attribute lAttribute = (Attribute) lCombinedAttributesIterator
1914: .next();
1915: // We can only modify attributes which are not part of system id or primary key
1916: if (!lAttribute.isPartOfPrimaryKey(lEntity)) {
1917: AttributeStereotype lAttrStereotype = lAttribute
1918: .getStereotype();
1919: // Sets are only applicable to stereotypes of Mandatory and Optional
1920: if (lAttrStereotype
1921: .equals(AttributeStereotypeEnum.MANDATORY)
1922: || lAttrStereotype
1923: .equals(AttributeStereotypeEnum.OPTIONAL)) {
1924: STAttributeStylesheet lAttributeStylesheet = CodeGenerationStylesheetAccessor
1925: .getAttributeStylesheet(lAttribute);
1926: lWriter
1927: .println(" if (lProposedDetails.get"
1928: + lAttributeStylesheet
1929: .getNormalisedName()
1930: + "() != null)");
1931: lWriter
1932: .println(" lEntity.set"
1933: + lAttributeStylesheet
1934: .getNormalisedName()
1935: + "(lProposedDetails.get"
1936: + lAttributeStylesheet
1937: .getNormalisedName()
1938: + "());");
1939: }
1940: }
1941: }
1942: for (Iterator lCombinedReferencesIterator = lCombinedReferences
1943: .iterator(); lCombinedReferencesIterator
1944: .hasNext();) {
1945: AssociationRole lRole = (AssociationRole) lCombinedReferencesIterator
1946: .next();
1947: if (lRole.equals(lOwnerReference) == false
1948: && // Not an owner
1949: lRole.isPartOfPrimaryKey(lEntity) == false
1950: && // Not a part of primary key
1951: lRole.isPlural() == false && // Singular
1952: lRole
1953: .getOppositeRole()
1954: .getAggregationType()
1955: .equals(
1956: AggregationTypeEnum.AGGREGATION) == true) // Aggregation is on our side
1957: {
1958: STAssociationRoleStylesheet lRoleStylesheet = CodeGenerationStylesheetAccessor
1959: .getAssociationRoleStylesheet(lRole);
1960: STEntityStylesheet lRoleEntityStylesheet = CodeGenerationStylesheetAccessor
1961: .getEntityStylesheet(lRole
1962: .getEntity());
1963: lWriter
1964: .println(" if (lProposedDetails.get"
1965: + lRoleStylesheet
1966: .getNormalisedName()
1967: + "() != null)");
1968: lWriter.println(" {");
1969: lWriter
1970: .println(" if (!lProposedDetails.get"
1971: + lRoleStylesheet
1972: .getNormalisedName()
1973: + "().isEmpty())");
1974: lWriter
1975: .println(" lEntity.set"
1976: + lRoleStylesheet
1977: .getNormalisedName()
1978: + "("
1979: + lRoleEntityStylesheet
1980: .getServiceDetailsStructureTranslatorName()
1981: + ".get"
1982: + lRoleEntityStylesheet
1983: .getDomainInterfaceName()
1984: + "( lDomain, lProposedDetails.get"
1985: + lRoleStylesheet
1986: .getNormalisedName()
1987: + "()));");
1988: lWriter.println(" else");
1989: if (lRole.isOptional())
1990: lWriter
1991: .println(" lEntity.clear"
1992: + lRoleStylesheet
1993: .getNormalisedName()
1994: + "();");
1995: else
1996: lWriter
1997: .println(" throw new BSIllegalArgumentException(\"The "
1998: + lRoleStylesheet
1999: .getNormalisedName()
2000: + " field can not be empty for the "
2001: + lOperationName
2002: + "() operation.\");");
2003: lWriter.println(" }");
2004: }
2005: }
2006: lWriter
2007: .println(" lOperationResult.setUpdatedDetails( "
2008: + lEntityStylesheet
2009: .getServiceDetailsStructureTranslatorName()
2010: + ".convertToDetailsStructure(lEntity));");
2011: lWriter
2012: .println(" return lOperationResult;");
2013: lWriter.println(" }");
2014: lWriter
2015: .println(" catch (javax.naming.NamingException e)");
2016: lWriter.println(" {");
2017: lWriter
2018: .println(" throw new BSNamingAndDirectoryServiceInvocationException(\"Unable to complete "
2019: + lOperationName
2020: + " operation.\", e);");
2021: lWriter.println(" }");
2022: // We may have entity instances not found error (definitely will have at least our own)
2023: lWriter
2024: .println(" catch (BORecordNotFoundException e)");
2025: lWriter.println(" {");
2026: for (Iterator lEntitiesWhichMayBeNotFoundWhenUpdatingInstanceIterator = lEntitiesWhichMayBeNotFoundWhenUpdatingInstance
2027: .iterator(); lEntitiesWhichMayBeNotFoundWhenUpdatingInstanceIterator
2028: .hasNext();) {
2029: Entity lEntityWhichMayNotBeFound = (Entity) lEntitiesWhichMayBeNotFoundWhenUpdatingInstanceIterator
2030: .next();
2031: STEntityStylesheet lEntityWhichMayNotBeFoundStylesheet = CodeGenerationStylesheetAccessor
2032: .getEntityStylesheet(lEntityWhichMayNotBeFound);
2033: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
2034: .getMessageStylesheet(pServicemodule
2035: .getMessage(lEntityWhichMayNotBeFoundStylesheet
2036: .getServiceInstanceNotFoundMessageName()));
2037: lWriter
2038: .println(" if (e.getRecordType().equals(\""
2039: + lEntityWhichMayNotBeFound
2040: .getRef() + "\"))");
2041: lWriter.println(" {");
2042: lWriter.println(" "
2043: + lMessageStylesheet.getClassFullName()
2044: + " lErrorMessage = new "
2045: + lMessageStylesheet.getClassFullName()
2046: + "();");
2047: lWriter
2048: .println(" lOperationResult.set"
2049: + lEntityWhichMayNotBeFound
2050: .getName()
2051: + "NotFoundError(lErrorMessage);");
2052: lWriter
2053: .println(" BSTransactionUtils.markCurrentTransactionForRollback();");
2054: lWriter
2055: .println(" return lOperationResult;");
2056: lWriter.println(" }");
2057: }
2058: // Caught some unexpected exception. Looks very bad
2059: lWriter
2060: .println(" throw new BSUnexpectedProgramConditionException(\"Caught unexpected exception.\",e);");
2061: lWriter.println(" }");
2062: lWriter.println(" catch (BOException e)");
2063: lWriter.println(" {");
2064: lWriter
2065: .println(" throw new BSDomainObjectInvocationException(\"Unable to complete "
2066: + lOperationName
2067: + " operation.\", e);");
2068: lWriter.println(" }");
2069: lWriter.println(" }");
2070: }
2071: // Now generate delete operation
2072: {
2073: String lOperationName = "delete"
2074: + lEntityStylesheet.getNormalisedName();
2075: Operation lOperation = pService
2076: .getOperation(lOperationName);
2077: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
2078: .getOperationStylesheet(lOperation);
2079: lWriter.println(" /** "
2080: + lOperation.getDescription() + " */");
2081: lWriter.println(" public "
2082: + lOperationStylesheet
2083: .getResultClassFullName()
2084: + " "
2085: + lOperationStylesheet.getMethodName()
2086: + "( "
2087: + lOperationStylesheet
2088: .getInputClassFullName()
2089: + " pInput) throws BSException");
2090: lWriter.println(" {");
2091: lWriter.println(" "
2092: + lOperationStylesheet
2093: .getResultClassFullName()
2094: + " lOperationResult = new "
2095: + lOperationStylesheet
2096: .getResultClassFullName() + "();");
2097: lWriter.println(" "
2098: + lEntityKeyStructureStylesheet
2099: .getClassFullName() + " l"
2100: + lEntityStylesheet.getNormalisedName()
2101: + "Key = pInput.get"
2102: + lEntityStylesheet.getNormalisedName()
2103: + "Key();");
2104: lWriter.println(" try");
2105: lWriter.println(" {");
2106: lWriter
2107: .println(" javax.naming.Context lContext = new javax.naming.InitialContext();");
2108: lWriter.println(" "
2109: + lDomainStylesheet
2110: .getDomainInterfaceFullName()
2111: + " lDomain = ("
2112: + lDomainStylesheet
2113: .getDomainInterfaceFullName()
2114: + ")lContext.lookup("
2115: + lDomainStylesheet
2116: .getDomainInterfaceFullName()
2117: + ".COMPONENT_URL);");
2118: lWriter.println(" lDomain.beginEdit();"); // Need to consider implicit joining of the objects to transaction (this would get rid of beginEdit())
2119: lWriter
2120: .println(" "
2121: + lEntityStylesheet
2122: .getDomainInterfaceFullName()
2123: + " lEntity = "
2124: + lEntityStylesheet
2125: .getServiceDetailsStructureTranslatorName()
2126: + ".get"
2127: + lEntityStylesheet
2128: .getDomainInterfaceName()
2129: + "( lDomain, l"
2130: + lEntityStylesheet
2131: .getNormalisedName()
2132: + "Key);");
2133: lWriter.println(" lEntity.delete();");
2134: lWriter
2135: .println(" return lOperationResult;");
2136: lWriter.println(" }");
2137: lWriter
2138: .println(" catch (javax.naming.NamingException e)");
2139: lWriter.println(" {");
2140: lWriter
2141: .println(" throw new BSNamingAndDirectoryServiceInvocationException(\"Unable to complete "
2142: + lOperationName
2143: + " operation.\", e);");
2144: lWriter.println(" }");
2145: // We may have entity instances not found error (definitely will have at least our own)
2146: lWriter
2147: .println(" catch (BORecordNotFoundException e)");
2148: lWriter.println(" {");
2149: for (Iterator lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator = lEntitiesWhichMayBeNotFoundWhenLoadingInstance
2150: .iterator(); lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator
2151: .hasNext();) {
2152: Entity lEntityWhichMayNotBeFound = (Entity) lEntitiesWhichMayBeNotFoundWhenLoadingInstanceIterator
2153: .next();
2154: STEntityStylesheet lEntityWhichMayNotBeFoundStylesheet = CodeGenerationStylesheetAccessor
2155: .getEntityStylesheet(lEntityWhichMayNotBeFound);
2156: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
2157: .getMessageStylesheet(pServicemodule
2158: .getMessage(lEntityWhichMayNotBeFoundStylesheet
2159: .getServiceInstanceNotFoundMessageName()));
2160: lWriter
2161: .println(" if (e.getRecordType().equals(\""
2162: + lEntityWhichMayNotBeFound
2163: .getRef() + "\"))");
2164: lWriter.println(" {");
2165: lWriter.println(" "
2166: + lMessageStylesheet.getClassFullName()
2167: + " lErrorMessage = new "
2168: + lMessageStylesheet.getClassFullName()
2169: + "();");
2170: lWriter
2171: .println(" lOperationResult.set"
2172: + lEntityWhichMayNotBeFound
2173: .getName()
2174: + "NotFoundError(lErrorMessage);");
2175: lWriter
2176: .println(" return lOperationResult;");
2177: lWriter.println(" }");
2178: }
2179: // Caught some unexpected exception. Looks very bad
2180: lWriter
2181: .println(" throw new BSUnexpectedProgramConditionException(\"Caught unexpected exception.\",e);");
2182: lWriter.println(" }");
2183: lWriter.println(" catch (BOException e)");
2184: lWriter.println(" {");
2185: lWriter
2186: .println(" throw new BSDomainObjectInvocationException(\"Unable to complete "
2187: + lOperationName
2188: + " operation.\", e);");
2189: lWriter.println(" }");
2190: lWriter.println(" }");
2191: }
2192: }
2193: // Iterate through associations and generate all necessary methods for many to many associations
2194: Collection lAssociations = pDomain.getAssociations();
2195: for (Iterator lAssociationsIterator = lAssociations
2196: .iterator(); lAssociationsIterator.hasNext();) {
2197: Association lAssociation = (Association) lAssociationsIterator
2198: .next();
2199: if (!CommonUtil.doEntitiesStoreReference(lAssociation)) {
2200: // Find a aggregator side, so we can name the method correctly
2201: List lAssociataionRoles = lAssociation.getRoles();
2202: AssociationRole lAssociationRoleA = (AssociationRole) lAssociataionRoles
2203: .get(0);
2204: AssociationRole lAssociationRoleB = (AssociationRole) lAssociataionRoles
2205: .get(1);
2206: AssociationRole lAggregatorRole = lAssociationRoleA
2207: .getAggregationType().equals(
2208: AggregationTypeEnum.AGGREGATION) ? lAssociationRoleA
2209: : lAssociationRoleB;
2210: AssociationRole lAggregateeRole = lAggregatorRole
2211: .getOppositeRole();
2212: String lAggregateeRolePluralName = lAggregateeRole
2213: .getPluralName();
2214: Entity lAggregatorEntity = lAggregatorRole
2215: .getEntity();
2216: STEntityStylesheet lAggregatorEntityStylesheet = CodeGenerationStylesheetAccessor
2217: .getEntityStylesheet(lAggregatorEntity);
2218: STStructureStylesheet lAggregatorKeyStructureStylesheet = CodeGenerationStylesheetAccessor
2219: .getStructureStylesheet(pServicemodule
2220: .getStructure(lAggregatorEntityStylesheet
2221: .getServiceKeyStructureName()));
2222: Entity lAggregateeEntity = lAggregateeRole
2223: .getEntity();
2224: STEntityStylesheet lAggregateeEntityStylesheet = CodeGenerationStylesheetAccessor
2225: .getEntityStylesheet(lAggregateeEntity);
2226: STStructureStylesheet lAggregateeKeyStructureStylesheet = CodeGenerationStylesheetAccessor
2227: .getStructureStylesheet(pServicemodule
2228: .getStructure(lAggregateeEntityStylesheet
2229: .getServiceKeyStructureName()));
2230:
2231: // When associations get modified (add or remove associated entity) we need to load instances of the aggregator and agregatee
2232: // both of them have a chance not to be found. We need to add relevant output mesages in the output specification
2233: Set lEntitiesWhichMayBeNotFoundWhenModifyingAssociation = new HashSet();
2234: {
2235: lEntitiesWhichMayBeNotFoundWhenModifyingAssociation
2236: .add(lAggregatorEntity);
2237: collectEntitiesWhichMayBeNotFoundWhenLoadingInstance(
2238: lAggregatorEntity,
2239: lEntitiesWhichMayBeNotFoundWhenModifyingAssociation);
2240: lEntitiesWhichMayBeNotFoundWhenModifyingAssociation
2241: .add(lAggregateeEntity);
2242: collectEntitiesWhichMayBeNotFoundWhenLoadingInstance(
2243: lAggregateeEntity,
2244: lEntitiesWhichMayBeNotFoundWhenModifyingAssociation);
2245: }
2246: // When associations get read we need to load instances of the aggregator
2247: // and there is a chance it may not be found. We need to add relevant output mesages in the output specification
2248: Set lEntitiesWhichMayBeNotFoundWhenLoadingAssociation = new HashSet();
2249: {
2250: lEntitiesWhichMayBeNotFoundWhenLoadingAssociation
2251: .add(lAggregatorEntity);
2252: collectEntitiesWhichMayBeNotFoundWhenLoadingInstance(
2253: lAggregatorEntity,
2254: lEntitiesWhichMayBeNotFoundWhenLoadingAssociation);
2255: }
2256:
2257: // Generate add operation
2258: {
2259: String lOperationName = "add"
2260: + lAggregateeRolePluralName
2261: + "To"
2262: + lAggregatorEntityStylesheet
2263: .getNormalisedName();
2264: Operation lOperation = pService
2265: .getOperation(lOperationName);
2266: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
2267: .getOperationStylesheet(lOperation);
2268: lWriter.println();
2269: lWriter.println(" /** "
2270: + lOperation.getDescription() + " */");
2271: lWriter.println(" public "
2272: + lOperationStylesheet
2273: .getResultClassFullName()
2274: + " "
2275: + lOperationStylesheet.getMethodName()
2276: + "( "
2277: + lOperationStylesheet
2278: .getInputClassFullName()
2279: + " pInput) throws BSException");
2280: lWriter.println(" {");
2281: lWriter.println(" "
2282: + lOperationStylesheet
2283: .getResultClassFullName()
2284: + " lOperationResult = new "
2285: + lOperationStylesheet
2286: .getResultClassFullName()
2287: + "();");
2288: lWriter
2289: .println(" "
2290: + lAggregatorKeyStructureStylesheet
2291: .getClassFullName()
2292: + " l"
2293: + lAggregatorEntityStylesheet
2294: .getNormalisedName()
2295: + "Key = pInput.get"
2296: + lAggregatorEntityStylesheet
2297: .getNormalisedName()
2298: + "Key();");
2299: lWriter
2300: .println(" "
2301: + lAggregateeKeyStructureStylesheet
2302: .getClassFullName()
2303: + "[] l"
2304: + lAggregateeRole.getName()
2305: + "Keys = pInput.get"
2306: + lAggregateeRole.getName()
2307: + "Keys();");
2308: lWriter.println(" try");
2309: lWriter.println(" {");
2310: lWriter
2311: .println(" javax.naming.Context lContext = new javax.naming.InitialContext();");
2312: lWriter.println(" "
2313: + lDomainStylesheet
2314: .getDomainInterfaceFullName()
2315: + " lDomain = ("
2316: + lDomainStylesheet
2317: .getDomainInterfaceFullName()
2318: + ")lContext.lookup("
2319: + lDomainStylesheet
2320: .getDomainInterfaceFullName()
2321: + ".COMPONENT_URL);");
2322: lWriter
2323: .println(" lDomain.beginEdit();"); // Need to consider implicit joining of the objects to transaction (this would get rid of beginEdit())
2324: lWriter
2325: .println(" "
2326: + lAggregatorEntityStylesheet
2327: .getDomainInterfaceFullName()
2328: + " l"
2329: + lAggregatorEntityStylesheet
2330: .getNormalisedName()
2331: + " = "
2332: + lAggregatorEntityStylesheet
2333: .getServiceDetailsStructureTranslatorName()
2334: + ".get"
2335: + lAggregatorEntityStylesheet
2336: .getDomainInterfaceName()
2337: + "( lDomain, l"
2338: + lAggregatorEntityStylesheet
2339: .getNormalisedName()
2340: + "Key);");
2341: lWriter.println(" l"
2342: + lAggregatorEntityStylesheet
2343: .getNormalisedName()
2344: + ".beginEdit();"); // Need to consider implicit joining of the objects to transaction (this would get rid of beginEdit())
2345: lWriter
2346: .println(" for (int i = 0; i < l"
2347: + lAggregateeRole.getName()
2348: + "Keys.length; i++)");
2349: lWriter.println(" {");
2350: lWriter
2351: .println(" "
2352: + lAggregateeEntityStylesheet
2353: .getDomainInterfaceFullName()
2354: + " l"
2355: + lAggregateeRole.getName()
2356: + " = "
2357: + lAggregateeEntityStylesheet
2358: .getServiceDetailsStructureTranslatorName()
2359: + ".get"
2360: + lAggregateeEntityStylesheet
2361: .getDomainInterfaceName()
2362: + "( lDomain, l"
2363: + lAggregateeRole.getName()
2364: + "Keys[i]);");
2365: lWriter.println(" l"
2366: + lAggregatorEntityStylesheet
2367: .getNormalisedName() + ".add"
2368: + lAggregateeRole.getName() + "(l"
2369: + lAggregateeRole.getName() + ");");
2370: lWriter.println(" }");
2371: lWriter
2372: .println(" return lOperationResult;");
2373: lWriter.println(" }");
2374: lWriter
2375: .println(" catch (javax.naming.NamingException e)");
2376: lWriter.println(" {");
2377: lWriter
2378: .println(" throw new BSNamingAndDirectoryServiceInvocationException(\"Unable to complete "
2379: + lOperationName
2380: + " operation.\", e);");
2381: lWriter.println(" }");
2382: // We may have entity instances not found error (definitely will have at least our own)
2383: lWriter
2384: .println(" catch (BORecordNotFoundException e)");
2385: lWriter.println(" {");
2386: for (Iterator lEntitiesWhichMayBeNotFoundWhenModifyingAssociationIterator = lEntitiesWhichMayBeNotFoundWhenModifyingAssociation
2387: .iterator(); lEntitiesWhichMayBeNotFoundWhenModifyingAssociationIterator
2388: .hasNext();) {
2389: Entity lEntityWhichMayNotBeFound = (Entity) lEntitiesWhichMayBeNotFoundWhenModifyingAssociationIterator
2390: .next();
2391: STEntityStylesheet lEntityWhichMayNotBeFoundStylesheet = CodeGenerationStylesheetAccessor
2392: .getEntityStylesheet(lEntityWhichMayNotBeFound);
2393: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
2394: .getMessageStylesheet(pServicemodule
2395: .getMessage(lEntityWhichMayNotBeFoundStylesheet
2396: .getServiceInstanceNotFoundMessageName()));
2397: lWriter
2398: .println(" if (e.getRecordType().equals(\""
2399: + lEntityWhichMayNotBeFound
2400: .getRef() + "\"))");
2401: lWriter.println(" {");
2402: lWriter
2403: .println(" "
2404: + lMessageStylesheet
2405: .getClassFullName()
2406: + " lErrorMessage = new "
2407: + lMessageStylesheet
2408: .getClassFullName()
2409: + "();");
2410: lWriter
2411: .println(" lOperationResult.set"
2412: + lEntityWhichMayNotBeFound
2413: .getName()
2414: + "NotFoundError(lErrorMessage);");
2415: lWriter
2416: .println(" return lOperationResult;");
2417: lWriter.println(" }");
2418: }
2419: // Caught some unexpected exception. Looks very bad
2420: lWriter
2421: .println(" throw new BSUnexpectedProgramConditionException(\"Caught unexpected exception.\",e);");
2422: lWriter.println(" }");
2423: lWriter
2424: .println(" catch (BOException e)");
2425: lWriter.println(" {");
2426: lWriter
2427: .println(" throw new BSDomainObjectInvocationException(\"Unable to complete "
2428: + lOperationName
2429: + " operation.\", e);");
2430: lWriter.println(" }");
2431: lWriter.println(" }");
2432: }
2433: // Generate remove operation
2434: {
2435: String lOperationName = "remove"
2436: + lAggregateeRolePluralName
2437: + "From"
2438: + lAggregatorEntityStylesheet
2439: .getNormalisedName();
2440: Operation lOperation = pService
2441: .getOperation(lOperationName);
2442: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
2443: .getOperationStylesheet(lOperation);
2444: lWriter.println();
2445: lWriter.println(" /** "
2446: + lOperation.getDescription() + " */");
2447: lWriter.println(" public "
2448: + lOperationStylesheet
2449: .getResultClassFullName()
2450: + " "
2451: + lOperationStylesheet.getMethodName()
2452: + "( "
2453: + lOperationStylesheet
2454: .getInputClassFullName()
2455: + " pInput) throws BSException");
2456: lWriter.println(" {");
2457: lWriter.println(" "
2458: + lOperationStylesheet
2459: .getResultClassFullName()
2460: + " lOperationResult = new "
2461: + lOperationStylesheet
2462: .getResultClassFullName()
2463: + "();");
2464: lWriter
2465: .println(" "
2466: + lAggregatorKeyStructureStylesheet
2467: .getClassFullName()
2468: + " l"
2469: + lAggregatorEntityStylesheet
2470: .getNormalisedName()
2471: + "Key = pInput.get"
2472: + lAggregatorEntityStylesheet
2473: .getNormalisedName()
2474: + "Key();");
2475: lWriter
2476: .println(" "
2477: + lAggregateeKeyStructureStylesheet
2478: .getClassFullName()
2479: + "[] l"
2480: + lAggregateeRole.getName()
2481: + "Keys = pInput.get"
2482: + lAggregateeRole.getName()
2483: + "Keys();");
2484: lWriter.println(" try");
2485: lWriter.println(" {");
2486: lWriter
2487: .println(" javax.naming.Context lContext = new javax.naming.InitialContext();");
2488: lWriter.println(" "
2489: + lDomainStylesheet
2490: .getDomainInterfaceFullName()
2491: + " lDomain = ("
2492: + lDomainStylesheet
2493: .getDomainInterfaceFullName()
2494: + ")lContext.lookup("
2495: + lDomainStylesheet
2496: .getDomainInterfaceFullName()
2497: + ".COMPONENT_URL);");
2498: lWriter
2499: .println(" lDomain.beginEdit();"); // Need to consider implicit joining of the objects to transaction (this would get rid of beginEdit())
2500: lWriter
2501: .println(" "
2502: + lAggregatorEntityStylesheet
2503: .getDomainInterfaceFullName()
2504: + " l"
2505: + lAggregatorEntityStylesheet
2506: .getNormalisedName()
2507: + " = "
2508: + lAggregatorEntityStylesheet
2509: .getServiceDetailsStructureTranslatorName()
2510: + ".get"
2511: + lAggregatorEntityStylesheet
2512: .getDomainInterfaceName()
2513: + "( lDomain, l"
2514: + lAggregatorEntityStylesheet
2515: .getNormalisedName()
2516: + "Key);");
2517: lWriter.println(" l"
2518: + lAggregatorEntityStylesheet
2519: .getNormalisedName()
2520: + ".beginEdit();"); // Need to consider implicit joining of the objects to transaction (this would get rid of beginEdit())
2521: lWriter
2522: .println(" for (int i = 0; i < l"
2523: + lAggregateeRole.getName()
2524: + "Keys.length; i++)");
2525: lWriter.println(" {");
2526: lWriter
2527: .println(" "
2528: + lAggregateeEntityStylesheet
2529: .getDomainInterfaceFullName()
2530: + " l"
2531: + lAggregateeRole.getName()
2532: + " = "
2533: + lAggregateeEntityStylesheet
2534: .getServiceDetailsStructureTranslatorName()
2535: + ".get"
2536: + lAggregateeEntityStylesheet
2537: .getDomainInterfaceName()
2538: + "( lDomain, l"
2539: + lAggregateeRole.getName()
2540: + "Keys[i]);");
2541: lWriter.println(" l"
2542: + lAggregatorEntityStylesheet
2543: .getNormalisedName()
2544: + ".remove" + lAggregateeRole.getName()
2545: + "(l" + lAggregateeRole.getName()
2546: + ");");
2547: lWriter.println(" }");
2548: lWriter
2549: .println(" return lOperationResult;");
2550: lWriter.println(" }");
2551: lWriter
2552: .println(" catch (javax.naming.NamingException e)");
2553: lWriter.println(" {");
2554: lWriter
2555: .println(" throw new BSNamingAndDirectoryServiceInvocationException(\"Unable to complete "
2556: + lOperationName
2557: + " operation.\", e);");
2558: lWriter.println(" }");
2559: // We may have entity instances not found error (definitely will have at least our own)
2560: lWriter
2561: .println(" catch (BORecordNotFoundException e)");
2562: lWriter.println(" {");
2563: for (Iterator lEntitiesWhichMayBeNotFoundWhenModifyingAssociationIterator = lEntitiesWhichMayBeNotFoundWhenModifyingAssociation
2564: .iterator(); lEntitiesWhichMayBeNotFoundWhenModifyingAssociationIterator
2565: .hasNext();) {
2566: Entity lEntityWhichMayNotBeFound = (Entity) lEntitiesWhichMayBeNotFoundWhenModifyingAssociationIterator
2567: .next();
2568: STEntityStylesheet lEntityWhichMayNotBeFoundStylesheet = CodeGenerationStylesheetAccessor
2569: .getEntityStylesheet(lEntityWhichMayNotBeFound);
2570: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
2571: .getMessageStylesheet(pServicemodule
2572: .getMessage(lEntityWhichMayNotBeFoundStylesheet
2573: .getServiceInstanceNotFoundMessageName()));
2574: lWriter
2575: .println(" if (e.getRecordType().equals(\""
2576: + lEntityWhichMayNotBeFound
2577: .getRef() + "\"))");
2578: lWriter.println(" {");
2579: lWriter
2580: .println(" "
2581: + lMessageStylesheet
2582: .getClassFullName()
2583: + " lErrorMessage = new "
2584: + lMessageStylesheet
2585: .getClassFullName()
2586: + "();");
2587: lWriter
2588: .println(" lOperationResult.set"
2589: + lEntityWhichMayNotBeFound
2590: .getName()
2591: + "NotFoundError(lErrorMessage);");
2592: lWriter
2593: .println(" return lOperationResult;");
2594: lWriter.println(" }");
2595: }
2596: // Caught some unexpected exception. Looks very bad
2597: lWriter
2598: .println(" throw new BSUnexpectedProgramConditionException(\"Caught unexpected exception.\",e);");
2599: lWriter.println(" }");
2600: lWriter
2601: .println(" catch (BOException e)");
2602: lWriter.println(" {");
2603: lWriter
2604: .println(" throw new BSDomainObjectInvocationException(\"Unable to complete "
2605: + lOperationName
2606: + " operation.\", e);");
2607: lWriter.println(" }");
2608: lWriter.println(" }");
2609: }
2610: // Generate GetAll method
2611: {
2612: String lOperationName = "getAll"
2613: + lAggregateeRolePluralName
2614: + "For"
2615: + lAggregatorEntityStylesheet
2616: .getNormalisedName();
2617: Operation lOperation = pService
2618: .getOperation(lOperationName);
2619: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
2620: .getOperationStylesheet(lOperation);
2621: lWriter.println();
2622: lWriter.println(" /** "
2623: + lOperation.getDescription() + " */");
2624: lWriter.println(" public "
2625: + lOperationStylesheet
2626: .getResultClassFullName()
2627: + " "
2628: + lOperationStylesheet.getMethodName()
2629: + "( "
2630: + lOperationStylesheet
2631: .getInputClassFullName()
2632: + " pInput) throws BSException");
2633: lWriter.println(" {");
2634: lWriter.println(" "
2635: + lOperationStylesheet
2636: .getResultClassFullName()
2637: + " lOperationResult = new "
2638: + lOperationStylesheet
2639: .getResultClassFullName()
2640: + "();");
2641: lWriter
2642: .println(" "
2643: + lAggregatorKeyStructureStylesheet
2644: .getClassFullName()
2645: + " l"
2646: + lAggregatorEntityStylesheet
2647: .getNormalisedName()
2648: + "Key = pInput.get"
2649: + lAggregatorEntityStylesheet
2650: .getNormalisedName()
2651: + "Key();");
2652: lWriter.println(" try");
2653: lWriter.println(" {");
2654: lWriter
2655: .println(" javax.naming.Context lContext = new javax.naming.InitialContext();");
2656: lWriter.println(" "
2657: + lDomainStylesheet
2658: .getDomainInterfaceFullName()
2659: + " lDomain = ("
2660: + lDomainStylesheet
2661: .getDomainInterfaceFullName()
2662: + ")lContext.lookup("
2663: + lDomainStylesheet
2664: .getDomainInterfaceFullName()
2665: + ".COMPONENT_URL);");
2666: lWriter
2667: .println(" "
2668: + lAggregatorEntityStylesheet
2669: .getDomainInterfaceFullName()
2670: + " l"
2671: + lAggregatorEntityStylesheet
2672: .getNormalisedName()
2673: + " = "
2674: + lAggregatorEntityStylesheet
2675: .getServiceDetailsStructureTranslatorName()
2676: + ".get"
2677: + lAggregatorEntityStylesheet
2678: .getDomainInterfaceName()
2679: + "( lDomain, l"
2680: + lAggregatorEntityStylesheet
2681: .getNormalisedName()
2682: + "Key);");
2683: lWriter.println(" "
2684: + lAggregateeEntityStylesheet
2685: .getDomainInterfaceFullName()
2686: + "[] l"
2687: + lAggregateeRolePluralName
2688: + " = l"
2689: + lAggregatorEntityStylesheet
2690: .getNormalisedName() + ".get"
2691: + lAggregateeRolePluralName + "().to"
2692: + lAggregateeEntity.getPluralName()
2693: + "Array();");
2694: lWriter
2695: .println(" lOperationResult.set"
2696: + lAggregateeRolePluralName
2697: + "( "
2698: + lAggregateeEntityStylesheet
2699: .getServiceDetailsStructureTranslatorName()
2700: + ".convertToDetailsStructureArray(l"
2701: + lAggregateeRolePluralName
2702: + "));");
2703: lWriter
2704: .println(" return lOperationResult;");
2705: lWriter.println(" }");
2706: lWriter
2707: .println(" catch (javax.naming.NamingException e)");
2708: lWriter.println(" {");
2709: lWriter
2710: .println(" throw new BSNamingAndDirectoryServiceInvocationException(\"Unable to complete "
2711: + lOperationName
2712: + " operation.\", e);");
2713: lWriter.println(" }");
2714: // We may have entity instances not found error (definitely will have at least our own)
2715: lWriter
2716: .println(" catch (BORecordNotFoundException e)");
2717: lWriter.println(" {");
2718: for (Iterator lEntitiesWhichMayBeNotFoundWhenLoadingAssociationIterator = lEntitiesWhichMayBeNotFoundWhenLoadingAssociation
2719: .iterator(); lEntitiesWhichMayBeNotFoundWhenLoadingAssociationIterator
2720: .hasNext();) {
2721: Entity lEntityWhichMayNotBeFound = (Entity) lEntitiesWhichMayBeNotFoundWhenLoadingAssociationIterator
2722: .next();
2723: STEntityStylesheet lEntityWhichMayNotBeFoundStylesheet = CodeGenerationStylesheetAccessor
2724: .getEntityStylesheet(lEntityWhichMayNotBeFound);
2725: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
2726: .getMessageStylesheet(pServicemodule
2727: .getMessage(lEntityWhichMayNotBeFoundStylesheet
2728: .getServiceInstanceNotFoundMessageName()));
2729: lWriter
2730: .println(" if (e.getRecordType().equals(\""
2731: + lEntityWhichMayNotBeFound
2732: .getRef() + "\"))");
2733: lWriter.println(" {");
2734: lWriter
2735: .println(" "
2736: + lMessageStylesheet
2737: .getClassFullName()
2738: + " lErrorMessage = new "
2739: + lMessageStylesheet
2740: .getClassFullName()
2741: + "();");
2742: lWriter
2743: .println(" lOperationResult.set"
2744: + lEntityWhichMayNotBeFound
2745: .getName()
2746: + "NotFoundError(lErrorMessage);");
2747: lWriter
2748: .println(" return lOperationResult;");
2749: lWriter.println(" }");
2750: }
2751: // Caught some unexpected exception. Looks very bad
2752: lWriter
2753: .println(" throw new BSUnexpectedProgramConditionException(\"Caught unexpected exception.\",e);");
2754: lWriter.println(" }");
2755: lWriter
2756: .println(" catch (BOException e)");
2757: lWriter.println(" {");
2758: lWriter
2759: .println(" throw new BSDomainObjectInvocationException(\"Unable to complete "
2760: + lOperationName
2761: + " operation.\", e);");
2762: lWriter.println(" }");
2763: lWriter.println(" }");
2764: }
2765: }
2766: }
2767: lWriter.println("}");
2768: } catch (BOException e) {
2769: throw new BSDomainObjectInvocationException(e);
2770: } catch (IOException e) {
2771: throw new BSException(
2772: "Unable to generate implementation for the service. ServiceRef "
2773: + pService.getRef(), e);
2774: } finally {
2775: if (lWriter != null) {
2776: lWriter.flush();
2777: lWriter.close();
2778: }
2779: if (lFileWriter != null) {
2780: try {
2781: lFileWriter.flush();
2782: } catch (IOException e) {
2783: // Ignore
2784: }
2785: try {
2786: lFileWriter.close();
2787: } catch (IOException e) {
2788: // Ignore
2789: }
2790: }
2791: }
2792: }
2793:
2794: private static Properties sGeneratePrimaryKeyArgumentsForCreateEntityMethodInvocationOutput = new Properties();
2795:
2796: // Helper. Returns the string containing expressions used to invoke create entity method */
2797: private static String generatePrimaryKeyArgumentsForCreateEntityMethodInvocation(
2798: Entity pEntity) throws BOException, BSException {
2799: String lCacheKey = pEntity.getRef();
2800: String lResult = sGeneratePrimaryKeyArgumentsForCreateEntityMethodInvocationOutput
2801: .getProperty(lCacheKey);
2802: if (lResult == null) {
2803: StringBuffer lMethodInvocation = new StringBuffer("");
2804: Collection lPrimaryKeyElements = pEntity
2805: .getPrimaryKeyElements();
2806: // Need to exclude association with the owner
2807: AssociationRole lOwnerReference = pEntity
2808: .getOwnerReference();
2809: boolean lNeedComma = false;
2810: for (Iterator lPrimaryKeyElementsIterator = lPrimaryKeyElements
2811: .iterator(); lPrimaryKeyElementsIterator.hasNext();) {
2812: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
2813: .next();
2814: if (lPrimaryKeyElement instanceof Attribute) {
2815: Attribute lAttribute = (Attribute) lPrimaryKeyElement;
2816: STAttributeStylesheet lAttributeStylesheet = CodeGenerationStylesheetAccessor
2817: .getAttributeStylesheet(lAttribute);
2818: if (lNeedComma)
2819: lMethodInvocation.append(", ");
2820: else
2821: lNeedComma = true; // Appending something, so we need comma at the next round
2822: lMethodInvocation.append(" lProposedDetails.get");
2823: lMethodInvocation.append(lAttributeStylesheet
2824: .getNormalisedName());
2825: lMethodInvocation.append("()");
2826: } else if (lPrimaryKeyElement instanceof AssociationRole) {
2827: AssociationRole lRole = (AssociationRole) lPrimaryKeyElement;
2828: STAssociationRoleStylesheet lReferenceStylesheet = CodeGenerationStylesheetAccessor
2829: .getAssociationRoleStylesheet(lRole);
2830: STEntityStylesheet lReferencedEntityStylesheet = CodeGenerationStylesheetAccessor
2831: .getEntityStylesheet(lRole.getEntity());
2832:
2833: if (!lRole.equals(lOwnerReference)) {
2834: if (lNeedComma)
2835: lMethodInvocation.append(", ");
2836: else
2837: lNeedComma = true; // Appending something, so we need comma at the next round
2838: lMethodInvocation
2839: .append(lReferencedEntityStylesheet
2840: .getServiceDetailsStructureTranslatorName()
2841: + ".get"
2842: + lReferencedEntityStylesheet
2843: .getDomainInterfaceName()
2844: + "( lDomain, lProposedDetails.get"
2845: + lReferenceStylesheet
2846: .getNormalisedName()
2847: + "())");
2848: }
2849: }
2850: }
2851: sGeneratePrimaryKeyArgumentsForCreateEntityMethodInvocationOutput
2852: .setProperty(lCacheKey, lResult = lMethodInvocation
2853: .toString());
2854: }
2855: return lResult;
2856: }
2857:
2858: // Helper method. Collects entities, instances of which may be not be found when
2859: // attempting to load given top entity. This helper is basically expected to
2860: // study elements of the primary key for this entity and add all associated entities, which are part of the primary key
2861: // The method is called recirsively to deal with primary keys of the associated entities, which areparts of primary key
2862: // to any depth.
2863: private static void collectEntitiesWhichMayBeNotFoundWhenLoadingInstance(
2864: Entity pTopEntity, Set pCollectedEntities)
2865: throws BOException {
2866: // Look at all associations, which are parts of primary key
2867: // We also may have entities, which are parts of primary key not found
2868: Collection lPrimaryKeyElements = pTopEntity
2869: .getPrimaryKeyElements();
2870: for (Iterator lPrimaryKeyElementsIterator = lPrimaryKeyElements
2871: .iterator(); lPrimaryKeyElementsIterator.hasNext();) {
2872: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
2873: .next();
2874: if (lPrimaryKeyElement instanceof AssociationRole) {
2875: AssociationRole lRole = (AssociationRole) lPrimaryKeyElement;
2876: // Only register this entity and its dependents if it is not already in the list
2877: Entity lAssociatedEntityInPrimaryKey = lRole
2878: .getEntity();
2879: if (!pCollectedEntities
2880: .contains(lAssociatedEntityInPrimaryKey)) {
2881: // Add this entity to collected entities and call this operation recursively
2882: pCollectedEntities
2883: .add(lAssociatedEntityInPrimaryKey);
2884: collectEntitiesWhichMayBeNotFoundWhenLoadingInstance(
2885: lAssociatedEntityInPrimaryKey,
2886: pCollectedEntities);
2887: }
2888: }
2889: }
2890: }
2891:
2892: // Helper method. Collects entities, instances of which may be not be found when
2893: // attempting to update or create given top entity. This helper is basically expected to
2894: // add all association roles present in the entity
2895: private static void collectEntitiesWhichMayBeNotFoundWhenUpdatingOrCreatingInstance(
2896: Entity pEntity, Set pCollectedEntities) throws BSException,
2897: BOException {
2898: // Now look through all associations for which we have a reference
2899: Collection lReferences = pEntity.getCombinedReferences();
2900: for (Iterator lReferencesIterator = lReferences.iterator(); lReferencesIterator
2901: .hasNext();) {
2902: AssociationRole lRole = (AssociationRole) lReferencesIterator
2903: .next();
2904: // Singular multiplicities resolved simply by having the other entity id as the member of the structure
2905: // Not singular cardinality is resolved by having a separate service call
2906: if (!lRole.isPlural() == true) {
2907: // Only register this entity and its dependents if it is not already in the list
2908: Entity lAssociatedEntityInRole = lRole.getEntity();
2909: if (!pCollectedEntities
2910: .contains(lAssociatedEntityInRole)) {
2911: // Add this entity to collected entities and collect all entities, which may go wrong when editing this one
2912: pCollectedEntities.add(lAssociatedEntityInRole);
2913: collectEntitiesWhichMayBeNotFoundWhenLoadingInstance(
2914: lAssociatedEntityInRole, pCollectedEntities);
2915: }
2916: }
2917: }
2918: }
2919: }
|