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 2006/10/26 08:55:19 UTC
svn commit: r467891 - in /incubator/servicemix/trunk/servicemix-services: ./
src/main/java/org/apache/servicemix/finder/
src/main/java/org/apache/servicemix/jdbc/
src/main/java/org/apache/servicemix/store/jdbc/
Author: gnodet
Date: Wed Oct 25 23:55:18 2006
New Revision: 467891
URL: http://svn.apache.org/viewvc?view=rev&rev=467891
Log:
Move FactoryFinder from servicemix-core to servicemix-services
Added:
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/finder/
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/finder/FactoryFinder.java
Modified:
incubator/servicemix/trunk/servicemix-services/pom.xml
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java
incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java
Modified: incubator/servicemix/trunk/servicemix-services/pom.xml
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-services/pom.xml?view=diff&rev=467891&r1=467890&r2=467891
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/pom.xml (original)
+++ incubator/servicemix/trunk/servicemix-services/pom.xml Wed Oct 25 23:55:18 2006
@@ -36,11 +36,6 @@
<dependencies>
<dependency>
- <groupId>org.apache.activemq</groupId>
- <artifactId>activeio-core</artifactId>
- <optional>true</optional>
- </dependency>
- <dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-j2ee-connector_1.5_spec</artifactId>
<optional>true</optional>
Added: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/finder/FactoryFinder.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/finder/FactoryFinder.java?view=auto&rev=467891
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/finder/FactoryFinder.java (added)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/finder/FactoryFinder.java Wed Oct 25 23:55:18 2006
@@ -0,0 +1,105 @@
+/*
+ * 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.finder;
+
+import java.io.BufferedInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentHashMap;
+
+
+public class FactoryFinder {
+
+ private final String path;
+ private final ConcurrentHashMap classMap = new ConcurrentHashMap();
+
+ public FactoryFinder(String path) {
+ this.path = path;
+ }
+
+ /**
+ * Creates a new instance of the given key
+ *
+ * @param key is the key to add to the path to find a text file
+ * containing the factory name
+ * @return a newly created instance
+ */
+ public Object newInstance(String key)
+ throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException
+ {
+ return newInstance(key, null);
+ }
+
+ public Object newInstance(String key, String propertyPrefix)
+ throws IllegalAccessException, InstantiationException, IOException, ClassNotFoundException
+ {
+ if (propertyPrefix == null)
+ propertyPrefix = "";
+
+ Class clazz = (Class) classMap.get(propertyPrefix + key);
+ if (clazz == null) {
+ clazz = newInstance(doFindFactoryProperies(key), propertyPrefix);
+ classMap.put(propertyPrefix + key, clazz);
+ }
+ return clazz.newInstance();
+ }
+
+ private Class newInstance(Properties properties, String propertyPrefix) throws ClassNotFoundException, IOException {
+
+ String className = properties.getProperty(propertyPrefix + "class");
+ if (className == null) {
+ throw new IOException("Expected property is missing: " + propertyPrefix + "class");
+ }
+ Class clazz;
+ try {
+ clazz = Thread.currentThread().getContextClassLoader().loadClass(className);
+ } catch (ClassNotFoundException e) {
+ clazz = FactoryFinder.class.getClassLoader().loadClass(className);
+ }
+
+ return clazz;
+ }
+
+ private Properties doFindFactoryProperies(String key) throws IOException {
+ String uri = path + key;
+
+ // lets try the thread context class loader first
+ InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(uri);
+ if (in == null) {
+ in = FactoryFinder.class.getClassLoader().getResourceAsStream(uri);
+ if (in == null) {
+ throw new IOException("Could not find factory class for resource: " + uri);
+ }
+ }
+
+ // lets load the file
+ BufferedInputStream reader = null;
+ try {
+ reader = new BufferedInputStream(in);
+ Properties properties = new Properties();
+ properties.load(reader);
+ return properties;
+ } finally {
+ try {
+ reader.close();
+ } catch (Exception e) {
+ }
+ }
+ }
+}
\ No newline at end of file
Modified: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java?view=diff&rev=467891&r1=467890&r2=467891
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java (original)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/jdbc/JDBCAdapterFactory.java Wed Oct 25 23:55:18 2006
@@ -19,9 +19,9 @@
import java.sql.Connection;
import java.sql.SQLException;
-import org.apache.activeio.util.FactoryFinder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.finder.FactoryFinder;
import org.apache.servicemix.jdbc.adapter.DefaultJDBCAdapter;
public class JDBCAdapterFactory {
Modified: incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java?view=diff&rev=467891&r1=467890&r2=467891
==============================================================================
--- incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java (original)
+++ incubator/servicemix/trunk/servicemix-services/src/main/java/org/apache/servicemix/store/jdbc/JdbcStore.java Wed Oct 25 23:55:18 2006
@@ -16,13 +16,13 @@
*/
package org.apache.servicemix.store.jdbc;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.sql.Connection;
-import org.apache.activeio.util.ByteArrayInputStream;
-import org.apache.activeio.util.ByteArrayOutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.servicemix.store.Store;