From 35b26fdd32a8ba41e266d3e7c88626fedc32fe34 Mon Sep 17 00:00:00 2001 From: edwardsmj Date: Fri, 8 May 2009 12:01:56 +0000 Subject: Updates and additions to add preResolve phase to contribution processing (See TUSCANY-3012) git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@772949 13f79535-47bb-0310-9956-ffa450edef68 --- .../DefaultURLArtifactProcessorExtensionPoint.java | 29 ++++++++++----- .../processor/ExtendedArtifactProcessor.java | 41 ++++++++++++++++++++++ .../processor/ExtendedURLArtifactProcessor.java | 30 ++++++++++++++++ 3 files changed, 92 insertions(+), 8 deletions(-) create mode 100644 java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java create mode 100644 java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedURLArtifactProcessor.java (limited to 'java/sca') 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 f318525bce..d3dbc66609 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 @@ -119,7 +119,8 @@ public class DefaultURLArtifactProcessorExtensionPoint extends } } - @Override + @SuppressWarnings("unchecked") + @Override public URLArtifactProcessor getProcessor(Class modelType) { loadProcessors(); return (URLArtifactProcessor)super.getProcessor(modelType); @@ -145,7 +146,8 @@ public class DefaultURLArtifactProcessorExtensionPoint extends return processors; } - public URLArtifactProcessor getProcessor(Object artifactType) { + @SuppressWarnings("unchecked") + public URLArtifactProcessor getProcessor(Object artifactType) { Collection> processors = getProcessors(artifactType); return processors.isEmpty() ? null : processors.iterator().next(); } @@ -242,7 +244,7 @@ public class DefaultURLArtifactProcessorExtensionPoint extends String modelTypeName = attributes.get("model"); // Create a processor wrapper and register it - URLArtifactProcessor processor = + URLArtifactProcessor processor = new LazyURLArtifactProcessor(artifactType, modelTypeName, processorDeclaration, extensionPoints, staxProcessor, monitor); addArtifactProcessor(processor); @@ -255,13 +257,13 @@ public class DefaultURLArtifactProcessorExtensionPoint extends * A wrapper around an Artifact processor class allowing lazy loading and * initialization of artifact processors. */ - private static class LazyURLArtifactProcessor implements URLArtifactProcessor { + private static class LazyURLArtifactProcessor implements ExtendedURLArtifactProcessor { private ExtensionPointRegistry extensionPoints; private String artifactType; private String modelTypeName; private ServiceDeclaration processorDeclaration; - private URLArtifactProcessor processor; + private URLArtifactProcessor processor; private Class modelType; private StAXArtifactProcessor staxProcessor; private Monitor monitor; @@ -353,7 +355,18 @@ public class DefaultURLArtifactProcessorExtensionPoint extends @SuppressWarnings("unchecked") public void resolve(Object model, ModelResolver resolver) throws ContributionResolveException { getProcessor().resolve(model, resolver); - } + } // end method resolve + + /** + * Preresolve phase, for ExtendedURLArtifactProcessors only + */ + @SuppressWarnings("unchecked") + public void preResolve( Object model, ModelResolver resolver ) throws ContributionResolveException { + URLArtifactProcessor processor = getProcessor(); + if( processor instanceof ExtendedURLArtifactProcessor ) { + ((ExtendedURLArtifactProcessor)processor).preResolve(model, resolver); + } // end if + } // end method resolve - } -} + } // end class LazyURLArtifactProcessor +} // end class DefaultURLArtifactProcessorExtensionPoint diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java new file mode 100644 index 0000000000..ba8844b41a --- /dev/null +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedArtifactProcessor.java @@ -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.contribution.processor; + +import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * Interface for extended Artifact Processors which require a pre-resolve phase prior to the resolve phase + * + * @version $Rev: 704156 $ $Date: 2008-10-13 17:31:59 +0100 (Mon, 13 Oct 2008) $ + */ +public interface ExtendedArtifactProcessor extends ArtifactProcessor { + + /** + * Pre-resolve references from this model to other models. Used for models where initial setup of + * the resolve phase is required. An example is Contribution models with imports and exports which must + * be set up prior to the main resolve phase + * + * @param model The model to resolve + * @param resolver The resolver to use to resolve referenced models + */ + void preResolve(M model, ModelResolver resolver) throws ContributionResolveException; + +} // end interface diff --git a/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedURLArtifactProcessor.java b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedURLArtifactProcessor.java new file mode 100644 index 0000000000..872b9804ce --- /dev/null +++ b/java/sca/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/ExtendedURLArtifactProcessor.java @@ -0,0 +1,30 @@ +/* + * 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 extended artifact processor that can read models from a URL. + * + * @version $Rev: 704156 $ $Date: 2008-10-13 17:31:59 +0100 (Mon, 13 Oct 2008) $ + */ +public interface ExtendedURLArtifactProcessor extends ExtendedArtifactProcessor, URLArtifactProcessor { + +} // end interface -- cgit v1.2.3