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.util.Arrays;
018: import java.util.HashSet;
019: import java.util.Iterator;
020: import java.util.Set;
021:
022: import javax.jmi.reflect.JmiException;
023:
024: import org.apache.tools.ant.BuildException;
025:
026: import com.metaboss.sdlctools.applications.anttasks.builder.ModuleDefinition;
027: import com.metaboss.sdlctools.applications.anttasks.builder.ModuleElementDefinition;
028: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
029: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
030: import com.metaboss.sdlctools.models.metabossmodel.designlibrarymodel.DesignLibrary;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
033:
034: /** The definition of how to build a data dictionary. */
035: public class IncludeDataDictionaryDefinition extends
036: ModuleElementDefinition {
037: // Initialise metadata for supplying in the constructor
038: private static ElementMetadata sElementMetadata = new ElementMetadata();
039: static {
040: sElementMetadata.ElementTypeName = "IncludeDataDictionary";
041: sElementMetadata.SupportsModelElementRefs = true;
042: sElementMetadata.AllowedModelElementTypes = new Class[] {
043: Enterprise.class,
044: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System.class,
045: DataDictionary.class, DesignLibrary.class, };
046: }
047: private boolean mIncludeReferenced = false;
048: private boolean mIncludeContained = true;
049: private Set mReferencedDataDictionaries = new HashSet(); // Referenced only. Need to generate and compile but do not package
050: private Set mContainedDataDictionaries = new HashSet(); // Included. Do everything
051:
052: /** The only available constructor */
053: public IncludeDataDictionaryDefinition(
054: ModuleDefinition pOwnerDefinition) {
055: super (pOwnerDefinition, sElementMetadata);
056: }
057:
058: /** The setter for the "includeReferenced" attribute */
059: public void setIncludeReferenced(boolean pIncludeReferenced) {
060: mIncludeReferenced = pIncludeReferenced;
061: }
062:
063: /** The setter for the "includeContained" attribute */
064: public void setIncludeContained(boolean pIncludeContained) {
065: mIncludeContained = pIncludeContained;
066: }
067:
068: // Called when initialisation of parameters has been completed and generation is about to commence
069: public void completeInitialisation() throws BuildException {
070: try {
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: mContainedDataDictionaries
077: .addAll(Arrays
078: .asList(getOwnerTask()
079: .findModelElementsByXPath(
080: lIncludedModelElement,
081: "descendant-or-self::DataDictionary",
082: new Class[] { DataDictionary.class })));
083: // Also add all data dictionaries referenced from servicemodules
084: ModelElement[] lIncludedServicemodules = (ModelElement[]) getOwnerTask()
085: .findModelElementsByXPath(
086: lIncludedModelElement,
087: "descendant-or-self::Servicemodule",
088: new Class[] { Servicemodule.class });
089: for (int i = 0; i < lIncludedServicemodules.length; i++) {
090: mReferencedDataDictionaries
091: .addAll(((Servicemodule) lIncludedServicemodules[i])
092: .getReferencedDataDictionaries());
093: }
094: }
095: // Now we have all servicemodules and datadictionaries explicitly included in the adapter.
096: // It is possible that there is an external data dictionary or servicemodule we need to have
097: // available to compile this one successfully.
098: for (Iterator lDataDictionariesIterator = mContainedDataDictionaries
099: .iterator(); lDataDictionariesIterator.hasNext();) {
100: DataDictionary lDataDictionary = (DataDictionary) lDataDictionariesIterator
101: .next();
102: mReferencedDataDictionaries.addAll(lDataDictionary
103: .getReferencedDataDictionaries());
104: }
105: } catch (JmiException e) {
106: throw new BuildException(
107: "Caught exception while preparing to build the Servicemodule Adapter. "
108: + e.getMessage());
109: }
110: }
111:
112: /** Returns array of datadictionaries which must be fully included in this definition */
113: public DataDictionary[] getDataDictionariesToInclude() {
114: Set lDataDictionariesToInclude = new HashSet();
115: if (mIncludeReferenced)
116: lDataDictionariesToInclude
117: .addAll(mReferencedDataDictionaries);
118: if (mIncludeContained)
119: lDataDictionariesToInclude
120: .addAll(mContainedDataDictionaries);
121: return (DataDictionary[]) lDataDictionariesToInclude
122: .toArray(new DataDictionary[lDataDictionariesToInclude
123: .size()]);
124: }
125:
126: /** Returns array of datadictionaries which must be referenced, which means only generated, compiled but not included */
127: public DataDictionary[] getDataDictionariesToReference() {
128: Set lDataDictionariesToReference = new HashSet();
129: if (!mIncludeReferenced)
130: lDataDictionariesToReference
131: .addAll(mReferencedDataDictionaries);
132: if (!mIncludeContained)
133: lDataDictionariesToReference
134: .addAll(mContainedDataDictionaries);
135: return (DataDictionary[]) lDataDictionariesToReference
136: .toArray(new DataDictionary[lDataDictionariesToReference
137: .size()]);
138: }
139: }
|