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 org.apache.tools.ant.BuildException;
024:
025: import com.metaboss.enterprise.bs.BSException;
026: import com.metaboss.sdlctools.applications.anttasks.builder.ModuleDefinition;
027: import com.metaboss.sdlctools.applications.anttasks.builder.ModuleElementDefinition;
028: import com.metaboss.sdlctools.applications.anttasks.builder.ToolInvocationDefinition;
029: import com.metaboss.sdlctools.applications.anttasks.builder.tools.JavaCompilerInvocationDefinitionUtils;
030: import com.metaboss.sdlctools.applications.anttasks.builder.tools.CoreCodeGeneratorInvocationDefinition;
031: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
034: import com.metaboss.sdlctools.services.codegeneration.CodeGenerationStylesheetAccessor;
035: import com.metaboss.sdlctools.services.codegenerationstylesheet.STDomainStylesheet;
036: import com.metaboss.util.StringUtils;
037:
038: /** The definition of included storage implementation. */
039: public class IncludeDomainImplementationDefinition extends
040: ModuleElementDefinition {
041: // Initialise metadata for supplying in the constructor
042: private static ElementMetadata sElementMetadata = new ElementMetadata();
043: static {
044: sElementMetadata.ElementTypeName = "IncludeDomainImplementation";
045: sElementMetadata.SupportsModelElementRefs = true;
046: sElementMetadata.AllowedModelElementTypes = new Class[] {
047: Enterprise.class,
048: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System.class,
049: Domain.class, };
050: }
051: private List mDomainsToDo = new ArrayList();
052:
053: /** The only available constructor */
054: public IncludeDomainImplementationDefinition(
055: ModuleDefinition pOwnerModule) {
056: super (pOwnerModule, sElementMetadata);
057: }
058:
059: /** Returns array of domains included in this definition */
060: public Domain[] getIncludedDomains() {
061: return (Domain[]) mDomainsToDo.toArray(new Domain[mDomainsToDo
062: .size()]);
063: }
064:
065: // Called when initialisation of parameters has been completed and generation is about to commence
066: public void completeInitialisation() throws BuildException {
067: // Work on included module elements
068: ModelElement[] lIncludedModelElements = getIncludedModelElements();
069: // First collect list of al domains to generate implementations for
070: for (int lElementsIndex = 0; lElementsIndex < lIncludedModelElements.length; lElementsIndex++) {
071: ModelElement lIncludedModelElement = lIncludedModelElements[lElementsIndex];
072: mDomainsToDo.addAll(Arrays.asList(getOwnerTask()
073: .findModelElementsByXPath(lIncludedModelElement,
074: "descendant-or-self::Domain",
075: new Class[] { Domain.class })));
076: }
077: }
078:
079: // Returns plan to invoke any number of code generators necessary to build the module
080: public ToolInvocationDefinition[] getGenerationPlan() {
081: List lInvocations = new ArrayList();
082: for (Iterator lDomainsIterator = mDomainsToDo.iterator(); lDomainsIterator
083: .hasNext();) {
084: Domain lDomain = (Domain) lDomainsIterator.next();
085: // Will need to generate core of the system this is where domain is
086: CoreCodeGeneratorInvocationDefinition lSystemCoreGeneratorInvocationDefinition = new CoreCodeGeneratorInvocationDefinition(
087: getOwnerTask());
088: lSystemCoreGeneratorInvocationDefinition
089: .setSystemRef(lDomain.getSystem().getRef());
090: lInvocations.add(lSystemCoreGeneratorInvocationDefinition);
091: }
092: // Return what we have
093: return (ToolInvocationDefinition[]) lInvocations
094: .toArray(new ToolInvocationDefinition[lInvocations
095: .size()]);
096: }
097:
098: // Returns tasks to do after generation. (Normally compillation would go in here
099: public ToolInvocationDefinition[] getCompilationPlan() {
100: try {
101: List lInvocations = new ArrayList();
102: // Compile parts of the core
103: for (Iterator lDomainsIterator = mDomainsToDo.iterator(); lDomainsIterator
104: .hasNext();) {
105: Domain lDomain = (Domain) lDomainsIterator.next();
106: // Will need to compile enterprise types
107: lInvocations.add(JavaCompilerInvocationDefinitionUtils
108: .createForEnterpriseTypes(this , lDomain
109: .getSystem().getEnterprise()));
110: // Will need to compile system types
111: lInvocations
112: .add(JavaCompilerInvocationDefinitionUtils
113: .createForSystemTypes(this , lDomain
114: .getSystem()));
115: // Domain interfaces
116: lInvocations.add(JavaCompilerInvocationDefinitionUtils
117: .createForDomainInterfaces(this , lDomain));
118: // Storage interfaces
119: lInvocations.add(JavaCompilerInvocationDefinitionUtils
120: .createForStorageInterfaces(this , lDomain));
121: // Domain implementations interfaces
122: lInvocations.add(JavaCompilerInvocationDefinitionUtils
123: .createForDomainImplementation(this , lDomain));
124: }
125: // Return what we have
126: return (ToolInvocationDefinition[]) lInvocations
127: .toArray(new ToolInvocationDefinition[lInvocations
128: .size()]);
129: } catch (BSException e) {
130: throw new BuildException(
131: "Caught exception while generating packaging plan. "
132: + e.getMessage());
133: }
134: }
135:
136: /** Return tool invocations */
137: public String[] getJarClassIncludes() throws BSException {
138: List lJarClassIncludes = new ArrayList();
139: // Compile parts of the core
140: for (Iterator lDomainsIterator = mDomainsToDo.iterator(); lDomainsIterator
141: .hasNext();) {
142: Domain lDomain = (Domain) lDomainsIterator.next();
143: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
144: .getSystem();
145: STDomainStylesheet lDomainStylesheet = CodeGenerationStylesheetAccessor
146: .getDomainStylesheet(lDomain);
147: // Domain interfaces
148: String lDomainInterfacePackage = lDomainStylesheet
149: .getDomainPackageName();
150: String lDomainInterfaceSubdirectory = StringUtils.replace(
151: lDomainInterfacePackage, ".", File.separator);
152: lJarClassIncludes.add(lDomainInterfaceSubdirectory
153: + File.separator + "*.*");
154: // Domain implementations interfaces
155: String lDomainImplementationPackage = lDomainStylesheet
156: .getImplementationPackageName();
157: String lDomainImplementationSubdirectory = StringUtils
158: .replace(lDomainImplementationPackage, ".",
159: File.separator);
160: lJarClassIncludes.add(lDomainImplementationSubdirectory
161: + File.separator + "*.*");
162: }
163: // Return what we have
164: return (String[]) lJarClassIncludes
165: .toArray(new String[lJarClassIncludes.size()]);
166: }
167: }
|