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.enterprisemodel.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.BOIllegalArgumentException;
023: import com.metaboss.enterprise.bo.BOInvalidOperationForReadOnlyObjectException;
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.enterprisemodel.BOServicemodule;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystem;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystemServicemoduleList;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSSystem;
031: import com.oldboss.framework.bo.impl.BOObjectImpl;
032:
033: public class BOSystemServicemoduleListImpl extends BOObjectImpl
034: implements BOSystemServicemoduleList {
035: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
036: private BOSystem mSystem = null;
037:
038: /* Instance creator */
039: public static BOSystemServicemoduleList createInstanceForExisting(
040: BOMetaBossDomainImpl pMetaBossDomainImpl, BOSystem pSystem)
041: throws BOException {
042: BOSystemServicemoduleListImpl lImpl = new BOSystemServicemoduleListImpl();
043: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
044: lImpl.mSystem = pSystem;
045: lImpl.setupForExisting();
046: return lImpl;
047: }
048:
049: /* Private constructor restricts instance creation from outside */
050: private BOSystemServicemoduleListImpl() throws BOException {
051: }
052:
053: /* Retrieves all servicemodules */
054: public BOServicemodule[] getAllServicemodules() throws BOException {
055: try {
056: // Get the instance of the enterprise ps home via jndi
057: Context ctx = new InitialContext();
058: PSSystem lPs = (PSSystem) ctx
059: .lookup(PSSystem.COMPONENT_URL);
060:
061: String[] lServicemoduleRefs = lPs
062: .getAllServicemoduleRefs(mSystem.getRef());
063: if (lServicemoduleRefs == null
064: || lServicemoduleRefs.length == 0)
065: return new BOServicemodule[0];
066: BOServicemodule[] lReturn = new BOServicemodule[lServicemoduleRefs.length];
067: for (int i = 0; i < lServicemoduleRefs.length; i++) {
068: lReturn[i] = BOServicemoduleImpl
069: .createInstanceForExisting(mMetaBossDomainImpl,
070: lServicemoduleRefs[i]);
071: }
072: return lReturn;
073: } catch (NamingException e) {
074: throw new BONamingAndDirectoryServiceInvocationException(
075: "Error while loading all servicemodules. SystemRef: "
076: + mSystem.getRef(), e);
077: } catch (PSException e) {
078: throw new BOPersistenceServiceInvocationException(
079: "Error while loading all servicemodules. SystemRef: "
080: + mSystem.getRef(), e);
081: }
082: }
083:
084: /** Retrieves particular servicemodule. */
085: public BOServicemodule getServicemodule(String pServicemoduleRef)
086: throws BOException {
087: // Check if this servicemodule even belongs to this enteprise
088: if (!pServicemoduleRef.startsWith(mSystem.getRef() + "."))
089: throw new BOIllegalArgumentException("ServicemoduleRef "
090: + pServicemoduleRef
091: + " is not valid within system. SystemRef: "
092: + mSystem.getRef());
093: return BOServicemoduleImpl.createInstanceForExisting(
094: mMetaBossDomainImpl, pServicemoduleRef);
095: }
096:
097: /** Returns true if particular servicemodule exists. */
098: public boolean contains(String pServicemoduleRef)
099: throws BOException {
100: // Check if this servicemodule even belongs to this enteprise
101: if (!pServicemoduleRef.startsWith(mSystem.getRef() + "."))
102: return false;
103: return BOServicemoduleImpl.loadInstanceForExisting(
104: mMetaBossDomainImpl, pServicemoduleRef) != null;
105: }
106:
107: /** Creates new servicemodule. */
108: public BOServicemodule create(String pServicemoduleRef)
109: throws BOException {
110: // Check if this servicemodule even belongs to this enteprise
111: if (!pServicemoduleRef.startsWith(mSystem.getRef() + "."))
112: throw new BOIllegalArgumentException("ServicemoduleRef "
113: + pServicemoduleRef
114: + " is not valid within system. SystemRef: "
115: + mSystem.getRef());
116: if (!isBeingEdited())
117: throw new BOInvalidOperationForReadOnlyObjectException();
118: return BOServicemoduleImpl.createInstanceForNew(
119: fetchTransaction(), mMetaBossDomainImpl,
120: pServicemoduleRef);
121: }
122: }
|