diff options
Diffstat (limited to 'sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz')
10 files changed, 0 insertions, 745 deletions
diff --git a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/DefaultImportExportXYZFactory.java b/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/DefaultImportExportXYZFactory.java deleted file mode 100644 index b9a7bf6c0c..0000000000 --- a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/DefaultImportExportXYZFactory.java +++ /dev/null @@ -1,28 +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.imprt.xyz; - -/** - * Default Import/Export model factory implementation - * - * @version $Rev$ $Date$ - */ -public class DefaultImportExportXYZFactory extends ImportExportXYZFactoryImpl implements ImportExportXYZFactory { -} diff --git a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZ.java b/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZ.java deleted file mode 100644 index b099cfee11..0000000000 --- a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZ.java +++ /dev/null @@ -1,60 +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.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/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZImpl.java b/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZImpl.java deleted file mode 100644 index 6e98979b5d..0000000000 --- a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZImpl.java +++ /dev/null @@ -1,64 +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.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/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZModelResolver.java b/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZModelResolver.java deleted file mode 100644 index c3d2663d62..0000000000 --- a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZModelResolver.java +++ /dev/null @@ -1,54 +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.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/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZProcessor.java b/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZProcessor.java deleted file mode 100644 index 7d4aafa31f..0000000000 --- a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ExportXYZProcessor.java +++ /dev/null @@ -1,171 +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.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.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; -import org.apache.tuscany.sca.monitor.impl.ProblemImpl; - - -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/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactory.java b/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactory.java deleted file mode 100644 index db2bab7f99..0000000000 --- a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactory.java +++ /dev/null @@ -1,27 +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.imprt.xyz; - -public interface ImportExportXYZFactory { - - ImportXYZ createImport(); - - ExportXYZ createExport(); -} diff --git a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactoryImpl.java b/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactoryImpl.java deleted file mode 100644 index b0a9c80d88..0000000000 --- a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportExportXYZFactoryImpl.java +++ /dev/null @@ -1,32 +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.imprt.xyz; - -public class ImportExportXYZFactoryImpl implements ImportExportXYZFactory { - - public ImportXYZ createImport() { - return new ImportXYZImpl(); - } - - public ExportXYZ createExport() { - return new ExportXYZImpl(); - } - -} diff --git a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZ.java b/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZ.java deleted file mode 100644 index 3e883e84a2..0000000000 --- a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZ.java +++ /dev/null @@ -1,59 +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.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/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZImpl.java b/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZImpl.java deleted file mode 100644 index ef3f0653f3..0000000000 --- a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZImpl.java +++ /dev/null @@ -1,79 +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.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) { - if (export instanceof ExportXYZ){ - return anAttribute.equals(((ExportXYZ)export).getAnAttribute()); - } - return false; - } - - @Override - public String toString() { - return String.valueOf(URI); - } -} diff --git a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZProcessor.java b/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZProcessor.java deleted file mode 100644 index 763fa30002..0000000000 --- a/sca-java-1.x/tags/1.5.1-RC4/itest/workspace-manager/src/main/java/org/apache/tuscany/sca/imprt/xyz/ImportXYZProcessor.java +++ /dev/null @@ -1,171 +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.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.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; -import org.apache.tuscany.sca.monitor.impl.ProblemImpl; - -/** - * 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 { - } -} |