ode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mr...@apache.org
Subject svn commit: r452179 - in /incubator/ode/trunk: axis2/src/main/java/org/apache/ode/axis2/ bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/ bpel-test/src/test/java/org/apache/ode/test/ bpel-test/src/test/resources/bpel/2.0/TestXslTransform/ jbi/...
Date Mon, 02 Oct 2006 19:36:15 GMT
Author: mriou
Date: Mon Oct  2 12:36:15 2006
New Revision: 452179

URL: http://svn.apache.org/viewvc?view=rev&rev=452179
Log:
[ODE-57] Made sure that doXslTranform works (including xsl params) and added a test case for
it.

Added:
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.bpel
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.wsdl
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.xsl
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/deploy.xml
    incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/test.properties
Modified:
    incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
    incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java
    incubator/ode/trunk/bpel-test/src/test/java/org/apache/ode/test/BPELTest.java
    incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java

Modified: incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java?view=diff&rev=452179&r1=452178&r2=452179
==============================================================================
--- incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java (original)
+++ incubator/ode/trunk/axis2/src/main/java/org/apache/ode/axis2/ODEServer.java Mon Oct  2
12:36:15 2006
@@ -35,6 +35,7 @@
 import org.apache.ode.bpel.dao.BpelDAOConnectionFactory;
 import org.apache.ode.bpel.engine.BpelServerImpl;
 import org.apache.ode.bpel.scheduler.quartz.QuartzSchedulerImpl;
+import org.apache.ode.bpel.xsl.XslTransformHandler;
 import org.apache.ode.daohib.DataSourceConnectionProvider;
 import org.apache.ode.daohib.HibernateTransactionManagerLookup;
 import org.apache.ode.daohib.SessionManager;
@@ -58,6 +59,7 @@
 import javax.transaction.TransactionManager;
 import javax.wsdl.Definition;
 import javax.xml.namespace.QName;
+import javax.xml.transform.TransformerFactory;
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
@@ -124,6 +126,8 @@
         __log.debug("Initializing BPEL server.");
         initBpelServer();
 
+        initXslt();
+
         try {
             _server.start();
         } catch (Exception ex) {
@@ -441,6 +445,10 @@
         _server.init();
     }
 
+    private void initXslt() {
+        TransformerFactory trsf = new net.sf.saxon.TransformerFactoryImpl();
+        XslTransformHandler.getInstance().setTransformerFactory(trsf);
+    }
 
     @SuppressWarnings("unchecked")
     private <T> T lookupInJndi(String objName) throws Exception {

Modified: incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java?view=diff&rev=452179&r1=452178&r2=452179
==============================================================================
--- incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java
(original)
+++ incubator/ode/trunk/bpel-compiler/src/main/java/org/apache/ode/bpel/compiler/BpelC.java
Mon Oct  2 12:36:15 2006
@@ -363,10 +363,7 @@
   }
 
   private void initializeXslEngine(BpelCompiler compiler) {
-    System.setProperty("javax.xml.transform.TransformerFactory",
-            "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl");
-
-    TransformerFactory trsf = TransformerFactory.newInstance();
+    TransformerFactory trsf = new net.sf.saxon.TransformerFactoryImpl();
     XslTransformHandler.getInstance().setTransformerFactory(trsf);
 
     XslCompilationErrorListener xe = new XslCompilationErrorListener(compiler);

Modified: incubator/ode/trunk/bpel-test/src/test/java/org/apache/ode/test/BPELTest.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/java/org/apache/ode/test/BPELTest.java?view=diff&rev=452179&r1=452178&r2=452179
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/java/org/apache/ode/test/BPELTest.java (original)
+++ incubator/ode/trunk/bpel-test/src/test/java/org/apache/ode/test/BPELTest.java Mon Oct
 2 12:36:15 2006
@@ -191,7 +191,10 @@
 	public void testCorrelationAsync() throws Exception {
 		go("target/test-classes/bpel/2.0/testCorrelationAsync");
 	}
-    
+    public void testXslTransform() throws Exception {
+        go("target/test-classes/bpel/2.0/TestXslTransform");
+    }
+
     /** These tests compile however they fail at runtime */
   
 //	public void testCompensationHandlers() throws Exception {

Added: incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.bpel
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.bpel?view=auto&rev=452179
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.bpel
(added)
+++ incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.bpel
Mon Oct  2 12:36:15 2006
@@ -0,0 +1,52 @@
+<process name="HelloXslWorld" 
+    targetNamespace="http://pxe/bpel/unit-test" 
+    xmlns:bpws="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+    xmlns="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+    xmlns:tns="http://pxe/bpel/unit-test"
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    xmlns:types="http://pxe/bpel/types"
+    xmlns:test="http://pxe/bpel/unit-test.wsdl">
+
+    <import location="HelloXslWorld.wsdl"
+        namespace="http://pxe/bpel/unit-test.wsdl"
+        importType="http://schemas.xmlsoap.org/wsdl/"/>
+    
+    <partnerLinks>
+        <partnerLink name="helloXslPartnerLink" 
+            partnerLinkType="test:HelloXslPartnerLinkType" 
+            myRole="me" />
+    </partnerLinks>
+        
+    <variables>
+        <variable name="myVar" messageType="test:HelloXslMessage"/>
+        <variable name="xslVar" type="xsd:string"/>
+    </variables>
+            
+    <sequence>   
+        <receive 
+            name="start"
+            partnerLink="helloXslPartnerLink"
+            portType="test:HelloXslPortType"
+            operation="helloXsl"
+            variable="myVar"
+            createInstance="yes"/>
+        <assign name="assign1">
+            <copy>
+                <from><literal>Xsl</literal></from>
+                <to>$xslVar</to>
+            </copy>
+            <copy>
+                <from>
+                    bpws:doXslTransform("HelloXslWorld.xsl", $myVar/TestPart, 'middle', $xslVar)
+                </from>
+                <to variable="myVar" part="TestPart"/>
+            </copy>
+        </assign>
+        <reply name="end"  
+                partnerLink="helloXslPartnerLink"
+                portType="test:HelloXslPortType" 
+                operation="helloXsl"
+                variable="myVar"/>
+    </sequence>
+    
+</process>

Added: incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.wsdl
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.wsdl?view=auto&rev=452179
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.wsdl
(added)
+++ incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.wsdl
Mon Oct  2 12:36:15 2006
@@ -0,0 +1,62 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+<wsdl:definitions 
+    targetNamespace="http://pxe/bpel/unit-test.wsdl"
+    xmlns="http://schemas.xmlsoap.org/wsdl/"
+    xmlns:tns="http://pxe/bpel/unit-test.wsdl"
+    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" 
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+    xmlns:types="http://pxe/bpel/types"
+    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
+    xmlns:bpws="http://schemas.xmlsoap.org/ws/2004/03/business-process/"
+    xmlns:plnk="http://schemas.xmlsoap.org/ws/2004/03/partner-link/">
+
+    <wsdl:types>
+        <xsd:schema targetNamespace="http://pxe/bpel/types">
+                <xsd:complexType name="ContentCT">
+                <xsd:sequence>
+                    <xsd:element name="content" type="xsd:string"/>
+                </xsd:sequence>
+                </xsd:complexType>
+        </xsd:schema>
+    </wsdl:types>
+
+    <wsdl:message name="HelloXslMessage">
+        <wsdl:part name="TestPart" type="types:ContentCT"/>
+    </wsdl:message>
+
+    <wsdl:portType name="HelloXslPortType">
+        <wsdl:operation name="helloXsl">
+            <wsdl:input message="tns:HelloXslMessage" name="TestIn"/>
+            <wsdl:output message="tns:HelloXslMessage" name="TestOut"/>
+        </wsdl:operation>    
+    </wsdl:portType>
+
+    <wsdl:binding name="HelloXslSoapBinding" type="tns:HelloXslPortType">
+        <soap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
+        <wsdl:operation name="helloXsl">
+            <soap:operation soapAction="" style="rpc"/>
+            <wsdl:input>
+                <soap:body
+                    namespace="http://pxe/bpel/unit-test.wsdl"
+                    use="literal"/>
+            </wsdl:input>
+            <wsdl:output>
+                <soap:body
+                    namespace="http://pxe/bpel/unit-test.wsdl" 
+                    use="literal"/>
+            </wsdl:output>
+        </wsdl:operation>
+    </wsdl:binding>
+    <wsdl:service name="HelloXslService">
+                <wsdl:port name="HelloXslPort" binding="tns:HelloXslSoapBinding">
+                <soap:address location="http://localhost:8080/pxe/soap/helloXslWorld"/>
+                </wsdl:port>
+    </wsdl:service>
+    
+    <plnk:partnerLinkType name="HelloXslPartnerLinkType">
+        <plnk:role name="me" portType="tns:HelloXslPortType"/>
+        <plnk:role name="you" portType="tns:HelloXslPortType"/>
+    </plnk:partnerLinkType>
+</wsdl:definitions>
+

Added: incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.xsl
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.xsl?view=auto&rev=452179
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.xsl
(added)
+++ incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/HelloXslWorld.xsl
Mon Oct  2 12:36:15 2006
@@ -0,0 +1,16 @@
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
+  <xsl:output method="xml"/>
+  <xsl:param name = "middle"/>
+
+  <xsl:template match="content">
+    <!-- Per the WS-BPEL spec, only the single child of the root of the 
+         result tree is considered (so the root element here is "suppressed"
+         in the engine) -->
+    <xsl:element name="root"> 
+      <xsl:element name="hello">
+        <xsl:value-of select="concat(text(), $middle, ' World')"/>
+      </xsl:element>
+    </xsl:element>
+  </xsl:template>
+
+</xsl:stylesheet>
\ No newline at end of file

Added: incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/deploy.xml
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/deploy.xml?view=auto&rev=452179
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/deploy.xml
(added)
+++ incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/deploy.xml
Mon Oct  2 12:36:15 2006
@@ -0,0 +1,11 @@
+<deploy xmlns="http://ode.fivesight.com/schemas/2006/06/27/dd" 
+        xmlns:pns="http://pxe/bpel/unit-test"
+        xmlns:wns="http://ode/bpel/unit-test.wsdl">
+
+    <process name="pns:HelloXslWorld">
+        <active>true</active>
+        <provide partnerLink="helloXslPartnerLink">
+            <service name="wns:HelloXslService" port="HelloXslPort"/>
+        </provide>
+    </process>
+</deploy>

Added: incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/test.properties
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/test.properties?view=auto&rev=452179
==============================================================================
--- incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/test.properties
(added)
+++ incubator/ode/trunk/bpel-test/src/test/resources/bpel/2.0/TestXslTransform/test.properties
Mon Oct  2 12:36:15 2006
@@ -0,0 +1,6 @@
+namespace=http://ode/bpel/unit-test.wsdl
+service=HelloXslService
+operation=helloXsl
+request1=<message><TestPart><content>Hello</content></TestPart></message>
+response1=.*HelloXsl World.*
+

Modified: incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java
URL: http://svn.apache.org/viewvc/incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java?view=diff&rev=452179&r1=452178&r2=452179
==============================================================================
--- incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java (original)
+++ incubator/ode/trunk/jbi/src/main/java/org/apache/ode/jbi/OdeLifeCycle.java Mon Oct  2
12:36:15 2006
@@ -37,6 +37,7 @@
 import javax.naming.InitialContext;
 import javax.sql.DataSource;
 import javax.transaction.TransactionManager;
+import javax.xml.transform.TransformerFactory;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -44,6 +45,7 @@
 import org.apache.ode.bpel.connector.BpelServerConnector;
 import org.apache.ode.bpel.engine.BpelServerImpl;
 import org.apache.ode.bpel.scheduler.quartz.QuartzSchedulerImpl;
+import org.apache.ode.bpel.xsl.XslTransformHandler;
 import org.apache.ode.daohib.DataSourceConnectionProvider;
 import org.apache.ode.daohib.HibernateTransactionManagerLookup;
 import org.apache.ode.daohib.SessionManager;
@@ -62,481 +64,488 @@
  */
 public class OdeLifeCycle implements ComponentLifeCycle {
 
-  private static final String DEFAULT_HIBERNATE_DIALECT = "org.hibernate.dialect.DerbyDialect";
+    private static final String DEFAULT_HIBERNATE_DIALECT = "org.hibernate.dialect.DerbyDialect";
 
-  private static final Messages __msgs = Messages.getMessages(Messages.class);
+    private static final Messages __msgs = Messages.getMessages(Messages.class);
 
-  private static final Log __log = LogFactory.getLog(OdeLifeCycle.class);
+    private static final Log __log = LogFactory.getLog(OdeLifeCycle.class);
 
-  private OdeSUManager _suManager = null;
+    private OdeSUManager _suManager = null;
 
-  private boolean _initSuccess = false;
-
-  private OdeContext _ode;
-
-  private Receiver _receiver;
-
-  private boolean _started;
-
-  private boolean _needDerbyShutdown;
-
-  private String _derbyUrl;
-
-  private BpelServerConnector _connector;
-
-  ServiceUnitManager getSUManager() {
-    return _suManager;
-  }
-
-  OdeContext getOdeContext() {
-    return _ode;
-  }
-
-  public ObjectName getExtensionMBeanName() {
-    return null;
-  }
-
-  public void init(ComponentContext context) throws JBIException {
-    try {
-      _ode = OdeContext.getInstance();
-      _ode.setContext(context);
-      _ode._consumer = new OdeConsumer(_ode);
-
-      
-      TempFileManager.setWorkingDirectory(new File(_ode.getContext()
-          .getWorkspaceRoot()));
-
-      __log.debug("Loading properties.");
-      initProperties();
-
-      __log.debug("Initializing message mappers.");
-      initMappers();
-      
-
-      __log.debug("Creating data source.");
-      initDataSource();
-
-      __log.debug("Starting Hibernate.");
-      initHibernate();
-
-      __log.info("Hibernate started.");
-
-      __log.debug("Starting BPEL server.");
-      initBpelServer();
-
-      __log.debug("Starting JCA connector.");
-      initConnector();
-      
-      _suManager = new OdeSUManager(_ode);
-      _initSuccess = true;
-      __log.info(__msgs.msgOdeInitialized());
-    } finally {
-      if (!_initSuccess) {
-        // TODO ..then what? at least shutdown the scheduler 
-      }
-    }
-  }
-
-  private void initMappers() throws JBIException  {
-    Class mapperClass;
-    try {
-      mapperClass = Class.forName(_ode._config.getMessageMapper());
-    } catch (ClassNotFoundException e) {
-      String errmsg = __msgs.msgOdeInitMapperClassNotFound(_ode._config.getMessageMapper());
-      __log.error(errmsg);
-      throw new JBIException(errmsg, e);
-    } catch (Throwable t) {
-      String errmsg = __msgs.msgOdeInitMapperClassLoadFailed(_ode._config.getMessageMapper());
-      __log.error(errmsg);
-      throw new JBIException(errmsg, t);
-    }
-    try {
-      _ode.registerMapper((Mapper) mapperClass.newInstance());
-    } catch (Throwable t) {
-      String errmsg = __msgs.msgOdeInitMapperInstantiationFailed(_ode._config.getMessageMapper());
-      __log.error(errmsg);
-      throw new JBIException(errmsg, t);
-    }
-  }
-
-  private void initDataSource() throws JBIException {
-    switch (_ode._config.getDbMode()) {
-    case EXTERNAL:
-      initExternalDb();
-      break;
-    case EMBEDDED:
-      initEmbeddedDb();
-      break;
-    case INTERNAL:
-      initInternalDb();
-      break;
-    default:
-      break;
-    }
-  }
-
-  private void initExternalDb() throws JBIException {
-    try {
-      _ode._dataSource = lookupInJndi(_ode._config.getDbDataSource());
-      __log.info(__msgs.msgOdeUsingExternalDb(_ode._config.getDbDataSource()));
-    } catch (Exception ex) {
-      String msg = __msgs.msgOdeInitExternalDbFailed(_ode._config.getDbDataSource());
-      __log.error(msg,ex);
-      throw new JBIException(msg,ex);
-    }
-  }
-
-  private void initInternalDb() throws JBIException {
-    throw new JBIException("internalDb not supported!");
-  }
-
-  /**
-   * Initialize embedded (DERBY) database.
-   */
-  private void initEmbeddedDb() throws JBIException {
-    __log.info("Using DataSource Derby");
-
-    String url = 
-      "jdbc:derby:" + _ode.getContext().getInstallRoot() + "/"
-      + _ode._config.getDbEmbeddedName();
-    
-    __log.debug("creating Minerva pool for " + url);
-    
-    MinervaPool minervaPool = new MinervaPool();
-    minervaPool.setTransactionManager(_ode.getTransactionManager());
-    minervaPool.getConnectionFactory().setConnectionURL(url);
-    minervaPool.getConnectionFactory().setUserName("sa");
-    minervaPool.getConnectionFactory().setDriver(
-        org.apache.derby.jdbc.EmbeddedDriver.class.getName());
-
-    minervaPool.getPoolParams().maxSize = _ode._config.getPoolMaxSize();
-    minervaPool.getPoolParams().minSize = _ode._config.getPoolMinSize();
-    minervaPool.getPoolParams().blocking = false;
-    minervaPool.setType(PoolType.MANAGED);
-    
-    try {
-      minervaPool.start();
-    } catch (Exception ex) {
-      String errmsg = __msgs.msgOdeDbPoolStartupFailed(url);
-      __log.error(errmsg,ex);
-      throw new JBIException(errmsg,ex);
-    }
-
-    _ode._dataSource = minervaPool.createDataSource();
-    _needDerbyShutdown = true;
-    _derbyUrl = url;
-  }
-
-  /**
-   * Load the "ode-jbi.properties" file from the install directory.
-   * 
-   * @throws JBIException
-   */
-  private void initProperties() throws JBIException {
-    OdeConfigProperties config = new OdeConfigProperties(_ode.getContext()
-        .getInstallRoot());
-    config.load();
-    _ode._config = config;
-  }
-
-  private void initBpelServer() throws JBIException {
-    if (__log.isDebugEnabled()) {
-      __log.debug("ODE initializing");
-    }
-
-    _ode._server = new BpelServerImpl();
-    // We don't want the server to automatically activate deployed processes,
-    // we'll do that explcitly
-    _ode._server.setAutoActivate(true);
-    _ode._eprContext = new EndpointReferenceContextImpl(_ode);
-    _ode._mexContext = new MessageExchangeContextImpl(_ode);
-    _ode._executorService = Executors.newCachedThreadPool();
-    _ode._scheduler = new QuartzSchedulerImpl();
-    _ode._scheduler.setBpelServer(_ode._server);
-    _ode._scheduler.setExecutorService(_ode._executorService, 20);
-    _ode._scheduler.setTransactionManager((TransactionManager) _ode
-        .getContext().getTransactionManager());
-    _ode._scheduler.setDataSource(_ode._dataSource);
-    _ode._scheduler.init();
-
-    _ode._server.setDaoConnectionFactory(_ode._daocf);
-    _ode._server.setEndpointReferenceContext(_ode._eprContext);
-    _ode._server.setMessageExchangeContext(_ode._mexContext);
-    _ode._server.setBindingContext(new BindingContextImpl(_ode));
-    _ode._server.setScheduler(_ode._scheduler);
-    _ode._server.init();
-
-  }
-
-  /**
-   * Initialize the Hibernate data store.
-   * 
-   * @throws JBIException
-   */
-  private void initHibernate() throws JBIException {
-    Properties properties = new Properties();
-    properties.put(Environment.CONNECTION_PROVIDER,
-        DataSourceConnectionProvider.class.getName());
-    properties.put(Environment.TRANSACTION_MANAGER_STRATEGY,
-        HibernateTransactionManagerLookup.class.getName());
-    properties.put(Environment.SESSION_FACTORY_NAME, "jta");
-    
-    try {
-      properties.put(Environment.DIALECT, guessDialect(_ode._dataSource));
-    } catch (Exception ex) {
-      String errmsg = __msgs.msgOdeInitHibernateDialectDetectFailed();
-      __log.error(errmsg,ex);
-      throw new JBIException(errmsg,ex);
-    }
-
-    File hibernatePropFile = new File(_ode.getContext().getInstallRoot()
-        + File.separatorChar + "hibernate.properties");
-
-    if (hibernatePropFile.exists()) {
-      FileInputStream fis = null;
-      try {
-        fis = new FileInputStream(hibernatePropFile);
-        properties.load(new BufferedInputStream(fis));
-      } catch (IOException e) {
-        String errmsg = __msgs
-            .msgOdeInitHibernateErrorReadingHibernateProperties(hibernatePropFile);
-        __log.error(errmsg, e);
-        throw new JBIException(errmsg, e);
-      }
-    } else {
-      __log.info(__msgs
-          .msgOdeInitHibernatePropertiesNotFound(hibernatePropFile));
-    }
-
-    SessionManager sm = new SessionManager(properties, _ode._dataSource, _ode
-        .getTransactionManager());
-    _ode._daocf = new BpelDAOConnectionFactoryImpl(sm);
-  }
-
-  private void initConnector() throws JBIException {
-    int port = _ode._config.getConnectorPort();
-    if (port == 0) {
-      __log.info("Skipping connector initialization.");
-    } else {
-      _connector = new BpelServerConnector();
-      _connector.setBpelServer(_ode._server);
-      _connector.setPort(_ode._config.getConnectorPort());
-      _connector.setId(_ode._config.getConnectorName());
-      try {
-        _connector.start();
-      } catch (Exception e) {
-    	__log.error("Failed to initialize JCA connector.",e);
-      }
-    }
-  }
-  
-  public synchronized void start() throws JBIException {
-    if (_started)
-      return;
-    
-    try {
-      __log.info(__msgs.msgOdeStarting());
-
-      if (!_initSuccess) {
-        String errmsg = "attempt to call start() after init() failure.";
-        IllegalStateException ex = new IllegalStateException(errmsg); 
-        __log.fatal(errmsg, ex);
-        throw new JBIException(errmsg,ex);
-      }
-
-      if (_ode.getChannel() == null) {
-        throw (new JBIException("No channel!", new NullPointerException()));
-      }
-
-      try {
-        _ode._server.start();
-      } catch (Exception ex) {
-        String errmsg = __msgs.msgOdeBpelServerStartFailure();
-        __log.error(errmsg,ex);
-        throw new JBIException(errmsg, ex);
-      }
-
-      _receiver = new Receiver(_ode);
-      _receiver.start();
-      _started = true;
-      __log.info(__msgs.msgOdeStarted());
-    } finally {
-      if (!_started) {
-        if (_receiver != null) {
-          _receiver.cease();
-        }
-        _receiver = null;
-      }
-    }
-  }
-
-  public synchronized void stop() throws JBIException {
-    if (!_started) {
-      return;
+    private boolean _initSuccess = false;
+
+    private OdeContext _ode;
+
+    private Receiver _receiver;
+
+    private boolean _started;
+
+    private boolean _needDerbyShutdown;
+
+    private String _derbyUrl;
+
+    private BpelServerConnector _connector;
+
+    ServiceUnitManager getSUManager() {
+        return _suManager;
     }
 
-    __log.info("Stopping ODE.");
+    OdeContext getOdeContext() {
+        return _ode;
+    }
 
-    try {
+    public ObjectName getExtensionMBeanName() {
+        return null;
+    }
 
-      if (_receiver != null) {
+    public void init(ComponentContext context) throws JBIException {
         try {
-          _receiver.cease();
-        } catch (Exception ex) {
-          __log.fatal("Error ceasing receiver.", ex);
+            _ode = OdeContext.getInstance();
+            _ode.setContext(context);
+            _ode._consumer = new OdeConsumer(_ode);
+
+
+            TempFileManager.setWorkingDirectory(new File(_ode.getContext()
+                    .getWorkspaceRoot()));
+
+            __log.debug("Loading properties.");
+            initProperties();
+
+            __log.debug("Initializing message mappers.");
+            initMappers();
+
+            __log.debug("Creating data source.");
+            initDataSource();
+
+            __log.debug("Starting Hibernate.");
+            initHibernate();
+
+            __log.info("Hibernate started.");
+
+            __log.debug("Starting BPEL server.");
+            initBpelServer();
+
+            __log.debug("Starting JCA connector.");
+            initConnector();
+
+            initXslt();
+
+            _suManager = new OdeSUManager(_ode);
+            _initSuccess = true;
+            __log.info(__msgs.msgOdeInitialized());
         } finally {
-          _receiver = null;
+            if (!_initSuccess) {
+                // TODO ..then what? at least shutdown the scheduler
+            }
+        }
+    }
+
+    private void initMappers() throws JBIException  {
+        Class mapperClass;
+        try {
+            mapperClass = Class.forName(_ode._config.getMessageMapper());
+        } catch (ClassNotFoundException e) {
+            String errmsg = __msgs.msgOdeInitMapperClassNotFound(_ode._config.getMessageMapper());
+            __log.error(errmsg);
+            throw new JBIException(errmsg, e);
+        } catch (Throwable t) {
+            String errmsg = __msgs.msgOdeInitMapperClassLoadFailed(_ode._config.getMessageMapper());
+            __log.error(errmsg);
+            throw new JBIException(errmsg, t);
+        }
+        try {
+            _ode.registerMapper((Mapper) mapperClass.newInstance());
+        } catch (Throwable t) {
+            String errmsg = __msgs.msgOdeInitMapperInstantiationFailed(_ode._config.getMessageMapper());
+            __log.error(errmsg);
+            throw new JBIException(errmsg, t);
+        }
+    }
+
+    private void initDataSource() throws JBIException {
+        switch (_ode._config.getDbMode()) {
+            case EXTERNAL:
+                initExternalDb();
+                break;
+            case EMBEDDED:
+                initEmbeddedDb();
+                break;
+            case INTERNAL:
+                initInternalDb();
+                break;
+            default:
+                break;
+        }
+    }
+
+    private void initExternalDb() throws JBIException {
+        try {
+            _ode._dataSource = lookupInJndi(_ode._config.getDbDataSource());
+            __log.info(__msgs.msgOdeUsingExternalDb(_ode._config.getDbDataSource()));
+        } catch (Exception ex) {
+            String msg = __msgs.msgOdeInitExternalDbFailed(_ode._config.getDbDataSource());
+            __log.error(msg,ex);
+            throw new JBIException(msg,ex);
+        }
+    }
+
+    private void initInternalDb() throws JBIException {
+        throw new JBIException("internalDb not supported!");
+    }
+
+    /**
+     * Initialize embedded (DERBY) database.
+     */
+    private void initEmbeddedDb() throws JBIException {
+        __log.info("Using DataSource Derby");
+
+        String url =
+                "jdbc:derby:" + _ode.getContext().getInstallRoot() + "/"
+                        + _ode._config.getDbEmbeddedName();
+
+        __log.debug("creating Minerva pool for " + url);
+
+        MinervaPool minervaPool = new MinervaPool();
+        minervaPool.setTransactionManager(_ode.getTransactionManager());
+        minervaPool.getConnectionFactory().setConnectionURL(url);
+        minervaPool.getConnectionFactory().setUserName("sa");
+        minervaPool.getConnectionFactory().setDriver(
+                org.apache.derby.jdbc.EmbeddedDriver.class.getName());
+
+        minervaPool.getPoolParams().maxSize = _ode._config.getPoolMaxSize();
+        minervaPool.getPoolParams().minSize = _ode._config.getPoolMinSize();
+        minervaPool.getPoolParams().blocking = false;
+        minervaPool.setType(PoolType.MANAGED);
+
+        try {
+            minervaPool.start();
+        } catch (Exception ex) {
+            String errmsg = __msgs.msgOdeDbPoolStartupFailed(url);
+            __log.error(errmsg,ex);
+            throw new JBIException(errmsg,ex);
         }
-      }
 
-      try {
-        _ode._server.stop();
+        _ode._dataSource = minervaPool.createDataSource();
+        _needDerbyShutdown = true;
+        _derbyUrl = url;
+    }
+
+    /**
+     * Load the "ode-jbi.properties" file from the install directory.
+     *
+     * @throws JBIException
+     */
+    private void initProperties() throws JBIException {
+        OdeConfigProperties config = new OdeConfigProperties(_ode.getContext()
+                .getInstallRoot());
+        config.load();
+        _ode._config = config;
+    }
+
+    private void initBpelServer() throws JBIException {
+        if (__log.isDebugEnabled()) {
+            __log.debug("ODE initializing");
+        }
+
+        _ode._server = new BpelServerImpl();
+        // We don't want the server to automatically activate deployed processes,
+        // we'll do that explcitly
+        _ode._server.setAutoActivate(true);
+        _ode._eprContext = new EndpointReferenceContextImpl(_ode);
+        _ode._mexContext = new MessageExchangeContextImpl(_ode);
+        _ode._executorService = Executors.newCachedThreadPool();
+        _ode._scheduler = new QuartzSchedulerImpl();
+        _ode._scheduler.setBpelServer(_ode._server);
+        _ode._scheduler.setExecutorService(_ode._executorService, 20);
+        _ode._scheduler.setTransactionManager((TransactionManager) _ode
+                .getContext().getTransactionManager());
+        _ode._scheduler.setDataSource(_ode._dataSource);
+        _ode._scheduler.init();
+
+        _ode._server.setDaoConnectionFactory(_ode._daocf);
+        _ode._server.setEndpointReferenceContext(_ode._eprContext);
+        _ode._server.setMessageExchangeContext(_ode._mexContext);
+        _ode._server.setBindingContext(new BindingContextImpl(_ode));
+        _ode._server.setScheduler(_ode._scheduler);
+        _ode._server.init();
+
+    }
+
+    /**
+     * Initialize the Hibernate data store.
+     *
+     * @throws JBIException
+     */
+    private void initHibernate() throws JBIException {
+        Properties properties = new Properties();
+        properties.put(Environment.CONNECTION_PROVIDER,
+                DataSourceConnectionProvider.class.getName());
+        properties.put(Environment.TRANSACTION_MANAGER_STRATEGY,
+                HibernateTransactionManagerLookup.class.getName());
+        properties.put(Environment.SESSION_FACTORY_NAME, "jta");
 
-      } catch (Throwable ex) {
-        __log.fatal("Error stopping services.", ex);
-      }
-
-      __log.info("ODE stopped.");
-    } finally {
-      _started = false;
-    }
-  }
-
-  /**
-   * Shutdown the service engine. This performs cleanup before the BPE is
-   * terminated. Once this method has been called, init() must be called before
-   * the transformation engine can be started again with a call to start().
-   * 
-   * @throws javax.jbi.JBIException
-   *           if the transformation engine is unable to shut down.
-   */
-  public void shutDown() throws JBIException {
-    ClassLoader old = Thread.currentThread().getContextClassLoader();
-    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-    
-    if (_connector != null) {
-      try {
-        _connector.shutdown();
-      } catch (Exception e) {
-        __log.error("Error shutting down JCA server.",e);
-      }
-      _connector = null;
-    }
-    
-    try {
-
-      try {
-        __log.debug("shutting down quartz scheduler.");
-        _ode._scheduler.shutdown();
-      } catch (Exception ex) {
-
-      }
-
-      __log.debug("cleaning up temporary files.");
-      TempFileManager.cleanup();
-
-      _suManager = null;
-      _ode = null;
-
-      if (_needDerbyShutdown) {
-        __log.debug("shutting down derby.");
-        EmbeddedDriver driver = new EmbeddedDriver();
         try {
-          driver.connect(_derbyUrl+";shutdown", new Properties());
+            properties.put(Environment.DIALECT, guessDialect(_ode._dataSource));
         } catch (Exception ex) {
-          __log.error("Error shutting down derby.", ex);
+            String errmsg = __msgs.msgOdeInitHibernateDialectDetectFailed();
+            __log.error(errmsg,ex);
+            throw new JBIException(errmsg,ex);
+        }
+
+        File hibernatePropFile = new File(_ode.getContext().getInstallRoot()
+                + File.separatorChar + "hibernate.properties");
+
+        if (hibernatePropFile.exists()) {
+            FileInputStream fis = null;
+            try {
+                fis = new FileInputStream(hibernatePropFile);
+                properties.load(new BufferedInputStream(fis));
+            } catch (IOException e) {
+                String errmsg = __msgs
+                        .msgOdeInitHibernateErrorReadingHibernateProperties(hibernatePropFile);
+                __log.error(errmsg, e);
+                throw new JBIException(errmsg, e);
+            }
+        } else {
+            __log.info(__msgs
+                    .msgOdeInitHibernatePropertiesNotFound(hibernatePropFile));
         }
-      }
-      __log.info("Shutdown completed.");
-    } finally {
-      Thread.currentThread().setContextClassLoader(old);
-    }
-  }
-
-  @SuppressWarnings("unchecked")
-  private <T> T lookupInJndi(String objName) throws Exception {
-    ClassLoader old = Thread.currentThread().getContextClassLoader();
-    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
-    try {
-      InitialContext ctx = null;
-      try {
-        ctx = new InitialContext();
-        return (T) ctx.lookup(objName);
-      } finally {
-        if (ctx != null)
-          try {
-            ctx.close();
-          } catch (Exception ex1) {
-            ; // swallow
-            __log.error("Error closing JNDI connection.", ex1);
-          }
-      }
-    } finally {
-      Thread.currentThread().setContextClassLoader(old);
-    }
-
-  }
-
-  private String guessDialect(DataSource dataSource) throws Exception {
-    String dialect = null;
-    // Open a connection and use that connection to figure out database
-    // product name/version number in order to decide which Hibernate
-    // dialect to use.
-    Connection conn = dataSource.getConnection();
-    try {
-      DatabaseMetaData metaData = conn.getMetaData();
-      if (metaData != null) {
-        String dbProductName = metaData.getDatabaseProductName();
-        int dbMajorVer = metaData.getDatabaseMajorVersion();
-        __log.info("Using database " + dbProductName + " major version "
-            + dbMajorVer);
-        DialectFactory.DatabaseDialectMapper mapper = (DialectFactory.DatabaseDialectMapper)
HIBERNATE_DIALECTS
-            .get(dbProductName);
-        if (mapper != null) {
-          dialect = mapper.getDialectClass(dbMajorVer);
+
+        SessionManager sm = new SessionManager(properties, _ode._dataSource, _ode
+                .getTransactionManager());
+        _ode._daocf = new BpelDAOConnectionFactoryImpl(sm);
+    }
+
+    private void initConnector() throws JBIException {
+        int port = _ode._config.getConnectorPort();
+        if (port == 0) {
+            __log.info("Skipping connector initialization.");
         } else {
-          Dialect hbDialect = DialectFactory.determineDialect(
-              dbProductName, dbMajorVer);
-          if (hbDialect != null)
-            dialect = hbDialect.getClass().getName();
-        }
-      }
-    } finally {
-      conn.close();
-    }
-
-    if (dialect == null) {
-      __log
-          .info("Cannot determine hibernate dialect for this database: using the default
one.");
-      dialect = DEFAULT_HIBERNATE_DIALECT;
-    }
-
-    assert dialect != null;
-
-    return dialect;
-
-  }
-
-  private static final HashMap<String, DialectFactory.VersionInsensitiveMapper> HIBERNATE_DIALECTS
= new HashMap<String, DialectFactory.VersionInsensitiveMapper>();
-
-  static {
-    // Hibernate has a nice table that resolves the dialect from the database
-    // product name,
-    // but doesn't include all the drivers. So this is supplementary, and some
-    // day in the
-    // future they'll add more drivers and we can get rid of this.
-    // Drivers already recognized by Hibernate:
-    // HSQL Database Engine
-    // DB2/NT
-    // MySQL
-    // PostgreSQL
-    // Microsoft SQL Server Database, Microsoft SQL Server
-    // Sybase SQL Server
-    // Informix Dynamic Server
-    // Oracle 8 and Oracle >8
-    HIBERNATE_DIALECTS.put("Apache Derby",
-        new DialectFactory.VersionInsensitiveMapper(
-            "org.hibernate.dialect.DerbyDialect"));
-  }
+            _connector = new BpelServerConnector();
+            _connector.setBpelServer(_ode._server);
+            _connector.setPort(_ode._config.getConnectorPort());
+            _connector.setId(_ode._config.getConnectorName());
+            try {
+                _connector.start();
+            } catch (Exception e) {
+                __log.error("Failed to initialize JCA connector.",e);
+            }
+        }
+    }
+
+    private void initXslt() {
+        TransformerFactory trsf = new net.sf.saxon.TransformerFactoryImpl();
+        XslTransformHandler.getInstance().setTransformerFactory(trsf);
+    }
+
+
+    public synchronized void start() throws JBIException {
+        if (_started)
+            return;
+
+        try {
+            __log.info(__msgs.msgOdeStarting());
+
+            if (!_initSuccess) {
+                String errmsg = "attempt to call start() after init() failure.";
+                IllegalStateException ex = new IllegalStateException(errmsg);
+                __log.fatal(errmsg, ex);
+                throw new JBIException(errmsg,ex);
+            }
+
+            if (_ode.getChannel() == null) {
+                throw (new JBIException("No channel!", new NullPointerException()));
+            }
+
+            try {
+                _ode._server.start();
+            } catch (Exception ex) {
+                String errmsg = __msgs.msgOdeBpelServerStartFailure();
+                __log.error(errmsg,ex);
+                throw new JBIException(errmsg, ex);
+            }
+
+            _receiver = new Receiver(_ode);
+            _receiver.start();
+            _started = true;
+            __log.info(__msgs.msgOdeStarted());
+        } finally {
+            if (!_started) {
+                if (_receiver != null) {
+                    _receiver.cease();
+                }
+                _receiver = null;
+            }
+        }
+    }
+
+    public synchronized void stop() throws JBIException {
+        if (!_started) {
+            return;
+        }
+
+        __log.info("Stopping ODE.");
+
+        try {
+
+            if (_receiver != null) {
+                try {
+                    _receiver.cease();
+                } catch (Exception ex) {
+                    __log.fatal("Error ceasing receiver.", ex);
+                } finally {
+                    _receiver = null;
+                }
+            }
+
+            try {
+                _ode._server.stop();
+
+            } catch (Throwable ex) {
+                __log.fatal("Error stopping services.", ex);
+            }
+
+            __log.info("ODE stopped.");
+        } finally {
+            _started = false;
+        }
+    }
+
+    /**
+     * Shutdown the service engine. This performs cleanup before the BPE is
+     * terminated. Once this method has been called, init() must be called before
+     * the transformation engine can be started again with a call to start().
+     *
+     * @throws javax.jbi.JBIException
+     *           if the transformation engine is unable to shut down.
+     */
+    public void shutDown() throws JBIException {
+        ClassLoader old = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+
+        if (_connector != null) {
+            try {
+                _connector.shutdown();
+            } catch (Exception e) {
+                __log.error("Error shutting down JCA server.",e);
+            }
+            _connector = null;
+        }
+
+        try {
+
+            try {
+                __log.debug("shutting down quartz scheduler.");
+                _ode._scheduler.shutdown();
+            } catch (Exception ex) {
+
+            }
+
+            __log.debug("cleaning up temporary files.");
+            TempFileManager.cleanup();
+
+            _suManager = null;
+            _ode = null;
+
+            if (_needDerbyShutdown) {
+                __log.debug("shutting down derby.");
+                EmbeddedDriver driver = new EmbeddedDriver();
+                try {
+                    driver.connect(_derbyUrl+";shutdown", new Properties());
+                } catch (Exception ex) {
+                    __log.error("Error shutting down derby.", ex);
+                }
+            }
+            __log.info("Shutdown completed.");
+        } finally {
+            Thread.currentThread().setContextClassLoader(old);
+        }
+    }
+
+    @SuppressWarnings("unchecked")
+    private <T> T lookupInJndi(String objName) throws Exception {
+        ClassLoader old = Thread.currentThread().getContextClassLoader();
+        Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
+        try {
+            InitialContext ctx = null;
+            try {
+                ctx = new InitialContext();
+                return (T) ctx.lookup(objName);
+            } finally {
+                if (ctx != null)
+                    try {
+                        ctx.close();
+                    } catch (Exception ex1) {
+                        ; // swallow
+                        __log.error("Error closing JNDI connection.", ex1);
+                    }
+            }
+        } finally {
+            Thread.currentThread().setContextClassLoader(old);
+        }
+
+    }
+
+    private String guessDialect(DataSource dataSource) throws Exception {
+        String dialect = null;
+        // Open a connection and use that connection to figure out database
+        // product name/version number in order to decide which Hibernate
+        // dialect to use.
+        Connection conn = dataSource.getConnection();
+        try {
+            DatabaseMetaData metaData = conn.getMetaData();
+            if (metaData != null) {
+                String dbProductName = metaData.getDatabaseProductName();
+                int dbMajorVer = metaData.getDatabaseMajorVersion();
+                __log.info("Using database " + dbProductName + " major version "
+                        + dbMajorVer);
+                DialectFactory.DatabaseDialectMapper mapper = (DialectFactory.DatabaseDialectMapper)
HIBERNATE_DIALECTS
+                        .get(dbProductName);
+                if (mapper != null) {
+                    dialect = mapper.getDialectClass(dbMajorVer);
+                } else {
+                    Dialect hbDialect = DialectFactory.determineDialect(
+                            dbProductName, dbMajorVer);
+                    if (hbDialect != null)
+                        dialect = hbDialect.getClass().getName();
+                }
+            }
+        } finally {
+            conn.close();
+        }
+
+        if (dialect == null) {
+            __log
+                    .info("Cannot determine hibernate dialect for this database: using the
default one.");
+            dialect = DEFAULT_HIBERNATE_DIALECT;
+        }
+
+        assert dialect != null;
+
+        return dialect;
+
+    }
+
+    private static final HashMap<String, DialectFactory.VersionInsensitiveMapper> HIBERNATE_DIALECTS
= new HashMap<String, DialectFactory.VersionInsensitiveMapper>();
+
+    static {
+        // Hibernate has a nice table that resolves the dialect from the database
+        // product name,
+        // but doesn't include all the drivers. So this is supplementary, and some
+        // day in the
+        // future they'll add more drivers and we can get rid of this.
+        // Drivers already recognized by Hibernate:
+        // HSQL Database Engine
+        // DB2/NT
+        // MySQL
+        // PostgreSQL
+        // Microsoft SQL Server Database, Microsoft SQL Server
+        // Sybase SQL Server
+        // Informix Dynamic Server
+        // Oracle 8 and Oracle >8
+        HIBERNATE_DIALECTS.put("Apache Derby",
+                new DialectFactory.VersionInsensitiveMapper(
+                        "org.hibernate.dialect.DerbyDialect"));
+    }
 
 }



Mime
View raw message