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.Servicemodule;
030: import com.metaboss.sdlctools.services.codegeneration.BSAdapterGenerator;
031: import com.metaboss.util.PropertiesUtils;
032:
033: /** This class offers command line access to the code generation of the servicemodule adapters.
034: * It expects following arguments :
035: * <OL>
036: * <LI>Implementation mapping. Since every adapter implementation generator mapping must be a subpackage of the
037: * com.metaboss.sdlctools.services.codegeneration.servicemoduleadaptergenerator package, implementation mapping argument is only expected to contain
038: * relative package name. <I>For example to invoke activex adapter generator implemented in "com.metaboss.sdlctools.services.codegeneration.servicemoduleadaptergenerator.microsoftwindows.activex"
039: * this argument must only contain "microsoftwindows.activex"</I>
040: * There is also the reserved word - "default" - if it is used this application will look for implementation
041: * mapping in the jndi properties (if default mapping is not configurred - naming error will occur). This feature
042: * really does not make a lot of sence for the adapter generator (since there is no such a thing as default adapter)
043: * It is provided just to satisfy ant integration. This argument can also contain a comma separated list of implementation mappings
044: * in case more than one target code generation style is required. The result will be just like calling this application
045: * separately for each mapping.</LI>
046: * <LI>Destination directory. The directory to generate code to.</LI>
047: * <LI>Ref. The reference to generate code for. The only allowed type at the moment is Servicemodule.
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: * </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 j2ee.jboss implementation it must be in form "MetaBoss.j2ee.jboss.<property name></i>"</LI>
057: * </UL>
058: */
059: public class ServicemoduleAdapterGeneratorApplication {
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)
067: throw new IllegalArgumentException(
068: "Invalid arguments passed to the generator. Expecting three arguments : <implementation name> <destination directory> <reference type> <reference>");
069: // arg[0] is the implementation mapping - comma separated list of implementations to invoke
070: String lImplementationNames = args[0];
071: // arg[1] is the absolute path to the destination directory
072: String lDestinationDirectory = args[1];
073: // arg[2] is the ref - comma separated list of references to generate stuff for
074: String lReferences = args[2];
075:
076: // First load all requested generators
077: ArrayList lGeneratorsList = new ArrayList();
078: StringTokenizer lImplementationNamesTokenizer = new StringTokenizer(
079: lImplementationNames, ",", false);
080: while (lImplementationNamesTokenizer.hasMoreTokens()) {
081: String lImplementationSuffix = lImplementationNamesTokenizer
082: .nextToken();
083: // Prepare the property based on implementation asked for.
084: Properties lContextProps = new Properties();
085: // This is the case where we do not want to use implementations cached for us by
086: // context because this will not allow us to load different implementations.
087: // The com.metaboss.naming.component.DisableContextCaching property switches thia off.
088: if (!lImplementationSuffix.equals("default"))
089: lContextProps
090: .setProperty(
091: "com.metaboss.naming.component.com.metaboss.sdlctools.services.codegeneration.BSAdapterGenerator",
092: "com.metaboss.sdlctools.services.codegeneration.servicemoduleadaptergenerator."
093: + lImplementationSuffix);
094: // Also pass all possible MetaBoss environment properties
095: lContextProps.putAll(PropertiesUtils.filterProperties(
096: System.getProperties(), "MetaBoss.", false));
097: Context ctx = new InitialContext(lContextProps);
098: lGeneratorsList.add(ctx
099: .lookup(BSAdapterGenerator.COMPONENT_URL));
100: }
101: // Now iterate through references calling all generators on each reference
102: Context lContext = new InitialContext();
103: ModelRepository lModelRepository = (ModelRepository) lContext
104: .lookup(ModelRepository.COMPONENT_URL);
105: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
106: .getDefaultModelExtent();
107: ModelElementClass lModelElementClass = lMetaBossModelPackage
108: .getModelElement();
109: StringTokenizer lReferencesTokenizer = new StringTokenizer(
110: lReferences, ",", false);
111: while (lReferencesTokenizer.hasMoreTokens()) {
112: String lRef = lReferencesTokenizer.nextToken();
113: ModelElement lModelElement = lModelElementClass
114: .getByRef(lRef);
115: if (lModelElement instanceof Servicemodule) {
116: Iterator lGenerators = lGeneratorsList.iterator();
117: while (lGenerators.hasNext()) {
118: BSAdapterGenerator lGenerator = (BSAdapterGenerator) lGenerators
119: .next();
120: lGenerator.generateSourceCodeForServicemodule(
121: lDestinationDirectory, lRef);
122: }
123: } else
124: throw new IllegalArgumentException(
125: "Invalid reference passed to the generator. Expecting reference to the Servicemodule. Got "
126: + lRef);
127: }
128: System.exit(0);
129: } catch (Throwable t) {
130: ApplicationUtils.handleException(t);
131: System.exit(1);
132: }
133: }
134: }
|