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