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.applications.utils;
0016:
0017: import java.io.BufferedReader;
0018: import java.io.BufferedWriter;
0019: import java.io.File;
0020: import java.io.StringReader;
0021: import java.io.StringWriter;
0022: import java.util.ArrayList;
0023: import java.util.Arrays;
0024: import java.util.Collection;
0025: import java.util.Iterator;
0026: import java.util.List;
0027: import java.util.Map;
0028: import java.util.Properties;
0029: import java.util.StringTokenizer;
0030:
0031: import javax.naming.Context;
0032: import javax.naming.InitialContext;
0033:
0034: import org.apache.commons.logging.Log;
0035: import org.apache.commons.logging.LogFactory;
0036:
0037: import com.metaboss.enterprise.BaseException;
0038: import com.metaboss.sdlctools.domains.enterprisemodel.BOAssociation;
0039: import com.metaboss.sdlctools.domains.enterprisemodel.BOAssociationRole;
0040: import com.metaboss.sdlctools.domains.enterprisemodel.BOAttribute;
0041: import com.metaboss.sdlctools.domains.enterprisemodel.BOConstraint;
0042: import com.metaboss.sdlctools.domains.enterprisemodel.BODatatype;
0043: import com.metaboss.sdlctools.domains.enterprisemodel.BODomain;
0044: import com.metaboss.sdlctools.domains.enterprisemodel.BOEnterprise;
0045: import com.metaboss.sdlctools.domains.enterprisemodel.BOEntity;
0046: import com.metaboss.sdlctools.domains.enterprisemodel.BOField;
0047: import com.metaboss.sdlctools.domains.enterprisemodel.BOMessage;
0048: import com.metaboss.sdlctools.domains.enterprisemodel.BOMessageField;
0049: import com.metaboss.sdlctools.domains.enterprisemodel.BOMetaBossDomain;
0050: import com.metaboss.sdlctools.domains.enterprisemodel.BOOperation;
0051: import com.metaboss.sdlctools.domains.enterprisemodel.BOOutputMessage;
0052: import com.metaboss.sdlctools.domains.enterprisemodel.BOPrimaryKeyElement;
0053: import com.metaboss.sdlctools.domains.enterprisemodel.BOPropertyDescriptor;
0054: import com.metaboss.sdlctools.domains.enterprisemodel.BOReport;
0055: import com.metaboss.sdlctools.domains.enterprisemodel.BOReportEntity;
0056: import com.metaboss.sdlctools.domains.enterprisemodel.BOReportOutputElement;
0057: import com.metaboss.sdlctools.domains.enterprisemodel.BOSelector;
0058: import com.metaboss.sdlctools.domains.enterprisemodel.BOService;
0059: import com.metaboss.sdlctools.domains.enterprisemodel.BOServicemodule;
0060: import com.metaboss.sdlctools.domains.enterprisemodel.BOState;
0061: import com.metaboss.sdlctools.domains.enterprisemodel.BOStateTransition;
0062: import com.metaboss.sdlctools.domains.enterprisemodel.BOStructure;
0063: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystem;
0064: import com.metaboss.sdlctools.domains.enterprisemodel.BOTypetemplate;
0065: import com.metaboss.sdlctools.domains.storagemodel.BORelationalStorageTechnology;
0066: import com.metaboss.sdlctools.domains.storagemodel.BOStorageTechnology;
0067: import com.metaboss.sdlctools.models.ModelElementNotFoundException;
0068: import com.metaboss.sdlctools.models.ModelRepository;
0069: import com.metaboss.sdlctools.models.ModelValidationException;
0070: import com.metaboss.sdlctools.models.impl.metabossmodel.ModelElementResolverImpl;
0071: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
0072: import com.metaboss.sdlctools.models.metabossmodel.ModelElementAttachment;
0073: import com.metaboss.sdlctools.models.metabossmodel.ModelElementAttachmentClass;
0074: import com.metaboss.sdlctools.models.metabossmodel.ModelElementAttachmentUtils;
0075: import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraint;
0076: import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraintClass;
0077: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.AbstractNamespace;
0078: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
0079: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionaryClass;
0080: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionaryModelPackage;
0081: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
0082: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataTypeClass;
0083: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Namespace;
0084: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.NamespaceClass;
0085: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Property;
0086: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyClass;
0087: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptor;
0088: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptorClass;
0089: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
0090: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureClass;
0091: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureField;
0092: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureFieldClass;
0093: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplate;
0094: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplateClass;
0095: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.TypeTemplateLanguageEnum;
0096: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
0097: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibraryClass;
0098: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibraryModelPackage;
0099: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
0100: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseClass;
0101: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EnterpriseModelPackage;
0102: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
0103: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageClass;
0104: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageField;
0105: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageFieldClass;
0106: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageTypeEnum;
0107: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Operation;
0108: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationClass;
0109: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputField;
0110: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationInputFieldClass;
0111: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputField;
0112: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputFieldClass;
0113: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputMessage;
0114: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.OperationOutputMessageClass;
0115: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
0116: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.ServiceClass;
0117: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
0118: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.ServicemoduleClass;
0119: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.SystemClass;
0120: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationTypeEnum;
0121: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Association;
0122: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationClass;
0123: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
0124: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleCardinalityEnum;
0125: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleClass;
0126: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
0127: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeClass;
0128: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotypeEnum;
0129: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
0130: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.DomainClass;
0131: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
0132: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityClass;
0133: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotypeEnum;
0134: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Report;
0135: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportClass;
0136: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportInputField;
0137: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportInputFieldClass;
0138: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputElement;
0139: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputElementClass;
0140: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputEntity;
0141: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputEntityClass;
0142: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputField;
0143: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.ReportOutputFieldClass;
0144: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Selector;
0145: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorCardinalityEnum;
0146: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorClass;
0147: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorInputField;
0148: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorInputFieldClass;
0149: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
0150: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.State;
0151: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateClass;
0152: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
0153: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachineClass;
0154: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachineModelPackage;
0155: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateTypeEnum;
0156: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.Transition;
0157: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.TransitionClass;
0158: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.NameConversionTypeEnum;
0159: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.RelationalStorageTechnology;
0160: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.RelationalStorageTechnologyClass;
0161: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.TechnologyLibrary;
0162: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.TechnologyLibraryClass;
0163: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.TechnologyLibraryModelPackage;
0164: import com.metaboss.sdlctools.types.enterprisemodel.AssociationRoleCardinality;
0165: import com.metaboss.sdlctools.types.enterprisemodel.AssociationRoleStereotype;
0166: import com.metaboss.sdlctools.types.enterprisemodel.AttributeStereotype;
0167: import com.metaboss.sdlctools.types.enterprisemodel.EntityStereotype;
0168: import com.metaboss.sdlctools.types.enterprisemodel.MessageType;
0169: import com.metaboss.sdlctools.types.enterprisemodel.PrimaryKeyElementType;
0170: import com.metaboss.sdlctools.types.enterprisemodel.SelectorCardinality;
0171: import com.metaboss.sdlctools.types.enterprisemodel.StateType;
0172: import com.metaboss.sdlctools.types.enterprisemodel.TemplateSourceType;
0173: import com.metaboss.sdlctools.types.enterprisemodel.TransactionPolicy;
0174: import com.metaboss.sdlctools.types.storagemodel.NameConversionType;
0175: import com.metaboss.util.DirectoryUtils;
0176: import com.metaboss.util.MetaBossSpecificUtils;
0177: import com.oldboss.framework.bo.BOObject;
0178:
0179: /*
0180: * Created on 23/10/2003
0181: *
0182: * To change the template for this generated file go to
0183: * Window>Preferences>Java>Code Generation>Code and Comments
0184: */
0185:
0186: /**
0187: * @author Rost
0188: *
0189: * To change the template for this generated type comment go to
0190: * Window>Preferences>Java>Code Generation>Code and Comments
0191: */
0192: public class OldMetaBossModelConverter {
0193: // // Commons Logging instance.
0194: private static final Log sLogger = LogFactory
0195: .getLog(OldMetaBossModelConverter.class);
0196: private static ModelRepository sModelRepository = null;
0197: private static String sDesignLibraryModelName = null;
0198: private static String sTechnologyLibraryModelName = null;
0199:
0200: private static final String TECHLIB_MODEL_NAME = "TechLibModel";
0201:
0202: public static void main(String[] args) {
0203: try {
0204: // Read metaboss installation specific properties
0205: MetaBossSpecificUtils.setupSystemProperties();
0206:
0207: // Scan the arguments (must be three)
0208: if (args == null || args.length != 2)
0209: throw new IllegalArgumentException(
0210: "Invalid arguments passed to the generator. Expecting two arguments : <old model directory> <new model directory>");
0211: String lOldModelDirectory = args[0];
0212: String lNewModelDirectory = args[1];
0213: // Immediately setup system definition directory - needed for old model to work
0214: System.setProperty("MetaBoss.SystemDefinitionPath",
0215: lOldModelDirectory);
0216: // Initilaise design library
0217: sDesignLibraryModelName = System
0218: .getProperty("MetaBoss.Home")
0219: + File.separator
0220: + "designlib"
0221: + File.separator
0222: + "Model.xml";
0223: sTechnologyLibraryModelName = System
0224: .getProperty("MetaBoss.Home")
0225: + File.separator
0226: + "technologylib"
0227: + File.separator
0228: + "Model.xml";
0229:
0230: // Now create enterprise models
0231: convertEnterpriseModel(lNewModelDirectory);
0232: // Exit normally
0233: System.exit(0);
0234: } catch (Throwable t) {
0235: handleException(t);
0236: // Exit abnormally
0237: System.exit(-1);
0238: }
0239: }
0240:
0241: // Converts an enterprise model
0242: private static void convertEnterpriseModel(
0243: String pDestinationModelDirectory) throws Exception {
0244: try {
0245: Context lContext = new InitialContext();
0246: sModelRepository = (ModelRepository) lContext
0247: .lookup(ModelRepository.COMPONENT_URL);
0248: // Immediately open design and technology libraries
0249: sModelRepository.openModel(sDesignLibraryModelName,
0250: new File(sDesignLibraryModelName),
0251: "MetaBossMetaModel");
0252: sModelRepository.openModel(sTechnologyLibraryModelName,
0253: new File(sTechnologyLibraryModelName),
0254: "MetaBossMetaModel");
0255: // Iterate through enterprises and add them one by one
0256: BOMetaBossDomain lOriginalMetaBossDomain = (BOMetaBossDomain) lContext
0257: .lookup(BOMetaBossDomain.COMPONENT_URL);
0258: BOEnterprise[] lEnterprises = lOriginalMetaBossDomain
0259: .getEnterprises().getAllEnterprises();
0260: for (int i = 0; i < lEnterprises.length; i++) {
0261: BOEnterprise lEnterprise = lEnterprises[i];
0262: sLogger.info("Converting " + lEnterprise.getName()
0263: + " Enterprise...");
0264: File lEnterpriseModelFile = new File(
0265: pDestinationModelDirectory + File.separator
0266: + lEnterprise.getName()
0267: + File.separator + "Model.xml");
0268: String lModelName = lEnterprise.getName()
0269: + "Enterprise";
0270: DirectoryUtils
0271: .ensureNewCleanDirectory(lEnterpriseModelFile
0272: .getParentFile().getAbsolutePath());
0273: sModelRepository.createModel(lModelName,
0274: lEnterpriseModelFile,
0275: ModelRepository.METAMODEL_NAME_METABOSS, null);
0276: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) sModelRepository
0277: .getModelExtent(lModelName);
0278: try {
0279: addEnterprise(lOriginalMetaBossDomain, lEnterprise,
0280: lMetaBossModelPackage);
0281: sLogger.info("Done converting "
0282: + lEnterprise.getName() + " Enterprise");
0283: sLogger
0284: .info("Running model rectification process to repair constraint violations.....");
0285: sModelRepository.rectifyModel(lModelName);
0286: sLogger
0287: .info("Saving what we have just created.....");
0288: sModelRepository.saveModel(lModelName, false);
0289: sLogger
0290: .info("Validating what we have just created.....");
0291: sModelRepository.validateModel(lModelName);
0292: sLogger.info("Done validating");
0293: } finally {
0294: if (sModelRepository.isInTransaction())
0295: sModelRepository.rollbackTransaction();
0296: }
0297: }
0298: } finally {
0299: if (sModelRepository != null)
0300: sModelRepository.close();
0301: sModelRepository = null;
0302: }
0303: }
0304:
0305: private static void addEnterprise(
0306: BOMetaBossDomain pOriginalMetaBossDomain,
0307: BOEnterprise pSourceEnterprise,
0308: MetaBossModelPackage pRootModel) throws Exception {
0309: EnterpriseModelPackage lEnterpriseModelPackage = pRootModel
0310: .getEnterpriseModel();
0311: EnterpriseClass lEntepriseClass = lEnterpriseModelPackage
0312: .getEnterprise();
0313: // DesignLibraryModelPackage lDesignLibraryModelPackage = pRootModel.getDesignLibraryModel();
0314: // DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel.getDataDictionaryModel();
0315: // DesignLibraryClass lDesignLibraryClass = lDesignLibraryModelPackage.getDesignLibrary();
0316: // DataDictionaryClass lDataDictionaryClass = lDataDictionaryModelPackage.getDataDictionary();
0317: sModelRepository.beginTransaction();
0318: Enterprise lTargetEnterprise = lEntepriseClass
0319: .createEnterprise();
0320: lTargetEnterprise.setName(pSourceEnterprise.getName());
0321: lTargetEnterprise.setDescription(pSourceEnterprise
0322: .getDescription());
0323: sModelRepository.commitTransaction();
0324: // // Create and populate data dictionary in the enterprise meta library
0325: // {
0326: // DesignLibrary lEntepriseDesignLibrary = lDesignLibraryClass.createDesignLibrary();
0327: // lEntepriseDesignLibrary.setName("Default");
0328: // lEntepriseDesignLibrary.setDescription("Enterprise wide library of reuseable model elements");
0329: // lTargetEnterprise.setDesignLibrary(lEntepriseDesignLibrary);
0330: // DataDictionary lDictionary = lDataDictionaryClass.createDataDictionary();
0331: // lDictionary.setName("Default");
0332: // lDictionary.setDescription("Data dictionary of the types reused throughout enteprise");
0333: // lEntepriseDesignLibrary.setDataDictionary(lDictionary);
0334: // // Immediately add all core templates and datatypes as they are instrumental in MetaBoss internal workings
0335: // {
0336: // List lCoreTypetemplates = new ArrayList();
0337: // BOTypetemplate[] lPublicTypetemplates = pOriginalMetaBossDomain.getPublicTypetemplates().getAllTypetemplates();
0338: // for (int i = 0; i < lPublicTypetemplates.length; i++)
0339: // {
0340: // BOTypetemplate lPublicTypetemplate = lPublicTypetemplates[i];
0341: // if (lPublicTypetemplate.getRef().startsWith(".core."))
0342: // lCoreTypetemplates.add(lPublicTypetemplate);
0343: // }
0344: // addTypetemplates(lDictionary,(BOTypetemplate[])lCoreTypetemplates.toArray(new BOTypetemplate[lCoreTypetemplates.size()]), pRootModel);
0345: // }
0346: // {
0347: // List lCoreDatatypes = new ArrayList();
0348: // BODatatype[] lPublicDatatypes = pOriginalMetaBossDomain.getPublicDatatypes().getAllDatatypes();
0349: // for (int i = 0; i < lPublicDatatypes.length; i++)
0350: // {
0351: // BODatatype lPublicDatatype = lPublicDatatypes[i];
0352: // if (lPublicDatatype.getRef().startsWith(".core."))
0353: // lCoreDatatypes.add(lPublicDatatype);
0354: // }
0355: // addDatatypes(lDictionary,(BODatatype[])lCoreDatatypes.toArray(new BODatatype[lCoreDatatypes.size()]), pRootModel);
0356: // }
0357: // }
0358: // Create technology library and populate it if necessary
0359: {
0360: Context lContext = new InitialContext();
0361: com.metaboss.sdlctools.domains.storagemodel.BOMetaBossDomain lSourceMetaBossDomain = (com.metaboss.sdlctools.domains.storagemodel.BOMetaBossDomain) lContext
0362: .lookup(com.metaboss.sdlctools.domains.storagemodel.BOMetaBossDomain.COMPONENT_URL);
0363:
0364: TechnologyLibrary lEntepriseTechnologyLibrary = lTargetEnterprise
0365: .getTechnologyLibrary();
0366: BOStorageTechnology[] lStorageTechnologies = lSourceMetaBossDomain
0367: .getStorageTechnologies()
0368: .getAllStorageTechnologies();
0369: for (int i = 0; i < lStorageTechnologies.length; i++) {
0370: BOStorageTechnology lStorageTechnology = lStorageTechnologies[i];
0371: // Add all technologies from this enterprise as well as library ones
0372: if (lStorageTechnology.getRef().startsWith(
0373: pSourceEnterprise.getName() + ".")
0374: || lStorageTechnology.getRef().startsWith(".")) {
0375: // Old model only had relational ones
0376: addStorageTechnology(
0377: lEntepriseTechnologyLibrary,
0378: (BORelationalStorageTechnology) lStorageTechnology,
0379: pRootModel);
0380: }
0381: }
0382: }
0383:
0384: // Now create and populate systems
0385: addSystems(pSourceEnterprise.getSystems().getAllSystems(),
0386: lTargetEnterprise, pRootModel);
0387: }
0388:
0389: private static void addSystems(BOSystem[] pSourceSystems,
0390: Enterprise pTargetEnterprise,
0391: MetaBossModelPackage pRootModel) throws Exception {
0392: EnterpriseModelPackage lEnterpriseModelPackage = pRootModel
0393: .getEnterpriseModel();
0394: SystemClass lSystemClass = lEnterpriseModelPackage.getSystem();
0395: // DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel.getDataDictionaryModel();
0396: // DataDictionaryClass lDataDictionaryClass = lDataDictionaryModelPackage.getDataDictionary();
0397: // At the first go create systems with their data dictionaries and add typetemplates
0398: // this is safe because typetemplates do not refer to anything here
0399: for (int i = 0; i < pSourceSystems.length; i++) {
0400: BOSystem lSourceSystem = pSourceSystems[i];
0401: sLogger.info("Converting " + lSourceSystem.getRef()
0402: + " System...");
0403: sModelRepository.beginTransaction();
0404: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lTargetSystem = lSystemClass
0405: .createSystem();
0406: lTargetSystem.setName(lSourceSystem.getName());
0407: pTargetEnterprise.getSystems().add(lTargetSystem);
0408: lTargetSystem
0409: .setDescription("System description is not a part of source model");
0410: sModelRepository.commitTransaction();
0411: // // Create and populate System data dictionary
0412: // DataDictionary lSystemDictionary = lDataDictionaryClass.createDataDictionary();
0413: // lSystemDictionary.setName("Default");
0414: // lSystemDictionary.setDescription("System's data dictionary");
0415: // lTargetSystem.setDataDictionary(lSystemDictionary);
0416:
0417: // Typetemplates should be added first
0418: addTypetemplates(lTargetSystem.getDataDictionary(),
0419: lSourceSystem.getTypetemplates()
0420: .getAllTypetemplates(), pRootModel);
0421: }
0422: // At the second go add datatypes (this is safe because all typetemplates are defined)
0423: for (int i = 0; i < pSourceSystems.length; i++) {
0424: BOSystem lSourceSystem = pSourceSystems[i];
0425: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lTargetSystem = (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) pRootModel
0426: .getModelElement()
0427: .getByRef(
0428: convertOldSystemRefToNewFormat(lSourceSystem
0429: .getRef()));
0430: DataDictionary lSystemDictionary = lTargetSystem
0431: .getDataDictionary();
0432: // Datatypes can be aded here
0433: addDatatypes(lTargetSystem.getDataDictionary(),
0434: lSourceSystem.getDatatypes().getAllDatatypes(),
0435: pRootModel);
0436: }
0437: // At the third go collect all other elements to add
0438: // Adding the whole lot as we go may fail if we add some structures which use otehr structures from as yet undefined systems.
0439: List lAllServicemodules = new ArrayList();
0440: List lAllMessages = new ArrayList();
0441: List lAllStructures = new ArrayList();
0442: List lAllServices = new ArrayList();
0443: List lAllDomains = new ArrayList();
0444: List lAllEntities = new ArrayList();
0445: List lAllAssociations = new ArrayList();
0446: List lAllReports = new ArrayList();
0447: List lAllAttributes = new ArrayList();
0448: List lAllSelectors = new ArrayList();
0449: List lAllPrimaryKeyElements = new ArrayList();
0450: List lAllEntityConstraints = new ArrayList();
0451: for (int i = 0; i < pSourceSystems.length; i++) {
0452: BOSystem lSourceSystem = pSourceSystems[i];
0453:
0454: BODomain[] lDomains = lSourceSystem.getDomains()
0455: .getAllDomains();
0456: lAllDomains.addAll(Arrays.asList(lDomains));
0457: for (int j = 0; j < lDomains.length; j++) {
0458: BODomain lDomain = lDomains[j];
0459:
0460: BOEntity[] lEntities = lDomain.getEntities()
0461: .getAllEntities();
0462: lAllEntities.addAll(Arrays.asList(lEntities));
0463:
0464: for (int k = 0; k < lEntities.length; k++) {
0465: BOEntity lEntity = lEntities[k];
0466:
0467: BOAttribute[] lAttributes = lEntity.getAttributes()
0468: .getAllAttributes();
0469: lAllAttributes.addAll(Arrays.asList(lAttributes));
0470:
0471: BOSelector[] lSelectors = lEntity.getSelectors()
0472: .getAllSelectors();
0473: lAllSelectors.addAll(Arrays.asList(lSelectors));
0474:
0475: BOPrimaryKeyElement[] lPrimaryKeyElements = lEntity
0476: .getPrimaryKeyElements().getAllElements();
0477: lAllPrimaryKeyElements.addAll(Arrays
0478: .asList(lPrimaryKeyElements));
0479:
0480: BOConstraint[] lConstraints = lEntity
0481: .getConstraints().getAllConstraints();
0482: lAllEntityConstraints.addAll(Arrays
0483: .asList(lConstraints));
0484: }
0485:
0486: BOAssociation[] lAssociations = lDomain
0487: .getAssociations().getAllAssociations();
0488: lAllAssociations.addAll(Arrays.asList(lAssociations));
0489:
0490: BOReport[] lReports = lDomain.getReports()
0491: .getAllReports();
0492: lAllReports.addAll(Arrays.asList(lReports));
0493: }
0494:
0495: BOServicemodule[] lServicemodules = lSourceSystem
0496: .getServicemodules().getAllServicemodules();
0497: lAllServicemodules.addAll(Arrays.asList(lServicemodules));
0498: for (int j = 0; j < lServicemodules.length; j++) {
0499: BOServicemodule lServicemodule = lServicemodules[j];
0500:
0501: BOMessage[] lMessages = lServicemodule.getMessages()
0502: .getAllMessages();
0503: lAllMessages.addAll(Arrays.asList(lMessages));
0504:
0505: BOStructure[] lStructures = lServicemodule
0506: .getStructures().getAllStructures();
0507: lAllStructures.addAll(Arrays.asList(lStructures));
0508:
0509: BOService[] lServices = lServicemodule.getServices()
0510: .getAllServices();
0511: lAllServices.addAll(Arrays.asList(lServices));
0512: }
0513: }
0514: // Add domains and elements of domains first - this will introduce implicit data types (which may be used in service specifications)
0515: {
0516: addDomains((BODomain[]) lAllDomains
0517: .toArray(new BODomain[lAllDomains.size()]),
0518: pRootModel);
0519: // Add entities before associations. Note that this adds entities, but does not
0520: // work on primary keys. This is because association role may be a primary key element.
0521: // Associations and AssociationRoles are not added first, because they
0522: // need in turn refer to entities.
0523: addEntities((BOEntity[]) lAllEntities
0524: .toArray(new BOEntity[lAllEntities.size()]),
0525: pRootModel);
0526: // Add attributes
0527: addAttributes((BOAttribute[]) lAllAttributes
0528: .toArray(new BOAttribute[lAllAttributes.size()]),
0529: pRootModel);
0530: // Add selectors
0531: addSelectors((BOSelector[]) lAllSelectors
0532: .toArray(new BOSelector[lAllSelectors.size()]),
0533: pRootModel);
0534: // Add associations
0535: addAssociations(
0536: (BOAssociation[]) lAllAssociations
0537: .toArray(new BOAssociation[lAllAssociations
0538: .size()]), pRootModel);
0539: // Add primary keys after associations. This ensures that references which are the primary key elements can be found
0540: addPrimaryKeyElements(
0541: (BOPrimaryKeyElement[]) lAllPrimaryKeyElements
0542: .toArray(new BOPrimaryKeyElement[lAllPrimaryKeyElements
0543: .size()]), pRootModel);
0544: // Add entity constraints
0545: addEntityConstraints((BOConstraint[]) lAllEntityConstraints
0546: .toArray(new BOConstraint[lAllEntityConstraints
0547: .size()]), pRootModel);
0548: // Now work on reports
0549: addReports((BOReport[]) lAllReports
0550: .toArray(new BOReport[lAllReports.size()]),
0551: pRootModel);
0552: }
0553:
0554: // Next servicemodules
0555: addServicemodules(
0556: (BOServicemodule[]) lAllServicemodules
0557: .toArray(new BOServicemodule[lAllServicemodules
0558: .size()]), pRootModel);
0559: // Next messages
0560: addMessages((BOMessage[]) lAllMessages
0561: .toArray(new BOMessage[lAllMessages.size()]),
0562: pRootModel);
0563: // Next structures
0564: addStructures((BOStructure[]) lAllStructures
0565: .toArray(new BOStructure[lAllStructures.size()]),
0566: pRootModel);
0567: // Next services
0568: addServices((BOService[]) lAllServices
0569: .toArray(new BOService[lAllServices.size()]),
0570: pRootModel);
0571: }
0572:
0573: private static void addServicemodules(
0574: BOServicemodule[] pSourceServicemodules,
0575: MetaBossModelPackage pRootModel) throws Exception {
0576: EnterpriseModelPackage lEnterpriseModelPackage = pRootModel
0577: .getEnterpriseModel();
0578: ServicemoduleClass lServicemoduleClass = lEnterpriseModelPackage
0579: .getServicemodule();
0580: for (int i = 0; i < pSourceServicemodules.length; i++) {
0581: BOServicemodule lSourceServicemodule = pSourceServicemodules[i];
0582: // Locate target system
0583: String lNewSystemRef = convertOldSystemRefToNewFormat(lSourceServicemodule
0584: .getSystem().getRef());
0585: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lTargetSystem = (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) pRootModel
0586: .getModelElement().getByRef(lNewSystemRef);
0587: sModelRepository.beginTransaction();
0588: Servicemodule lTargetServicemodule = lServicemoduleClass
0589: .createServicemodule();
0590: lTargetServicemodule
0591: .setName(lSourceServicemodule.getName());
0592: lTargetSystem.getServicemodules().add(lTargetServicemodule);
0593: lTargetServicemodule.setDescription(lSourceServicemodule
0594: .getDescription());
0595: sModelRepository.commitTransaction();
0596: }
0597: }
0598:
0599: private static void addServices(BOService[] pSourceServices,
0600: MetaBossModelPackage pRootModel) throws Exception {
0601: EnterpriseModelPackage lEnterpriseModelPackage = pRootModel
0602: .getEnterpriseModel();
0603: ServiceClass lServiceClass = lEnterpriseModelPackage
0604: .getService();
0605: for (int i = 0; i < pSourceServices.length; i++) {
0606: BOService lSourceService = pSourceServices[i];
0607: sModelRepository.beginTransaction();
0608: // Locate target servicemodule
0609: Servicemodule lTargetServicemodule = (Servicemodule) pRootModel
0610: .getModelElement()
0611: .getByRef(
0612: convertOldServicemoduleRefToNewFormat(lSourceService
0613: .getServicemodule().getRef()));
0614: Service lTargetService = lServiceClass.createService();
0615: lTargetService.setName(lSourceService.getName());
0616: lTargetServicemodule.getServices().add(lTargetService);
0617: lTargetService.setDescription(lSourceService
0618: .getDescription());
0619: sModelRepository.commitTransaction();
0620: // Add operations
0621: addOperations(lSourceService.getOperations()
0622: .getAllOperations(), pRootModel);
0623: }
0624: }
0625:
0626: private static void addDomains(BODomain[] pSourceDomains,
0627: MetaBossModelPackage pRootModel) throws Exception {
0628: SystemImplementationModelPackage lSystemImplementationModelPackage = pRootModel
0629: .getEnterpriseModel().getSystemImplementationModel();
0630: DomainClass lDomainClass = lSystemImplementationModelPackage
0631: .getDomain();
0632: for (int i = 0; i < pSourceDomains.length; i++) {
0633: BODomain lSourceDomain = pSourceDomains[i];
0634: // Locate target servicemodule
0635: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lTargetSystem = (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) pRootModel
0636: .getModelElement()
0637: .getByRef(
0638: convertOldSystemRefToNewFormat(lSourceDomain
0639: .getSystem().getRef()));
0640: sModelRepository.beginTransaction();
0641: Domain lTargetDomain = lDomainClass.createDomain();
0642: lTargetDomain.setName(lSourceDomain.getName());
0643: lTargetSystem.getDomains().add(lTargetDomain);
0644: lTargetDomain
0645: .setDescription(lSourceDomain.getDescription());
0646: sModelRepository.commitTransaction();
0647: }
0648: }
0649:
0650: private static void addReports(BOReport[] pSourceReports,
0651: MetaBossModelPackage pRootModel) throws Exception {
0652: SystemImplementationModelPackage lSystemImplementationModelPackage = pRootModel
0653: .getEnterpriseModel().getSystemImplementationModel();
0654: AttributeClass lAttributeClass = lSystemImplementationModelPackage
0655: .getAttribute();
0656: EntityClass lEntityClass = lSystemImplementationModelPackage
0657: .getEntity();
0658: ReportClass lReportClass = lSystemImplementationModelPackage
0659: .getReport();
0660: ReportInputFieldClass lReportInputFieldClass = lSystemImplementationModelPackage
0661: .getReportInputField();
0662: ReportOutputElementClass lReportOutputElementClass = lSystemImplementationModelPackage
0663: .getReportOutputElement();
0664: ReportOutputFieldClass lReportOutputFieldClass = lSystemImplementationModelPackage
0665: .getReportOutputField();
0666: ReportOutputEntityClass lReportOutputEntityClass = lSystemImplementationModelPackage
0667: .getReportOutputEntity();
0668: for (int i = 0; i < pSourceReports.length; i++) {
0669: BOReport lSourceReport = pSourceReports[i];
0670: // Locate target domain
0671: Domain lTargetDomain = (Domain) pRootModel
0672: .getModelElement()
0673: .getByRef(
0674: convertOldDomainRefToNewFormat(lSourceReport
0675: .getDomain().getRef()));
0676: sModelRepository.beginTransaction();
0677: Report lTargetReport = lReportClass.createReport();
0678: lTargetReport.setName(lSourceReport.getName());
0679: lTargetReport
0680: .setDescription(lSourceReport.getDescription());
0681: lTargetReport.setPaginal(lSourceReport
0682: .hasPaginationFacility());
0683: lTargetReport.setReportSizeDataType(getDataTypeByOldRef(
0684: pRootModel, lSourceReport.getReportSizeDatatype()
0685: .getRef()));
0686: if (lSourceReport.getReportPageSizeDatatype() != null)
0687: lTargetReport
0688: .setReportPageSizeDataType(getDataTypeByOldRef(
0689: pRootModel, lSourceReport
0690: .getReportPageSizeDatatype()
0691: .getRef()));
0692: if (lSourceReport.getReportPageOffsetDatatype() != null)
0693: lTargetReport
0694: .setReportPageOffsetDataType(getDataTypeByOldRef(
0695: pRootModel, lSourceReport
0696: .getReportPageOffsetDatatype()
0697: .getRef()));
0698: lTargetDomain.getReports().add(lTargetReport);
0699: // Work on report's input fields
0700: {
0701: BOField[] lSourceReportInputFields = lSourceReport
0702: .getInputFields().getAllFields();
0703: Collection lTargetReportInputFieldsCollection = lTargetReport
0704: .getInputFields();
0705: for (int j = 0; j < lSourceReportInputFields.length; j++) {
0706: BOField lSourceReportInputField = lSourceReportInputFields[j];
0707: ReportInputField lTargetReportInputField = lReportInputFieldClass
0708: .createReportInputField();
0709: lTargetReportInputField
0710: .setName(lSourceReportInputField.getName());
0711: lTargetReportInputField
0712: .setDescription(lSourceReportInputField
0713: .getDescription());
0714: lTargetReportInputField
0715: .setArray(lSourceReportInputField.isArray());
0716: BOObject lSourceInputFieldType = lSourceReportInputField
0717: .getType();
0718: if ((lSourceInputFieldType instanceof BODatatype) == false)
0719: throw new Exception(
0720: "Report input field can only carry data type. ReportRef: "
0721: + lSourceReport.getRef());
0722: lTargetReportInputField
0723: .setDataType(getDataTypeByOldRef(
0724: pRootModel,
0725: ((BODatatype) lSourceInputFieldType)
0726: .getRef()));
0727: lTargetReportInputFieldsCollection
0728: .add(lTargetReportInputField);
0729: }
0730: }
0731: // Work on report output fields
0732: {
0733: ReportOutputElement lPreviousLevelTargetReportOutputElement = null;
0734: int lOutputLevels = lSourceReport.getOutputLevels();
0735: for (int j = 0; j < lOutputLevels; j++) {
0736: BOReportOutputElement lSourceReportOutputElement = lSourceReport
0737: .getOutputElement(j);
0738: ReportOutputElement lTargetReportOutputElement = lReportOutputElementClass
0739: .createReportOutputElement();
0740: lTargetReportOutputElement.setName("Level"
0741: + Integer.toString(j + 1));
0742: // Work on output fields
0743: Collection lTargetReportOutputFieldsCollection = lTargetReportOutputElement
0744: .getOutputFields();
0745: BOField[] lSourceReportOutputFields = lSourceReportOutputElement
0746: .getFields().getAllFields();
0747: for (int k = 0; k < lSourceReportOutputFields.length; k++) {
0748: BOField lSourceReportOutputField = lSourceReportOutputFields[k];
0749: ReportOutputField lTargetReportOutputField = lReportOutputFieldClass
0750: .createReportOutputField();
0751: lTargetReportOutputField
0752: .setName(lSourceReportOutputField
0753: .getName());
0754: lTargetReportOutputField
0755: .setDescription(lSourceReportOutputField
0756: .getDescription());
0757: lTargetReportOutputField
0758: .setArray(lSourceReportOutputField
0759: .isArray());
0760: BOObject lSourceOutputFieldType = lSourceReportOutputField
0761: .getType();
0762: if ((lSourceOutputFieldType instanceof BODatatype) == false)
0763: throw new Exception(
0764: "Report output field can only carry data type. ReportRef: "
0765: + lSourceReport.getRef());
0766: lTargetReportOutputField
0767: .setDataType(getDataTypeByOldRef(
0768: pRootModel,
0769: ((BODatatype) lSourceOutputFieldType)
0770: .getRef()));
0771: lTargetReportOutputFieldsCollection
0772: .add(lTargetReportOutputField);
0773: }
0774: // Work on output entities
0775: Collection lTargetReportOutputEntitiesCollection = lTargetReportOutputElement
0776: .getOutputEntities();
0777: BOReportEntity[] lSourceReportOutputEntities = lSourceReportOutputElement
0778: .getEntities().getAllEntities();
0779: for (int k = 0; k < lSourceReportOutputEntities.length; k++) {
0780: BOReportEntity lSourceReportOutputEntity = lSourceReportOutputEntities[k];
0781: ReportOutputEntity lTargetReportOutputEntity = lReportOutputEntityClass
0782: .createReportOutputEntity();
0783: lTargetReportOutputEntity
0784: .setName(lSourceReportOutputEntity
0785: .getName());
0786: lTargetReportOutputEntity
0787: .setDescription(lSourceReportOutputEntity
0788: .getDescription());
0789: lTargetReportOutputEntity
0790: .setArray(lSourceReportOutputEntity
0791: .getCardinality().isPlural());
0792: lTargetReportOutputEntity
0793: .setEntity((Entity) pRootModel
0794: .getModelElement()
0795: .getByRef(
0796: convertOldEntityRefToNewFormat(lSourceReportOutputEntity
0797: .getEntity()
0798: .getRef())));
0799: // Work on attributes
0800: BOAttribute[] lSourceRetrievedAttributes = lSourceReportOutputEntity
0801: .getRetrievedAttributes()
0802: .getAllAttributes();
0803: Collection lTargetReportOutputEntityAttributesCollection = lTargetReportOutputEntity
0804: .getAttributes();
0805: for (int m = 0; m < lSourceRetrievedAttributes.length; m++)
0806: lTargetReportOutputEntityAttributesCollection
0807: .add((Attribute) pRootModel
0808: .getModelElement()
0809: .getByRef(
0810: convertOldAttributeRefToNewFormat(lSourceRetrievedAttributes[m]
0811: .getRef())));
0812: lTargetReportOutputEntitiesCollection
0813: .add(lTargetReportOutputEntity);
0814: }
0815: // Add output element to the appropriate level
0816: if (j == 0)
0817: lTargetReport
0818: .setTopLevelOutputElement(lTargetReportOutputElement);
0819: else
0820: lPreviousLevelTargetReportOutputElement
0821: .setSubElement(lTargetReportOutputElement);
0822: lPreviousLevelTargetReportOutputElement = lTargetReportOutputElement;
0823: }
0824: }
0825: sModelRepository.commitTransaction();
0826: }
0827: }
0828:
0829: private static void addEntities(BOEntity[] pSourceEntities,
0830: MetaBossModelPackage pRootModel) throws Exception {
0831: SystemImplementationModelPackage lSystemImplementationModelPackage = pRootModel
0832: .getEnterpriseModel().getSystemImplementationModel();
0833: EntityClass lEntityClass = lSystemImplementationModelPackage
0834: .getEntity();
0835: for (int i = 0; i < pSourceEntities.length; i++) {
0836: BOEntity lSourceEntity = pSourceEntities[i];
0837: // Locate target servicemodule
0838: Domain lTargetDomain = (Domain) pRootModel
0839: .getModelElement()
0840: .getByRef(
0841: convertOldDomainRefToNewFormat(lSourceEntity
0842: .getDomain().getRef()));
0843: sModelRepository.beginTransaction();
0844: Entity lTargetEntity = lEntityClass.createEntity();
0845: lTargetEntity.setName(lSourceEntity.getName());
0846: lTargetDomain.getEntities().add(lTargetEntity);
0847: lTargetEntity
0848: .setDescription(lSourceEntity.getDescription());
0849: lTargetEntity.setPluralName(lSourceEntity.getPluralName());
0850: lTargetEntity.setAbstract(lSourceEntity.isAbstract());
0851: lTargetEntity.setFinal(lSourceEntity.isFinal());
0852: EntityStereotype lEntityStereotype = lSourceEntity
0853: .getStereotype();
0854: if (lEntityStereotype.equals(EntityStereotype.CARD_FILE))
0855: lTargetEntity
0856: .setStereotype(EntityStereotypeEnum.CARD_FILE);
0857: else if (lEntityStereotype
0858: .equals(EntityStereotype.LOG_FILE))
0859: lTargetEntity
0860: .setStereotype(EntityStereotypeEnum.LOG_FILE);
0861: else
0862: throw new Exception(
0863: "Unrecognised Entity Stereotype. EntityRef: "
0864: + lSourceEntity.getRef());
0865: sModelRepository.commitTransaction();
0866:
0867: if (lSourceEntity.getStates().size() > 0)
0868: addStateMachine(lSourceEntity, pRootModel);
0869: }
0870: // We need to set super / subtype relationship at the second go, this ensures that
0871: // all entities are defined and there will be no problem referencing them
0872: sModelRepository.beginTransaction();
0873: for (int i = 0; i < pSourceEntities.length; i++) {
0874: BOEntity lSourceEntity = pSourceEntities[i];
0875: BOEntity lSourceEntitySupertype = lSourceEntity
0876: .getSupertype();
0877: if (lSourceEntitySupertype != null) {
0878: // Need to set the association
0879: Entity lTargetSubtypeEntity = (Entity) pRootModel
0880: .getModelElement()
0881: .getByRef(
0882: convertOldEntityRefToNewFormat(lSourceEntity
0883: .getRef()));
0884: Entity lTargetSupertypeEntity = (Entity) pRootModel
0885: .getModelElement()
0886: .getByRef(
0887: convertOldEntityRefToNewFormat(lSourceEntitySupertype
0888: .getRef()));
0889: lTargetSubtypeEntity
0890: .setSupertype(lTargetSupertypeEntity);
0891: }
0892: }
0893: sModelRepository.commitTransaction();
0894: }
0895:
0896: private static void addStateMachine(BOEntity pSourceEntity,
0897: MetaBossModelPackage pRootModel) throws Exception {
0898: BOState[] lSourceStates = pSourceEntity.getStates()
0899: .getAllStates();
0900: if (lSourceStates.length > 0) {
0901: StateMachineModelPackage lStateMachineModelPackage = pRootModel
0902: .getStateMachineModel();
0903: StateMachineClass lStateMachineClass = lStateMachineModelPackage
0904: .getStateMachine();
0905: StateClass lStateClass = lStateMachineModelPackage
0906: .getState();
0907: TransitionClass lTransitionClass = lStateMachineModelPackage
0908: .getTransition();
0909: Entity lTargetEntity = (Entity) pRootModel
0910: .getModelElement()
0911: .getByRef(
0912: convertOldEntityRefToNewFormat(pSourceEntity
0913: .getRef()));
0914: sModelRepository.beginTransaction();
0915: StateMachine lStateMachine = lStateMachineClass
0916: .createStateMachine();
0917: lStateMachine.setName(pSourceEntity.getName()
0918: + "StateMachine");
0919: lStateMachine
0920: .setDescription("State machine definition for the "
0921: + pSourceEntity.getName() + " entity");
0922: lTargetEntity.setStateMachine(lStateMachine);
0923: // Add all of the states at the first iteration, so, when it comes to add transitions
0924: // we will be able to reference all states
0925: for (int i = 0; i < lSourceStates.length; i++) {
0926: BOState lSourceState = lSourceStates[i];
0927: State lTargetState = lStateClass.createState();
0928: lTargetState.setName(lSourceState.getName());
0929: lTargetState.setDescription(lSourceState
0930: .getDescription());
0931: lTargetState.setStateMachine(lStateMachine);
0932: StateType lStateType = lSourceState.getType();
0933: if (lStateType.equals(StateType.INITIAL))
0934: lTargetState.setType(StateTypeEnum.INITIAL);
0935: else if (lStateType.equals(StateType.NORMAL))
0936: lTargetState.setType(StateTypeEnum.NORMAL);
0937: else if (lStateType.equals(StateType.FINAL))
0938: lTargetState.setType(StateTypeEnum.FINAL);
0939: else
0940: throw new Exception(
0941: "Unrecognised State Type. EntityRef: "
0942: + pSourceEntity.getRef());
0943: }
0944: // Now add transitions
0945: // we will be able to reference all states
0946: for (int i = 0; i < lSourceStates.length; i++) {
0947: BOState lSourceState = lSourceStates[i];
0948: BOStateTransition[] lSourceTransitions = lSourceState
0949: .getTransitions().getAllTransitions();
0950: for (int j = 0; j < lSourceTransitions.length; j++) {
0951: BOStateTransition lSourceTransition = lSourceTransitions[j];
0952: String lTargetTranstionName = "From"
0953: + lSourceTransition.getStartingState()
0954: .getName()
0955: + "To"
0956: + lSourceTransition.getDestinationState()
0957: .getName();
0958: Transition lTargetTransition = lStateMachine
0959: .findTransition(lTargetTranstionName);
0960: if (lTargetTransition == null) {
0961: // Have not created this transition yet - do it
0962: lTargetTransition = lTransitionClass
0963: .createTransition();
0964: lTargetTransition.setName(lTargetTranstionName);
0965: lTargetTransition
0966: .setDescription(lSourceTransition
0967: .getDescription());
0968: lTargetTransition
0969: .setStateMachine(lStateMachine);
0970: lTargetTransition.setStartState(lStateMachine
0971: .getState(lSourceTransition
0972: .getStartingState().getName()));
0973: lTargetTransition.setEndState(lStateMachine
0974: .getState(lSourceTransition
0975: .getDestinationState()
0976: .getName()));
0977: }
0978: }
0979: }
0980: sModelRepository.commitTransaction();
0981: }
0982: }
0983:
0984: private static void addPrimaryKeyElements(
0985: BOPrimaryKeyElement[] pSourcePrimaryKeyElements,
0986: MetaBossModelPackage pRootModel) throws Exception {
0987: SystemImplementationModelPackage lSystemImplementationModelPackage = pRootModel
0988: .getEnterpriseModel().getSystemImplementationModel();
0989: EntityClass lEntityClass = lSystemImplementationModelPackage
0990: .getEntity();
0991: AttributeClass lAttributeClass = lSystemImplementationModelPackage
0992: .getAttribute();
0993: AssociationRoleClass lAssociationRoleClass = lSystemImplementationModelPackage
0994: .getAssociationRole();
0995: sModelRepository.beginTransaction();
0996: for (int i = 0; i < pSourcePrimaryKeyElements.length; i++) {
0997: BOPrimaryKeyElement lSourcePrimaryKeyElement = pSourcePrimaryKeyElements[i];
0998: // Locate entity in our model
0999: Entity lTargetEntity = (Entity) pRootModel
1000: .getModelElement()
1001: .getByRef(
1002: convertOldEntityRefToNewFormat(lSourcePrimaryKeyElement
1003: .getEntity().getRef()));
1004: PrimaryKeyElementType lPrimaryKeyElementType = lSourcePrimaryKeyElement
1005: .getType();
1006: if (lPrimaryKeyElementType
1007: .equals(PrimaryKeyElementType.ASSOCIATION)) {
1008: BOAssociationRole lSourceAssociationRole = lSourcePrimaryKeyElement
1009: .getUnderlyingAssociationRole();
1010: AssociationRole lTargetAssociationRole = (AssociationRole) pRootModel
1011: .getModelElement()
1012: .getByRef(
1013: convertOldAssociationRoleRefToNewFormat(lSourceAssociationRole
1014: .getRef()));
1015: lTargetEntity.getPrimaryKeyElements().add(
1016: lTargetAssociationRole);
1017:
1018: } else if (lPrimaryKeyElementType
1019: .equals(PrimaryKeyElementType.ATTRIBUTE)) {
1020: BOAttribute lSourceAttribute = lSourcePrimaryKeyElement
1021: .getUnderlyingAttribute();
1022: Attribute lTargetAttribute = (Attribute) pRootModel
1023: .getModelElement()
1024: .getByRef(
1025: convertOldAttributeRefToNewFormat(lSourceAttribute
1026: .getRef()));
1027: lTargetEntity.getPrimaryKeyElements().add(
1028: lTargetAttribute);
1029: } else
1030: throw new Exception(
1031: "Unrecognised Entity Primary Key element. EntityRef: "
1032: + lSourcePrimaryKeyElement.getEntity()
1033: .getRef());
1034: }
1035: sModelRepository.commitTransaction();
1036: }
1037:
1038: private static void addAssociations(
1039: BOAssociation[] pSourceAssociations,
1040: MetaBossModelPackage pRootModel) throws Exception {
1041: SystemImplementationModelPackage lSystemImplementationModelPackage = pRootModel
1042: .getEnterpriseModel().getSystemImplementationModel();
1043: AssociationClass lAssociationClass = lSystemImplementationModelPackage
1044: .getAssociation();
1045: AssociationRoleClass lAssociationRoleClass = lSystemImplementationModelPackage
1046: .getAssociationRole();
1047: for (int i = 0; i < pSourceAssociations.length; i++) {
1048: BOAssociation lSourceAssociation = pSourceAssociations[i];
1049: // Locate target domain, parent to this association
1050: Domain lTargetDomain = (Domain) pRootModel
1051: .getModelElement()
1052: .getByRef(
1053: convertOldDomainRefToNewFormat(lSourceAssociation
1054: .getDomain().getRef()));
1055: sModelRepository.beginTransaction();
1056: Association lTargetAssociation = lAssociationClass
1057: .createAssociation();
1058: lTargetAssociation.setName(lSourceAssociation.getName());
1059: lTargetDomain.getAssociations().add(lTargetAssociation);
1060: lTargetAssociation.setDescription(lSourceAssociation
1061: .getDescription());
1062: // Add role A
1063: {
1064: BOAssociationRole lSourceAssociationRole = lSourceAssociation
1065: .getRoleA();
1066: AssociationRole lTargetAssociationRole = lAssociationRoleClass
1067: .createAssociationRole();
1068: lTargetAssociationRole.setName(lSourceAssociationRole
1069: .getName());
1070: lTargetAssociation.getRoles().add(
1071: lTargetAssociationRole);
1072: lTargetAssociationRole
1073: .setDescription(lSourceAssociationRole
1074: .getDescription());
1075: lTargetAssociationRole
1076: .setPluralName(lSourceAssociationRole
1077: .getPluralName());
1078: lTargetAssociationRole
1079: .setEntity((Entity) pRootModel
1080: .getModelElement()
1081: .getByRef(
1082: convertOldEntityRefToNewFormat(lSourceAssociationRole
1083: .getEntity().getRef())));
1084: AssociationRoleCardinality lAssociationRoleCardinality = lSourceAssociationRole
1085: .getCardinality();
1086: if (lAssociationRoleCardinality
1087: .equals(AssociationRoleCardinality.ONE))
1088: lTargetAssociationRole
1089: .setCardinality(AssociationRoleCardinalityEnum.ONE);
1090: else if (lAssociationRoleCardinality
1091: .equals(AssociationRoleCardinality.ONE_TO_MANY))
1092: lTargetAssociationRole
1093: .setCardinality(AssociationRoleCardinalityEnum.ONE_TO_MANY);
1094: else if (lAssociationRoleCardinality
1095: .equals(AssociationRoleCardinality.ZERO_OR_ONE))
1096: lTargetAssociationRole
1097: .setCardinality(AssociationRoleCardinalityEnum.ZERO_OR_ONE);
1098: else if (lAssociationRoleCardinality
1099: .equals(AssociationRoleCardinality.ZERO_TO_MANY))
1100: lTargetAssociationRole
1101: .setCardinality(AssociationRoleCardinalityEnum.ZERO_TO_MANY);
1102: else
1103: throw new Exception(
1104: "Unrecognised Association Role Cardinality. AssociationRoleRef: "
1105: + lSourceAssociationRole.getRef());
1106: // The only difference here is that we have to "flip" the association stereotype
1107: // from the oposite role in source model to this role in the target model
1108: BOAssociationRole lSourceOppositeAssociationRole = lSourceAssociation
1109: .getRoleB();
1110: AssociationRoleStereotype lAssociationRoleStereotype = lSourceOppositeAssociationRole
1111: .getStereotype();
1112: if (lAssociationRoleStereotype
1113: .equals(AssociationRoleStereotype.ASSOCIATION))
1114: lTargetAssociationRole
1115: .setAggregationType(AggregationTypeEnum.NONE);
1116: else if (lAssociationRoleStereotype
1117: .equals(AssociationRoleStereotype.AGGREGATION))
1118: lTargetAssociationRole
1119: .setAggregationType(AggregationTypeEnum.AGGREGATION);
1120: else if (lAssociationRoleStereotype
1121: .equals(AssociationRoleStereotype.COMPOSITION))
1122: lTargetAssociationRole
1123: .setAggregationType(AggregationTypeEnum.COMPOSITION);
1124: else
1125: throw new Exception(
1126: "Unrecognised Association Role Stereotype. AssociationRoleRef: "
1127: + lSourceAssociationRole.getRef());
1128: }
1129: // Add role B
1130: {
1131: BOAssociationRole lSourceAssociationRole = lSourceAssociation
1132: .getRoleB();
1133: AssociationRole lTargetAssociationRole = lAssociationRoleClass
1134: .createAssociationRole();
1135: lTargetAssociationRole.setName(lSourceAssociationRole
1136: .getName());
1137: lTargetAssociation.getRoles().add(
1138: lTargetAssociationRole);
1139: lTargetAssociationRole
1140: .setDescription(lSourceAssociationRole
1141: .getDescription());
1142: lTargetAssociationRole
1143: .setPluralName(lSourceAssociationRole
1144: .getPluralName());
1145: lTargetAssociationRole
1146: .setEntity((Entity) pRootModel
1147: .getModelElement()
1148: .getByRef(
1149: convertOldEntityRefToNewFormat(lSourceAssociationRole
1150: .getEntity().getRef())));
1151: AssociationRoleCardinality lAssociationRoleCardinality = lSourceAssociationRole
1152: .getCardinality();
1153: if (lAssociationRoleCardinality
1154: .equals(AssociationRoleCardinality.ONE))
1155: lTargetAssociationRole
1156: .setCardinality(AssociationRoleCardinalityEnum.ONE);
1157: else if (lAssociationRoleCardinality
1158: .equals(AssociationRoleCardinality.ONE_TO_MANY))
1159: lTargetAssociationRole
1160: .setCardinality(AssociationRoleCardinalityEnum.ONE_TO_MANY);
1161: else if (lAssociationRoleCardinality
1162: .equals(AssociationRoleCardinality.ZERO_OR_ONE))
1163: lTargetAssociationRole
1164: .setCardinality(AssociationRoleCardinalityEnum.ZERO_OR_ONE);
1165: else if (lAssociationRoleCardinality
1166: .equals(AssociationRoleCardinality.ZERO_TO_MANY))
1167: lTargetAssociationRole
1168: .setCardinality(AssociationRoleCardinalityEnum.ZERO_TO_MANY);
1169: else
1170: throw new Exception(
1171: "Unrecognised Association Role Cardinality. AssociationRoleRef: "
1172: + lSourceAssociationRole.getRef());
1173: // The only difference here is that we have to "flip" the association stereotype
1174: // from the oposite role in source model to this role in the target model
1175: BOAssociationRole lSourceOppositeAssociationRole = lSourceAssociation
1176: .getRoleA();
1177: AssociationRoleStereotype lAssociationRoleStereotype = lSourceOppositeAssociationRole
1178: .getStereotype();
1179: if (lAssociationRoleStereotype
1180: .equals(AssociationRoleStereotype.ASSOCIATION))
1181: lTargetAssociationRole
1182: .setAggregationType(AggregationTypeEnum.NONE);
1183: else if (lAssociationRoleStereotype
1184: .equals(AssociationRoleStereotype.AGGREGATION))
1185: lTargetAssociationRole
1186: .setAggregationType(AggregationTypeEnum.AGGREGATION);
1187: else if (lAssociationRoleStereotype
1188: .equals(AssociationRoleStereotype.COMPOSITION))
1189: lTargetAssociationRole
1190: .setAggregationType(AggregationTypeEnum.COMPOSITION);
1191: else
1192: throw new Exception(
1193: "Unrecognised Association Role Stereotype. AssociationRoleRef: "
1194: + lSourceAssociationRole.getRef());
1195: }
1196: sModelRepository.commitTransaction();
1197: }
1198: }
1199:
1200: private static void addAttributes(BOAttribute[] pSourceAttributes,
1201: MetaBossModelPackage pRootModel) throws Exception {
1202: SystemImplementationModelPackage lSystemImplementationModelPackage = pRootModel
1203: .getEnterpriseModel().getSystemImplementationModel();
1204: AttributeClass lAttributeClass = lSystemImplementationModelPackage
1205: .getAttribute();
1206: for (int i = 0; i < pSourceAttributes.length; i++) {
1207: BOAttribute lSourceAttribute = pSourceAttributes[i];
1208: // Locate target servicemodule
1209: Entity lTargetEntity = (Entity) pRootModel
1210: .getModelElement()
1211: .getByRef(
1212: convertOldEntityRefToNewFormat(lSourceAttribute
1213: .getEntity().getRef()));
1214: sModelRepository.beginTransaction();
1215: Attribute lTargetAttribute = lAttributeClass
1216: .createAttribute();
1217: lTargetAttribute.setName(lSourceAttribute.getName());
1218: lTargetEntity.getAttributes().add(lTargetAttribute);
1219: lTargetAttribute.setDescription(lSourceAttribute
1220: .getDescription());
1221: lTargetAttribute
1222: .setDataType(getDataTypeByOldRef(pRootModel,
1223: lSourceAttribute.getDatatype().getRef()));
1224: lTargetAttribute.setUsedForOrdering(lSourceAttribute
1225: .getCanUseForOrdering());
1226: AttributeStereotype lAttributeStereotype = lSourceAttribute
1227: .getStereotype();
1228: if (lAttributeStereotype
1229: .equals(AttributeStereotype.CREATE_STAMP))
1230: lTargetAttribute
1231: .setStereotype(AttributeStereotypeEnum.CREATE_STAMP);
1232: else if (lAttributeStereotype
1233: .equals(AttributeStereotype.MANDATORY))
1234: lTargetAttribute
1235: .setStereotype(AttributeStereotypeEnum.MANDATORY);
1236: else if (lAttributeStereotype
1237: .equals(AttributeStereotype.OPTIONAL))
1238: lTargetAttribute
1239: .setStereotype(AttributeStereotypeEnum.OPTIONAL);
1240: else if (lAttributeStereotype
1241: .equals(AttributeStereotype.UPDATE_STAMP))
1242: lTargetAttribute
1243: .setStereotype(AttributeStereotypeEnum.UPDATE_STAMP);
1244: else
1245: throw new Exception(
1246: "Unrecognised Attribute Stereotype. AttributeRef: "
1247: + lSourceAttribute.getRef());
1248: sModelRepository.commitTransaction();
1249: }
1250: }
1251:
1252: private static void addSelectors(BOSelector[] pSourceSelectors,
1253: MetaBossModelPackage pRootModel) throws Exception {
1254: SystemImplementationModelPackage lSystemImplementationModelPackage = pRootModel
1255: .getEnterpriseModel().getSystemImplementationModel();
1256: SelectorClass lSelectorClass = lSystemImplementationModelPackage
1257: .getSelector();
1258: for (int i = 0; i < pSourceSelectors.length; i++) {
1259: BOSelector lSourceSelector = pSourceSelectors[i];
1260: // Locate target servicemodule
1261: Entity lTargetEntity = (Entity) pRootModel
1262: .getModelElement()
1263: .getByRef(
1264: convertOldEntityRefToNewFormat(lSourceSelector
1265: .getEntity().getRef()));
1266: sModelRepository.beginTransaction();
1267: Selector lTargetSelector = lSelectorClass.createSelector();
1268: lTargetSelector.setName(lSourceSelector.getName());
1269: lTargetEntity.getSelectors().add(lTargetSelector);
1270: lTargetSelector.setDescription(lSourceSelector
1271: .getDescription());
1272: lTargetSelector.setImplicit(lSourceSelector.isImplicit());
1273: lTargetSelector.setTextOfSqlSelect(lSourceSelector
1274: .getSQLSelector());
1275: SelectorCardinality lSelectorCardinality = lSourceSelector
1276: .getCardinality();
1277: if (lSelectorCardinality
1278: .equals(SelectorCardinality.ZERO_OR_ONE))
1279: lTargetSelector
1280: .setCardinality(SelectorCardinalityEnum.ZERO_OR_ONE);
1281: else if (lSelectorCardinality
1282: .equals(SelectorCardinality.ZERO_TO_MANY))
1283: lTargetSelector
1284: .setCardinality(SelectorCardinalityEnum.ZERO_TO_MANY);
1285: else
1286: throw new Exception(
1287: "Unrecognised Selector Cardinality. SelectorRef: "
1288: + lSourceSelector.getRef());
1289: sModelRepository.commitTransaction();
1290: // Add fields
1291: addSelectorFields(lSourceSelector.getInputFields()
1292: .getAllFields(), pRootModel);
1293: }
1294: }
1295:
1296: private static void addEntityConstraints(
1297: BOConstraint[] pSourceConstraints,
1298: MetaBossModelPackage pRootModel) throws Exception {
1299: if (pSourceConstraints != null) {
1300: ModelElementConstraintClass lModelElementConstraintClass = pRootModel
1301: .getModelElementConstraint();
1302: for (int i = 0; i < pSourceConstraints.length; i++) {
1303: BOConstraint lSourceConstraint = pSourceConstraints[i];
1304: // Locate target entity
1305: Entity lTargetEntity = (Entity) pRootModel
1306: .getModelElement()
1307: .getByRef(
1308: convertOldEntityRefToNewFormat(lSourceConstraint
1309: .getOwnerEntity().getRef()));
1310: sModelRepository.beginTransaction();
1311: ModelElementConstraint lTargetConstraint = lModelElementConstraintClass
1312: .createModelElementConstraint();
1313: lTargetConstraint.setName(lSourceConstraint.getName());
1314: lTargetEntity.getConstraints().add(lTargetConstraint);
1315: lTargetConstraint.setDescription(lSourceConstraint
1316: .getDescription());
1317: lTargetConstraint.setOclExpression(lSourceConstraint
1318: .getOCLExpression());
1319: lTargetConstraint.setDefaultErrorText(lSourceConstraint
1320: .getDefaultErrorText());
1321: sModelRepository.commitTransaction();
1322: }
1323: }
1324: }
1325:
1326: private static void addSelectorFields(BOField[] pSourceFields,
1327: MetaBossModelPackage pRootModel) throws Exception {
1328: SystemImplementationModelPackage lSystemImplementationModelPackage = pRootModel
1329: .getEnterpriseModel().getSystemImplementationModel();
1330: SelectorInputFieldClass lSelectorInputFieldClass = lSystemImplementationModelPackage
1331: .getSelectorInputField();
1332: for (int i = 0; i < pSourceFields.length; i++) {
1333: BOField lSourceField = pSourceFields[i];
1334: // Locate target structure
1335: Selector lTargetSelector = (Selector) pRootModel
1336: .getModelElement()
1337: .getByRef(
1338: convertOldSelectorRefToNewFormat(lSourceField
1339: .getOwnerSelector().getRef()));
1340: sModelRepository.beginTransaction();
1341: SelectorInputField lTargetField = lSelectorInputFieldClass
1342: .createSelectorInputField();
1343: lTargetField.setName(lSourceField.getName());
1344: lTargetSelector.getInputFields().add(lTargetField);
1345: lTargetField.setDescription(lSourceField.getDescription());
1346: //TODO: Modify old model to bring the flag from the model
1347: lTargetField.setArray(false);
1348: BOObject lSourceFieldType = lSourceField.getType();
1349: if (lSourceFieldType instanceof BODatatype)
1350: lTargetField.setDataType(getDataTypeByOldRef(
1351: pRootModel, ((BODatatype) lSourceFieldType)
1352: .getRef()));
1353: else
1354: throw new Exception(
1355: "Unrecognised type of the selector field.");
1356: sModelRepository.commitTransaction();
1357: }
1358: }
1359:
1360: private static void addStructures(BOStructure[] pSourceStructures,
1361: MetaBossModelPackage pRootModel) throws Exception {
1362: DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel
1363: .getDataDictionaryModel();
1364: StructureClass lStructureClass = lDataDictionaryModelPackage
1365: .getStructure();
1366: // At the first go we will collect all structure fields and add them at the second go
1367: // Adding the whole lot as we go may fail if we add some fields referring to as yet unadded structures
1368: List lAllFields = new ArrayList();
1369: List lAllConstraints = new ArrayList();
1370: for (int i = 0; i < pSourceStructures.length; i++) {
1371: BOStructure lSourceStructure = pSourceStructures[i];
1372: sModelRepository.beginTransaction();
1373: // Locate target servicemodule
1374: Servicemodule lTargetServicemodule = (Servicemodule) pRootModel
1375: .getModelElement()
1376: .getByRef(
1377: convertOldServicemoduleRefToNewFormat(lSourceStructure
1378: .getServicemodule().getRef()));
1379: Structure lTargetStructure = lStructureClass
1380: .createStructure();
1381: lTargetStructure.setName(lSourceStructure.getName());
1382: lTargetServicemodule.getStructures().add(lTargetStructure);
1383: lTargetStructure.setDescription(lSourceStructure
1384: .getDescription());
1385: lAllFields.addAll(Arrays.asList(lSourceStructure
1386: .getFields().getAllFields()));
1387: lAllConstraints.addAll(Arrays.asList(lSourceStructure
1388: .getConstraints().getAllConstraints()));
1389: sModelRepository.commitTransaction();
1390: }
1391: // Add fields
1392: addStructureFields((BOField[]) lAllFields
1393: .toArray(new BOField[lAllFields.size()]), pRootModel);
1394: addStructureConstraints((BOConstraint[]) lAllConstraints
1395: .toArray(new BOConstraint[lAllConstraints.size()]),
1396: pRootModel);
1397: }
1398:
1399: private static void addStructureFields(BOField[] pSourceFields,
1400: MetaBossModelPackage pRootModel) throws Exception {
1401: DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel
1402: .getDataDictionaryModel();
1403: StructureFieldClass lStructureFieldClass = lDataDictionaryModelPackage
1404: .getStructureField();
1405: for (int i = 0; i < pSourceFields.length; i++) {
1406: BOField lSourceField = pSourceFields[i];
1407: // Locate target structure
1408: Structure lTargetStructure = (Structure) pRootModel
1409: .getModelElement()
1410: .getByRef(
1411: convertOldStructureRefToNewFormat(lSourceField
1412: .getOwnerStructure().getRef()));
1413: sModelRepository.beginTransaction();
1414: StructureField lTargetField = lStructureFieldClass
1415: .createStructureField();
1416: lTargetField.setName(lSourceField.getName());
1417: lTargetStructure.getFields().add(lTargetField);
1418: lTargetField.setDescription(lSourceField.getDescription());
1419: lTargetField.setArray(lSourceField.isArray());
1420: BOObject lSourceFieldType = lSourceField.getType();
1421: if (lSourceFieldType instanceof BODatatype)
1422: lTargetField.setDataType(getDataTypeByOldRef(
1423: pRootModel, ((BODatatype) lSourceFieldType)
1424: .getRef()));
1425: else if (lSourceFieldType instanceof BOStructure)
1426: lTargetField
1427: .setStructureType((Structure) pRootModel
1428: .getModelElement()
1429: .getByRef(
1430: convertOldStructureRefToNewFormat(((BOStructure) lSourceFieldType)
1431: .getRef())));
1432: else
1433: throw new Exception(
1434: "Unrecognised type of the structure field.");
1435: sModelRepository.commitTransaction();
1436: }
1437: }
1438:
1439: private static void addStructureConstraints(
1440: BOConstraint[] pSourceConstraints,
1441: MetaBossModelPackage pRootModel) throws Exception {
1442: if (pSourceConstraints != null) {
1443: ModelElementConstraintClass lModelElementConstraintClass = pRootModel
1444: .getModelElementConstraint();
1445: for (int i = 0; i < pSourceConstraints.length; i++) {
1446: BOConstraint lSourceConstraint = pSourceConstraints[i];
1447: // Locate target structure
1448: Structure lTargetStructure = (Structure) pRootModel
1449: .getModelElement()
1450: .getByRef(
1451: convertOldStructureRefToNewFormat(lSourceConstraint
1452: .getOwnerStructure().getRef()));
1453: sModelRepository.beginTransaction();
1454: ModelElementConstraint lTargetConstraint = lModelElementConstraintClass
1455: .createModelElementConstraint();
1456: lTargetConstraint.setName(lSourceConstraint.getName());
1457: lTargetStructure.getConstraints()
1458: .add(lTargetConstraint);
1459: lTargetConstraint.setDescription(lSourceConstraint
1460: .getDescription());
1461: lTargetConstraint.setOclExpression(lSourceConstraint
1462: .getOCLExpression());
1463: lTargetConstraint.setDefaultErrorText(lSourceConstraint
1464: .getDefaultErrorText());
1465: sModelRepository.commitTransaction();
1466: }
1467: }
1468: }
1469:
1470: private static void addOperationInputFields(
1471: BOField[] pSourceFields, MetaBossModelPackage pRootModel)
1472: throws Exception {
1473: EnterpriseModelPackage lEnterpriseModelPackage = pRootModel
1474: .getEnterpriseModel();
1475: OperationInputFieldClass lOperationInputFieldClass = lEnterpriseModelPackage
1476: .getOperationInputField();
1477: for (int i = 0; i < pSourceFields.length; i++) {
1478: BOField lSourceField = pSourceFields[i];
1479: // Locate target structure
1480: Operation lTargetOperation = (Operation) pRootModel
1481: .getModelElement()
1482: .getByRef(
1483: convertOldOperationRefToNewFormat(lSourceField
1484: .getOwnerOperation().getRef()));
1485: sModelRepository.beginTransaction();
1486: OperationInputField lTargetField = lOperationInputFieldClass
1487: .createOperationInputField();
1488: lTargetField.setName(lSourceField.getName());
1489: lTargetOperation.getInputFields().add(lTargetField);
1490: lTargetField.setDescription(lSourceField.getDescription());
1491: lTargetField.setArray(lSourceField.isArray());
1492: BOObject lSourceFieldType = lSourceField.getType();
1493: if (lSourceFieldType instanceof BODatatype)
1494: lTargetField.setDataType(getDataTypeByOldRef(
1495: pRootModel, ((BODatatype) lSourceFieldType)
1496: .getRef()));
1497: else if (lSourceFieldType instanceof BOStructure)
1498: lTargetField
1499: .setStructureType((Structure) pRootModel
1500: .getModelElement()
1501: .getByRef(
1502: convertOldStructureRefToNewFormat(((BOStructure) lSourceFieldType)
1503: .getRef())));
1504: else
1505: throw new Exception(
1506: "Unrecognised type of the operation input field.");
1507: sModelRepository.commitTransaction();
1508: }
1509: }
1510:
1511: private static void addOperationInputConstraints(
1512: BOConstraint[] pSourceConstraints,
1513: MetaBossModelPackage pRootModel) throws Exception {
1514: if (pSourceConstraints != null) {
1515: ModelElementConstraintClass lModelElementConstraintClass = pRootModel
1516: .getModelElementConstraint();
1517: for (int i = 0; i < pSourceConstraints.length; i++) {
1518: BOConstraint lSourceConstraint = pSourceConstraints[i];
1519: // Locate target structure
1520: Operation lTargetOperation = (Operation) pRootModel
1521: .getModelElement()
1522: .getByRef(
1523: convertOldOperationRefToNewFormat(lSourceConstraint
1524: .getOwnerOperation().getRef()));
1525: sModelRepository.beginTransaction();
1526: ModelElementConstraint lTargetConstraint = lModelElementConstraintClass
1527: .createModelElementConstraint();
1528: lTargetConstraint.setName(lSourceConstraint.getName());
1529: lTargetOperation.getInputConstraints().add(
1530: lTargetConstraint);
1531: lTargetConstraint.setDescription(lSourceConstraint
1532: .getDescription());
1533: lTargetConstraint.setOclExpression(lSourceConstraint
1534: .getOCLExpression());
1535: lTargetConstraint.setDefaultErrorText(lSourceConstraint
1536: .getDefaultErrorText());
1537: sModelRepository.commitTransaction();
1538: }
1539: }
1540: }
1541:
1542: private static void addOperationOutputFields(
1543: BOField[] pSourceFields, MetaBossModelPackage pRootModel)
1544: throws Exception {
1545: EnterpriseModelPackage lEnterpriseModelPackage = pRootModel
1546: .getEnterpriseModel();
1547: OperationOutputFieldClass lOperationOutputFieldClass = lEnterpriseModelPackage
1548: .getOperationOutputField();
1549: for (int i = 0; i < pSourceFields.length; i++) {
1550: BOField lSourceField = pSourceFields[i];
1551: // Locate target structure
1552: Operation lTargetOperation = (Operation) pRootModel
1553: .getModelElement()
1554: .getByRef(
1555: convertOldOperationRefToNewFormat(lSourceField
1556: .getOwnerOperation().getRef()));
1557: sModelRepository.beginTransaction();
1558: OperationOutputField lTargetField = lOperationOutputFieldClass
1559: .createOperationOutputField();
1560: lTargetField.setName(lSourceField.getName());
1561: lTargetOperation.getOutputFields().add(lTargetField);
1562: lTargetField.setDescription(lSourceField.getDescription());
1563: lTargetField.setArray(lSourceField.isArray());
1564: BOObject lSourceFieldType = lSourceField.getType();
1565: if (lSourceFieldType instanceof BODatatype)
1566: lTargetField.setDataType(getDataTypeByOldRef(
1567: pRootModel, ((BODatatype) lSourceFieldType)
1568: .getRef()));
1569: else if (lSourceFieldType instanceof BOStructure)
1570: lTargetField
1571: .setStructureType((Structure) pRootModel
1572: .getModelElement()
1573: .getByRef(
1574: convertOldStructureRefToNewFormat(((BOStructure) lSourceFieldType)
1575: .getRef())));
1576: else
1577: throw new Exception(
1578: "Unrecognised type of the operation output field.");
1579: sModelRepository.commitTransaction();
1580: }
1581: }
1582:
1583: private static void addOperationOutputMessages(
1584: BOOutputMessage[] pSourceOutputMessages,
1585: MetaBossModelPackage pRootModel) throws Exception {
1586: EnterpriseModelPackage lEnterpriseModelPackage = pRootModel
1587: .getEnterpriseModel();
1588: OperationOutputMessageClass lOperationOutputMessageClass = lEnterpriseModelPackage
1589: .getOperationOutputMessage();
1590: for (int i = 0; i < pSourceOutputMessages.length; i++) {
1591: BOOutputMessage lSourceMessage = pSourceOutputMessages[i];
1592: // Locate target structure
1593: Operation lTargetOperation = (Operation) pRootModel
1594: .getModelElement()
1595: .getByRef(
1596: convertOldOperationRefToNewFormat(lSourceMessage
1597: .getOperation().getRef()));
1598: sModelRepository.beginTransaction();
1599: OperationOutputMessage lTargetMessage = lOperationOutputMessageClass
1600: .createOperationOutputMessage();
1601: lTargetMessage.setName(lSourceMessage.getName());
1602: lTargetOperation.getOutputMessages().add(lTargetMessage);
1603: lTargetMessage.setDescription(lSourceMessage
1604: .getDescription());
1605: lTargetMessage.setArray(lSourceMessage.isArray());
1606: lTargetMessage
1607: .setMessageType((Message) pRootModel
1608: .getModelElement()
1609: .getByRef(
1610: convertOldMessageRefToNewFormat(lSourceMessage
1611: .getMessage().getRef())));
1612: sModelRepository.commitTransaction();
1613: }
1614: }
1615:
1616: private static void addMessages(BOMessage[] pSourceMessages,
1617: MetaBossModelPackage pRootModel) throws Exception {
1618: DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel
1619: .getDataDictionaryModel();
1620: EnterpriseModelPackage lEnterpriseModelPackage = pRootModel
1621: .getEnterpriseModel();
1622: DataTypeClass lDataTypeClass = lDataDictionaryModelPackage
1623: .getDataType();
1624: MessageClass lMessageClass = lEnterpriseModelPackage
1625: .getMessage();
1626: MessageFieldClass lMessageFieldClass = lEnterpriseModelPackage
1627: .getMessageField();
1628: for (int i = 0; i < pSourceMessages.length; i++) {
1629: BOMessage lSourceMessage = pSourceMessages[i];
1630: // Locate target servicemodule
1631: Servicemodule lTargetServicemodule = (Servicemodule) pRootModel
1632: .getModelElement()
1633: .getByRef(
1634: convertOldServicemoduleRefToNewFormat(lSourceMessage
1635: .getServicemodule().getRef()));
1636: sModelRepository.beginTransaction();
1637: Message lTargetMessage = lMessageClass.createMessage();
1638: lTargetMessage.setName(lSourceMessage.getName());
1639: lTargetServicemodule.getMessages().add(lTargetMessage);
1640: lTargetMessage.setDescription(lSourceMessage
1641: .getDescription());
1642: lTargetMessage.setDefaultText(lSourceMessage
1643: .getDefaultText());
1644: MessageType lMessageType = lSourceMessage.getType();
1645: if (lMessageType.equals(MessageType.INFORMATION))
1646: lTargetMessage.setType(MessageTypeEnum.INFORMATION);
1647: else if (lMessageType.equals(MessageType.WARNING))
1648: lTargetMessage.setType(MessageTypeEnum.WARNING);
1649: else if (lMessageType.equals(MessageType.ERROR))
1650: lTargetMessage.setType(MessageTypeEnum.ERROR);
1651: else if (lMessageType.equals(MessageType.FAILURE))
1652: lTargetMessage.setType(MessageTypeEnum.FAILURE);
1653: else
1654: throw new Exception(
1655: "Unrecognised MessageType. MessageRef: "
1656: + lSourceMessage.getRef());
1657: // Now add message fields
1658: BOMessageField[] lMessageFields = lSourceMessage
1659: .getFields().getAllFields();
1660: for (int j = 0; j < lMessageFields.length; j++) {
1661: BOMessageField lMessageField = lMessageFields[j];
1662: MessageField lTargetMessageField = lMessageFieldClass
1663: .createMessageField();
1664: lTargetMessageField.setName(lMessageField.getName());
1665: lTargetMessage.getFields().add(lTargetMessageField);
1666: lTargetMessageField.setDescription(lMessageField
1667: .getDescription());
1668: BODatatype lMessageFieldType = lMessageField.getType();
1669: DataType lDataType = getDataTypeByOldRef(pRootModel,
1670: lMessageFieldType.getRef());
1671: lTargetMessageField.setDataType(lDataType);
1672: }
1673: sModelRepository.commitTransaction();
1674: }
1675: }
1676:
1677: private static void addOperations(BOOperation[] pSourceOperations,
1678: MetaBossModelPackage pRootModel) throws Exception {
1679: EnterpriseModelPackage lEnterpriseModelPackage = pRootModel
1680: .getEnterpriseModel();
1681: OperationClass lOperationClass = lEnterpriseModelPackage
1682: .getOperation();
1683: for (int i = 0; i < pSourceOperations.length; i++) {
1684: BOOperation lSourceOperation = pSourceOperations[i];
1685: // Locate target service
1686: Service lTargetService = (Service) pRootModel
1687: .getModelElement()
1688: .getByRef(
1689: convertOldServiceRefToNewFormat(lSourceOperation
1690: .getService().getRef()));
1691: sModelRepository.beginTransaction();
1692: Operation lTargetOperation = lOperationClass
1693: .createOperation();
1694: lTargetOperation.setName(lSourceOperation.getName());
1695: lTargetOperation.setQuery(lSourceOperation.isQuery());
1696: lTargetService.getOperations().add(lTargetOperation);
1697: lTargetOperation.setDescription(lSourceOperation
1698: .getDescription());
1699: TransactionPolicy lTransactionPolicy = lSourceOperation
1700: .getTransactionPolicy();
1701: if (lTransactionPolicy.equals(TransactionPolicy.MANDATORY))
1702: lTargetOperation
1703: .setTransactionPolicy(com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicyEnum.MANDATORY);
1704: else if (lTransactionPolicy.equals(TransactionPolicy.NEVER))
1705: lTargetOperation
1706: .setTransactionPolicy(com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicyEnum.NEVER);
1707: else if (lTransactionPolicy
1708: .equals(TransactionPolicy.NOT_SUPPORTED))
1709: lTargetOperation
1710: .setTransactionPolicy(com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicyEnum.NOT_SUPPORTED);
1711: else if (lTransactionPolicy
1712: .equals(TransactionPolicy.REQUIRED))
1713: lTargetOperation
1714: .setTransactionPolicy(com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicyEnum.REQUIRED);
1715: else if (lTransactionPolicy
1716: .equals(TransactionPolicy.REQUIRED_NEW))
1717: lTargetOperation
1718: .setTransactionPolicy(com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicyEnum.REQUIRED_NEW);
1719: else if (lTransactionPolicy
1720: .equals(TransactionPolicy.SUPPORTED))
1721: lTargetOperation
1722: .setTransactionPolicy(com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.TransactionPolicyEnum.SUPPORTED);
1723: else
1724: throw new Exception(
1725: "Unexpected value of the transaction policy in the operation. OperationRef: "
1726: + lSourceOperation.getRef());
1727: sModelRepository.commitTransaction();
1728: // Add operation fields and messages
1729: addOperationInputFields(lSourceOperation.getInputFields()
1730: .getAllFields(), pRootModel);
1731: addOperationInputConstraints(lSourceOperation
1732: .getInputConstraints().getAllConstraints(),
1733: pRootModel);
1734: addOperationOutputFields(lSourceOperation.getOutputFields()
1735: .getAllFields(), pRootModel);
1736: addOperationOutputMessages(lSourceOperation
1737: .getOutputMessages().getAllOutputMessages(),
1738: pRootModel);
1739:
1740: }
1741: }
1742:
1743: private static void addTechLib(
1744: com.metaboss.sdlctools.domains.storagemodel.BOMetaBossDomain lSourceMetaBossDomain,
1745: MetaBossModelPackage pRootModel) throws Exception {
1746: TechnologyLibraryModelPackage lTechLibraryPackage = pRootModel
1747: .getTechnologyLibraryModel();
1748: TechnologyLibraryClass lTechLibraryClass = lTechLibraryPackage
1749: .getTechnologyLibrary();
1750: TechnologyLibrary lTechLibrary = lTechLibraryClass
1751: .createTechnologyLibrary();
1752: lTechLibrary.setName("MetaBoss");
1753: lTechLibrary
1754: .setDescription("MetaBoss library of standard reusable technologies");
1755: BOStorageTechnology[] lStorageTechnologies = lSourceMetaBossDomain
1756: .getStorageTechnologies().getAllStorageTechnologies();
1757: for (int i = 0; i < lStorageTechnologies.length; i++) {
1758: BOStorageTechnology lStorageTechnology = lStorageTechnologies[i];
1759: if (lStorageTechnology.getRef().startsWith(".")) {
1760: // Old model only had relational ones
1761: addStorageTechnology(
1762: lTechLibrary,
1763: (BORelationalStorageTechnology) lStorageTechnology,
1764: pRootModel);
1765: }
1766: }
1767: }
1768:
1769: private static void addStorageTechnology(
1770: TechnologyLibrary pTargetTechLibrary,
1771: BORelationalStorageTechnology pSourceStorageTechnology,
1772: MetaBossModelPackage pRootModel) throws Exception {
1773: sModelRepository.beginTransaction();
1774: TechnologyLibraryModelPackage lTechLibraryPackage = pRootModel
1775: .getTechnologyLibraryModel();
1776: RelationalStorageTechnologyClass lRelationalStorageTechnologyClass = lTechLibraryPackage
1777: .getRelationalStorageTechnology();
1778: RelationalStorageTechnology lTargetStorageTechnology = lRelationalStorageTechnologyClass
1779: .createRelationalStorageTechnology();
1780: lTargetStorageTechnology.setName(pSourceStorageTechnology
1781: .getName());
1782: lTargetStorageTechnology
1783: .setDescription(pSourceStorageTechnology
1784: .getDescription());
1785:
1786: String lDomainStorageImplementationGeneratorRef = pSourceStorageTechnology
1787: .getDomainStorageImplementationGeneratorRef();
1788: if (lDomainStorageImplementationGeneratorRef != null
1789: && lDomainStorageImplementationGeneratorRef.length() > 0)
1790: lTargetStorageTechnology
1791: .setImplementationGeneratorPackage(lDomainStorageImplementationGeneratorRef);
1792:
1793: String lDomainStorageMetaDataGeneratorRef = pSourceStorageTechnology
1794: .getDomainStorageMetaDataGeneratorRef();
1795: if (lDomainStorageMetaDataGeneratorRef != null
1796: && lDomainStorageMetaDataGeneratorRef.length() > 0)
1797: lTargetStorageTechnology
1798: .setMetadataGeneratorPackage(lDomainStorageMetaDataGeneratorRef);
1799:
1800: lTargetStorageTechnology
1801: .setMaxTableNameLength(pSourceStorageTechnology
1802: .getMaxTableNameLength());
1803:
1804: lTargetStorageTechnology
1805: .setAssociationTableNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1806: .getAssociationTableNameConversionType()));
1807: lTargetStorageTechnology
1808: .setAssociationTableNamePrefix(pSourceStorageTechnology
1809: .getAssociationTableNamePrefix());
1810: lTargetStorageTechnology
1811: .setAssociationTableNameSuffix(pSourceStorageTechnology
1812: .getAssociationTableNameSuffix());
1813:
1814: lTargetStorageTechnology
1815: .setEntityTableNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1816: .getEntityTableNameConversionType()));
1817: lTargetStorageTechnology
1818: .setEntityTableNamePrefix(pSourceStorageTechnology
1819: .getEntityTableNamePrefix());
1820: lTargetStorageTechnology
1821: .setEntityTableNameSuffix(pSourceStorageTechnology
1822: .getEntityTableNameSuffix());
1823:
1824: lTargetStorageTechnology
1825: .setReferenceTableNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1826: .getReferenceTableNameConversionType()));
1827: lTargetStorageTechnology
1828: .setReferenceTableNamePrefix(pSourceStorageTechnology
1829: .getReferenceTableNamePrefix());
1830: lTargetStorageTechnology
1831: .setReferenceTableNameSuffix(pSourceStorageTechnology
1832: .getReferenceTableNameSuffix());
1833:
1834: lTargetStorageTechnology
1835: .setMaxColumnNameLength(pSourceStorageTechnology
1836: .getMaxColumnNameLength());
1837:
1838: lTargetStorageTechnology
1839: .setAttributeColumnNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1840: .getAttributeColumnNameConversionType()));
1841: lTargetStorageTechnology
1842: .setAttributeColumnNamePrefix(pSourceStorageTechnology
1843: .getAttributeColumnNamePrefix());
1844: lTargetStorageTechnology
1845: .setAttributeColumnNameSuffix(pSourceStorageTechnology
1846: .getAttributeColumnNameSuffix());
1847:
1848: lTargetStorageTechnology
1849: .setAssociationRoleColumnNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1850: .getAssociationRoleColumnNameConversionType()));
1851: lTargetStorageTechnology
1852: .setAssociationRoleColumnNamePrefix(pSourceStorageTechnology
1853: .getAssociationRoleColumnNamePrefix());
1854: lTargetStorageTechnology
1855: .setAssociationRoleColumnNameSuffix(pSourceStorageTechnology
1856: .getAssociationRoleColumnNameSuffix());
1857:
1858: lTargetStorageTechnology
1859: .setEntityInstanceIdColumnName(pSourceStorageTechnology
1860: .getEntityInstanceIdColumnName());
1861: lTargetStorageTechnology
1862: .setEntityVersionIdColumnName(pSourceStorageTechnology
1863: .getEntityVersionIdColumnName());
1864: lTargetStorageTechnology
1865: .setEntityStateColumnName(pSourceStorageTechnology
1866: .getEntityStateColumnName());
1867:
1868: lTargetStorageTechnology
1869: .setReferenceValueColumnName(pSourceStorageTechnology
1870: .getReferenceValueColumnName());
1871: lTargetStorageTechnology
1872: .setReferenceDescriptionColumnName(pSourceStorageTechnology
1873: .getReferenceDescriptionColumnName());
1874: lTargetStorageTechnology
1875: .setReferenceWeightColumnName(pSourceStorageTechnology
1876: .getReferenceWeightColumnName());
1877:
1878: lTargetStorageTechnology
1879: .setMaxConstraintNameLength(pSourceStorageTechnology
1880: .getMaxConstraintNameLength());
1881:
1882: lTargetStorageTechnology
1883: .setAssociationRoleReferentialConstraintNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1884: .getAssociationRoleReferentialConstraintNameConversionType()));
1885: lTargetStorageTechnology
1886: .setAssociationRoleReferentialConstraintNamePrefix(pSourceStorageTechnology
1887: .getAssociationRoleReferentialConstraintNamePrefix());
1888: lTargetStorageTechnology
1889: .setAssociationRoleReferentialConstraintNameSuffix(pSourceStorageTechnology
1890: .getAssociationRoleReferentialConstraintNameSuffix());
1891:
1892: lTargetStorageTechnology
1893: .setAssociationPrimaryKeyConstraintNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1894: .getAssociationPrimaryKeyConstraintNameConversionType()));
1895: lTargetStorageTechnology
1896: .setAssociationPrimaryKeyConstraintNamePrefix(pSourceStorageTechnology
1897: .getAssociationPrimaryKeyConstraintNamePrefix());
1898: lTargetStorageTechnology
1899: .setAssociationPrimaryKeyConstraintNameSuffix(pSourceStorageTechnology
1900: .getAssociationPrimaryKeyConstraintNameSuffix());
1901:
1902: lTargetStorageTechnology
1903: .setEntityPrimaryKeyConstraintNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1904: .getEntityPrimaryKeyConstraintNameConversionType()));
1905: lTargetStorageTechnology
1906: .setEntityPrimaryKeyConstraintNamePrefix(pSourceStorageTechnology
1907: .getEntityPrimaryKeyConstraintNamePrefix());
1908: lTargetStorageTechnology
1909: .setEntityPrimaryKeyConstraintNameSuffix(pSourceStorageTechnology
1910: .getEntityPrimaryKeyConstraintNameSuffix());
1911:
1912: lTargetStorageTechnology
1913: .setEntityNaturalPrimaryKeyConstraintNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1914: .getEntityNaturalPrimaryKeyConstraintNameConversionType()));
1915: lTargetStorageTechnology
1916: .setEntityNaturalPrimaryKeyConstraintNamePrefix(pSourceStorageTechnology
1917: .getEntityNaturalPrimaryKeyConstraintNamePrefix());
1918: lTargetStorageTechnology
1919: .setEntityNaturalPrimaryKeyConstraintNameSuffix(pSourceStorageTechnology
1920: .getEntityNaturalPrimaryKeyConstraintNameSuffix());
1921:
1922: lTargetStorageTechnology
1923: .setEntityAttributeRefConstraintNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1924: .getEntityAttributeRefConstraintNameConversionType()));
1925: lTargetStorageTechnology
1926: .setEntityAttributeRefConstraintNamePrefix(pSourceStorageTechnology
1927: .getEntityAttributeRefConstraintNamePrefix());
1928: lTargetStorageTechnology
1929: .setEntityAttributeRefConstraintNameSuffix(pSourceStorageTechnology
1930: .getEntityAttributeRefConstraintNameSuffix());
1931:
1932: lTargetStorageTechnology
1933: .setReferencePrimaryKeyConstraintNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1934: .getReferencePrimaryKeyConstraintNameConversionType()));
1935: lTargetStorageTechnology
1936: .setReferencePrimaryKeyConstraintNamePrefix(pSourceStorageTechnology
1937: .getReferencePrimaryKeyConstraintNamePrefix());
1938: lTargetStorageTechnology
1939: .setReferencePrimaryKeyConstraintNameSuffix(pSourceStorageTechnology
1940: .getReferencePrimaryKeyConstraintNameSuffix());
1941:
1942: lTargetStorageTechnology
1943: .setReferenceWeightConstraintNameConversionType(convertFromOldNameConversionType(pSourceStorageTechnology
1944: .getReferenceWeightConstraintNameConversionType()));
1945: lTargetStorageTechnology
1946: .setReferenceWeightConstraintNamePrefix(pSourceStorageTechnology
1947: .getReferenceWeightConstraintNamePrefix());
1948: lTargetStorageTechnology
1949: .setReferenceWeightConstraintNameSuffix(pSourceStorageTechnology
1950: .getReferenceWeightConstraintNameSuffix());
1951:
1952: pTargetTechLibrary.getStorageTechnologies().add(
1953: lTargetStorageTechnology);
1954: sModelRepository.commitTransaction();
1955: }
1956:
1957: private static NameConversionTypeEnum convertFromOldNameConversionType(
1958: NameConversionType pOldNameConversionType) {
1959: if (pOldNameConversionType.equals(NameConversionType.NONE))
1960: return NameConversionTypeEnum.NONE;
1961: if (pOldNameConversionType.equals(NameConversionType.LOWER))
1962: return NameConversionTypeEnum.LOWER;
1963: if (pOldNameConversionType
1964: .equals(NameConversionType.LOWER_UNDERSCORED))
1965: return NameConversionTypeEnum.LOWER_UNDERSCORED;
1966: if (pOldNameConversionType.equals(NameConversionType.UPPER))
1967: return NameConversionTypeEnum.UPPER;
1968: if (pOldNameConversionType
1969: .equals(NameConversionType.UPPER_UNDERSCORED))
1970: return NameConversionTypeEnum.UPPER_UNDERSCORED;
1971: throw new IllegalArgumentException(
1972: "Unrecognised NameConversionType :"
1973: + pOldNameConversionType);
1974: }
1975:
1976: private static void addMetaLib(
1977: BOMetaBossDomain lSourceMetaBossDomain,
1978: MetaBossModelPackage pRootModel) throws Exception {
1979: DesignLibraryModelPackage lDesignLibraryPackage = pRootModel
1980: .getDesignLibraryModel();
1981: DesignLibraryClass lDesignLibraryClass = lDesignLibraryPackage
1982: .getDesignLibrary();
1983: DesignLibrary lDesignLibrary = lDesignLibraryClass
1984: .createDesignLibrary();
1985: lDesignLibrary.setName("MetaBoss");
1986: lDesignLibrary
1987: .setDescription("MetaBoss library of standard reusable model elements");
1988: DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel
1989: .getDataDictionaryModel();
1990: DataDictionaryClass lDataDictionaryClass = lDataDictionaryModelPackage
1991: .getDataDictionary();
1992: DataDictionary lDataDictionary = lDataDictionaryClass
1993: .createDataDictionary();
1994: lDataDictionary.setName("core");
1995: lDataDictionary
1996: .setDescription("The core types dictionary owned by DesignLibrary");
1997: lDataDictionary.setDesignLibrary(lDesignLibrary);
1998: // Add all public typetemplates and datatypes
1999: addTypetemplates(lDataDictionary, lSourceMetaBossDomain
2000: .getPublicTypetemplates().getAllTypetemplates(),
2001: pRootModel);
2002: addDatatypes(lDataDictionary, lSourceMetaBossDomain
2003: .getPublicDatatypes().getAllDatatypes(), pRootModel);
2004: }
2005:
2006: private static void addDatatypes(
2007: DataDictionary pTargetDataDictionary,
2008: BODatatype[] pSourceDatatypes,
2009: MetaBossModelPackage pRootModel) throws Exception {
2010: DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel
2011: .getDataDictionaryModel();
2012: DataTypeClass lDataTypeClass = lDataDictionaryModelPackage
2013: .getDataType();
2014: PropertyClass lPropertyClass = lDataDictionaryModelPackage
2015: .getProperty();
2016: ModelElementAttachmentClass lModelElementAttachmentClass = pRootModel
2017: .getModelElementAttachment();
2018: for (int i = 0; i < pSourceDatatypes.length; i++) {
2019: BODatatype lSourceDatatype = pSourceDatatypes[i];
2020: // Obtain, or create namespace where this datatype should be located
2021: AbstractNamespace lTargetNamespace = getOrCreateNamespace(
2022: lSourceDatatype.getRef(), pRootModel);
2023: sModelRepository.beginTransaction();
2024: DataType lTargetDataType = lDataTypeClass.createDataType();
2025: lTargetDataType.setName(lSourceDatatype.getName());
2026: lTargetNamespace.getDataTypes().add(lTargetDataType);
2027: lTargetDataType.setDescription(lSourceDatatype
2028: .getDescription());
2029: // Associate with the template or attach source if no template
2030: BOTypetemplate lTypetemplate = lSourceDatatype
2031: .getTypetemplate();
2032: if (lTypetemplate != null) {
2033: // If we are adding datatype to metalib - we need to refer to the typetemplate from metalib and we expect to find it
2034: // Otherwise we need to obtain typetemplate from the enterprise extent. If we are referring to the global template and it is not copied yet - it will be copied now
2035: TypeTemplate lTargetTypetemplate = getTypeTemplateByOldRef(
2036: pRootModel, lTypetemplate.getRef());
2037: lTargetDataType.setTypetemplate(lTargetTypetemplate);
2038: // Convert properties
2039: Properties lTypetemplateProperties = lSourceDatatype
2040: .getTypetemplateProperties();
2041: for (Iterator lPropertiesIterator = lTypetemplateProperties
2042: .entrySet().iterator(); lPropertiesIterator
2043: .hasNext();) {
2044: Map.Entry lPropertyEntry = (Map.Entry) lPropertiesIterator
2045: .next();
2046: StringTokenizer lTokenizer = new StringTokenizer(
2047: (String) lPropertyEntry.getKey(), ".",
2048: false);
2049: boolean lFirstIteration = true;
2050: Property lCurrentProperty = null;
2051: PropertyDescriptor lCurrentPropertyDescriptor = null;
2052: while (lTokenizer.hasMoreTokens()) {
2053: String lPropertyKey = lTokenizer.nextToken();
2054: Property lProperty = (lCurrentProperty == null) ? lTargetDataType
2055: .findTypetemplatePropertyByKey(lPropertyKey)
2056: : lCurrentProperty
2057: .findPropertyByKey(lPropertyKey);
2058: if (lProperty == null) {
2059: // Need to create this property
2060: int lPropertyIndex = 0;
2061: String lPropertyName = null;
2062: int lIndexPos = lPropertyKey.indexOf("[");
2063: if (lIndexPos > 0) {
2064: lPropertyIndex = Integer
2065: .parseInt(lPropertyKey
2066: .substring(
2067: lIndexPos + 1,
2068: lPropertyKey
2069: .length() - 1));
2070: lPropertyName = lPropertyKey.substring(
2071: 0, lIndexPos);
2072: } else {
2073: lPropertyIndex = 0;
2074: lPropertyName = lPropertyKey;
2075: }
2076: if (lFirstIteration)
2077: lCurrentPropertyDescriptor = lTargetTypetemplate
2078: .findPropertyDescriptor(lPropertyName);
2079: else
2080: lCurrentPropertyDescriptor = lCurrentPropertyDescriptor
2081: .findPropertyDescriptor(lPropertyName);
2082: // Only create a property if descriptor is present
2083: if (lCurrentPropertyDescriptor == null) {
2084: // We know of some legitimate properties we are ommitting - filter them
2085: if (lPropertyEntry.getKey().equals(
2086: "EntityRef") == true
2087: && (lTypetemplate
2088: .getRef()
2089: .equals(
2090: ".core.EntityInstanceIdentifierField")
2091: || lTypetemplate
2092: .getRef()
2093: .equals(
2094: ".core.EntityVersionIdentifierField") || lTypetemplate
2095: .getRef()
2096: .equals(
2097: ".core.EntityStateField"))) {
2098: lCurrentProperty = null;
2099: break;
2100: }
2101: throw new Exception(
2102: "TypeTemplate Property '"
2103: + (String) lPropertyEntry
2104: .getKey()
2105: + "' from DataType '"
2106: + lSourceDatatype
2107: .getRef()
2108: + "' is not described in the new model. Unable to convert");
2109: }
2110: lProperty = lPropertyClass.createProperty();
2111: lProperty.setName(lPropertyName);
2112: lProperty
2113: .setDescriptor(lCurrentPropertyDescriptor);
2114: if (lCurrentProperty == null)
2115: lProperty.setDataType(lTargetDataType);
2116: else
2117: lProperty
2118: .setParentProperty(lCurrentProperty);
2119: } else {
2120: // Already have a property - set up current descriptor
2121: lCurrentPropertyDescriptor = ((lCurrentPropertyDescriptor == null) ? lTargetTypetemplate
2122: .getPropertyDescriptor(lProperty
2123: .getName())
2124: : lCurrentPropertyDescriptor
2125: .getPropertyDescriptor(lProperty
2126: .getName()));
2127: }
2128: lCurrentProperty = lProperty;
2129: lFirstIteration = false;
2130: }
2131: // Only set value if property has actually been created
2132: if (lCurrentProperty != null)
2133: lCurrentProperty
2134: .setValue((String) lPropertyEntry
2135: .getValue());
2136: }
2137: } else if (lTypetemplate == null) {
2138: ModelElementAttachment lDatatypeSourceAttachment = lModelElementAttachmentClass
2139: .createModelElementAttachment();
2140: lDatatypeSourceAttachment.setName("Source");
2141: lDatatypeSourceAttachment
2142: .setDescription("The implementation source of the data type.");
2143: lTargetDataType.getAttachments().add(
2144: lDatatypeSourceAttachment);
2145: ModelElementAttachmentUtils.setAttachmentData(
2146: lDatatypeSourceAttachment, lSourceDatatype
2147: .getSource().getBytes());
2148: }
2149: sModelRepository.commitTransaction();
2150: }
2151: }
2152:
2153: private static void addTypetemplates(
2154: DataDictionary pTargetDataDictionary,
2155: BOTypetemplate[] pSourceTypetemplates,
2156: MetaBossModelPackage pRootModel) throws Exception {
2157: DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel
2158: .getDataDictionaryModel();
2159: TypeTemplateClass lTypeTemplateClass = lDataDictionaryModelPackage
2160: .getTypeTemplate();
2161: ModelElementAttachmentClass lModelElementAttachmentClass = pRootModel
2162: .getModelElementAttachment();
2163: for (int i = 0; i < pSourceTypetemplates.length; i++) {
2164: BOTypetemplate lSourceTypetemplate = pSourceTypetemplates[i];
2165: // Obtain, or create namespace where this datatype should be located
2166: AbstractNamespace lTargetNamespace = getOrCreateNamespace(
2167: lSourceTypetemplate.getRef(), pRootModel);
2168: sModelRepository.beginTransaction();
2169: TypeTemplate lTargetTypeTemplate = lTypeTemplateClass
2170: .createTypeTemplate();
2171: lTargetTypeTemplate.setName(lSourceTypetemplate.getName());
2172: lTargetTypeTemplate.setDescription(lSourceTypetemplate
2173: .getDescription());
2174: lTargetNamespace.getTypeTemplates()
2175: .add(lTargetTypeTemplate);
2176: TemplateSourceType lTemplateSourceType = lSourceTypetemplate
2177: .getSourceType();
2178: if (lTemplateSourceType.equals(TemplateSourceType.JAMON))
2179: lTargetTypeTemplate
2180: .setLanguage(TypeTemplateLanguageEnum.JAMON);
2181: else if (lTemplateSourceType
2182: .equals(TemplateSourceType.VELOCITY))
2183: lTargetTypeTemplate
2184: .setLanguage(TypeTemplateLanguageEnum.VELOCITY);
2185: else if (lTemplateSourceType
2186: .equals(TemplateSourceType.JAVA))
2187: lTargetTypeTemplate
2188: .setLanguage(TypeTemplateLanguageEnum.JAVA);
2189: else
2190: throw new Exception(
2191: "Unrecognised TemplateSourceType. TypetemplateRef: "
2192: + lSourceTypetemplate.getRef());
2193: // Now attach source
2194: ModelElementAttachment lTemplateSourceAttachment = lModelElementAttachmentClass
2195: .createModelElementAttachment();
2196: lTemplateSourceAttachment.setName("Source");
2197: lTemplateSourceAttachment
2198: .setDescription("The source of the template in the language specified by language attribute.");
2199: lTargetTypeTemplate.getAttachments().add(
2200: lTemplateSourceAttachment);
2201: // New model requires java templates to have no package. Strip the package statement from source - if it is a java source
2202: String lTemplateSource = lSourceTypetemplate.getSource();
2203: if (lTemplateSourceType.equals(TemplateSourceType.JAVA)) {
2204: StringWriter lStringWriter = new StringWriter();
2205: BufferedWriter lWriter = new BufferedWriter(
2206: lStringWriter);
2207: BufferedReader lReader = new BufferedReader(
2208: new StringReader(lTemplateSource));
2209: for (String lNewLine = lReader.readLine(); lNewLine != null; lNewLine = lReader
2210: .readLine()) {
2211: if (!lNewLine.trim().startsWith("package ")) {
2212: lWriter.write(lNewLine);
2213: lWriter.newLine();
2214: }
2215: }
2216: lWriter.flush();
2217: lTemplateSource = lStringWriter.toString();
2218: }
2219: ModelElementAttachmentUtils.setAttachmentData(
2220: lTemplateSourceAttachment, lTemplateSource
2221: .getBytes());
2222: sModelRepository.commitTransaction();
2223: // Now add property dscriptors
2224: addTypetemplatePropertyDescriptors(lSourceTypetemplate
2225: .getPropertyDescriptors()
2226: .getAllPropertyDescriptors(), lTargetTypeTemplate,
2227: pRootModel);
2228: }
2229: }
2230:
2231: private static void addTypetemplatePropertyDescriptors(
2232: BOPropertyDescriptor[] pSourcePropertyDescriptors,
2233: TypeTemplate pParentTypetemplate,
2234: MetaBossModelPackage pRootModel) throws Exception {
2235: DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel
2236: .getDataDictionaryModel();
2237: PropertyDescriptorClass lPropertyDescriptorClass = lDataDictionaryModelPackage
2238: .getPropertyDescriptor();
2239: for (int i = 0; i < pSourcePropertyDescriptors.length; i++) {
2240: BOPropertyDescriptor lSourceDescriptor = pSourcePropertyDescriptors[i];
2241: sModelRepository.beginTransaction();
2242: PropertyDescriptor lTargetDescriptor = lPropertyDescriptorClass
2243: .createPropertyDescriptor();
2244: lTargetDescriptor.setName(lSourceDescriptor
2245: .getPropertyName());
2246: pParentTypetemplate.getPropertyDescriptors().add(
2247: lTargetDescriptor);
2248: lTargetDescriptor.setDescription(lSourceDescriptor
2249: .getPropertyDescription());
2250: lTargetDescriptor.setArray(lSourceDescriptor
2251: .isArrayProperty());
2252: // If this property descriptor has subdescriptors - it is a container
2253: BOPropertyDescriptor[] lSubDescriptors = lSourceDescriptor
2254: .getSubPropertiesDescriptors()
2255: .getAllPropertyDescriptors();
2256: if (lSubDescriptors != null && lSubDescriptors.length > 0) {
2257: lTargetDescriptor.setContainer(true);
2258: // Now add sub property dscriptors
2259: addTypetemplatePropertyDescriptors(lSubDescriptors,
2260: lTargetDescriptor, pRootModel);
2261: } else
2262: lTargetDescriptor.setContainer(false);
2263: sModelRepository.commitTransaction();
2264: }
2265: }
2266:
2267: private static void addTypetemplatePropertyDescriptors(
2268: BOPropertyDescriptor[] pSourcePropertyDescriptors,
2269: PropertyDescriptor pParentTypeTemplatePropertyDescriptor,
2270: MetaBossModelPackage pRootModel) throws Exception {
2271: DataDictionaryModelPackage lDataDictionaryModelPackage = pRootModel
2272: .getDataDictionaryModel();
2273: PropertyDescriptorClass lPropertyDescriptorClass = lDataDictionaryModelPackage
2274: .getPropertyDescriptor();
2275: for (int i = 0; i < pSourcePropertyDescriptors.length; i++) {
2276: BOPropertyDescriptor lSourceDescriptor = pSourcePropertyDescriptors[i];
2277: PropertyDescriptor lTargetDescriptor = lPropertyDescriptorClass
2278: .createPropertyDescriptor();
2279: lTargetDescriptor.setName(lSourceDescriptor
2280: .getPropertyName());
2281: pParentTypeTemplatePropertyDescriptor
2282: .getSubPropertyDescriptors().add(lTargetDescriptor);
2283: lTargetDescriptor.setDescription(lSourceDescriptor
2284: .getPropertyDescription());
2285: lTargetDescriptor.setArray(lSourceDescriptor
2286: .isArrayProperty());
2287: // If this property descriptor has subdescriptors - it is a container
2288: BOPropertyDescriptor[] lSubDescriptors = lSourceDescriptor
2289: .getSubPropertiesDescriptors()
2290: .getAllPropertyDescriptors();
2291: if (lSubDescriptors != null && lSubDescriptors.length > 0) {
2292: lTargetDescriptor.setContainer(true);
2293: // Now add sub property dscriptors
2294: addTypetemplatePropertyDescriptors(lSubDescriptors,
2295: lTargetDescriptor, pRootModel);
2296: } else
2297: lTargetDescriptor.setContainer(false);
2298: }
2299: }
2300:
2301: // Helper. Obtains or creates the namespace to house data dictionary element given old element reference
2302: // (may be datatype or typetemplate reference)
2303: private static AbstractNamespace getOrCreateNamespace(
2304: String pOldElementRef, MetaBossModelPackage pRootModel)
2305: throws Exception {
2306: boolean lSystemDatatype = pOldElementRef.startsWith(".") == false;
2307: // We will replace .common with .core for all typetemplates and datatypes during conversion
2308: if (pOldElementRef.startsWith(".common."))
2309: pOldElementRef = ".core." + pOldElementRef.substring(8);
2310:
2311: // First locate the dictionary
2312: String lDataDictionaryRef = null;
2313: if (lSystemDatatype) {
2314: // Ref must at least contain three tokens - enterprise name, system name and data type name
2315: StringTokenizer lTokenizer = new StringTokenizer(
2316: pOldElementRef, ".", false);
2317: if (lTokenizer.countTokens() < 3)
2318: throw new IllegalArgumentException("Invalid Ref: "
2319: + pOldElementRef);
2320: lTokenizer.nextToken(); // Skip enterprise name
2321: lDataDictionaryRef = "Enterprise/systems["
2322: + lTokenizer.nextToken() + "]/dataDictionary";
2323: } else {
2324: // This is Design Library data type
2325: // Ref must at least contain two tokens - dictionary name and data type name
2326: StringTokenizer lTokenizer = new StringTokenizer(
2327: pOldElementRef, ".", false);
2328: if (lTokenizer.countTokens() < 2)
2329: throw new IllegalArgumentException("Invalid Ref: "
2330: + pOldElementRef);
2331: lDataDictionaryRef = "DesignLibrary/dataDictionaries["
2332: + lTokenizer.nextToken() + "]";
2333: }
2334: DataDictionary lTargetDataDictionary = (DataDictionary) pRootModel
2335: .getModelElement().getByRef(lDataDictionaryRef);
2336:
2337: // Obtain, or create namespace where this datatype should be located
2338: AbstractNamespace lTargetNamespace = null;
2339: {
2340: StringTokenizer lTokenizer = new StringTokenizer(
2341: pOldElementRef, ".", false);
2342: int lTokenCount = lTokenizer.countTokens();
2343: // Skip enterprise and system in the ref if it is a system datatype
2344: if (lSystemDatatype) {
2345: lTokenizer.nextToken();
2346: lTokenizer.nextToken();
2347: } else
2348: // Skip dictionary name in the ref if it is a design library
2349: {
2350: lTokenizer.nextToken();
2351: }
2352: // Start iterations from DataDictionary
2353: lTargetNamespace = lTargetDataDictionary;
2354:
2355: for (int j = (lSystemDatatype ? 3 : 2); j < lTokenCount; j++) {
2356: String lNamespaceName = lTokenizer.nextToken();
2357: Namespace lSubNamespace = lTargetNamespace
2358: .findSubNamespace(lNamespaceName);
2359: if (lSubNamespace == null) {
2360: sModelRepository.beginTransaction();
2361: NamespaceClass lNamespaceClass = ((DataDictionaryModelPackage) lTargetDataDictionary
2362: .refImmediatePackage()).getNamespace();
2363: lSubNamespace = lNamespaceClass.createNamespace();
2364: lSubNamespace.setName(lNamespaceName);
2365: lSubNamespace.setNamespace(lTargetNamespace);
2366: sModelRepository.commitTransaction();
2367: }
2368: lTargetNamespace = lSubNamespace;
2369: }
2370: }
2371: return lTargetNamespace;
2372: }
2373:
2374: // Helper. Converts old type template ref to the new format
2375: private static TypeTemplate getTypeTemplateByOldRef(
2376: MetaBossModelPackage pRootModel, String pOldTypetemplateRef)
2377: throws Exception {
2378: // First locate an enterprise object in this extent
2379: Collection lAllEnterprises = pRootModel.getEnterpriseModel()
2380: .getEnterprise().refAllOfClass();
2381: if (lAllEnterprises.size() != 1)
2382: throw new IllegalArgumentException(
2383: "Unable to locate Enterprise object in the given extent.");
2384: Enterprise lEnterprise = (Enterprise) lAllEnterprises.toArray()[0];
2385: String lTypeTemplateRef = convertOldTypetemplateRefToNewEnterpriseFormat(
2386: lEnterprise.getName(), pOldTypetemplateRef);
2387: TypeTemplate lTypeTemplate = (TypeTemplate) pRootModel
2388: .getModelElement().findByRef(lTypeTemplateRef);
2389: if (lTypeTemplate != null)
2390: return lTypeTemplate;
2391: // Now - if this is global type template - we might ned to copy it over. If not - no one can help us
2392: if (!pOldTypetemplateRef.startsWith("."))
2393: throw new ModelElementNotFoundException(lTypeTemplateRef);
2394: TypeTemplate lMetaLibTypeTemplate = getTypeTemplateFromMetaLibByOldRef(pOldTypetemplateRef);
2395:
2396: Context lContext = new InitialContext();
2397: ModelRepository lModelRepository = (ModelRepository) lContext
2398: .lookup(ModelRepository.COMPONENT_URL);
2399: TypeTemplate lEnterpriseCopyOfMetaLibTypeTemplate = (TypeTemplate) lModelRepository
2400: .copyModelElement(lMetaLibTypeTemplate,
2401: lModelRepository.getOwnerModelName(pRootModel),
2402: true, ModelElementResolverImpl.getInstance());
2403: AbstractNamespace lTargetNamespace = getOrCreateNamespace(
2404: pOldTypetemplateRef, pRootModel);
2405: lTargetNamespace.getTypeTemplates().add(
2406: lEnterpriseCopyOfMetaLibTypeTemplate);
2407: return lEnterpriseCopyOfMetaLibTypeTemplate;
2408: }
2409:
2410: // Helper. Converts old type template ref to the new format
2411: private static DataType getDataTypeByOldRef(
2412: MetaBossModelPackage pRootModel, String pOldDataTypeRef)
2413: throws Exception {
2414: // First locate an enterprise object in this extent
2415: Collection lAllEnterprises = pRootModel.getEnterpriseModel()
2416: .getEnterprise().refAllOfClass();
2417: if (lAllEnterprises.size() != 1)
2418: throw new IllegalArgumentException(
2419: "Unable to locate Enterprise object in the given extent.");
2420: Enterprise lEnterprise = (Enterprise) lAllEnterprises.toArray()[0];
2421: String lDataTypeRef = convertOldDataTypeRefToNewEnterpriseFormat(
2422: lEnterprise.getName(), pOldDataTypeRef);
2423: DataType lDataType = (DataType) pRootModel.getModelElement()
2424: .findByRef(lDataTypeRef);
2425: if (lDataType != null)
2426: return lDataType;
2427: // Now - if this is global type template - we might ned to copy it over. If not - no one can help us
2428: if (!pOldDataTypeRef.startsWith("."))
2429: throw new ModelElementNotFoundException(lDataTypeRef);
2430: DataType lMetaLibDataType = getDataTypeFromMetaLibByOldRef(pOldDataTypeRef);
2431:
2432: Context lContext = new InitialContext();
2433: BOMetaBossDomain lOriginalMetaBossDomain = (BOMetaBossDomain) lContext
2434: .lookup(BOMetaBossDomain.COMPONENT_URL);
2435: BODatatype lOldDataType = lOriginalMetaBossDomain
2436: .getDatatype(pOldDataTypeRef);
2437: ModelRepository lModelRepository = (ModelRepository) lContext
2438: .lookup(ModelRepository.COMPONENT_URL);
2439: DataType lEnterpriseCopyOfMetaLibDataType = (DataType) lModelRepository
2440: .copyModelElement(lMetaLibDataType, lModelRepository
2441: .getOwnerModelName(pRootModel), true,
2442: ModelElementResolverImpl.getInstance());
2443: AbstractNamespace lTargetNamespace = getOrCreateNamespace(
2444: pOldDataTypeRef, pRootModel);
2445: lTargetNamespace.getDataTypes().add(
2446: lEnterpriseCopyOfMetaLibDataType);
2447: // Work on typetemplate if necessary
2448: if (lOldDataType.getTypetemplate() != null)
2449: lEnterpriseCopyOfMetaLibDataType
2450: .setTypetemplate(getTypeTemplateByOldRef(
2451: pRootModel, lOldDataType.getTypetemplate()
2452: .getRef()));
2453: return lEnterpriseCopyOfMetaLibDataType;
2454: }
2455:
2456: // Helper. Converts old type template ref to the new format
2457: private static TypeTemplate getTypeTemplateFromMetaLibByOldRef(
2458: String pOldTypetemplateRef) throws Exception {
2459: if (pOldTypetemplateRef.startsWith(".") == false)
2460: throw new IllegalArgumentException(
2461: "Illegal old typetemplate reference for the metalibrary typetemplate");
2462: Context lContext = new InitialContext();
2463: ModelRepository lModelRepository = (ModelRepository) lContext
2464: .lookup(ModelRepository.COMPONENT_URL);
2465: MetaBossModelPackage lMetaLibExtent = (MetaBossModelPackage) lModelRepository
2466: .getModelExtent(sDesignLibraryModelName);
2467: return (TypeTemplate) lMetaLibExtent
2468: .getModelElement()
2469: .getByRef(
2470: convertOldTypetemplateRefToNewMetaLibFormat(pOldTypetemplateRef));
2471: }
2472:
2473: // Helper. Converts old type template ref to the new format
2474: private static DataType getDataTypeFromMetaLibByOldRef(
2475: String pOldDatatypeRef) throws Exception {
2476: if (pOldDatatypeRef.startsWith(".") == false)
2477: throw new IllegalArgumentException(
2478: "Illegal old datatype reference for the metalibrary datatype");
2479: Context lContext = new InitialContext();
2480: ModelRepository lModelRepository = (ModelRepository) lContext
2481: .lookup(ModelRepository.COMPONENT_URL);
2482: MetaBossModelPackage lMetaLibExtent = (MetaBossModelPackage) lModelRepository
2483: .getModelExtent(sDesignLibraryModelName);
2484: return (DataType) lMetaLibExtent
2485: .getModelElement()
2486: .getByRef(
2487: convertOldDatatypeRefToNewMetaLibFormat(pOldDatatypeRef));
2488: }
2489:
2490: // Helper. Converts old type template ref to the new format
2491: private static String convertOldTypetemplateRefToNewMetaLibFormat(
2492: String pOldTypetemplateRef) throws Exception {
2493: if (pOldTypetemplateRef.startsWith(".") == false)
2494: throw new IllegalArgumentException(
2495: "Illegal old typetemplate reference for the metalibrary typetemplate");
2496: // We will replace .common with .core for all typetemplates during conversion
2497: if (pOldTypetemplateRef.startsWith(".common."))
2498: pOldTypetemplateRef = ".core."
2499: + pOldTypetemplateRef.substring(8);
2500:
2501: // This is Design Library typetemplate
2502: // Ref must at least contain two tokens - dictionary name and data type name
2503: StringTokenizer lTokenizer = new StringTokenizer(
2504: pOldTypetemplateRef, ".", false);
2505: int lTokenCount = lTokenizer.countTokens();
2506: if (lTokenCount < 2)
2507: throw new IllegalArgumentException("Invalid Ref: "
2508: + pOldTypetemplateRef);
2509: StringBuffer lNewTypetemplateRef = new StringBuffer(
2510: "DesignLibrary/dataDictionaries[");
2511: lNewTypetemplateRef.append(lTokenizer.nextToken());
2512: lNewTypetemplateRef.append("]");
2513: for (int j = 2; j < lTokenCount; j++) {
2514: lNewTypetemplateRef.append("/subNamespaces[");
2515: lNewTypetemplateRef.append(lTokenizer.nextToken());
2516: lNewTypetemplateRef.append("]");
2517: }
2518: lNewTypetemplateRef.append("/typeTemplates[");
2519: lNewTypetemplateRef.append(lTokenizer.nextToken());
2520: lNewTypetemplateRef.append("]");
2521: return lNewTypetemplateRef.toString();
2522: }
2523:
2524: // Helper. Converts old data type ref to the new format
2525: private static String convertOldDatatypeRefToNewMetaLibFormat(
2526: String pOldDatatypeRef) throws Exception {
2527: if (pOldDatatypeRef.startsWith(".") == false)
2528: throw new IllegalArgumentException(
2529: "Illegal old datatype reference for the metalibrary datatype");
2530: // We will replace .common with .core for all datatypes during conversion
2531: if (pOldDatatypeRef.startsWith(".common."))
2532: pOldDatatypeRef = ".core." + pOldDatatypeRef.substring(8);
2533:
2534: // This is Design Library DataType
2535: // Ref must at least contain two tokens - dictionary name and data type name
2536: StringTokenizer lTokenizer = new StringTokenizer(
2537: pOldDatatypeRef, ".", false);
2538: int lTokenCount = lTokenizer.countTokens();
2539: if (lTokenCount < 2)
2540: throw new IllegalArgumentException("Invalid Ref: "
2541: + pOldDatatypeRef);
2542: StringBuffer lNewDatatypeRef = new StringBuffer(
2543: "DesignLibrary/dataDictionaries[");
2544: lNewDatatypeRef.append(lTokenizer.nextToken());
2545: lNewDatatypeRef.append("]");
2546: for (int j = 2; j < lTokenCount; j++) {
2547: lNewDatatypeRef.append("/subNamespaces[");
2548: lNewDatatypeRef.append(lTokenizer.nextToken());
2549: lNewDatatypeRef.append("]");
2550: }
2551: lNewDatatypeRef.append("/dataTypes[");
2552: lNewDatatypeRef.append(lTokenizer.nextToken());
2553: lNewDatatypeRef.append("]");
2554: return lNewDatatypeRef.toString();
2555: }
2556:
2557: // Helper. Converts old type template ref to the new format
2558: private static String convertOldTypetemplateRefToNewEnterpriseFormat(
2559: String pEnterpriseName, String pOldTypetemplateRef)
2560: throws Exception {
2561: // We will replace .common with .core for all typetemplates during conversion
2562: if (pOldTypetemplateRef.startsWith(".common."))
2563: pOldTypetemplateRef = ".core."
2564: + pOldTypetemplateRef.substring(8);
2565: StringTokenizer lTokenizer = new StringTokenizer(
2566: pOldTypetemplateRef, ".", false);
2567: int lTokenCount = lTokenizer.countTokens();
2568: int lFirstDotPos = pOldTypetemplateRef.indexOf(".");
2569: if (lFirstDotPos == 0) {
2570: // Must be at least two tokens - dictionary name and template name
2571: if (lTokenCount < 2)
2572: throw new IllegalArgumentException("Invalid Ref: "
2573: + pOldTypetemplateRef);
2574: // This is the metalib's typetemplate
2575: StringBuffer lNewTypetemplateRef = new StringBuffer(
2576: "Enterprise/designLibrary/dataDictionaries[");
2577: lNewTypetemplateRef.append(lTokenizer.nextToken());
2578: lNewTypetemplateRef.append("]");
2579: for (int j = 2; j < lTokenCount; j++) {
2580: lNewTypetemplateRef.append("/subNamespaces[");
2581: lNewTypetemplateRef.append(lTokenizer.nextToken());
2582: lNewTypetemplateRef.append("]");
2583: }
2584: lNewTypetemplateRef.append("/typeTemplates[");
2585: lNewTypetemplateRef.append(lTokenizer.nextToken());
2586: lNewTypetemplateRef.append("]");
2587: return lNewTypetemplateRef.toString();
2588: } else if (lFirstDotPos > 0) {
2589: // Must be at least three tokens - enterprise name, system name and template name
2590: if (lTokenCount < 3)
2591: throw new IllegalArgumentException("Invalid Ref: "
2592: + pOldTypetemplateRef);
2593: lTokenizer.nextToken(); // Skip enterprise name
2594: StringBuffer lNewTypetemplateRef = new StringBuffer(
2595: "Enterprise/systems[");
2596: lNewTypetemplateRef.append(lTokenizer.nextToken());
2597: lNewTypetemplateRef.append("]/dataDictionary");
2598: for (int j = 3; j < lTokenCount; j++) {
2599: lNewTypetemplateRef.append("/subNamespaces[");
2600: lNewTypetemplateRef.append(lTokenizer.nextToken());
2601: lNewTypetemplateRef.append("]");
2602: }
2603: lNewTypetemplateRef.append("/typeTemplates[");
2604: lNewTypetemplateRef.append(lTokenizer.nextToken());
2605: lNewTypetemplateRef.append("]");
2606: return lNewTypetemplateRef.toString();
2607: } else
2608: throw new IllegalArgumentException(
2609: "Invalid TypetemplateRef: " + pOldTypetemplateRef);
2610: }
2611:
2612: // Helper. Converts old type template ref to the new format
2613: private static String convertOldDataTypeRefToNewEnterpriseFormat(
2614: String pEnterpriseName, String pOldDataTypeRef)
2615: throws Exception {
2616: // We will replace .common with .core for all datatypes during conversion
2617: if (pOldDataTypeRef.startsWith(".common."))
2618: pOldDataTypeRef = ".core." + pOldDataTypeRef.substring(8);
2619: StringTokenizer lTokenizer = new StringTokenizer(
2620: pOldDataTypeRef, ".", false);
2621: int lTokenCount = lTokenizer.countTokens();
2622: int lFirstDotPos = pOldDataTypeRef.indexOf(".");
2623: if (lFirstDotPos == 0) {
2624: // Must be at least two tokens - dictionary name and datatype name
2625: if (lTokenCount < 2)
2626: throw new IllegalArgumentException("Invalid Ref: "
2627: + pOldDataTypeRef);
2628: // This is the metalib's typetemplate
2629: StringBuffer lNewDatatypeRef = new StringBuffer(
2630: "Enterprise/designLibrary/dataDictionaries[");
2631: lNewDatatypeRef.append(lTokenizer.nextToken());
2632: lNewDatatypeRef.append("]");
2633: for (int j = 2; j < lTokenCount; j++) {
2634: lNewDatatypeRef.append("/subNamespaces[");
2635: lNewDatatypeRef.append(lTokenizer.nextToken());
2636: lNewDatatypeRef.append("]");
2637: }
2638: lNewDatatypeRef.append("/dataTypes[");
2639: lNewDatatypeRef.append(lTokenizer.nextToken());
2640: lNewDatatypeRef.append("]");
2641: return lNewDatatypeRef.toString();
2642: } else if (lFirstDotPos > 0) {
2643: // Must be at least three tokens - enterprise name, system name and template name
2644: if (lTokenCount < 3)
2645: throw new IllegalArgumentException("Invalid Ref: "
2646: + pOldDataTypeRef);
2647: lTokenizer.nextToken(); // Skip enterprise name
2648: StringBuffer lNewDatatypeRef = new StringBuffer(
2649: "Enterprise/systems[");
2650: lNewDatatypeRef.append(lTokenizer.nextToken());
2651: lNewDatatypeRef.append("]/dataDictionary");
2652: for (int j = 3; j < lTokenCount; j++) {
2653: lNewDatatypeRef.append("/subNamespaces[");
2654: lNewDatatypeRef.append(lTokenizer.nextToken());
2655: lNewDatatypeRef.append("]");
2656: }
2657: lNewDatatypeRef.append("/dataTypes[");
2658: lNewDatatypeRef.append(lTokenizer.nextToken());
2659: lNewDatatypeRef.append("]");
2660: return lNewDatatypeRef.toString();
2661: } else
2662: throw new IllegalArgumentException("Invalid DataTypeRef: "
2663: + pOldDataTypeRef);
2664: }
2665:
2666: // Helper. Converts old ref to the new format
2667: private static String convertOldSystemRefToNewFormat(
2668: String pOldSystemRef) throws Exception {
2669: StringTokenizer lTokenizer = new StringTokenizer(pOldSystemRef,
2670: ".", false);
2671: if (lTokenizer.countTokens() != 2)
2672: throw new IllegalArgumentException("Invalid SystemRef: "
2673: + pOldSystemRef);
2674: lTokenizer.nextToken(); // Skip enterprise name
2675: return "Enterprise/systems[" + lTokenizer.nextToken() + "]";
2676: }
2677:
2678: // Helper. Converts old ref to the new format
2679: private static String convertOldServicemoduleRefToNewFormat(
2680: String pOldServicemoduleRef) throws Exception {
2681: StringTokenizer lTokenizer = new StringTokenizer(
2682: pOldServicemoduleRef, ".", false);
2683: if (lTokenizer.countTokens() != 3)
2684: throw new IllegalArgumentException(
2685: "Invalid ServicemoduleRef: " + pOldServicemoduleRef);
2686: lTokenizer.nextToken(); // Skip enterprise name
2687: return "Enterprise/systems[" + lTokenizer.nextToken()
2688: + "]/servicemodules[" + lTokenizer.nextToken() + "]";
2689: }
2690:
2691: // Helper. Converts old ref to the new format
2692: private static String convertOldDomainRefToNewFormat(
2693: String pOldDomainRef) throws Exception {
2694: StringTokenizer lTokenizer = new StringTokenizer(pOldDomainRef,
2695: ".", false);
2696: if (lTokenizer.countTokens() != 3)
2697: throw new IllegalArgumentException("Invalid DomainRef: "
2698: + pOldDomainRef);
2699: lTokenizer.nextToken(); // Skip enterprise name
2700: return "Enterprise/systems[" + lTokenizer.nextToken()
2701: + "]/domains[" + lTokenizer.nextToken() + "]";
2702: }
2703:
2704: // Helper. Converts old ref to the new format
2705: private static String convertOldStructureRefToNewFormat(
2706: String pOldStructureRef) throws Exception {
2707: StringTokenizer lTokenizer = new StringTokenizer(
2708: pOldStructureRef, ".", false);
2709: if (lTokenizer.countTokens() != 4)
2710: throw new IllegalArgumentException("Invalid StructureRef: "
2711: + pOldStructureRef);
2712: lTokenizer.nextToken(); // Skip enterprise name
2713: return "Enterprise/systems[" + lTokenizer.nextToken()
2714: + "]/servicemodules[" + lTokenizer.nextToken()
2715: + "]/structures[" + lTokenizer.nextToken() + "]";
2716: }
2717:
2718: // Helper. Converts old ref to the new format
2719: private static String convertOldServiceRefToNewFormat(
2720: String pOldServiceRef) throws Exception {
2721: StringTokenizer lTokenizer = new StringTokenizer(
2722: pOldServiceRef, ".", false);
2723: if (lTokenizer.countTokens() != 4)
2724: throw new IllegalArgumentException("Invalid ServiceRef: "
2725: + pOldServiceRef);
2726: lTokenizer.nextToken(); // Skip enterprise name
2727: return "Enterprise/systems[" + lTokenizer.nextToken()
2728: + "]/servicemodules[" + lTokenizer.nextToken()
2729: + "]/services[" + lTokenizer.nextToken() + "]";
2730: }
2731:
2732: // Helper. Converts old ref to the new format
2733: private static String convertOldEntityRefToNewFormat(
2734: String pOldEntityRef) throws Exception {
2735: StringTokenizer lTokenizer = new StringTokenizer(pOldEntityRef,
2736: ".", false);
2737: if (lTokenizer.countTokens() != 4)
2738: throw new IllegalArgumentException("Invalid EntityRef: "
2739: + pOldEntityRef);
2740: lTokenizer.nextToken(); // Skip enterprise name
2741: return "Enterprise/systems[" + lTokenizer.nextToken()
2742: + "]/domains[" + lTokenizer.nextToken() + "]/entities["
2743: + lTokenizer.nextToken() + "]";
2744: }
2745:
2746: // Helper. Converts old ref to the new format
2747: private static String convertOldSelectorRefToNewFormat(
2748: String pOldSelectorRef) throws Exception {
2749: StringTokenizer lTokenizer = new StringTokenizer(
2750: pOldSelectorRef, ".", false);
2751: if (lTokenizer.countTokens() != 5)
2752: throw new IllegalArgumentException("Invalid SelectorRef: "
2753: + pOldSelectorRef);
2754: lTokenizer.nextToken(); // Skip enterprise name
2755: return "Enterprise/systems[" + lTokenizer.nextToken()
2756: + "]/domains[" + lTokenizer.nextToken() + "]/entities["
2757: + lTokenizer.nextToken() + "]/selectors["
2758: + lTokenizer.nextToken() + "]";
2759: }
2760:
2761: // Helper. Converts old ref to the new format
2762: private static String convertOldAttributeRefToNewFormat(
2763: String pOldAttributeRef) throws Exception {
2764: StringTokenizer lTokenizer = new StringTokenizer(
2765: pOldAttributeRef, ".", false);
2766: if (lTokenizer.countTokens() != 5)
2767: throw new IllegalArgumentException("Invalid AttributeRef: "
2768: + pOldAttributeRef);
2769: lTokenizer.nextToken(); // Skip enterprise name
2770: return "Enterprise/systems[" + lTokenizer.nextToken()
2771: + "]/domains[" + lTokenizer.nextToken() + "]/entities["
2772: + lTokenizer.nextToken() + "]/attributes["
2773: + lTokenizer.nextToken() + "]";
2774: }
2775:
2776: // Helper. Converts old ref to the new format
2777: private static String convertOldAssociationRefToNewFormat(
2778: String pOldAssociationRef) throws Exception {
2779: StringTokenizer lTokenizer = new StringTokenizer(
2780: pOldAssociationRef, ".", false);
2781: if (lTokenizer.countTokens() != 4)
2782: throw new IllegalArgumentException(
2783: "Invalid AssociationRef: " + pOldAssociationRef);
2784: lTokenizer.nextToken(); // Skip enterprise name
2785: return "Enterprise/systems[" + lTokenizer.nextToken()
2786: + "]/domains[" + lTokenizer.nextToken()
2787: + "]/associations[" + lTokenizer.nextToken() + "]";
2788: }
2789:
2790: // Helper. Converts old ref to the new format
2791: private static String convertOldAssociationRoleRefToNewFormat(
2792: String pOldAssociationRoleRef) throws Exception {
2793: StringTokenizer lTokenizer = new StringTokenizer(
2794: pOldAssociationRoleRef, ".", false);
2795: if (lTokenizer.countTokens() != 5)
2796: throw new IllegalArgumentException(
2797: "Invalid AssociationRoleRef: "
2798: + pOldAssociationRoleRef);
2799: lTokenizer.nextToken(); // Skip enterprise name
2800: return "Enterprise/systems[" + lTokenizer.nextToken()
2801: + "]/domains[" + lTokenizer.nextToken()
2802: + "]/associations[" + lTokenizer.nextToken()
2803: + "]/roles[" + lTokenizer.nextToken() + "]";
2804: }
2805:
2806: // Helper. Converts old ref to the new format
2807: private static String convertOldMessageRefToNewFormat(
2808: String pOldMessageRef) throws Exception {
2809: StringTokenizer lTokenizer = new StringTokenizer(
2810: pOldMessageRef, ".", false);
2811: if (lTokenizer.countTokens() != 4)
2812: throw new IllegalArgumentException("Invalid MessageRef: "
2813: + pOldMessageRef);
2814: lTokenizer.nextToken(); // Skip enterprise name
2815: return "Enterprise/systems[" + lTokenizer.nextToken()
2816: + "]/servicemodules[" + lTokenizer.nextToken()
2817: + "]/messages[" + lTokenizer.nextToken() + "]";
2818: }
2819:
2820: // Helper. Converts old ref to the new format
2821: private static String convertOldOperationRefToNewFormat(
2822: String pOldOperationRef) throws Exception {
2823: StringTokenizer lTokenizer = new StringTokenizer(
2824: pOldOperationRef, ".", false);
2825: if (lTokenizer.countTokens() != 5)
2826: throw new IllegalArgumentException("Invalid ServiceRef: "
2827: + pOldOperationRef);
2828: lTokenizer.nextToken(); // Skip enterprise name
2829: return "Enterprise/systems[" + lTokenizer.nextToken()
2830: + "]/servicemodules[" + lTokenizer.nextToken()
2831: + "]/services[" + lTokenizer.nextToken()
2832: + "]/operations[" + lTokenizer.nextToken() + "]";
2833: }
2834:
2835: // This helper must be called from all tools when exception has been caught
2836: // it will print the exception in the best possible manner
2837: static void handleException(Throwable pThrowable) {
2838: System.out.println("Caught exception "
2839: + pThrowable.getClass().getName());
2840: if (pThrowable instanceof BaseException) {
2841: pThrowable.printStackTrace(System.out);
2842: // Special case for model validation exception - it has explanation
2843: if (pThrowable instanceof ModelValidationException) {
2844: System.out
2845: .println(((ModelValidationException) pThrowable)
2846: .getFullExplanation());
2847: return;
2848: }
2849: Throwable t = pThrowable.getCause();
2850: while (t != null) {
2851: System.out.println();
2852: System.out.println();
2853: System.out.println("Cause : " + t.getClass().getName());
2854: t.printStackTrace(System.out);
2855: // Special case for model validation exception - it has explanation
2856: if (t instanceof ModelValidationException) {
2857: System.out.println(((ModelValidationException) t)
2858: .getFullExplanation());
2859: break;
2860: } else if (t instanceof BaseException) {
2861: t = ((BaseException) t).getCause();
2862: } else
2863: break;
2864: }
2865: } else
2866: // Special case for model validation exception - it has explanation
2867: if (pThrowable instanceof ModelValidationException) {
2868: System.out.println(((ModelValidationException) pThrowable)
2869: .getFullExplanation());
2870: } else {
2871: System.out.println(pThrowable.getMessage());
2872: pThrowable.printStackTrace(System.out);
2873: }
2874: }
2875: }
|