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.storage.xmlfileimpl;
016:
017: import java.util.Iterator;
018: import java.util.List;
019:
020: import com.metaboss.enterprise.ps.PSException;
021: import com.metaboss.enterprise.ps.PSIllegalArgumentException;
022: import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSReport;
023: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STField;
024: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STReport;
025: import com.metaboss.sdlctools.domains.enterprisemodel.storage.STReportEntity;
026: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.FieldDefType;
027: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.InputFieldDefListType;
028: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ReportDefType;
029: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ReportEntityDefType;
030: import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ReportOutputElementDefType;
031:
032: public class PSReportImpl implements PSReport {
033: /** Returns details structure corresponding to given reference or null struct if definition not found */
034: public STReport getReport(String pReportRef) throws PSException {
035: ReportDefType lReportDef = Storage.getReport(pReportRef);
036: if (lReportDef == null)
037: return null;
038: STReport lStruct = new STReport();
039: lStruct.ReportRef = lReportDef.getReportRef();
040: lStruct.Description = lReportDef.getDescription();
041: lStruct.HasPaginationFacility = lReportDef
042: .isHasPaginationFacility();
043: return lStruct;
044: }
045:
046: /** Returns number of output levels in the report */
047: public int getReportOutputLevels(String pReportRef)
048: throws PSException {
049: ReportDefType lReportDef = Storage.getReport(pReportRef);
050: if (lReportDef == null)
051: return 0;
052: ReportOutputElementDefType lOutputDef = lReportDef
053: .getReportOutputElementDef();
054: int lOutputLevels = 0;
055: for (; lOutputDef != null; lOutputLevels++)
056: lOutputDef = lOutputDef.getReportOutputElementDef();
057: return lOutputLevels;
058: }
059:
060: /** Returns report's input fields */
061: public STField[] getInputFields(String pReportRef)
062: throws PSException {
063: ReportDefType lReportDef = Storage.getReport(pReportRef);
064: if (lReportDef == null)
065: return null;
066: InputFieldDefListType lInputFieldDefList = lReportDef
067: .getInputFieldDefList();
068: if (lInputFieldDefList == null
069: || lInputFieldDefList.getFieldDef() == null)
070: return new STField[0];
071: STField[] lReturn = new STField[lInputFieldDefList
072: .getFieldDef().size()];
073: Iterator lIter1 = lInputFieldDefList.getFieldDef().iterator();
074: for (int j = 0; lIter1.hasNext(); j++) {
075: lReturn[j] = Util.getField((FieldDefType) lIter1.next());
076: }
077: return lReturn;
078: }
079:
080: /** Returns report's top level output fields */
081: public STField[] getOutputFields(String pReportRef, int pFromLevel)
082: throws PSException {
083: ReportDefType lReportDef = Storage.getReport(pReportRef);
084: if (lReportDef == null)
085: return null;
086: // Make sure that we are positioned on the required level
087: ReportOutputElementDefType lOutputDef = lReportDef
088: .getReportOutputElementDef();
089: for (int i = 0; i < pFromLevel; i++) {
090: if (lOutputDef == null)
091: throw new PSIllegalArgumentException(
092: "pFromLevel argument referring to non-existant report level.");
093: lOutputDef = lOutputDef.getReportOutputElementDef();
094: }
095: if (lOutputDef == null)
096: throw new PSIllegalArgumentException(
097: "pFromLevel argument referring to non-existant report level.");
098: List lFieldDefList = lOutputDef.getFieldDef();
099: if (lFieldDefList == null)
100: return new STField[0];
101: STField[] lReturn = new STField[lFieldDefList.size()];
102: Iterator lIter1 = lFieldDefList.iterator();
103: for (int j = 0; lIter1.hasNext(); j++) {
104: lReturn[j] = Util.getField((FieldDefType) lIter1.next());
105: }
106: return lReturn;
107: }
108:
109: /* Returns report's top level output entities */
110: public STReportEntity[] getOutputEntities(String pReportRef,
111: int pFromLevel) throws PSException {
112: ReportDefType lReportDef = Storage.getReport(pReportRef);
113: if (lReportDef == null)
114: return null;
115: // Make sure that we are positioned on the required level
116: ReportOutputElementDefType lOutputDef = lReportDef
117: .getReportOutputElementDef();
118: for (int i = 0; i < pFromLevel; i++) {
119: if (lOutputDef == null)
120: throw new PSIllegalArgumentException(
121: "pFromLevel argument referring to non-existant report level.");
122: lOutputDef = lOutputDef.getReportOutputElementDef();
123: }
124: if (lOutputDef == null)
125: throw new PSIllegalArgumentException(
126: "pFromLevel argument referring to non-existant report level.");
127: List lReportEntityDefList = lOutputDef.getReportEntityDef();
128: if (lReportEntityDefList == null)
129: return new STReportEntity[0];
130: STReportEntity[] lReturn = new STReportEntity[lReportEntityDefList
131: .size()];
132: Iterator lIter1 = lReportEntityDefList.iterator();
133: for (int j = 0; lIter1.hasNext(); j++) {
134: lReturn[j] = Util
135: .getReportEntity((ReportEntityDefType) lIter1
136: .next());
137: }
138: return lReturn;
139: }
140:
141: /** Returns attributes included in the report */
142: public String[] getOutputEntitiyAttributes(String pReportRef,
143: int pFromLevel, String pOutputEntityName)
144: throws PSException {
145: ReportDefType lReportDef = Storage.getReport(pReportRef);
146: if (lReportDef == null)
147: return null;
148: // Make sure that we are positioned on the required level
149: ReportOutputElementDefType lOutputDef = lReportDef
150: .getReportOutputElementDef();
151: for (int i = 0; i < pFromLevel; i++) {
152: if (lOutputDef == null)
153: throw new PSIllegalArgumentException(
154: "pFromLevel argument referring to non-existant report level.");
155: lOutputDef = lOutputDef.getReportOutputElementDef();
156: }
157: if (lOutputDef == null)
158: throw new PSIllegalArgumentException(
159: "pFromLevel argument referring to non-existant report level.");
160: List lReportEntityDefList = lOutputDef.getReportEntityDef();
161: if (lReportEntityDefList == null)
162: return null;
163: Iterator lIter1 = lReportEntityDefList.iterator();
164: for (int j = 0; lIter1.hasNext(); j++) {
165: ReportEntityDefType lReportEntityDef = (ReportEntityDefType) lIter1
166: .next();
167: if (lReportEntityDef.getName().equals(pOutputEntityName)) {
168: List lAttributeNames = lReportEntityDef
169: .getReportEntityAttributeRefList()
170: .getAttributeRef();
171: return (String[]) lAttributeNames
172: .toArray(new String[lAttributeNames.size()]);
173: }
174: }
175: return null;
176: }
177: }
|