You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2008/03/07 07:35:54 UTC
svn commit: r634558 - in
/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca:
core/ provider/
Author: rfeng
Date: Thu Mar 6 22:35:52 2008
New Revision: 634558
URL: http://svn.apache.org/viewvc?rev=634558&view=rev
Log:
Add PolicyProviderFactory/PolicyProvider SPIs to allow policy providers to contribute interceptors
Added:
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java (with props)
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java (with props)
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java (with props)
Modified:
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java
incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java
Modified: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java?rev=634558&r1=634557&r2=634558&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java (original)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/core/DefaultExtensionPointRegistry.java Thu Mar 6 22:35:52 2008
@@ -131,10 +131,10 @@
private static void getAllInterfaces(Class clazz, Set<Class> implemented) {
Class[] interfaces = clazz.getInterfaces();
for (Class interfaze : interfaces) {
- String name = interfaze.getName();
- if (name.startsWith("java.") || name.startsWith("javax.")) {
- continue;
- }
+// String name = interfaze.getName();
+// if (name.startsWith("java.") || name.startsWith("javax.")) {
+// continue;
+// }
if (Modifier.isPublic(interfaze.getModifiers())) {
implemented.add(interfaze);
}
Modified: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java?rev=634558&r1=634557&r2=634558&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java (original)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/DefaultProviderFactoryExtensionPoint.java Thu Mar 6 22:35:52 2008
@@ -41,9 +41,10 @@
* @version $Rev$ $Date$
*/
public class DefaultProviderFactoryExtensionPoint implements ProviderFactoryExtensionPoint {
-
+
private ExtensionPointRegistry registry;
private final Map<Class<?>, ProviderFactory> providerFactories = new HashMap<Class<?>, ProviderFactory>();
+ private final List<PolicyProviderFactory> policyProviderFactories = new ArrayList<PolicyProviderFactory>();
private boolean loaded;
/**
@@ -60,18 +61,24 @@
* @param providerFactory The provider factory
*/
public void addProviderFactory(ProviderFactory providerFactory) {
+ if(providerFactory instanceof PolicyProviderFactory) {
+ policyProviderFactories.add((PolicyProviderFactory)providerFactory);
+ }
providerFactories.put(providerFactory.getModelType(), providerFactory);
}
-
+
/**
* Remove a provider factory.
*
* @param providerFactory The provider factory
*/
public void removeProviderFactory(ProviderFactory providerFactory) {
+ if(providerFactory instanceof PolicyProviderFactory) {
+ policyProviderFactories.remove((PolicyProviderFactory)providerFactory);
+ }
providerFactories.remove(providerFactory.getModelType());
}
-
+
/**
* Returns the provider factory associated with the given model type.
* @param modelType A model type
@@ -79,7 +86,7 @@
*/
public ProviderFactory getProviderFactory(Class<?> modelType) {
loadProviderFactories();
-
+
Class<?>[] classes = modelType.getInterfaces();
for (Class<?> c : classes) {
ProviderFactory factory = providerFactories.get(c);
@@ -90,6 +97,11 @@
return providerFactories.get(modelType);
}
+ public List<PolicyProviderFactory> getPolicyProviderFactories() {
+ loadProviderFactories();
+ return policyProviderFactories;
+ }
+
/**
* Load provider factories declared under META-INF/services.
* @param registry
@@ -100,10 +112,11 @@
loadProviderFactories(BindingProviderFactory.class);
loadProviderFactories(ImplementationProviderFactory.class);
-
+ loadProviderFactories(PolicyProviderFactory.class);
+
loaded = true;
}
-
+
/**
* Load provider factories declared under META-INF/services.
* @param registry
@@ -113,27 +126,29 @@
private List<ProviderFactory> loadProviderFactories(Class<?> factoryClass) {
// Get the provider factory service declarations
- Set<ServiceDeclaration> factoryDeclarations;
+ Set<ServiceDeclaration> factoryDeclarations;
ServiceDiscovery serviceDiscovery = ServiceDiscovery.getInstance();
try {
factoryDeclarations = serviceDiscovery.getServiceDeclarations(factoryClass);
} catch (Exception e) {
throw new IllegalStateException(e);
}
-
+
// Get the target extension point
- ProviderFactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+ ProviderFactoryExtensionPoint factoryExtensionPoint =
+ registry.getExtensionPoint(ProviderFactoryExtensionPoint.class);
List<ProviderFactory> factories = new ArrayList<ProviderFactory>();
-
- for (ServiceDeclaration factoryDeclaration: factoryDeclarations) {
+
+ for (ServiceDeclaration factoryDeclaration : factoryDeclarations) {
Map<String, String> attributes = factoryDeclaration.getAttributes();
-
+
// Load an implementation provider factory
if (factoryClass == ImplementationProviderFactory.class) {
String modelTypeName = attributes.get("model");
-
+
// Create a provider factory wrapper and register it
- ImplementationProviderFactory factory = new LazyImplementationProviderFactory(registry, modelTypeName, factoryDeclaration);
+ ImplementationProviderFactory factory =
+ new LazyImplementationProviderFactory(registry, modelTypeName, factoryDeclaration);
factoryExtensionPoint.addProviderFactory(factory);
factories.add(factory);
@@ -141,11 +156,22 @@
// Load a binding provider factory
String modelTypeName = attributes.get("model");
-
+
+ // Create a provider factory wrapper and register it
+ BindingProviderFactory factory =
+ new LazyBindingProviderFactory(registry, modelTypeName, factoryDeclaration);
+ factoryExtensionPoint.addProviderFactory(factory);
+ factories.add(factory);
+ } else if (factoryClass == PolicyProviderFactory.class) {
+ // Load a policy provider factory
+ String modelTypeName = attributes.get("model");
+
// Create a provider factory wrapper and register it
- BindingProviderFactory factory = new LazyBindingProviderFactory(registry, modelTypeName, factoryDeclaration);
+ PolicyProviderFactory factory =
+ new LazyPolicyProviderFactory(registry, modelTypeName, factoryDeclaration);
factoryExtensionPoint.addProviderFactory(factory);
factories.add(factory);
+
}
}
return factories;
@@ -162,10 +188,10 @@
private ServiceDeclaration factoryDeclaration;
private BindingProviderFactory factory;
private Class modelType;
-
- private LazyBindingProviderFactory(ExtensionPointRegistry registry,
- String modelTypeName,
- ServiceDeclaration factoryDeclaration) {
+
+ private LazyBindingProviderFactory(ExtensionPointRegistry registry,
+ String modelTypeName,
+ ServiceDeclaration factoryDeclaration) {
this.registry = registry;
this.modelTypeName = modelTypeName;
this.factoryDeclaration = factoryDeclaration;
@@ -175,8 +201,10 @@
private BindingProviderFactory getFactory() {
if (factory == null) {
try {
- Class<BindingProviderFactory> factoryClass = (Class<BindingProviderFactory>)factoryDeclaration.loadClass();
- Constructor<BindingProviderFactory> constructor = factoryClass.getConstructor(ExtensionPointRegistry.class);
+ Class<BindingProviderFactory> factoryClass =
+ (Class<BindingProviderFactory>)factoryDeclaration.loadClass();
+ Constructor<BindingProviderFactory> constructor =
+ factoryClass.getConstructor(ExtensionPointRegistry.class);
factory = constructor.newInstance(registry);
} catch (Exception e) {
throw new IllegalStateException(e);
@@ -186,19 +214,23 @@
}
@SuppressWarnings("unchecked")
- public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, Binding binding) {
+ public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding) {
return getFactory().createReferenceBindingProvider(component, reference, binding);
}
-
+
@SuppressWarnings("unchecked")
- public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, Binding binding) {
+ public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding) {
return getFactory().createServiceBindingProvider(component, service, binding);
}
-
+
public Class getModelType() {
if (modelType == null) {
try {
- modelType = factoryDeclaration.loadClass(modelTypeName);
+ modelType = factoryDeclaration.loadClass(modelTypeName);
} catch (Exception e) {
throw new IllegalStateException(e);
}
@@ -219,8 +251,10 @@
private ServiceDeclaration providerClass;
private ImplementationProviderFactory factory;
private Class modelType;
-
- private LazyImplementationProviderFactory(ExtensionPointRegistry registry, String modelTypeName, ServiceDeclaration providerClass) {
+
+ private LazyImplementationProviderFactory(ExtensionPointRegistry registry,
+ String modelTypeName,
+ ServiceDeclaration providerClass) {
this.registry = registry;
this.modelTypeName = modelTypeName;
this.providerClass = providerClass;
@@ -230,8 +264,10 @@
private ImplementationProviderFactory getFactory() {
if (factory == null) {
try {
- Class<ImplementationProviderFactory> factoryClass = (Class<ImplementationProviderFactory>)providerClass.loadClass();
- Constructor<ImplementationProviderFactory> constructor = factoryClass.getConstructor(ExtensionPointRegistry.class);
+ Class<ImplementationProviderFactory> factoryClass =
+ (Class<ImplementationProviderFactory>)providerClass.loadClass();
+ Constructor<ImplementationProviderFactory> constructor =
+ factoryClass.getConstructor(ExtensionPointRegistry.class);
factory = constructor.newInstance(registry);
} catch (Exception e) {
throw new IllegalStateException(e);
@@ -241,14 +277,79 @@
}
@SuppressWarnings("unchecked")
- public ImplementationProvider createImplementationProvider(RuntimeComponent component, Implementation Implementation) {
+ public ImplementationProvider createImplementationProvider(RuntimeComponent component,
+ Implementation Implementation) {
return getFactory().createImplementationProvider(component, Implementation);
}
public Class getModelType() {
if (modelType == null) {
try {
-
+
+ modelType = providerClass.loadClass(modelTypeName);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return modelType;
+ }
+
+ }
+
+ /**
+ * A wrapper around an policy provider factory allowing lazy
+ * loading and initialization of policy providers.
+ */
+ private class LazyPolicyProviderFactory implements PolicyProviderFactory {
+ private ExtensionPointRegistry registry;
+ private String modelTypeName;
+ private ServiceDeclaration providerClass;
+ private PolicyProviderFactory factory;
+ private Class modelType;
+
+ private LazyPolicyProviderFactory(ExtensionPointRegistry registry,
+ String modelTypeName,
+ ServiceDeclaration providerClass) {
+ this.registry = registry;
+ this.modelTypeName = modelTypeName;
+ this.providerClass = providerClass;
+ }
+
+ @SuppressWarnings("unchecked")
+ private PolicyProviderFactory getFactory() {
+ if (factory == null) {
+ try {
+ Class<PolicyProviderFactory> factoryClass = (Class<PolicyProviderFactory>)providerClass.loadClass();
+ Constructor<PolicyProviderFactory> constructor =
+ factoryClass.getConstructor(ExtensionPointRegistry.class);
+ factory = constructor.newInstance(registry);
+ } catch (Exception e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ return factory;
+ }
+
+ public PolicyProvider createImplementationPolicyProvider(RuntimeComponent component,
+ Implementation implementation) {
+ return getFactory().createImplementationPolicyProvider(component, implementation);
+ }
+
+ public PolicyProvider createReferencePolicyProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding) {
+ return getFactory().createReferencePolicyProvider(component, reference, binding);
+ }
+
+ public PolicyProvider createServicePolicyProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding) {
+ return getFactory().createServicePolicyProvider(component, service, binding);
+ }
+
+ public Class getModelType() {
+ if (modelType == null) {
+ try {
modelType = providerClass.loadClass(modelTypeName);
} catch (Exception e) {
throw new IllegalStateException(e);
Added: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java?rev=634558&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java (added)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java Thu Mar 6 22:35:52 2008
@@ -0,0 +1,38 @@
+/*
+ * 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.tuscany.sca.provider;
+
+import java.util.List;
+
+import javax.xml.namespace.QName;
+
+/**
+ * This interface can be optionally implemented by the Binding or Implementation providers to
+ * indicate if they implement the policies in the binding/implementation provider.
+ *
+ * @version $Rev$ $Date$
+ */
+public interface PolicyImplementor {
+ /**
+ * Get a list of policy names that are implemented by this policy implementor
+ * @return A list of policy names
+ */
+ List<QName> getImplementedPolicies();
+}
Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyImplementor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java?rev=634558&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java (added)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java Thu Mar 6 22:35:52 2008
@@ -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.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface PolicyProvider {
+ /**
+ * Create an interceptor for a given operation
+ * @param operation
+ * @return An interceptor that realize the policySet
+ */
+ Interceptor createInterceptor(Operation operation);
+
+ /**
+ * Get the phase that the interceptor should be added
+ * @return The phase that this interceptor belongs to
+ */
+ String getPhase();
+}
Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProvider.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Added: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java?rev=634558&view=auto
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java (added)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java Thu Mar 6 22:35:52 2008
@@ -0,0 +1,63 @@
+/*
+ * 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.tuscany.sca.provider;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.assembly.Implementation;
+import org.apache.tuscany.sca.policy.Policy;
+import org.apache.tuscany.sca.runtime.RuntimeComponent;
+import org.apache.tuscany.sca.runtime.RuntimeComponentReference;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public interface PolicyProviderFactory<M extends Policy> extends ProviderFactory<M> {
+ /**
+ * Create policy provider for a given reference binding
+ * @param component
+ * @param reference
+ * @param binding
+ * @return
+ */
+ PolicyProvider createReferencePolicyProvider(RuntimeComponent component,
+ RuntimeComponentReference reference,
+ Binding binding);
+
+ /**
+ * Create policy provider for a given service binding
+ * @param component
+ * @param service
+ * @param binding
+ * @return
+ */
+ PolicyProvider createServicePolicyProvider(RuntimeComponent component,
+ RuntimeComponentService service,
+ Binding binding);
+
+ /**
+ * Create policy provider for a given component implementation
+ * @param component
+ * @param implementation
+ * @return
+ */
+ PolicyProvider createImplementationPolicyProvider(RuntimeComponent component, Implementation implementation);
+
+}
Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/PolicyProviderFactory.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Modified: incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java
URL: http://svn.apache.org/viewvc/incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java?rev=634558&r1=634557&r2=634558&view=diff
==============================================================================
--- incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java (original)
+++ incubator/tuscany/java/sca/modules/core-spi/src/main/java/org/apache/tuscany/sca/provider/ProviderFactoryExtensionPoint.java Thu Mar 6 22:35:52 2008
@@ -19,6 +19,8 @@
package org.apache.tuscany.sca.provider;
+import java.util.List;
+
/**
* An extension point for provider factories. Holds all of the provider
@@ -51,5 +53,11 @@
* @return The provider factory associated with the given model type
*/
ProviderFactory getProviderFactory(Class<?> modelType);
+
+ /**
+ * Get a list of registered PolicyProviderFactory
+ * @return a list of registered PolicyProviderFactory
+ */
+ List<PolicyProviderFactory> getPolicyProviderFactories();
}
---------------------------------------------------------------------
To unsubscribe, e-mail: tuscany-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: tuscany-commits-help@ws.apache.org