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.Properties;
019:
020: import javax.naming.Context;
021: import javax.naming.InitialContext;
022:
023: import org.apache.tools.ant.BuildException;
024:
025: import com.metaboss.sdlctools.applications.anttasks.MetaBossModelToolTask;
026: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
028: import com.metaboss.sdlctools.services.codegeneration.BSStorageDistributionGenerator;
029:
030: /** Special Ant task used to generate storage distribution layer */
031: public class StorageDistributionGeneratorTask extends
032: MetaBossModelToolTask {
033: private File mDestinationDir = null;
034: private String mRef = null;
035: private String mImplementationName = null;
036:
037: public StorageDistributionGeneratorTask() {
038: // This task uses existing model
039: super (true);
040: }
041:
042: /** The setter for the "ref" attribute */
043: public void setRef(String pRef) {
044: mRef = pRef;
045: }
046:
047: // The getter for the "Ref" attribute. Passed to the destination application as an argument
048: protected String getRef() {
049: if (mRef == null)
050: throw new BuildException(
051: "Missing 'ref' attribute, which is mandatory for <"
052: + getTaskName() + "> task.");
053: return mRef;
054: }
055:
056: /** The setter for the "destinationdir" attribute */
057: public void setDestinationdir(File pDestinationDir) {
058: mDestinationDir = pDestinationDir;
059: }
060:
061: // The getter for the "destinationdir" attribute
062: protected File getDestinationdir() {
063: if (mDestinationDir == null)
064: throw new BuildException(
065: "Missing 'destinationdir' attribute, which is mandatory for <"
066: + getTaskName() + "> task.");
067: return mDestinationDir;
068: }
069:
070: /** The setter for the "implementationname" attribute */
071: public void setImplementationName(String pImplementationName) {
072: mImplementationName = pImplementationName;
073: }
074:
075: /** The getter for the "implementationname" attribute */
076: public String getImplementationName() {
077: return mImplementationName;
078: }
079:
080: // The method executing the tool
081: public void runTool() throws Exception {
082: // Get the domain and storage technology details
083: ModelElement lModelElement = getModelElement(getRef(),
084: new Class[] { Domain.class });
085:
086: // Get generator and run generation
087: Context lContext = null;
088: // Initialise context with the specified implementation if there is one
089: if (getImplementationName() != null
090: && getImplementationName().equals("default") == false) {
091: Properties lContextProps = new Properties();
092: lContextProps
093: .setProperty(
094: "com.metaboss.naming.component.com.metaboss.sdlctools.services.codegeneration.BSStorageDistributionGenerator",
095: "com.metaboss.sdlctools.services.codegeneration.storagedistributiongenerator."
096: + getImplementationName());
097: lContext = new InitialContext(lContextProps);
098: } else
099: lContext = new InitialContext();
100: BSStorageDistributionGenerator lGenerator = (BSStorageDistributionGenerator) lContext
101: .lookup(BSStorageDistributionGenerator.COMPONENT_URL);
102: lGenerator.generateImplementationSourceCodeForDomain(
103: getDestinationdir().getAbsolutePath(), lModelElement
104: .getRef());
105: }
106: }
|