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.BOInvalidOperationForReadOnlyObjectException;
023: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
024: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
025: import com.metaboss.enterprise.bo.BOUnexpectedProgramConditionException;
026: import com.metaboss.enterprise.ps.PSException;
027: import com.metaboss.sdlctools.domains.storagemodel.BODomainStorage;
028: import com.metaboss.sdlctools.domains.storagemodel.BORelationalStorageTechnology;
029: import com.metaboss.sdlctools.domains.storagemodel.BOStorageTechnology;
030: import com.metaboss.sdlctools.domains.storagemodel.storage.PSDomainStorage;
031: import com.metaboss.sdlctools.domains.storagemodel.storage.STDomainStorage;
032: import com.metaboss.sdlctools.domains.storagemodel.storage.STDomainStorageKey;
033: import com.metaboss.sdlctools.types.storagemodel.StorageTechnologyType;
034: import com.oldboss.framework.bo.impl.BOObjectImpl;
035:
036: public class BODomainStorageImpl extends BOObjectImpl implements
037: BODomainStorage {
038: protected BOMetaBossDomainImpl mMetaBossDomainImpl = null;
039: protected BOStorageTechnology mStorageTechnology = null;
040: protected String mDomainRef = null;
041: protected STDomainStorage mDomainStorageDetails = null;
042:
043: /* Instance creator */
044: public static BODomainStorage createInstanceForExisting(
045: BOMetaBossDomainImpl pMetaBossDomainImpl,
046: BOStorageTechnology pStorageTechnology, String pDomainRef)
047: throws BOException {
048: if (pStorageTechnology.getType().equals(
049: StorageTechnologyType.RELATIONAL))
050: return BORelationalDomainStorageImpl
051: .createInstanceForExisting(
052: pMetaBossDomainImpl,
053: (BORelationalStorageTechnology) pStorageTechnology,
054: pDomainRef);
055: throw new BOUnexpectedProgramConditionException(
056: "Storage technology type is not supported. StorageTechnologyRef: "
057: + pStorageTechnology.getRef()
058: + " StorageTechnologyType: "
059: + pStorageTechnology.getType());
060: }
061:
062: /* Protect an access to this constructor */
063: protected BODomainStorageImpl() throws BOException {
064: }
065:
066: // Sets up the instance to represent existing object
067: protected void setupInstanceForExisting(
068: BOMetaBossDomainImpl pMetaBossDomainImpl,
069: BOStorageTechnology pStorageTechnology, String pDomainRef)
070: throws BOException {
071: mMetaBossDomainImpl = pMetaBossDomainImpl;
072: mStorageTechnology = pStorageTechnology;
073: mDomainRef = pDomainRef;
074: }
075:
076: // Sets up the instance to represent new object
077: protected void setupInstanceForNew(
078: BOMetaBossDomainImpl pMetaBossDomainImpl,
079: BOStorageTechnology pStorageTechnology, String pDomainRef)
080: throws BOException {
081: mMetaBossDomainImpl = pMetaBossDomainImpl;
082: mStorageTechnology = pStorageTechnology;
083: mDomainRef = pDomainRef;
084: mDomainStorageDetails = new STDomainStorage();
085: mDomainStorageDetails.StorageTechnologyRef = pStorageTechnology
086: .getRef();
087: mDomainStorageDetails.DomainRef = pDomainRef;
088: }
089:
090: /** Retrieves the storage technology this storage is based on */
091: public BOStorageTechnology getStorageTechnology()
092: throws BOException {
093: return mStorageTechnology;
094: }
095:
096: /** Retrieves domain reference this storage is for */
097: public String getDomainRef() throws BOException {
098: return mDomainRef;
099: }
100:
101: /* Retrieves description */
102: public String getDescription() throws BOException {
103: loadDetailsIfNecessary();
104: return mDomainStorageDetails.Description;
105: }
106:
107: /* Sets description */
108: public void setDescription(String pDescription) throws BOException {
109: if (!isBeingEdited())
110: throw new BOInvalidOperationForReadOnlyObjectException();
111: mDomainStorageDetails.Description = pDescription;
112: }
113:
114: private void loadDetailsIfNecessary() throws BOException {
115: if (mDomainStorageDetails == null) {
116: try {
117: // Get the instance of the enterprise ps home via jndi
118: Context ctx = new InitialContext();
119: PSDomainStorage lPs = (PSDomainStorage) ctx
120: .lookup(PSDomainStorage.COMPONENT_URL);
121: STDomainStorageKey lKey = new STDomainStorageKey();
122: lKey.StorageTechnologyRef = mStorageTechnology.getRef();
123: lKey.DomainRef = mDomainRef;
124: mDomainStorageDetails = lPs.getDomainStorage(lKey);
125: if (mDomainStorageDetails == null)
126: throw new BOException(
127: "DomainStorage not found. StorageTechnologyRef: "
128: + mStorageTechnology.getRef()
129: + " DomainRef: " + mDomainRef);
130: } catch (NamingException e) {
131: throw new BONamingAndDirectoryServiceInvocationException(
132: "", e);
133: } catch (PSException e) {
134: throw new BOPersistenceServiceInvocationException(
135: "Exception caught during loading of DomainStorage details. StorageTechnologyRef: "
136: + mStorageTechnology.getRef()
137: + " DomainRef: " + mDomainRef, e);
138: }
139: }
140: }
141: }
|