You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2008/06/18 22:48:05 UTC
svn commit: r669288 - in
/servicemix/components/common/trunk/servicemix-common: ./
src/main/java/org/apache/servicemix/common/
src/main/java/org/apache/servicemix/common/endpoints/
src/main/java/org/apache/servicemix/common/osgi/ src/main/java/org/apac...
Author: gnodet
Date: Wed Jun 18 13:48:04 2008
New Revision: 669288
URL: http://svn.apache.org/viewvc?rev=669288&view=rev
Log:
SM-1412: Reduce dependency on servicemix-core
Added:
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/JbiConstants.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/
- copied from r669166, servicemix/smx3/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/components/varscheduler/
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/DOMUtil.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/URIResolver.java
Modified:
servicemix/components/common/trunk/servicemix-common/pom.xml
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Container.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ResolvedEndpoint.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ConsumerEndpoint.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/PollingEndpoint.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ProviderEndpoint.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointExporter.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/ScheduleIterator.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/Scheduler.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/SchedulerTask.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java
servicemix/components/common/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/NewTransactionsTest.java
Modified: servicemix/components/common/trunk/servicemix-common/pom.xml
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/pom.xml?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/pom.xml (original)
+++ servicemix/components/common/trunk/servicemix-common/pom.xml Wed Jun 18 13:48:04 2008
@@ -41,11 +41,27 @@
</dependency>
<dependency>
<groupId>org.apache.servicemix</groupId>
+ <artifactId>servicemix-services</artifactId>
+ <version>${servicemix-version}</version>
+ <scope>provided</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.servicemix</groupId>
<artifactId>servicemix-core</artifactId>
<version>${servicemix-version}</version>
<scope>provided</scope>
+ <optional>true</optional>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xbean</groupId>
+ <artifactId>xbean-spring</artifactId>
+ <version>3.4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.xbean</groupId>
+ <artifactId>xbean-classloader</artifactId>
+ <version>3.4.1</version>
</dependency>
-
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
@@ -106,7 +122,7 @@
<excludes>
<!-- exclude abstract test cases -->
<exclude>**/Abstract*.*</exclude>
- <exclude>**/TransactionsTest.*</exclude>
+ <exclude>**/NewTransactionsTest.*</exclude>
</excludes>
</configuration>
</plugin>
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/AsyncBaseLifeCycle.java Wed Jun 18 13:48:04 2008
@@ -38,7 +38,6 @@
import javax.xml.namespace.QName;
import org.apache.commons.logging.Log;
-import org.apache.servicemix.JbiConstants;
import org.apache.servicemix.executors.Executor;
import org.apache.servicemix.executors.ExecutorFactory;
import org.apache.servicemix.executors.impl.ExecutorFactoryImpl;
@@ -102,6 +101,10 @@
setComponent(component);
}
+ public Container getContainer() {
+ return container;
+ }
+
protected void setComponent(ServiceMixComponent component) {
this.component = component;
this.logger = component.getLogger();
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Container.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Container.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Container.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/Container.java Wed Jun 18 13:48:04 2008
@@ -42,6 +42,14 @@
public abstract boolean handleTransactions();
+ public ClassLoader getSharedLibraryClassLoader(String name) {
+ throw new UnsupportedOperationException("Can not access shared libraries");
+ }
+
+ public ClassLoader getComponentClassLoader(String name) {
+ throw new UnsupportedOperationException("Can not access components");
+ }
+
public static Container detect(ComponentContext context) {
try {
String clName = context.getClass().getName();
@@ -62,13 +70,13 @@
public Smx3Container(ComponentContext context) {
super(context);
try {
- Method getContainerMth = context.getClass().getMethod("getContainer", new Class[0]);
+ Method getContainerMth = context.getClass().getMethod("getContainer");
container = getContainerMth.invoke(context, new Object[0]);
} catch (Throwable t) {
}
try {
- Method isUseNewTransactionModelMth = container.getClass().getMethod("isUseNewTransactionModel", new Class[0]);
- Boolean b = (Boolean) isUseNewTransactionModelMth.invoke(container, new Object[0]);
+ Method isUseNewTransactionModelMth = container.getClass().getMethod("isUseNewTransactionModel");
+ Boolean b = (Boolean) isUseNewTransactionModelMth.invoke(container);
handleTransactions = !b;
} catch (Throwable t) {
handleTransactions = true;
@@ -83,6 +91,27 @@
public Object getSmx3Container() {
return container;
}
+
+ public ClassLoader getSharedLibraryClassLoader(String name) {
+ try {
+ Object registry = container.getClass().getMethod("getRegistry").invoke(container);
+ Object sl = registry.getClass().getMethod("getSharedLibrary", String.class).invoke(registry, name);
+ return (ClassLoader) sl.getClass().getMethod("getClassLoader").invoke(sl);
+ } catch (Throwable t) {
+ return null;
+ }
+ }
+
+ public ClassLoader getComponentClassLoader(String name) {
+ try {
+ Object registry = container.getClass().getMethod("getRegistry").invoke(container);
+ Object mbean = registry.getClass().getMethod("getComponent", String.class).invoke(registry, name);
+ Object cmp = mbean.getClass().getMethod("getComponent").invoke(mbean);
+ return cmp.getClass().getClassLoader();
+ } catch (Throwable t) {
+ return null;
+ }
+ }
}
public static class Smx4Container extends Container {
Added: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/JbiConstants.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/JbiConstants.java?rev=669288&view=auto
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/JbiConstants.java (added)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/JbiConstants.java Wed Jun 18 13:48:04 2008
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.common;
+
+public interface JbiConstants {
+
+ String SEND_SYNC = "javax.jbi.messaging.sendSync";
+
+ String PROTOCOL_TYPE = "javax.jbi.messaging.protocol.type";
+
+ String PROTOCOL_HEADERS = "javax.jbi.messaging.protocol.headers";
+
+ String SECURITY_SUBJECT = "javax.jbi.security.subject";
+
+ String SOAP_HEADERS = "org.apache.servicemix.soap.headers";
+
+ String PERSISTENT_PROPERTY_NAME = "org.apache.servicemix.persistent";
+
+ String DATESTAMP_PROPERTY_NAME = "org.apache.servicemix.datestamp";
+
+ String FLOW_PROPERTY_NAME = "org.apache.servicemix.flow";
+
+ String STATELESS_CONSUMER = "org.apache.servicemix.consumer.stateless";
+
+ String STATELESS_PROVIDER = "org.apache.servicemix.provider.stateless";
+
+ String SENDER_ENDPOINT = "org.apache.servicemix.senderEndpoint";
+
+ String HTTP_DESTINATION_URI = "org.apache.servicemix.http.destination.uri";
+
+ /**
+ * This property should be set when a consumer endpoint creates an exchange
+ * related to another provider exchange. The value of the property should be
+ * set to the value of this property in the provider exchange, or to the id
+ * of the provider exchange if the property does not exist.
+ */
+ String CORRELATION_ID = "org.apache.servicemix.correlationId";
+
+}
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ResolvedEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ResolvedEndpoint.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ResolvedEndpoint.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ResolvedEndpoint.java Wed Jun 18 13:48:04 2008
@@ -17,8 +17,6 @@
*/
package org.apache.servicemix.common;
-import org.apache.servicemix.jbi.resolver.URIResolver;
-import org.apache.servicemix.jbi.util.DOMUtil;
import org.w3c.dom.DocumentFragment;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -27,6 +25,9 @@
import javax.jbi.servicedesc.ServiceEndpoint;
import javax.xml.namespace.QName;
+import org.apache.servicemix.common.util.URIResolver;
+import org.apache.servicemix.common.util.DOMUtil;
+
/**
* A default implementation of a resolved endpoint
*/
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/ServiceMixComponent.java Wed Jun 18 13:48:04 2008
@@ -54,6 +54,11 @@
public ComponentContext getComponentContext();
/**
+ * @return the JBI container
+ */
+ public Container getContainer();
+
+ /**
* @return the servicemix 3 container if deployed into it
*/
public Object getSmx3Container();
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ConsumerEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ConsumerEndpoint.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ConsumerEndpoint.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ConsumerEndpoint.java Wed Jun 18 13:48:04 2008
@@ -27,7 +27,7 @@
import org.apache.servicemix.common.ExternalEndpoint;
import org.apache.servicemix.common.ServiceMixComponent;
import org.apache.servicemix.common.ServiceUnit;
-import org.apache.servicemix.jbi.resolver.URIResolver;
+import org.apache.servicemix.common.util.URIResolver;
public abstract class ConsumerEndpoint extends SimpleEndpoint {
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/PollingEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/PollingEndpoint.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/PollingEndpoint.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/PollingEndpoint.java Wed Jun 18 13:48:04 2008
@@ -24,9 +24,9 @@
import org.apache.servicemix.common.DefaultComponent;
import org.apache.servicemix.common.ServiceUnit;
-import org.apache.servicemix.components.varscheduler.ScheduleIterator;
-import org.apache.servicemix.components.varscheduler.Scheduler;
-import org.apache.servicemix.components.varscheduler.SchedulerTask;
+import org.apache.servicemix.common.scheduler.ScheduleIterator;
+import org.apache.servicemix.common.scheduler.Scheduler;
+import org.apache.servicemix.common.scheduler.SchedulerTask;
import org.apache.servicemix.executors.Executor;
/**
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ProviderEndpoint.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ProviderEndpoint.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ProviderEndpoint.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/endpoints/ProviderEndpoint.java Wed Jun 18 13:48:04 2008
@@ -26,7 +26,7 @@
import javax.jbi.servicedesc.ServiceEndpoint;
import javax.xml.namespace.QName;
-import org.apache.servicemix.JbiConstants;
+import org.apache.servicemix.common.JbiConstants;
import org.apache.servicemix.common.DefaultComponent;
import org.apache.servicemix.common.ServiceUnit;
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointExporter.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointExporter.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointExporter.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/osgi/EndpointExporter.java Wed Jun 18 13:48:04 2008
@@ -20,12 +20,12 @@
import java.util.Properties;
import java.util.Collection;
+import org.apache.servicemix.common.Endpoint;
+import org.osgi.framework.BundleContext;
import org.springframework.osgi.context.BundleContextAware;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.ApplicationContext;
-import org.osgi.framework.BundleContext;
-import org.apache.servicemix.common.Endpoint;
public class EndpointExporter implements BundleContextAware, ApplicationContextAware, InitializingBean {
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/ScheduleIterator.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/ScheduleIterator.java?rev=669288&r1=669166&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/ScheduleIterator.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/ScheduleIterator.java Wed Jun 18 13:48:04 2008
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.components.varscheduler;
+package org.apache.servicemix.common.scheduler;
import java.util.Date;
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/Scheduler.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/Scheduler.java?rev=669288&r1=669166&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/Scheduler.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/Scheduler.java Wed Jun 18 13:48:04 2008
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.components.varscheduler;
+package org.apache.servicemix.common.scheduler;
import java.util.Date;
import java.util.Timer;
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/SchedulerTask.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/SchedulerTask.java?rev=669288&r1=669166&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/SchedulerTask.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/scheduler/SchedulerTask.java Wed Jun 18 13:48:04 2008
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.servicemix.components.varscheduler;
+package org.apache.servicemix.common.scheduler;
import java.util.TimerTask;
Added: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/DOMUtil.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/DOMUtil.java?rev=669288&view=auto
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/DOMUtil.java (added)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/DOMUtil.java Wed Jun 18 13:48:04 2008
@@ -0,0 +1,252 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.common.util;
+
+import java.io.StringWriter;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerException;
+import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.stream.StreamResult;
+
+import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * A collection of W3C DOM helper methods
+ *
+ * @version $Revision: 564607 $
+ */
+public final class DOMUtil {
+
+ private static final Log LOG = LogFactory.getLog(DOMUtil.class);
+ private static DocumentBuilderFactory dbf;
+ private static Queue builders = new ConcurrentLinkedQueue();
+
+
+ private DOMUtil() {
+ }
+
+ /**
+ * Returns the text of the element
+ */
+ public static String getElementText(Element element) {
+ StringBuffer buffer = new StringBuffer();
+ NodeList nodeList = element.getChildNodes();
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node node = nodeList.item(i);
+ if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) {
+ buffer.append(node.getNodeValue());
+ }
+ }
+ return buffer.toString();
+ }
+
+ /**
+ * Moves the content of the given element to the given element
+ */
+ public static void moveContent(Element from, Element to) {
+ // lets move the child nodes across
+ NodeList childNodes = from.getChildNodes();
+ while (childNodes.getLength() > 0) {
+ Node node = childNodes.item(0);
+ from.removeChild(node);
+ to.appendChild(node);
+ }
+ }
+
+ /**
+ * Copy the attribues on one element to the other
+ */
+ public static void copyAttributes(Element from, Element to) {
+ // lets copy across all the remainingattributes
+ NamedNodeMap attributes = from.getAttributes();
+ for (int i = 0; i < attributes.getLength(); i++) {
+ Attr node = (Attr) attributes.item(i);
+ to.setAttributeNS(node.getNamespaceURI(), node.getName(), node.getValue());
+ }
+ }
+
+ /**
+ * A helper method useful for debugging and logging which will convert the given DOM node into XML text
+ */
+ public static String asXML(Node node) throws TransformerException {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ StringWriter buffer = new StringWriter();
+ transformer.transform(new DOMSource(node), new StreamResult(buffer));
+ return buffer.toString();
+ }
+
+ /**
+ * A helper method useful for debugging and logging which will convert the given DOM node into XML text
+ */
+ public static String asIndentedXML(Node node) throws TransformerException {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer();
+ transformer.setOutputProperty(OutputKeys.INDENT, "yes");
+ StringWriter buffer = new StringWriter();
+ transformer.transform(new DOMSource(node), new StreamResult(buffer));
+ return buffer.toString();
+ }
+
+ /**
+ * Adds the child element with the given text
+ */
+ public static void addChildElement(Element element, String name, Object textValue) {
+ Document document = element.getOwnerDocument();
+ Element child = document.createElement(name);
+ element.appendChild(child);
+ if (textValue != null) {
+ String text = textValue.toString();
+ child.appendChild(document.createTextNode(text));
+ }
+ }
+
+ /**
+ * Creates a QName instance from the given namespace context for the given qualifiedName
+ *
+ * @param element the element to use as the namespace context
+ * @param qualifiedName the fully qualified name
+ * @return the QName which matches the qualifiedName
+ */
+ public static QName createQName(Element element, String qualifiedName) {
+ int index = qualifiedName.indexOf(':');
+ if (index >= 0) {
+ String prefix = qualifiedName.substring(0, index);
+ String localName = qualifiedName.substring(index + 1);
+ String uri = recursiveGetAttributeValue(element, "xmlns:" + prefix);
+ return new QName(uri, localName, prefix);
+ } else {
+ String uri = recursiveGetAttributeValue(element, "xmlns");
+ if (uri != null) {
+ return new QName(uri, qualifiedName);
+ }
+ return new QName(qualifiedName);
+ }
+ }
+
+ /**
+ * Recursive method to find a given attribute value
+ */
+ public static String recursiveGetAttributeValue(Element element, String attributeName) {
+ String answer = null;
+ try {
+ answer = element.getAttribute(attributeName);
+ } catch (Exception e) {
+ if (LOG.isTraceEnabled()) {
+ LOG.trace("Caught exception looking up attribute: " + attributeName + " on element: " + element + ". Cause: " + e, e);
+ }
+ }
+ if (answer == null || answer.length() == 0) {
+ Node parentNode = element.getParentNode();
+ if (parentNode instanceof Element) {
+ return recursiveGetAttributeValue((Element) parentNode, attributeName);
+ }
+ }
+ return answer;
+ }
+
+ /**
+ * Get the first child element
+ * @param parent
+ * @return
+ */
+ public static Element getFirstChildElement(Node parent) {
+ NodeList childs = parent.getChildNodes();
+ for (int i = 0; i < childs.getLength(); i++) {
+ Node child = childs.item(i);
+ if (child instanceof Element) {
+ return (Element) child;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Get the next sibling element
+ * @param el
+ * @return
+ */
+ public static Element getNextSiblingElement(Element el) {
+ for (Node n = el.getNextSibling(); n != null; n = n.getNextSibling()) {
+ if (n instanceof Element) {
+ return (Element) n;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Build a QName from the element name
+ * @param el
+ * @return
+ */
+ public static QName getQName(Element el) {
+ if (el == null) {
+ return null;
+ } else if (el.getPrefix() != null) {
+ return new QName(el.getNamespaceURI(), el.getLocalName(), el.getPrefix());
+ } else {
+ return new QName(el.getNamespaceURI(), el.getLocalName());
+ }
+ }
+
+ public static DocumentBuilder getBuilder() throws ParserConfigurationException {
+ DocumentBuilder builder = (DocumentBuilder) builders.poll();
+ if (builder == null) {
+ if (dbf == null) {
+ dbf = DocumentBuilderFactory.newInstance();
+ dbf.setNamespaceAware(true);
+ }
+ builder = dbf.newDocumentBuilder();
+ }
+ return builder;
+ }
+
+ public static void releaseBuilder(DocumentBuilder builder) {
+ if (builder != null) {
+ builders.add(builder);
+ }
+ }
+
+ /**
+ * Return a new document, ready to populate.
+ * @return
+ * @throws ParserConfigurationException
+ */
+ public static Document newDocument() throws ParserConfigurationException {
+ DocumentBuilder builder = getBuilder();
+ Document doc = builder.newDocument();
+ releaseBuilder(builder);
+ return doc;
+ }
+
+}
Added: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/URIResolver.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/URIResolver.java?rev=669288&view=auto
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/URIResolver.java (added)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/util/URIResolver.java Wed Jun 18 13:48:04 2008
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.servicemix.common.util;
+
+import javax.jbi.JBIException;
+import javax.jbi.component.ComponentContext;
+import javax.jbi.messaging.MessageExchange;
+import javax.jbi.servicedesc.ServiceEndpoint;
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+public class URIResolver {
+
+ private static final String WSA_NAMESPACE = "http://www.w3.org/2005/08/addressing";
+ private static final String WSA_PREFIX = "wsa";
+ private static final String WSA_EL_ADDRESS = "Address";
+
+ /**
+ * The uri to resolve
+ */
+ private String uri;
+
+ public URIResolver() {
+ }
+
+ public URIResolver(String uri) {
+ this.uri = uri;
+ }
+
+ protected JBIException createServiceUnavailableException() {
+ return new JBIException("Unable to resolve uri: " + uri);
+ }
+
+ public ServiceEndpoint[] resolveAvailableEndpoints(ComponentContext context,
+ MessageExchange exchange) throws JBIException {
+ if (uri.startsWith("interface:")) {
+ String u = this.uri.substring(10);
+ String[] parts = split2(u);
+ return context.getEndpoints(new QName(parts[0], parts[1]));
+ } else if (uri.startsWith("operation:")) {
+ // ignore operation
+ String u = this.uri.substring(10);
+ String[] parts = split3(u);
+ return context.getEndpoints(new QName(parts[0], parts[1]));
+ } else if (uri.startsWith("service:")) {
+ String u = this.uri.substring(8);
+ String[] parts = split2(u);
+ return context.getEndpointsForService(new QName(parts[0], parts[1]));
+ } else if (uri.startsWith("endpoint:")) {
+ String u = this.uri.substring(9);
+ String[] parts = split3(u);
+ ServiceEndpoint se = context.getEndpoint(new QName(parts[0], parts[1]), parts[2]);
+ if (se != null) {
+ return new ServiceEndpoint[] {se };
+ }
+ // Try an EPR resolution
+ } else {
+ DocumentFragment epr = createWSAEPR(uri);
+ ServiceEndpoint se = context.resolveEndpointReference(epr);
+ if (se != null) {
+ return new ServiceEndpoint[] {se };
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @return the uri
+ */
+ public String getUri() {
+ return uri;
+ }
+
+ /**
+ * @param uri the uri to set
+ */
+ public void setUri(String uri) {
+ this.uri = uri;
+ }
+
+ public static DocumentFragment createWSAEPR(String uri) {
+ Document doc;
+ try {
+ doc = DOMUtil.newDocument();
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ DocumentFragment epr = doc.createDocumentFragment();
+ Element root = doc.createElement("epr");
+ Element address = doc.createElementNS(WSA_NAMESPACE, WSA_PREFIX + ":" + WSA_EL_ADDRESS);
+ Text txt = doc.createTextNode(uri);
+ address.appendChild(txt);
+ root.appendChild(address);
+ epr.appendChild(root);
+ return epr;
+ }
+
+ /**
+ * Configure a JBI exchange with the given URI as the target
+ *
+ * @param exchange the exchange to configure
+ * @param context a component context used to resolve endpoints
+ * @param uri the target uri
+ */
+ public static void configureExchange(MessageExchange exchange, ComponentContext context, String uri) {
+ if (exchange == null) {
+ throw new NullPointerException("exchange is null");
+ }
+ if (context == null) {
+ throw new NullPointerException("context is null");
+ }
+ if (uri == null) {
+ throw new NullPointerException("uri is null");
+ }
+ if (uri.startsWith("interface:")) {
+ String uri2 = uri.substring(10);
+ String[] parts = URIResolver.split2(uri2);
+ exchange.setInterfaceName(new QName(parts[0], parts[1]));
+ } else if (uri.startsWith("operation:")) {
+ String uri2 = uri.substring(10);
+ String[] parts = URIResolver.split3(uri2);
+ exchange.setInterfaceName(new QName(parts[0], parts[1]));
+ exchange.setOperation(new QName(parts[0], parts[2]));
+ } else if (uri.startsWith("service:")) {
+ String uri2 = uri.substring(8);
+ String[] parts = URIResolver.split2(uri2);
+ exchange.setService(new QName(parts[0], parts[1]));
+ } else if (uri.startsWith("endpoint:")) {
+ String uri2 = uri.substring(9);
+ String[] parts = URIResolver.split3(uri2);
+ ServiceEndpoint se = context.getEndpoint(new QName(parts[0], parts[1]), parts[2]);
+ exchange.setEndpoint(se);
+ } else {
+ DocumentFragment epr = URIResolver.createWSAEPR(uri);
+ ServiceEndpoint se = context.resolveEndpointReference(epr);
+ exchange.setEndpoint(se);
+ }
+ }
+
+ public static String[] split3(String uri) {
+ char sep;
+ uri = uri.trim();
+ if (uri.indexOf('/') > 0) {
+ sep = '/';
+ } else {
+ sep = ':';
+ }
+ int idx1 = uri.lastIndexOf(sep);
+ int idx2 = uri.lastIndexOf(sep, idx1 - 1);
+ if (idx1 < 0 || idx2 < 0) {
+ throw new IllegalArgumentException("Bad syntax: expected [part0][sep][part1][sep][part2]");
+ }
+ String epName = uri.substring(idx1 + 1);
+ String svcName = uri.substring(idx2 + 1, idx1);
+ String nsUri = uri.substring(0, idx2);
+ return new String[] {nsUri, svcName, epName };
+ }
+
+ public static String[] split2(String uri) {
+ char sep;
+ uri = uri.trim();
+ if (uri.indexOf('/') > 0) {
+ sep = '/';
+ } else {
+ sep = ':';
+ }
+ int idx1 = uri.lastIndexOf(sep);
+ if (idx1 < 0) {
+ throw new IllegalArgumentException("Bad syntax: expected [part0][sep][part1]");
+ }
+ String svcName = uri.substring(idx1 + 1);
+ String nsUri = uri.substring(0, idx1);
+ return new String[] {nsUri, svcName };
+ }
+
+}
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/AbstractXBeanDeployer.java Wed Jun 18 13:48:04 2008
@@ -32,8 +32,6 @@
import org.apache.servicemix.common.EndpointComponentContext;
import org.apache.servicemix.common.ServiceMixComponent;
import org.apache.servicemix.common.ServiceUnit;
-import org.apache.servicemix.jbi.container.JBIContainer;
-import org.apache.servicemix.jbi.framework.ComponentContextImpl;
import org.apache.xbean.spring.context.FileSystemXmlApplicationContext;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
@@ -139,11 +137,7 @@
}
protected List getXmlPreProcessors(String serviceUnitRootPath) {
- JBIContainer container = null;
- try {
- container = ((ComponentContextImpl) component.getComponentContext()).getContainer();
- } catch (Throwable t) { }
- ClassLoaderXmlPreprocessor classLoaderXmlPreprocessor = new ClassLoaderXmlPreprocessor(new File(serviceUnitRootPath), container);
+ ClassLoaderXmlPreprocessor classLoaderXmlPreprocessor = new ClassLoaderXmlPreprocessor(new File(serviceUnitRootPath), component);
return Collections.singletonList(classLoaderXmlPreprocessor);
}
Modified: servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/main/java/org/apache/servicemix/common/xbean/ClassLoaderXmlPreprocessor.java Wed Jun 18 13:48:04 2008
@@ -27,10 +27,9 @@
import javax.xml.parsers.DocumentBuilder;
-import org.apache.servicemix.jbi.container.JBIContainer;
-import org.apache.servicemix.jbi.framework.SharedLibrary;
-import org.apache.servicemix.jbi.framework.ComponentMBeanImpl;
-import org.apache.servicemix.jbi.jaxp.SourceTransformer;
+import org.apache.servicemix.common.ServiceMixComponent;
+import org.apache.servicemix.common.Container;
+import org.apache.servicemix.common.util.DOMUtil;
import org.apache.xbean.classloader.JarFileClassLoader;
import org.apache.xbean.spring.context.SpringApplicationContext;
import org.apache.xbean.spring.context.SpringXmlPreprocessor;
@@ -53,15 +52,15 @@
public static final String LIB_DIR = "/lib";
private final File root;
- private final JBIContainer container;
+ private final ServiceMixComponent component;
public ClassLoaderXmlPreprocessor(File root) {
this(root, null);
}
- public ClassLoaderXmlPreprocessor(File root, JBIContainer container) {
+ public ClassLoaderXmlPreprocessor(File root, ServiceMixComponent component) {
this.root = root;
- this.container = container;
+ this.component = component;
}
public void preprocess(SpringApplicationContext applicationContext, XmlBeanDefinitionReader reader, Document document) {
@@ -72,12 +71,15 @@
// Check if a classpath.xml file exists in the root of the SU
URL url = getResource(CLASSPATH_XML);
if (url != null) {
+ DocumentBuilder builder = null;
try {
- DocumentBuilder builder = new SourceTransformer().createDocumentBuilder();
+ builder = DOMUtil.getBuilder();
Document doc = builder.parse(url.toString());
classLoader = getClassLoader(applicationContext, reader, doc);
} catch (Exception e) {
throw new FatalBeanException("Unable to load classpath.xml file", e);
+ } finally {
+ DOMUtil.releaseBuilder(builder);
}
} else {
try {
@@ -187,7 +189,7 @@
String library = ((Text) locationElement.getFirstChild()).getData().trim();
sls.add(library);
}
- if (sls.size() > 0 && container == null) {
+ if (sls.size() > 0 && component.getContainer().getType() != Container.Type.ServiceMix3) {
throw new IllegalStateException("Can not reference shared libraries if the component is not deployed in ServiceMix");
}
@@ -199,7 +201,7 @@
String component = ((Text) locationElement.getFirstChild()).getData().trim();
components.add(component);
}
- if (components.size() > 0 && container == null) {
+ if (components.size() > 0 && component.getContainer().getType() != Container.Type.ServiceMix3) {
throw new IllegalStateException("Can not reference other components if the component is not deployed in ServiceMix");
}
@@ -223,18 +225,18 @@
List<ClassLoader> parents = new ArrayList<ClassLoader>();
parents.add(getParentClassLoader(applicationContext));
for (String library : sls) {
- SharedLibrary sl = container.getRegistry().getSharedLibrary(library);
- if (sl == null) {
+ ClassLoader cl = this.component.getContainer().getSharedLibraryClassLoader(library);
+ if (cl == null) {
throw new IllegalStateException("No such shared library: " + library);
}
- parents.add(sl.getClassLoader());
+ parents.add(cl);
}
for (String component : components) {
- ComponentMBeanImpl componentMBean = container.getRegistry().getComponent(component);
- if (componentMBean == null) {
- throw new IllegalStateException("No such component: " + componentMBean);
+ ClassLoader cl = this.component.getContainer().getComponentClassLoader(component);
+ if (cl == null) {
+ throw new IllegalStateException("No such component: " + component);
}
- parents.add(componentMBean.getComponent().getClass().getClassLoader());
+ parents.add(cl);
}
classLoader = new JarFileClassLoader(applicationContext.getDisplayName(),
urls,
Modified: servicemix/components/common/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/NewTransactionsTest.java
URL: http://svn.apache.org/viewvc/servicemix/components/common/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/NewTransactionsTest.java?rev=669288&r1=669287&r2=669288&view=diff
==============================================================================
--- servicemix/components/common/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/NewTransactionsTest.java (original)
+++ servicemix/components/common/trunk/servicemix-common/src/test/java/org/apache/servicemix/common/NewTransactionsTest.java Wed Jun 18 13:48:04 2008
@@ -47,6 +47,7 @@
public class NewTransactionsTest extends TestCase {
+ /*
protected JBIContainer jbi;
protected TransactionManager txManager;
protected TestComponent component;
@@ -280,5 +281,6 @@
}
}
}
+ */
}