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: DefaultReportJob.java 3525 2007-10-16 11:43:48Z tmorgner $
027     * ------------
028     * (C) Copyright 2000-2005, by Object Refinery Limited.
029     * (C) Copyright 2005-2007, by Pentaho Corporation.
030     */
031    package org.jfree.report.flow;
032    
033    import java.awt.print.PageFormat;
034    
035    import org.jfree.base.config.HierarchicalConfiguration;
036    import org.jfree.base.config.ModifiableConfiguration;
037    import org.jfree.report.ReportDataFactory;
038    import org.jfree.report.i18n.DefaultResourceBundleFactory;
039    import org.jfree.report.i18n.ResourceBundleFactory;
040    import org.jfree.report.util.ReportParameters;
041    
042    /**
043     * Creation-Date: 22.02.2006, 12:47:53
044     *
045     * @author Thomas Morgner
046     */
047    public class DefaultReportJob
048    implements ReportJob
049    {
050      private ReportStructureRoot report;
051      private ReportDataFactory dataFactory;
052      private ReportParameters parameters;
053      private ModifiableConfiguration configuration;
054      private ResourceBundleFactory resourceBundleFactory;
055      private String name;
056      //private PageFormat pageFormat;
057    
058      public DefaultReportJob(final ReportStructureRoot report)
059      {
060        this.resourceBundleFactory = new DefaultResourceBundleFactory();
061        this.report = report;
062        final ReportDataFactory dataFactory = report.getDataFactory();
063        if (dataFactory != null)
064        {
065          this.dataFactory = dataFactory.derive();
066        }
067        this.parameters = new ReportParameters(report.getInputParameters());
068        this.configuration = new HierarchicalConfiguration(report.getConfiguration());
069      }
070    
071      public ModifiableConfiguration getConfiguration()
072      {
073        return configuration;
074      }
075    
076      public ReportParameters getParameters()
077      {
078        return parameters;
079      }
080    
081      public ReportStructureRoot getReportStructureRoot()
082      {
083        return report;
084      }
085    
086      public ReportDataFactory getDataFactory()
087      {
088        return dataFactory;
089      }
090    
091      public void setDataFactory(final ReportDataFactory dataFactory)
092      {
093        this.dataFactory = dataFactory;
094      }
095    
096      public Object clone() throws CloneNotSupportedException
097      {
098        final DefaultReportJob job = (DefaultReportJob) super.clone();
099        if (dataFactory != null)
100        {
101          job.dataFactory = dataFactory.derive();
102        }
103        job.parameters = (ReportParameters) parameters.clone();
104        job.configuration = (ModifiableConfiguration) configuration.clone();
105        return job;
106      }
107    
108      public ReportJob derive()
109      {
110        try
111        {
112          return (ReportJob) clone();
113        }
114        catch (CloneNotSupportedException e)
115        {
116          throw new IllegalStateException
117              ("A report job should always be cloneable.");
118        }
119      }
120    
121      public synchronized void close()
122      {
123        if (dataFactory != null)
124        {
125          dataFactory.close();
126        }
127      }
128    
129      public ResourceBundleFactory getResourceBundleFactory()
130      {
131        return resourceBundleFactory;
132      }
133    
134      public void setResourceBundleFactory(final ResourceBundleFactory resourceBundleFactory)
135      {
136        this.resourceBundleFactory = resourceBundleFactory;
137      }
138    
139      public String getName()
140      {
141        return name;
142      }
143    
144      public void setName(final String name)
145      {
146        this.name = name;
147      }
148    //
149    //  public PageFormat getPageFormat()
150    //  {
151    //    return pageFormat;
152    //  }
153    //
154    //  public void setPageFormat(PageFormat pageFormat)
155    //  {
156    //    this.pageFormat = pageFormat;
157    //  }
158    }