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 org.apache.tools.ant.taskdefs.optional.metaboss;
016:
017: import java.io.File;
018: import java.util.Iterator;
019: import java.util.List;
020:
021: import javax.naming.Context;
022: import javax.naming.InitialContext;
023:
024: import org.apache.tools.ant.BuildException;
025:
026: import com.metaboss.sdlctools.applications.anttasks.AntMetaBossUtils;
027: import com.metaboss.sdlctools.applications.anttasks.MetaBossModelToolTask;
028: import com.metaboss.sdlctools.models.ModelRepository;
029: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Enterprise;
031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
032: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.StorageTechnology;
033: import com.metaboss.sdlctools.services.metadatamanagement.BSDomainStorageManagement;
034:
035: /** Special Ant task used to invoke domain storage metadata generator. */
036: public class StorageMetadataGeneratorTask extends MetaBossModelToolTask {
037: private String mRef = null;
038: private String mStoragetechnologyref = null;
039: private String mReferenceModelName = null;
040:
041: /** Default constructor */
042: public StorageMetadataGeneratorTask() {
043: // This task uses existing model
044: super (true);
045: }
046:
047: /** The setter for the "storagetechnologyref" attribute */
048: public void setStoragetechnologyref(String pStoragetechnologyref) {
049: mStoragetechnologyref = pStoragetechnologyref;
050: }
051:
052: /** The getter for the "storagetechnologyref" attribute. */
053: public String getStoragetechnologyref() {
054: if (mStoragetechnologyref == null)
055: throw new BuildException(
056: "Missing 'mStoragetechnologyref' attribute, which is mandatory for <"
057: + getTaskName() + "> task.");
058: return mStoragetechnologyref;
059: }
060:
061: /** The setter for the "ref" attribute */
062: public void setRef(String pRef) {
063: mRef = pRef;
064: }
065:
066: /** The getter for the "Ref" attribute. Passed to the destination application as an argument */
067: public String getRef() {
068: if (mRef == null)
069: throw new BuildException(
070: "Missing 'ref' attribute, which is mandatory for <"
071: + getTaskName() + "> task.");
072: return mRef;
073: }
074:
075: // The setter for the "referencemodeldir" attribute
076: public void setReferenceModelDir(File pReferenceModelDir) {
077: mReferenceModelName = pReferenceModelDir.getAbsolutePath()
078: + File.separator + "Model.xml";
079: }
080:
081: // The getter for the optional reference model name
082: protected String getReferenceModelName() throws BuildException {
083: return mReferenceModelName;
084: }
085:
086: // The method executing the tool
087: public void runTool() throws Exception {
088: Context lContext = new InitialContext();
089:
090: // Obtain the system here, so we can complain if something is wrong
091: ModelElement lModelElement = getModelElement(
092: getRef(),
093: new Class[] {
094: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System.class,
095: Domain.class, Enterprise.class });
096: StorageTechnology lStorageTechnology = (StorageTechnology) getModelElement(
097: getStoragetechnologyref(),
098: new Class[] { StorageTechnology.class });
099:
100: // Ensure that the reference model is loaded
101: if (getReferenceModelName() != null) {
102: ModelRepository lModelRepository = (ModelRepository) lContext
103: .lookup(ModelRepository.COMPONENT_URL);
104: if (!lModelRepository
105: .containsModel(getReferenceModelName()))
106: lModelRepository.openModel(getReferenceModelName(),
107: new File(getReferenceModelName()),
108: ModelRepository.METAMODEL_NAME_METABOSS);
109: }
110:
111: // Get the generator
112: BSDomainStorageManagement lGenerator = (BSDomainStorageManagement) lContext
113: .lookup(BSDomainStorageManagement.COMPONENT_URL);
114:
115: // Use XPath to locate all domains under specified ref and generate metadata for it
116: List lDomains = AntMetaBossUtils.getModelRepository()
117: .searchByXPath(lModelElement,
118: "descendant-or-self::Domain");
119: for (Iterator lDomainsIter = lDomains.iterator(); lDomainsIter
120: .hasNext();) {
121: lGenerator.updateMetadataForDomain(lStorageTechnology
122: .getRef(), ((Domain) lDomainsIter.next()).getRef(),
123: getReferenceModelName());
124: }
125: }
126: }
|