You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2010/05/28 09:52:36 UTC
svn commit: r949127 [4/5] - in /camel/trunk: components/
components/camel-blueprint/
components/camel-blueprint/src/main/java/org/apache/camel/blueprint/
components/camel-blueprint/src/main/java/org/apache/camel/blueprint/handler/
components/camel-blue...
Added: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelThreadPoolFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelThreadPoolFactoryBean.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelThreadPoolFactoryBean.java (added)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/AbstractCamelThreadPoolFactoryBean.java Fri May 28 07:52:33 2010
@@ -0,0 +1,179 @@
+/**
+ * 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.camel.core.xml;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.RejectedExecutionHandler;
+import java.util.concurrent.TimeUnit;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
+import org.apache.camel.ThreadPoolRejectedPolicy;
+import org.apache.camel.builder.xml.TimeUnitAdapter;
+import org.apache.camel.model.IdentifiedType;
+
+import static org.apache.camel.util.ObjectHelper.notNull;
+
+/**
+ * A factory which instantiates {@link java.util.concurrent.ExecutorService} objects
+ *
+ * @version $Revision: 925208 $
+ */
+@XmlAccessorType(XmlAccessType.FIELD)
+public abstract class AbstractCamelThreadPoolFactoryBean extends IdentifiedType implements CamelContextAware {
+
+ @XmlAttribute(required = true)
+ private Integer poolSize;
+ @XmlAttribute
+ private Integer maxPoolSize;
+ @XmlAttribute
+ private Long keepAliveTime = 60L;
+ @XmlAttribute
+ @XmlJavaTypeAdapter(TimeUnitAdapter.class)
+ private TimeUnit timeUnit = TimeUnit.SECONDS;
+ @XmlAttribute
+ private Integer maxQueueSize = -1;
+ @XmlAttribute
+ private ThreadPoolRejectedPolicy rejectedPolicy = ThreadPoolRejectedPolicy.CallerRuns;
+ @XmlAttribute(required = true)
+ private String threadName;
+ @XmlAttribute
+ private Boolean daemon = Boolean.TRUE;
+ @XmlAttribute
+ private String camelContextId;
+ @XmlTransient
+ private CamelContext camelContext;
+
+ public Object getObject() throws Exception {
+ if (camelContext == null && camelContextId != null) {
+ camelContext = getCamelContextWithId(camelContextId);
+ }
+
+ notNull(camelContext, "camelContext");
+ if (poolSize == null || poolSize <= 0) {
+ throw new IllegalArgumentException("PoolSize must be a positive number");
+ }
+
+ int max = getMaxPoolSize() != null ? getMaxPoolSize() : getPoolSize();
+ RejectedExecutionHandler rejected = null;
+ if (rejectedPolicy != null) {
+ rejected = rejectedPolicy.asRejectedExecutionHandler();
+ }
+
+ ExecutorService answer = camelContext.getExecutorServiceStrategy().newThreadPool(getId(), getThreadName(), getPoolSize(), max,
+ getKeepAliveTime(), getTimeUnit(), getMaxQueueSize(), rejected, isDaemon());
+ return answer;
+ }
+
+ protected abstract CamelContext getCamelContextWithId(String camelContextId);
+
+ public Class getObjectType() {
+ return ExecutorService.class;
+ }
+
+ public boolean isSingleton() {
+ return true;
+ }
+
+ public Integer getPoolSize() {
+ return poolSize;
+ }
+
+ public void setPoolSize(Integer poolSize) {
+ this.poolSize = poolSize;
+ }
+
+ public Integer getMaxPoolSize() {
+ return maxPoolSize;
+ }
+
+ public void setMaxPoolSize(Integer maxPoolSize) {
+ this.maxPoolSize = maxPoolSize;
+ }
+
+ public Long getKeepAliveTime() {
+ return keepAliveTime;
+ }
+
+ public void setKeepAliveTime(Long keepAliveTime) {
+ this.keepAliveTime = keepAliveTime;
+ }
+
+ public TimeUnit getTimeUnit() {
+ return timeUnit;
+ }
+
+ public void setTimeUnit(TimeUnit timeUnit) {
+ this.timeUnit = timeUnit;
+ }
+
+ public Integer getMaxQueueSize() {
+ return maxQueueSize;
+ }
+
+ public void setMaxQueueSize(Integer maxQueueSize) {
+ this.maxQueueSize = maxQueueSize;
+ }
+
+ public ThreadPoolRejectedPolicy getRejectedPolicy() {
+ return rejectedPolicy;
+ }
+
+ public void setRejectedPolicy(ThreadPoolRejectedPolicy rejectedPolicy) {
+ this.rejectedPolicy = rejectedPolicy;
+ }
+
+ public String getThreadName() {
+ return threadName;
+ }
+
+ public void setThreadName(String threadName) {
+ this.threadName = threadName;
+ }
+
+ public Boolean isDaemon() {
+ return daemon;
+ }
+
+ public void setDaemon(Boolean daemon) {
+ this.daemon = daemon;
+ }
+
+ public String getCamelContextId() {
+ return camelContextId;
+ }
+
+ public void setCamelContextId(String camelContextId) {
+ this.camelContextId = camelContextId;
+ }
+
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
+ }
+
+}
\ No newline at end of file
Added: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelJMXAgentDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelJMXAgentDefinition.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelJMXAgentDefinition.java (added)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelJMXAgentDefinition.java Fri May 28 07:52:33 2010
@@ -0,0 +1,210 @@
+/**
+ * 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.camel.core.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.ManagementStatisticsLevel;
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * The JAXB type class for the configuration of jmxAgent
+ *
+ * @version $Revision: 911871 $
+ */
+@XmlRootElement(name = "jmxAgent")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelJMXAgentDefinition extends IdentifiedType {
+
+ /**
+ * Disable JMI (default false)
+ */
+ @XmlAttribute(required = false)
+ private String disabled = "false";
+
+ /**
+ * Only register processor if a custom id was defined for it.
+ */
+ @XmlAttribute(required = false)
+ private String onlyRegisterProcessorWithCustomId = "false";
+
+ /**
+ * RMI connector registry port (default 1099)
+ */
+ @XmlAttribute(required = false)
+ private String registryPort;
+
+ /**
+ * RMI connector server port (default -1 not used)
+ */
+ @XmlAttribute(required = false)
+ private String connectorPort;
+
+ /**
+ * MBean server default domain name (default org.apache.camel)
+ */
+ @XmlAttribute(required = false)
+ private String mbeanServerDefaultDomain;
+
+ /**
+ * MBean object domain name (default org.apache.camel)
+ */
+ @XmlAttribute(required = false)
+ private String mbeanObjectDomainName;
+
+ /**
+ * JMX Service URL path (default /jmxrmi)
+ */
+ @XmlAttribute(required = false)
+ private String serviceUrlPath;
+
+ /**
+ * A flag that indicates whether the agent should be created
+ */
+ @XmlAttribute(required = false)
+ private String createConnector = "true";
+
+ /**
+ * A flag that indicates whether the platform mbean server should be used
+ */
+ @XmlAttribute(required = false)
+ private String usePlatformMBeanServer = "true";
+
+ /**
+ * Level of granularity for performance statistics enabled
+ */
+ @XmlAttribute(required = false)
+ private ManagementStatisticsLevel statisticsLevel = ManagementStatisticsLevel.All;
+
+ public String getDisabled() {
+ return disabled;
+ }
+
+ public boolean isAgentDisabled() {
+ return disabled != null && Boolean.parseBoolean(disabled);
+ }
+
+ public void setDisabled(String disabled) {
+ this.disabled = disabled;
+ }
+
+ public String getOnlyRegisterProcessorWithCustomId() {
+ return onlyRegisterProcessorWithCustomId;
+ }
+
+ public void setOnlyRegisterProcessorWithCustomId(String onlyRegisterProcessorWithCustomId) {
+ this.onlyRegisterProcessorWithCustomId = onlyRegisterProcessorWithCustomId;
+ }
+
+ public String getRegistryPort() {
+ return registryPort;
+ }
+
+ public void setRegistryPort(String registryPort) {
+ this.registryPort = registryPort;
+ }
+
+ public String getConnectorPort() {
+ return connectorPort;
+ }
+
+ public void setConnectorPort(String connectorPort) {
+ this.connectorPort = connectorPort;
+ }
+
+ public String getMbeanServerDefaultDomain() {
+ return mbeanServerDefaultDomain;
+ }
+
+ public void setMbeanServerDefaultDomain(String mbeanServerDefaultDomain) {
+ this.mbeanServerDefaultDomain = mbeanServerDefaultDomain;
+ }
+
+ public String getMbeanObjectDomainName() {
+ return mbeanObjectDomainName;
+ }
+
+ public void setMbeanObjectDomainName(String mbeanObjectDomainName) {
+ this.mbeanObjectDomainName = mbeanObjectDomainName;
+ }
+
+ public String getServiceUrlPath() {
+ return serviceUrlPath;
+ }
+
+ public void setServiceUrlPath(String serviceUrlPath) {
+ this.serviceUrlPath = serviceUrlPath;
+ }
+
+ public String getCreateConnector() {
+ return createConnector;
+ }
+
+ public void setCreateConnector(String createConnector) {
+ this.createConnector = createConnector;
+ }
+
+ public String getUsePlatformMBeanServer() {
+ return usePlatformMBeanServer;
+ }
+
+ public void setUsePlatformMBeanServer(String usePlatformMBeanServer) {
+ this.usePlatformMBeanServer = usePlatformMBeanServer;
+ }
+
+ public ManagementStatisticsLevel getStatisticsLevel() {
+ return statisticsLevel;
+ }
+
+ public void setStatisticsLevel(ManagementStatisticsLevel statisticsLevel) {
+ this.statisticsLevel = statisticsLevel;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("CamelJMXAgent[");
+ sb.append("usePlatformMBeanServer=").append(usePlatformMBeanServer);
+ if (createConnector != null) {
+ sb.append(", createConnector=").append(createConnector);
+ }
+ if (connectorPort != null) {
+ sb.append(", connectorPort=").append(connectorPort);
+ }
+ if (registryPort != null) {
+ sb.append(", registryPort=").append(registryPort);
+ }
+ if (serviceUrlPath != null) {
+ sb.append(", serviceUrlPath=").append(serviceUrlPath);
+ }
+ if (mbeanServerDefaultDomain != null) {
+ sb.append(", mbeanServerDefaultDomain=").append(mbeanServerDefaultDomain);
+ }
+ if (mbeanObjectDomainName != null) {
+ sb.append(", mbeanObjectDomainName=").append(mbeanObjectDomainName);
+ }
+ if (statisticsLevel != null) {
+ sb.append(", statisticsLevel=").append(statisticsLevel);
+ }
+ sb.append("]");
+ return sb.toString();
+ }
+
+}
\ No newline at end of file
Added: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java (added)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelPropertyPlaceholderDefinition.java Fri May 28 07:52:33 2010
@@ -0,0 +1,57 @@
+/**
+ * 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.camel.core.xml;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * <code>PropertyPlaceholderDefinition</code> represents a <propertyPlaceholder/> element.
+ *
+ * @version $Revision: 911816 $
+ */
+@XmlRootElement(name = "propertyPlaceholder")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelPropertyPlaceholderDefinition extends IdentifiedType {
+
+ @XmlAttribute(required = true)
+ private String location;
+
+ @XmlAttribute
+ private String propertiesResolverRef;
+
+ public String getLocation() {
+ return location;
+ }
+
+ public void setLocation(String location) {
+ this.location = location;
+ }
+
+ public String getPropertiesResolverRef() {
+ return propertiesResolverRef;
+ }
+
+ public void setPropertiesResolverRef(String propertiesResolverRef) {
+ this.propertiesResolverRef = propertiesResolverRef;
+ }
+
+}
Added: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelProxyFactoryDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelProxyFactoryDefinition.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelProxyFactoryDefinition.java (added)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelProxyFactoryDefinition.java Fri May 28 07:52:33 2010
@@ -0,0 +1,41 @@
+/**
+ * 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.camel.core.xml;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * The <proxy> tag element.
+ *
+ * @version $Revision: 938746 $
+*/ // to fudge the XSD generation
+@XmlRootElement(name = "proxy")
+@SuppressWarnings("unused")
+public class CamelProxyFactoryDefinition extends IdentifiedType {
+ @XmlAttribute
+ private String serviceUrl;
+ @XmlAttribute
+ private String serviceRef;
+ @XmlAttribute
+ private Class serviceInterface;
+ @XmlAttribute
+ private String camelContextId;
+
+}
Added: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelServiceExporterDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelServiceExporterDefinition.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelServiceExporterDefinition.java (added)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/CamelServiceExporterDefinition.java Fri May 28 07:52:33 2010
@@ -0,0 +1,41 @@
+/**
+ * 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.camel.core.xml;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.apache.camel.model.IdentifiedType;
+
+/**
+ * The <export> tag element.
+ *
+ * @version $Revision: 938746 $
+*/
+@XmlRootElement(name = "export")
+@SuppressWarnings("unused")
+public class CamelServiceExporterDefinition extends IdentifiedType {
+ @XmlAttribute
+ private String uri;
+ @XmlAttribute
+ private String serviceRef;
+ @XmlAttribute
+ private Class serviceInterface;
+ @XmlAttribute
+ private String camelContextId;
+
+}
Added: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/package-info.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/package-info.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/package-info.java (added)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/package-info.java Fri May 28 07:52:33 2010
@@ -0,0 +1,22 @@
+/**
+ * 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.
+ */
+
+/**
+ * The classes for working with Camel and XML along with the primary factory beans.
+ */
+@javax.xml.bind.annotation.XmlSchema(namespace = "http://camel.apache.org/schema/spring", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
+package org.apache.camel.core.xml;
Added: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/scan/AntPathMatcher.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/scan/AntPathMatcher.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/scan/AntPathMatcher.java (added)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/scan/AntPathMatcher.java Fri May 28 07:52:33 2010
@@ -0,0 +1,445 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed 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.camel.core.xml.scan;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.StringTokenizer;
+
+/**
+ * PathMatcher implementation for Ant-style path patterns.
+ * Examples are provided below.
+ *
+ * <p>Part of this mapping code has been kindly borrowed from
+ * <a href="http://ant.apache.org">Apache Ant</a>.
+ *
+ * <p>The mapping matches URLs using the following rules:<br>
+ * <ul>
+ * <li>? matches one character</li>
+ * <li>* matches zero or more characters</li>
+ * <li>** matches zero or more 'directories' in a path</li>
+ * </ul>
+ *
+ * <p>Some examples:<br>
+ * <ul>
+ * <li><code>com/t?st.jsp</code> - matches <code>com/test.jsp</code> but also
+ * <code>com/tast.jsp</code> or <code>com/txst.jsp</code></li>
+ * <li><code>com/*.jsp</code> - matches all <code>.jsp</code> files in the
+ * <code>com</code> directory</li>
+ * <li><code>com/**/test.jsp</code> - matches all <code>test.jsp</code>
+ * files underneath the <code>com</code> path</li>
+ * <li><code>org/springframework/**/*.jsp</code> - matches all <code>.jsp</code>
+ * files underneath the <code>org/springframework</code> path</li>
+ * <li><code>org/**/servlet/bla.jsp</code> - matches
+ * <code>org/springframework/servlet/bla.jsp</code> but also
+ * <code>org/springframework/testing/servlet/bla.jsp</code> and
+ * <code>org/servlet/bla.jsp</code></li>
+ * </ul>
+ *
+ * @author Alef Arendsen
+ * @author Juergen Hoeller
+ * @author Rob Harrop
+ * @since 16.07.2003
+ */
+public class AntPathMatcher {
+
+ /** Default path separator: "/" */
+ public static final String DEFAULT_PATH_SEPARATOR = "/";
+
+ private String pathSeparator = DEFAULT_PATH_SEPARATOR;
+
+
+ /**
+ * Set the path separator to use for pattern parsing.
+ * Default is "/", as in Ant.
+ */
+ public void setPathSeparator(String pathSeparator) {
+ this.pathSeparator = (pathSeparator != null ? pathSeparator : DEFAULT_PATH_SEPARATOR);
+ }
+
+
+ public boolean isPattern(String path) {
+ return (path.indexOf('*') != -1 || path.indexOf('?') != -1);
+ }
+
+ public boolean match(String pattern, String path) {
+ return doMatch(pattern, path, true);
+ }
+
+ public boolean matchStart(String pattern, String path) {
+ return doMatch(pattern, path, false);
+ }
+
+
+ /**
+ * Actually match the given <code>path</code> against the given <code>pattern</code>.
+ * @param pattern the pattern to match against
+ * @param path the path String to test
+ * @param fullMatch whether a full pattern match is required
+ * (else a pattern match as far as the given base path goes is sufficient)
+ * @return <code>true</code> if the supplied <code>path</code> matched,
+ * <code>false</code> if it didn't
+ */
+ protected boolean doMatch(String pattern, String path, boolean fullMatch) {
+ if (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
+ return false;
+ }
+
+ String[] pattDirs = tokenizeToStringArray(pattern, this.pathSeparator);
+ String[] pathDirs = tokenizeToStringArray(path, this.pathSeparator);
+
+ int pattIdxStart = 0;
+ int pattIdxEnd = pattDirs.length - 1;
+ int pathIdxStart = 0;
+ int pathIdxEnd = pathDirs.length - 1;
+
+ // Match all elements up to the first **
+ while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
+ String patDir = pattDirs[pattIdxStart];
+ if ("**".equals(patDir)) {
+ break;
+ }
+ if (!matchStrings(patDir, pathDirs[pathIdxStart])) {
+ return false;
+ }
+ pattIdxStart++;
+ pathIdxStart++;
+ }
+
+ if (pathIdxStart > pathIdxEnd) {
+ // Path is exhausted, only match if rest of pattern is * or **'s
+ if (pattIdxStart > pattIdxEnd) {
+ return (pattern.endsWith(this.pathSeparator) ?
+ path.endsWith(this.pathSeparator) : !path.endsWith(this.pathSeparator));
+ }
+ if (!fullMatch) {
+ return true;
+ }
+ if (pattIdxStart == pattIdxEnd && pattDirs[pattIdxStart].equals("*") &&
+ path.endsWith(this.pathSeparator)) {
+ return true;
+ }
+ for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
+ if (!pattDirs[i].equals("**")) {
+ return false;
+ }
+ }
+ return true;
+ }
+ else if (pattIdxStart > pattIdxEnd) {
+ // String not exhausted, but pattern is. Failure.
+ return false;
+ }
+ else if (!fullMatch && "**".equals(pattDirs[pattIdxStart])) {
+ // Path start definitely matches due to "**" part in pattern.
+ return true;
+ }
+
+ // up to last '**'
+ while (pattIdxStart <= pattIdxEnd && pathIdxStart <= pathIdxEnd) {
+ String patDir = pattDirs[pattIdxEnd];
+ if (patDir.equals("**")) {
+ break;
+ }
+ if (!matchStrings(patDir, pathDirs[pathIdxEnd])) {
+ return false;
+ }
+ pattIdxEnd--;
+ pathIdxEnd--;
+ }
+ if (pathIdxStart > pathIdxEnd) {
+ // String is exhausted
+ for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
+ if (!pattDirs[i].equals("**")) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ while (pattIdxStart != pattIdxEnd && pathIdxStart <= pathIdxEnd) {
+ int patIdxTmp = -1;
+ for (int i = pattIdxStart + 1; i <= pattIdxEnd; i++) {
+ if (pattDirs[i].equals("**")) {
+ patIdxTmp = i;
+ break;
+ }
+ }
+ if (patIdxTmp == pattIdxStart + 1) {
+ // '**/**' situation, so skip one
+ pattIdxStart++;
+ continue;
+ }
+ // Find the pattern between padIdxStart & padIdxTmp in str between
+ // strIdxStart & strIdxEnd
+ int patLength = (patIdxTmp - pattIdxStart - 1);
+ int strLength = (pathIdxEnd - pathIdxStart + 1);
+ int foundIdx = -1;
+
+ strLoop:
+ for (int i = 0; i <= strLength - patLength; i++) {
+ for (int j = 0; j < patLength; j++) {
+ String subPat = (String) pattDirs[pattIdxStart + j + 1];
+ String subStr = (String) pathDirs[pathIdxStart + i + j];
+ if (!matchStrings(subPat, subStr)) {
+ continue strLoop;
+ }
+ }
+ foundIdx = pathIdxStart + i;
+ break;
+ }
+
+ if (foundIdx == -1) {
+ return false;
+ }
+
+ pattIdxStart = patIdxTmp;
+ pathIdxStart = foundIdx + patLength;
+ }
+
+ for (int i = pattIdxStart; i <= pattIdxEnd; i++) {
+ if (!pattDirs[i].equals("**")) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Tests whether or not a string matches against a pattern.
+ * The pattern may contain two special characters:<br>
+ * '*' means zero or more characters<br>
+ * '?' means one and only one character
+ * @param pattern pattern to match against.
+ * Must not be <code>null</code>.
+ * @param str string which must be matched against the pattern.
+ * Must not be <code>null</code>.
+ * @return <code>true</code> if the string matches against the
+ * pattern, or <code>false</code> otherwise.
+ */
+ private boolean matchStrings(String pattern, String str) {
+ char[] patArr = pattern.toCharArray();
+ char[] strArr = str.toCharArray();
+ int patIdxStart = 0;
+ int patIdxEnd = patArr.length - 1;
+ int strIdxStart = 0;
+ int strIdxEnd = strArr.length - 1;
+ char ch;
+
+ boolean containsStar = false;
+ for (int i = 0; i < patArr.length; i++) {
+ if (patArr[i] == '*') {
+ containsStar = true;
+ break;
+ }
+ }
+
+ if (!containsStar) {
+ // No '*'s, so we make a shortcut
+ if (patIdxEnd != strIdxEnd) {
+ return false; // Pattern and string do not have the same size
+ }
+ for (int i = 0; i <= patIdxEnd; i++) {
+ ch = patArr[i];
+ if (ch != '?') {
+ if (ch != strArr[i]) {
+ return false;// Character mismatch
+ }
+ }
+ }
+ return true; // String matches against pattern
+ }
+
+
+ if (patIdxEnd == 0) {
+ return true; // Pattern contains only '*', which matches anything
+ }
+
+ // Process characters before first star
+ while ((ch = patArr[patIdxStart]) != '*' && strIdxStart <= strIdxEnd) {
+ if (ch != '?') {
+ if (ch != strArr[strIdxStart]) {
+ return false;// Character mismatch
+ }
+ }
+ patIdxStart++;
+ strIdxStart++;
+ }
+ if (strIdxStart > strIdxEnd) {
+ // All characters in the string are used. Check if only '*'s are
+ // left in the pattern. If so, we succeeded. Otherwise failure.
+ for (int i = patIdxStart; i <= patIdxEnd; i++) {
+ if (patArr[i] != '*') {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // Process characters after last star
+ while ((ch = patArr[patIdxEnd]) != '*' && strIdxStart <= strIdxEnd) {
+ if (ch != '?') {
+ if (ch != strArr[strIdxEnd]) {
+ return false;// Character mismatch
+ }
+ }
+ patIdxEnd--;
+ strIdxEnd--;
+ }
+ if (strIdxStart > strIdxEnd) {
+ // All characters in the string are used. Check if only '*'s are
+ // left in the pattern. If so, we succeeded. Otherwise failure.
+ for (int i = patIdxStart; i <= patIdxEnd; i++) {
+ if (patArr[i] != '*') {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ // process pattern between stars. padIdxStart and patIdxEnd point
+ // always to a '*'.
+ while (patIdxStart != patIdxEnd && strIdxStart <= strIdxEnd) {
+ int patIdxTmp = -1;
+ for (int i = patIdxStart + 1; i <= patIdxEnd; i++) {
+ if (patArr[i] == '*') {
+ patIdxTmp = i;
+ break;
+ }
+ }
+ if (patIdxTmp == patIdxStart + 1) {
+ // Two stars next to each other, skip the first one.
+ patIdxStart++;
+ continue;
+ }
+ // Find the pattern between padIdxStart & padIdxTmp in str between
+ // strIdxStart & strIdxEnd
+ int patLength = (patIdxTmp - patIdxStart - 1);
+ int strLength = (strIdxEnd - strIdxStart + 1);
+ int foundIdx = -1;
+ strLoop:
+ for (int i = 0; i <= strLength - patLength; i++) {
+ for (int j = 0; j < patLength; j++) {
+ ch = patArr[patIdxStart + j + 1];
+ if (ch != '?') {
+ if (ch != strArr[strIdxStart + i + j]) {
+ continue strLoop;
+ }
+ }
+ }
+
+ foundIdx = strIdxStart + i;
+ break;
+ }
+
+ if (foundIdx == -1) {
+ return false;
+ }
+
+ patIdxStart = patIdxTmp;
+ strIdxStart = foundIdx + patLength;
+ }
+
+ // All characters in the string are used. Check if only '*'s are left
+ // in the pattern. If so, we succeeded. Otherwise failure.
+ for (int i = patIdxStart; i <= patIdxEnd; i++) {
+ if (patArr[i] != '*') {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Given a pattern and a full path, determine the pattern-mapped part.
+ * <p>For example:
+ * <ul>
+ * <li>'<code>/docs/cvs/commit.html</code>' and '<code>/docs/cvs/commit.html</code> -> ''</li>
+ * <li>'<code>/docs/*</code>' and '<code>/docs/cvs/commit</code> -> '<code>cvs/commit</code>'</li>
+ * <li>'<code>/docs/cvs/*.html</code>' and '<code>/docs/cvs/commit.html</code> -> '<code>commit.html</code>'</li>
+ * <li>'<code>/docs/**</code>' and '<code>/docs/cvs/commit</code> -> '<code>cvs/commit</code>'</li>
+ * <li>'<code>/docs/**\/*.html</code>' and '<code>/docs/cvs/commit.html</code> -> '<code>cvs/commit.html</code>'</li>
+ * <li>'<code>/*.html</code>' and '<code>/docs/cvs/commit.html</code> -> '<code>docs/cvs/commit.html</code>'</li>
+ * <li>'<code>*.html</code>' and '<code>/docs/cvs/commit.html</code> -> '<code>/docs/cvs/commit.html</code>'</li>
+ * <li>'<code>*</code>' and '<code>/docs/cvs/commit.html</code> -> '<code>/docs/cvs/commit.html</code>'</li>
+ * </ul>
+ * <p>Assumes that {@link #match} returns <code>true</code> for '<code>pattern</code>'
+ * and '<code>path</code>', but does <strong>not</strong> enforce this.
+ */
+ public String extractPathWithinPattern(String pattern, String path) {
+ String[] patternParts = tokenizeToStringArray(pattern, this.pathSeparator);
+ String[] pathParts = tokenizeToStringArray(path, this.pathSeparator);
+
+ StringBuffer buffer = new StringBuffer();
+
+ // Add any path parts that have a wildcarded pattern part.
+ int puts = 0;
+ for (int i = 0; i < patternParts.length; i++) {
+ String patternPart = patternParts[i];
+ if ((patternPart.indexOf('*') > -1 || patternPart.indexOf('?') > -1) && pathParts.length >= i + 1) {
+ if (puts > 0 || (i == 0 && !pattern.startsWith(this.pathSeparator))) {
+ buffer.append(this.pathSeparator);
+ }
+ buffer.append(pathParts[i]);
+ puts++;
+ }
+ }
+
+ // Append any trailing path parts.
+ for (int i = patternParts.length; i < pathParts.length; i++) {
+ if (puts > 0 || i > 0) {
+ buffer.append(this.pathSeparator);
+ }
+ buffer.append(pathParts[i]);
+ }
+
+ return buffer.toString();
+ }
+
+ /**
+ * Tokenize the given String into a String array via a StringTokenizer.
+ * Trims tokens and omits empty tokens.
+ * <p>The given delimiters string is supposed to consist of any number of
+ * delimiter characters. Each of those characters can be used to separate
+ * tokens. A delimiter is always a single character; for multi-character
+ * delimiters, consider using <code>delimitedListToStringArray</code>
+ * @param str the String to tokenize
+ * @param delimiters the delimiter characters, assembled as String
+ * (each of those characters is individually considered as delimiter).
+ * @return an array of the tokens
+ * @see java.util.StringTokenizer
+ * @see java.lang.String#trim()
+ */
+ public static String[] tokenizeToStringArray(String str, String delimiters) {
+ if (str == null) {
+ return null;
+ }
+ StringTokenizer st = new StringTokenizer(str, delimiters);
+ List tokens = new ArrayList();
+ while (st.hasMoreTokens()) {
+ String token = st.nextToken();
+ token = token.trim();
+ if (token.length() > 0) {
+ tokens.add(token);
+ }
+ }
+ return (String[]) tokens.toArray(new String[tokens.size()]);
+ }
+
+}
Added: camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/scan/PatternBasedPackageScanFilter.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/scan/PatternBasedPackageScanFilter.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/scan/PatternBasedPackageScanFilter.java (added)
+++ camel/trunk/components/camel-core-xml/src/main/java/org/apache/camel/core/xml/scan/PatternBasedPackageScanFilter.java Fri May 28 07:52:33 2010
@@ -0,0 +1,126 @@
+/**
+ * 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.camel.core.xml.scan;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.apache.camel.spi.PackageScanFilter;
+
+/**
+ * <code>PatternBasedPackageScanFilter</code> uses an underlying
+ * {@link AntPathMatcher} to filter scanned files according to include and
+ * exclude patterns.
+ *
+ * @see AntPathMatcher
+ */
+public class PatternBasedPackageScanFilter implements PackageScanFilter {
+ private AntPathMatcher matcher = new AntPathMatcher();
+
+ private List<String> excludePatterns;
+ private List<String> includePatterns;
+
+ /**
+ * add and exclude pattern to the filter. Classes matching this pattern will
+ * not match the filter
+ *
+ * @param excludePattern
+ */
+ public void addExcludePattern(String excludePattern) {
+ if (excludePatterns == null) {
+ excludePatterns = new ArrayList<String>();
+ }
+ excludePatterns.add(excludePattern);
+ }
+
+ /**
+ * add and include pattern to the filter. Classes must match one of supplied
+ * include patterns to match the filter
+ *
+ * @param includePattern
+ */
+ public void addIncludePattern(String includePattern) {
+ if (includePatterns == null) {
+ includePatterns = new ArrayList<String>();
+ }
+ includePatterns.add(includePattern);
+ }
+
+ public void addIncludePatterns(Collection<String> includes) {
+ if (includePatterns == null) {
+ includePatterns = new ArrayList<String>();
+ }
+ includePatterns.addAll(includes);
+ }
+
+ public void addExcludePatterns(Collection<String> excludes) {
+ if (excludePatterns == null) {
+ excludePatterns = new ArrayList<String>();
+ }
+ excludePatterns.addAll(excludes);
+ }
+
+ /**
+ * Tests if a given class matches the patterns in this filter. Patterns are
+ * specified by {@link AntPathMatcher}
+ * <p>
+ * if no include or exclude patterns are set then all classes match.
+ * <p>
+ * If the filter contains only include filters, then the candidate class
+ * must match one of the include patterns to match the filter and return
+ * true.
+ * <p>
+ * If the filter contains only exclude filters, then the filter will return
+ * true unless the candidate class matches an exclude pattern.
+ * <p>
+ * if this contains both include and exclude filters, then the above rules
+ * apply with excludes taking precedence over includes i.e. an include
+ * pattern of java.util.* and an exclude pattern of java.util.jar.* will
+ * include a file only if it is in the util pkg and not in the util.jar
+ * package.
+ *
+ * @return true if candidate class matches according to the above rules
+ */
+ public boolean matches(Class<?> candidateClass) {
+ String candidate = candidateClass.getName();
+ if (includePatterns != null || excludePatterns != null) {
+
+ if (excludePatterns != null && excludePatterns.size() > 0) {
+ if (matchesAny(excludePatterns, candidate)) {
+ return false;
+ }
+ }
+
+ if (includePatterns != null && includePatterns.size() > 0) {
+ return matchesAny(includePatterns, candidate);
+ }
+
+ }
+ return true;
+ }
+
+ private boolean matchesAny(List<String> patterns, String candidate) {
+ for (String pattern : patterns) {
+ if (matcher.match(pattern, candidate)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
Added: camel/trunk/components/camel-core-xml/src/main/resources/org/apache/camel/core/xml/jaxb.index
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-core-xml/src/main/resources/org/apache/camel/core/xml/jaxb.index?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-core-xml/src/main/resources/org/apache/camel/core/xml/jaxb.index (added)
+++ camel/trunk/components/camel-core-xml/src/main/resources/org/apache/camel/core/xml/jaxb.index Fri May 28 07:52:33 2010
@@ -0,0 +1,20 @@
+## ------------------------------------------------------------------------
+## 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.
+## ------------------------------------------------------------------------
+CamelJMXAgentDefinition
+CamelPropertyPlaceholderDefinition
+CamelProxyFactoryDefinition
+CamelServiceExporterDefinition
Modified: camel/trunk/components/camel-osgi/pom.xml
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/pom.xml?rev=949127&r1=949126&r2=949127&view=diff
==============================================================================
--- camel/trunk/components/camel-osgi/pom.xml (original)
+++ camel/trunk/components/camel-osgi/pom.xml Fri May 28 07:52:33 2010
@@ -26,27 +26,9 @@
</parent>
<artifactId>camel-osgi</artifactId>
- <packaging>bundle</packaging>
<name>Camel :: OSGi</name>
<description>Camel OSGi support</description>
- <properties>
- <camel.osgi.export.pkg>
- org.apache.camel.osgi.*
- </camel.osgi.export.pkg>
- <camel.osgi.import.pkg>
- !org.apache.camel.osgi.*,
- org.osgi.framework;version="[1.3,2)",
- org.apache.camel.*;${camel.osgi.import.strict.version},
- org.springframework.osgi.*;version="[1.2,2)",
- ${camel.osgi.import.defaults},
- *
- </camel.osgi.import.pkg>
- <camel.osgi.activator>
- org.apache.camel.osgi.Activator
- </camel.osgi.activator>
- </properties>
-
<dependencies>
<dependency>
@@ -58,26 +40,8 @@
<artifactId>camel-spring</artifactId>
</dependency>
<dependency>
- <groupId>org.springframework.osgi</groupId>
- <artifactId>spring-osgi-core</artifactId>
- <exclusions>
- <exclusion>
- <groupId>org.springframework</groupId>
- <artifactId>org.springframework.aop</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.springframework</groupId>
- <artifactId>org.springframework.beans</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.springframework</groupId>
- <artifactId>org.springframework.context</artifactId>
- </exclusion>
- <exclusion>
- <groupId>org.springframework</groupId>
- <artifactId>org.springframework.core</artifactId>
- </exclusion>
- </exclusions>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core-osgi</artifactId>
</dependency>
<dependency>
<groupId>org.apache.felix</groupId>
@@ -85,6 +49,10 @@
<scope>provided</scope>
</dependency>
<dependency>
+ <groupId>org.springframework.osgi</groupId>
+ <artifactId>spring-osgi-core</artifactId>
+ </dependency>
+ <dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<optional>false</optional>
@@ -145,40 +113,4 @@
</repository>
</repositories>
- <build>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <includes>
- <include>**/*</include>
- </includes>
- <filtering>true</filtering>
- </resource>
- </resources>
- <plugins>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-artifacts</id>
- <phase>package</phase>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <configuration>
- <artifacts>
- <artifact>
- <file>${basedir}/src/main/resources/camel-osgi.xsd</file>
- <type>xsd</type>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- </plugins>
- </build>
-
</project>
Added: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactory.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactory.java (added)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactory.java Fri May 28 07:52:33 2010
@@ -0,0 +1,54 @@
+/**
+ * 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.camel.osgi;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.core.osgi.OsgiDefaultCamelContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.BundleContext;
+import org.springframework.osgi.context.BundleContextAware;
+
+/**
+ * This factory just create a DefaultContext in OSGi without
+ * any spring application context involved.
+ */
+public class CamelContextFactory implements BundleContextAware {
+ private static final transient Log LOG = LogFactory.getLog(CamelContextFactory.class);
+ private BundleContext bundleContext;
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using BundleContext: " + bundleContext);
+ }
+ this.bundleContext = bundleContext;
+ }
+
+ protected DefaultCamelContext newCamelContext() {
+ return new OsgiDefaultCamelContext(bundleContext);
+ }
+
+ public DefaultCamelContext createContext() {
+ LOG.debug("Creating DefaultCamelContext");
+ return newCamelContext();
+ }
+
+}
Added: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java (added)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java Fri May 28 07:52:33 2010
@@ -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.camel.osgi;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlTransient;
+
+import org.apache.camel.spring.SpringCamelContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.osgi.framework.BundleContext;
+import org.springframework.osgi.context.BundleContextAware;
+
+@XmlRootElement(name = "camelContext")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class CamelContextFactoryBean extends org.apache.camel.spring.CamelContextFactoryBean implements BundleContextAware {
+ private static final transient Log LOG = LogFactory.getLog(CamelContextFactoryBean.class);
+
+ @XmlTransient
+ private BundleContext bundleContext;
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public void setBundleContext(BundleContext bundleContext) {
+ if (LOG.isDebugEnabled()) {
+ LOG.debug("Using BundleContext: " + bundleContext);
+ }
+ this.bundleContext = bundleContext;
+ }
+
+ protected SpringCamelContext newCamelContext() {
+ return new OsgiSpringCamelContext(getApplicationContext(), getBundleContext());
+ }
+
+}
Added: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java (added)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelNamespaceHandler.java Fri May 28 07:52:33 2010
@@ -0,0 +1,46 @@
+/**
+ * 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.camel.osgi;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.camel.osgi.CamelContextFactoryBean;
+
+public class CamelNamespaceHandler extends org.apache.camel.spring.handler.CamelNamespaceHandler {
+
+ public void init() {
+ super.init();
+ registerParser("camelContext", new CamelContextBeanDefinitionParser(CamelContextFactoryBean.class));
+ }
+
+ // It just add the package of the class for initiate the JAXB context
+ protected Set<Class> getJaxbPackages() {
+ Set<Class> classes = new HashSet<Class>();
+ classes.add(CamelContextFactoryBean.class);
+ classes.add(org.apache.camel.spring.CamelContextFactoryBean.class);
+ classes.add(org.apache.camel.ExchangePattern.class);
+ classes.add(org.apache.camel.model.RouteDefinition.class);
+ classes.add(org.apache.camel.model.config.StreamResequencerConfig.class);
+ classes.add(org.apache.camel.model.dataformat.DataFormatsDefinition.class);
+ classes.add(org.apache.camel.model.language.ExpressionDefinition.class);
+ classes.add(org.apache.camel.model.loadbalancer.RoundRobinLoadBalancerDefinition.class);
+ return classes;
+ }
+
+
+}
Added: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiSpringCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiSpringCamelContext.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiSpringCamelContext.java (added)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiSpringCamelContext.java Fri May 28 07:52:33 2010
@@ -0,0 +1,37 @@
+/**
+ * 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.camel.osgi;
+
+import org.apache.camel.TypeConverter;
+import org.apache.camel.core.osgi.OsgiCamelContextHelper;
+import org.apache.camel.spring.SpringCamelContext;
+import org.osgi.framework.BundleContext;
+import org.springframework.context.ApplicationContext;
+
+public class OsgiSpringCamelContext extends SpringCamelContext {
+
+ public OsgiSpringCamelContext(ApplicationContext applicationContext, BundleContext bundleContext) {
+ super(applicationContext);
+ OsgiCamelContextHelper.osgiUpdate(this, bundleContext);
+ }
+
+ @Override
+ protected TypeConverter createTypeConverter() {
+ return OsgiCamelContextHelper.createTypeConverter(this);
+ }
+
+}
Added: camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java (added)
+++ camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/SpringCamelContextFactory.java Fri May 28 07:52:33 2010
@@ -0,0 +1,37 @@
+/**
+ * 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.camel.osgi;
+
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.osgi.CamelContextFactory;
+import org.apache.camel.spring.SpringCamelContext;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
+
+public class SpringCamelContextFactory extends CamelContextFactory implements ApplicationContextAware {
+ private ApplicationContext applicationContext;
+
+ public void setApplicationContext(ApplicationContext context) {
+ this.applicationContext = context;
+ }
+
+ @Override
+ protected DefaultCamelContext newCamelContext() {
+ return new SpringCamelContext(applicationContext);
+ }
+
+}
Added: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/ActivatorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/ActivatorTest.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/ActivatorTest.java (added)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/ActivatorTest.java Fri May 28 07:52:33 2010
@@ -0,0 +1,57 @@
+/**
+ * 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.camel.core.osgi;
+
+import org.junit.Test;
+
+public class ActivatorTest extends CamelOsgiTestSupport {
+
+ @Test
+ public void testGetComponent() throws Exception {
+ Class clazz = Activator.getComponent("timer");
+ assertNull("Here should not find the timer component", clazz);
+
+ clazz = Activator.getComponent("timer_test");
+ assertNotNull("The timer_test component should not be null", clazz);
+ }
+
+ @Test
+ public void testGetLanaguge() throws Exception {
+ Class clazz = Activator.getLanguage("bean_test");
+ assertNotNull("The bean_test component should not be null", clazz);
+ }
+
+ private boolean containsPackageName(String packageName, Activator.TypeConverterEntry[] entries) {
+ for (Activator.TypeConverterEntry entry : entries) {
+ for (String name : entry.converterPackages) {
+ if (name.equals(packageName)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ @Test
+ public void testFindTypeConverterPackageNames() throws Exception {
+ Activator.TypeConverterEntry[] entries = Activator.getTypeConverterEntries();
+ assertTrue("We should find some converter packages here", entries.length > 0);
+ assertTrue("Here should contains org.apache.camel.osgi.test", containsPackageName("org.apache.camel.osgi.test", entries));
+ assertTrue("Here should contains org.apache.camel.osgi.test", containsPackageName("org.apache.camel.osgi.test", entries));
+ }
+
+}
Added: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelMockBundle.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelMockBundle.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelMockBundle.java (added)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelMockBundle.java Fri May 28 07:52:33 2010
@@ -0,0 +1,93 @@
+/**
+ * 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.camel.core.osgi;
+
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+
+import org.apache.camel.core.osgi.Activator;
+import org.springframework.osgi.mock.MockBundle;
+
+/**
+ * The mock bundle will make up a normal camel-components bundle
+ */
+public class CamelMockBundle extends MockBundle {
+
+ private class ListEnumeration implements Enumeration {
+ private final List list;
+ private int index;
+
+ public ListEnumeration(List list) {
+ this.list = list;
+ }
+
+ public boolean hasMoreElements() {
+ return list != null && index < list.size();
+ }
+
+ public Object nextElement() {
+ Object result = null;
+ if (list != null) {
+ result = list.get(index);
+ index++;
+ }
+ return result;
+ }
+
+ }
+
+ private Enumeration getListEnumeration(String prefix, String entrys[]) {
+ List<String> list = new ArrayList<String>();
+ for (String entry : entrys) {
+ list.add(prefix + entry);
+ }
+ return new ListEnumeration(list);
+ }
+
+ public Enumeration getEntryPaths(String path) {
+ Enumeration result = null;
+ if (Activator.META_INF_COMPONENT.equals(path)) {
+ String[] entries = new String[] {"timer_test", "file_test"};
+ result = getListEnumeration(Activator.META_INF_COMPONENT, entries);
+ }
+ if (Activator.META_INF_LANGUAGE.equals(path)) {
+ String[] entries = new String[] {"bean_test", "file_test"};
+ result = getListEnumeration(Activator.META_INF_LANGUAGE, entries);
+ }
+ if (Activator.META_INF_LANGUAGE_RESOLVER.equals(path)) {
+ String[] entries = new String[] {"default"};
+ result = getListEnumeration(Activator.META_INF_LANGUAGE_RESOLVER, entries);
+ }
+
+ return result;
+ }
+
+ public Enumeration findEntries(String path, String filePattern, boolean recurse) {
+ if (path.equals("/org/apache/camel/osgi/test") && filePattern.equals("*.class")) {
+ List<URL> urls = new ArrayList<URL>();
+ URL url = getClass().getClassLoader().getResource("org/apache/camel/osgi/test/MyTypeConverter.class");
+ urls.add(url);
+ url = getClass().getClassLoader().getResource("org/apache/camel/osgi/test/MyRouteBuilder.class");
+ urls.add(url);
+ return new ListEnumeration(urls);
+ } else {
+ return super.findEntries(path, filePattern, recurse);
+ }
+ }
+}
Added: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelMockBundleContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelMockBundleContext.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelMockBundleContext.java (added)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelMockBundleContext.java Fri May 28 07:52:33 2010
@@ -0,0 +1,35 @@
+/**
+ * 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.camel.core.osgi;
+
+import org.apache.camel.osgi.test.MyService;
+import org.osgi.framework.Constants;
+import org.osgi.framework.ServiceReference;
+import org.springframework.osgi.mock.MockBundleContext;
+
+public class CamelMockBundleContext extends MockBundleContext {
+
+ public Object getService(ServiceReference reference) {
+ String[] classNames = (String[]) reference.getProperty(Constants.OBJECTCLASS);
+ if (classNames[0].equals("org.apache.camel.osgi.test.MyService")) {
+ return new MyService();
+ } else {
+ return null;
+ }
+ }
+
+}
Added: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelOsgiTestSupport.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelOsgiTestSupport.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelOsgiTestSupport.java (added)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/CamelOsgiTestSupport.java Fri May 28 07:52:33 2010
@@ -0,0 +1,64 @@
+/**
+ * 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.camel.core.osgi;
+
+import org.apache.camel.core.osgi.Activator;
+import org.apache.camel.core.osgi.OsgiClassResolver;
+import org.apache.camel.core.osgi.OsgiPackageScanClassResolver;
+import org.apache.camel.spi.ClassResolver;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.osgi.framework.BundleContext;
+import org.springframework.osgi.mock.MockBundle;
+import org.springframework.osgi.mock.MockBundleContext;
+
+public class CamelOsgiTestSupport extends Assert {
+ private Activator testActivator;
+ private MockBundleContext bundleContext = new CamelMockBundleContext();
+ private OsgiPackageScanClassResolver packageScanClassResolver = new OsgiPackageScanClassResolver(bundleContext);
+ private ClassResolver classResolver = new OsgiClassResolver(bundleContext);
+ private MockBundle bundle = new CamelMockBundle();
+
+ @Before
+ public void setUp() throws Exception {
+ bundleContext.setBundle(bundle);
+ testActivator = new Activator();
+ testActivator.start(bundleContext);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ testActivator.stop(bundleContext);
+ }
+
+ public Activator getActivator() {
+ return testActivator;
+ }
+
+ public BundleContext getBundleContext() {
+ return bundleContext;
+ }
+
+ public OsgiPackageScanClassResolver getPackageScanClassResolver() {
+ return packageScanClassResolver;
+ }
+
+ public ClassResolver getClassResolver() {
+ return classResolver;
+ }
+}
Added: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiAnnotationTypeConverterLoaderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiAnnotationTypeConverterLoaderTest.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiAnnotationTypeConverterLoaderTest.java (added)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiAnnotationTypeConverterLoaderTest.java Fri May 28 07:52:33 2010
@@ -0,0 +1,34 @@
+/**
+ * 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.camel.core.osgi;
+
+import org.apache.camel.core.osgi.OsgiAnnotationTypeConverterLoader;
+import org.apache.camel.osgi.test.MockTypeConverterRegistry;
+import org.junit.Test;
+
+public class OsgiAnnotationTypeConverterLoaderTest extends CamelOsgiTestSupport {
+
+ @Test
+ public void testLoad() throws Exception {
+ OsgiAnnotationTypeConverterLoader loader = new OsgiAnnotationTypeConverterLoader(getPackageScanClassResolver());
+ MockTypeConverterRegistry registry = new MockTypeConverterRegistry();
+ loader.load(registry);
+ assertTrue("There should have at lest one fallback converter", registry.getFallbackTypeConverters().size() >= 1);
+ assertTrue("There should have at lest one converter", registry.getTypeConverters().size() >= 1);
+ }
+
+}
Added: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiClassResolverTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiClassResolverTest.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiClassResolverTest.java (added)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiClassResolverTest.java Fri May 28 07:52:33 2010
@@ -0,0 +1,40 @@
+/**
+ * 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.camel.core.osgi;
+
+import java.io.InputStream;
+
+import org.apache.camel.spi.ClassResolver;
+import org.junit.Test;
+
+public class OsgiClassResolverTest extends CamelOsgiTestSupport {
+
+ @Test
+ public void testResolveClass() {
+ ClassResolver classResolver = getClassResolver();
+ Class routeBuilder = classResolver.resolveClass("org.apache.camel.osgi.test.MyRouteBuilder");
+ assertNotNull("The class of routeBuilder should not be null.", routeBuilder);
+ }
+
+ @Test
+ public void testResolverResource() {
+ ClassResolver classResolver = getClassResolver();
+ InputStream is = classResolver.loadResourceAsStream("META-INF/services/org/apache/camel/TypeConverter");
+ assertNotNull("The InputStream should not be null.", is);
+ }
+
+}
Added: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiComponentResolverTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiComponentResolverTest.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiComponentResolverTest.java (added)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiComponentResolverTest.java Fri May 28 07:52:33 2010
@@ -0,0 +1,37 @@
+/**
+ * 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.camel.core.osgi;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
+import org.apache.camel.component.file.FileComponent;
+import org.apache.camel.core.osgi.OsgiComponentResolver;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.junit.Test;
+
+public class OsgiComponentResolverTest extends CamelOsgiTestSupport {
+
+ @Test
+ public void testOsgiResolverFindLanguageTest() throws Exception {
+ CamelContext camelContext = new DefaultCamelContext();
+ OsgiComponentResolver resolver = new OsgiComponentResolver();
+ Component component = resolver.resolveComponent("file_test", camelContext);
+ assertNotNull("We should find file_test component", component);
+ assertTrue("We should get the file component here", component instanceof FileComponent);
+ }
+
+}
Added: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiFactoryFinderTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiFactoryFinderTest.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiFactoryFinderTest.java (added)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiFactoryFinderTest.java Fri May 28 07:52:33 2010
@@ -0,0 +1,49 @@
+/**
+ * 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.camel.core.osgi;
+
+import java.io.IOException;
+
+import org.apache.camel.NoFactoryAvailableException;
+import org.apache.camel.impl.DefaultClassResolver;
+import org.apache.camel.core.osgi.OsgiFactoryFinder;
+import org.junit.Test;
+
+public class OsgiFactoryFinderTest extends CamelOsgiTestSupport {
+
+ @Test
+ public void testFindClass() throws Exception {
+ OsgiFactoryFinder finder = new OsgiFactoryFinder(new DefaultClassResolver(), "META-INF/services/org/apache/camel/component/");
+ Class clazz = finder.findClass("file_test", "strategy.factory.");
+ assertNotNull("We should get the file strategy factory here", clazz);
+
+ try {
+ clazz = finder.findClass("nofile", "strategy.factory.");
+ fail("We should get exception here");
+ } catch (Exception ex) {
+ assertTrue("Should get NoFactoryAvailableException", ex instanceof NoFactoryAvailableException);
+ }
+
+ try {
+ clazz = finder.findClass("file_test", "nostrategy.factory.");
+ fail("We should get exception here");
+ } catch (Exception ex) {
+ assertTrue("Should get IOException", ex instanceof IOException);
+ }
+ }
+
+}
Added: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiLanguageResolverTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiLanguageResolverTest.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiLanguageResolverTest.java (added)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiLanguageResolverTest.java Fri May 28 07:52:33 2010
@@ -0,0 +1,35 @@
+/**
+ * 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.camel.core.osgi;
+
+import java.io.IOException;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.core.osgi.OsgiLanguageResolver;
+import org.apache.camel.spi.Language;
+import org.junit.Test;
+
+public class OsgiLanguageResolverTest extends CamelOsgiTestSupport {
+ @Test
+ public void testOsgiResolverFindLanguageTest() throws IOException {
+ CamelContext camelContext = new DefaultCamelContext();
+ OsgiLanguageResolver resolver = new OsgiLanguageResolver();
+ Language language = resolver.resolveLanguage("js", camelContext);
+ assertNotNull("We should find js language", language);
+ }
+}
Added: camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiPackageScanClassResolverTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiPackageScanClassResolverTest.java?rev=949127&view=auto
==============================================================================
--- camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiPackageScanClassResolverTest.java (added)
+++ camel/trunk/components/camel-osgi/src/test/java/org/apache/camel/core/osgi/OsgiPackageScanClassResolverTest.java Fri May 28 07:52:33 2010
@@ -0,0 +1,56 @@
+/**
+ * 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.camel.core.osgi;
+
+import java.io.IOException;
+import java.util.Set;
+
+import org.apache.camel.Converter;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.core.osgi.Activator;
+import org.apache.camel.core.osgi.OsgiPackageScanClassResolver;
+import org.apache.camel.osgi.test.MyRouteBuilder;
+import org.apache.camel.osgi.test.MyTypeConverter;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+
+public class OsgiPackageScanClassResolverTest extends CamelOsgiTestSupport {
+
+ @Test
+ public void testOsgiResolverFindAnnotatedTest() throws IOException {
+ BundleContext context = Activator.getBundle().getBundleContext();
+ assertNotNull("The BundleContext should not be null", context);
+ OsgiPackageScanClassResolver resolver = new OsgiPackageScanClassResolver(context);
+
+ String[] packageNames = {"org.apache.camel.osgi.test"};
+ Set<Class<?>> classes = resolver.findAnnotated(Converter.class, packageNames);
+ assertEquals("There should find a class", classes.size(), 1);
+ assertTrue("Find a wrong class", classes.contains(MyTypeConverter.class));
+ }
+
+ @Test
+ public void testOsgiResolverFindImplementationTest() {
+ BundleContext context = Activator.getBundle().getBundleContext();
+ assertNotNull("The BundleContext should not be null", context);
+ OsgiPackageScanClassResolver resolver = new OsgiPackageScanClassResolver(context);
+ String[] packageNames = {"org.apache.camel.osgi.test"};
+ Set<Class<?>> classes = resolver.findImplementations(RoutesBuilder.class, packageNames);
+ assertEquals("There should find a class", classes.size(), 1);
+ assertTrue("Find a wrong class", classes.contains(MyRouteBuilder.class));
+ }
+
+}