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.servicemoduleadaptergenerator.generic.stringstructures;
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.Iterator;
0023:
0024: import javax.jmi.reflect.JmiException;
0025: import javax.naming.Context;
0026: import javax.naming.InitialContext;
0027: import javax.naming.NamingException;
0028:
0029: import org.apache.commons.logging.Log;
0030: import org.apache.commons.logging.LogFactory;
0031:
0032: import com.metaboss.enterprise.bo.BOException;
0033: import com.metaboss.enterprise.bs.BSDomainObjectInvocationException;
0034: import com.metaboss.enterprise.bs.BSException;
0035: import com.metaboss.enterprise.bs.BSNamingAndDirectoryServiceInvocationException;
0036: import com.metaboss.enterprise.bs.BSServiceProviderException;
0037: import com.metaboss.enterprise.bs.BSUnexpectedProgramConditionException;
0038: import com.metaboss.sdlctools.models.ModelRepository;
0039: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
0040: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
0041: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.AbstractNamespace;
0042: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
0043: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
0044: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
0045: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
0046: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureField;
0047: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
0048: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageField;
0049: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
0050: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputField;
0051: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputField;
0052: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputMessage;
0053: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
0054: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
0055: import com.metaboss.sdlctools.services.codegeneration.BSAdapterGenerator;
0056: import com.metaboss.sdlctools.services.codegeneration.CodeGenerationStylesheetAccessor;
0057: import com.metaboss.sdlctools.services.codegeneration.CopyrightUtils;
0058: import com.metaboss.sdlctools.services.codegenerationstylesheet.STDataDictionaryStylesheet;
0059: import com.metaboss.sdlctools.services.codegenerationstylesheet.STDatatypeStylesheet;
0060: import com.metaboss.sdlctools.services.codegenerationstylesheet.STDocumentationStylesheet;
0061: import com.metaboss.sdlctools.services.codegenerationstylesheet.STMessageFieldStylesheet;
0062: import com.metaboss.sdlctools.services.codegenerationstylesheet.STMessageStylesheet;
0063: import com.metaboss.sdlctools.services.codegenerationstylesheet.STNamespaceStylesheet;
0064: import com.metaboss.sdlctools.services.codegenerationstylesheet.STOperationInputFieldStylesheet;
0065: import com.metaboss.sdlctools.services.codegenerationstylesheet.STOperationOutputFieldStylesheet;
0066: import com.metaboss.sdlctools.services.codegenerationstylesheet.STOperationOutputMessageStylesheet;
0067: import com.metaboss.sdlctools.services.codegenerationstylesheet.STOperationStylesheet;
0068: import com.metaboss.sdlctools.services.codegenerationstylesheet.STServiceStylesheet;
0069: import com.metaboss.sdlctools.services.codegenerationstylesheet.STServicemoduleStylesheet;
0070: import com.metaboss.sdlctools.services.codegenerationstylesheet.STStructureFieldStylesheet;
0071: import com.metaboss.sdlctools.services.codegenerationstylesheet.STStructureStylesheet;
0072: import com.metaboss.util.DirectoryUtils;
0073: import com.metaboss.util.StringUtils;
0074:
0075: /** Generator of adapter offering access via simple strings */
0076: public class BSAdapterGeneratorImpl implements BSAdapterGenerator {
0077: // Commons Logging instance.
0078: private static final Log sLogger = LogFactory
0079: .getLog(BSAdapterGeneratorImpl.class);
0080: // This constant is set up from constructor and is directing how operation inputs and outputs are generated
0081: private boolean mUseInnerClasses = false;
0082:
0083: // Constructor
0084: public BSAdapterGeneratorImpl(boolean pUseInnerClasses,
0085: java.util.Hashtable pEnvironment) {
0086: mUseInnerClasses = pUseInnerClasses;
0087: }
0088:
0089: /* @return array of names of adapters, which are required by this adapter,
0090: * may be zero length array if this adapter is not relying on any other one. */
0091: public String[] getRequiredAdapters() throws BSException {
0092: return new String[0]; // No other adapters are required by this one
0093: }
0094:
0095: // Generates servicemodules distribution implementation sourcecode for the particular servicemodule within particular enterprise
0096: public void generateSourceCodeForServicemodule(
0097: String pGenerationDirectoryPath, String pServicemoduleRef)
0098: throws BSException {
0099: try {
0100: if (mUseInnerClasses)
0101: sLogger
0102: .info("Generating generic string structures adapter implementation source for "
0103: + pServicemoduleRef
0104: + " servicemodule...");
0105: else
0106: sLogger
0107: .info("Generating generic simplified string structures adapter implementation source for "
0108: + pServicemoduleRef
0109: + " servicemodule...");
0110: // Get the referenced objects from the model
0111: Context lContext = new InitialContext();
0112: ModelRepository lModelRepository = (ModelRepository) lContext
0113: .lookup(ModelRepository.COMPONENT_URL);
0114: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
0115: .getDefaultModelExtent();
0116: Servicemodule lServicemodule = (Servicemodule) lMetaBossModelPackage
0117: .getModelElement().getByRef(pServicemoduleRef);
0118:
0119: // Generate services adapters
0120: String lServicesAdapterPackageName = getPackageNameForServicemoduleServices(lServicemodule
0121: .getRef());
0122: String lServicesAdapterSourceDirectoryPath = pGenerationDirectoryPath
0123: + File.separator
0124: + StringUtils.replace(lServicesAdapterPackageName,
0125: ".", File.separator);
0126: DirectoryUtils
0127: .ensureThereIsDirectory(lServicesAdapterSourceDirectoryPath);
0128: // Generate bits and pieces
0129: generateServicesPackageDescription(
0130: lServicesAdapterPackageName,
0131: lServicesAdapterSourceDirectoryPath, lServicemodule);
0132: generateAdapterImplementation(lServicesAdapterPackageName,
0133: lServicesAdapterSourceDirectoryPath, lServicemodule);
0134: generateStructureProxies(pGenerationDirectoryPath,
0135: lServicemodule);
0136: generateStructureProxyTranslators(pGenerationDirectoryPath,
0137: lServicemodule);
0138: generateMessageProxies(pGenerationDirectoryPath,
0139: lServicemodule.getMessages());
0140: generateMessageProxyTranslators(pGenerationDirectoryPath,
0141: lServicemodule.getMessages());
0142: // Done
0143: if (mUseInnerClasses)
0144: sLogger
0145: .info("Done generating generic string structures adapter implementation source for "
0146: + pServicemoduleRef + " servicemodule");
0147: else
0148: sLogger
0149: .info("Done generating generic simplified string structures adapter implementation source for "
0150: + pServicemoduleRef + " servicemodule");
0151: } catch (NamingException e) {
0152: throw new BSNamingAndDirectoryServiceInvocationException(e);
0153: } catch (BOException e) {
0154: throw new BSDomainObjectInvocationException(e);
0155: }
0156: }
0157:
0158: /* Returns the name of the package where adapter code is generated to */
0159: public String getPackageNameForServicemoduleServices(
0160: String pServicemoduleRef) throws BSException {
0161: // This is a standard adapter - so stylesheet dictates the package name
0162: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
0163: .getServicemoduleStylesheet(pServicemoduleRef);
0164: return mUseInnerClasses ? lServicemoduleStylesheet
0165: .getServicesGenericStringStructuresAdapterPackageName()
0166: : lServicemoduleStylesheet
0167: .getServicesGenericSimplifiedStringStructuresAdapterPackageName();
0168: }
0169:
0170: /* Returns the name of the package where adapter code is generated to */
0171: public String getPackageNameForServicemoduleEventPublishers(
0172: String pServicemoduleRef) throws BSException {
0173: // This is a standard adapter - so stylesheet dictates the package name
0174: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
0175: .getServicemoduleStylesheet(pServicemoduleRef);
0176: return mUseInnerClasses ? lServicemoduleStylesheet
0177: .getEventPublishersGenericStringStructuresAdapterPackageName()
0178: : lServicemoduleStylesheet
0179: .getEventPublishersGenericSimplifiedStringStructuresAdapterPackageName();
0180: }
0181:
0182: /** Generates adapter implementation sourcecode for the particular data dictionary
0183: * @param pGenerationDirectoryPath directory to generate code to
0184: * @param pDataDictionaryRef identifier of the datadictionary to generate the code for
0185: */
0186: public void generateSourceCodeForDataDictionary(
0187: String pGenerationDirectoryPath, String pDataDictionaryRef)
0188: throws BSException {
0189: try {
0190: if (mUseInnerClasses)
0191: sLogger
0192: .info("Generating generic string structures adapter implementation source for "
0193: + pDataDictionaryRef
0194: + " data dictionary...");
0195: else
0196: sLogger
0197: .info("Generating generic simplified string structures adapter implementation source for "
0198: + pDataDictionaryRef
0199: + " data dictionary...");
0200: // Get the referenced objects from the model
0201: Context lContext = new InitialContext();
0202: ModelRepository lModelRepository = (ModelRepository) lContext
0203: .lookup(ModelRepository.COMPONENT_URL);
0204: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
0205: .getDefaultModelExtent();
0206: DataDictionary lDataDictionary = (DataDictionary) lMetaBossModelPackage
0207: .getModelElement().getByRef(pDataDictionaryRef);
0208:
0209: // Generate bits and pieces
0210: // generateStructureProxies(pGenerationDirectoryPath, lServicemodule);
0211: // generateStructureProxyTranslators(pGenerationDirectoryPath, lServicemodule);
0212: generateMessageProxies(pGenerationDirectoryPath,
0213: lDataDictionary.getCombinedMessages());
0214: generateMessageProxyTranslators(pGenerationDirectoryPath,
0215: lDataDictionary.getCombinedMessages());
0216: // Done
0217: if (mUseInnerClasses)
0218: sLogger
0219: .info("Done generating generic string structures adapter implementation source for "
0220: + pDataDictionaryRef
0221: + " data dictionary");
0222: else
0223: sLogger
0224: .info("Done generating generic simplified string structures adapter implementation source for "
0225: + pDataDictionaryRef
0226: + " data dictionary");
0227: } catch (NamingException e) {
0228: throw new BSNamingAndDirectoryServiceInvocationException(e);
0229: } catch (BOException e) {
0230: throw new BSDomainObjectInvocationException(e);
0231: }
0232: }
0233:
0234: /** Returns the name of the package where adapter code is generated to
0235: * @param pDataDictionaryRef identifier of the datadictionary to generate the code for
0236: */
0237: public String getPackageNameForDataDictionary(
0238: String pDataDictionaryRef) throws BSException {
0239: // This is a standard adapter - so stylesheet dictates the package name
0240: STDataDictionaryStylesheet lDataDictionaryStylesheet = CodeGenerationStylesheetAccessor
0241: .getDataDictionaryStylesheet(pDataDictionaryRef);
0242: return mUseInnerClasses ? lDataDictionaryStylesheet
0243: .getGenericStringStructuresAdapterPackageName()
0244: : lDataDictionaryStylesheet
0245: .getGenericSimplifiedStringStructuresAdapterPackageName();
0246: }
0247:
0248: // Helper. Generates adapter implementation
0249: private void generateAdapterImplementation(
0250: String pAdapterPackageName,
0251: String pAdapterSourceDirectoryPath,
0252: Servicemodule pServicemodule) throws BOException,
0253: BSException {
0254: STDocumentationStylesheet lDocumentationStylesheet = CodeGenerationStylesheetAccessor
0255: .getDocumentationStylesheet();
0256: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
0257: .getServicemoduleStylesheet(pServicemodule);
0258: // Generate implementations for the specific services
0259: Collection lServices = pServicemodule.getServices();
0260: for (Iterator lServicesIterator = lServices.iterator(); lServicesIterator
0261: .hasNext();) {
0262: Service lService = (Service) lServicesIterator.next();
0263: STServiceStylesheet lServiceStylesheet = CodeGenerationStylesheetAccessor
0264: .getServiceStylesheet(lService);
0265: String lServiceAdapterClassName = lServiceStylesheet
0266: .getAdapterClassName();
0267: String lServiceAdapterFullName = pAdapterPackageName + "."
0268: + lServiceAdapterClassName;
0269: // Generate adapter implementation class
0270: String lServiceAdapterFileName = pAdapterSourceDirectoryPath
0271: + File.separator
0272: + lServiceAdapterClassName
0273: + ".java";
0274: java.io.FileWriter lFileWriter = null;
0275: java.io.PrintWriter lWriter = null;
0276: try {
0277: lWriter = new java.io.PrintWriter(
0278: lFileWriter = new java.io.FileWriter(
0279: lServiceAdapterFileName));
0280: CopyrightUtils.writeCopyrightToGeneratedJavaSource(
0281: lWriter, getClass());
0282: lWriter.println("package " + pAdapterPackageName + ";");
0283: lWriter.println("");
0284: lWriter.println("import javax.naming.Context;");
0285: lWriter.println("import javax.naming.InitialContext;");
0286: lWriter.println("import javax.naming.NamingException;");
0287: lWriter
0288: .println("import com.metaboss.enterprise.bs.BSException;");
0289: lWriter
0290: .println("import com.metaboss.enterprise.datatypes.DataTypeValidationException;");
0291: lWriter
0292: .println("import com.metaboss.enterprise.datatypes.DataTypeFieldValidationException;");
0293: lWriter
0294: .println("import com.metaboss.enterprise.messages.Message;");
0295: lWriter.println();
0296: lWriter
0297: .println("/** This class is an adapter between siple (non MetaBoss compliant) java client code and enterprise services.");
0298: lWriter
0299: .println(" * It offers client code a simple String based access to the enterprise services. This simplicity ");
0300: lWriter
0301: .println(" * comes at the expence of losing the benefits strong data types, such as compile time detection of ");
0302: lWriter.println(" * some data validation errors */");
0303: lWriter.println("public class "
0304: + lServiceAdapterClassName);
0305: lWriter.println("{");
0306: Collection lOperations = lService.getOperations();
0307: for (Iterator lOperationsIterator = lOperations
0308: .iterator(); lOperationsIterator.hasNext();) {
0309: Operation lOperation = (Operation) lOperationsIterator
0310: .next();
0311: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
0312: .getOperationStylesheet(lOperation);
0313: // Generate operation description
0314: String lOperationDescription = lOperation
0315: .getDescription();
0316: if (lOperationDescription == null
0317: || lOperationDescription.length() == 0)
0318: lOperationDescription = lDocumentationStylesheet
0319: .getMissingDescriptionHtmlText();
0320:
0321: // Write out method definition
0322: if (mUseInnerClasses) {
0323: // Write out input and result structure proxies
0324: // Call helper method to generate input proxy code as inner class
0325: lWriter.println();
0326: generateInputProxyCode(lWriter, lOperation,
0327: true);
0328: // Call helper method to generate result proxy code as inner class
0329: lWriter.println();
0330: generateResultProxyCode(lWriter, lOperation,
0331: true);
0332: // Call helper method to generate input proxy translator code as inner class
0333: lWriter.println();
0334: generateInputProxyTranslatorCode(lWriter,
0335: lOperation, true);
0336: // Call helper method to generate result proxy translator code as inner class
0337: lWriter.println();
0338: generateResultProxyTranslatorCode(lWriter,
0339: lOperation, true);
0340:
0341: // Write out method definition
0342: lWriter.println();
0343: lWriter.println(" /** "
0344: + lOperationDescription);
0345: lWriter
0346: .println(" * @exception DataTypeValidationException thrown if any of the input strings did not pass validation during conversion to enterprise datatypes");
0347: lWriter
0348: .println(" * @exception NamingException thrown if this adapter was unable to lookup enteprise service component");
0349: lWriter
0350: .println(" * @exception BSException re-thrown from enteprise service component */");
0351: lWriter
0352: .println(" public "
0353: + lServiceAdapterClassName
0354: + "."
0355: + lOperationStylesheet
0356: .getResultProxyInnerClassName()
0357: + " "
0358: + lOperationStylesheet
0359: .getMethodName()
0360: + "( "
0361: + lServiceAdapterClassName
0362: + "."
0363: + lOperationStylesheet
0364: .getInputProxyInnerClassName()
0365: + " pInput) throws BSException, DataTypeValidationException, NamingException");
0366: lWriter.println(" {");
0367: lWriter
0368: .println(" Context lContext = new InitialContext();");
0369: lWriter.println(" "
0370: + lServiceStylesheet
0371: .getInterfaceFullName()
0372: + " lService = ("
0373: + lServiceStylesheet
0374: .getInterfaceFullName()
0375: + ")lContext.lookup("
0376: + lServiceStylesheet
0377: .getInterfaceFullName()
0378: + ".COMPONENT_URL);");
0379: lWriter
0380: .println(" return "
0381: + lOperationStylesheet
0382: .getResultProxyTranslatorInnerClassName()
0383: + ".toProxy(lService."
0384: + lOperationStylesheet
0385: .getMethodName()
0386: + "("
0387: + lOperationStylesheet
0388: .getInputProxyTranslatorInnerClassName()
0389: + ".fromProxy(pInput)));");
0390: lWriter.println(" }");
0391: } else {
0392: // Write out method definition
0393: lWriter.println();
0394: lWriter.println(" /** "
0395: + lOperationDescription);
0396: lWriter
0397: .println(" * @exception DataTypeValidationException thrown if any of the input strings did not pass validation during conversion to enterprise datatypes");
0398: lWriter
0399: .println(" * @exception NamingException thrown if this adapter was unable to lookup enteprise service component");
0400: lWriter
0401: .println(" * @exception BSException re-thrown from enteprise service component */");
0402: lWriter
0403: .println(" public "
0404: + lOperationStylesheet
0405: .getResultProxyOuterClassName()
0406: + " "
0407: + lOperationStylesheet
0408: .getMethodName()
0409: + "( "
0410: + lOperationStylesheet
0411: .getInputProxyOuterClassName()
0412: + " pInput) throws BSException, DataTypeValidationException, NamingException");
0413: lWriter.println(" {");
0414: lWriter
0415: .println(" Context lContext = new InitialContext();");
0416: lWriter.println(" "
0417: + lServiceStylesheet
0418: .getInterfaceFullName()
0419: + " lService = ("
0420: + lServiceStylesheet
0421: .getInterfaceFullName()
0422: + ")lContext.lookup("
0423: + lServiceStylesheet
0424: .getInterfaceFullName()
0425: + ".COMPONENT_URL);");
0426: lWriter
0427: .println(" return "
0428: + lOperationStylesheet
0429: .getResultProxyTranslatorOuterClassName()
0430: + ".toProxy(lService."
0431: + lOperationStylesheet
0432: .getMethodName()
0433: + "("
0434: + lOperationStylesheet
0435: .getInputProxyTranslatorOuterClassName()
0436: + ".fromProxy(pInput)));");
0437: lWriter.println(" }");
0438: }
0439: }
0440: lWriter.println("}");
0441: } catch (IOException e) {
0442: throw new BSException("Unable to write file "
0443: + lServiceAdapterFileName, e);
0444: } finally {
0445: if (lWriter != null) {
0446: lWriter.flush();
0447: lWriter.close();
0448: }
0449: if (lFileWriter != null) {
0450: try {
0451: lFileWriter.flush();
0452: } catch (IOException e) {
0453: // Ignore
0454: }
0455: try {
0456: lFileWriter.close();
0457: } catch (IOException e) {
0458: // Ignore
0459: }
0460: }
0461: }
0462: }
0463: }
0464:
0465: // Helper. Generates IDL Compliant interfaces
0466: private void generateStructureProxies(
0467: String pGenerationDirectoryPath,
0468: Servicemodule pServicemodule) throws BOException,
0469: BSException {
0470: // The IDL definition will be located in the top directory
0471: String lServicemoduleRef = pServicemodule.getRef();
0472: STDocumentationStylesheet lDocumentationStylesheet = CodeGenerationStylesheetAccessor
0473: .getDocumentationStylesheet();
0474: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
0475: .getServicemoduleStylesheet(pServicemodule);
0476: String lServicemoduleProxyPackageName = getPackageNameForServicemoduleServices(pServicemodule
0477: .getRef());
0478: String lServicemoduleProxySourceDirectoryPath = pGenerationDirectoryPath
0479: + File.separator
0480: + StringUtils.replace(lServicemoduleProxyPackageName,
0481: ".", File.separator);
0482: DirectoryUtils
0483: .ensureThereIsDirectory(lServicemoduleProxySourceDirectoryPath);
0484:
0485: // If we are using inner structures - create separate input / output structure proxy files
0486: if (mUseInnerClasses == false) {
0487: Collection lServices = pServicemodule.getServices();
0488: for (Iterator lServicesIterator = lServices.iterator(); lServicesIterator
0489: .hasNext();) {
0490: Service lService = (Service) lServicesIterator.next();
0491: Collection lOperations = lService.getOperations();
0492: for (Iterator lOperationsIterator = lOperations
0493: .iterator(); lOperationsIterator.hasNext();) {
0494: Operation lOperation = (Operation) lOperationsIterator
0495: .next();
0496: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
0497: .getOperationStylesheet(lOperation);
0498: // Work on generating input structure proxy
0499: {
0500: String lInputStructureProxyFileName = lServicemoduleProxySourceDirectoryPath
0501: + File.separator
0502: + lOperationStylesheet
0503: .getInputProxyOuterClassName()
0504: + ".java";
0505: FileWriter lFileWriter = null;
0506: PrintWriter lWriter = null;
0507: try {
0508: lWriter = new PrintWriter(
0509: lFileWriter = new FileWriter(
0510: lInputStructureProxyFileName));
0511: CopyrightUtils
0512: .writeCopyrightToGeneratedJavaSource(
0513: lWriter, getClass());
0514: lWriter.println("package "
0515: + lServicemoduleProxyPackageName
0516: + ";");
0517: lWriter.println();
0518: // Call helper method to generate proxy code as outer class
0519: generateInputProxyCode(lWriter, lOperation,
0520: false);
0521: } catch (IOException e) {
0522: throw new BSException(
0523: "Unable to write file "
0524: + lInputStructureProxyFileName,
0525: e);
0526: } finally {
0527: if (lWriter != null) {
0528: lWriter.flush();
0529: lWriter.close();
0530: }
0531:
0532: if (lFileWriter != null) {
0533: try {
0534: lFileWriter.flush();
0535: } catch (IOException e) {
0536: // Ignore
0537: }
0538: try {
0539: lFileWriter.close();
0540: } catch (IOException e) {
0541: // Ignore
0542: }
0543: }
0544: }
0545: }
0546: // Work on generating result structure proxy
0547: {
0548: String lResultStructureProxyFileName = lServicemoduleProxySourceDirectoryPath
0549: + File.separator
0550: + lOperationStylesheet
0551: .getResultProxyOuterClassName()
0552: + ".java";
0553: FileWriter lFileWriter = null;
0554: PrintWriter lWriter = null;
0555: try {
0556: lWriter = new PrintWriter(
0557: lFileWriter = new FileWriter(
0558: lResultStructureProxyFileName));
0559: CopyrightUtils
0560: .writeCopyrightToGeneratedJavaSource(
0561: lWriter, getClass());
0562: lWriter.println("package "
0563: + lServicemoduleProxyPackageName
0564: + ";");
0565: lWriter.println();
0566: // Call helper method to generate proxy code as outer class
0567: generateResultProxyCode(lWriter,
0568: lOperation, false);
0569: } catch (IOException e) {
0570: throw new BSException(
0571: "Unable to write file "
0572: + lResultStructureProxyFileName,
0573: e);
0574: } finally {
0575: if (lWriter != null) {
0576: lWriter.flush();
0577: lWriter.close();
0578: }
0579:
0580: if (lFileWriter != null) {
0581: try {
0582: lFileWriter.flush();
0583: } catch (IOException e) {
0584: // Ignore
0585: }
0586: try {
0587: lFileWriter.close();
0588: } catch (IOException e) {
0589: // Ignore
0590: }
0591: }
0592: }
0593: }
0594: }
0595: }
0596: }
0597: Collection lCombinedTypes = pServicemodule.getCombinedTypes();
0598: for (Iterator lCombinedTypesIterator = lCombinedTypes
0599: .iterator(); lCombinedTypesIterator.hasNext();) {
0600: ModelElement lType = (ModelElement) lCombinedTypesIterator
0601: .next();
0602: if ((lType instanceof Structure) == false)
0603: continue;
0604: Structure lStructure = (Structure) lType;
0605: STStructureStylesheet lStructureStylesheet = CodeGenerationStylesheetAccessor
0606: .getStructureStylesheet(lStructure);
0607: String lStructureProxyPackageName = getPackageNameForStructure(lStructure);
0608: String lStructureProxySourceDirectoryPath = pGenerationDirectoryPath
0609: + File.separator
0610: + StringUtils.replace(lStructureProxyPackageName,
0611: ".", File.separator);
0612: DirectoryUtils
0613: .ensureThereIsDirectory(lStructureProxySourceDirectoryPath);
0614: String lStructureProxyFileName = lStructureProxySourceDirectoryPath
0615: + File.separator
0616: + lStructureStylesheet.getProxyClassName()
0617: + ".java";
0618: FileWriter lFileWriter = null;
0619: PrintWriter lWriter = null;
0620: try {
0621: lWriter = new PrintWriter(lFileWriter = new FileWriter(
0622: lStructureProxyFileName));
0623: CopyrightUtils.writeCopyrightToGeneratedJavaSource(
0624: lWriter, getClass());
0625: lWriter.println("package " + lStructureProxyPackageName
0626: + ";");
0627: lWriter.println();
0628: // Construct description
0629: String lDescription = lStructure.getDescription();
0630: if (lDescription == null
0631: || lDescription.trim().length() == 0)
0632: lDescription = lDocumentationStylesheet
0633: .getMissingDescriptionHtmlText();
0634: lWriter.println("/** " + lDescription);
0635: lWriter.println(" *<P>This class represents the "
0636: + lStructure.getRef() + " structure.");
0637: lWriter
0638: .println(" * It is a simple value carrier class, which may be thought of as a composite data type.");
0639: lWriter
0640: .println(" * Every field of this structure is just plain public (directly accessible) field.</p>");
0641: lWriter
0642: .println(" *<P><I><U>Field values note</U> If field is null - it is interpreted as \"not specified by client\" or \"not retrieved from the storage\"");
0643: lWriter
0644: .println(" * Compare this to the empty string or zero length array - they are interpreted as specified or retrieved empty data value");
0645: lWriter
0646: .println(" * For example if null field is submitted for update operation - it will be ignored and value in storage will not be changed");
0647: lWriter
0648: .println(" * On the other hand if empty string or zero-length array is submitted for update operation - the values in storage will be updated accordingly</I>");
0649: lWriter.println(" */");
0650: lWriter.println("public final class "
0651: + lStructureStylesheet.getProxyClassName());
0652: lWriter.println("{");
0653: Collection lFields = lStructure.getFields();
0654: for (Iterator lFieldsIterator = lFields.iterator(); lFieldsIterator
0655: .hasNext();) {
0656: StructureField lField = (StructureField) lFieldsIterator
0657: .next();
0658: STStructureFieldStylesheet lStructureFieldStylesheet = CodeGenerationStylesheetAccessor
0659: .getStructureFieldStylesheet(lField);
0660: String lFieldDescription = lField.getDescription();
0661: if (lFieldDescription == null
0662: || lFieldDescription.length() == 0)
0663: lFieldDescription = lDocumentationStylesheet
0664: .getMissingDescriptionHtmlText();
0665: if (lField.getDataType() != null) {
0666: DataType lDatatypeType = lField.getDataType();
0667: STDatatypeStylesheet lDatatypeStylesheet = CodeGenerationStylesheetAccessor
0668: .getDatatypeStylesheet(lDatatypeType);
0669: lWriter.println(" /** <p>"
0670: + lFieldDescription + "</p>");
0671: lWriter
0672: .println(" * <p>The range of string values this field can be populated with is governed by the ");
0673: lWriter.println(" * {@link "
0674: + lDatatypeStylesheet
0675: .getClassFullName() + " "
0676: + lDatatypeType.getName()
0677: + "} datatype.</p>");
0678: lWriter.println(" */");
0679: if (lField.isArray())
0680: lWriter.println(" public String[] "
0681: + lStructureFieldStylesheet
0682: .getNormalisedName() + ";");
0683: else
0684: lWriter.println(" public String "
0685: + lStructureFieldStylesheet
0686: .getNormalisedName() + ";");
0687: } else if (lField.getStructureType() != null) {
0688: Structure lFieldStructure = lField
0689: .getStructureType();
0690: STStructureStylesheet lFieldStructureStylesheet = CodeGenerationStylesheetAccessor
0691: .getStructureStylesheet(lFieldStructure);
0692: String lFieldStructureProxyPackageName = getPackageNameForStructure(lFieldStructure);
0693: String lFieldStructureProxyFullName = lFieldStructureProxyPackageName
0694: + "."
0695: + lFieldStructureStylesheet
0696: .getProxyClassName();
0697: lWriter.println(" /** <p>"
0698: + lFieldDescription + "</p>");
0699: lWriter.println(" */");
0700: if (lField.isArray())
0701: lWriter.println(" public "
0702: + lFieldStructureProxyFullName
0703: + "[] "
0704: + lStructureFieldStylesheet
0705: .getNormalisedName() + ";");
0706: else
0707: lWriter.println(" public "
0708: + lFieldStructureProxyFullName
0709: + " "
0710: + lStructureFieldStylesheet
0711: .getNormalisedName() + ";");
0712: }
0713: }
0714: lWriter.println("}");
0715: } catch (IOException e) {
0716: throw new BSException("Unable to write file "
0717: + lStructureProxyFileName, e);
0718: } finally {
0719: if (lWriter != null) {
0720: lWriter.flush();
0721: lWriter.close();
0722: }
0723:
0724: if (lFileWriter != null) {
0725: try {
0726: lFileWriter.flush();
0727: } catch (IOException e) {
0728: // Ignore
0729: }
0730: try {
0731: lFileWriter.close();
0732: } catch (IOException e) {
0733: // Ignore
0734: }
0735: }
0736: }
0737: }
0738: }
0739:
0740: // Helper. Generates translators for data structures
0741: private void generateStructureProxyTranslators(
0742: String pGenerationDirectoryPath,
0743: Servicemodule pServicemodule) throws BOException,
0744: BSException {
0745: // The IDL definition will be located in the top directory
0746: String lServicemoduleRef = pServicemodule.getRef();
0747: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
0748: .getServicemoduleStylesheet(pServicemodule);
0749: String lServicemoduleProxyPackageName = getPackageNameForServicemoduleServices(pServicemodule
0750: .getRef());
0751: String lServicemoduleProxySourceDirectoryPath = pGenerationDirectoryPath
0752: + File.separator
0753: + StringUtils.replace(lServicemoduleProxyPackageName,
0754: ".", File.separator);
0755: DirectoryUtils
0756: .ensureThereIsDirectory(lServicemoduleProxySourceDirectoryPath);
0757:
0758: // If we are using inner structures - create separate input output structure translator files
0759: if (mUseInnerClasses == false) {
0760: Collection lServices = pServicemodule.getServices();
0761: for (Iterator lServicesIterator = lServices.iterator(); lServicesIterator
0762: .hasNext();) {
0763: Service lService = (Service) lServicesIterator.next();
0764: Collection lOperations = lService.getOperations();
0765: for (Iterator lOperationsIterator = lOperations
0766: .iterator(); lOperationsIterator.hasNext();) {
0767: Operation lOperation = (Operation) lOperationsIterator
0768: .next();
0769: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
0770: .getOperationStylesheet(lOperation);
0771: // Work on generating input structure proxy translator
0772: {
0773: String lInputStructureProxyTranslatorFileName = lServicemoduleProxySourceDirectoryPath
0774: + File.separator
0775: + lOperationStylesheet
0776: .getInputProxyTranslatorOuterClassName()
0777: + ".java";
0778: FileWriter lFileWriter = null;
0779: PrintWriter lWriter = null;
0780: try {
0781: lWriter = new PrintWriter(
0782: lFileWriter = new FileWriter(
0783: lInputStructureProxyTranslatorFileName));
0784: CopyrightUtils
0785: .writeCopyrightToGeneratedJavaSource(
0786: lWriter, getClass());
0787: lWriter.println("package "
0788: + lServicemoduleProxyPackageName
0789: + ";");
0790: lWriter.println();
0791: lWriter
0792: .println("import com.metaboss.enterprise.datatypes.DataTypeValidationException;");
0793: lWriter
0794: .println("import com.metaboss.enterprise.datatypes.DataTypeFieldValidationException;");
0795: // Call helper method to generate proxy translator code as outer class
0796: lWriter.println();
0797: generateInputProxyTranslatorCode(lWriter,
0798: lOperation, false);
0799: } catch (IOException e) {
0800: throw new BSException(
0801: "Unable to write file "
0802: + lInputStructureProxyTranslatorFileName,
0803: e);
0804: } finally {
0805: if (lWriter != null) {
0806: lWriter.flush();
0807: lWriter.close();
0808: }
0809:
0810: if (lFileWriter != null) {
0811: try {
0812: lFileWriter.flush();
0813: } catch (IOException e) {
0814: // Ignore
0815: }
0816: try {
0817: lFileWriter.close();
0818: } catch (IOException e) {
0819: // Ignore
0820: }
0821: }
0822: }
0823: }
0824: // Work on generating result structure proxy translator
0825: {
0826: String lResultStructureProxyTranslatorFileName = lServicemoduleProxySourceDirectoryPath
0827: + File.separator
0828: + lOperationStylesheet
0829: .getResultProxyTranslatorOuterClassName()
0830: + ".java";
0831: FileWriter lFileWriter = null;
0832: PrintWriter lWriter = null;
0833: try {
0834: lWriter = new PrintWriter(
0835: lFileWriter = new FileWriter(
0836: lResultStructureProxyTranslatorFileName));
0837: CopyrightUtils
0838: .writeCopyrightToGeneratedJavaSource(
0839: lWriter, getClass());
0840: lWriter.println("package "
0841: + lServicemoduleProxyPackageName
0842: + ";");
0843: lWriter.println();
0844: lWriter
0845: .println("import com.metaboss.enterprise.datatypes.DataTypeValidationException;");
0846: lWriter
0847: .println("import com.metaboss.enterprise.datatypes.DataTypeFieldValidationException;");
0848: lWriter.println();
0849: // Call helper method to generate result proxy translator code as outer class
0850: generateResultProxyTranslatorCode(lWriter,
0851: lOperation, false);
0852: } catch (IOException e) {
0853: throw new BSException(
0854: "Unable to write file "
0855: + lResultStructureProxyTranslatorFileName,
0856: e);
0857: } finally {
0858: if (lWriter != null) {
0859: lWriter.flush();
0860: lWriter.close();
0861: }
0862:
0863: if (lFileWriter != null) {
0864: try {
0865: lFileWriter.flush();
0866: } catch (IOException e) {
0867: // Ignore
0868: }
0869: try {
0870: lFileWriter.close();
0871: } catch (IOException e) {
0872: // Ignore
0873: }
0874: }
0875: }
0876: }
0877: }
0878: }
0879: }
0880: Collection lCombinedTypes = pServicemodule.getCombinedTypes();
0881: for (Iterator lCombinedTypesIterator = lCombinedTypes
0882: .iterator(); lCombinedTypesIterator.hasNext();) {
0883: ModelElement lType = (ModelElement) lCombinedTypesIterator
0884: .next();
0885: if ((lType instanceof Structure) == false)
0886: continue;
0887: Structure lStructure = (Structure) lType;
0888: STStructureStylesheet lStructureStylesheet = CodeGenerationStylesheetAccessor
0889: .getStructureStylesheet(lStructure);
0890: String lStructureProxyPackageName = getPackageNameForStructure(lStructure);
0891: String lStructureProxySourceDirectoryPath = pGenerationDirectoryPath
0892: + File.separator
0893: + StringUtils.replace(lStructureProxyPackageName,
0894: ".", File.separator);
0895: DirectoryUtils
0896: .ensureThereIsDirectory(lStructureProxySourceDirectoryPath);
0897: String lStructureProxyTranslatorFileName = lStructureProxySourceDirectoryPath
0898: + File.separator
0899: + lStructureStylesheet
0900: .getProxyTranslatorClassName() + ".java";
0901: String lStructureProxyClassFullName = lStructureProxyPackageName
0902: + "." + lStructureStylesheet.getProxyClassName();
0903: FileWriter lFileWriter = null;
0904: PrintWriter lWriter = null;
0905: try {
0906: lWriter = new PrintWriter(lFileWriter = new FileWriter(
0907: lStructureProxyTranslatorFileName));
0908: CopyrightUtils.writeCopyrightToGeneratedJavaSource(
0909: lWriter, getClass());
0910: lWriter.println("package " + lStructureProxyPackageName
0911: + ";");
0912: lWriter.println();
0913: lWriter
0914: .println("import com.metaboss.enterprise.datatypes.DataTypeValidationException;");
0915: lWriter
0916: .println("import com.metaboss.enterprise.datatypes.DataTypeFieldValidationException;");
0917: lWriter.println();
0918: lWriter
0919: .println("/** This class contains utilities to translate data between enterprise data structure and string based data structure.");
0920: lWriter
0921: .println(" * This class is used internally in the adapter, but it can also be used for translation externally. */");
0922: lWriter.println("public final class "
0923: + lStructureStylesheet
0924: .getProxyTranslatorClassName());
0925: lWriter.println("{");
0926: // Prevent creation of the instances by making constructor private");
0927: lWriter.println(" private "
0928: + lStructureStylesheet
0929: .getProxyTranslatorClassName() + " ()");
0930: lWriter.println(" {");
0931: lWriter.println(" }");
0932: lWriter.println();
0933: lWriter.println(" public static "
0934: + lStructureProxyClassFullName
0935: + "[] toProxyArray("
0936: + lStructureStylesheet.getClassFullName()
0937: + "[] pStructArray)");
0938: lWriter.println(" {");
0939: lWriter.println(" if (pStructArray == null)");
0940: lWriter.println(" return null;");
0941: lWriter.println(" "
0942: + lStructureProxyClassFullName
0943: + "[] lReturn = new "
0944: + lStructureProxyClassFullName
0945: + "[pStructArray.length];");
0946: lWriter
0947: .println(" for (int i = 0; i < lReturn.length; i++)");
0948: lWriter
0949: .println(" lReturn[i] = toProxy(pStructArray[i]);");
0950: lWriter.println(" return lReturn;");
0951: lWriter.println(" }");
0952: lWriter.println();
0953: lWriter
0954: .println(" public static "
0955: + lStructureStylesheet
0956: .getClassFullName()
0957: + "[] fromProxyArray("
0958: + lStructureProxyClassFullName
0959: + "[] pProxyArray) throws DataTypeFieldValidationException");
0960: lWriter.println(" {");
0961: lWriter.println(" if (pProxyArray == null)");
0962: lWriter.println(" return null;");
0963: lWriter.println(" "
0964: + lStructureStylesheet.getClassFullName()
0965: + "[] lReturn = new "
0966: + lStructureStylesheet.getClassFullName()
0967: + "[pProxyArray.length];");
0968: lWriter
0969: .println(" for (int i = 0; i < lReturn.length; i++)");
0970: lWriter
0971: .println(" lReturn[i] = fromProxy(pProxyArray[i]);");
0972: lWriter.println(" return lReturn;");
0973: lWriter.println(" }");
0974: lWriter.println();
0975: lWriter.println(" public static "
0976: + lStructureProxyClassFullName + " toProxy("
0977: + lStructureStylesheet.getClassFullName()
0978: + " pStruct)");
0979: lWriter.println(" {");
0980: lWriter.println(" if (pStruct == null)");
0981: lWriter.println(" return null;");
0982: lWriter.println(" "
0983: + lStructureProxyClassFullName
0984: + " lProxy = new "
0985: + lStructureProxyClassFullName + "();");
0986: Collection lFields = lStructure.getFields();
0987: for (Iterator lFieldsIterator = lFields.iterator(); lFieldsIterator
0988: .hasNext();) {
0989: StructureField lField = (StructureField) lFieldsIterator
0990: .next();
0991: STStructureFieldStylesheet lStructureFieldStylesheet = CodeGenerationStylesheetAccessor
0992: .getStructureFieldStylesheet(lField);
0993: if (lField.getDataType() != null) {
0994: DataType lDatatypeType = lField.getDataType();
0995: STDatatypeStylesheet lDatatypeStylesheet = CodeGenerationStylesheetAccessor
0996: .getDatatypeStylesheet(lDatatypeType);
0997: if (lField.isArray()) {
0998: lWriter.println(" "
0999: + lDatatypeStylesheet
1000: .getClassFullName()
1001: + "[] l"
1002: + lStructureFieldStylesheet
1003: .getNormalisedName()
1004: + " = pStruct.get"
1005: + lStructureFieldStylesheet
1006: .getNormalisedName()
1007: + "();");
1008: lWriter.println(" if (l"
1009: + lStructureFieldStylesheet
1010: .getNormalisedName()
1011: + " != null)");
1012: lWriter.println(" {");
1013: lWriter.println(" lProxy."
1014: + lStructureFieldStylesheet
1015: .getNormalisedName()
1016: + " = new String[l"
1017: + lStructureFieldStylesheet
1018: .getNormalisedName()
1019: + ".length];");
1020: lWriter
1021: .println(" for (int i = 0; i < l"
1022: + lStructureFieldStylesheet
1023: .getNormalisedName()
1024: + ".length; i++)");
1025: lWriter.println(" {");
1026: lWriter.println(" "
1027: + lDatatypeStylesheet
1028: .getClassFullName()
1029: + " l"
1030: + lStructureFieldStylesheet
1031: .getNormalisedName()
1032: + "Element = l"
1033: + lStructureFieldStylesheet
1034: .getNormalisedName()
1035: + "[i];");
1036: lWriter.println(" if (l"
1037: + lStructureFieldStylesheet
1038: .getNormalisedName()
1039: + "Element != null)");
1040: lWriter.println(" lProxy."
1041: + lStructureFieldStylesheet
1042: .getNormalisedName()
1043: + "[i] = l"
1044: + lStructureFieldStylesheet
1045: .getNormalisedName()
1046: + "Element.toString();");
1047: lWriter.println(" }");
1048: lWriter.println(" }");
1049: } else {
1050: lWriter.println(" "
1051: + lDatatypeStylesheet
1052: .getClassFullName()
1053: + " l"
1054: + lStructureFieldStylesheet
1055: .getNormalisedName()
1056: + " = pStruct.get"
1057: + lStructureFieldStylesheet
1058: .getNormalisedName()
1059: + "();");
1060: lWriter.println(" if (l"
1061: + lStructureFieldStylesheet
1062: .getNormalisedName()
1063: + " != null)");
1064: lWriter.println(" lProxy."
1065: + lStructureFieldStylesheet
1066: .getNormalisedName()
1067: + " = l"
1068: + lStructureFieldStylesheet
1069: .getNormalisedName()
1070: + ".toString();");
1071: }
1072: } else if (lField.getStructureType() != null) {
1073: Structure lFieldStructure = lField
1074: .getStructureType();
1075: STStructureStylesheet lFieldStructureStylesheet = CodeGenerationStylesheetAccessor
1076: .getStructureStylesheet(lFieldStructure);
1077: String lFieldStructureProxyPackageName = getPackageNameForStructure(lFieldStructure);
1078: String lFieldStructureProxyTranslatorFullName = lFieldStructureProxyPackageName
1079: + "."
1080: + lFieldStructureStylesheet
1081: .getProxyTranslatorClassName();
1082: if (lField.isArray())
1083: lWriter
1084: .println(" lProxy."
1085: + lStructureFieldStylesheet
1086: .getNormalisedName()
1087: + " = "
1088: + lFieldStructureProxyTranslatorFullName
1089: + ".toProxyArray( pStruct.get"
1090: + lStructureFieldStylesheet
1091: .getNormalisedName()
1092: + "());");
1093: else
1094: lWriter
1095: .println(" lProxy."
1096: + lStructureFieldStylesheet
1097: .getNormalisedName()
1098: + " = "
1099: + lFieldStructureProxyTranslatorFullName
1100: + ".toProxy( pStruct.get"
1101: + lStructureFieldStylesheet
1102: .getNormalisedName()
1103: + "());");
1104: }
1105: }
1106: lWriter.println(" return lProxy;");
1107: lWriter.println(" }");
1108:
1109: lWriter
1110: .println(" public static "
1111: + lStructureStylesheet
1112: .getClassFullName()
1113: + " fromProxy("
1114: + lStructureProxyClassFullName
1115: + " pProxy) throws DataTypeFieldValidationException");
1116: lWriter.println(" {");
1117: lWriter.println(" if (pProxy == null)");
1118: lWriter.println(" return null;");
1119: lWriter.println(" "
1120: + lStructureStylesheet.getClassFullName()
1121: + " lStruct = new "
1122: + lStructureStylesheet.getClassFullName()
1123: + "();");
1124: for (Iterator lFieldsIterator = lFields.iterator(); lFieldsIterator
1125: .hasNext();) {
1126: StructureField lField = (StructureField) lFieldsIterator
1127: .next();
1128: STStructureFieldStylesheet lStructureFieldStylesheet = CodeGenerationStylesheetAccessor
1129: .getStructureFieldStylesheet(lField);
1130: lWriter.println(" try");
1131: lWriter.println(" {");
1132: if (lField.getDataType() != null) {
1133: DataType lDatatypeType = lField.getDataType();
1134: STDatatypeStylesheet lDatatypeStylesheet = CodeGenerationStylesheetAccessor
1135: .getDatatypeStylesheet(lDatatypeType);
1136: if (lField.isArray()) {
1137: lWriter.println(" if (pProxy."
1138: + lStructureFieldStylesheet
1139: .getNormalisedName()
1140: + " != null)");
1141: lWriter.println(" {");
1142: lWriter.println(" "
1143: + lDatatypeStylesheet
1144: .getClassFullName()
1145: + "[] l"
1146: + lStructureFieldStylesheet
1147: .getNormalisedName()
1148: + " = new "
1149: + lDatatypeStylesheet
1150: .getClassFullName()
1151: + "[pProxy."
1152: + lStructureFieldStylesheet
1153: .getNormalisedName()
1154: + ".length];");
1155: lWriter
1156: .println(" for (int i = 0; i < pProxy."
1157: + lStructureFieldStylesheet
1158: .getNormalisedName()
1159: + ".length; i++)");
1160: lWriter.println(" {");
1161: lWriter
1162: .println(" String l"
1163: + lStructureFieldStylesheet
1164: .getNormalisedName()
1165: + "Element = pProxy."
1166: + lStructureFieldStylesheet
1167: .getNormalisedName()
1168: + "[i];");
1169: lWriter.println(" if (l"
1170: + lStructureFieldStylesheet
1171: .getNormalisedName()
1172: + "Element != null)");
1173: lWriter.println(" l"
1174: + lStructureFieldStylesheet
1175: .getNormalisedName()
1176: + "[i] = "
1177: + lDatatypeStylesheet
1178: .getClassFullName()
1179: + ".createFromString(l"
1180: + lStructureFieldStylesheet
1181: .getNormalisedName()
1182: + "Element);");
1183: lWriter.println(" }");
1184: lWriter
1185: .println(" lStruct.set"
1186: + lStructureFieldStylesheet
1187: .getNormalisedName()
1188: + "(l"
1189: + lStructureFieldStylesheet
1190: .getNormalisedName()
1191: + ");");
1192: lWriter.println(" }");
1193: } else {
1194: lWriter.println(" if (pProxy."
1195: + lStructureFieldStylesheet
1196: .getNormalisedName()
1197: + " != null)");
1198: lWriter
1199: .println(" lStruct.set"
1200: + lStructureFieldStylesheet
1201: .getNormalisedName()
1202: + "("
1203: + lDatatypeStylesheet
1204: .getClassFullName()
1205: + ".createFromString(pProxy."
1206: + lStructureFieldStylesheet
1207: .getNormalisedName()
1208: + "));");
1209: }
1210: } else if (lField.getStructureType() != null) {
1211: Structure lFieldStructure = lField
1212: .getStructureType();
1213: STStructureStylesheet lFieldStructureStylesheet = CodeGenerationStylesheetAccessor
1214: .getStructureStylesheet(lFieldStructure);
1215: String lFieldStructureProxyPackageName = getPackageNameForStructure(lFieldStructure);
1216: String lFieldStructureProxyTranslatorFullName = lFieldStructureProxyPackageName
1217: + "."
1218: + lFieldStructureStylesheet
1219: .getProxyTranslatorClassName();
1220: if (lField.isArray())
1221: lWriter
1222: .println(" lStruct.set"
1223: + lStructureFieldStylesheet
1224: .getNormalisedName()
1225: + "("
1226: + lFieldStructureProxyTranslatorFullName
1227: + ".fromProxyArray( pProxy."
1228: + lStructureFieldStylesheet
1229: .getNormalisedName()
1230: + "));");
1231: else
1232: lWriter
1233: .println(" lStruct.set"
1234: + lStructureFieldStylesheet
1235: .getNormalisedName()
1236: + "("
1237: + lFieldStructureProxyTranslatorFullName
1238: + ".fromProxy( pProxy."
1239: + lStructureFieldStylesheet
1240: .getNormalisedName()
1241: + "));");
1242: }
1243: lWriter.println(" }");
1244: lWriter
1245: .println(" catch (DataTypeValidationException e)");
1246: lWriter.println(" {");
1247: lWriter
1248: .println(" throw new DataTypeFieldValidationException(\""
1249: + lStructureFieldStylesheet
1250: .getNormalisedName()
1251: + "\", e);");
1252: lWriter.println(" }");
1253: }
1254: lWriter.println(" return lStruct;");
1255: lWriter.println(" }");
1256: lWriter.println("}");
1257: } catch (IOException e) {
1258: throw new BSException("Unable to write file "
1259: + lStructureProxyTranslatorFileName, e);
1260: } finally {
1261: if (lWriter != null) {
1262: lWriter.flush();
1263: lWriter.close();
1264: }
1265:
1266: if (lFileWriter != null) {
1267: try {
1268: lFileWriter.flush();
1269: } catch (IOException e) {
1270: // Ignore
1271: }
1272: try {
1273: lFileWriter.close();
1274: } catch (IOException e) {
1275: // Ignore
1276: }
1277: }
1278: }
1279: }
1280: }
1281:
1282: // Helper. Generates message proxy structures
1283: private void generateMessageProxies(
1284: String pGenerationDirectoryPath, Collection pMessages)
1285: throws BOException, BSException {
1286: STDocumentationStylesheet lDocumentationStylesheet = CodeGenerationStylesheetAccessor
1287: .getDocumentationStylesheet();
1288: for (Iterator lIter = pMessages.iterator(); lIter.hasNext();) {
1289: Message lMessage = (Message) lIter.next();
1290: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
1291: .getMessageStylesheet(lMessage);
1292: String lAdapterPackageName = getPackageNameForMessage(lMessage);
1293: String lAdapterSourceDirectoryPath = pGenerationDirectoryPath
1294: + File.separator
1295: + StringUtils.replace(lAdapterPackageName, ".",
1296: File.separator);
1297: String lMessageProxyFileName = lAdapterSourceDirectoryPath
1298: + File.separator
1299: + lMessageStylesheet.getProxyClassName() + ".java";
1300: FileWriter lFileWriter = null;
1301: PrintWriter lWriter = null;
1302: DirectoryUtils
1303: .ensureThereIsDirectory(lAdapterSourceDirectoryPath);
1304: try {
1305: lWriter = new PrintWriter(lFileWriter = new FileWriter(
1306: lMessageProxyFileName));
1307: CopyrightUtils.writeCopyrightToGeneratedJavaSource(
1308: lWriter, getClass());
1309: lWriter.println("package " + lAdapterPackageName + ";");
1310: lWriter.println();
1311: // Construct description
1312: String lDescription = lMessage.getDescription();
1313: if (lDescription == null
1314: || lDescription.trim().length() == 0)
1315: lDescription = lDocumentationStylesheet
1316: .getMissingDescriptionHtmlText();
1317: lWriter.println("/** " + lDescription);
1318: lWriter.println(" *<P>This class represents the "
1319: + lMessage.getRef() + " message.");
1320: lWriter
1321: .println(" * It is a simple value carrier class, which may be thought of as a composite data type.");
1322: lWriter
1323: .println(" * Every field of this structure is just plain public (directly accessible) field.</p>");
1324: lWriter
1325: .println(" *<P><I><U>Field values note</U> If field is null - it is interpreted as \"not specified by client\" or \"not retrieved from the storage\"");
1326: lWriter
1327: .println(" * Compare this to the empty string or zero length array - they are interpreted as specified or retrieved empty data value");
1328: lWriter
1329: .println(" * For example if null field is submitted for update operation - it will be ignored and value in storage will not be changed");
1330: lWriter
1331: .println(" * On the other hand if empty string or zero-length array is submitted for update operation - the values in storage will be updated accordingly</I>");
1332: lWriter.println(" */");
1333: lWriter.println("public final class "
1334: + lMessageStylesheet.getProxyClassName());
1335: lWriter.println("{");
1336: Collection lMessageFields = lMessage.getFields();
1337: for (Iterator lMessageFieldsIterator = lMessageFields
1338: .iterator(); lMessageFieldsIterator.hasNext();) {
1339: MessageField lField = (MessageField) lMessageFieldsIterator
1340: .next();
1341: STMessageFieldStylesheet lMessageFieldStylesheet = CodeGenerationStylesheetAccessor
1342: .getMessageFieldStylesheet(lField);
1343: String lFieldDescription = lField.getDescription();
1344: if (lFieldDescription == null
1345: || lFieldDescription.length() == 0)
1346: lFieldDescription = lDocumentationStylesheet
1347: .getMissingDescriptionHtmlText();
1348: lWriter.println(" /** " + lFieldDescription
1349: + " */");
1350: DataType lFieldType = lField.getDataType();
1351: STDatatypeStylesheet lDatatypeStylesheet = CodeGenerationStylesheetAccessor
1352: .getDatatypeStylesheet(lFieldType);
1353: lWriter.println(" public String "
1354: + lMessageFieldStylesheet
1355: .getNormalisedName() + ";");
1356: }
1357: lWriter.println("}");
1358: } catch (IOException e) {
1359: throw new BSException("Unable to write file "
1360: + lMessageProxyFileName, e);
1361: } finally {
1362: if (lWriter != null) {
1363: lWriter.flush();
1364: lWriter.close();
1365: }
1366:
1367: if (lFileWriter != null) {
1368: try {
1369: lFileWriter.flush();
1370: } catch (IOException e) {
1371: // Ignore
1372: }
1373: try {
1374: lFileWriter.close();
1375: } catch (IOException e) {
1376: // Ignore
1377: }
1378: }
1379: }
1380: }
1381: }
1382:
1383: // Helper. Generates translators for data structures
1384: private void generateMessageProxyTranslators(
1385: String pGenerationDirectoryPath, Collection pMessages)
1386: throws BOException, BSException {
1387: STDocumentationStylesheet lDocumentationStylesheet = CodeGenerationStylesheetAccessor
1388: .getDocumentationStylesheet();
1389: for (Iterator lIter = pMessages.iterator(); lIter.hasNext();) {
1390: Message lMessage = (Message) lIter.next();
1391: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
1392: .getMessageStylesheet(lMessage);
1393: String lAdapterPackageName = getPackageNameForMessage(lMessage);
1394: String lAdapterSourceDirectoryPath = pGenerationDirectoryPath
1395: + File.separator
1396: + StringUtils.replace(lAdapterPackageName, ".",
1397: File.separator);
1398: String lMessageProxyTranslatorFileName = lAdapterSourceDirectoryPath
1399: + File.separator
1400: + lMessageStylesheet.getProxyTranslatorClassName()
1401: + ".java";
1402: String lMessageProxyClassFullName = lAdapterPackageName
1403: + "." + lMessageStylesheet.getProxyClassName();
1404: FileWriter lFileWriter = null;
1405: PrintWriter lWriter = null;
1406: DirectoryUtils
1407: .ensureThereIsDirectory(lAdapterSourceDirectoryPath);
1408: try {
1409: lWriter = new PrintWriter(lFileWriter = new FileWriter(
1410: lMessageProxyTranslatorFileName));
1411: CopyrightUtils.writeCopyrightToGeneratedJavaSource(
1412: lWriter, getClass());
1413: lWriter.println("package " + lAdapterPackageName + ";");
1414: lWriter.println();
1415: lWriter
1416: .println("import com.metaboss.enterprise.datatypes.DataTypeValidationException;");
1417: lWriter
1418: .println("import com.metaboss.enterprise.datatypes.DataTypeFieldValidationException;");
1419: lWriter.println();
1420: lWriter
1421: .println("/** This class contains utilities to translate data between enterprise data structure and string based data structure.");
1422: lWriter
1423: .println(" * This class is used internally in the adapter, but it can also be used for translation externally. */");
1424: lWriter.println("public final class "
1425: + lMessageStylesheet
1426: .getProxyTranslatorClassName());
1427: lWriter.println("{");
1428: // Prevent creation of the instances by making constructor private");
1429: lWriter.println(" private "
1430: + lMessageStylesheet
1431: .getProxyTranslatorClassName() + " ()");
1432: lWriter.println(" {");
1433: lWriter.println(" }");
1434: lWriter.println();
1435: lWriter.println(" public static "
1436: + lMessageProxyClassFullName
1437: + "[] toProxyArray("
1438: + lMessageStylesheet.getClassFullName()
1439: + "[] pMessageArray)");
1440: lWriter.println(" {");
1441: lWriter.println(" if (pMessageArray == null)");
1442: lWriter.println(" return null;");
1443: lWriter.println(" " + lMessageProxyClassFullName
1444: + "[] lReturn = new "
1445: + lMessageProxyClassFullName
1446: + "[pMessageArray.length];");
1447: lWriter
1448: .println(" for (int i = 0; i < lReturn.length; i++)");
1449: lWriter
1450: .println(" lReturn[i] = toProxy(pMessageArray[i]);");
1451: lWriter.println(" return lReturn;");
1452: lWriter.println(" }");
1453:
1454: lWriter
1455: .println(" public static "
1456: + lMessageStylesheet.getClassFullName()
1457: + "[] fromProxyArray("
1458: + lMessageProxyClassFullName
1459: + "[] pProxyArray) throws DataTypeFieldValidationException");
1460: lWriter.println(" {");
1461: lWriter.println(" if (pProxyArray == null)");
1462: lWriter.println(" return null;");
1463: lWriter.println(" "
1464: + lMessageStylesheet.getClassFullName()
1465: + "[] lReturn = new "
1466: + lMessageStylesheet.getClassFullName()
1467: + "[pProxyArray.length];");
1468: lWriter
1469: .println(" for (int i = 0; i < lReturn.length; i++)");
1470: lWriter
1471: .println(" lReturn[i] = fromProxy(pProxyArray[i]);");
1472: lWriter.println(" return lReturn;");
1473: lWriter.println(" }");
1474:
1475: lWriter.println(" public static "
1476: + lMessageProxyClassFullName + " toProxy("
1477: + lMessageStylesheet.getClassFullName()
1478: + " pMessage)");
1479: lWriter.println(" {");
1480: lWriter.println(" if (pMessage == null)");
1481: lWriter.println(" return null;");
1482: lWriter.println(" " + lMessageProxyClassFullName
1483: + " lProxy = new " + lMessageProxyClassFullName
1484: + "();");
1485: Collection lMessageFields = lMessage.getFields();
1486: for (Iterator lMessageFieldsIterator = lMessageFields
1487: .iterator(); lMessageFieldsIterator.hasNext();) {
1488: MessageField lField = (MessageField) lMessageFieldsIterator
1489: .next();
1490: STMessageFieldStylesheet lMessageFieldStylesheet = CodeGenerationStylesheetAccessor
1491: .getMessageFieldStylesheet(lField);
1492: DataType lFieldType = lField.getDataType();
1493: STDatatypeStylesheet lDatatypeStylesheet = CodeGenerationStylesheetAccessor
1494: .getDatatypeStylesheet(lFieldType);
1495: lWriter.println(" "
1496: + lDatatypeStylesheet.getClassFullName()
1497: + " l"
1498: + lMessageFieldStylesheet
1499: .getNormalisedName()
1500: + " = pMessage.get"
1501: + lMessageFieldStylesheet
1502: .getNormalisedName() + "();");
1503: lWriter.println(" if (l"
1504: + lMessageFieldStylesheet
1505: .getNormalisedName() + " != null)");
1506: lWriter.println(" lProxy."
1507: + lMessageFieldStylesheet
1508: .getNormalisedName()
1509: + " = l"
1510: + lMessageFieldStylesheet
1511: .getNormalisedName()
1512: + ".toString();");
1513: }
1514: lWriter.println(" return lProxy;");
1515: lWriter.println(" }");
1516:
1517: lWriter
1518: .println(" public static "
1519: + lMessageStylesheet.getClassFullName()
1520: + " fromProxy("
1521: + lMessageProxyClassFullName
1522: + " pProxy) throws DataTypeFieldValidationException");
1523: lWriter.println(" {");
1524: lWriter.println(" if (pProxy == null)");
1525: lWriter.println(" return null;");
1526: lWriter
1527: .println(" "
1528: + lMessageStylesheet.getClassFullName()
1529: + " lReturn = new "
1530: + lMessageStylesheet.getClassFullName()
1531: + "();");
1532: for (Iterator lMessageFieldsIterator = lMessageFields
1533: .iterator(); lMessageFieldsIterator.hasNext();) {
1534: MessageField lField = (MessageField) lMessageFieldsIterator
1535: .next();
1536: STMessageFieldStylesheet lMessageFieldStylesheet = CodeGenerationStylesheetAccessor
1537: .getMessageFieldStylesheet(lField);
1538: lWriter.println(" try");
1539: lWriter.println(" {");
1540: DataType lFieldType = lField.getDataType();
1541: STDatatypeStylesheet lDatatypeStylesheet = CodeGenerationStylesheetAccessor
1542: .getDatatypeStylesheet(lFieldType);
1543: lWriter.println(" if (pProxy."
1544: + lMessageFieldStylesheet
1545: .getNormalisedName() + " != null)");
1546: lWriter.println(" lReturn.set"
1547: + lMessageFieldStylesheet
1548: .getNormalisedName()
1549: + "("
1550: + lDatatypeStylesheet.getClassFullName()
1551: + ".createFromString(pProxy."
1552: + lMessageFieldStylesheet
1553: .getNormalisedName() + "));");
1554: lWriter.println(" }");
1555: lWriter
1556: .println(" catch (DataTypeValidationException e)");
1557: lWriter.println(" {");
1558: lWriter
1559: .println(" throw new DataTypeFieldValidationException(\""
1560: + lMessageFieldStylesheet
1561: .getNormalisedName()
1562: + "\", e);");
1563: lWriter.println(" }");
1564: }
1565: lWriter.println(" return lReturn;");
1566: lWriter.println(" }");
1567: lWriter.println("}");
1568: } catch (IOException e) {
1569: throw new BSException("Unable to write file "
1570: + lMessageProxyTranslatorFileName, e);
1571: } finally {
1572: if (lWriter != null) {
1573: lWriter.flush();
1574: lWriter.close();
1575: }
1576:
1577: if (lFileWriter != null) {
1578: try {
1579: lFileWriter.flush();
1580: } catch (IOException e) {
1581: // Ignore
1582: }
1583: try {
1584: lFileWriter.close();
1585: } catch (IOException e) {
1586: // Ignore
1587: }
1588: }
1589: }
1590: }
1591: }
1592:
1593: // Generates an interface description for the adapter package
1594: private void generateServicesPackageDescription(
1595: String pPackageName, String pPackageDirectory,
1596: Servicemodule pServicemodule) throws BSException {
1597: FileWriter lFileWriter = null;
1598: PrintWriter lWriter = null;
1599: // Generate services interface
1600: try {
1601: String lFileName = pPackageDirectory + File.separator
1602: + "package.html";
1603: lWriter = new PrintWriter(lFileWriter = new FileWriter(
1604: lFileName));
1605: lWriter.println("<html>");
1606: lWriter.println(" <body>");
1607: lWriter.println(" <p>");
1608: lWriter
1609: .println(" This package contains adapter between simple String based java client and enterprise implementation of the "
1610: + pServicemodule.getRef()
1611: + " servicemodule.");
1612: lWriter
1613: .println(" In other words it is a translation library, which allows to access services in the "
1614: + pServicemodule.getRef()
1615: + " servicemodule using simple structures based on java.lang.String fields");
1616: lWriter
1617: .println(" and not strongly typed ones. This package consists of classes, which fall into one of the following categories:");
1618: lWriter.println(" <ul>");
1619: lWriter.println(" <li>");
1620: lWriter
1621: .println(" <u>Busines Service Adapter</u> This class provides set of adapter methods - each one wrapping around an original operation, which could be found in ");
1622: lWriter
1623: .println(" original business service. There is a separate Busines Service Adapter per each Busines Service in the original servicemodule.");
1624: lWriter
1625: .println(" The name of this class usually same as the name of the corresponding Busines Service interface prefixed with \"AD\" (<i>stands for ADapter</i>).");
1626: lWriter.println(" </li>");
1627: lWriter.println(" <li>");
1628: lWriter
1629: .println(" <u>Data Structure Proxy</u>This class is a variant of the underlying data structure where each and every field has a type of java.lang.String. ");
1630: lWriter
1631: .println(" There is a separate Data Structure Proxy class per each Data Structure in the original servicemodule, including operation input and output structures.");
1632: lWriter
1633: .println(" The name of this class usually same as the name of the corresponding Data Structure prefixed with \"PX\" (<i>stands for ProXy</i>).");
1634: lWriter.println(" </li>");
1635: lWriter.println(" <li>");
1636: lWriter
1637: .println(" <u>Data Structure Proxy Translator</u> This class is a utility class used to convert data between Data Structure Proxy and corresponding Data Structure. ");
1638: lWriter
1639: .println(" There is a separate Data Structure Proxy Translator class per each Data Structure in the original servicemodule, including operation input and output structures.");
1640: lWriter
1641: .println(" The name of this class usually same as the name of the corresponding Data Structure prefixed with \"TR\" (<i>stands for TRanslator</i>).");
1642: lWriter
1643: .println(" The Adapter classes use Translator classes internally to translate data and simple client code does not really have to deal with Translator classes directly.");
1644: lWriter
1645: .println(" Despite of this, Translator classes are public and available for use in any java code requiring such translation.");
1646: lWriter.println(" </li>");
1647: lWriter.println(" <li>");
1648: lWriter
1649: .println(" <u>Message Object Proxy</u>This class is a variant of the underlying message object where each and every field has a type of java.lang.String. ");
1650: lWriter
1651: .println(" There is a separate Message Object Proxy class per each Message Object in the original servicemodule.");
1652: lWriter
1653: .println(" The name of this class usually same as the name of the corresponding Message Object prefixed with \"PX\" (<i>stands for ProXy</i>).");
1654: lWriter.println(" </li>");
1655: lWriter.println(" <li>");
1656: lWriter
1657: .println(" <u>Message Object Proxy Translator</u> This class is a utility class used to convert data between Message Object Proxy and corresponding Message Object. ");
1658: lWriter
1659: .println(" There is a separate Message Object Proxy Translator class per each Message Object in the original servicemodule.");
1660: lWriter
1661: .println(" The name of this class usually same as the name of the corresponding Message Object prefixed with \"TR\" (<i>stands for TRanslator</i>).");
1662: lWriter
1663: .println(" The Adapter classes use Translator classes internally to translate data and simple client code does not really have to deal with Translator classes directly.");
1664: lWriter
1665: .println(" Despite of this, Translator classes are public and available for use in any java code requiring such translation.");
1666: lWriter.println(" </li>");
1667: lWriter.println(" </ul>");
1668: lWriter.println(" </p>");
1669: lWriter.println(" <p>");
1670: lWriter
1671: .println(" Simple example below shows the typical client code using this adapter:");
1672: lWriter.println(" <pre><kbd><code>");
1673: lWriter
1674: .println(" <font color=\"green\">// Import adapter package contents</font>");
1675: lWriter
1676: .println(" import com.someenterprise.somesystem.adapters.someservicemodule.generic.stringstructures.*;");
1677: lWriter.println(" ............");
1678: lWriter.println(" ............");
1679: lWriter
1680: .println(" <font color=\"green\">// Create adapter class</font>");
1681: lWriter
1682: .println(" ADBSSomeService lAdapter = new ADBSSomeService();");
1683: lWriter.println(" ............");
1684: lWriter.println(" ............");
1685: lWriter
1686: .println(" <font color=\"green\">// Create and populate operation input structure</font>");
1687: if (mUseInnerClasses)
1688: lWriter
1689: .println(" ADBSSomeService.PXSTSomeOperationInput lOperationInput = new ADBSSomeService.PXSTSomeOperationInput();");
1690: else
1691: lWriter
1692: .println(" PXSTSomeServiceSomeOperationInput lOperationInput = new PXSTSomeServiceSomeOperationInput();");
1693: lWriter.println(" lInput.SomeField = \"SomeValue\";");
1694: lWriter.println();
1695: lWriter
1696: .println(" <font color=\"green\">// Execute operation</font>");
1697: if (mUseInnerClasses)
1698: lWriter
1699: .println(" ADBSSomeService.PXSTSomeOperationResult lOperationResult = lAdapter.someOperation(lOperationInput);");
1700: else
1701: lWriter
1702: .println(" PXSTSomeServiceSomeOperationResult lOperationResult = lAdapter.someOperation(lOperationInput);");
1703: lWriter.println();
1704: lWriter
1705: .println(" <font color=\"green\">// Work with obtained operation results</font>");
1706: lWriter
1707: .println(" <font color=\"green\">// Note that result structure may have uninitialised members (set to null)</font>");
1708: lWriter
1709: .println(" if (lOperationResult.SomeField != null)");
1710: lWriter
1711: .println(" System.out.println(lOperationResult.SomeField);");
1712: lWriter.println(" ............");
1713: lWriter.println(" ............");
1714: lWriter.println(" </code></kbd></pre>");
1715: lWriter.println(" </p>");
1716: lWriter.println(" </body>");
1717: lWriter.println("</html>");
1718: } catch (IOException e) {
1719: throw new BSException(e);
1720: } catch (JmiException e) {
1721: throw new BSServiceProviderException(
1722: "Error while generating servicemodule interface package description. ServicemoduleRef : "
1723: + pServicemodule.getRef(), e);
1724: } finally {
1725: if (lWriter != null) {
1726: lWriter.flush();
1727: lWriter.close();
1728: }
1729: if (lFileWriter != null) {
1730: try {
1731: lFileWriter.flush();
1732: } catch (IOException e) {
1733: // Ignore
1734: }
1735: try {
1736: lFileWriter.close();
1737: } catch (IOException e) {
1738: // Ignore
1739: }
1740: }
1741: }
1742: }
1743:
1744: // Helper method. Generates the input structure proxy
1745: private void generateInputProxyCode(PrintWriter pWriter,
1746: Operation pOperation, boolean pAsInnerClass)
1747: throws BSException, BOException, IOException {
1748: String lIndent;
1749: STDocumentationStylesheet lDocumentationStylesheet = CodeGenerationStylesheetAccessor
1750: .getDocumentationStylesheet();
1751: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
1752: .getOperationStylesheet(pOperation);
1753: if (pAsInnerClass) {
1754: lIndent = " ";
1755: pWriter.println(lIndent
1756: + "/** This class contains an input to the "
1757: + pOperation.getName() + " operation */");
1758: pWriter.println(lIndent
1759: + "public static final class "
1760: + lOperationStylesheet
1761: .getInputProxyInnerClassName());
1762: } else {
1763: lIndent = "";
1764: pWriter
1765: .println(lIndent
1766: + "/** This class contains an input to the "
1767: + pOperation.getName()
1768: + " operation from the "
1769: + pOperation.getService().getName()
1770: + " service */");
1771: pWriter.println(lIndent
1772: + "public final class "
1773: + lOperationStylesheet
1774: .getInputProxyOuterClassName());
1775: }
1776: pWriter.println(lIndent + "{");
1777: Collection lInputFields = pOperation.getInputFields();
1778: for (Iterator lInputFieldsIterator = lInputFields.iterator(); lInputFieldsIterator
1779: .hasNext();) {
1780: OperationInputField lField = (OperationInputField) lInputFieldsIterator
1781: .next();
1782: STOperationInputFieldStylesheet lOperationInputFieldStylesheet = CodeGenerationStylesheetAccessor
1783: .getOperationInputFieldStylesheet(lField);
1784: String lFieldDescription = lField.getDescription();
1785: if (lFieldDescription == null
1786: || lFieldDescription.length() == 0)
1787: lFieldDescription = lDocumentationStylesheet
1788: .getMissingDescriptionHtmlText();
1789: if (lField.getDataType() != null) {
1790: DataType lDatatypeType = lField.getDataType();
1791: STDatatypeStylesheet lDatatypeStylesheet = CodeGenerationStylesheetAccessor
1792: .getDatatypeStylesheet(lDatatypeType);
1793: pWriter.println(" /** <p>" + lFieldDescription
1794: + "</p>");
1795: pWriter
1796: .println(" * <p>The range of string values this field can be populated with is governed by the ");
1797: pWriter.println(" * {@link "
1798: + lDatatypeStylesheet.getClassFullName() + " "
1799: + lDatatypeType.getName() + "} datatype.</p>");
1800: pWriter.println(" */");
1801: if (lField.isArray())
1802: pWriter.println(lIndent
1803: + " public String[] "
1804: + lOperationInputFieldStylesheet
1805: .getNormalisedName() + ";");
1806: else
1807: pWriter.println(lIndent
1808: + " public String "
1809: + lOperationInputFieldStylesheet
1810: .getNormalisedName() + ";");
1811: } else if (lField.getStructureType() != null) {
1812: Structure lFieldStructure = lField.getStructureType();
1813: STStructureStylesheet lFieldStructureStylesheet = CodeGenerationStylesheetAccessor
1814: .getStructureStylesheet(lFieldStructure);
1815: String lAdapterPackageName = getPackageNameForStructure(lFieldStructure);
1816: String lFieldStructureProxyFullName = lAdapterPackageName
1817: + "."
1818: + lFieldStructureStylesheet.getProxyClassName();
1819: pWriter.println(" /** <p>" + lFieldDescription
1820: + "</p>");
1821: pWriter.println(" */");
1822: if (lField.isArray())
1823: pWriter.println(lIndent
1824: + " public "
1825: + lFieldStructureProxyFullName
1826: + "[] "
1827: + lOperationInputFieldStylesheet
1828: .getNormalisedName() + ";");
1829: else
1830: pWriter.println(lIndent
1831: + " public "
1832: + lFieldStructureProxyFullName
1833: + " "
1834: + lOperationInputFieldStylesheet
1835: .getNormalisedName() + ";");
1836: }
1837: }
1838: pWriter.println(lIndent + "}");
1839: }
1840:
1841: // Helper method. Generates the input structure proxy translator
1842: private void generateInputProxyTranslatorCode(PrintWriter pWriter,
1843: Operation pOperation, boolean pAsInnerClass)
1844: throws BSException, BOException, IOException {
1845: String lIndent;
1846: String lProxyClassName;
1847: String lTranslatorClassName;
1848: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
1849: .getOperationStylesheet(pOperation);
1850: if (pAsInnerClass) {
1851: lIndent = " ";
1852: lProxyClassName = lOperationStylesheet
1853: .getInputProxyInnerClassName();
1854: lTranslatorClassName = lOperationStylesheet
1855: .getInputProxyTranslatorInnerClassName();
1856: pWriter
1857: .println(lIndent
1858: + "/** This class contains utilities to translate data between "
1859: + lOperationStylesheet
1860: .getInputClassFullName()
1861: + " enterprise data structure and");
1862: pWriter.println(lIndent + " * " + lProxyClassName
1863: + " string based proxy structure.");
1864: pWriter
1865: .println(lIndent
1866: + " * This class is used internally in the adapter, but it can also be used externally by any code needing translation. */");
1867: pWriter.println(lIndent + "public static final class "
1868: + lTranslatorClassName);
1869: } else {
1870: lIndent = "";
1871: lProxyClassName = lOperationStylesheet
1872: .getInputProxyOuterClassName();
1873: lTranslatorClassName = lOperationStylesheet
1874: .getInputProxyTranslatorOuterClassName();
1875: pWriter
1876: .println(lIndent
1877: + "/** This class contains utilities to translate data between "
1878: + lOperationStylesheet
1879: .getInputClassFullName()
1880: + " enterprise data structure and");
1881: pWriter.println(lIndent + " * " + lProxyClassName
1882: + " string based proxy structure.");
1883: pWriter
1884: .println(lIndent
1885: + " * This class is used internally in the adapter, but it can also be used externally by any code needing translation. */");
1886: pWriter.println(lIndent + "public final class "
1887: + lTranslatorClassName);
1888: }
1889: pWriter.println(lIndent + "{");
1890: pWriter.println(lIndent + " private " + lTranslatorClassName
1891: + " ()");
1892: pWriter.println(lIndent + " {");
1893: pWriter.println(lIndent + " }");
1894: pWriter.println();
1895: pWriter
1896: .println(lIndent
1897: + " /** This method converts string based operation input structure to the enterprise operation input structure. */");
1898: pWriter.println(lIndent + " public static "
1899: + lOperationStylesheet.getInputClassFullName()
1900: + " fromProxy( " + lProxyClassName
1901: + " pProxy) throws DataTypeFieldValidationException");
1902: pWriter.println(lIndent + " {");
1903: pWriter.println(lIndent + " "
1904: + lOperationStylesheet.getInputClassFullName()
1905: + " lStruct = new "
1906: + lOperationStylesheet.getInputClassFullName() + "();");
1907: Collection lInputFields = pOperation.getInputFields();
1908: for (Iterator lInputFieldsIterator = lInputFields.iterator(); lInputFieldsIterator
1909: .hasNext();) {
1910: OperationInputField lField = (OperationInputField) lInputFieldsIterator
1911: .next();
1912: STOperationInputFieldStylesheet lOperationInputFieldStylesheet = CodeGenerationStylesheetAccessor
1913: .getOperationInputFieldStylesheet(lField);
1914: pWriter.println(lIndent + " try");
1915: pWriter.println(lIndent + " {");
1916: if (lField.getDataType() != null) {
1917: DataType lDatatypeType = lField.getDataType();
1918: STDatatypeStylesheet lDatatypeStylesheet = CodeGenerationStylesheetAccessor
1919: .getDatatypeStylesheet(lDatatypeType);
1920: if (lField.isArray()) {
1921: pWriter.println(lIndent
1922: + " if (pProxy."
1923: + lOperationInputFieldStylesheet
1924: .getNormalisedName() + " != null)");
1925: pWriter.println(lIndent + " {");
1926: pWriter.println(lIndent
1927: + " "
1928: + lDatatypeStylesheet.getClassFullName()
1929: + "[] lStructArray = new "
1930: + lDatatypeStylesheet.getClassFullName()
1931: + "[pProxy."
1932: + lOperationInputFieldStylesheet
1933: .getNormalisedName() + ".length];");
1934: pWriter
1935: .println(lIndent
1936: + " for (int i = 0; i < lStructArray.length; i++)");
1937: pWriter.println(lIndent + " {");
1938: pWriter
1939: .println(lIndent
1940: + " String lProxyElement = pProxy."
1941: + lOperationInputFieldStylesheet
1942: .getNormalisedName()
1943: + "[i];");
1944: pWriter
1945: .println(lIndent
1946: + " if (lProxyElement != null)");
1947: pWriter
1948: .println(lIndent
1949: + " lStructArray[i] = "
1950: + lDatatypeStylesheet
1951: .getClassFullName()
1952: + ".createFromString(lProxyElement);");
1953: pWriter.println(lIndent + " }");
1954: pWriter.println(lIndent
1955: + " lStruct.set"
1956: + lOperationInputFieldStylesheet
1957: .getNormalisedName()
1958: + "(lStructArray);");
1959: pWriter.println(lIndent + " }");
1960: } else
1961: pWriter.println(lIndent
1962: + " lStruct.set"
1963: + lOperationInputFieldStylesheet
1964: .getNormalisedName()
1965: + "("
1966: + lDatatypeStylesheet.getClassFullName()
1967: + ".createFromString(pProxy."
1968: + lOperationInputFieldStylesheet
1969: .getNormalisedName() + "));");
1970: } else if (lField.getStructureType() != null) {
1971: Structure lFieldStructure = lField.getStructureType();
1972: STStructureStylesheet lFieldStructureStylesheet = CodeGenerationStylesheetAccessor
1973: .getStructureStylesheet(lFieldStructure);
1974: String lAdapterPackageName = getPackageNameForStructure(lFieldStructure);
1975: String lFieldStructureProxyTranslatorFullName = lAdapterPackageName
1976: + "."
1977: + lFieldStructureStylesheet
1978: .getProxyTranslatorClassName();
1979: if (lField.isArray())
1980: pWriter.println(lIndent
1981: + " lStruct.set"
1982: + lOperationInputFieldStylesheet
1983: .getNormalisedName()
1984: + "("
1985: + lFieldStructureProxyTranslatorFullName
1986: + ".fromProxyArray( pProxy."
1987: + lOperationInputFieldStylesheet
1988: .getNormalisedName() + "));");
1989: else
1990: pWriter.println(lIndent
1991: + " lStruct.set"
1992: + lOperationInputFieldStylesheet
1993: .getNormalisedName()
1994: + "("
1995: + lFieldStructureProxyTranslatorFullName
1996: + ".fromProxy( pProxy."
1997: + lOperationInputFieldStylesheet
1998: .getNormalisedName() + "));");
1999: }
2000: pWriter.println(lIndent + " }");
2001: pWriter.println(lIndent
2002: + " catch (DataTypeValidationException e)");
2003: pWriter.println(lIndent + " {");
2004: pWriter
2005: .println(lIndent
2006: + " throw new DataTypeFieldValidationException(\""
2007: + lOperationInputFieldStylesheet
2008: .getNormalisedName() + "\", e);");
2009: pWriter.println(lIndent + " }");
2010: }
2011: pWriter.println(lIndent + " return lStruct;");
2012: pWriter.println(lIndent + " }");
2013: pWriter.println(lIndent + "}");
2014: }
2015:
2016: // Helper method. Generates the result structure proxy
2017: private void generateResultProxyCode(PrintWriter pWriter,
2018: Operation pOperation, boolean pAsInnerClass)
2019: throws BSException, BOException, IOException {
2020: String lIndent;
2021: STDocumentationStylesheet lDocumentationStylesheet = CodeGenerationStylesheetAccessor
2022: .getDocumentationStylesheet();
2023: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
2024: .getOperationStylesheet(pOperation);
2025: Collection lOutputFields = pOperation.getOutputFields();
2026: Collection lOutputMessages = pOperation.getOutputMessages();
2027: if (pAsInnerClass) {
2028: lIndent = " ";
2029: pWriter.println(lIndent
2030: + "/** This class contains result of the "
2031: + pOperation.getName() + " operation. */");
2032: pWriter.println(lIndent
2033: + "public static final class "
2034: + lOperationStylesheet
2035: .getResultProxyInnerClassName());
2036: } else {
2037: lIndent = "";
2038: pWriter.println(lIndent
2039: + "/** This class contains result of the "
2040: + pOperation.getName() + " operation from the "
2041: + pOperation.getService().getName()
2042: + " service. */");
2043: pWriter.println(lIndent
2044: + "public final class "
2045: + lOperationStylesheet
2046: .getResultProxyOuterClassName());
2047: }
2048: pWriter.println(lIndent + "{");
2049: // Deal with messages first
2050: for (Iterator lOutputMessagesIterator = lOutputMessages
2051: .iterator(); lOutputMessagesIterator.hasNext();) {
2052: OperationOutputMessage lOutputMessage = (OperationOutputMessage) lOutputMessagesIterator
2053: .next();
2054: STOperationOutputMessageStylesheet lOperationOutputMessageStylesheet = CodeGenerationStylesheetAccessor
2055: .getOperationOutputMessageStylesheet(lOutputMessage);
2056: Message lMessage = lOutputMessage.getMessageType();
2057: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
2058: .getMessageStylesheet(lMessage);
2059: String lAdapterPackageName = getPackageNameForMessage(lMessage);
2060: String lMessageProxyFullName = lAdapterPackageName + "."
2061: + lMessageStylesheet.getProxyClassName();
2062: if (lOutputMessage.isArray())
2063: pWriter.println(lIndent
2064: + " public "
2065: + lMessageProxyFullName
2066: + "[] "
2067: + lOperationOutputMessageStylesheet
2068: .getNormalisedName() + "Messages;");
2069: else
2070: pWriter.println(lIndent
2071: + " public "
2072: + lMessageProxyFullName
2073: + " "
2074: + lOperationOutputMessageStylesheet
2075: .getNormalisedName() + "Message;");
2076: }
2077: for (Iterator lOutputFieldsIterator = lOutputFields.iterator(); lOutputFieldsIterator
2078: .hasNext();) {
2079: OperationOutputField lField = (OperationOutputField) lOutputFieldsIterator
2080: .next();
2081: STOperationOutputFieldStylesheet lOperationOutputFieldStylesheet = CodeGenerationStylesheetAccessor
2082: .getOperationOutputFieldStylesheet(lField);
2083: String lFieldDescription = lField.getDescription();
2084: if (lFieldDescription == null
2085: || lFieldDescription.length() == 0)
2086: lFieldDescription = lDocumentationStylesheet
2087: .getMissingDescriptionHtmlText();
2088: if (lField.getDataType() != null) {
2089: DataType lDatatypeType = lField.getDataType();
2090: STDatatypeStylesheet lDatatypeStylesheet = CodeGenerationStylesheetAccessor
2091: .getDatatypeStylesheet(lDatatypeType);
2092: pWriter.println(" /** <p>" + lFieldDescription
2093: + "</p>");
2094: pWriter
2095: .println(" * <p>The range of string values this field can be populated with is governed by the ");
2096: pWriter.println(" * {@link "
2097: + lDatatypeStylesheet.getClassFullName() + " "
2098: + lDatatypeType.getName() + "} datatype.</p>");
2099: pWriter.println(" */");
2100: if (lField.isArray())
2101: pWriter.println(lIndent
2102: + " public String[] "
2103: + lOperationOutputFieldStylesheet
2104: .getNormalisedName() + ";");
2105: else
2106: pWriter.println(lIndent
2107: + " public String "
2108: + lOperationOutputFieldStylesheet
2109: .getNormalisedName() + ";");
2110: } else if (lField.getStructureType() != null) {
2111: Structure lFieldStructure = lField.getStructureType();
2112: STStructureStylesheet lFieldStructureStylesheet = CodeGenerationStylesheetAccessor
2113: .getStructureStylesheet(lFieldStructure);
2114: String lAdapterPackageName = getPackageNameForStructure(lFieldStructure);
2115: String lFieldStructureProxyFullName = lAdapterPackageName
2116: + "."
2117: + lFieldStructureStylesheet.getProxyClassName();
2118: pWriter.println(" /** <p>" + lFieldDescription
2119: + "</p>");
2120: pWriter.println(" */");
2121: if (lField.isArray())
2122: pWriter.println(lIndent
2123: + " public "
2124: + lFieldStructureProxyFullName
2125: + "[] "
2126: + lOperationOutputFieldStylesheet
2127: .getNormalisedName() + ";");
2128: else
2129: pWriter.println(lIndent
2130: + " public "
2131: + lFieldStructureProxyFullName
2132: + " "
2133: + lOperationOutputFieldStylesheet
2134: .getNormalisedName() + ";");
2135: }
2136: }
2137: pWriter.println(lIndent + "}");
2138: }
2139:
2140: // Helper method. Generates the reult structure proxy translator
2141: private void generateResultProxyTranslatorCode(PrintWriter pWriter,
2142: Operation pOperation, boolean pAsInnerClass)
2143: throws BSException, BOException, IOException {
2144: String lIndent;
2145: String lProxyClassName;
2146: String lTranslatorClassName;
2147: STOperationStylesheet lOperationStylesheet = CodeGenerationStylesheetAccessor
2148: .getOperationStylesheet(pOperation);
2149: Servicemodule lServicemodule = pOperation.getService()
2150: .getServicemodule();
2151: Collection lOutputFields = pOperation.getOutputFields();
2152: Collection lOutputMessages = pOperation.getOutputMessages();
2153: if (pAsInnerClass) {
2154: lIndent = " ";
2155: lProxyClassName = lOperationStylesheet
2156: .getResultProxyInnerClassName();
2157: lTranslatorClassName = lOperationStylesheet
2158: .getResultProxyTranslatorInnerClassName();
2159: pWriter
2160: .println(lIndent
2161: + "/** This class contains utilities to translate data between "
2162: + lOperationStylesheet
2163: .getResultClassFullName()
2164: + " enterprise data structure and");
2165: pWriter.println(lIndent + " * " + lProxyClassName
2166: + " string based proxy structure.");
2167: pWriter
2168: .println(lIndent
2169: + " * This class is used internally in the adapter, but it can also be used externally by any code needing translation. */");
2170: pWriter.println(lIndent + "public static final class "
2171: + lTranslatorClassName);
2172: } else {
2173: lIndent = "";
2174: lProxyClassName = lOperationStylesheet
2175: .getResultProxyOuterClassName();
2176: lTranslatorClassName = lOperationStylesheet
2177: .getResultProxyTranslatorOuterClassName();
2178: pWriter
2179: .println(lIndent
2180: + "/** This class contains utilities to translate data between "
2181: + lOperationStylesheet
2182: .getResultClassFullName()
2183: + " enterprise data structure and");
2184: pWriter.println(lIndent + " * " + lProxyClassName
2185: + " string based proxy structure.");
2186: pWriter
2187: .println(lIndent
2188: + " * This class is used internally in the adapter, but it can also be used externally by any code needing translation. */");
2189: pWriter.println(lIndent + "public final class "
2190: + lTranslatorClassName);
2191: }
2192:
2193: pWriter.println(lIndent + "{");
2194: pWriter.println(lIndent + " private " + lTranslatorClassName
2195: + " ()");
2196: pWriter.println(lIndent + " {");
2197: pWriter.println(lIndent + " }");
2198: pWriter.println();
2199: pWriter
2200: .println(lIndent
2201: + " /** This method converts enterprise data structure to the string based proxy structure. */");
2202: pWriter.println(lIndent + " public static "
2203: + lProxyClassName + " toProxy( "
2204: + lOperationStylesheet.getResultClassFullName()
2205: + " pStruct)");
2206: pWriter.println(lIndent + " {");
2207: pWriter.println(lIndent + " " + lProxyClassName
2208: + " lProxy = new " + lProxyClassName + "();");
2209: // Deal with messages first
2210: for (Iterator lOutputMessagesIterator = lOutputMessages
2211: .iterator(); lOutputMessagesIterator.hasNext();) {
2212: OperationOutputMessage lOutputMessage = (OperationOutputMessage) lOutputMessagesIterator
2213: .next();
2214: STOperationOutputMessageStylesheet lOperationOutputMessageStylesheet = CodeGenerationStylesheetAccessor
2215: .getOperationOutputMessageStylesheet(lOutputMessage);
2216: Message lMessage = lOutputMessage.getMessageType();
2217: STMessageStylesheet lMessageStylesheet = CodeGenerationStylesheetAccessor
2218: .getMessageStylesheet(lMessage);
2219: String lMessageProxyTranslatorClass = null;
2220: if (lMessage.getServicemodule() == null
2221: || lMessage.getServicemodule().equals(
2222: lServicemodule) == false) {
2223: // Different servicemodule
2224: String lAdapterPackageName = getPackageNameForMessage(lMessage);
2225: lMessageProxyTranslatorClass = lAdapterPackageName
2226: + "."
2227: + lMessageStylesheet
2228: .getProxyTranslatorClassName();
2229: } else {
2230: // Same servicemodule
2231: lMessageProxyTranslatorClass = lMessageStylesheet
2232: .getProxyTranslatorClassName();
2233: }
2234: if (lOutputMessage.isArray())
2235: pWriter.println(lIndent
2236: + " lProxy."
2237: + lOperationOutputMessageStylesheet
2238: .getNormalisedName()
2239: + "Messages = "
2240: + lMessageProxyTranslatorClass
2241: + ".toProxyArray(pStruct.get"
2242: + lOperationOutputMessageStylesheet
2243: .getNormalisedName() + "());");
2244: else
2245: pWriter.println(lIndent
2246: + " lProxy."
2247: + lOperationOutputMessageStylesheet
2248: .getNormalisedName()
2249: + "Message = "
2250: + lMessageProxyTranslatorClass
2251: + ".toProxy(pStruct.get"
2252: + lOperationOutputMessageStylesheet
2253: .getNormalisedName() + "());");
2254: }
2255: for (Iterator lOutputFieldsIterator = lOutputFields.iterator(); lOutputFieldsIterator
2256: .hasNext();) {
2257: OperationOutputField lField = (OperationOutputField) lOutputFieldsIterator
2258: .next();
2259: STOperationOutputFieldStylesheet lOperationOutputFieldStylesheet = CodeGenerationStylesheetAccessor
2260: .getOperationOutputFieldStylesheet(lField);
2261: if (lField.getDataType() != null) {
2262: DataType lDatatypeType = lField.getDataType();
2263: STDatatypeStylesheet lDatatypeStylesheet = CodeGenerationStylesheetAccessor
2264: .getDatatypeStylesheet(lDatatypeType);
2265: if (lField.isArray()) {
2266: pWriter.println(lIndent
2267: + " "
2268: + lDatatypeStylesheet.getClassFullName()
2269: + "[] l"
2270: + lOperationOutputFieldStylesheet
2271: .getNormalisedName()
2272: + " = pStruct.get"
2273: + lOperationOutputFieldStylesheet
2274: .getNormalisedName() + "();");
2275: pWriter.println(lIndent
2276: + " if (l"
2277: + lOperationOutputFieldStylesheet
2278: .getNormalisedName() + " != null)");
2279: pWriter.println(lIndent + " {");
2280: pWriter.println(lIndent
2281: + " lProxy."
2282: + lOperationOutputFieldStylesheet
2283: .getNormalisedName()
2284: + " = new String[l"
2285: + lOperationOutputFieldStylesheet
2286: .getNormalisedName() + ".length];");
2287: pWriter.println(lIndent
2288: + " for (int i = 0; i < l"
2289: + lOperationOutputFieldStylesheet
2290: .getNormalisedName()
2291: + ".length; i++)");
2292: pWriter.println(lIndent + " {");
2293: pWriter.println(lIndent
2294: + " "
2295: + lDatatypeStylesheet.getClassFullName()
2296: + " l"
2297: + lOperationOutputFieldStylesheet
2298: .getNormalisedName()
2299: + "Element = l"
2300: + lOperationOutputFieldStylesheet
2301: .getNormalisedName() + "[i];");
2302: pWriter.println(lIndent
2303: + " if (l"
2304: + lOperationOutputFieldStylesheet
2305: .getNormalisedName()
2306: + "Element != null)");
2307: pWriter.println(lIndent
2308: + " lProxy."
2309: + lOperationOutputFieldStylesheet
2310: .getNormalisedName()
2311: + "[i] = l"
2312: + lOperationOutputFieldStylesheet
2313: .getNormalisedName()
2314: + "Element.toString();");
2315: pWriter.println(lIndent + " }");
2316: pWriter.println(lIndent + " }");
2317: } else {
2318: pWriter.println(lIndent
2319: + " "
2320: + lDatatypeStylesheet.getClassFullName()
2321: + " l"
2322: + lOperationOutputFieldStylesheet
2323: .getNormalisedName()
2324: + " = pStruct.get"
2325: + lOperationOutputFieldStylesheet
2326: .getNormalisedName() + "();");
2327: pWriter.println(lIndent
2328: + " if (l"
2329: + lOperationOutputFieldStylesheet
2330: .getNormalisedName() + " != null)");
2331: pWriter.println(lIndent
2332: + " lProxy."
2333: + lOperationOutputFieldStylesheet
2334: .getNormalisedName()
2335: + " = l"
2336: + lOperationOutputFieldStylesheet
2337: .getNormalisedName()
2338: + ".toString();");
2339: }
2340: } else if (lField.getStructureType() != null) {
2341: Structure lFieldStructure = lField.getStructureType();
2342: STStructureStylesheet lFieldStructureStylesheet = CodeGenerationStylesheetAccessor
2343: .getStructureStylesheet(lFieldStructure);
2344: String lFieldStructureProxyTranslatorFullName = getPackageNameForStructure(lFieldStructure)
2345: + "."
2346: + lFieldStructureStylesheet
2347: .getProxyTranslatorClassName();
2348: if (lField.isArray())
2349: pWriter.println(lIndent
2350: + " lProxy."
2351: + lOperationOutputFieldStylesheet
2352: .getNormalisedName()
2353: + " = "
2354: + lFieldStructureProxyTranslatorFullName
2355: + ".toProxyArray( pStruct.get"
2356: + lOperationOutputFieldStylesheet
2357: .getNormalisedName() + "());");
2358: else
2359: pWriter.println(lIndent
2360: + " lProxy."
2361: + lOperationOutputFieldStylesheet
2362: .getNormalisedName()
2363: + " = "
2364: + lFieldStructureProxyTranslatorFullName
2365: + ".toProxy( pStruct.get"
2366: + lOperationOutputFieldStylesheet
2367: .getNormalisedName() + "());");
2368: }
2369: }
2370: pWriter.println(lIndent + " return lProxy;");
2371: pWriter.println(lIndent + " }");
2372: pWriter.println(lIndent + "}");
2373: }
2374:
2375: private String getPackageNameForStructure(Structure pStructure)
2376: throws BSException {
2377: Servicemodule lOwnerServicemodule = pStructure
2378: .getServicemodule();
2379: DataDictionary lOwnerDataDictionary = pStructure
2380: .getOwnerDataDictionary();
2381: AbstractNamespace lAbstractNamespace = pStructure
2382: .getNamespace();
2383: if (lOwnerServicemodule != null) {
2384: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
2385: .getServicemoduleStylesheet(lOwnerServicemodule);
2386: return mUseInnerClasses ? lServicemoduleStylesheet
2387: .getServicesGenericStringStructuresAdapterPackageName()
2388: : lServicemoduleStylesheet
2389: .getServicesGenericSimplifiedStringStructuresAdapterPackageName();
2390: } else if (lOwnerDataDictionary != null) {
2391: STDataDictionaryStylesheet lDataDictionaryStylesheet = CodeGenerationStylesheetAccessor
2392: .getDataDictionaryStylesheet((DataDictionary) lOwnerDataDictionary);
2393: if (lAbstractNamespace instanceof DataDictionary) {
2394: if (lAbstractNamespace.equals(lOwnerDataDictionary))
2395: return (mUseInnerClasses ? lDataDictionaryStylesheet
2396: .getGenericStringStructuresAdapterPackageName()
2397: : lDataDictionaryStylesheet
2398: .getGenericSimplifiedStringStructuresAdapterPackageName());
2399: throw new BSUnexpectedProgramConditionException(
2400: "getNamespace() call is expected to return Owner Data Dictionary for the elements located at the top level of the Data Dictionary");
2401: } else if (lAbstractNamespace instanceof Namespace) {
2402: STNamespaceStylesheet lNamespaceStylesheet = CodeGenerationStylesheetAccessor
2403: .getNamespaceStylesheet((Namespace) lAbstractNamespace);
2404: return (mUseInnerClasses ? lDataDictionaryStylesheet
2405: .getGenericStringStructuresAdapterPackageName()
2406: : lDataDictionaryStylesheet
2407: .getGenericSimplifiedStringStructuresAdapterPackageName())
2408: + "."
2409: + lNamespaceStylesheet
2410: .getDictionarySubPackageName();
2411: } else
2412: throw new BSUnexpectedProgramConditionException(
2413: "Unrecognised concrete type of the AbstractNamespace.");
2414: } else
2415: throw new BSUnexpectedProgramConditionException(
2416: "Structure can only be contained inside Servicemodule or Data Dictionary.");
2417: }
2418:
2419: private String getPackageNameForMessage(Message pMessage)
2420: throws BSException {
2421: Servicemodule lOwnerServicemodule = pMessage.getServicemodule();
2422: DataDictionary lOwnerDataDictionary = pMessage
2423: .getOwnerDataDictionary();
2424: AbstractNamespace lAbstractNamespace = pMessage.getNamespace();
2425: if (lOwnerServicemodule != null) {
2426: STServicemoduleStylesheet lServicemoduleStylesheet = CodeGenerationStylesheetAccessor
2427: .getServicemoduleStylesheet(lOwnerServicemodule);
2428: return mUseInnerClasses ? lServicemoduleStylesheet
2429: .getServicesGenericStringStructuresAdapterPackageName()
2430: : lServicemoduleStylesheet
2431: .getServicesGenericSimplifiedStringStructuresAdapterPackageName();
2432: } else if (lOwnerDataDictionary != null) {
2433: STDataDictionaryStylesheet lDataDictionaryStylesheet = CodeGenerationStylesheetAccessor
2434: .getDataDictionaryStylesheet((DataDictionary) lOwnerDataDictionary);
2435: if (lAbstractNamespace instanceof DataDictionary) {
2436: if (lAbstractNamespace.equals(lOwnerDataDictionary))
2437: return (mUseInnerClasses ? lDataDictionaryStylesheet
2438: .getGenericStringStructuresAdapterPackageName()
2439: : lDataDictionaryStylesheet
2440: .getGenericSimplifiedStringStructuresAdapterPackageName());
2441: throw new BSUnexpectedProgramConditionException(
2442: "getNamespace() call is expected to return Owner Data Dictionary for the elements located at the top level of the Data Dictionary");
2443: } else if (lAbstractNamespace instanceof Namespace) {
2444: STNamespaceStylesheet lNamespaceStylesheet = CodeGenerationStylesheetAccessor
2445: .getNamespaceStylesheet((Namespace) lAbstractNamespace);
2446: return (mUseInnerClasses ? lDataDictionaryStylesheet
2447: .getGenericStringStructuresAdapterPackageName()
2448: : lDataDictionaryStylesheet
2449: .getGenericSimplifiedStringStructuresAdapterPackageName())
2450: + "."
2451: + lNamespaceStylesheet
2452: .getDictionarySubPackageName();
2453: } else
2454: throw new BSUnexpectedProgramConditionException(
2455: "Unrecognised concrete type of the AbstractNamespace.");
2456: } else
2457: throw new BSUnexpectedProgramConditionException(
2458: "Message can only be contained inside Servicemodule or Data Dictionary.");
2459: }
2460: }
|