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.BONamingAndDirectoryServiceInvocationException;
023: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
024: import com.metaboss.enterprise.ps.PSException;
025: import com.metaboss.sdlctools.domains.enterprisemodel.BOConstraint;
026: import com.metaboss.sdlctools.domains.enterprisemodel.BOEntity;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOEntityConstraintList;
028: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSEntity;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STConstraint;
030: import com.oldboss.framework.bo.impl.BOObjectImpl;
031:
032: public class BOEntityConstraintListImpl extends BOObjectImpl implements
033: BOEntityConstraintList {
034: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
035: private BOEntity mEntity = null;
036:
037: /* Instance creator */
038: public static BOEntityConstraintList createInstanceForExisting(
039: BOMetaBossDomainImpl pMetaBossDomainImpl, BOEntity pEntity)
040: throws BOException {
041: BOEntityConstraintListImpl lImpl = new BOEntityConstraintListImpl();
042: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
043: lImpl.mEntity = pEntity;
044: lImpl.setupForExisting();
045: return lImpl;
046: }
047:
048: /* Private constructor restricts instance creation from outside */
049: private BOEntityConstraintListImpl() throws BOException {
050: }
051:
052: /* Retrieves owner entity */
053: public BOEntity getEntity() throws BOException {
054: return mEntity;
055: }
056:
057: /** Retrieves number of elements in this list */
058: public long size() throws BOException {
059: try {
060: // Get the instance of the enterprise ps home via jndi
061: Context ctx = new InitialContext();
062: PSEntity lPs = (PSEntity) ctx
063: .lookup(PSEntity.COMPONENT_URL);
064:
065: STConstraint[] lConstraints = lPs.getConstraints(mEntity
066: .getRef());
067: if (lConstraints == null)
068: return 0;
069: return lConstraints.length;
070: } catch (NamingException e) {
071: throw new BONamingAndDirectoryServiceInvocationException(
072: "", e);
073: } catch (PSException e) {
074: throw new BOPersistenceServiceInvocationException("", e);
075: }
076: }
077:
078: /* Retrieves all Constraints in this entity */
079: public BOConstraint[] getAllConstraints() throws BOException {
080: try {
081: // Get the instance of the enterprise ps home via jndi
082: Context ctx = new InitialContext();
083: PSEntity lPs = (PSEntity) ctx
084: .lookup(PSEntity.COMPONENT_URL);
085:
086: STConstraint[] lConstraints = lPs.getConstraints(mEntity
087: .getRef());
088: if (lConstraints == null || lConstraints.length == 0)
089: return new BOConstraint[0];
090: BOConstraint[] lReturn = new BOConstraint[lConstraints.length];
091: for (int i = 0; i < lConstraints.length; i++) {
092: lReturn[i] = BOConstraintImpl
093: .createInstanceForExistingEntityConstraint(
094: mMetaBossDomainImpl, mEntity,
095: lConstraints[i]);
096: }
097: return lReturn;
098: } catch (NamingException e) {
099: throw new BONamingAndDirectoryServiceInvocationException(
100: "", e);
101: } catch (PSException e) {
102: throw new BOPersistenceServiceInvocationException("", e);
103: }
104: }
105: }
|