[jboss-svn-commits] JBL Code SVN: r7760 - in labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting: . api api/impl
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Nov 22 04:05:11 EST 2006
Author: noel.rocher at jboss.com
Date: 2006-11-22 04:05:09 -0500 (Wed, 22 Nov 2006)
New Revision: 7760
Added:
labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/api/
labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/api/impl/
labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/api/impl/ReportTaskFactory.java
labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/api/impl/ReportTaskImpl.java
Log:
Added: labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/api/impl/ReportTaskFactory.java
===================================================================
--- labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/api/impl/ReportTaskFactory.java 2006-11-22 08:48:49 UTC (rev 7759)
+++ labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/api/impl/ReportTaskFactory.java 2006-11-22 09:05:09 UTC (rev 7760)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.reporting.api.impl;
+
+
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.util.Properties;
+
+import org.jboss.remoting.Client;
+import org.jboss.remoting.InvokerLocator;
+import org.jboss.util.id.GUID;
+
+/**
+ * @author noel
+ *
+ */
+public class ReportTaskFactory
+{
+
+ private final static String PROPERTY_LOCATOR_URL="jboss.reporting.locator";
+ private final static String PROPERTY_REPORTING_SUBSYSTEM="jboss.reporting.subsystem";
+
+ private final static String DEFAULT_LOCATOR_URL="socket://localhost:8085";
+ private final static String DEFAULT_REPORTING_SUBSYSTEM="reporting-services";
+
+ private static String reportLocatorURL="";
+ private static String reportSubsystem="";
+ private static InvokerLocator reportLocator=null;
+ public static Client reportClient=null;
+
+
+ /*
+ * Initialisation
+ */
+ static
+ {
+ try
+ { Properties props = new Properties();
+ props.load( (ReportTaskFactory.class).getClassLoader().getResourceAsStream("report-client.properties"));
+ reportLocatorURL = props.getProperty(PROPERTY_LOCATOR_URL);
+ reportSubsystem = props.getProperty(PROPERTY_REPORTING_SUBSYSTEM);
+ } catch (IOException ignore){}
+
+ if (reportLocatorURL == null || reportLocatorURL.length() == 0)
+ {
+ // look for a system property
+ reportLocatorURL = System.getProperty(PROPERTY_LOCATOR_URL);
+ if (reportLocatorURL == null || reportLocatorURL.length() == 0)
+ {
+ // use the default
+ reportLocatorURL = DEFAULT_LOCATOR_URL;
+ }
+ }
+
+
+ if (reportSubsystem == null || reportSubsystem.length() == 0)
+ {
+ // look for a system property
+ reportSubsystem = System.getProperty(PROPERTY_REPORTING_SUBSYSTEM);
+ if (reportSubsystem == null || reportSubsystem.length() == 0)
+ {
+ // use the default
+ reportSubsystem = DEFAULT_REPORTING_SUBSYSTEM;
+ }
+ }
+
+ try
+ {
+ reportLocator = new InvokerLocator(reportLocatorURL);
+ reportClient = new Client(reportLocator, reportSubsystem);
+ System.out.println(reportLocator);
+ reportClient.connect();
+ System.out.println(reportClient.isConnected());
+ } catch (MalformedURLException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+
+
+ /**
+ * Return a ReportTask implementation
+ */
+ public static ReportTask getInstance()
+ {
+ ReportTaskImpl result=null;
+ result = new ReportTaskImpl(newReportTaskID());
+ return result;
+ }
+
+ /**
+ * Return a ReportTask ID
+ */
+ public static String newReportTaskID()
+ {
+ return new GUID().toString();
+ }
+
+
+
+}
Added: labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/api/impl/ReportTaskImpl.java
===================================================================
--- labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/api/impl/ReportTaskImpl.java 2006-11-22 08:48:49 UTC (rev 7759)
+++ labs/reportingservices/trunk/dev/modules/client/impl/src/main/java/org/jboss/reporting/api/impl/ReportTaskImpl.java 2006-11-22 09:05:09 UTC (rev 7760)
@@ -0,0 +1,230 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.reporting.api.impl;
+
+import java.io.Serializable;
+
+import org.jboss.reporting.api.distribute.Distribute;
+import org.jboss.reporting.api.distribute.DistributeByMethodReturn;
+import org.jboss.reporting.api.output.OutputFormat;
+import org.jboss.reporting.api.schedule.Schedule;
+import org.jboss.reporting.api.schedule.ScheduleNow;
+import org.jboss.reporting.util.ByteArrayWrapper;
+
+/**
+ * @author noel
+ *
+ */
+public class ReportTaskImpl implements ReportTask, Serializable
+{
+ private static final long serialVersionUID = -3943314104014993256L;
+
+
+ private Report report = null;
+ private Distribute distribute = null;
+ private int outputFormat = 0;
+ private Schedule schedule = null;
+ private String ID = "";
+ private boolean requiresNewID=false;
+
+ // keep this for later
+// private SecurityThing securityInfo=null;
+
+
+ // CTOR
+ /**
+ * default : distribute is synchrone, output is PDF, Shedule is NOW
+ */
+ protected ReportTaskImpl(String in_ID)
+ {
+ this.ID = in_ID;
+ this.distribute = new DistributeByMethodReturn();
+ this.outputFormat = OutputFormat.PDF;
+ this.schedule = new ScheduleNow();
+ }
+
+
+ /** trigger the execution of the report */
+ public void submit() throws Exception
+ {
+ String previousID=this.ID;
+ boolean error=false;
+ try
+ {
+ // when submitted, the RT ID is used as the timer ID
+ // if the RT is used several times, its ID will change
+ if (this.requiresNewID == true)
+ {
+ this.ID = ReportTaskFactory.newReportTaskID();
+ }
+ ReportTaskFactory.reportClient.invoke(this);
+ this.requiresNewID = true;
+ }
+ catch (Throwable e)
+ {
+ error=true;
+ Exception ee=new Exception("Invocation error.");
+ ee.initCause(e);
+ throw ee;
+ }
+ finally
+ {
+ if (error)
+ {
+ this.ID=previousID;
+ }
+ }
+ }
+
+ /**
+ * used to obtain the result of the execution as a string
+ * (<b>not valid</b> for binary output format such as PDF or XLS)
+ * Distribute is DistributeByMethodReturn
+ * Schedule is ScheduleNow
+ */
+ public String executeToString() throws Exception
+ {
+ String result="";
+ this.distribute = new DistributeByMethodReturn();
+ this.schedule = new ScheduleNow();
+ try
+ {
+ result = (String)ReportTaskFactory.reportClient.invoke(this);
+ }
+ catch (Throwable e)
+ {
+ Exception ee=new Exception("Invocation error.");
+ ee.initCause(e);
+ throw ee;
+ }
+ return result;
+ }
+
+ public String executeToString(Report in_report) throws Exception
+ {
+ this.report = in_report;
+ return this.executeToString();
+ }
+
+ public String executeToString(String in_reportAbsoluteName) throws Exception
+ {
+ this.report = new Report(in_reportAbsoluteName);
+ return this.executeToString();
+ }
+
+ /**
+ * used to obtain the result of the execution as a byte array
+ * (for binary output format such as PDF or XLS)
+ * Distribute is DistributeByMethodReturn
+ * Schedule is ScheduleNow
+ */
+ public byte[] executeToByteArray() throws Exception
+ {
+ byte[] result=null;
+ this.distribute = new DistributeByMethodReturn();
+ this.schedule = new ScheduleNow();
+
+ try
+ {
+ result = ((ByteArrayWrapper)ReportTaskFactory.reportClient.invoke(this)).getValue();
+ }
+ catch (Throwable e)
+ {
+ Exception ee=new Exception("Invocation error. " + e);
+ ee.initCause(e);
+ throw ee;
+ }
+
+ return result;
+ }
+
+ public byte[] executeToByteArray(Report in_report) throws Exception
+ {
+ this.report = in_report;
+ return this.executeToByteArray();
+ }
+
+ public byte[] executeToByteArray(String in_reportAbsoluteName) throws Exception
+ {
+ this.report = new Report(in_reportAbsoluteName);
+ return this.executeToByteArray();
+ }
+
+
+
+
+
+
+ public String toString()
+ {
+ String result=
+ "\n\n******************** ReportTask ***********************\n" +
+ "** ID \t= " + this.ID + "\n" +
+ "** report \t= " + this.report.toString() + "\n" +
+ "** output \t= " + OutputFormat.toString(this.outputFormat) + "\n" +
+ "** schedule \t= " + this.schedule.toString() + "\n" +
+ "** distribute \t= " + this.distribute.toString() + "\n";
+
+ if (report.getData() != null) result = result +
+ "** data columns = " + report.getData().toString() + "\n";
+
+ result = result +
+ "*******************************************************\n";
+
+ return result;
+ }
+
+
+// ---- accessors
+
+ public Report getReport()
+ {
+ return report;
+ }
+
+ public void setReport(Report in_value)
+ {
+ report = in_value;
+ }
+
+ public Distribute getDistribute()
+ {
+ return distribute;
+ }
+
+ public void setDistribute(Distribute in_value)
+ {
+ distribute = in_value;
+ }
+
+ public int getOutputFormat()
+ {
+ return outputFormat;
+ }
+
+ public void setOutputFormat(int in_value)
+ {
+ outputFormat = in_value;
+ }
+
+ public Schedule getSchedule()
+ {
+ return this.schedule;
+ }
+
+ public void setSchedule(Schedule in_value)
+ {
+ this.schedule = in_value;
+ }
+
+
+ public String getID()
+ {
+ return ID;
+ }
+
+}
More information about the jboss-svn-commits
mailing list