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.tools;
016:
017: import org.apache.tools.ant.BuildException;
018:
019: import com.metaboss.enterprise.bs.BSException;
020: import com.metaboss.sdlctools.applications.anttasks.builder.MetaBossBuilderTask;
021: import com.metaboss.sdlctools.applications.anttasks.builder.ToolInvocationDefinition;
022: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.domainimplementationmodel.DomainRelationalStorageDefinition;
023: import com.metaboss.sdlctools.services.codegeneration.BSStorageImplementationGenerator;
024:
025: /** This definition is responsible for invocation of the StorageImplementation generator */
026: public class StorageImplementationGeneratorInvocationDefinition extends
027: ToolInvocationDefinition {
028: private BSStorageImplementationGenerator mGenerator = null;
029: private DomainRelationalStorageDefinition mDomainRelationalStorageDefinition = null;
030:
031: /** Public constructor for the invocation */
032: public StorageImplementationGeneratorInvocationDefinition(
033: MetaBossBuilderTask pOwnerTask) {
034: super (pOwnerTask,
035: "Generate implementation code for the storage");
036: }
037:
038: // Override to return better description if possible
039: public String getToolInvocationName() {
040: if (mDomainRelationalStorageDefinition == null)
041: return super .getToolInvocationName();
042: return "Generate implementation code for the "
043: + getDomainRelationalStorageDefinition().getRef()
044: + " storage";
045: }
046:
047: /** Setter for the DomainRelationalStorageDefinition this invocation is dealing with */
048: public void setDomainRelationalStorageDefinition(
049: DomainRelationalStorageDefinition pDomainRelationalStorageDefinition) {
050: mDomainRelationalStorageDefinition = pDomainRelationalStorageDefinition;
051: }
052:
053: /** Getter for the DomainRelationalStorageDefinition this invocation is dealing with */
054: public DomainRelationalStorageDefinition getDomainRelationalStorageDefinition() {
055: if (mDomainRelationalStorageDefinition == null)
056: throw new BuildException(
057: "Missing DomainRelationalStorageDefinition, which is mandatory for generator invocation.");
058: return mDomainRelationalStorageDefinition;
059: }
060:
061: /** Setter for the Generator */
062: public void setGenerator(BSStorageImplementationGenerator pGenerator) {
063: mGenerator = pGenerator;
064: }
065:
066: /** Getter for the Generator */
067: public BSStorageImplementationGenerator getGenerator() {
068: if (mGenerator == null)
069: throw new BuildException(
070: "Missing BSStorageImplementationGenerator service, which is mandatory for storage implmentation generation.");
071: return mGenerator;
072: }
073:
074: /** Overridden to compare details of the invocation */
075: public boolean equals(Object pOther) {
076: if (this == pOther)
077: return true;
078: if (pOther instanceof StorageImplementationGeneratorInvocationDefinition) {
079: StorageImplementationGeneratorInvocationDefinition lOther = (StorageImplementationGeneratorInvocationDefinition) pOther;
080: if (getDomainRelationalStorageDefinition().equals(
081: lOther.getDomainRelationalStorageDefinition()))
082: return true;
083: }
084: return false;
085: }
086:
087: /** This method will have to invoke the generator */
088: public void invoke() throws BuildException {
089: // Allow to look for the data type classes in the destination class ditectory
090: String lOriginalProperty = System
091: .setProperty(
092: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath",
093: getOwnerTask().getClassDir().getAbsolutePath());
094: // Run inprocess
095: try {
096: mGenerator.generateImplementationSourceCodeForDomain(
097: getOwnerTask().getGenDir().getAbsolutePath(),
098: getDomainRelationalStorageDefinition().getRef());
099: } catch (BSException e) {
100: throw new BuildException(
101: "Unable to run generator for the Storage Implementation. Caught BSException: "
102: + e.getMessage());
103: } finally {
104: if (lOriginalProperty != null)
105: System
106: .setProperty(
107: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath",
108: lOriginalProperty);
109: else
110: System
111: .getProperties()
112: .remove(
113: "com.metaboss.sdlctools.services.codegenerationstylesheet.BSCodeGenerationStylesheet.datatypeclasspath");
114: }
115: }
116: }
|