summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java37
-rw-r--r--java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java45
2 files changed, 53 insertions, 29 deletions
diff --git a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java
index c19949d77f..f9228efd71 100644
--- a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java
+++ b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultModuleActivatorExtensionPoint.java
@@ -20,9 +20,13 @@
package org.apache.tuscany.sca.core;
import java.io.IOException;
+import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.apache.tuscany.sca.extensibility.ServiceDeclaration;
import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
@@ -33,6 +37,7 @@ import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
* @version $Rev$ $Date$
*/
public class DefaultModuleActivatorExtensionPoint implements ModuleActivatorExtensionPoint {
+ private final static Logger logger = Logger.getLogger(DefaultModuleActivatorExtensionPoint.class.getName());
private List<ModuleActivator> activators = new ArrayList<ModuleActivator>();
private boolean loadedActivators;
@@ -72,17 +77,31 @@ public class DefaultModuleActivatorExtensionPoint implements ModuleActivatorExte
}
// Load and instantiate module activators
- for (ServiceDeclaration activatorDeclaration: activatorDeclarations) {
- ModuleActivator activator;
+ for (ServiceDeclaration activatorDeclaration : activatorDeclarations) {
+ if (logger.isLoggable(Level.FINE)) {
+ logger.fine("Loading " + activatorDeclaration.getClassName());
+ }
+ ModuleActivator activator = null;
try {
Class<ModuleActivator> activatorClass = (Class<ModuleActivator>)activatorDeclaration.loadClass();
- activator = activatorClass.newInstance();
- } catch (ClassNotFoundException e) {
- throw new IllegalArgumentException(e);
- } catch (InstantiationException e) {
- throw new IllegalArgumentException(e);
- } catch (IllegalAccessException e) {
- throw new IllegalArgumentException(e);
+ Constructor<ModuleActivator> constructor = null;
+ try {
+ constructor = activatorClass.getConstructor();
+ activator = constructor.newInstance();
+ } catch (NoSuchMethodException e) {
+ // Try the one that takes a Map<String, String>
+ constructor = activatorClass.getConstructor(Map.class);
+ activator = constructor.newInstance(activatorDeclaration.getAttributes());
+ }
+ } catch (Throwable e) {
+ String optional = activatorDeclaration.getAttributes().get("optional");
+ if ("true".equalsIgnoreCase(optional)) {
+ // If the optional flag is true, just log the error
+ logger.log(Level.SEVERE, e.getMessage(), e);
+ continue;
+ } else {
+ throw new IllegalArgumentException(e);
+ }
}
addModuleActivator(activator);
}
diff --git a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java
index e059a55ad0..c7ff4e1858 100644
--- a/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java
+++ b/java/sca/modules/extensibility/src/main/java/org/apache/tuscany/sca/core/DefaultUtilityExtensionPoint.java
@@ -6,15 +6,15 @@
* 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.
+ * under the License.
*/
package org.apache.tuscany.sca.core;
@@ -38,11 +38,11 @@ import org.apache.tuscany.sca.extensibility.ServiceDiscovery;
*/
public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint {
private Map<Class<?>, Object> utilities = new ConcurrentHashMap<Class<?>, Object>();
-
+
private ExtensionPointRegistry extensionPoints;
-
+
/**
- * Constructs a new extension point.
+ * Constructs a new extension point.
*/
public DefaultUtilityExtensionPoint(ExtensionPointRegistry extensionPoints) {
this.extensionPoints = extensionPoints;
@@ -66,8 +66,8 @@ public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint {
utilities.put(i, utility);
}
}
-
- private Constructor<?> getConstructor(Constructor<?>[] constructors, Class<?>[] paramTypes) {
+
+ private Constructor<?> getConstructor(Constructor<?>[] constructors, Class<?>... paramTypes) {
for (Constructor<?> c : constructors) {
Class<?>[] types = c.getParameterTypes();
if (c.getParameterTypes().length == paramTypes.length) {
@@ -150,28 +150,32 @@ public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint {
utility = utilities.get(utilityType);
}
if (utility == null) {
-
- // Dynamically load a utility class declared under META-INF/services/"utilityType"
+
+ // Dynamically load a utility class declared under META-INF/services/"utilityType"
try {
- ServiceDeclaration utilityDeclaration =ServiceDiscovery.getInstance().getServiceDeclaration(utilityType.getName());
+ ServiceDeclaration utilityDeclaration =
+ ServiceDiscovery.getInstance().getServiceDeclaration(utilityType.getName());
if (utilityDeclaration != null) {
Class<?> utilityClass = utilityDeclaration.loadClass();
-
+
// Construct the utility
Constructor<?>[] constructors = utilityClass.getConstructors();
- Constructor<?> constructor = getConstructor(constructors, new Class<?>[] {ExtensionPointRegistry.class});
+ Constructor<?> constructor = getConstructor(constructors, ExtensionPointRegistry.class, Map.class);
if (constructor != null) {
- utility = constructor.newInstance(extensionPoints);
+ utility = constructor.newInstance(extensionPoints, utilityDeclaration.getAttributes());
} else {
- constructor = getConstructor(constructors, new Class<?>[] {});
+ constructor = getConstructor(constructors, ExtensionPointRegistry.class);
if (constructor != null) {
- utility = constructor.newInstance();
+ utility = constructor.newInstance(extensionPoints);
} else {
- throw new IllegalArgumentException(
- "No valid constructor is found for " + utilityClass);
+ constructor = getConstructor(constructors);
+ if (constructor != null) {
+ utility = constructor.newInstance();
+ } else {
+ throw new IllegalArgumentException("No valid constructor is found for " + utilityClass);
+ }
}
}
-
// Cache the loaded utility
addUtility(utility);
}
@@ -187,6 +191,7 @@ public class DefaultUtilityExtensionPoint implements UtilityExtensionPoint {
throw new IllegalArgumentException(e);
}
}
- return utilityType.cast(utility); }
+ return utilityType.cast(utility);
+ }
}