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.Properties;
018: import java.util.StringTokenizer;
019:
020: import javax.naming.Context;
021: import javax.naming.InitialContext;
022:
023: import com.metaboss.sdlctools.models.ModelRepository;
024: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
025: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
026: import com.metaboss.sdlctools.models.metabossmodel.ModelElementClass;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
028: import com.metaboss.sdlctools.services.metadatamanagement.BSDomainImplicitElementsManagement;
029: import com.metaboss.util.PropertiesUtils;
030:
031: /** This class offers command line access to the generation of the implicit elements of the domain model metadata.
032: * It expects following arguments :
033: * <OL>
034: * <LI>Implementation mapping. Since every domain storage implementation generator mapping must be a subpackage of the
035: * com.metaboss.sdlctools.services.metadatamanagement.domainimplicitelementsmanagement package, implementation mapping argument is only expected to contain
036: * relative package name. <I>For example to invoke generator implemented in "com.metaboss.sdlctools.services.metadatamanagement.domainimplicitelementsmanagement.intuitive"
037: * this argument must only contain "intuitive".</I>
038: * There is also the reserved word - "default" - if it is used this application will look for implementation
039: * mapping in the jndi properties (if default mapping is not configurred - naming error will occur).</LI>
040: * <LI>Ref. The model element reference to generate code for. Expecting reference to System or Domain.
041: * 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.
042: * The result will be just like calling this application separately for each ref.</LI>
043: * </OL>
044: * It expects following java properties :
045: * <UL>
046: * <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>
047: * <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>
048: * <LI>Any number of properties in form "MetaBoss.<implementation mapping>.<property name> to be passed to actual implementation.
049: * <i>For example to pass property to the intuitive implementation it must be in form "MetaBoss.intuitive.<property name></i>"</LI>
050: * </UL>
051: */
052: public class DomainImplicitMetadataGeneratorApplication {
053: public static void main(String[] args) {
054: try {
055: // Call common initialisation
056: ApplicationUtils.initialiseApplication();
057:
058: // Scan the arguments (must be three)
059: if (args == null || args.length != 2)
060: throw new IllegalArgumentException(
061: "Invalid arguments passed to the generator. Expecting three arguments : <implementation name> <reference type> <reference>");
062: // arg[0] is the implementation mapping
063: String lImplementationMapping = args[0];
064: // arg[1] is the ref - comma separated list of references to work on
065: String lReferences = args[1];
066: // Prepare to generator invocation and do it in the loop
067: // Prepare the property based on implementation asked for
068: Properties lContextProps = new Properties();
069: if (!lImplementationMapping.equals("default"))
070: lContextProps
071: .setProperty(
072: "com.metaboss.naming.component.com.metaboss.sdlctools.services.metadatamanagement.BSDomainImplicitElementsManagement",
073: "com.metaboss.sdlctools.services.metadatamanagement.domainimplicitelementsmanagement."
074: + lImplementationMapping);
075: // Also pass all possible MetaBoss environment properties
076: lContextProps.putAll(PropertiesUtils.filterProperties(
077: System.getProperties(), "MetaBoss.", false));
078: Context ctx = new InitialContext(lContextProps);
079: BSDomainImplicitElementsManagement lMetadataGenerator = (BSDomainImplicitElementsManagement) ctx
080: .lookup(BSDomainImplicitElementsManagement.COMPONENT_URL);
081:
082: // Now iterate through references calling all generators on each reference
083: Context lContext = new InitialContext();
084: ModelRepository lModelRepository = (ModelRepository) lContext
085: .lookup(ModelRepository.COMPONENT_URL);
086: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
087: .getDefaultModelExtent();
088: ModelElementClass lModelElementClass = lMetaBossModelPackage
089: .getModelElement();
090: StringTokenizer lReferencesTokenizer = new StringTokenizer(
091: lReferences, ",", false);
092: while (lReferencesTokenizer.hasMoreTokens()) {
093: String lRef = lReferencesTokenizer.nextToken();
094: ModelElement lModelElement = lModelElementClass
095: .getByRef(lRef);
096: if (lModelElement instanceof com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System)
097: lMetadataGenerator.updateMetadataForSystem(lRef);
098: else if (lModelElement instanceof Domain)
099: lMetadataGenerator.updateMetadataForDomain(lRef);
100: else
101: throw new IllegalArgumentException(
102: "Invalid reference passed to the generator. Expecting reference to the System or Domain. Got "
103: + lRef);
104: }
105: System.exit(0);
106: } catch (Throwable t) {
107: ApplicationUtils.handleException(t);
108: System.exit(1);
109: }
110: }
111: }
|