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.anttasks.builder.modules.subelements;
016:
017: import java.io.File;
018: import java.util.ArrayList;
019: import java.util.Arrays;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import javax.jmi.reflect.JmiException;
024: import javax.naming.Context;
025: import javax.naming.InitialContext;
026: import javax.naming.NamingException;
027:
028: import org.apache.tools.ant.BuildException;
029:
030: import com.metaboss.enterprise.bs.BSException;
031: import com.metaboss.sdlctools.applications.anttasks.builder.ModuleDefinition;
032: import com.metaboss.sdlctools.applications.anttasks.builder.ModuleElementDefinition;
033: import com.metaboss.sdlctools.applications.anttasks.builder.ToolInvocationDefinition;
034: import com.metaboss.sdlctools.applications.anttasks.builder.tools.DomainSupportGeneratorInvocationDefinition;
035: import com.metaboss.sdlctools.applications.anttasks.builder.tools.JavaCompilerInvocationDefinitionUtils;
036: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
037: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
038: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
039: import com.metaboss.sdlctools.services.codegeneration.BSDomainSupportServicesImplementationGenerator;
040: import com.metaboss.util.StringUtils;
041:
042: /** The definition of how to build a generated implementation of the domain support business service. */
043: public class BusinessServiceDomainSupportImplementationDefinition
044: extends ModuleElementDefinition {
045: // Initialise metadata for supplying in the constructor
046: private static ElementMetadata sElementMetadata = new ElementMetadata();
047: static {
048: sElementMetadata.ElementTypeName = "BusinessServiceDomainSupportImplementation";
049: sElementMetadata.SupportsModelElementRefs = true;
050: sElementMetadata.AllowedModelElementTypes = new Class[] {
051: Enterprise.class,
052: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System.class,
053: Domain.class, };
054: }
055: private BSDomainSupportServicesImplementationGenerator mServiceImplementationGenerator = null;
056: private List mDomainsToDo = new ArrayList();
057:
058: /** The only available constructor */
059: public BusinessServiceDomainSupportImplementationDefinition(
060: ModuleDefinition pOwnerModule) {
061: super (pOwnerModule, sElementMetadata);
062: }
063:
064: // Called when initialisation of parameters has been completed and generation is about to commence
065: public void completeInitialisation() throws BuildException {
066: try {
067: Context lContext = new InitialContext();
068: mServiceImplementationGenerator = (BSDomainSupportServicesImplementationGenerator) lContext
069: .lookup(BSDomainSupportServicesImplementationGenerator.COMPONENT_URL);
070:
071: // Work on included module elements
072: ModelElement[] lIncludedModelElements = getIncludedModelElements();
073: // First collect list of al domains to generate implementations for
074: for (int lElementsIndex = 0; lElementsIndex < lIncludedModelElements.length; lElementsIndex++) {
075: ModelElement lIncludedModelElement = lIncludedModelElements[lElementsIndex];
076: mDomainsToDo.addAll(Arrays.asList(getOwnerTask()
077: .findModelElementsByXPath(
078: lIncludedModelElement,
079: "descendant-or-self::Domain",
080: new Class[] { Domain.class })));
081: }
082: } catch (NamingException e) {
083: throw new BuildException(
084: "Unable to locate generator for the Service Implementation. Caught NamingException: "
085: + e.getMessage());
086: } catch (JmiException e) {
087: throw new BuildException(
088: "Caught exception while preparing to build module. "
089: + e.getMessage());
090: }
091: }
092:
093: /** Returns array of domains included in this definition */
094: public Domain[] getIncludedDomains() {
095: return (Domain[]) mDomainsToDo.toArray(new Domain[mDomainsToDo
096: .size()]);
097: }
098:
099: /** Return tool invocations */
100: public ToolInvocationDefinition[] getGenerationPlan()
101: throws BSException {
102: List lInvocations = new ArrayList();
103: for (Iterator lDomainsIterator = mDomainsToDo.iterator(); lDomainsIterator
104: .hasNext();) {
105: Domain lDomain = (Domain) lDomainsIterator.next();
106: DomainSupportGeneratorInvocationDefinition lDomainSupportGeneratorInvocationDefinition = new DomainSupportGeneratorInvocationDefinition(
107: getOwnerTask());
108: lDomainSupportGeneratorInvocationDefinition.setRef(lDomain
109: .getRef());
110: lInvocations
111: .add(lDomainSupportGeneratorInvocationDefinition);
112: }
113: // Return what we have
114: return (ToolInvocationDefinition[]) lInvocations
115: .toArray(new ToolInvocationDefinition[lInvocations
116: .size()]);
117: }
118:
119: /** Return tool invocations */
120: public ToolInvocationDefinition[] getCompilationPlan()
121: throws BSException {
122: List lInvocations = new ArrayList();
123: for (Iterator lDomainsIterator = mDomainsToDo.iterator(); lDomainsIterator
124: .hasNext();) {
125: Domain lDomain = (Domain) lDomainsIterator.next();
126: lInvocations.add(JavaCompilerInvocationDefinitionUtils
127: .createForDomainSupportImplementation(this ,
128: lDomain, getGenerator()));
129: }
130: // Return what we have
131: return (ToolInvocationDefinition[]) lInvocations
132: .toArray(new ToolInvocationDefinition[lInvocations
133: .size()]);
134: }
135:
136: /** Return tool invocations */
137: public String[] getJarClassIncludes() throws BSException {
138: List lJarClassIncludes = new ArrayList();
139: for (Iterator lDomainsIterator = mDomainsToDo.iterator(); lDomainsIterator
140: .hasNext();) {
141: Domain lDomain = (Domain) lDomainsIterator.next();
142: String lImplementationPackage = getGenerator()
143: .getImplementationPackageName(lDomain.getRef());
144: String lCLassInclude = StringUtils.replace(
145: lImplementationPackage, ".", File.separator)
146: + File.separator + "/*.*";
147: lJarClassIncludes.add(lCLassInclude);
148: }
149: // Return what we have
150: return (String[]) lJarClassIncludes
151: .toArray(new String[lJarClassIncludes.size()]);
152: }
153:
154: /** @return generator for the adapter */
155: public BSDomainSupportServicesImplementationGenerator getGenerator() {
156: if (mServiceImplementationGenerator == null)
157: throw new BuildException("Element <"
158: + sElementMetadata.ElementTypeName
159: + ">has not been initialised properly.");
160: return mServiceImplementationGenerator;
161: }
162: }
|