diff options
author | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-22 21:51:38 +0000 |
---|---|---|
committer | rfeng <rfeng@13f79535-47bb-0310-9956-ffa450edef68> | 2009-04-22 21:51:38 +0000 |
commit | b354c03aecb7f30bfd65f0ec02a81ab915ba4966 (patch) | |
tree | 569564504b982d2a5bfb3ab3052c0c5130fcae28 /branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca | |
parent | baa5887866a52cd40be16707d9741cbbad9d7263 (diff) |
Add "Extensible" support for the ContributionMetaData/Contribution/Import/Export models (TUSCANY-2983)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@767683 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca')
11 files changed, 246 insertions, 180 deletions
diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java index 7400501d85..84a6a9a8f9 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Artifact.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; @@ -24,63 +24,51 @@ import org.apache.tuscany.sca.assembly.Base; /** * Represents an artifact in an SCA contribution. - * + * * @version $Rev$ $Date$ */ public interface Artifact extends Base { - + /** * Returns the URI that unique identifies the artifact inside the contribution. - * + * * @return The artifact URI */ String getURI(); - + /** * Sets the URI that uniquely identifies the artifact inside the contribution. - * + * * @param uri The artifact URI */ void setURI(String uri); /** * Returns the location of the artifact. - * + * * @return The artifact location */ String getLocation(); - + /** * Set the location of the artifact. - * + * * @param location The artifact location */ void setLocation(String location); - + /** * Returns the in-memory model representing the artifact. - * + * * @return The model object */ Object getModel(); - + /** * Sets the in-memory model representing the artifact. - * + * * @param model The model object */ void setModel(Object model); - - /** - * Returns the contents of the artifact cached here. - * @return the contents of the artifact - */ - byte[] getContents(); - - /** - * Sets the contents of the artifact. - * @param contents the contents of the artifact - */ - void setContents(byte[] contents); } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java index 84a927628d..0076e1c89f 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Contribution.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; @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.contribution; import java.util.List; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Extensible; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** @@ -29,48 +30,48 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; * * @version $Rev$ $Date$ */ -public interface Contribution extends Artifact { - +public interface Contribution extends Artifact, Extensible { + /** * Default location of contribution metadata in an SCA contribution. */ String SCA_CONTRIBUTION_META = "META-INF/sca-contribution.xml"; - + /** * Default location of a generated contribution metadata in an SCA contribution. */ String SCA_CONTRIBUTION_GENERATED_META = "META-INF/sca-contribution-generated.xml"; - + /** * Default location of deployable composites in an SCA contribution. */ String SCA_CONTRIBUTION_DEPLOYABLES = "META-INF/sca-deployables/"; - + /** * Returns a list of exports based on the contribution metadata. - * + * * @return The list of exports in this contribution */ List<Export> getExports(); /** * Returns a list of imports based on the contribution metadata. - * + * * @return The list of imports in this contribution */ List<Import> getImports(); - + /** * Returns the list of deployable composites in the contribution. - * + * * @return The list of deployable composites */ List<Composite> getDeployables(); /** * Returns the list of artifacts in the contribution. - * + * * @return The list of artifacts in the contribution */ List<Artifact> getArtifacts(); @@ -78,41 +79,41 @@ public interface Contribution extends Artifact { /** * Returns the model resolver for the models representing the artifacts * visible in the scope of this contribution. - * + * * @return The model resolver */ ModelResolver getModelResolver(); - + /** * Sets the model resolver for the models representing the artifacts * visible in the scope of this contribution. - * + * * @param modelResolver The model resolver */ void setModelResolver(ModelResolver modelResolver); - + /** * Returns the ClassLoader used to load classes and resources from * this contribution - * + * * FIXME Remove this, the base contribution model should not depend - * on Java ClassLoaders. - * + * on Java ClassLoaders. + * * @return The contribution ClassLoader */ ClassLoader getClassLoader(); - + /** * Sets the ClassLoader used to load classes and resources from * this contribution - * + * * FIXME Remove this, the base contribution model should not depend - * on Java ClassLoaders. - * + * on Java ClassLoaders. + * * @param classLoader the contribution class loader */ void setClassLoader(ClassLoader classLoader); - + /** * Returns the type string based on the types that appear in * o.a.t.s.contribution.PackageType diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java index 4043fb9eda..5f26c3d907 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/ContributionMetadata.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; @@ -23,31 +23,32 @@ import java.util.List; import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.Extensible; /** * The representation of SCA contribution metadata. * * @version $Rev$ $Date$ */ -public interface ContributionMetadata extends Base { - +public interface ContributionMetadata extends Base, Extensible { + /** * Returns a list of exports based on the contribution metadata. - * + * * @return The list of exports */ List<Export> getExports(); /** * Returns a list of imports based on the contribution metadata. - * + * * @return The list of imports */ List<Import> getImports(); - + /** * Returns the list of deployable based on the contribution metadata. - * + * * @return The list of deployable composites */ List<Composite> getDeployables(); diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java index bfa16b1ce3..a6e5afe7b8 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Export.java @@ -6,42 +6,43 @@ * 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; +import org.apache.tuscany.sca.assembly.Extensible; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an export. - * + * * @version $Rev$ $Date$ */ -public interface Export { +public interface Export extends Extensible { /** * Returns the model resolver for the models representing artifacts * made available by this export. - * + * * @return The model resolver */ ModelResolver getModelResolver(); - + /** * Sets the model resolver for the models representing artifacts * made available by this export. - * + * * @param modelResolver */ void setModelResolver(ModelResolver modelResolver); - + } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java index 35076f55a7..256a2387f1 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/Import.java @@ -6,33 +6,34 @@ * 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; +import org.apache.tuscany.sca.assembly.Extensible; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an import. - * + * * @version $Rev$ $Date$ */ -public interface Import { +public interface Import extends Extensible { /** * Returns the model resolver for the models representing artifacts * made available by this import. - * + * * @return The model resolver */ ModelResolver getModelResolver(); @@ -40,17 +41,17 @@ public interface Import { /** * Sets the model resolver for the models representing artifacts * made available by this import. - * + * * @param modelResolver The model resolver */ void setModelResolver(ModelResolver modelResolver); - + /** * Verify that a specific export actually exports what is being imported. - * + * * @param export The Exported being verified * @return true/false */ boolean match(Export export); - + }
\ No newline at end of file diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java index 881987f622..3ce27d47c3 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ArtifactImpl.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.impl; @@ -24,7 +24,7 @@ import org.apache.tuscany.sca.contribution.Artifact; /** * The model representing an artifact in a contribution. - * + * * @version $Rev$ $Date$ */ class ArtifactImpl implements Artifact { @@ -32,11 +32,10 @@ class ArtifactImpl implements Artifact { private String location; private Object model; private boolean unresolved; - private byte[] contents; ArtifactImpl() { } - + public String getLocation() { return location; } @@ -44,35 +43,27 @@ class ArtifactImpl implements Artifact { public void setLocation(String location) { this.location = location; } - + public String getURI() { return uri; } - + public void setURI(String uri) { this.uri = uri; } - + public Object getModel() { return model; } - + public void setModel(Object model) { this.model = model; } - public byte[] getContents() { - return contents; - } - - public void setContents(byte[] contents) { - this.contents = contents; - } - public boolean isUnresolved() { return unresolved; } - + public void setUnresolved(boolean unresolved) { this.unresolved = unresolved; } @@ -81,7 +72,7 @@ class ArtifactImpl implements Artifact { public int hashCode() { return uri.hashCode(); } - + @Override public boolean equals(Object obj) { if (obj == this) { diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java index dcdbda8ce7..3bad5c3612 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionImpl.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.impl; @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.Artifact; import org.apache.tuscany.sca.contribution.Contribution; import org.apache.tuscany.sca.contribution.Export; @@ -34,7 +35,7 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; * * @version $Rev$ $Date$ */ -class ContributionImpl implements Contribution { +class ContributionImpl extends ExtensibleImpl implements Contribution { private String type; private String uri; private String location; @@ -46,13 +47,13 @@ class ContributionImpl implements Contribution { private List<Composite> deployables = new ArrayList<Composite>(); private List<Artifact> artifacts = new ArrayList<Artifact>(); private ModelResolver modelResolver; - + // FIXME remove this dependency on Java ClassLoaders private ClassLoader classLoader; ContributionImpl() { } - + public String getLocation() { return this.location; } @@ -65,17 +66,17 @@ class ContributionImpl implements Contribution { public ClassLoader getClassLoader() { return classLoader; } - + //FIXME Remove dependency on Java ClassLoaders public void setClassLoader(ClassLoader classLoader) { this.classLoader = classLoader; } - - + + public String getURI() { return this.uri; } - + public void setURI(String uri) { this.uri = uri; } @@ -83,27 +84,27 @@ class ContributionImpl implements Contribution { public Object getModel() { return model; } - + public void setModel(Object model) { this.model = model; } - + public byte[] getContents() { return contents; } - + public void setContents(byte[] contents) { this.contents = contents; } - + public boolean isUnresolved() { return unresolved; } - + public void setUnresolved(boolean unresolved) { this.unresolved = unresolved; } - + public ModelResolver getModelResolver() { return modelResolver; } @@ -111,7 +112,7 @@ class ContributionImpl implements Contribution { public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + public List<Export> getExports() { return exports; } @@ -132,7 +133,7 @@ class ContributionImpl implements Contribution { public int hashCode() { return uri.hashCode(); } - + @Override public boolean equals(Object obj) { if (obj == this) { diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java index 75b12b1260..da8c879a93 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/ContributionMetadataImpl.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.impl; @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.ContributionMetadata; import org.apache.tuscany.sca.contribution.Export; import org.apache.tuscany.sca.contribution.Import; @@ -32,7 +33,7 @@ import org.apache.tuscany.sca.contribution.Import; * * @version $Rev$ $Date$ */ -class ContributionMetadataImpl implements ContributionMetadata { +class ContributionMetadataImpl extends ExtensibleImpl implements ContributionMetadata { private boolean unresolved; private List<Export> exports = new ArrayList<Export>(); private List<Import> imports = new ArrayList<Import>(); @@ -40,15 +41,15 @@ class ContributionMetadataImpl implements ContributionMetadata { ContributionMetadataImpl() { } - + public boolean isUnresolved() { return unresolved; } - + public void setUnresolved(boolean unresolved) { this.unresolved = unresolved; } - + public List<Export> getExports() { return exports; } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java index e67395337a..d4614e5427 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultExportImpl.java @@ -6,40 +6,41 @@ * 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.impl; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.DefaultExport; import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an export for the contribution - * + * * @version $Rev$ $Date$ */ -public class DefaultExportImpl implements DefaultExport { +public class DefaultExportImpl extends ExtensibleImpl implements DefaultExport { private ModelResolver modelResolver; - + protected DefaultExportImpl() { super(); } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java index 17c09f2cbc..7ab535f916 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/impl/DefaultImportImpl.java @@ -6,19 +6,20 @@ * 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.impl; +import org.apache.tuscany.sca.assembly.impl.ExtensibleImpl; import org.apache.tuscany.sca.contribution.DefaultExport; import org.apache.tuscany.sca.contribution.DefaultImport; import org.apache.tuscany.sca.contribution.Export; @@ -26,30 +27,30 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; /** * The representation of an import for the contribution - * + * * @version $Rev$ $Date$ */ -public class DefaultImportImpl implements DefaultImport { +public class DefaultImportImpl extends ExtensibleImpl implements DefaultImport { private ModelResolver modelResolver; protected DefaultImportImpl() { super(); } - + public ModelResolver getModelResolver() { return modelResolver; } - + public void setModelResolver(ModelResolver modelResolver) { this.modelResolver = modelResolver; } - + public boolean match(Export export) { if (export instanceof DefaultExport) { return true; } return false; } - + } diff --git a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java index f23797a831..84ac93313d 100644 --- a/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.java +++ b/branches/sca-java-1.x/modules/contribution/src/main/java/org/apache/tuscany/sca/contribution/processor/BaseStAXArtifactProcessor.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; @@ -35,16 +35,22 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.Extensible; +import org.apache.tuscany.sca.assembly.Extension; +import org.apache.tuscany.sca.assembly.ExtensionFactory; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; + /** - * A base class with utility methods for the other artifact processors in this module. - * + * A base class with utility methods for the other artifact processors in this module. + * * @version $Rev$ $Date$ */ public abstract class BaseStAXArtifactProcessor { /** - * Returns a QName from a string. + * Returns a QName from a string. * @param reader * @param value * @return @@ -178,9 +184,9 @@ public abstract class BaseStAXArtifactProcessor { } } } - + /** - * + * * @param writer * @param uri * @throws XMLStreamException @@ -193,8 +199,8 @@ public abstract class BaseStAXArtifactProcessor { if (prefix != null) { return null; } else { - - // Find an available prefix and bind it to the given URI + + // Find an available prefix and bind it to the given URI NamespaceContext nsc = writer.getNamespaceContext(); for (int i=1; ; i++) { prefix = "ns" + i; @@ -205,7 +211,7 @@ public abstract class BaseStAXArtifactProcessor { writer.setPrefix(prefix, uri); return prefix; } - + } /** @@ -219,12 +225,12 @@ public abstract class BaseStAXArtifactProcessor { String prefix = writeElementPrefix(writer, uri); writer.writeStartElement(uri, name); if (prefix != null){ - writer.writeNamespace(prefix,uri); + writer.writeNamespace(prefix,uri); } writeAttributePrefixes(writer, attrs); writeAttributes(writer, attrs); } - + /** * Start an element. * @param qname @@ -234,9 +240,9 @@ public abstract class BaseStAXArtifactProcessor { protected void writeStart(XMLStreamWriter writer, QName qname, XAttr... attrs) throws XMLStreamException { writeStart(writer, qname.getNamespaceURI(), qname.getLocalPart(), attrs); } - + /** - * End an element. + * End an element. * @param writer * @throws XMLStreamException */ @@ -303,10 +309,83 @@ public abstract class BaseStAXArtifactProcessor { } /** + * + * @param reader + * @param elementName + * @param extensible + * @param extensionAttributeProcessor + * @param extensionAttributeProcessor + * @param extensionFactory + * @throws ContributionReadException + * @throws XMLStreamException + */ + protected void readExtendedAttributes(XMLStreamReader reader, + Extensible extensible, + StAXAttributeProcessor extensionAttributeProcessor, + ExtensionFactory extensionFactory) throws ContributionReadException, + XMLStreamException { + QName elementName = reader.getName(); + for (int a = 0; a < reader.getAttributeCount(); a++) { + QName attributeName = reader.getAttributeName(a); + if (attributeName.getNamespaceURI() != null && attributeName.getNamespaceURI().length() > 0) { + if (!elementName.getNamespaceURI().equals(attributeName.getNamespaceURI())) { + Object attributeValue = extensionAttributeProcessor.read(attributeName, reader); + Extension attributeExtension; + if (attributeValue instanceof Extension) { + attributeExtension = (Extension)attributeValue; + } else { + attributeExtension = extensionFactory.createExtension(attributeName, attributeValue, true); + } + extensible.getAttributeExtensions().add(attributeExtension); + } + } + } + } + + /** + * + * @param attributeModel + * @param writer + * @param extensibleElement + * @param extensionAttributeProcessor + * @throws ContributionWriteException + * @throws XMLStreamException + */ + protected void writeExtendedAttributes(XMLStreamWriter writer, + Extensible extensibleElement, + StAXAttributeProcessor extensionAttributeProcessor) + throws ContributionWriteException, XMLStreamException { + for (Extension extension : extensibleElement.getAttributeExtensions()) { + if (extension.isAttribute()) { + extensionAttributeProcessor.write(extension, writer); + } + } + } + + protected void readExtendedElement(XMLStreamReader reader, + Extensible extensible, + StAXArtifactProcessor extensionProcessor) throws ContributionReadException, + XMLStreamException { + Object ext = extensionProcessor.read(reader); + if (extensible != null) { + extensible.getExtensions().add(ext); + } + } + + protected void writeExtendedElements(XMLStreamWriter writer, + Extensible extensible, + StAXArtifactProcessor extensionProcessor) throws ContributionWriteException, + XMLStreamException { + for (Object ext : extensible.getExtensions()) { + extensionProcessor.write(ext, writer); + } + } + + /** * Represents an XML attribute that needs to be written to a document. */ public static class XAttr { - + private static final String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; private String uri = SCA10_NS; @@ -374,7 +453,7 @@ public abstract class BaseStAXArtifactProcessor { } /** - * Writes a string from a QName and registers a prefix for its namespace. + * Writes a string from a QName and registers a prefix for its namespace. * @param reader * @param value * @return @@ -390,14 +469,14 @@ public abstract class BaseStAXArtifactProcessor { if (prefix.length() > 0) { return prefix + ":" + qname.getLocalPart(); } else { - + // Empty prefix, just return the local part of the given qname return qname.getLocalPart(); } - + } else { - - // Find an available prefix and bind it to the given URI + + // Find an available prefix and bind it to the given URI NamespaceContext nsc = writer.getNamespaceContext(); for (int i=1; ; i++) { prefix = "ns" + i; @@ -415,7 +494,7 @@ public abstract class BaseStAXArtifactProcessor { } /** - * Registers a prefix for the namespace of a QName. + * Registers a prefix for the namespace of a QName. * @param reader * @param value * @return @@ -428,8 +507,8 @@ public abstract class BaseStAXArtifactProcessor { if (prefix != null) { return; } else { - - // Find an available prefix and bind it to the given URI + + // Find an available prefix and bind it to the given URI NamespaceContext nsc = writer.getNamespaceContext(); for (int i=1; ; i++) { prefix = "ns" + i; @@ -451,12 +530,12 @@ public abstract class BaseStAXArtifactProcessor { public void write(XMLStreamWriter writer) throws XMLStreamException { String str; if (value instanceof QName) { - + // Write a QName str = writeQNameValue(writer, (QName)value); - + } else if (value instanceof List) { - + // Write a list of values List<?> values = (List<?>)value; if (values.isEmpty()) { @@ -468,7 +547,7 @@ public abstract class BaseStAXArtifactProcessor { // Skip null values continue; } - + if (v instanceof XAttr) { // Write an XAttr value ((XAttr)v).write(writer); @@ -482,14 +561,14 @@ public abstract class BaseStAXArtifactProcessor { // Write a QName value buffer.append(writeQNameValue(writer, (QName)v)); } else { - // Write value as a string + // Write value as a string buffer.append(String.valueOf(v)); } } str = buffer.toString(); - + } else { - + // Write a string if (value == null) { return; @@ -509,24 +588,24 @@ public abstract class BaseStAXArtifactProcessor { } /** - * Registers a prefix for the namespace of a QName or list of QNames + * Registers a prefix for the namespace of a QName or list of QNames * @param writer * @throws XMLStreamException */ public void writePrefix(XMLStreamWriter writer) throws XMLStreamException { if (value instanceof QName) { - + // Write prefix for a single QName value writeQNamePrefix(writer, (QName)value); - + } else if (value instanceof List) { - + // Write prefixes for a list of values for (Object v: (List<?>)value) { if (v instanceof QName) { // Write prefix for a QName value writeQNamePrefix(writer, (QName)v); - + } else if (v instanceof XAttr) { // Write prefix for an XAttr value ((XAttr)v).writePrefix(writer); @@ -535,5 +614,5 @@ public abstract class BaseStAXArtifactProcessor { } } } - + } |