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.domains.storagemodel.impl;
016:
017: import javax.naming.Context;
018: import javax.naming.InitialContext;
019: import javax.naming.NamingException;
020:
021: import com.metaboss.enterprise.bo.BOException;
022: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
023: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
024: import com.metaboss.enterprise.bo.BOUnexpectedProgramConditionException;
025: import com.metaboss.enterprise.ps.PSException;
026: import com.metaboss.sdlctools.domains.storagemodel.BOStorageTechnology;
027: import com.metaboss.sdlctools.domains.storagemodel.BOStorageTechnologyDomainStorageList;
028: import com.metaboss.sdlctools.domains.storagemodel.storage.PSStorageTechnology;
029: import com.metaboss.sdlctools.domains.storagemodel.storage.STStorageTechnology;
030: import com.metaboss.sdlctools.types.storagemodel.StorageTechnologyType;
031: import com.oldboss.framework.bo.impl.BOObjectImpl;
032:
033: public abstract class BOStorageTechnologyImpl extends BOObjectImpl
034: implements BOStorageTechnology {
035: protected BOMetaBossDomainImpl mMetaBossDomainImpl = null;
036: protected String mStorageTechnologyRef = null;
037: private STStorageTechnology mStorageTechnologyDetails = null;
038:
039: /* Instance creator */
040: public static BOStorageTechnology createInstanceForExisting(
041: BOMetaBossDomainImpl pMetaBossDomainImpl,
042: String pStorageTechnologyRef) throws BOException {
043: try {
044: // Get the instance of the enterprise ps home via jndi
045: Context ctx = new InitialContext();
046: PSStorageTechnology lPs = (PSStorageTechnology) ctx
047: .lookup(PSStorageTechnology.COMPONENT_URL);
048: STStorageTechnology lDetails = lPs
049: .getStorageTechnology(pStorageTechnologyRef);
050: if (lDetails == null)
051: throw new BOException(
052: "StorageTechnology not found. StorageTechnologyRef: "
053: + pStorageTechnologyRef);
054: if (lDetails.TechnologyType
055: .equals(StorageTechnologyType.RELATIONAL))
056: return BORelationalStorageTechnologyImpl
057: .createInstanceForExisting(pMetaBossDomainImpl,
058: pStorageTechnologyRef, lDetails);
059: throw new BOUnexpectedProgramConditionException(
060: "Storage technology type is not supported. StorageTechnologyRef: "
061: + pStorageTechnologyRef
062: + " StorageTechnologyType: "
063: + lDetails.TechnologyType);
064: } catch (NamingException e) {
065: throw new BONamingAndDirectoryServiceInvocationException(
066: "", e);
067: } catch (PSException e) {
068: throw new BOPersistenceServiceInvocationException(
069: "Exception caught during loading of Storage Technology details. StorageTechnologyRef: "
070: + pStorageTechnologyRef, e);
071: }
072: }
073:
074: /* Protect an access to this constructor */
075: protected BOStorageTechnologyImpl() throws BOException {
076: }
077:
078: /* Setup instance representing an existing entity */
079: protected void setupInstanceForExisting(
080: BOMetaBossDomainImpl pMetaBossDomainImpl,
081: String pStorageTechnologyRef,
082: STStorageTechnology pStorageTechnologyDetails)
083: throws BOException {
084: mMetaBossDomainImpl = pMetaBossDomainImpl;
085: mStorageTechnologyRef = pStorageTechnologyRef;
086: mStorageTechnologyDetails = pStorageTechnologyDetails;
087: }
088:
089: /* Retrieves unique reference */
090: public String getRef() throws BOException {
091: return mStorageTechnologyRef;
092: }
093:
094: /* Retrieves technology name. Usually last part of the reference.
095: * name is only unique within its package */
096: public String getName() throws BOException {
097: String lRef = getRef();
098: return lRef.substring(lRef.lastIndexOf(".") + 1);
099: }
100:
101: /* Retrieves description */
102: public String getDescription() throws BOException {
103: loadDetailsIfNecessary();
104: return mStorageTechnologyDetails.Description;
105: }
106:
107: /* Retrieves the reference to the optional domain storage metadata generator */
108: public String getDomainStorageMetaDataGeneratorRef()
109: throws BOException {
110: loadDetailsIfNecessary();
111: return mStorageTechnologyDetails.DomainStorageMetaDataGeneratorRef;
112: }
113:
114: /* Retrieves the reference to the domain storage implementation generator */
115: public String getDomainStorageImplementationGeneratorRef()
116: throws BOException {
117: loadDetailsIfNecessary();
118: return mStorageTechnologyDetails.DomainStorageImplementationGeneratorRef;
119: }
120:
121: /* Retrieves all domain storage definitions for this storage technology */
122: public BOStorageTechnologyDomainStorageList getDomainStorages()
123: throws BOException {
124: return BOStorageTechnologyDomainStorageListImpl
125: .createInstanceForExisting(mMetaBossDomainImpl, this );
126: }
127:
128: /* Retrieves the type of the template source */
129: public StorageTechnologyType getType() throws BOException {
130: loadDetailsIfNecessary();
131: return mStorageTechnologyDetails.TechnologyType;
132: }
133:
134: private void loadDetailsIfNecessary() throws BOException {
135: if (mStorageTechnologyDetails == null) {
136: try {
137: // Get the instance of the enterprise ps home via jndi
138: Context ctx = new InitialContext();
139: PSStorageTechnology lPs = (PSStorageTechnology) ctx
140: .lookup(PSStorageTechnology.COMPONENT_URL);
141:
142: mStorageTechnologyDetails = lPs
143: .getStorageTechnology(mStorageTechnologyRef);
144: if (mStorageTechnologyDetails == null)
145: throw new BOException(
146: "StorageTechnology not found. StorageTechnologyRef: "
147: + mStorageTechnologyRef);
148: } catch (NamingException e) {
149: throw new BONamingAndDirectoryServiceInvocationException(
150: "", e);
151: } catch (PSException e) {
152: throw new BOPersistenceServiceInvocationException(
153: "Exception caught during loading of Storage Technology details. StorageTechnologyRef: "
154: + mStorageTechnologyRef, e);
155: }
156: }
157: }
158: }
|