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 java.util.ArrayList;
018:
019: import javax.naming.Context;
020: import javax.naming.InitialContext;
021: import javax.naming.NamingException;
022:
023: import com.metaboss.enterprise.bo.BOException;
024: import com.metaboss.enterprise.bo.BOInvalidOperationForReadOnlyObjectException;
025: import com.metaboss.enterprise.bo.BONamingAndDirectoryServiceInvocationException;
026: import com.metaboss.enterprise.bo.BOPersistenceServiceInvocationException;
027: import com.metaboss.enterprise.ps.PSException;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOField;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOSelector;
030: import com.metaboss.sdlctools.domains.enterprisemodel.BOSelectorInputFieldList;
031: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSEntity;
032: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STField;
033: import com.oldboss.framework.bo.impl.BOObjectImpl;
034:
035: public class BOSelectorInputFieldListImpl extends BOObjectImpl
036: implements BOSelectorInputFieldList {
037: private BOMetaBossDomainImpl mMetaBossDomainImpl = null;
038: private BOSelector mSelector = null;
039:
040: /* Instance creator */
041: public static BOSelectorInputFieldList createInstanceForExisting(
042: BOMetaBossDomainImpl pMetaBossDomainImpl,
043: BOSelector pSelector) throws BOException {
044: BOSelectorInputFieldListImpl lImpl = new BOSelectorInputFieldListImpl();
045: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
046: lImpl.mSelector = pSelector;
047: lImpl.setupForExisting();
048: return lImpl;
049: }
050:
051: /* Private constructor restricts instance creation from outside */
052: private BOSelectorInputFieldListImpl() throws BOException {
053: }
054:
055: /* Retrieves all fields in this list */
056: public BOField[] getAllFields() throws BOException {
057: STField[] lFields = retrieveAllFields();
058: BOField[] lReturn = new BOField[lFields.length];
059: for (int i = 0; i < lFields.length; i++)
060: lReturn[i] = BOFieldImpl
061: .createInstanceForExistingSelectorInputField(
062: mMetaBossDomainImpl, mSelector, lFields[i]);
063: return lReturn;
064: }
065:
066: /* Retrieves particular field object by it's name or null if none exists */
067: public BOField getField(String pName) throws BOException {
068: STField[] lFields = retrieveAllFields();
069: BOField[] lReturn = new BOField[lFields.length];
070: for (int i = 0; i < lFields.length; i++) {
071: STField lField = lFields[i];
072: if (lField.Name.equals(pName))
073: return BOFieldImpl
074: .createInstanceForExistingSelectorInputField(
075: mMetaBossDomainImpl, mSelector,
076: lFields[i]);
077: }
078: return null; // Field with this name os not found
079: }
080:
081: /* Retrieves all fields in this which are arrays */
082: public BOField[] selectArrayFields() throws BOException {
083: STField[] lFields = retrieveAllFields();
084: ArrayList lMatchingFields = new ArrayList();
085: for (int i = 0; i < lFields.length; i++) {
086: STField lField = lFields[i];
087: if (lField.IsArray)
088: lMatchingFields
089: .add(BOFieldImpl
090: .createInstanceForExistingSelectorInputField(
091: mMetaBossDomainImpl, mSelector,
092: lField));
093: }
094: return (BOField[]) lMatchingFields
095: .toArray(new BOField[lMatchingFields.size()]);
096: }
097:
098: /* Retrieves all fields in this list, which are not arrays */
099: public BOField[] selectNonArrayFields() throws BOException {
100: STField[] lFields = retrieveAllFields();
101: ArrayList lMatchingFields = new ArrayList();
102: for (int i = 0; i < lFields.length; i++) {
103: STField lField = lFields[i];
104: if (!lField.IsArray)
105: lMatchingFields
106: .add(BOFieldImpl
107: .createInstanceForExistingSelectorInputField(
108: mMetaBossDomainImpl, mSelector,
109: lField));
110: }
111: return (BOField[]) lMatchingFields
112: .toArray(new BOField[lMatchingFields.size()]);
113: }
114:
115: /** Creates the new instance of the fields */
116: public BOField create(String pFieldName) throws BOException {
117: if (!isBeingEdited())
118: throw new BOInvalidOperationForReadOnlyObjectException();
119: return BOFieldImpl.createInstanceForNewSelectorInputField(
120: fetchTransaction(), mMetaBossDomainImpl, mSelector,
121: pFieldName);
122: }
123:
124: // Helper retrieves all fields
125: private STField[] retrieveAllFields() throws BOException {
126: try {
127: // Get the instance of the enterprise ps home via jndi
128: Context ctx = new InitialContext();
129: PSEntity lPs = (PSEntity) ctx
130: .lookup(PSEntity.COMPONENT_URL);
131: STField[] lFields = lPs.getSelectorInputFields(mSelector
132: .getEntity().getRef(), mSelector.getName());
133: if (lFields == null || lFields.length == 0)
134: return new STField[0];
135: return lFields;
136: } catch (NamingException e) {
137: throw new BONamingAndDirectoryServiceInvocationException(
138: "", e);
139: } catch (PSException e) {
140: throw new BOPersistenceServiceInvocationException("", e);
141: }
142: }
143: }
|