001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.sdlctools.applications.cmdlinetools;
016:
017: import java.util.ArrayList;
018: import java.util.Iterator;
019: import java.util.Properties;
020: import java.util.StringTokenizer;
021:
022: import javax.naming.Context;
023: import javax.naming.InitialContext;
024:
025: import com.metaboss.sdlctools.models.ModelRepository;
026: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
027: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
028: import com.metaboss.sdlctools.models.metabossmodel.ModelElementClass;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.domainimplementationmodel.DomainRelationalStorageDefinition;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.domainimplementationmodel.DomainRelationalStorageDefinitionClass;
032: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.RelationalStorageTechnology;
033: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.StorageTechnology;
034: import com.metaboss.sdlctools.services.codegeneration.BSStorageImplementationGenerator;
035: import com.metaboss.util.PropertiesUtils;
036:
037: /** This class offers command line access to the code generation of the storage layer.
038: * It expects following arguments :
039: * <OL>
040: * <LI>Implementation mapping. Since every storage implementation generator mapping must be a subpackage of the
041: * com.metaboss.sdlctools.services.codegeneration.storageimpl package, implementation mapping argument is only expected to contain
042: * relative package name. <I>For example to invoke oracle generator implemented in "com.metaboss.sdlctools.services.codegeneration.storageimpl.jdbcsql.oracle"
043: * this argument must only contain "jdbcsql.oracle"</I>
044: * There is also the reserved word - "default" - if it is used this application will look for implementation
045: * mapping in the jndi properties (if default mapping is not configurred - naming error will occur).</LI>
046: * <LI>Destination directory. The directory to generate code to.</LI>
047: * <LI>Ref. The model element reference to generate for. Expecting reference to Domain.
048: * This argument can also contain a comma separated list of references in case this appliction needs to be run for more than one element of the model.
049: * The result will be just like calling this application separately for each ref.</LI>
050: * <LI>StorageTechnologyRef. Valid reference to the target storage technology.
051: * This argument can also contain a comma separated list of references in case this appliction needs to be run for more than storage technology.
052: * The result will be just like calling this application separately for each storage technology ref.</LI>
053: * </OL>
054: * It expects following java properties :
055: * <UL>
056: * <LI>MetaBoss.Home - this property should point to the top level installation directory of MetaBoss. <I>For example : "-DMetaBoss.Home=c:\MetaBoss-0.1"</I></LI>
057: * <LI>MetaBoss.ModelDir - this property should point to the top level directory of the model. <I>For example : "-DMetaBoss.ModelDir=c:\MetaBoss-0.1\example\EnterpriseModel"</I></LI>
058: * <LI>Any number of properties in form "MetaBoss.<implementation mapping>.<property name> to be passed to actual implementation.
059: * <i>For example to pass property to the jdbcsql.oracle implementation it must be in form "MetaBoss.jdbcsql.oracle.<property name></i>"</LI>
060: * </UL>
061: */
062: public class StorageImplementationGeneratorApplication {
063: public static void main(String[] args) {
064: try {
065: // Call common initialisation
066: ApplicationUtils.initialiseApplication();
067:
068: // Scan the arguments (must be three)
069: if (args == null || args.length != 4)
070: throw new IllegalArgumentException(
071: "Invalid arguments passed to the generator. Expecting three arguments : <implementation name> <destination directory> <reference type> <reference> <storage technology reference>");
072: // arg[0] is the implementation mapping
073: String lImplementationMapping = args[0];
074: // arg[1] is the absolute path to the destination directory
075: String lDestinationDirectory = args[1];
076: // arg[2] is the ref - comma separated list of references to work on
077: String lReferences = args[2];
078: // arg[3] is the storage technology ref - comma separated list of stroage technologies to work on
079: String lStorageTechnologies = args[3];
080: // Generate source code
081: // Prepare the property based on implementation asked for
082: Properties lContextProps = new Properties();
083: if (!lImplementationMapping.equals("default"))
084: lContextProps
085: .setProperty(
086: "com.metaboss.naming.component.com.metaboss.sdlctools.services.codegeneration.BSStorageImplementationGenerator",
087: "com.metaboss.sdlctools.services.codegeneration.storageimplementationgenerator."
088: + lImplementationMapping);
089: // Also pass all possible MetaBoss environment properties
090: lContextProps.putAll(PropertiesUtils.filterProperties(
091: System.getProperties(), "MetaBoss.", false));
092: Context ctx = new InitialContext(lContextProps);
093: BSStorageImplementationGenerator lGenerator = (BSStorageImplementationGenerator) ctx
094: .lookup(BSStorageImplementationGenerator.COMPONENT_URL);
095:
096: // Now iterate through references calling all generators on each reference
097: Context lContext = new InitialContext();
098: ModelRepository lModelRepository = (ModelRepository) lContext
099: .lookup(ModelRepository.COMPONENT_URL);
100: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
101: .getDefaultModelExtent();
102: ModelElementClass lModelElementClass = lMetaBossModelPackage
103: .getModelElement();
104: // First verify storage technologies and collect array of them
105: ArrayList lStorageTechnologiesList = new ArrayList();
106: StringTokenizer lStorageTechnologyReferencesTokenizer = new StringTokenizer(
107: lStorageTechnologies, ",", false);
108: while (lStorageTechnologyReferencesTokenizer
109: .hasMoreTokens()) {
110: String lRef = lStorageTechnologyReferencesTokenizer
111: .nextToken();
112: ModelElement lModelElement = lModelElementClass
113: .getByRef(lRef);
114: if (lModelElement instanceof StorageTechnology)
115: lStorageTechnologiesList.add(lRef);
116: else
117: throw new IllegalArgumentException(
118: "Invalid reference passed to the generator. Expecting reference to the StorageTechnology. Got "
119: + lRef);
120: }
121: // Now run alll technologies for all domains
122: StringTokenizer lReferencesTokenizer = new StringTokenizer(
123: lReferences, ",", false);
124: while (lReferencesTokenizer.hasMoreTokens()) {
125: String lRef = lReferencesTokenizer.nextToken();
126: ModelElement lModelElement = lModelElementClass
127: .getByRef(lRef);
128: if (lModelElement instanceof Domain) {
129: // Get the domain and storage details
130: Domain lDomain = (Domain) lModelElement;
131:
132: for (Iterator lStorageTechnologyIter = lStorageTechnologiesList
133: .iterator(); lStorageTechnologyIter
134: .hasNext();) {
135: String lStorageTechnologyRef = (String) lStorageTechnologyIter
136: .next();
137: // Get the domain and storage details
138: RelationalStorageTechnology lTechnology = (RelationalStorageTechnology) lMetaBossModelPackage
139: .getModelElement().getByRef(
140: lStorageTechnologyRef);
141: // Get the definition for this domain on this technology
142: DomainRelationalStorageDefinitionClass lDomainStorageDefinitionClass = lMetaBossModelPackage
143: .getEnterpriseModel()
144: .getSystemImplementationModel()
145: .getDomainImplementationModel()
146: .getDomainRelationalStorageDefinition();
147: DomainRelationalStorageDefinition lDomainStorageDefinition = lDomainStorageDefinitionClass
148: .getDomainRelationalStorageDefinition(
149: lDomain, lTechnology);
150: lGenerator
151: .generateImplementationSourceCodeForDomain(
152: lDestinationDirectory,
153: lDomainStorageDefinition
154: .getRef());
155: }
156: } else
157: throw new IllegalArgumentException(
158: "Invalid reference passed to the generator. Expecting reference to the Domain. Got "
159: + lRef);
160: }
161: System.exit(0);
162: } catch (Throwable t) {
163: ApplicationUtils.handleException(t);
164: System.exit(1);
165: }
166: }
167: }
|