// THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
// CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
// BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
// OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Copyright 2000-2005 Softaris Pty.Ltd. All Rights Reserved.
package com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl;
import java.util.Iterator;
import java.util.List;
import com.metaboss.enterprise.ps.PSException;
import com.metaboss.enterprise.ps.PSIllegalArgumentException;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.PSReport;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.STField;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.STReport;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.STReportEntity;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.FieldDefType;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.InputFieldDefListType;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ReportDefType;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ReportEntityDefType;
import com.metaboss.sdlctools.domains.enterprisemodel.storage.xmlfileimpl.dom.ReportOutputElementDefType;
public class PSReportImpl implements PSReport
{
/** Returns details structure corresponding to given reference or null struct if definition not found */
public STReport getReport(String pReportRef) throws PSException
{
ReportDefType lReportDef = Storage.getReport(pReportRef);
if (lReportDef == null)
return null;
STReport lStruct = new STReport();
lStruct.ReportRef = lReportDef.getReportRef();
lStruct.Description = lReportDef.getDescription();
lStruct.HasPaginationFacility = lReportDef.isHasPaginationFacility();
return lStruct;
}
/** Returns number of output levels in the report */
public int getReportOutputLevels(String pReportRef) throws PSException
{
ReportDefType lReportDef = Storage.getReport(pReportRef);
if (lReportDef == null)
return 0;
ReportOutputElementDefType lOutputDef = lReportDef.getReportOutputElementDef();
int lOutputLevels = 0;
for ( ; lOutputDef != null ; lOutputLevels++)
lOutputDef = lOutputDef.getReportOutputElementDef();
return lOutputLevels;
}
/** Returns report's input fields */
public STField[] getInputFields(String pReportRef) throws PSException
{
ReportDefType lReportDef = Storage.getReport(pReportRef);
if (lReportDef == null)
return null;
InputFieldDefListType lInputFieldDefList = lReportDef.getInputFieldDefList();
if (lInputFieldDefList == null || lInputFieldDefList.getFieldDef() == null)
return new STField[0];
STField[] lReturn = new STField[lInputFieldDefList.getFieldDef().size()];
Iterator lIter1 = lInputFieldDefList.getFieldDef().iterator();
for (int j = 0; lIter1.hasNext(); j++)
{
lReturn[j] = Util.getField((FieldDefType)lIter1.next());
}
return lReturn;
}
/** Returns report's top level output fields */
public STField[] getOutputFields(String pReportRef, int pFromLevel) throws PSException
{
ReportDefType lReportDef = Storage.getReport(pReportRef);
if (lReportDef == null)
return null;
// Make sure that we are positioned on the required level
ReportOutputElementDefType lOutputDef = lReportDef.getReportOutputElementDef();
for (int i = 0; i < pFromLevel; i++)
{
if (lOutputDef == null)
throw new PSIllegalArgumentException("pFromLevel argument referring to non-existant report level.");
lOutputDef = lOutputDef.getReportOutputElementDef();
}
if (lOutputDef == null)
throw new PSIllegalArgumentException("pFromLevel argument referring to non-existant report level.");
List lFieldDefList = lOutputDef.getFieldDef();
if (lFieldDefList == null)
return new STField[0];
STField[] lReturn = new STField[lFieldDefList.size()];
Iterator lIter1 = lFieldDefList.iterator();
for (int j = 0; lIter1.hasNext(); j++)
{
lReturn[j] = Util.getField((FieldDefType)lIter1.next());
}
return lReturn;
}
/* Returns report's top level output entities */
public STReportEntity[] getOutputEntities(String pReportRef, int pFromLevel) throws PSException
{
ReportDefType lReportDef = Storage.getReport(pReportRef);
if (lReportDef == null)
return null;
// Make sure that we are positioned on the required level
ReportOutputElementDefType lOutputDef = lReportDef.getReportOutputElementDef();
for (int i = 0; i < pFromLevel; i++)
{
if (lOutputDef == null)
throw new PSIllegalArgumentException("pFromLevel argument referring to non-existant report level.");
lOutputDef = lOutputDef.getReportOutputElementDef();
}
if (lOutputDef == null)
throw new PSIllegalArgumentException("pFromLevel argument referring to non-existant report level.");
List lReportEntityDefList = lOutputDef.getReportEntityDef();
if (lReportEntityDefList == null)
return new STReportEntity[0];
STReportEntity[] lReturn = new STReportEntity[lReportEntityDefList.size()];
Iterator lIter1 = lReportEntityDefList.iterator();
for (int j = 0; lIter1.hasNext(); j++)
{
lReturn[j] = Util.getReportEntity((ReportEntityDefType)lIter1.next());
}
return lReturn;
}
/** Returns attributes included in the report */
public String[] getOutputEntitiyAttributes(String pReportRef, int pFromLevel, String pOutputEntityName) throws PSException
{
ReportDefType lReportDef = Storage.getReport(pReportRef);
if (lReportDef == null)
return null;
// Make sure that we are positioned on the required level
ReportOutputElementDefType lOutputDef = lReportDef.getReportOutputElementDef();
for (int i = 0; i < pFromLevel; i++)
{
if (lOutputDef == null)
throw new PSIllegalArgumentException("pFromLevel argument referring to non-existant report level.");
lOutputDef = lOutputDef.getReportOutputElementDef();
}
if (lOutputDef == null)
throw new PSIllegalArgumentException("pFromLevel argument referring to non-existant report level.");
List lReportEntityDefList = lOutputDef.getReportEntityDef();
if (lReportEntityDefList == null)
return null;
Iterator lIter1 = lReportEntityDefList.iterator();
for (int j = 0; lIter1.hasNext(); j++)
{
ReportEntityDefType lReportEntityDef = (ReportEntityDefType)lIter1.next();
if (lReportEntityDef.getName().equals(pOutputEntityName))
{
List lAttributeNames = lReportEntityDef.getReportEntityAttributeRefList().getAttributeRef();
return (String[])lAttributeNames.toArray(new String[lAttributeNames.size()]);
}
}
return null;
}
}
|