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