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