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.services.codegeneration.storageimplementationgenerator.relational.oracle;
016:
017: import java.util.Hashtable;
018:
019: import javax.naming.Context;
020: import javax.naming.InitialContext;
021: import javax.naming.NamingException;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025:
026: import com.metaboss.enterprise.bo.BOException;
027: import com.metaboss.enterprise.bs.BSDomainObjectInvocationException;
028: import com.metaboss.enterprise.bs.BSException;
029: import com.metaboss.enterprise.bs.BSNamingAndDirectoryServiceInvocationException;
030: import com.metaboss.sdlctools.models.ModelRepository;
031: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.domainimplementationmodel.DomainRelationalStorageDefinition;
033: import com.metaboss.sdlctools.services.codegeneration.BSStorageImplementationGenerator;
034: import com.metaboss.sdlctools.services.codegeneration.storageimplementationgenerator.relational.DataBaseMetaData;
035:
036: /** Generator of storage implementation based on Oracle DBMS */
037: public class BSStorageImplementationGeneratorImpl implements
038: BSStorageImplementationGenerator {
039: // Commons Logging instance.
040: private static final Log sLogger = LogFactory
041: .getLog(BSStorageImplementationGeneratorImpl.class);
042: private static DataBaseMetaData sDataBaseMetaData = new OracleDataBaseMetaData();
043:
044: private Hashtable mEnvironment = null;
045: private ImplementationGenerator mImplementationGenerator = null;
046: private DBScriptsGenerator mDBScriptsGenerator = null;
047:
048: public BSStorageImplementationGeneratorImpl(Hashtable pEnvironment)
049: throws BSException {
050: mEnvironment = pEnvironment;
051: mImplementationGenerator = new ImplementationGenerator(
052: sDataBaseMetaData);
053: mDBScriptsGenerator = new DBScriptsGenerator(sDataBaseMetaData);
054: }
055:
056: /** Returns the name of the implementation package for use in jndi mapping */
057: public String getImplementationPackageName(
058: String pDomainRelationalStorageDefinitionRef)
059: throws BSException {
060: try {
061: // Get the referenced objects from the model
062: Context lContext = new InitialContext();
063: ModelRepository lModelRepository = (ModelRepository) lContext
064: .lookup(ModelRepository.COMPONENT_URL);
065: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
066: .getDefaultModelExtent();
067: // Get the definition to work with
068: DomainRelationalStorageDefinition lDomainStorageDefinition = (DomainRelationalStorageDefinition) lMetaBossModelPackage
069: .getModelElement().getByRef(
070: pDomainRelationalStorageDefinitionRef);
071: // Now we can do the job
072: return mImplementationGenerator
073: .getImplementationJavaPackage(lDomainStorageDefinition);
074: } catch (NamingException e) {
075: throw new BSNamingAndDirectoryServiceInvocationException(e);
076: } catch (BOException e) {
077: throw new BSDomainObjectInvocationException(e);
078: }
079: }
080:
081: /* Generates storage implementation sourcecode for the particular domain within particular enterprise */
082: public void generateImplementationSourceCodeForDomain(
083: String pGenerationDirectoryPath,
084: String pDomainRelationalStorageDefinitionRef)
085: throws BSException {
086: try {
087: sLogger
088: .info("Generating storage implementation source for "
089: + pDomainRelationalStorageDefinitionRef
090: + " storage");
091:
092: // Get the referenced objects from the model
093: Context lContext = new InitialContext();
094: ModelRepository lModelRepository = (ModelRepository) lContext
095: .lookup(ModelRepository.COMPONENT_URL);
096: MetaBossModelPackage lMetaBossModelPackage = (MetaBossModelPackage) lModelRepository
097: .getDefaultModelExtent();
098: // Get the definition to work with
099: DomainRelationalStorageDefinition lDomainStorageDefinition = (DomainRelationalStorageDefinition) lMetaBossModelPackage
100: .getModelElement().getByRef(
101: pDomainRelationalStorageDefinitionRef);
102:
103: // Now do the actual generation
104: mImplementationGenerator.generateImplementation(
105: pGenerationDirectoryPath, lDomainStorageDefinition);
106: mDBScriptsGenerator.generateDBScripts(
107: pGenerationDirectoryPath, lDomainStorageDefinition);
108:
109: // Done
110: sLogger
111: .info("Done generating storage implementation source for "
112: + pDomainRelationalStorageDefinitionRef
113: + " storage");
114: } catch (NamingException e) {
115: throw new BSNamingAndDirectoryServiceInvocationException(e);
116: } catch (BOException e) {
117: throw new BSDomainObjectInvocationException(e);
118: }
119: }
120: }
|