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 java.util.HashMap;
018:
019: import javax.naming.Context;
020: import javax.naming.InitialContext;
021: import javax.naming.NamingException;
022:
023: import com.metaboss.enterprise.bo.BOException;
024: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
025: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
026: import com.metaboss.enterprise.ps.PSException;
027: import com.metaboss.sdlctools.domains.storagemodel.BODomainStorage;
028: import com.metaboss.sdlctools.domains.storagemodel.BODomainStorageList;
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.STDomainStorageKey;
032: import com.oldboss.framework.bo.impl.BOObjectImpl;
033:
034: public class BODomainStorageListImpl extends BOObjectImpl implements
035: BODomainStorageList {
036: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
037:
038: /* Instance creator */
039: public static BODomainStorageList createInstanceForExisting(
040: BOMetaBossDomainImpl pMetaBossDomainImpl)
041: throws BOException {
042: BODomainStorageListImpl lImpl = new BODomainStorageListImpl();
043: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
044: lImpl.setupForExisting();
045: return lImpl;
046: }
047:
048: /* Private constructor restricts instance creation from outside */
049: private BODomainStorageListImpl() throws BOException {
050: }
051:
052: /* Returns true if this list contains storage definition for the specified domain */
053: public boolean contains(String pStorageTechnologyRef,
054: String pDomainRef) throws BOException {
055: try {
056: // Get the instance of the enterprise ps home via jndi
057: Context ctx = new InitialContext();
058: PSDomainStorage lPs = (PSDomainStorage) ctx
059: .lookup(PSDomainStorage.COMPONENT_URL);
060: STDomainStorageKey lKey = new STDomainStorageKey();
061: lKey.StorageTechnologyRef = pStorageTechnologyRef;
062: lKey.DomainRef = pDomainRef;
063: return lPs.containsDomainStorage(lKey);
064: } catch (NamingException e) {
065: throw new BONamingAndDirectoryServiceInvocationException(
066: "", e);
067: } catch (PSException e) {
068: throw new BOPersistenceServiceInvocationException("", e);
069: }
070: }
071:
072: /** Retrieves all domain storages defined within this list */
073: public BODomainStorage[] getAllDomainStorages() throws BOException {
074: try {
075: // Get the instance of the enterprise ps home via jndi
076: Context ctx = new InitialContext();
077: PSDomainStorage lPs = (PSDomainStorage) ctx
078: .lookup(PSDomainStorage.COMPONENT_URL);
079:
080: STDomainStorageKey[] lDomainStorages = lPs
081: .getDomainStorageRefs();
082: if (lDomainStorages == null || lDomainStorages.length == 0)
083: return new BODomainStorage[0];
084: BODomainStorage[] lReturn = new BODomainStorage[lDomainStorages.length];
085: HashMap lStorageTechnologies = new HashMap();
086: for (int i = 0; i < lDomainStorages.length; i++) {
087: STDomainStorageKey lKey = lDomainStorages[i];
088: BOStorageTechnology lStorageTechnology = (BOStorageTechnology) lStorageTechnologies
089: .get(lKey.StorageTechnologyRef);
090: if (lStorageTechnology == null)
091: lStorageTechnologies
092: .put(
093: lKey.StorageTechnologyRef,
094: lStorageTechnology = BOStorageTechnologyImpl
095: .createInstanceForExisting(
096: mMetaBossDomainImpl,
097: lKey.StorageTechnologyRef));
098: lReturn[i] = BODomainStorageImpl
099: .createInstanceForExisting(mMetaBossDomainImpl,
100: lStorageTechnology, lKey.DomainRef);
101: }
102: return lReturn;
103: } catch (NamingException e) {
104: throw new BONamingAndDirectoryServiceInvocationException(
105: "", e);
106: } catch (PSException e) {
107: throw new BOPersistenceServiceInvocationException("", e);
108: }
109: }
110:
111: /* Retrieves definition of particular domain storage or null if none found */
112: public BODomainStorage getDomainStorage(
113: String pStorageTechnologyRef, String pDomainRef)
114: throws BOException {
115: return BODomainStorageImpl.createInstanceForExisting(
116: mMetaBossDomainImpl, BOStorageTechnologyImpl
117: .createInstanceForExisting(mMetaBossDomainImpl,
118: pStorageTechnologyRef), pDomainRef);
119: }
120: }
|