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.io.File;
018: import java.util.ArrayList;
019: import java.util.Iterator;
020: import java.util.Properties;
021: import java.util.StringTokenizer;
022:
023: import javax.naming.Context;
024: import javax.naming.InitialContext;
025:
026: import com.metaboss.sdlctools.models.ModelRepository;
027: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
028: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
029: import com.metaboss.sdlctools.models.metabossmodel.ModelElementClass;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
031: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.StorageTechnology;
032: import com.metaboss.sdlctools.services.metadatamanagement.BSDomainStorageManagement;
033: import com.metaboss.util.PropertiesUtils;
034:
035: /** This class offers command line access to the generation of the domain storage layer metadata.
036: * It expects following arguments :
037: * <OL>
038: * <LI>Implementation mapping. Since every domain storage implementation generator mapping must be a subpackage of the
039: * com.metaboss.sdlctools.services.metadatamanagement.domainstoragemanagement package, implementation mapping argument is only expected to contain
040: * relative package name. <I>For example to invoke generator implemented in "com.metaboss.sdlctools.services.metadatamanagement.domainstoragemanagement.intuitive"
041: * this argument must only contain "intuitive".</I>
042: * There is also the reserved word - "default" - if it is used this application will look for implementation
043: * mapping in the jndi properties (if default mapping is not configurred - naming error will occur).</LI>
044: * <LI>Ref. The model element reference to generate for. Expecting reference to Domain.
045: * 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.
046: * The result will be just like calling this application separately for each ref.</LI>
047: * <LI>StorageTechnologyRef. Valid reference to the target storage technology.
048: * This argument can also contain a comma separated list of references in case this appliction needs to be run for more than storage technology.
049: * The result will be just like calling this application separately for each storage technology ref.</LI>
050: * </OL>
051: * It expects following java properties :
052: * <UL>
053: * <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>
054: * <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>
055: * <LI>Any number of properties in form "MetaBoss.<implementation mapping>.<property name> to be passed to actual implementation.
056: * <i>For example to pass property to the intuitive implementation it must be in form "MetaBoss.intuitive.<property name></i>"</LI>
057: * </UL>
058: */
059: public class StorageMetadataGeneratorApplication {
060: public static void main(String[] args) {
061: try {
062: // Call common initialisation
063: ApplicationUtils.initialiseApplication();
064:
065: // Scan the arguments (must be three)
066: if (args == null || args.length != 3 || args.length != 4)
067: throw new IllegalArgumentException(
068: "Invalid arguments passed to the generator. Expecting four arguments : <implementation name> <reference type> <reference> <storage technology reference> [<reference model directory>]");
069: // args[0] is the implementation mapping
070: String lImplementationMapping = args[0];
071: // args[1] is the ref - comma separated list of references to work on
072: String lReferences = args[1];
073: // args[2] is the storage technology ref - comma separated list of stroage technologies to work on
074: String lStorageTechnologies = args[2];
075: // args[3] is optional reference model directory - open the model if it is specified
076: String lReferenceModelFile = args.length == 4 ? (args[3]
077: + File.separator + "Model.xml") : null;
078: // Generate metadata
079: // Prepare the property based on implementation asked for
080: Properties lContextProps = new Properties();
081: if (!lImplementationMapping.equals("default"))
082: lContextProps
083: .setProperty(
084: "com.metaboss.naming.component.com.metaboss.sdlctools.services.metadatamanagement.BSDomainStorageManagement",
085: "com.metaboss.sdlctools.services.metadatamanagement.domainstoragemanagement."
086: + lImplementationMapping);
087: // Also pass all possible MetaBoss environment properties
088: lContextProps.putAll(PropertiesUtils.filterProperties(
089: System.getProperties(), "MetaBoss.", false));
090: Context ctx = new InitialContext(lContextProps);
091: BSDomainStorageManagement lMetadataGenerator = (BSDomainStorageManagement) ctx
092: .lookup(BSDomainStorageManagement.COMPONENT_URL);
093: // Now iterate through references calling all generators on each reference
094: Context lContext = new InitialContext();
095: ModelRepository lModelRepository = (ModelRepository) lContext
096: .lookup(ModelRepository.COMPONENT_URL);
097: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
098: .getDefaultModelExtent();
099: ModelElementClass lModelElementClass = lMetaBossModelPackage
100: .getModelElement();
101: // Open the reference model if it is specified
102: if (lReferenceModelFile != null)
103: lModelRepository.openModel(lReferenceModelFile,
104: new File(lReferenceModelFile),
105: ModelRepository.METAMODEL_NAME_METABOSS);
106: // First verify storage technologies and collect array of them
107: ArrayList lStorageTechnologiesList = new ArrayList();
108: StringTokenizer lStorageTechnologyReferencesTokenizer = new StringTokenizer(
109: lStorageTechnologies, ",", false);
110: while (lStorageTechnologyReferencesTokenizer
111: .hasMoreTokens()) {
112: String lRef = lStorageTechnologyReferencesTokenizer
113: .nextToken();
114: ModelElement lModelElement = lModelElementClass
115: .getByRef(lRef);
116: if (lModelElement instanceof StorageTechnology)
117: lStorageTechnologiesList.add(lRef);
118: else
119: throw new IllegalArgumentException(
120: "Invalid reference passed to the generator. Expecting reference to the StorageTechnology. Got "
121: + lRef);
122: }
123: // Now run alll technologies for all domains
124: StringTokenizer lReferencesTokenizer = new StringTokenizer(
125: lReferences, ",", false);
126: while (lReferencesTokenizer.hasMoreTokens()) {
127: String lRef = lReferencesTokenizer.nextToken();
128: ModelElement lModelElement = lModelElementClass
129: .getByRef(lRef);
130: if (lModelElement instanceof Domain) {
131: Iterator lStorageTechnologyIter = lStorageTechnologiesList
132: .iterator();
133: while (lStorageTechnologyIter.hasNext()) {
134: String lStorageTechnologyRef = (String) lStorageTechnologyIter
135: .next();
136: lMetadataGenerator.updateMetadataForDomain(
137: lStorageTechnologyRef, lRef,
138: lReferenceModelFile);
139: }
140: } else
141: throw new IllegalArgumentException(
142: "Invalid reference passed to the generator. Expecting reference to the Domain. Got "
143: + lRef);
144: }
145: System.exit(0);
146: } catch (Throwable t) {
147: ApplicationUtils.handleException(t);
148: System.exit(1);
149: }
150: }
151: }
|