01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.sdlctools.domains.enterprisemodel.impl;
16:
17: import javax.naming.Context;
18: import javax.naming.InitialContext;
19: import javax.naming.NamingException;
20:
21: import com.metaboss.enterprise.bo.BOException;
22: import com.metaboss.enterprise.bo.BOIllegalArgumentException;
23: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
24: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
25: import com.metaboss.enterprise.ps.PSException;
26: import com.metaboss.sdlctools.domains.enterprisemodel.BODomain;
27: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystem;
28: import com.metaboss.sdlctools.domains.enterprisemodel.BOSystemDomainList;
29: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSSystem;
30: import com.oldboss.framework.bo.impl.BOObjectImpl;
31:
32: public class BOSystemDomainListImpl extends BOObjectImpl implements
33: BOSystemDomainList {
34: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
35: private BOSystem mSystem = null;
36:
37: /* Instance creator */
38: public static BOSystemDomainList createInstanceForExisting(
39: BOMetaBossDomainImpl pMetaBossDomainImpl, BOSystem pSystem)
40: throws BOException {
41: BOSystemDomainListImpl lImpl = new BOSystemDomainListImpl();
42: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
43: lImpl.mSystem = pSystem;
44: lImpl.setupForExisting();
45: return lImpl;
46: }
47:
48: /* Private constructor restricts instance creation from outside */
49: private BOSystemDomainListImpl() throws BOException {
50: }
51:
52: /* Retrieves domains in order of dependencies. */
53: public BODomain[] getAllDomains() throws BOException {
54: try {
55: // Get the instance of the System ps home via jndi
56: Context ctx = new InitialContext();
57: PSSystem lPs = (PSSystem) ctx
58: .lookup(PSSystem.COMPONENT_URL);
59:
60: String[] lDomainRefs = lPs.getAllDomainRefs(mSystem
61: .getRef());
62: if (lDomainRefs == null || lDomainRefs.length == 0)
63: return new BODomain[0];
64: BODomain[] lReturn = new BODomain[lDomainRefs.length];
65: for (int i = 0; i < lDomainRefs.length; i++) {
66: lReturn[i] = BODomainImpl.createInstanceForExisting(
67: mMetaBossDomainImpl, lDomainRefs[i]);
68: }
69: return lReturn;
70: } catch (NamingException e) {
71: throw new BONamingAndDirectoryServiceInvocationException(
72: "Error while loading all domains. SystemRef: "
73: + mSystem.getRef(), e);
74: } catch (PSException e) {
75: throw new BOPersistenceServiceInvocationException(
76: "Error while loading all domains. SystemRef: "
77: + mSystem.getRef(), e);
78: }
79: }
80:
81: /** Retrieves Domain object by it's Ref */
82: public BODomain getDomain(String pDomainRef) throws BOException {
83: if (!pDomainRef.startsWith(mSystem.getRef() + "."))
84: throw new BOIllegalArgumentException("DomainRef "
85: + pDomainRef
86: + " is not valid within system. SystemRef: "
87: + mSystem.getRef());
88: return BODomainImpl.createInstanceForExisting(
89: mMetaBossDomainImpl, pDomainRef);
90: }
91: }
|