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.Properties;
019: import java.util.StringTokenizer;
020:
021: import javax.naming.Context;
022: import javax.naming.InitialContext;
023:
024: import com.metaboss.enterprise.bs.BSException;
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.Enterprise;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
032: import com.metaboss.sdlctools.services.codegeneration.BSServiceProxyGenerator;
033: import com.metaboss.util.PropertiesUtils;
034:
035: /** This class offers command line access to the code generation of the service proxies.
036: * It expects following arguments :
037: * <OL>
038: * <LI>Implementation mapping. Since every proxy implementation generator mapping must be a subpackage of the
039: * com.metaboss.sdlctools.services.codegeneration.serviceproxygenerator package, implementation mapping argument is only expected to contain
040: * relative package name. <I>For example to invoke security proxy generator implemented in "com.metaboss.sdlctools.services.codegeneration.serviceproxygenerator.security.accesscontrol"
041: * this argument must only contain "security.accesscontrol"</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). This feature
044: * really does not make a lot of sence for the proxy generator (since there is no such a thing as default proxy)
045: * It is provided just to satisfy ant integration. This argument can also contain a comma separated list of implementation mappings
046: * in case more than one proxy is required. The result will be just like calling this application
047: * separately for each mapping.</LI>
048: * <LI>Destination directory. The directory to generate code to.</LI>
049: * <LI>Ref. The reference to generate code for. Allowed types are Enterprise, System, Servicemodule or Service.
050: * 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.
051: * The result will be just like calling this application separately for each ref.</LI>
052: * </OL>
053: * It expects following java properties :
054: * <UL>
055: * <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>
056: * <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>
057: * <LI>Any number of properties in form "MetaBoss.<implementation mapping>.<property name> to be passed to actual implementation.
058: * <i>For example to pass property to the security.accesscontrol implementation it must be in form "MetaBoss.security.accesscontrol.<property name></i>"</LI>
059: * </UL>
060: */
061: public class ServiceProxyGeneratorApplication {
062: public static void main(String[] args) {
063: try {
064: // Call common initialisation
065: ApplicationUtils.initialiseApplication();
066:
067: // Scan the arguments (must be three)
068: if (args == null || args.length != 3)
069: throw new IllegalArgumentException(
070: "Invalid arguments passed to the generator. Expecting three arguments : <implementation name> <destination directory> <reference>");
071: // arg[0] is the implementation mapping - comma separated list of implementations to invoke
072: String lImplementationNames = args[0];
073: // arg[1] is the absolute path to the destination directory
074: String lDestinationDirectory = args[1];
075: // arg[2] is the ref - comma separated list of references to generate stuff for
076: String lReferences = args[2];
077:
078: // First load all requested generators
079: ArrayList lGeneratorsList = new ArrayList();
080: StringTokenizer lImplementationNamesTokenizer = new StringTokenizer(
081: lImplementationNames, ",", false);
082: while (lImplementationNamesTokenizer.hasMoreTokens()) {
083: String lImplementationSuffix = lImplementationNamesTokenizer
084: .nextToken();
085: // Prepare the property based on implementation asked for.
086: Properties lContextProps = new Properties();
087: // This is the case where we do not want to use implementations cached for us by
088: // context because this will not allow us to load different implementations.
089: // The com.metaboss.naming.component.DisableContextCaching property switches thia off.
090: if (!lImplementationSuffix.equals("default"))
091: lContextProps
092: .setProperty(
093: "com.metaboss.naming.component.com.metaboss.sdlctools.services.codegeneration.BSServiceProxyGenerator",
094: "com.metaboss.sdlctools.services.codegeneration.serviceproxygenerator."
095: + lImplementationSuffix);
096: // Also pass all possible MetaBoss environment properties
097: lContextProps.putAll(PropertiesUtils.filterProperties(
098: System.getProperties(), "MetaBoss.", false));
099: Context ctx = new InitialContext(lContextProps);
100: lGeneratorsList.add(ctx
101: .lookup(BSServiceProxyGenerator.COMPONENT_URL));
102: }
103: BSServiceProxyGenerator[] lGenerators = (BSServiceProxyGenerator[]) lGeneratorsList
104: .toArray(new BSServiceProxyGenerator[lGeneratorsList
105: .size()]);
106: // Now iterate through references calling all generators on each reference
107: Context lContext = new InitialContext();
108: ModelRepository lModelRepository = (ModelRepository) lContext
109: .lookup(ModelRepository.COMPONENT_URL);
110: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
111: .getDefaultModelExtent();
112: ModelElementClass lModelElementClass = lMetaBossModelPackage
113: .getModelElement();
114: StringTokenizer lReferencesTokenizer = new StringTokenizer(
115: lReferences, ",", false);
116: while (lReferencesTokenizer.hasMoreTokens()) {
117: String lRef = lReferencesTokenizer.nextToken();
118: ModelElement lModelElement = lModelElementClass
119: .getByRef(lRef);
120: if (lModelElement instanceof Enterprise)
121: runGenerators(
122: lGenerators,
123: ApplicationUtils
124: .getAllServiceRefs((Enterprise) lModelElement),
125: lDestinationDirectory);
126: else if (lModelElement instanceof com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System)
127: runGenerators(
128: lGenerators,
129: ApplicationUtils
130: .getAllServiceRefs((com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) lModelElement),
131: lDestinationDirectory);
132: else if (lModelElement instanceof Servicemodule)
133: runGenerators(
134: lGenerators,
135: ApplicationUtils
136: .getAllServiceRefs((Servicemodule) lModelElement),
137: lDestinationDirectory);
138: else if (lModelElement instanceof Service)
139: runGenerators(lGenerators,
140: new String[] { lModelElement.getRef() },
141: lDestinationDirectory);
142: else
143: throw new IllegalArgumentException(
144: "Invalid reference passed to the generator. Expecting reference to the Service, Servicemodule, System or Enterprisere. Got "
145: + lRef);
146: }
147: System.exit(0);
148: } catch (Throwable t) {
149: ApplicationUtils.handleException(t);
150: System.exit(1);
151: }
152: }
153:
154: // Helper. Executes all generators for all services
155: private static void runGenerators(
156: BSServiceProxyGenerator[] pGenerators,
157: String[] pServiceRefs, String pGenerationDirectoryPath)
158: throws BSException {
159: for (int i = 0; i < pGenerators.length; i++)
160: for (int j = 0; j < pServiceRefs.length; j++)
161: pGenerators[i].generateSourceCodeForService(
162: pGenerationDirectoryPath, pServiceRefs[j]);
163: }
164: }
|