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.BOAssociation;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BODomain;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BODomainAssociationList;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSDomain;
031: import com.oldboss.framework.bo.impl.BOObjectImpl;
032:
033: public class BODomainAssociationListImpl extends BOObjectImpl implements
034: BODomainAssociationList {
035: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
036: private BODomain mDomain = null;
037:
038: /* Instance creator */
039: public static BODomainAssociationList createInstanceForExisting(
040: BOMetaBossDomainImpl pMetaBossDomainImpl, BODomain pDomain)
041: throws BOException {
042: BODomainAssociationListImpl lImpl = new BODomainAssociationListImpl();
043: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
044: lImpl.mDomain = pDomain;
045: lImpl.setupForExisting();
046: return lImpl;
047: }
048:
049: /* Private constructor restricts instance creation from outside */
050: private BODomainAssociationListImpl() throws BOException {
051: }
052:
053: /* Retrieves an attribute object by it's name or null if none exists */
054: public BOAssociation getAssociation(String pAssociationRef)
055: throws BOException {
056: try {
057: // Get the instance of the enterprise ps home via jndi
058: Context ctx = new InitialContext();
059: PSDomain lPs = (PSDomain) ctx
060: .lookup(PSDomain.COMPONENT_URL);
061:
062: String[] lAssociations = lPs.getAllAssociationRefs(mDomain
063: .getRef());
064: if (lAssociations == null || lAssociations.length == 0)
065: return null;
066: for (int i = 0; i < lAssociations.length; i++) {
067: if (lAssociations[i].equals(pAssociationRef))
068: return BOAssociationImpl.createInstanceForExisting(
069: mMetaBossDomainImpl, lAssociations[i]);
070: }
071: return null;
072: } catch (NamingException e) {
073: throw new BONamingAndDirectoryServiceInvocationException(
074: "", e);
075: } catch (PSException e) {
076: throw new BOPersistenceServiceInvocationException("", e);
077: }
078: }
079:
080: /** Retrieves all associations in this domain */
081: public BOAssociation[] getAllAssociations() throws BOException {
082: try {
083: // Get the instance of the enterprise ps home via jndi
084: Context ctx = new InitialContext();
085: PSDomain lPs = (PSDomain) ctx
086: .lookup(PSDomain.COMPONENT_URL);
087:
088: String[] lAssociations = lPs.getAllAssociationRefs(mDomain
089: .getRef());
090: if (lAssociations == null || lAssociations.length == 0)
091: return new BOAssociation[0];
092: BOAssociation[] lReturn = new BOAssociation[lAssociations.length];
093: for (int i = 0; i < lAssociations.length; i++) {
094: lReturn[i] = BOAssociationImpl
095: .createInstanceForExisting(mMetaBossDomainImpl,
096: lAssociations[i]);
097: }
098: return lReturn;
099: } catch (NamingException e) {
100: throw new BONamingAndDirectoryServiceInvocationException(
101: "", e);
102: } catch (PSException e) {
103: throw new BOPersistenceServiceInvocationException("", e);
104: }
105: }
106:
107: /* Creates a new association with the given reference */
108: public BOAssociation createAssociation(String pAssociationRef)
109: throws BOException {
110: // Check if this servicemodule even belongs to this enteprise
111: if (!pAssociationRef.startsWith(mDomain.getRef() + "."))
112: throw new BOIllegalArgumentException(
113: "AssociationRef is not valid not valid within domain. AssociationRef: "
114: + pAssociationRef + " DomainRef: "
115: + mDomain.getRef());
116: if (!isBeingEdited())
117: throw new BOInvalidOperationForReadOnlyObjectException();
118: return BOAssociationImpl.createInstanceForNew(
119: fetchTransaction(), mMetaBossDomainImpl,
120: pAssociationRef);
121: }
122:
123: }
|