001    /**
002     * ========================================
003     * JFreeReport : a free Java report library
004     * ========================================
005     *
006     * Project Info:  http://reporting.pentaho.org/
007     *
008     * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
009     *
010     * This library is free software; you can redistribute it and/or modify it under the terms
011     * of the GNU Lesser General Public License as published by the Free Software Foundation;
012     * either version 2.1 of the License, or (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016     * See the GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public License along with this
019     * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020     * Boston, MA 02111-1307, USA.
021     *
022     * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023     * in the United States and other countries.]
024     *
025     * ------------
026     * $Id: SubReport.java 2725 2007-04-01 18:49:29Z taqua $
027     * ------------
028     * (C) Copyright 2000-2005, by Object Refinery Limited.
029     * (C) Copyright 2005-2007, by Pentaho Corporation.
030     */
031    package org.jfree.report.structure;
032    
033    import java.util.HashMap;
034    import java.util.Map;
035    
036    import org.jfree.report.flow.ParameterMapping;
037    
038    /**
039     * Creation-Date: 04.03.2006, 21:38:21
040     *
041     * @author Thomas Morgner
042     */
043    public class SubReport extends ReportDefinition
044    {
045      private HashMap exportParameters;
046      private HashMap inputParameters;
047    
048      public SubReport()
049      {
050        setType("sub-report");
051        exportParameters = new HashMap();
052        inputParameters = new HashMap();
053      }
054    
055      public void addExportParameter (final String outerName,
056                                      final String innerName)
057      {
058        exportParameters.put(outerName, innerName);
059      }
060    
061      public void removeExportParameter (final String outerName)
062      {
063        exportParameters.remove(outerName);
064      }
065    
066      public String getExportParameter (final String outerName)
067      {
068        return (String) exportParameters.get(outerName);
069      }
070    
071      public String[] getExportParameters ()
072      {
073        return (String[])
074                exportParameters.keySet().toArray(new String[exportParameters.size()]);
075      }
076    
077      public String[] getPeerExportParameters ()
078      {
079        return (String[])
080                exportParameters.values().toArray(new String[exportParameters.size()]);
081      }
082    
083      public ParameterMapping[] getExportMappings ()
084      {
085        final Map.Entry[] inputEntries = (Map.Entry[])
086            exportParameters.entrySet().toArray(new Map.Entry[exportParameters.size()]);
087        final ParameterMapping[] mapping =
088            new ParameterMapping[exportParameters.size()];
089    
090        for (int i = 0; i < inputEntries.length; i++)
091        {
092          final Map.Entry entry = inputEntries[i];
093          mapping[i] = new ParameterMapping
094              ((String) entry.getKey(), (String) entry.getValue());
095        }
096        return mapping;
097      }
098    
099      public void addInputParameter (final String outerName,
100                                     final String innerName)
101      {
102        inputParameters.put(outerName, innerName);
103      }
104    
105      public void removeInputParameter (final String outerName)
106      {
107        inputParameters.remove(outerName);
108      }
109    
110      public String getInnerParameter (final String outerName)
111      {
112        return (String) inputParameters.get(outerName);
113      }
114    
115      public String[] getInputParameters ()
116      {
117        return (String[])
118                inputParameters.keySet().toArray(new String[inputParameters.size()]);
119      }
120    
121      public String[] getPeerInputParameters ()
122      {
123        return (String[])
124                inputParameters.values().toArray(new String[inputParameters.size()]);
125      }
126    
127      public ParameterMapping[] getInputMappings ()
128      {
129        final Map.Entry[] inputEntries = (Map.Entry[])
130            inputParameters.entrySet().toArray(new Map.Entry[inputParameters.size()]);
131        final ParameterMapping[] mapping =
132            new ParameterMapping[inputParameters.size()];
133    
134        for (int i = 0; i < inputEntries.length; i++)
135        {
136          final Map.Entry entry = inputEntries[i];
137          mapping[i] = new ParameterMapping
138              ((String) entry.getKey(), (String) entry.getValue());
139        }
140        return mapping;
141      }
142    
143      public boolean isGlobalImport()
144      {
145        return "*".equals(inputParameters.get("*"));
146      }
147    
148      public boolean isGlobalExport()
149      {
150        return "*".equals(exportParameters.get("*"));
151      }
152    
153    
154      public Object clone()
155          throws CloneNotSupportedException
156      {
157        final SubReport report = (SubReport) super.clone();
158        report.inputParameters = (HashMap) inputParameters.clone();
159        report.exportParameters = (HashMap) exportParameters.clone();
160        return report;
161      }
162    }