diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-01 20:46:33 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-01 20:46:33 +0000 |
commit | 2aa21bba4f123189d0a816018a84d77756686a64 (patch) | |
tree | b094fb3fbc9b89b3f9c8bb9dc3ec7e6ba65609be /java/sca | |
parent | 39498b42068075878199f25292899931c120d768 (diff) |
Clean up the artifact processor extension point
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@761053 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
8 files changed, 407 insertions, 283 deletions
diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java deleted file mode 100644 index 029df61f0f..0000000000 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ArtifactProcessorExtensionPoint.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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.contribution.processor; - -/** - * An extension point for artifact processors. - * - * @version $Rev$ $Date$ - */ -public interface ArtifactProcessorExtensionPoint<P extends ArtifactProcessor> { - - /** - * Add an artifact processor. - * - * @param artifactProcessor The artifact processor to add - */ - void addArtifactProcessor(P artifactProcessor); - - /** - * Remove an artifact processor. - * - * @param artifactProcessor The artifact processor to remove - */ - void removeArtifactProcessor(P artifactProcessor); - - /** - * Returns the processor associated with the given artifact type. - * - * @param artifactType An artifact type - * @return The processor associated with the given artifact type - */ - P getProcessor(Object artifactType); - - /** - * Returns the processor associated with the given model type. - * - * @param modelType A model type - * @return The processor associated with the given model type - */ - P getProcessor(Class<?> modelType); - -} diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java index 3c67a8c550..c871e4c868 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultArtifactProcessorExtensionPoint.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.contribution.processor; @@ -23,10 +23,10 @@ import java.util.Map; /** * The default implementation of an artifact processor extension point. - * + * * @version $Rev$ $Date$ */ -abstract class DefaultArtifactProcessorExtensionPoint<P> { +abstract class DefaultArtifactProcessorExtensionPoint<P extends ArtifactProcessor<?>> { protected final Map<Object, P> processorsByArtifactType = new HashMap<Object, P>(); protected final Map<Class<?>, P> processorsByModelType = new HashMap<Class<?>, P>(); @@ -38,7 +38,7 @@ abstract class DefaultArtifactProcessorExtensionPoint<P> { /** * Returns the processor associated with the given artifact type. - * + * * @param artifactType An artifact type * @return The processor associated with the given artifact type */ @@ -48,11 +48,11 @@ abstract class DefaultArtifactProcessorExtensionPoint<P> { /** * Returns the processor associated with the given model type. - * + * * @param modelType A model type * @return The processor associated with the given model type */ - public P getProcessor(Class<?> modelType) { + public <T> P getProcessor(Class<T> modelType) { Class<?>[] classes = modelType.getInterfaces(); for (Class<?> c : classes) { P processor = processorsByModelType.get(c); diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java index a531eb9ddd..d1443f1162 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXArtifactProcessorExtensionPoint.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.contribution.processor; @@ -43,11 +43,11 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; /** * The default implementation of an extension point for StAX artifact processors. - * + * * @version $Rev$ $Date$ */ public class DefaultStAXArtifactProcessorExtensionPoint extends - DefaultArtifactProcessorExtensionPoint<StAXArtifactProcessor> implements StAXArtifactProcessorExtensionPoint { + DefaultArtifactProcessorExtensionPoint<StAXArtifactProcessor<?>> implements StAXArtifactProcessorExtensionPoint { private ExtensionPointRegistry extensionPoints; private FactoryExtensionPoint modelFactories; @@ -68,28 +68,37 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); if (monitorFactory != null) - this.monitor = monitorFactory.createMonitor(); - this.extensibleStAXProcessor = new ExtensibleStAXArtifactProcessor(this, inputFactory, outputFactory, this.monitor); - - StAXAttributeProcessorExtensionPoint attributeExtensionPoint = extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); - this.extensibleStAXAttributeProcessor = new ExtensibleStAXAttributeProcessor(attributeExtensionPoint ,inputFactory, outputFactory, this.monitor); + this.monitor = monitorFactory.createMonitor(); + this.extensibleStAXProcessor = + new ExtensibleStAXArtifactProcessor(this, inputFactory, outputFactory, this.monitor); + + StAXAttributeProcessorExtensionPoint attributeExtensionPoint = + extensionPoints.getExtensionPoint(StAXAttributeProcessorExtensionPoint.class); + this.extensibleStAXAttributeProcessor = + new ExtensibleStAXAttributeProcessor(attributeExtensionPoint, inputFactory, outputFactory, this.monitor); } - + /** * Report a exception. - * + * * @param problems * @param message * @param model */ private void error(String message, Object model, Exception ex) { if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } + Problem problem = + monitor.createProblem(this.getClass().getName(), + "contribution-validation-messages", + Severity.ERROR, + model, + message, + ex); + monitor.problem(problem); + } } - public void addArtifactProcessor(StAXArtifactProcessor artifactProcessor) { + public void addArtifactProcessor(StAXArtifactProcessor<?> artifactProcessor) { if (artifactProcessor.getArtifactType() != null) { processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); } @@ -98,7 +107,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends } } - public void removeArtifactProcessor(StAXArtifactProcessor artifactProcessor) { + public void removeArtifactProcessor(StAXArtifactProcessor<?> artifactProcessor) { if (artifactProcessor.getArtifactType() != null) { processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); } @@ -108,13 +117,13 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends } @Override - public StAXArtifactProcessor getProcessor(Class<?> modelType) { + public <T> StAXArtifactProcessor<T> getProcessor(Class<T> modelType) { loadArtifactProcessors(); - return super.getProcessor(modelType); + return (StAXArtifactProcessor<T>)super.getProcessor(modelType); } @Override - public StAXArtifactProcessor getProcessor(Object artifactType) { + public StAXArtifactProcessor<?> getProcessor(Object artifactType) { loadArtifactProcessors(); return super.getProcessor(artifactType); } @@ -122,7 +131,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends /** * Returns a QName object from a QName expressed as {ns}name * or ns#name. - * + * * @param qname * @return */ @@ -142,7 +151,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends return new QName(qname.substring(0, h), qname.substring(h + 1)); } } - throw new IllegalArgumentException("Invalid qname: "+qname); + throw new IllegalArgumentException("Invalid qname: " + qname); } /** @@ -155,10 +164,11 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends // Get the processor service declarations Set<ServiceDeclaration> processorDeclarations; try { - processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXArtifactProcessor.class.getName()); + processorDeclarations = + ServiceDiscovery.getInstance().getServiceDeclarations(StAXArtifactProcessor.class.getName()); } catch (IOException e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", extensibleStAXProcessor, ie); + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", extensibleStAXProcessor, ie); throw ie; } @@ -173,14 +183,14 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends // Get the model class name String modelTypeName = attributes.get("model"); - // Get the model factory class name + // Get the model factory class name String factoryName = attributes.get("factory"); // Create a processor wrapper and register it - StAXArtifactProcessor processor = - new LazyStAXArtifactProcessor(artifactType, modelTypeName, factoryName, - processorDeclaration, extensionPoints, modelFactories, - extensibleStAXProcessor,extensibleStAXAttributeProcessor, monitor); + StAXArtifactProcessor<?> processor = + new LazyStAXArtifactProcessor(artifactType, modelTypeName, factoryName, processorDeclaration, + extensionPoints, modelFactories, extensibleStAXProcessor, + extensibleStAXAttributeProcessor, monitor); addArtifactProcessor(processor); } @@ -198,7 +208,7 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends private String modelTypeName; private String factoryName; private ServiceDeclaration processorDeclaration; - private StAXArtifactProcessor processor; + private StAXArtifactProcessor<?> processor; private Class<?> modelType; private StAXArtifactProcessor<Object> extensionProcessor; private StAXAttributeProcessor<Object> extensionAttributeProcessor; @@ -227,12 +237,18 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends public QName getArtifactType() { return artifactType; } - + private void error(String message, Object model, Exception ex) { if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } + Problem problem = + monitor.createProblem(this.getClass().getName(), + "contribution-validation-messages", + Severity.ERROR, + model, + message, + ex); + monitor.problem(problem); + } } @SuppressWarnings("unchecked") @@ -243,7 +259,8 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends .equals("org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor")) { // Specific initialization for the DefaultBeanModelProcessor - FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + FactoryExtensionPoint modelFactories = + extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); try { Class<StAXArtifactProcessor> processorClass = (Class<StAXArtifactProcessor>)processorDeclaration.loadClass(); @@ -261,84 +278,109 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends Object.class, Monitor.class); processor = - constructor.newInstance(modelFactories, - artifactType, - getModelType(), - modelFactory, - monitor); + constructor + .newInstance(modelFactories, artifactType, getModelType(), modelFactory, monitor); } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processor, ie); + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processor, ie); throw ie; } } else { - FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); + FactoryExtensionPoint modelFactories = + extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); // Load and instantiate the processor class try { - Class<StAXArtifactProcessor> processorClass = - (Class<StAXArtifactProcessor>)processorDeclaration.loadClass(); - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class); - processor = constructor.newInstance(modelFactories, monitor); - } catch (NoSuchMethodException e) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, monitor); - } catch (NoSuchMethodException e1) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor, monitor); - } catch (NoSuchMethodException e2) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class, StAXAttributeProcessor.class, Monitor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor, extensionAttributeProcessor, monitor); - } catch (NoSuchMethodException e2a) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor); - } catch (NoSuchMethodException e3) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, StAXAttributeProcessor.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor, extensionAttributeProcessor, monitor); - } catch (NoSuchMethodException e3a) { - - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class); - processor = constructor.newInstance(modelFactories); - } catch (NoSuchMethodException e4) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class); - processor = constructor.newInstance(extensionPoints); - } catch (NoSuchMethodException e4a) { - try { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor); - } catch (NoSuchMethodException e5) { - Constructor<StAXArtifactProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor); - } - } - } - } - } - } - } - } - } + Class<StAXArtifactProcessor> processorClass = + (Class<StAXArtifactProcessor>)processorDeclaration.loadClass(); + try { + Constructor<StAXArtifactProcessor> constructor = + processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class); + processor = constructor.newInstance(modelFactories, monitor); + } catch (NoSuchMethodException e) { + try { + Constructor<StAXArtifactProcessor> constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); + processor = constructor.newInstance(extensionPoints, monitor); + } catch (NoSuchMethodException e1) { + try { + Constructor<StAXArtifactProcessor> constructor = + processorClass.getConstructor(FactoryExtensionPoint.class, + StAXArtifactProcessor.class, + Monitor.class); + processor = constructor.newInstance(modelFactories, extensionProcessor, monitor); + } catch (NoSuchMethodException e2) { + try { + Constructor<StAXArtifactProcessor> constructor = + processorClass.getConstructor(FactoryExtensionPoint.class, + StAXArtifactProcessor.class, + StAXAttributeProcessor.class, + Monitor.class); + processor = + constructor.newInstance(modelFactories, + extensionProcessor, + extensionAttributeProcessor, + monitor); + } catch (NoSuchMethodException e2a) { + try { + Constructor<StAXArtifactProcessor> constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, + StAXArtifactProcessor.class, + Monitor.class); + processor = + constructor.newInstance(extensionPoints, extensionProcessor, monitor); + } catch (NoSuchMethodException e3) { + try { + Constructor<StAXArtifactProcessor> constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, + StAXArtifactProcessor.class, + StAXAttributeProcessor.class, + Monitor.class); + processor = + constructor.newInstance(extensionPoints, + extensionProcessor, + extensionAttributeProcessor, + monitor); + } catch (NoSuchMethodException e3a) { + + try { + Constructor<StAXArtifactProcessor> constructor = + processorClass.getConstructor(FactoryExtensionPoint.class); + processor = constructor.newInstance(modelFactories); + } catch (NoSuchMethodException e4) { + try { + Constructor<StAXArtifactProcessor> constructor = + processorClass.getConstructor(ExtensionPointRegistry.class); + processor = constructor.newInstance(extensionPoints); + } catch (NoSuchMethodException e4a) { + try { + Constructor<StAXArtifactProcessor> constructor = + processorClass + .getConstructor(FactoryExtensionPoint.class, + StAXArtifactProcessor.class); + processor = + constructor.newInstance(modelFactories, + extensionProcessor); + } catch (NoSuchMethodException e5) { + Constructor<StAXArtifactProcessor> constructor = + processorClass + .getConstructor(ExtensionPointRegistry.class, + StAXArtifactProcessor.class); + processor = + constructor.newInstance(extensionPoints, + extensionProcessor); + } + } + } + } + } + } + } + } + } } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processor, ie); + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processor, ie); throw ie; } } @@ -361,8 +403,8 @@ public class DefaultStAXArtifactProcessorExtensionPoint extends try { modelType = processorDeclaration.loadClass(modelTypeName); } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processorDeclaration, ie); + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processorDeclaration, ie); throw ie; } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java index 3cdcddc976..789752fd17 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultStAXAttributeProcessorExtensionPoint.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.contribution.processor; @@ -43,11 +43,11 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; /** * The default implementation of an extension point for StAX artifact processors. - * + * * @version $Rev$ $Date$ */ public class DefaultStAXAttributeProcessorExtensionPoint extends - DefaultArtifactProcessorExtensionPoint<StAXAttributeProcessor> implements StAXAttributeProcessorExtensionPoint { + DefaultArtifactProcessorExtensionPoint<StAXAttributeProcessor<?>> implements StAXAttributeProcessorExtensionPoint { private ExtensionPointRegistry extensionPoints; private FactoryExtensionPoint modelFactories; @@ -66,26 +66,33 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends UtilityExtensionPoint utilities = this.extensionPoints.getExtensionPoint(UtilityExtensionPoint.class); MonitorFactory monitorFactory = utilities.getUtility(MonitorFactory.class); if (monitorFactory != null) { - this.monitor = monitorFactory.createMonitor(); + this.monitor = monitorFactory.createMonitor(); } - this.extensibleStAXAttributeProcessor = new ExtensibleStAXAttributeProcessor(this, inputFactory, outputFactory, this.monitor); + this.extensibleStAXAttributeProcessor = + new ExtensibleStAXAttributeProcessor(this, inputFactory, outputFactory, this.monitor); } - + /** * Report a exception. - * + * * @param problems * @param message * @param model */ private void error(String message, Object model, Exception ex) { if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } + Problem problem = + monitor.createProblem(this.getClass().getName(), + "contribution-validation-messages", + Severity.ERROR, + model, + message, + ex); + monitor.problem(problem); + } } - public void addArtifactProcessor(StAXAttributeProcessor artifactProcessor) { + public void addArtifactProcessor(StAXAttributeProcessor<?> artifactProcessor) { if (artifactProcessor.getArtifactType() != null) { processorsByArtifactType.put((Object)artifactProcessor.getArtifactType(), artifactProcessor); } @@ -94,7 +101,7 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends } } - public void removeArtifactProcessor(StAXAttributeProcessor artifactProcessor) { + public void removeArtifactProcessor(StAXAttributeProcessor<?> artifactProcessor) { if (artifactProcessor.getArtifactType() != null) { processorsByArtifactType.remove((Object)artifactProcessor.getArtifactType()); } @@ -104,13 +111,13 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends } @Override - public StAXAttributeProcessor getProcessor(Class<?> modelType) { + public <T> StAXAttributeProcessor<T> getProcessor(Class<T> modelType) { loadArtifactProcessors(); - return super.getProcessor(modelType); + return (StAXAttributeProcessor<T>)super.getProcessor(modelType); } @Override - public StAXAttributeProcessor getProcessor(Object artifactType) { + public StAXAttributeProcessor<?> getProcessor(Object artifactType) { loadArtifactProcessors(); return super.getProcessor(artifactType); } @@ -118,7 +125,7 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends /** * Returns a QName object from a QName expressed as {ns}name * or ns#name. - * + * * @param qname * @return */ @@ -138,7 +145,7 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends return new QName(qname.substring(0, h), qname.substring(h + 1)); } } - throw new IllegalArgumentException("Invalid qname: "+qname); + throw new IllegalArgumentException("Invalid qname: " + qname); } /** @@ -151,10 +158,11 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends // Get the processor service declarations Set<ServiceDeclaration> processorDeclarations; try { - processorDeclarations = ServiceDiscovery.getInstance().getServiceDeclarations(StAXAttributeProcessor.class.getName()); + processorDeclarations = + ServiceDiscovery.getInstance().getServiceDeclarations(StAXAttributeProcessor.class.getName()); } catch (IOException e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", extensibleStAXAttributeProcessor, ie); + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", extensibleStAXAttributeProcessor, ie); throw ie; } @@ -169,14 +177,14 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends // Get the model class name String modelTypeName = attributes.get("model"); - // Get the model factory class name + // Get the model factory class name String factoryName = attributes.get("factory"); // Create a processor wrapper and register it - StAXAttributeProcessor processor = - new LazyStAXAttributeProcessor(artifactType, modelTypeName, factoryName, - processorDeclaration, extensionPoints, modelFactories, - extensibleStAXAttributeProcessor, monitor); + StAXAttributeProcessor<?> processor = + new LazyStAXAttributeProcessor(artifactType, modelTypeName, factoryName, processorDeclaration, + extensionPoints, modelFactories, extensibleStAXAttributeProcessor, + monitor); addArtifactProcessor(processor); } @@ -194,19 +202,19 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends private String modelTypeName; private String factoryName; private ServiceDeclaration processorDeclaration; - private StAXAttributeProcessor processor; + private StAXAttributeProcessor<?> processor; private Class<?> modelType; private StAXAttributeProcessor<Object> extensionProcessor; private Monitor monitor; LazyStAXAttributeProcessor(QName artifactType, - String modelTypeName, - String factoryName, - ServiceDeclaration processorDeclaration, - ExtensionPointRegistry extensionPoints, - FactoryExtensionPoint modelFactories, - StAXAttributeProcessor<Object> extensionProcessor, - Monitor monitor) { + String modelTypeName, + String factoryName, + ServiceDeclaration processorDeclaration, + ExtensionPointRegistry extensionPoints, + FactoryExtensionPoint modelFactories, + StAXAttributeProcessor<Object> extensionProcessor, + Monitor monitor) { this.extensionPoints = extensionPoints; this.artifactType = artifactType; @@ -220,12 +228,18 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends public QName getArtifactType() { return artifactType; } - + private void error(String message, Object model, Exception ex) { if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "contribution-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } + Problem problem = + monitor.createProblem(this.getClass().getName(), + "contribution-validation-messages", + Severity.ERROR, + model, + message, + ex); + monitor.problem(problem); + } } @SuppressWarnings("unchecked") @@ -242,49 +256,56 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends processorClass.getConstructor(FactoryExtensionPoint.class, Monitor.class); processor = constructor.newInstance(modelFactories, monitor); } catch (NoSuchMethodException e) { - try { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, monitor); - } catch (NoSuchMethodException e1) { try { Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor, monitor); - } catch (NoSuchMethodException e2) { + processorClass.getConstructor(ExtensionPointRegistry.class, Monitor.class); + processor = constructor.newInstance(extensionPoints, monitor); + } catch (NoSuchMethodException e1) { try { Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class, Monitor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor); - } catch (NoSuchMethodException e3) { + processorClass.getConstructor(FactoryExtensionPoint.class, + StAXArtifactProcessor.class, + Monitor.class); + processor = constructor.newInstance(modelFactories, extensionProcessor, monitor); + } catch (NoSuchMethodException e2) { try { Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class); - processor = constructor.newInstance(modelFactories); - } catch (NoSuchMethodException e4) { - try { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class); - processor = constructor.newInstance(extensionPoints); - } catch (NoSuchMethodException e4a) { + processorClass.getConstructor(ExtensionPointRegistry.class, + StAXArtifactProcessor.class, + Monitor.class); + processor = constructor.newInstance(extensionPoints, extensionProcessor, monitor); + } catch (NoSuchMethodException e3) { try { Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(FactoryExtensionPoint.class, StAXArtifactProcessor.class); - processor = constructor.newInstance(modelFactories, extensionProcessor); - } catch (NoSuchMethodException e5) { - Constructor<StAXAttributeProcessor> constructor = - processorClass.getConstructor(ExtensionPointRegistry.class, StAXArtifactProcessor.class); - processor = constructor.newInstance(extensionPoints, extensionProcessor); + processorClass.getConstructor(FactoryExtensionPoint.class); + processor = constructor.newInstance(modelFactories); + } catch (NoSuchMethodException e4) { + try { + Constructor<StAXAttributeProcessor> constructor = + processorClass.getConstructor(ExtensionPointRegistry.class); + processor = constructor.newInstance(extensionPoints); + } catch (NoSuchMethodException e4a) { + try { + Constructor<StAXAttributeProcessor> constructor = + processorClass.getConstructor(FactoryExtensionPoint.class, + StAXArtifactProcessor.class); + processor = constructor.newInstance(modelFactories, extensionProcessor); + } catch (NoSuchMethodException e5) { + Constructor<StAXAttributeProcessor> constructor = + processorClass.getConstructor(ExtensionPointRegistry.class, + StAXArtifactProcessor.class); + processor = + constructor.newInstance(extensionPoints, extensionProcessor); + } + } } - } } } } - } } } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processor, ie); + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processor, ie); throw ie; } @@ -292,12 +313,14 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends return processor; } - public Object read(QName attributeName, XMLStreamReader inputSource) throws ContributionReadException, XMLStreamException { + public Object read(QName attributeName, XMLStreamReader inputSource) throws ContributionReadException, + XMLStreamException { return getProcessor().read(attributeName, inputSource); } @SuppressWarnings("unchecked") - public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, XMLStreamException { + public void write(Object model, XMLStreamWriter outputSource) throws ContributionWriteException, + XMLStreamException { getProcessor().write(model, outputSource); } @@ -306,8 +329,8 @@ public class DefaultStAXAttributeProcessorExtensionPoint extends try { modelType = processorDeclaration.loadClass(modelTypeName); } catch (Exception e) { - IllegalStateException ie = new IllegalStateException(e); - error("IllegalStateException", processorDeclaration, ie); + IllegalStateException ie = new IllegalStateException(e); + error("IllegalStateException", processorDeclaration, ie); throw ie; } } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java index 99b5b3d8b0..8ec9fe419f 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/DefaultURLArtifactProcessorExtensionPoint.java @@ -22,6 +22,10 @@ import java.io.IOException; import java.lang.reflect.Constructor; import java.net.URI; import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.regex.Pattern; @@ -46,7 +50,7 @@ import org.apache.tuscany.sca.monitor.Problem.Severity; * @version $Rev$ $Date$ */ public class DefaultURLArtifactProcessorExtensionPoint extends - DefaultArtifactProcessorExtensionPoint<URLArtifactProcessor> implements URLArtifactProcessorExtensionPoint { + DefaultArtifactProcessorExtensionPoint<URLArtifactProcessor<?>> implements URLArtifactProcessorExtensionPoint { private ExtensionPointRegistry extensionPoints; private StAXArtifactProcessor<?> staxProcessor; @@ -90,7 +94,7 @@ public class DefaultURLArtifactProcessorExtensionPoint extends } } - public void addArtifactProcessor(URLArtifactProcessor artifactProcessor) { + public void addArtifactProcessor(URLArtifactProcessor<?> artifactProcessor) { if (artifactProcessor.getArtifactType() != null) { Pattern pattern = Pattern.compile(wildcard2regex(artifactProcessor.getArtifactType())); processorsByArtifactType.put(pattern, artifactProcessor); @@ -100,7 +104,7 @@ public class DefaultURLArtifactProcessorExtensionPoint extends } } - public void removeArtifactProcessor(URLArtifactProcessor artifactProcessor) { + public void removeArtifactProcessor(URLArtifactProcessor<?> artifactProcessor) { if (artifactProcessor.getArtifactType() != null) { String regex = wildcard2regex(artifactProcessor.getArtifactType()); for (Object key : processorsByArtifactType.keySet()) { @@ -116,51 +120,74 @@ public class DefaultURLArtifactProcessorExtensionPoint extends } @Override - public URLArtifactProcessor getProcessor(Class<?> modelType) { + public <T> URLArtifactProcessor<T> getProcessor(Class<T> modelType) { loadProcessors(); - return super.getProcessor(modelType); + return (URLArtifactProcessor<T>)super.getProcessor(modelType); } - @Override - public URLArtifactProcessor getProcessor(Object artifactType) { + public Collection<URLArtifactProcessor<?>> getProcessors(Object artifactType) { loadProcessors(); - URLArtifactProcessor processor = null; String uri = (String)artifactType; if (uri.endsWith("/")) { // Ignore directories - return null; + return Collections.emptyList(); } if (!uri.startsWith("/")) { uri = "/" + uri; } - for (Object key : processorsByArtifactType.keySet()) { - Pattern pattern = (Pattern)key; + List<URLArtifactProcessor<?>> processors = new ArrayList<URLArtifactProcessor<?>>(); + for (Map.Entry<Object, URLArtifactProcessor<?>> e : processorsByArtifactType.entrySet()) { + Pattern pattern = (Pattern)e.getKey(); if (pattern.matcher(uri).matches()) { - return processorsByArtifactType.get(key); + processors.add(e.getValue()); } } - return processor; + return processors; + } + + public URLArtifactProcessor<?> getProcessor(Object artifactType) { + Collection<URLArtifactProcessor<?>> processors = getProcessors(artifactType); + return processors.isEmpty() ? null : processors.iterator().next(); } - private String wildcard2regex(String wildcard) { + private static String wildcard2regex(String pattern) { + String wildcard = pattern; + if (wildcard.endsWith("/")) { + // Directory: xyz/ --> xyz/** + wildcard = wildcard + "**"; + } if (wildcard.startsWith(".")) { - // File extension + // File extension: .xyz --> **/*.xyz wildcard = "**/*" + wildcard; } else if (wildcard.indexOf('/') == -1) { - // file name + // File name: abc.txt --> **/abc.txt wildcard = "**/" + wildcard; } else if (!(wildcard.startsWith("/") || wildcard.startsWith("**"))) { wildcard = '/' + wildcard; } + System.out.println(pattern +"-->" + wildcard); StringBuffer regex = new StringBuffer(); char[] chars = wildcard.toCharArray(); for (int i = 0; i < chars.length; i++) { switch (chars[i]) { case '*': if (i < chars.length - 1 && chars[i + 1] == '*') { - regex.append(".*"); - i++; // Skip next * + // Next char is '*' + if (i < chars.length - 2) { + if (chars[i + 2] == '/') { + // The wildcard is **/, it matches zero or more directories + regex.append("(.*/)*"); + i += 2; // Skip */ + } else { + // ** can only be followed by / + throw new IllegalArgumentException("** can only be used as the name for a directory"); + } + } else { + regex.append(".*"); + i++; // Skip next * + } } else { + // Non-directory regex.append("[^/]*"); } break; diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java index 9700e2bc60..0cfcf004b2 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXArtifactProcessorExtensionPoint.java @@ -6,24 +6,51 @@ * 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.contribution.processor; /** * An extension point for StAX artifact processors. - * + * * @version $Rev$ $Date$ */ -public interface StAXArtifactProcessorExtensionPoint extends - ArtifactProcessorExtensionPoint<StAXArtifactProcessor> { +public interface StAXArtifactProcessorExtensionPoint { + /** + * Add an artifact processor. + * + * @param artifactProcessor The artifact processor to add + */ + void addArtifactProcessor(StAXArtifactProcessor<?> artifactProcessor); + /** + * Remove an artifact processor. + * + * @param artifactProcessor The artifact processor to remove + */ + void removeArtifactProcessor(StAXArtifactProcessor<?> artifactProcessor); + + /** + * Returns the processor associated with the given artifact type. + * + * @param artifactType An artifact type + * @return The processor associated with the given artifact type + */ + <T> StAXArtifactProcessor<T> getProcessor(Object artifactType); + + /** + * Returns the processor associated with the given model type. + * + * @param modelType A model type + * @return The processor associated with the given model type + */ + <T> StAXArtifactProcessor<T> getProcessor(Class<T> modelType); } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java index ebad243c1c..dbc0a2c7bc 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/StAXAttributeProcessorExtensionPoint.java @@ -6,24 +6,51 @@ * 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.contribution.processor; /** * An extension point for StAX artifact processors. - * + * * @version $Rev$ $Date$ */ -public interface StAXAttributeProcessorExtensionPoint extends - ArtifactProcessorExtensionPoint<StAXAttributeProcessor> { +public interface StAXAttributeProcessorExtensionPoint { + /** + * Add an artifact processor. + * + * @param artifactProcessor The artifact processor to add + */ + void addArtifactProcessor(StAXAttributeProcessor<?> artifactProcessor); + /** + * Remove an artifact processor. + * + * @param artifactProcessor The artifact processor to remove + */ + void removeArtifactProcessor(StAXAttributeProcessor<?> artifactProcessor); + + /** + * Returns the processor associated with the given artifact type. + * + * @param artifactType An artifact type + * @return The processor associated with the given artifact type + */ + <T> StAXAttributeProcessor<T> getProcessor(Object artifactType); + + /** + * Returns the processor associated with the given model type. + * + * @param modelType A model type + * @return The processor associated with the given model type + */ + <T> StAXAttributeProcessor<T> getProcessor(Class<T> modelType); } diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java index 7714586951..4806d443eb 100644 --- a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/URLArtifactProcessorExtensionPoint.java @@ -6,24 +6,60 @@ * 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.contribution.processor; +import java.util.Collection; + /** * An extension point for URL artifact processors. - * + * * @version $Rev$ $Date$ */ -public interface URLArtifactProcessorExtensionPoint extends - ArtifactProcessorExtensionPoint<URLArtifactProcessor> { - +public interface URLArtifactProcessorExtensionPoint { + /** + * Add an artifact processor. + * + * @param artifactProcessor The artifact processor to add + */ + void addArtifactProcessor(URLArtifactProcessor<?> artifactProcessor); + + /** + * Remove an artifact processor. + * + * @param artifactProcessor The artifact processor to remove + */ + void removeArtifactProcessor(URLArtifactProcessor<?> artifactProcessor); + + /** + * Returns the processor associated with the given artifact type. + * + * @param artifactType An artifact type + * @return The processor associated with the given artifact type + */ + <T> URLArtifactProcessor<T> getProcessor(Object artifactType); + + /** + * Returns the processor associated with the given model type. + * + * @param modelType A model type + * @return The processor associated with the given model type + */ + <T> URLArtifactProcessor<T> getProcessor(Class<T> modelType); + + /** + * Return a collection of artifact processors that match the artifactType + * @param artifactType + * @return A collection of processors + */ + Collection<URLArtifactProcessor<?>> getProcessors(Object artifactType); } |