diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-24 17:48:23 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2009-07-24 17:48:23 +0000 |
commit | 00b04245e37062f04461a2f67ee79cff72c9a956 (patch) | |
tree | 2a4aa55a167aa6e10a738ddf9183370761d78c32 /branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz | |
parent | 38f008a47e7f76d39938264babf2da3508a1903a (diff) |
TUSCANY-3174 - add an itest to update the extension point registry programmatically with some dummy XYZ extensions and process a contribution
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@797577 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz')
11 files changed, 830 insertions, 0 deletions
diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/DefaultImportExportXYZFactory.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/DefaultImportExportXYZFactory.java new file mode 100644 index 0000000000..b9a7bf6c0c --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/DefaultImportExportXYZFactory.java @@ -0,0 +1,28 @@ +/* + * 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.imprt.xyz; + +/** + * Default Import/Export model factory implementation + * + * @version $Rev$ $Date$ + */ +public class DefaultImportExportXYZFactory extends ImportExportXYZFactoryImpl implements ImportExportXYZFactory { +} diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZ.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZ.java new file mode 100644 index 0000000000..b099cfee11 --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZ.java @@ -0,0 +1,60 @@ +/* + * 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.imprt.xyz; + +import org.apache.tuscany.sca.contribution.Export; + + +/** + * The model of an export. + * + * @version $Rev$ $Date$ + */ +public interface ExportXYZ extends Export { + + /** + * Get the uri of the contributions + * + * @return The URI + */ + String getURI(); + + /** + * Set the uri of the contributions + * + * @param URI + */ + void setURI(String URI); + + /** + * Get anAttribute + * + * @return anAttribute + */ + String getAnAttribute(); + + /** + * Set anAttribute + * + * @param anAttribute + */ + void setAnAttribute(String anAttribute); + +} diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZImpl.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZImpl.java new file mode 100644 index 0000000000..6e98979b5d --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZImpl.java @@ -0,0 +1,64 @@ +/* + * 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.imprt.xyz; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The model of an export + * + * @version $Rev$ $Date$ + */ +public class ExportXYZImpl extends ExtensibleImpl implements ExportXYZ { + private String URI; + private String anAttribute; + private ModelResolver modelResolver; + + protected ExportXYZImpl() { + super(); + } + + public String getURI() { + return URI; + } + + public void setURI(String URI) { + this.URI = URI; + } + + public String getAnAttribute() { + return anAttribute; + } + + public void setAnAttribute(String anAttribute) { + this.anAttribute = anAttribute; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + +} diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZModelResolver.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZModelResolver.java new file mode 100644 index 0000000000..c3d2663d62 --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZModelResolver.java @@ -0,0 +1,54 @@ +/* + * 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.imprt.xyz; + +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * A model resolver for exports. + * + * @version $Rev$ $Date$ + */ +public class ExportXYZModelResolver implements ModelResolver { + + private ModelResolver resolver; + + public ExportXYZModelResolver(ModelResolver resolver) { + this.resolver = resolver; + } + + public void addModel(Object resolved) { + throw new IllegalStateException(); + } + + public Object removeModel(Object resolved) { + throw new IllegalStateException(); + } + + public <T> T resolveModel(Class<T> modelClass, T unresolved) { + + // Just delegate to the contribution's model resolver, namespace + // based filtering is implemented in the model specific model + // resolver, which know how to get the namespace of the particular + // type of model that they handle + return resolver.resolveModel(modelClass, unresolved); + } + +} diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZProcessor.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZProcessor.java new file mode 100644 index 0000000000..31d435a12a --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZProcessor.java @@ -0,0 +1,171 @@ +/* + * 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.imprt.xyz; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + + +public class ExportXYZProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<ExportXYZ> { + + private static final String NS = "http://someuri"; + private static final QName EXPORT = new QName(NS, "export.xyz"); + private static final String URI = "uri"; + private static final String AN_ATTRIBUTE = "anAttribute"; + + private final ImportExportXYZFactory factory; + private final Monitor monitor; + private final ExtensionFactory extensionFactory; + + + public ExportXYZProcessor(ModelFactoryExtensionPoint modelFactories, + Monitor monitor) { + this.factory = modelFactories.getFactory(ImportExportXYZFactory.class); + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + this.monitor = monitor; + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "export-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "export-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return EXPORT; + } + + public Class<ExportXYZ> getModelType() { + return ExportXYZ.class; + } + + + public ExportXYZ read(XMLStreamReader reader) throws ContributionReadException { + ExportXYZ export = this.factory.createExport(); + QName element = null; + + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read <export> + if (EXPORT.equals(element)) { + String ns = reader.getAttributeValue(null, URI); + if (ns == null) { + error("AttributeNameSpaceMissing", reader); + } else { + export.setURI(ns); + } + + String anAttribute = reader.getAttributeValue(null, AN_ATTRIBUTE); + export.setAnAttribute(anAttribute); + } + + break; + case XMLStreamConstants.END_ELEMENT: + if (EXPORT.equals(reader.getName())) { + return export; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return export; + } + + public void write(ExportXYZ export, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write <export> + writer.writeStartElement(EXPORT.getNamespaceURI(), EXPORT.getLocalPart()); + + if (export.getURI() != null) { + writer.writeAttribute(URI, export.getURI()); + } + + if (export.getAnAttribute() != null) { + writer.writeAttribute(AN_ATTRIBUTE, export.getAnAttribute()); + } + + writer.writeEndElement(); + } + + public void resolve(ExportXYZ export, ModelResolver resolver) throws ContributionResolveException { + + if (export.getURI() != null) + // Initialize the export's resolver + export.setModelResolver(new ExportXYZModelResolver(resolver)); + } +} diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactory.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactory.java new file mode 100644 index 0000000000..db2bab7f99 --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactory.java @@ -0,0 +1,27 @@ +/* + * 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.imprt.xyz; + +public interface ImportExportXYZFactory { + + ImportXYZ createImport(); + + ExportXYZ createExport(); +} diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactoryImpl.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactoryImpl.java new file mode 100644 index 0000000000..b0a9c80d88 --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactoryImpl.java @@ -0,0 +1,32 @@ +/* + * 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.imprt.xyz; + +public class ImportExportXYZFactoryImpl implements ImportExportXYZFactory { + + public ImportXYZ createImport() { + return new ImportXYZImpl(); + } + + public ExportXYZ createExport() { + return new ExportXYZImpl(); + } + +} diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZListener.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZListener.java new file mode 100644 index 0000000000..3b0ff19ce9 --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZListener.java @@ -0,0 +1,88 @@ +/* + * 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.imprt.xyz; + +import org.apache.tuscany.sca.contribution.Contribution; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.Import; +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.resolver.DefaultImportAllModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionListener; +import org.apache.tuscany.sca.contribution.service.ContributionRepository; + + +/* + * IS THIS REALLY REQUIRED NOW? + */ +public class ImportExportXYZListener implements ContributionListener { + + + public void contributionAdded(ContributionRepository repository, Contribution contribution) { + // Initialize the contribution exports + for (Export export: contribution.getExports()) { + export.setModelResolver(contribution.getModelResolver()); + } + + // Initialize the contribution imports + for (Import import_: contribution.getImports()) { + boolean initialized = false; + + if (import_ instanceof NamespaceImport) { + NamespaceImport namespaceImport = (NamespaceImport)import_; + + // Find a matching contribution + if (namespaceImport.getLocation() != null) { + Contribution targetContribution = repository.getContribution(namespaceImport.getLocation()); + if (targetContribution != null) { + + // Find a matching contribution export + for (Export export: targetContribution.getExports()) { + if (export instanceof NamespaceExport) { + NamespaceExport namespaceExport = (NamespaceExport)export; + if (namespaceImport.getNamespace().equals(namespaceExport.getNamespace())) { + namespaceImport.setModelResolver(namespaceExport.getModelResolver()); + initialized = true; + break; + } + } + } + } + } + + //if no location was specified, try to resolve with any contribution + if( !initialized ) { + // Use a resolver that will consider all contributions + import_.setModelResolver(new DefaultImportAllModelResolver(import_, repository.getContributions())); + } + } + } + + } + + public void contributionRemoved(ContributionRepository repository, Contribution contribution) { + + } + + public void contributionUpdated(ContributionRepository repository, Contribution oldContribution, Contribution contribution) { + + } + +} diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZ.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZ.java new file mode 100644 index 0000000000..3e883e84a2 --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZ.java @@ -0,0 +1,59 @@ +/* + * 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.imprt.xyz; + +import org.apache.tuscany.sca.contribution.Import; + +/** + * The representation of an XML namespace import. + * + * @version $Rev$ $Date$ + */ +public interface ImportXYZ extends Import { + + /** + * Get the uri of the contributions + * + * @return The URI + */ + String getURI(); + + /** + * Set the uri of the contributions + * + * @param URI + */ + void setURI(String URI); + + /** + * Get anAttribute + * + * @return anAttribute + */ + String getAnAttribute(); + + /** + * Set anAttribute + * + * @param anAttribute + */ + void setAnAttribute(String anAttribute); + +}
\ No newline at end of file diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZImpl.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZImpl.java new file mode 100644 index 0000000000..d9ea8495f3 --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZImpl.java @@ -0,0 +1,76 @@ +/* + * 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.imprt.xyz; + +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; +import org.apache.tuscany.sca.contribution.Export; +import org.apache.tuscany.sca.contribution.namespace.NamespaceExport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; + +/** + * The representation of an import for the contribution + * + * @version $Rev$ $Date$ + */ +public class ImportXYZImpl extends ExtensibleImpl implements ImportXYZ { + private ModelResolver modelResolver; + + private String URI; + private String anAttribute; + + + protected ImportXYZImpl() { + super(); + } + + public String getURI() { + return URI; + } + + public void setURI(String URI) { + this.URI = URI; + } + + public String getAnAttribute() { + return anAttribute; + } + + public void setAnAttribute(String anAttribute) { + this.anAttribute = anAttribute; + } + + public ModelResolver getModelResolver() { + return modelResolver; + } + + public void setModelResolver(ModelResolver modelResolver) { + this.modelResolver = modelResolver; + } + + public boolean match(Export export) { + return false; + } + + @Override + public String toString() { + return String.valueOf(URI); + } +} diff --git a/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZProcessor.java b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZProcessor.java new file mode 100644 index 0000000000..7083eb5821 --- /dev/null +++ b/branches/sca-java-1.x/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZProcessor.java @@ -0,0 +1,171 @@ +/* + * 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.imprt.xyz; + +import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; + +import javax.xml.namespace.QName; +import javax.xml.stream.XMLStreamConstants; +import javax.xml.stream.XMLStreamException; +import javax.xml.stream.XMLStreamReader; +import javax.xml.stream.XMLStreamWriter; + +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.assembly.builder.impl.ProblemImpl; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; +import org.apache.tuscany.sca.contribution.namespace.NamespaceImportExportFactory; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXAttributeProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.monitor.Monitor; +import org.apache.tuscany.sca.monitor.Problem; +import org.apache.tuscany.sca.monitor.Problem.Severity; + +/** + * Artifact processor for Namespace import + * + * @version $Rev$ $Date$ + */ +public class ImportXYZProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<ImportXYZ> { + private static final String NS = "http://someuri"; + + private static final QName IMPORT = new QName(NS, "import.xyz"); + + private static final String URI = "uri"; + private static final String AN_ATTRIBUTE = "anAttribute"; + + private final ImportExportXYZFactory factory; + private final ExtensionFactory extensionFactory; + private final Monitor monitor; + + public ImportXYZProcessor(ModelFactoryExtensionPoint modelFactories, + Monitor monitor) { + this.factory = modelFactories.getFactory(ImportExportXYZFactory.class); + this.monitor = monitor; + this.extensionFactory = modelFactories.getFactory(ExtensionFactory.class); + } + + /** + * Report a warning. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); + monitor.problem(problem); + } + } + + /** + * Report a exception. + * + * @param problems + * @param message + * @param model + */ + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = new ProblemImpl(this.getClass().getName(), "contribution-namespace-validation-messages", Severity.ERROR, model, message, ex); + monitor.problem(problem); + } + } + + public QName getArtifactType() { + return IMPORT; + } + + public Class<ImportXYZ> getModelType() { + return ImportXYZ.class; + } + + public ImportXYZ read(XMLStreamReader reader) throws ContributionReadException { + ImportXYZ importXYZ= this.factory.createImport(); + QName element; + + try { + while (reader.hasNext()) { + int event = reader.getEventType(); + switch (event) { + case START_ELEMENT: + element = reader.getName(); + + // Read <import> + if (IMPORT.equals(element)) { + String ns = reader.getAttributeValue(null, URI); + if (ns == null) { + error("AttributeNameSpaceMissing", reader); + } else { + importXYZ.setURI(ns); + } + + String anAttribute = reader.getAttributeValue(null, AN_ATTRIBUTE); + if (anAttribute != null) { + importXYZ.setAnAttribute(anAttribute); + } + } + break; + case XMLStreamConstants.END_ELEMENT: + if (IMPORT.equals(reader.getName())) { + return importXYZ; + } + break; + } + + // Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + } + catch (XMLStreamException e) { + ContributionReadException ex = new ContributionReadException(e); + error("XMLStreamException", reader, ex); + } + + return importXYZ; + } + + public void write(ImportXYZ importXYZ, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write <import> + writer.writeStartElement(IMPORT.getNamespaceURI(), IMPORT.getLocalPart()); + + if (importXYZ.getURI() != null) { + writer.writeAttribute(URI, importXYZ.getURI()); + } + if (importXYZ.getAnAttribute() != null) { + writer.writeAttribute(AN_ATTRIBUTE, importXYZ.getAnAttribute()); + } + + writer.writeEndElement(); + } + + + public void resolve(ImportXYZ model, ModelResolver resolver) throws ContributionResolveException { + } +} |