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:
019: import javax.naming.Context;
020: import javax.naming.InitialContext;
021:
022: import org.apache.tools.ant.BuildException;
023:
024: import com.metaboss.sdlctools.applications.anttasks.MetaBossModelToolTask;
025: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
026: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.domainimplementationmodel.DomainRelationalStorageDefinition;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.domainimplementationmodel.DomainRelationalStorageDefinitionClass;
028: import com.metaboss.sdlctools.models.metabossmodel.technologylibrarymodel.RelationalStorageTechnology;
029: import com.metaboss.sdlctools.services.codegeneration.BSStorageImplementationGenerator;
030:
031: /** Special Ant task used to invoke storage implementation generator. */
032: public class StorageImplementationGeneratorTask extends
033: MetaBossModelToolTask {
034: private File mDestinationDir = null;
035: private String mRef = null;
036: private String mStoragetechnologyref = null;
037:
038: public StorageImplementationGeneratorTask() {
039: // This task uses existing model
040: super (true);
041: }
042:
043: /** The setter for the "ref" attribute */
044: public void setRef(String pRef) {
045: mRef = pRef;
046: }
047:
048: // The getter for the "Ref" attribute. Passed to the destination application as an argument
049: protected String getRef() {
050: if (mRef == null)
051: throw new BuildException(
052: "Missing 'ref' attribute, which is mandatory for <"
053: + getTaskName() + "> task.");
054: return mRef;
055: }
056:
057: // The setter for the "storagetechnologyref" attribute
058: public void setStoragetechnologyref(String pStoragetechnologyref) {
059: mStoragetechnologyref = pStoragetechnologyref;
060: }
061:
062: // The setter for the "storagetechnologyref" attribute
063: public String getStoragetechnologyref() {
064: if (mStoragetechnologyref == null)
065: throw new BuildException(
066: "Missing 'storagetechnologyref' attribute, which is mandatory for <"
067: + getTaskName() + "> task.");
068: return mStoragetechnologyref;
069: }
070:
071: /** The setter for the "destinationdir" attribute */
072: public void setDestinationdir(File pDestinationDir) {
073: mDestinationDir = pDestinationDir;
074: }
075:
076: // The getter for the "destinationdir" attribute
077: protected File getDestinationdir() {
078: if (mDestinationDir == null)
079: throw new BuildException(
080: "Missing 'destinationdir' attribute, which is mandatory for <"
081: + getTaskName() + "> task.");
082: return mDestinationDir;
083: }
084:
085: // The method executing the tool
086: public void runTool() throws Exception {
087: // Get the domain and storage technology details
088: Domain lDomain = (Domain) getModelElement(getRef(),
089: new Class[] { Domain.class });
090: RelationalStorageTechnology lTechnology = (RelationalStorageTechnology) getModelElement(
091: getStoragetechnologyref(),
092: new Class[] { RelationalStorageTechnology.class });
093: // Get the definition for this domain on this technology
094: DomainRelationalStorageDefinitionClass lDomainStorageDefinitionClass = getModelRootPackage()
095: .getEnterpriseModel().getSystemImplementationModel()
096: .getDomainImplementationModel()
097: .getDomainRelationalStorageDefinition();
098: DomainRelationalStorageDefinition lDomainStorageDefinition = lDomainStorageDefinitionClass
099: .getDomainRelationalStorageDefinition(lDomain,
100: lTechnology);
101:
102: // Get generator and run generation
103: Context ctx = new InitialContext();
104: BSStorageImplementationGenerator lGenerator = (BSStorageImplementationGenerator) ctx
105: .lookup(BSStorageImplementationGenerator.COMPONENT_URL);
106: lGenerator.generateImplementationSourceCodeForDomain(
107: getDestinationdir().getAbsolutePath(),
108: lDomainStorageDefinition.getRef());
109: }
110: }
|