[jboss-svn-commits] JBL Code SVN: r7006 - labs/reportingservices/trunk/dev/modules/server/impl/src/main/java/org/jboss/reporting/server/deployer
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Sun Oct 22 12:05:01 EDT 2006
Author: romainguinot at gmail.com
Date: 2006-10-22 12:04:59 -0400 (Sun, 22 Oct 2006)
New Revision: 7006
Added:
labs/reportingservices/trunk/dev/modules/server/impl/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGN.java
labs/reportingservices/trunk/dev/modules/server/impl/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGNMBean.java
Log:
initial BIRT deployer
Added: labs/reportingservices/trunk/dev/modules/server/impl/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGN.java
===================================================================
--- labs/reportingservices/trunk/dev/modules/server/impl/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGN.java 2006-10-22 15:59:25 UTC (rev 7005)
+++ labs/reportingservices/trunk/dev/modules/server/impl/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGN.java 2006-10-22 16:04:59 UTC (rev 7006)
@@ -0,0 +1,266 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.reporting.server.deployer;
+
+import java.io.File;
+
+import javax.management.MBeanServer;
+import javax.management.MalformedObjectNameException;
+import javax.management.Notification;
+import javax.management.ObjectName;
+
+import org.eclipse.birt.report.engine.api.IReportDocument;
+import org.jboss.deployment.DeploymentException;
+import org.jboss.deployment.DeploymentInfo;
+import org.jboss.mx.util.MBeanProxyExt;
+import org.jboss.mx.util.ObjectNameFactory;
+import org.jboss.reporting.api.Report;
+import org.jboss.reporting.server.ReportInfo;
+import org.jboss.reporting.server.engine.ReportEngineMBean;
+import org.jboss.reporting.server.repository.RepositoryEntry;
+
+/**
+ * This deployer compiles a JasperReports xml file and put the result into the
+ * repository
+ *
+ * @jmx:mbean name="reporting:service=ReportsDeployer,type=JRXML"
+ * extends="org.jboss.deployment.SubDeployerMBean"
+ *
+ * @version <tt>$Revision: 1.0 $</tt>
+ * @author <a href="mailto:noel.rocher at jboss.org">Noel Rocher</a>
+ */
+public class DeployerRPTDESIGN extends AbstractReportDeployer implements DeployerJRXMLMBean
+{
+
+ private static final ObjectName OBJECT_NAME = ObjectNameFactory.create("reporting:service=ReportsDeployer,type=RPTDESIGN");
+
+ private ReportEngineMBean engine;
+
+ private ObjectName reportEngine;
+
+ protected ObjectName getObjectName(MBeanServer server, ObjectName name) throws MalformedObjectNameException
+ {
+ return name == null ? OBJECT_NAME : name;
+ }
+
+ /**
+ * Get the value of ReportEngine.
+ *
+ * @jmx:managed-attribute
+ * @return value of ReportEngine.
+ */
+ public ObjectName getReportEngine()
+ {
+ return reportEngine;
+ }
+
+ /**
+ * Set the value of ReportEngine.
+ *
+ * @jmx:managed-attribute
+ * @param v
+ * Value to assign to ReportEngine.
+ */
+ public void setReportEngine(ObjectName objectName)
+ {
+ this.reportEngine = objectName;
+ }
+
+ /**
+ * Gets a reference to the JasperReports Engine MBean
+ */
+ protected void startService() throws Exception
+ {
+ engine = (ReportEngineMBean) MBeanProxyExt.create(ReportEngineMBean.class, reportEngine, server);
+
+ // register with MainDeployer
+ super.startService();
+ }
+
+ protected void stopService() throws Exception
+ {
+ // deregister with MainDeployer
+ super.stopService();
+ engine = null;
+ }
+
+ /**
+ * accepts xxx.rptdesign files
+ */
+ public boolean accepts(DeploymentInfo di)
+ {
+ // To be accepted the deployment's root name must end in jar
+ String urlStr = di.url.getFile();
+ if (!urlStr.toUpperCase().endsWith("RPTDESIGN"))
+ {
+ return false;
+ }
+ else
+ {
+ log.debug("accepts> url=" + di.url + ", accepted=" + true);
+ return true;
+ }
+ }
+
+ /**
+ * initialize the URL to be watched
+ */
+ public void init(DeploymentInfo di) throws DeploymentException
+ {
+ log.info("init, " + di.shortName);
+
+ try
+ {
+ di.watch = di.url;
+ log.info("Watch file : " + di.url);
+ }
+ catch (Exception e)
+ {
+ if (e instanceof DeploymentException) throw (DeploymentException) e;
+ throw new DeploymentException("failed to initialize", e);
+ }
+
+ // invoke super-class initialization
+ di.isXML = true;
+ super.init(di);
+ }
+
+ /**
+ * <li>compile the report</li>
+ * <li>bind or rebind it into the JNDI tree</li>
+ */
+ public synchronized void start(DeploymentInfo di) throws DeploymentException
+ {
+ super.start(di);
+ try
+ {
+ ObjectName engineName = new ObjectName("reporting:service=ReportEngine,type=" + di.shortName.substring(di.shortName.lastIndexOf('.') + 1).toUpperCase());
+ IReportDocument report = (IReportDocument) engine.compile(new java.io.FileInputStream(di.url.getFile()), engineName);
+ String jndi_name = toJndiName(di.shortName);
+ String jndi_path = DEFAULT_DOMAIN;
+ repository.put(jndi_path + "/" + jndi_name, new RepositoryEntry(report, engineName));
+
+ // build the ReportInfo for notification
+ ReportInfo ri = new ReportInfo();
+ ri.setFile(new File(di.url.getFile()));
+
+ Report r = new Report();
+ r.setReport_name(jndi_name);
+ r.setReport_path(jndi_path);
+ /*
+ * JRParameter[] jr_params = report.getParameters(); if (jr_params !=
+ * null && jr_params.length > 0) { Map parameters = new
+ * java.util.HashMap(jr_params.length); for (int i=0; i <
+ * jr_params.length ; i++ ) { if (jr_params[i].isForPrompting()) {
+ * parameters.put(jr_params[i].getName(),
+ * jr_params[i].getDescription()); } } r.setParameters(parameters); }
+ */
+
+ ri.setReport(r);
+
+ // Issue the DeployerJRXML.ADD_REPORT_NOTIFICATION
+ Notification msg = new Notification(AbstractReportDeployer.ADD_REPORT_NOTIFICATION, this, getNextNotificationSequenceNumber());
+ msg.setUserData(ri);
+ sendNotification(msg);
+ }
+ catch (Exception e)
+ {
+ log.error(e.getMessage());
+ }
+
+ }
+
+ /**
+ * <li>unbind the report from the JNDI tree</li>
+ */
+ public void stop(DeploymentInfo di) throws DeploymentException
+ {
+ super.stop(di);
+ try
+ {
+ String jndi_name = toJndiName(di.shortName);
+ String jndi_path = DEFAULT_DOMAIN;
+ repository.remove(jndi_path + "/" + jndi_name);
+ // build the ReportInfo for notification (only jndi path & name are
+ // necessary)
+ ReportInfo ri = new ReportInfo();
+ Report r = new Report();
+ r.setReport_path(jndi_path);
+ r.setReport_name(jndi_name);
+ ri.setReport(r);
+
+ // Issue the DeployerJRXML.REMOVE_REPORT_NOTIFICATION
+ Notification msg = new Notification(AbstractReportDeployer.REMOVE_REPORT_NOTIFICATION, this, getNextNotificationSequenceNumber());
+ msg.setUserData(ri);
+ sendNotification(msg);
+ }
+ catch (Exception e)
+ {
+ log.error(e.getMessage());
+ }
+ }
+
+ // -----------------------------------------
+
+ // /**
+ // * Bind the report into jndi
+ // */
+ // protected void bindReport(String jndi_path, String jndi_name,JasperReport
+ // report) throws Exception
+ // {
+ // InitialContext ctx = new InitialContext();
+ // try
+ // {
+ // log.debug("Binding object '" + jndi_name + "' into JNDI at 'java:/" +
+ // jndi_path + "/'");
+ // Name name = ctx.getNameParser("").parse(jndi_path+"/"+jndi_name);
+ // NonSerializableFactory.rebind(name, report, true);
+ // log.info("Bound Report '" + jndi_name + " to JNDI name '" + name + "'");
+ // }
+ // catch (NamingException ne)
+ // {
+ // ne.printStackTrace();
+ // throw new DeploymentException("Could not bind Report into jndi: " +
+ // jndi_path + "/" + jndi_name);
+ // }
+ // finally
+ // {
+ // ctx.close();
+ // }
+ // }
+ //
+ // /**
+ // * Unbind the report from jndi
+ // */
+ // protected void unbindReport(String jndi_path, String jndi_name) throws
+ // Exception
+ // {
+ // InitialContext ctx = new InitialContext();
+ // try
+ // {
+ // Name name = ctx.getNameParser("").parse(jndi_path+"/"+jndi_name);
+ // NonSerializableFactory.unbind(name);
+ // ctx.unbind(name);
+ // log.info("Unbound Report '" + jndi_name + " from JNDI name '" + name +
+ // "'");
+ // }
+ // catch (NamingException ne)
+ // {
+ // ne.printStackTrace();
+ // log.error("Could not unbind Report from jndi: " + jndi_path + "/" + jndi_name, ne);
+ // }
+ // finally
+ // {
+ // ctx.close();
+ // }
+ // }
+
+ protected static String toJndiName(String in_string)
+ {
+ return in_string.replaceAll(".jrxml", "").replaceAll(".RPTDESIGN", "").replaceAll(" ", "_");
+ }
+}
Added: labs/reportingservices/trunk/dev/modules/server/impl/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGNMBean.java
===================================================================
--- labs/reportingservices/trunk/dev/modules/server/impl/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGNMBean.java 2006-10-22 15:59:25 UTC (rev 7005)
+++ labs/reportingservices/trunk/dev/modules/server/impl/src/main/java/org/jboss/reporting/server/deployer/DeployerRPTDESIGNMBean.java 2006-10-22 16:04:59 UTC (rev 7006)
@@ -0,0 +1,21 @@
+package org.jboss.reporting.server.deployer;
+
+/**
+ * MBean interface.
+ */
+public interface DeployerRPTDESIGNMBean extends org.jboss.deployment.SubDeployerMBean {
+
+ //default object name
+ public static final javax.management.ObjectName OBJECT_NAME = org.jboss.mx.util.ObjectNameFactory.create("reporting:service=ReportsDeployer,type=RPTDESIGN");
+
+ /**
+ * Get the value of ReportEngine.
+ * @return value of ReportEngine. */
+ javax.management.ObjectName getReportEngine() ;
+
+ /**
+ * Set the value of ReportEngine.
+ * @param v Value to assign to ReportEngine. */
+ void setReportEngine(javax.management.ObjectName objectName) ;
+
+}
More information about the jboss-svn-commits
mailing list