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.BODatatype;
026: import com.metaboss.sdlctools.domains.enterprisemodel.BODomain;
027: import com.metaboss.sdlctools.domains.enterprisemodel.BOReport;
028: import com.metaboss.sdlctools.domains.enterprisemodel.BOReportInputFieldList;
029: import com.metaboss.sdlctools.domains.enterprisemodel.BOReportOutputElement;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSReport;
031: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STReport;
032: import com.oldboss.framework.bo.impl.BOObjectImpl;
033:
034: public class BOReportImpl extends BOObjectImpl implements BOReport {
035: protected BOMetaBossDomainImpl mMetaBossDomainImpl = null;
036: private BODomain mOwnerDomain = null;
037: private String mReportRef = null;
038: private STReport mDetails = null;
039:
040: /* Instance creator */
041: public static BOReport createInstanceForExisting(
042: BOMetaBossDomainImpl pMetaBossDomainImpl,
043: BODomain pOwnerDomain, String pReportRef)
044: throws BOException {
045: if (pReportRef == null || pReportRef.length() == 0)
046: throw new BOException("Empty ReportRef");
047: BOReportImpl lImpl = new BOReportImpl();
048: lImpl.mMetaBossDomainImpl = pMetaBossDomainImpl;
049: lImpl.mOwnerDomain = pOwnerDomain;
050: lImpl.mReportRef = pReportRef;
051: lImpl.setupForExisting();
052: return lImpl;
053: }
054:
055: /* Private constructor restricts instance creation from outside */
056: private BOReportImpl() throws BOException {
057: }
058:
059: /* Retrieves unique reference */
060: public String getRef() throws BOException {
061: return mReportRef;
062: }
063:
064: /* Retrieves element's name. Name is only unique within parent entity */
065: public String getName() throws BOException {
066: String lReportName = getRef();
067: if (lReportName.lastIndexOf(".") >= 0)
068: lReportName = lReportName.substring(lReportName
069: .lastIndexOf(".") + 1);
070: return lReportName;
071: }
072:
073: /* Returns element's description */
074: public String getDescription() throws BOException {
075: loadDetailsIfNecessary();
076: return mDetails.Description;
077: }
078:
079: /* Returns true if report should be run page by page */
080: public boolean hasPaginationFacility() throws BOException {
081: loadDetailsIfNecessary();
082: return mDetails.HasPaginationFacility;
083: }
084:
085: /* Retrieves datatype used carry full report size */
086: public BODatatype getReportSizeDatatype() throws BOException {
087: return BODatatypeImpl.createInstanceForExisting(
088: mMetaBossDomainImpl, ".core.ReportSize");
089: }
090:
091: /* Retrieves datatype used for carry report page size */
092: public BODatatype getReportPageSizeDatatype() throws BOException {
093: return BODatatypeImpl.createInstanceForExisting(
094: mMetaBossDomainImpl, ".core.ReportPageSize");
095: }
096:
097: /* Retrieves datatype used for carry report page offset */
098: public BODatatype getReportPageOffsetDatatype() throws BOException {
099: return BODatatypeImpl.createInstanceForExisting(
100: mMetaBossDomainImpl, ".core.ReportPageOffset");
101: }
102:
103: /* Retrieves the service this operation belongs to */
104: public BODomain getDomain() throws BOException {
105: return mOwnerDomain;
106: }
107:
108: /** Returns number of levels in the report output.
109: * 1 means that report returns some fields and / or entities but does not have repeatable records inside
110: * two or more means that there is one level of repeatable levels */
111: public int getOutputLevels() throws BOException {
112: try {
113: // Get the instance of the enterprise ps home via jndi
114: Context lCtx = new InitialContext();
115: PSReport lPs = (PSReport) lCtx
116: .lookup(PSReport.COMPONENT_URL);
117: return lPs.getReportOutputLevels(mReportRef);
118: } catch (NamingException e) {
119: throw new BONamingAndDirectoryServiceInvocationException(
120: "", e);
121: } catch (PSException e) {
122: throw new BOPersistenceServiceInvocationException("", e);
123: }
124: }
125:
126: /* Retireves the list of input fields */
127: public BOReportInputFieldList getInputFields() throws BOException {
128: return BOReportInputFieldListImpl.createInstanceForExisting(
129: mMetaBossDomainImpl, this );
130: }
131:
132: /* Retireves the top level output element */
133: public BOReportOutputElement getTopLevelOutputElement()
134: throws BOException {
135: return BOReportOutputElementImpl.createInstanceForExisting(
136: mMetaBossDomainImpl, this , 0);
137: }
138:
139: /* Retireves the output element from any level */
140: public BOReportOutputElement getOutputElement(int pLevel)
141: throws BOException {
142: int lOutputLevels = getOutputLevels();
143: if (pLevel >= lOutputLevels)
144: throw new com.metaboss.enterprise.bo.BOIllegalArgumentException(
145: "Invalid report level " + pLevel + " (expected "
146: + Integer.toString(lOutputLevels - 1)
147: + " max.) ReportRef : " + getRef());
148: return BOReportOutputElementImpl.createInstanceForExisting(
149: mMetaBossDomainImpl, this , pLevel);
150: }
151:
152: protected void loadDetailsIfNecessary() throws BOException {
153: if (mDetails == null) {
154: try {
155: // Get the instance of the enterprise ps home via jndi
156: Context lCtx = new InitialContext();
157: PSReport lPs = (PSReport) lCtx
158: .lookup(PSReport.COMPONENT_URL);
159:
160: STReport lDetails = lPs.getReport(mReportRef);
161: if (lDetails == null)
162: throw new BOException(
163: "Report not found. (ReportRef:"
164: + mReportRef + ")");
165: mDetails = lDetails;
166: } catch (NamingException e) {
167: throw new BONamingAndDirectoryServiceInvocationException(
168: "", e);
169: } catch (PSException e) {
170: throw new BOPersistenceServiceInvocationException("", e);
171: }
172: }
173: }
174: }
|