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.codegeneration.BSStorageDistributionGenerator;
029: import com.metaboss.util.PropertiesUtils;
030:
031: /** This class offers command line access to the code generation of the storage distribution.
032: * It expects following arguments :
033: * <OL>
034: * <LI>Implementation mapping. Since every distribution implementation generator mapping must be a subpackage of the
035: * com.metaboss.sdlctools.services.codegeneration.distribution package, implementation mapping argument is only expected to contain
036: * relative package name. <I>For example to invoke jboss generator implemented in "com.metaboss.sdlctools.services.codegeneration.distribution.j2ee.jboss"
037: * this argument must only contain "j2ee.jboss"</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). Note that there is no
040: * actual sensible default - so unless specifically configurred for particular installation - an error will occur if 'default'
041: * implementation mapping is used.</LI>
042: * <LI>Destination directory. The directory to generate code to.</LI>
043: * <LI>Ref. The reference to generate code for. At the moment only Domain is allowed.
044: * 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.
045: * The result will be just like calling this application separately for each ref.</LI>
046: * </OL>
047: * It expects following java properties :
048: * <UL>
049: * <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>
050: * <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>
051: * <LI>Any number of properties in form "MetaBoss.<implementation mapping>.<property name> to be passed to actual implementation.
052: * <i>For example to pass property to the j2ee.jboss implementation it must be in form "MetaBoss.j2ee.jboss.<property name></i>"</LI>
053: * </UL>
054: */
055: public class StorageDistributionGeneratorApplication {
056: public static void main(String[] args) {
057: try {
058: // Call common initialisation
059: ApplicationUtils.initialiseApplication();
060:
061: // Scan the arguments (must be three)
062: if (args == null || args.length != 3)
063: throw new IllegalArgumentException(
064: "Invalid arguments passed to the generator. Expecting three arguments : <implementation name> <destination directory> <reference type> <reference>");
065: // arg[0] is the implementation mapping
066: String lImplementationMapping = args[0];
067: // arg[1] is the absolute path to the destination directory
068: String lDestinationDirectory = args[1];
069: // arg[2] is the ref - comma separated list of references to work on
070: String lReferences = args[2];
071: // Prepare the property based on implementation asked for
072: Properties lContextProps = new Properties();
073: if (!lImplementationMapping.equals("default"))
074: lContextProps
075: .setProperty(
076: "com.metaboss.naming.component.com.metaboss.sdlctools.services.codegeneration.BSStorageDistributionGenerator",
077: "com.metaboss.sdlctools.services.codegeneration.storagedistributiongenerator."
078: + lImplementationMapping);
079: // Also pass all possible MetaBoss environment properties
080: lContextProps.putAll(PropertiesUtils.filterProperties(
081: System.getProperties(), "MetaBoss.", false));
082: Context ctx = new InitialContext(lContextProps);
083: BSStorageDistributionGenerator lGenerator = (BSStorageDistributionGenerator) ctx
084: .lookup(BSStorageDistributionGenerator.COMPONENT_URL);
085: // Now iterate through references calling all generators on each reference
086: Context lContext = new InitialContext();
087: ModelRepository lModelRepository = (ModelRepository) lContext
088: .lookup(ModelRepository.COMPONENT_URL);
089: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
090: .getDefaultModelExtent();
091: ModelElementClass lModelElementClass = lMetaBossModelPackage
092: .getModelElement();
093: StringTokenizer lReferencesTokenizer = new StringTokenizer(
094: lReferences, ",", false);
095: while (lReferencesTokenizer.hasMoreTokens()) {
096: String lRef = lReferencesTokenizer.nextToken();
097: ModelElement lModelElement = lModelElementClass
098: .getByRef(lRef);
099: if (lModelElement instanceof Domain)
100: lGenerator
101: .generateImplementationSourceCodeForDomain(
102: lDestinationDirectory, lRef);
103: else
104: throw new IllegalArgumentException(
105: "Invalid reference passed to the generator. Expecting reference to the System or Servicemodule. Got "
106: + lRef);
107: }
108: System.exit(0);
109: } catch (Throwable t) {
110: ApplicationUtils.handleException(t);
111: System.exit(1);
112: }
113: }
114: }
|