diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-10-26 07:11:27 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-10-26 07:11:27 +0000 |
commit | 0d6d7922ed17cca55ec36ff2626d1080e76d6d13 (patch) | |
tree | b4d1cd6855943866af3dc7bb77f0e83c9f44b2c4 /sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main | |
parent | 57ae1afa2ecfee292787d893ad8ba868a4a3504e (diff) |
Remove old beta1 branch
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1027389 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main')
38 files changed, 0 insertions, 7135 deletions
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java deleted file mode 100644 index 21a7efc9c8..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/BaseAssemblyProcessor.java +++ /dev/null @@ -1,781 +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.assembly.xml; - -import static javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI; -import static javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI; -import static javax.xml.stream.XMLStreamConstants.CDATA; -import static javax.xml.stream.XMLStreamConstants.CHARACTERS; -import static javax.xml.stream.XMLStreamConstants.COMMENT; -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; -import static org.apache.tuscany.sca.assembly.xml.Constants.ELEMENT; -import static org.apache.tuscany.sca.assembly.xml.Constants.MANY; -import static org.apache.tuscany.sca.assembly.xml.Constants.MULTIPLICITY; -import static org.apache.tuscany.sca.assembly.xml.Constants.MUST_SUPPLY; -import static org.apache.tuscany.sca.assembly.xml.Constants.NAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.ONE_N; -import static org.apache.tuscany.sca.assembly.xml.Constants.ONE_ONE; -import static org.apache.tuscany.sca.assembly.xml.Constants.PROPERTY; -import static org.apache.tuscany.sca.assembly.xml.Constants.PROPERTY_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.SCA11_NS; -import static org.apache.tuscany.sca.assembly.xml.Constants.TARGET; -import static org.apache.tuscany.sca.assembly.xml.Constants.TYPE; -import static org.apache.tuscany.sca.assembly.xml.Constants.VALUE; -import static org.apache.tuscany.sca.assembly.xml.Constants.VALUE_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.ZERO_N; -import static org.apache.tuscany.sca.assembly.xml.Constants.ZERO_ONE; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import javax.xml.namespace.QName; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.dom.DOMSource; - -import org.apache.tuscany.sca.assembly.AbstractContract; -import org.apache.tuscany.sca.assembly.AbstractProperty; -import org.apache.tuscany.sca.assembly.AbstractReference; -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.Base; -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Extensible; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Multiplicity; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -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.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -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.policy.PolicyFactory; -import org.w3c.dom.Document; -import org.w3c.dom.Element; -import org.w3c.dom.NamedNodeMap; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * A base class with utility methods for the other artifact processors in this module. - * - * @version $Rev$ $Date$ - */ -abstract class BaseAssemblyProcessor extends BaseStAXArtifactProcessor { - - protected AssemblyFactory assemblyFactory; - protected PolicyFactory policyFactory; - protected StAXArtifactProcessor<Object> extensionProcessor; - protected PolicySubjectProcessor policyProcessor; - private DocumentBuilderFactory documentBuilderFactory; - - - /** - * Constructs a new BaseArtifactProcessor. - * @param assemblyFactory - * @param policyFactory - */ - @SuppressWarnings("unchecked") - protected BaseAssemblyProcessor(AssemblyFactory assemblyFactory, - PolicyFactory policyFactory, - DocumentBuilderFactory documentBuilderFactory, - StAXArtifactProcessor extensionProcessor) { - this.assemblyFactory = assemblyFactory; - this.policyFactory = policyFactory; - this.documentBuilderFactory = documentBuilderFactory; - this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor; - this.policyProcessor = new PolicySubjectProcessor(policyFactory); - } - - /** - * @param modelFactories - * @param staxProcessor - * @param monitor - */ - protected BaseAssemblyProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor staxProcessor) { - this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - this.policyFactory = modelFactories.getFactory(PolicyFactory.class); - this.documentBuilderFactory = modelFactories.getFactory(DocumentBuilderFactory.class); - this.extensionProcessor = (StAXArtifactProcessor<Object>)staxProcessor; - this.policyProcessor = new PolicySubjectProcessor(policyFactory); - } - - /** - * Marshals warnings into the monitor - * - * @param message - * @param model - * @param messageParameters - */ - protected void warning(Monitor monitor, String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - Messages.RESOURCE_BUNDLE, - Severity.WARNING, - model, - message, - (Object[])messageParameters); - monitor.problem(problem); - } - } - - /** - * Marshals errors into the monitor - * - * @param problems - * @param message - * @param model - */ - protected void error(Monitor monitor, String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - Messages.RESOURCE_BUNDLE, - Severity.ERROR, - model, - message, - (Object[])messageParameters); - monitor.problem(problem); - } - } - - /** - * Marshals exceptions into the monitor - * - * @param problems - * @param message - * @param model - */ - protected void error(Monitor monitor, String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - Messages.RESOURCE_BUNDLE, - Severity.ERROR, - model, - message, - ex); - monitor.problem(problem); - } - } - - /** - * Start an element. - * @param writer - * @param name - * @param attrs - * @throws XMLStreamException - */ - protected void writeStart(XMLStreamWriter writer, String name, XAttr... attrs) throws XMLStreamException { - super.writeStart(writer, SCA11_NS, name, attrs); - } - - /** - * Start a document. - * @param writer - * @throws XMLStreamException - */ - protected void writeStartDocument(XMLStreamWriter writer, String name, XAttr... attrs) throws XMLStreamException { - super.writeStartDocument(writer, SCA11_NS, name, attrs); - } - - /** - * Read list of reference targets - * @param reference - * @param reader - */ - protected void readTargets(Reference reference, XMLStreamReader reader) { - String value = getString(reader, TARGET); - ComponentService target = null; - if (value != null) { - for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { - target = assemblyFactory.createComponentService(); - target.setUnresolved(true); - target.setName(tokens.nextToken()); - reference.getTargets().add(target); - } - } - } - - /** - * Write a list of targets into an attribute - * @param reference - * @return - */ - protected XAttr writeTargets(Reference reference) { - List<String> targets = new ArrayList<String>(); - for (Service target : reference.getTargets()) { - targets.add(target.getName()); - } - return new XAttr(TARGET, targets); - } - - /** - * Read a multiplicity attribute. - * @param reference - * @param reader - */ - protected void readMultiplicity(AbstractReference reference, XMLStreamReader reader) { - String value = reader.getAttributeValue(null, MULTIPLICITY); - if (ZERO_ONE.equals(value)) { - reference.setMultiplicity(Multiplicity.ZERO_ONE); - } else if (ONE_N.equals(value)) { - reference.setMultiplicity(Multiplicity.ONE_N); - } else if (ZERO_N.equals(value)) { - reference.setMultiplicity(Multiplicity.ZERO_N); - } else if (ONE_ONE.equals(value)) { - reference.setMultiplicity(Multiplicity.ONE_ONE); - } - } - - protected XAttr writeMultiplicity(AbstractReference reference) { - Multiplicity multiplicity = reference.getMultiplicity(); - if (multiplicity != null) { - String value = null; - if (Multiplicity.ZERO_ONE.equals(multiplicity)) { - value = ZERO_ONE; - } else if (Multiplicity.ONE_N.equals(multiplicity)) { - value = ONE_N; - } else if (Multiplicity.ZERO_N.equals(multiplicity)) { - value = ZERO_N; - } else if (Multiplicity.ONE_ONE.equals(multiplicity)) { - value = ONE_ONE; - return null; - } - return new XAttr(MULTIPLICITY, value); - } - return null; - } - - - /** - * Reads an abstract property element. - * @param property - * @param reader - * @param context TODO - * @throws XMLStreamException - * @throws ContributionReadException - */ - protected void readAbstractProperty(AbstractProperty property, XMLStreamReader reader, ProcessorContext context) throws XMLStreamException, - ContributionReadException { - - property.setName(getString(reader, NAME)); - property.setMany(getBoolean(reader, MANY)); - property.setMustSupply(getBoolean(reader, MUST_SUPPLY)); - property.setXSDElement(getQName(reader, ELEMENT)); - property.setXSDType(getQName(reader, TYPE)); - // MJE added 14/05/2009 - check for both @element and @type being present - disallowed by OASIS Assembly spec - if( property.getXSDElement() != null && property.getXSDType() != null ) { - ContributionReadException ce = new ContributionReadException("[ASM40010,ASM60040] Error: property has both @type and @element attribute values - " + - property.getName()); - error(context.getMonitor(), "ContributionReadException", property, ce); - } // end if - - } - - /** - * Resolve an implementation. - * @param implementation - * @param resolver - * @param context - * @return - * @throws ContributionResolveException - */ - protected Implementation resolveImplementation(Implementation implementation, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - if (implementation != null) { - if (implementation.isUnresolved()) { - implementation = resolver.resolveModel(Implementation.class, implementation, context); - - // Lazily resolve implementations - if (implementation.isUnresolved()) { - extensionProcessor.resolve(implementation, resolver, context); - if (!implementation.isUnresolved()) { - resolver.addModel(implementation, context); - } - } - } - } - return implementation; - } - - /** - * Resolve interface, callback interface and bindings on a list of contracts. - * @param contracts the list of contracts - * @param resolver the resolver to use to resolve models - * @param context TODO - */ - protected <C extends Contract> void resolveContracts(List<C> contracts, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - resolveContracts(null, contracts, resolver, context); - } - - /** - * Resolve interface, callback interface and bindings on a list of contracts. - * @param parent element for the contracts - * @param contracts the list of contracts - * @param resolver the resolver to use to resolve models - * @param context TODO - */ - protected <C extends Contract> void resolveContracts(Base parent, List<C> contracts, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - - String parentName = - (parent instanceof Composite) ? ((Composite)parent).getName().toString() : (parent instanceof Component) - ? ((Component)parent).getName() : "UNKNOWN"; - - for (Contract contract : contracts) { - // Resolve the interface contract - InterfaceContract interfaceContract = contract.getInterfaceContract(); - if (interfaceContract != null) { - extensionProcessor.resolve(interfaceContract, resolver, context); - } - - // Resolve bindings - for (int i = 0, n = contract.getBindings().size(); i < n; i++) { - Binding binding = contract.getBindings().get(i); - extensionProcessor.resolve(binding, resolver, context); - - } - - // Resolve callback bindings - if (contract.getCallback() != null) { - - for (int i = 0, n = contract.getCallback().getBindings().size(); i < n; i++) { - Binding binding = contract.getCallback().getBindings().get(i); - extensionProcessor.resolve(binding, resolver, context); - } - } - } - } - - /** - * Resolve interface and callback interface on a list of abstract contracts. - * @param contracts the list of contracts - * @param resolver the resolver to use to resolve models - * @param context TODO - */ - protected <C extends AbstractContract> void resolveAbstractContracts(List<C> contracts, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - for (AbstractContract contract : contracts) { - - // Resolve the interface contract - InterfaceContract interfaceContract = contract.getInterfaceContract(); - if (interfaceContract != null) { - extensionProcessor.resolve(interfaceContract, resolver, context); - } - } - } - - /** - * Read a property value into a DOM document. - * @param element - * @param type - * @param reader - * @param context - * @return - * @throws XMLStreamException - * @throws ContributionReadException - * @throws ParserConfigurationException - */ - protected Document readPropertyValue(QName element, QName type, boolean isMany, XMLStreamReader reader, ProcessorContext context) throws XMLStreamException, - ContributionReadException { - Document document; - try { - if (documentBuilderFactory == null) { - documentBuilderFactory = DocumentBuilderFactory.newInstance(); - documentBuilderFactory.setNamespaceAware(true); - } - document = documentBuilderFactory.newDocumentBuilder().newDocument(); - } catch (ParserConfigurationException e) { - ContributionReadException ce = new ContributionReadException(e); - error(context.getMonitor(), "ContributionReadException", documentBuilderFactory, ce); - throw ce; - } - - // Collect the property values as <value> elements under the <property> - Element root = document.createElementNS(SCA11_NS, "sca:" + PROPERTY); - String nameAttr = getString(reader, NAME); - if (nameAttr != null) { - root.setAttributeNS(SCA11_NS, "sca:" + NAME, nameAttr); - } - declareNamespace(root, "sca", SCA11_NS); - if (type != null) { - org.w3c.dom.Attr xsi = document.createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, "xmlns:xsi"); - xsi.setValue(W3C_XML_SCHEMA_INSTANCE_NS_URI); - root.setAttributeNodeNS(xsi); - - String prefix = type.getPrefix(); - if (prefix == null || prefix.length() == 0) { - prefix = "ns"; - } - - declareNamespace(root, prefix, type.getNamespaceURI()); - - org.w3c.dom.Attr xsiType = document.createAttributeNS(W3C_XML_SCHEMA_INSTANCE_NS_URI, "xsi:type"); - xsiType.setValue(prefix + ":" + type.getLocalPart()); - root.setAttributeNodeNS(xsiType); - } - document.appendChild(root); - - // Start to parse the property - QName name = reader.getName(); // Should be sca:property - - // SCA 1.1 supports the @value for simple types - String valueAttr = getString(reader, VALUE); - if (valueAttr != null) { - Element valueElement = document.createElementNS(SCA11_NS, VALUE); - root.appendChild(valueElement); - valueElement.setTextContent(valueAttr); - } - - boolean gotOneValue = false; - boolean isTextForProperty = true; - StringBuffer text = new StringBuffer(); - - int event = reader.getEventType(); - while (true) { - switch (event) { - case START_ELEMENT: - name = reader.getName(); - if (PROPERTY_QNAME.equals(name)) { - isTextForProperty = true; - break; - } - isTextForProperty = false; - - // CONFORMANCE: ASM50033 - // A property <value/> subelement MUST NOT be used when the @value attribute is used - // to specify the value for that property. - if (valueAttr != null) { - error(context.getMonitor(), "ASM50033: value attribute exists for the property element", name, name); - } - // Read <value> - if (VALUE_QNAME.equals(name)) { - if (gotOneValue && !isMany) { - // TODO: TUSCANY-3231 this should be error not warning but that breaks OASIS tests - // [rfeng] We should not issue warning here as the component property many inherit @many from the componentType property - // warning(context.getMonitor(), "ASM50032: multiple value elements for single-valued property", name, name); - } - loadElement(reader, root); - gotOneValue = true; - } else { - // Global elements - loadElement(reader, root); - } - break; - case XMLStreamConstants.CHARACTERS: - case XMLStreamConstants.CDATA: - if (isTextForProperty) { - text.append(reader.getText()); - } - break; - case END_ELEMENT: - name = reader.getName(); - if (PROPERTY_QNAME.equals(name)) { - - if (root.getChildNodes().getLength() == 0) { - // Add an text as an <value> - if (isTextForProperty){ - if (text.length() > 0) { - Element valueElement = document.createElementNS(SCA11_NS, VALUE); - root.appendChild(valueElement); - valueElement.setTextContent(text.toString()); - } - } - } - return document; - } - break; - } - if (reader.hasNext()) { - event = reader.next(); - } else { - break; - } - } - return document; - } - - /** - * Create a DOM element - * @param document - * @param name - * @return - */ - private Element createElement(Document document, QName name) { - String prefix = name.getPrefix(); - String qname = - (prefix != null && prefix.length() > 0) ? prefix + ":" + name.getLocalPart() : name.getLocalPart(); - return document.createElementNS(name.getNamespaceURI(), qname); - } - - /** - * Declare a namespace. - * @param element - * @param prefix - * @param ns - */ - private void declareNamespace(Element element, String prefix, String ns) { - if (ns == null) { - ns = ""; - } - if (prefix == null) { - prefix = ""; - } - String qname = null; - if ("".equals(prefix)) { - qname = "xmlns"; - } else { - qname = "xmlns:" + prefix; - } - Node node = element; - boolean declared = false; - while (node != null && node.getNodeType() == Node.ELEMENT_NODE) { - NamedNodeMap attrs = node.getAttributes(); - if (attrs == null) { - break; - } - Node attr = attrs.getNamedItem(qname); - if (attr != null) { - declared = ns.equals(attr.getNodeValue()); - break; - } - node = node.getParentNode(); - } - if (!declared) { - org.w3c.dom.Attr attr = element.getOwnerDocument().createAttributeNS(XMLNS_ATTRIBUTE_NS_URI, qname); - attr.setValue(ns); - element.setAttributeNodeNS(attr); - } - } - - /** - * Load a property value specification from an StAX stream into a DOM - * Document. Only elements, text and attributes are processed; all comments - * and other whitespace are ignored. - * - * @param reader the stream to read from - * @param root the DOM node to load - * @throws javax.xml.stream.XMLStreamException - */ - private void loadElement(XMLStreamReader reader, Element root) throws XMLStreamException { - Document document = root.getOwnerDocument(); - Node current = root; - while (true) { - switch (reader.getEventType()) { - case START_ELEMENT: - QName name = reader.getName(); - Element child = createElement(document, name); - - // push the new element and make it the current one - current.appendChild(child); - current = child; - - int count = reader.getNamespaceCount(); - for (int i = 0; i < count; i++) { - String prefix = reader.getNamespacePrefix(i); - String ns = reader.getNamespaceURI(i); - declareNamespace(child, prefix, ns); - } - - if (!"".equals(name.getNamespaceURI())) { - declareNamespace(child, name.getPrefix(), name.getNamespaceURI()); - } - - // add the attributes for this element - count = reader.getAttributeCount(); - for (int i = 0; i < count; i++) { - String ns = reader.getAttributeNamespace(i); - String prefix = reader.getAttributePrefix(i); - String qname = reader.getAttributeLocalName(i); - String value = reader.getAttributeValue(i); - if (prefix != null && prefix.length() != 0) { - qname = prefix + ":" + qname; - } - child.setAttributeNS(ns, qname, value); - if (ns != null) { - declareNamespace(child, prefix, ns); - } - } - - break; - case CDATA: - current.appendChild(document.createCDATASection(reader.getText())); - break; - case CHARACTERS: - current.appendChild(document.createTextNode(reader.getText())); - break; - case COMMENT: - current.appendChild(document.createComment(reader.getText())); - break; - case END_ELEMENT: - // pop the element off the stack - current = current.getParentNode(); - // if we are back at the root then we are done - if (current == root) { - return; - } - - } - if (reader.hasNext()) { - reader.next(); - } else { - return; - } - } - } - - /** - * Write the value of a property - * @param document - * @param element - * @param type - * @param writer - * @throws XMLStreamException - */ - protected void writePropertyValue(Object propertyValue, QName element, QName type, XMLStreamWriter writer) - throws XMLStreamException { - - if (propertyValue instanceof Document) { - Document document = (Document)propertyValue; - NodeList nodeList = document.getDocumentElement().getChildNodes(); - - for (int item = 0; item < nodeList.getLength(); ++item) { - Node node = nodeList.item(item); - int nodeType = node.getNodeType(); - if (nodeType == Node.ELEMENT_NODE) { - XMLStreamReader reader = XMLInputFactory.newInstance().createXMLStreamReader(new DOMSource(node)); - - while (reader.hasNext()) { - switch (reader.next()) { - case XMLStreamConstants.START_ELEMENT: - QName name = reader.getName(); - writer.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); - - int namespaces = reader.getNamespaceCount(); - for (int i = 0; i < namespaces; i++) { - String prefix = reader.getNamespacePrefix(i); - String ns = reader.getNamespaceURI(i); - writer.writeNamespace(prefix, ns); - } - - if (!"".equals(name.getNamespaceURI())) { - writer.writeNamespace(name.getPrefix(), name.getNamespaceURI()); - } - - // add the attributes for this element - namespaces = reader.getAttributeCount(); - for (int i = 0; i < namespaces; i++) { - String ns = reader.getAttributeNamespace(i); - String prefix = reader.getAttributePrefix(i); - String qname = reader.getAttributeLocalName(i); - String value = reader.getAttributeValue(i); - - writer.writeAttribute(prefix, ns, qname, value); - } - - break; - case XMLStreamConstants.CDATA: - writer.writeCData(reader.getText()); - break; - case XMLStreamConstants.CHARACTERS: - writer.writeCharacters(reader.getText()); - break; - case XMLStreamConstants.END_ELEMENT: - writer.writeEndElement(); - break; - } - } - } else { - writer.writeCharacters(node.getTextContent()); - } - } - } - } - - /** - * - * @param reader - * @param elementName - * @param extensionAttributeProcessor - * @param context TODO - * @param estensibleElement - * @throws ContributionReadException - * @throws XMLStreamException - */ - protected void readExtendedAttributes(XMLStreamReader reader, - QName elementName, - Extensible extensible, - StAXAttributeProcessor extensionAttributeProcessor, - ProcessorContext context) throws ContributionReadException, - XMLStreamException { - super.readExtendedAttributes(reader, extensible, extensionAttributeProcessor, assemblyFactory, context); - } - - - /*protected void validatePolicySets(PolicySubject policySetAttachPoint) - throws ContributionResolveException { - validatePolicySets(policySetAttachPoint, policySetAttachPoint.getApplicablePolicySets()); - } - - - protected void validatePolicySets(PolicySubject policySetAttachPoint, - List<PolicySet> applicablePolicySets) throws ContributionResolveException { - //Since the applicablePolicySets in a policySetAttachPoint will already have the - //list of policysets that might ever be applicable to this attachPoint, just check - //if the defined policysets feature in the list of applicable policysets - ExtensionType attachPointType = policySetAttachPoint.getType(); - for ( PolicySet definedPolicySet : policySetAttachPoint.getPolicySets() ) { - if ( !definedPolicySet.isUnresolved() ) { - if ( !applicablePolicySets.contains(definedPolicySet)) { - throw new ContributionResolveException("Policy Set '" + definedPolicySet.getName() - + "' does not apply to binding type " - + attachPointType.getName()); - } - } else { - throw new ContributionResolveException("Policy Set '" + definedPolicySet.getName() - + "' is not defined in this domain "); - - - } - } - }*/ -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java deleted file mode 100644 index b5fe005812..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeDocumentProcessor.java +++ /dev/null @@ -1,129 +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.assembly.xml; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URL; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sca.assembly.ComponentType; -import org.apache.tuscany.sca.common.java.io.IOHelper; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A componentType processor. - * - * @version $Rev$ $Date$ - */ -public class ComponentTypeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor<ComponentType> { - private ValidatingXMLInputFactory inputFactory; - - /** - * Constructs a new componentType processor. - * @param modelFactories - * @param staxProcessor - */ - public ComponentTypeDocumentProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor staxProcessor) { - super(modelFactories, staxProcessor); - this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); - } - - public ComponentType read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException { - InputStream urlStream = null; - Monitor monitor = context.getMonitor(); - try { - - // Create a stream reader - urlStream = IOHelper.openStream(url); - XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream); - ValidatingXMLInputFactory.setMonitor(reader, monitor); - reader.nextTag(); - - // Reader the componentType model - ComponentType componentType = (ComponentType)extensionProcessor.read(reader, context); - if (componentType != null) { - componentType.setURI(uri.toString()); - } - - // For debugging purposes, write it back to XML -// if (componentType != null) { -// try { -// ByteArrayOutputStream bos = new ByteArrayOutputStream(); -// XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); -// outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE); -// extensionProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos)); -// Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray())); -// OutputFormat format = new OutputFormat(); -// format.setIndenting(true); -// format.setIndent(2); -// XMLSerializer serializer = new XMLSerializer(System.out, format); -// serializer.serialize(document); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } - - return componentType; - - } catch (XMLStreamException e) { - ContributionReadException ce = new ContributionReadException(e); - error(monitor, "ContributionReadException", inputFactory, ce); - throw ce; - } catch (IOException e) { - ContributionReadException ce = new ContributionReadException(e); - error(monitor, "ContributionReadException", inputFactory, ce); - throw ce; - } finally { - try { - if (urlStream != null) { - urlStream.close(); - urlStream = null; - } - } catch (IOException ioe) { - //ignore - } - } - } - - public void resolve(ComponentType componentType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - extensionProcessor.resolve(componentType, resolver, context); - } - - public String getArtifactType() { - return ".componentType"; - } - - public Class<ComponentType> getModelType() { - return ComponentType.class; - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java deleted file mode 100644 index 9a4a0dc035..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeModelResolver.java +++ /dev/null @@ -1,96 +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.assembly.xml; - -import java.util.HashMap; -import java.util.Map; - -import org.apache.tuscany.sca.assembly.ComponentType; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.Import; -import org.apache.tuscany.sca.contribution.java.JavaImport; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; - -/** - * A Model Resolver for ComponentType models. - * - * @version $Rev$ $Date$ - */ -public class ComponentTypeModelResolver implements ModelResolver { - private Contribution contribution; - private Map<String, ComponentType> map = new HashMap<String, ComponentType>(); - - public ComponentTypeModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { - this.contribution = contribution; - } - - public void addModel(Object resolved, ProcessorContext context) { - ComponentType componentType = (ComponentType)resolved; - map.put(componentType.getURI(), componentType); - } - - public Object removeModel(Object resolved, ProcessorContext context) { - return map.remove(((ComponentType)resolved).getURI()); - } - - public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { - - //get componentType artifact URI - String uri = ((ComponentType)unresolved).getURI(); - if (uri == null) { - return (T)unresolved; - } - - //lookup the componentType - ComponentType resolved = (ComponentType) map.get(uri); - if (resolved != null) { - return modelClass.cast(resolved); - } - - //If not found, delegate the resolution to the imports (in this case based on the java imports) - //compute the package name from the componentType URI - if (unresolved instanceof ComponentType) { - //FIXME The core assembly model now depends on java imports to - // resolve componentTypes of all kinds, this is not right at all!!! - int s = uri.lastIndexOf('/'); - if (s != -1) { - String packageName = uri.substring(0, uri.lastIndexOf("/")); - for (Import import_ : this.contribution.getImports()) { - if (import_ instanceof JavaImport) { - JavaImport javaImport = (JavaImport)import_; - //check the import location against the computed package name from the componentType URI - if (javaImport.getPackage().equals(packageName)) { - // Delegate the resolution to the import resolver - resolved = javaImport.getModelResolver().resolveModel(ComponentType.class, (ComponentType)unresolved, context); - if (!resolved.isUnresolved()) { - return modelClass.cast(resolved); - } - } - } - } - } - } - - return (T)unresolved; - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java deleted file mode 100644 index b402b6e3a3..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ComponentTypeProcessor.java +++ /dev/null @@ -1,381 +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.assembly.xml; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; -import static org.apache.tuscany.sca.assembly.xml.Constants.CALLBACK; -import static org.apache.tuscany.sca.assembly.xml.Constants.CALLBACK_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.COMPONENT_TYPE; -import static org.apache.tuscany.sca.assembly.xml.Constants.COMPONENT_TYPE_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.ELEMENT; -import static org.apache.tuscany.sca.assembly.xml.Constants.IMPLEMENTATION; -import static org.apache.tuscany.sca.assembly.xml.Constants.MANY; -import static org.apache.tuscany.sca.assembly.xml.Constants.MUST_SUPPLY; -import static org.apache.tuscany.sca.assembly.xml.Constants.NAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.OPERATION_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.PROPERTY; -import static org.apache.tuscany.sca.assembly.xml.Constants.PROPERTY_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.REFERENCE; -import static org.apache.tuscany.sca.assembly.xml.Constants.REFERENCE_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.SERVICE; -import static org.apache.tuscany.sca.assembly.xml.Constants.SERVICE_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.TYPE; -import static org.apache.tuscany.sca.assembly.xml.Constants.EXTENSION; -import static org.apache.tuscany.sca.assembly.xml.Constants.EXTENSION_QNAME; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Callback; -import org.apache.tuscany.sca.assembly.ComponentType; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Extensible; -import org.apache.tuscany.sca.assembly.Property; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -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.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.interfacedef.impl.OperationImpl; -import org.apache.tuscany.sca.policy.PolicySubject; -import org.w3c.dom.Document; - -/** - * A componentType processor. - * - * @version $Rev$ $Date$ - */ -public class ComponentTypeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<ComponentType> { - - /** - * Constructs a new componentType processor. - * - * @param modelFactories - * @param extensionProcessor - * @param extensionAttributeProcessor - * @param monitor - */ - public ComponentTypeProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor) { - super(modelFactories, extensionProcessor); - } - - public ComponentType read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException { - ComponentType componentType = null; - Service service = null; - Reference reference = null; - Contract contract = null; - Property property = null; - Callback callback = null; - QName name = null; - - try { - // Read the componentType document - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - name = reader.getName(); - - if (Constants.COMPONENT_TYPE_QNAME.equals(name)) { - - // Read a <componentType> - componentType = assemblyFactory.createComponentType(); - - } else if (Constants.SERVICE_QNAME.equals(name)) { - - // Read a <service> - service = assemblyFactory.createService(); - contract = service; - service.setName(getString(reader, Constants.NAME)); - componentType.getServices().add(service); - policyProcessor.readPolicies(service, reader); - - } else if (Constants.REFERENCE_QNAME.equals(name)) { - - // Read a <reference> - reference = assemblyFactory.createReference(); - contract = reference; - reference.setName(getString(reader, Constants.NAME)); - reference.setWiredByImpl(getBoolean(reader, Constants.WIRED_BY_IMPL)); - readMultiplicity(reference, reader); - readTargets(reference, reader); - componentType.getReferences().add(reference); - policyProcessor.readPolicies(reference, reader); - - } else if (Constants.PROPERTY_QNAME.equals(name)) { - - // Read a <property> - property = assemblyFactory.createProperty(); - readAbstractProperty(property, reader, context); - policyProcessor.readPolicies(property, reader); - - // Read the property value - Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), property.isMany(), reader, context); - property.setValue(value); - - componentType.getProperties().add(property); - - } else if (Constants.IMPLEMENTATION_QNAME.equals(name)) { - - // Read an <implementation> element - policyProcessor.readPolicies(componentType, reader); - - } else if (Constants.CALLBACK_QNAME.equals(name)) { - - // Read a <callback> - callback = assemblyFactory.createCallback(); - contract.setCallback(callback); - policyProcessor.readPolicies(callback, reader); - - } else if (OPERATION_QNAME.equals(name)) { - - // Read an <operation> - Operation operation = new OperationImpl(); - operation.setName(getString(reader, NAME)); - operation.setUnresolved(true); - if (callback != null) { - policyProcessor.readPolicies(callback, operation, reader); - } else { - policyProcessor.readPolicies(contract, operation, reader); - } - } else if(EXTENSION_QNAME.equals(name)) { - // Handle <extension> - //ignore element as this is a wrapper for extensibility - break; - } else { - - - // Read an extension element - Object extension = extensionProcessor.read(reader, context); - if (extension != null) { - if (extension instanceof InterfaceContract) { - - // <service><interface> and <reference><interface> - contract.setInterfaceContract((InterfaceContract)extension); - - } else if (extension instanceof Binding) { - - // <service><binding> and <reference><binding> - if (callback != null) { - callback.getBindings().add((Binding)extension); - } else { - contract.getBindings().add((Binding)extension); - } - } else { - - // Add the extension element to the current element - if (callback != null) { - callback.getExtensions().add(extension); - } else if (contract != null) { - contract.getExtensions().add(extension); - } else if (property != null) { - property.getExtensions().add(extension); - } else { - if (componentType instanceof Extensible) { - ((Extensible)componentType).getExtensions().add(extension); - } - } - } - } - } - break; - - case END_ELEMENT: - name = reader.getName(); - - // Clear current state when reading reaching end element - if (SERVICE_QNAME.equals(name)) { - service = null; - contract = null; - } else if (REFERENCE_QNAME.equals(name)) { - reference = null; - contract = null; - } else if (PROPERTY_QNAME.equals(name)) { - property = null; - } else if (CALLBACK_QNAME.equals(name)) { - callback = null; - } - break; - } - - // Read the next element - if (reader.hasNext()) { - reader.next(); - } - } - } - catch (XMLStreamException e) { - ContributionReadException ex = new ContributionReadException(e); - error(context.getMonitor(), "XMLStreamException", reader, ex); - } - - return componentType; - } - - public void write(ComponentType componentType, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { - - // Write <componentType> element - writeStartDocument(writer, COMPONENT_TYPE); - - // Write <service> elements - for (Service service : componentType.getServices()) { - writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), - policyProcessor.writePolicies(service)); - - if (service.getInterfaceContract() != null) { - extensionProcessor.write(service.getInterfaceContract(), writer, context); - } - - for (Binding binding: service.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - if (service.getCallback() != null) { - Callback callback = service.getCallback(); - writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); - - for (Binding binding: callback.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - for (Object extension: callback.getExtensions()) { - extensionProcessor.write(extension, writer, context); - } - - writeEnd(writer); - } - - this.writeExtendedElements(writer, service, extensionProcessor, context); - - writeEnd(writer); - } - - // Write <reference> elements - for (Reference reference : componentType.getReferences()) { - - writeStart(writer, REFERENCE, - new XAttr(NAME, reference.getName()), - writeMultiplicity(reference), - writeTargets(reference), - policyProcessor.writePolicies(reference)); - - extensionProcessor.write(reference.getInterfaceContract(), writer, context); - - for (Binding binding: reference.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - if (reference.getCallback() != null) { - Callback callback = reference.getCallback(); - writeStart(writer, CALLBACK, - policyProcessor.writePolicies(callback)); - - for (Binding binding: callback.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - for (Object extension: callback.getExtensions()) { - extensionProcessor.write(extension, writer, context); - } - - writeEnd(writer); - } - - this.writeExtendedElements(writer, reference, extensionProcessor, context); - - writeEnd(writer); - } - - // Write <property> elements - for (Property property : componentType.getProperties()) { - writeStart(writer, - PROPERTY, - new XAttr(NAME, property.getName()), - new XAttr(MUST_SUPPLY, property.isMustSupply()), - new XAttr(MANY, property.isMany()), - new XAttr(TYPE, property.getXSDType()), - new XAttr(ELEMENT, property.getXSDElement()), - policyProcessor.writePolicies(property)); - - // Write property value - writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer); - - // Write extensions - for (Object extension : property.getExtensions()) { - extensionProcessor.write(extension, writer, context); - } - - writeEnd(writer); - } - - // Write extension elements - if (componentType instanceof Extensible) { - for (Object extension: ((Extensible)componentType).getExtensions()) { - extensionProcessor.write(extension, writer, context); - } - } - - // Write <implementation> elements if the componentType has - // any intents or policySets - boolean writeImplementation = false; - if (componentType instanceof PolicySubject) { - if (!((PolicySubject)componentType).getRequiredIntents().isEmpty()) { - writeImplementation = true; - } - } - if (componentType instanceof PolicySubject) { - if (!((PolicySubject)componentType).getPolicySets().isEmpty()) { - writeImplementation = true; - } - } - if (writeImplementation) { - writeStart(writer, IMPLEMENTATION, - policyProcessor.writePolicies(componentType)); - } - - writeEndDocument(writer); - } - - public void resolve(ComponentType componentType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - - // Resolve component type services and references - resolveContracts(componentType.getServices(), resolver, context); - resolveContracts(componentType.getReferences(), resolver, context); - } - - public QName getArtifactType() { - return COMPONENT_TYPE_QNAME; - } - - public Class<ComponentType> getModelType() { - return ComponentType.class; - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java deleted file mode 100644 index 5ba42a0dec..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeDocumentProcessor.java +++ /dev/null @@ -1,185 +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.assembly.xml; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URL; - -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.transform.stream.StreamSource; - -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.common.java.io.IOHelper; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; -import org.xml.sax.SAXException; - -/** - * A composite processor. - * - * @version $Rev$ $Date$ - */ -public class CompositeDocumentProcessor extends BaseAssemblyProcessor implements URLArtifactProcessor<Composite>, - XMLStreamConstants { - private ValidatingXMLInputFactory inputFactory; - - - /** - * Constructs a composite document processor - * @param modelFactories - * @param staxProcessor - * @param monitor - */ - public CompositeDocumentProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor<?> staxProcessor) { - super(modelFactories, staxProcessor); - this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); - } - - /** - * Reads the contents of a Composite document and returns a Composite object - * @param contributionURL - the URL of the contribution containing the Composite - can be null - * @param uri - the URI of the composite document - * @param url - the URL of the composite document - * @return a Composite object built from the supplied Composite document - */ - public Composite read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException { - if( uri == null || url == null ) { - throw new ContributionReadException("Request to read composite with uri or url NULL"); - } // end if - InputStream scdlStream = null; - - try { - scdlStream = IOHelper.openStream(url); - } catch (IOException e) { - ContributionReadException ce = new ContributionReadException("Exception reading " + uri, e); - error(context.getMonitor(), "ContributionReadException", url, ce); - throw ce; - } - return read(uri, url, scdlStream, context); - } - - public Composite read(URI uri, URL url, InputStream scdlStream, ProcessorContext context) throws ContributionReadException { - try { - - Composite composite = null; - Monitor monitor = context.getMonitor(); - // Tag the monitor with the name of the composite artifact - if( monitor != null ) { - monitor.setArtifactName(uri.toString()); - } //end if - - // Set up a StreamSource for the composite file, since this has an associated URL that - // can be used by the parser to find references to other files such as DTDs - StreamSource scdlSource = new StreamSource( scdlStream, url.toString() ); - XMLStreamReader reader = inputFactory.createXMLStreamReader(scdlSource); - - // set the monitor on the input factory as the standard XMLInputFactory - // methods used for creating readers don't allow for the context to - // be passed in - ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor()); - - // Read the header (i.e. text before the <composite> element, if any - readCompositeFileHeader( reader ); - - // Read the composite model - composite = (Composite)extensionProcessor.read(reader, context); - if (composite != null) { - composite.setURI(uri.toString()); - } - - return composite; - - } catch (XMLStreamException e) { - ContributionReadException ce = new ContributionReadException("Exception reading " + uri, e); - error(context.getMonitor(), "ContributionReadException", inputFactory, ce); - throw ce; - } finally { - try { - if (scdlStream != null) { - scdlStream.close(); - scdlStream = null; - } - } catch (IOException ioe) { - //ignore - } - } - } - - /** - * Reads the header portion of a composite file - i.e. the section of the file before the - * <composite> start tag - * In particular handle any DTD declarations - * @param reader - an XMLStreamReader which is reading the composite file - * @throws XMLStreamException - */ - private void readCompositeFileHeader( XMLStreamReader reader ) throws XMLStreamException { - - while (true) { - int event = reader.next(); - - if ( event == CHARACTERS - || event == CDATA - || event == SPACE - || event == PROCESSING_INSTRUCTION - || event == COMMENT - || event == DTD - || event == ENTITY_DECLARATION ) { - continue; - } // end if - - // The first start (or end) element terminates the header scan - if (event == START_ELEMENT || event == END_ELEMENT) { - return; - } // end if - } // end while - } // end method readCompositeFileHeader - - public void resolve(Composite composite, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - try { - if (composite != null) - extensionProcessor.resolve(composite, resolver, context); - } catch (Throwable e ) { - // Add information about which composite was being processed when the exception occurred - String newMessage = "Processing composite " + composite.getName() + ": " + e.getMessage(); - throw new ContributionResolveException( newMessage, e ); - } // end try - } - - public String getArtifactType() { - return ".composite"; - } - - public Class<Composite> getModelType() { - return Composite.class; - } - -} // end class diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java deleted file mode 100644 index 7a396fe100..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeModelResolver.java +++ /dev/null @@ -1,96 +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.assembly.xml; - -import java.util.HashMap; -import java.util.Map; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.Import; -import org.apache.tuscany.sca.contribution.namespace.NamespaceImport; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.monitor.Monitor; - -/** - * A Model Resolver for Composite models. - * - * @version $Rev$ $Date$ - */ -public class CompositeModelResolver implements ModelResolver { - - private Contribution contribution; - private Map<QName, Composite> map = new HashMap<QName, Composite>(); - - public CompositeModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) { - this.contribution = contribution; - } - - public void addModel(Object resolved, ProcessorContext context) { - Composite composite = (Composite)resolved; - Composite old = map.put(composite.getName(), composite); - if (old != null) { - Monitor.error(context.getMonitor(), - this, - Messages.RESOURCE_BUNDLE, - "DuplicateCompositeName", - composite.getName().toString(), - contribution.getLocation()); - } - } - - public Object removeModel(Object resolved, ProcessorContext context) { - return map.remove(((Composite)resolved).getName()); - } - - public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) { - - // Lookup a definition for the given namespace - QName qname = ((Composite)unresolved).getName(); - Composite resolved = null; - - // Delegate the resolution to the imports - for (Import import_ : this.contribution.getImports()) { - if (import_ instanceof NamespaceImport) { - NamespaceImport namespaceImport = (NamespaceImport)import_; - if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) { - - // Delegate the resolution to the import resolver - resolved = namespaceImport.getModelResolver().resolveModel(Composite.class, (Composite)unresolved, context); - if (!resolved.isUnresolved()) { - return modelClass.cast(resolved); - } - } - } - } - - // No definition found, search within the current contribution - resolved = (Composite) map.get(qname); - if (resolved != null) { - return modelClass.cast(resolved); - } - - return (T)unresolved; - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java deleted file mode 100644 index c2deacbb35..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/CompositeProcessor.java +++ /dev/null @@ -1,1257 +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.assembly.xml; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; -import static org.apache.tuscany.sca.assembly.xml.Constants.AUTOWIRE; -import static org.apache.tuscany.sca.assembly.xml.Constants.CALLBACK; -import static org.apache.tuscany.sca.assembly.xml.Constants.CALLBACK_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.COMPONENT; -import static org.apache.tuscany.sca.assembly.xml.Constants.COMPONENT_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.COMPOSITE; -import static org.apache.tuscany.sca.assembly.xml.Constants.COMPOSITE_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.ELEMENT; -import static org.apache.tuscany.sca.assembly.xml.Constants.EXTENSION_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.FILE; -import static org.apache.tuscany.sca.assembly.xml.Constants.IMPLEMENTATION_COMPOSITE; -import static org.apache.tuscany.sca.assembly.xml.Constants.IMPLEMENTATION_COMPOSITE_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.INCLUDE; -import static org.apache.tuscany.sca.assembly.xml.Constants.INCLUDE_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.INTENTS; -import static org.apache.tuscany.sca.assembly.xml.Constants.LOCAL; -import static org.apache.tuscany.sca.assembly.xml.Constants.MANY; -import static org.apache.tuscany.sca.assembly.xml.Constants.MUST_SUPPLY; -import static org.apache.tuscany.sca.assembly.xml.Constants.NAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.NONOVERRIDABLE; -import static org.apache.tuscany.sca.assembly.xml.Constants.POLICY_SET_ATTACHMENT_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.PROMOTE; -import static org.apache.tuscany.sca.assembly.xml.Constants.PROPERTY; -import static org.apache.tuscany.sca.assembly.xml.Constants.PROPERTY_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.REFERENCE; -import static org.apache.tuscany.sca.assembly.xml.Constants.REFERENCE_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.REPLACE; -import static org.apache.tuscany.sca.assembly.xml.Constants.REQUIRES_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.SCA11_NS; -import static org.apache.tuscany.sca.assembly.xml.Constants.SERVICE; -import static org.apache.tuscany.sca.assembly.xml.Constants.SERVICE_QNAME; -import static org.apache.tuscany.sca.assembly.xml.Constants.SOURCE; -import static org.apache.tuscany.sca.assembly.xml.Constants.TARGET; -import static org.apache.tuscany.sca.assembly.xml.Constants.TARGET_NAMESPACE; -import static org.apache.tuscany.sca.assembly.xml.Constants.TYPE; -import static org.apache.tuscany.sca.assembly.xml.Constants.URI; -import static org.apache.tuscany.sca.assembly.xml.Constants.WIRE; -import static org.apache.tuscany.sca.assembly.xml.Constants.WIRED_BY_IMPL; -import static org.apache.tuscany.sca.assembly.xml.Constants.WIRE_QNAME; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; -import javax.xml.transform.dom.DOMSource; -import javax.xml.xpath.XPathExpressionException; - -import org.apache.tuscany.sca.assembly.Binding; -import org.apache.tuscany.sca.assembly.Callback; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentProperty; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.CompositeReference; -import org.apache.tuscany.sca.assembly.CompositeService; -import org.apache.tuscany.sca.assembly.Contract; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.assembly.Property; -import org.apache.tuscany.sca.assembly.Reference; -import org.apache.tuscany.sca.assembly.Service; -import org.apache.tuscany.sca.assembly.Wire; -import org.apache.tuscany.sca.common.xml.stax.StAXHelper; -import org.apache.tuscany.sca.common.xml.xpath.XPathHelper; -import org.apache.tuscany.sca.contribution.Artifact; -import org.apache.tuscany.sca.contribution.Contribution; -import org.apache.tuscany.sca.contribution.ContributionFactory; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -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.resolver.ResolverExtension; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.policy.ExtensionType; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.PolicyFactory; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.PolicySubject; -import org.apache.tuscany.sca.xsd.XSDFactory; -import org.apache.tuscany.sca.xsd.XSDefinition; -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * A composite processor. - * - * @version $Rev$ $Date$ - */ -public class CompositeProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<Composite> { - private XPathHelper xpathHelper; - private PolicyFactory intentAttachPointTypeFactory; - private StAXAttributeProcessor<Object> extensionAttributeProcessor; - private ContributionFactory contributionFactory; - private XSDFactory xsdFactory; - - private StAXHelper staxHelper; - - /** - * Construct a new composite processor - * - * @param extensionPoints - * @param extensionProcessor - */ - public CompositeProcessor(ExtensionPointRegistry extensionPoints, - StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor) { - - this(modelFactories(extensionPoints), extensionProcessor, extensionAttributeProcessor); - - this.xpathHelper = XPathHelper.getInstance(extensionPoints); - this.extensionAttributeProcessor = extensionAttributeProcessor; - - this.xsdFactory = extensionPoints.getExtensionPoint(XSDFactory.class); - - // - staxHelper = StAXHelper.getInstance(extensionPoints); - } - - /** - * Constructs a new composite processor - * - * @param modelFactories - * @param extensionProcessor - * @param monitor - */ - private CompositeProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor) { - - super(modelFactories, extensionProcessor); - this.intentAttachPointTypeFactory = modelFactories.getFactory(PolicyFactory.class); - this.contributionFactory = modelFactories.getFactory(ContributionFactory.class); - this.extensionAttributeProcessor = extensionAttributeProcessor; - - this.xsdFactory = modelFactories.getFactory(XSDFactory.class); - } - - public Composite read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException { - Composite composite = null; - Composite include = null; - Component component = null; - Property property = null; - ComponentService componentService = null; - ComponentReference componentReference = null; - ComponentProperty componentProperty = null; - CompositeService compositeService = null; - CompositeReference compositeReference = null; - Contract contract = null; - Wire wire = null; - Callback callback = null; - QName name = null; - Monitor monitor = context.getMonitor(); - try { - // Read the composite document - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: - name = reader.getName(); - - if (COMPOSITE_QNAME.equals(name)) { - - // Read a <composite> - composite = assemblyFactory.createComposite(); - composite.setSpecVersion(Constants.SCA11_NS); - - composite.setName(new QName(getURIString(reader, TARGET_NAMESPACE), getString(reader, NAME))); - - if (!isSet(reader, TARGET_NAMESPACE)) { - // spec says that a composite must have a namespace - warning(monitor, "NoCompositeNamespace", composite, composite.getName().toString()); - } - - if (isSet(reader, AUTOWIRE)) { - composite.setAutowire(getBoolean(reader, AUTOWIRE)); - } - - //handle extension attributes - this.readExtendedAttributes(reader, name, composite, extensionAttributeProcessor, context); - - composite.setLocal(getBoolean(reader, LOCAL)); - policyProcessor.readPolicies(composite, reader); - - } else if (INCLUDE_QNAME.equals(name)) { - - // Read an <include> - include = assemblyFactory.createComposite(); - include.setName(getQName(reader, NAME)); - include.setURI(getURIString(reader, URI)); - include.setUnresolved(true); - composite.getIncludes().add(include); - - } else if (SERVICE_QNAME.equals(name)) { - if (component != null) { - - // Read a <component><service> - componentService = assemblyFactory.createComponentService(); - contract = componentService; - componentService.setName(getString(reader, NAME)); - - //handle extension attributes - this.readExtendedAttributes(reader, name, componentService, extensionAttributeProcessor, context); - - component.getServices().add(componentService); - policyProcessor.readPolicies(contract, reader); - } else { - - // Read a <composite><service> - compositeService = assemblyFactory.createCompositeService(); - contract = compositeService; - compositeService.setName(getString(reader, NAME)); - - String promoted = getURIString(reader, PROMOTE); - if (promoted != null) { - String promotedComponentName; - String promotedServiceName; - int s = promoted.indexOf('/'); - if (s == -1) { - promotedComponentName = promoted; - promotedServiceName = null; - } else { - promotedComponentName = promoted.substring(0, s); - promotedServiceName = promoted.substring(s + 1); - } - - Component promotedComponent = assemblyFactory.createComponent(); - promotedComponent.setUnresolved(true); - promotedComponent.setName(promotedComponentName); - compositeService.setPromotedComponent(promotedComponent); - - ComponentService promotedService = assemblyFactory.createComponentService(); - promotedService.setUnresolved(true); - promotedService.setName(promotedServiceName); - compositeService.setPromotedService(promotedService); - } - - //handle extension attributes - this.readExtendedAttributes(reader, name, compositeService, extensionAttributeProcessor, context); - - composite.getServices().add(compositeService); - policyProcessor.readPolicies(contract, reader); - } - - // set the parent model so that binding processing can - // detect it they're being read as part of a reference - // or a service - context.setParentModel(contract); - - } else if (REFERENCE_QNAME.equals(name)) { - if (component != null) { - // Read a <component><reference> - componentReference = assemblyFactory.createComponentReference(); - contract = componentReference; - componentReference.setName(getString(reader, NAME)); - readMultiplicity(componentReference, reader); - if (isSet(reader, AUTOWIRE)) { - componentReference.setAutowire(getBoolean(reader, AUTOWIRE)); - } - // Read @nonOverridable - String nonOverridable = reader.getAttributeValue(null, NONOVERRIDABLE); - if (nonOverridable != null) { - componentReference.setNonOverridable(Boolean.parseBoolean(nonOverridable)); - } - readTargets(componentReference, reader); - componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL)); - - //handle extension attributes - this.readExtendedAttributes(reader, - name, - componentReference, - extensionAttributeProcessor, context); - - component.getReferences().add(componentReference); - policyProcessor.readPolicies(contract, reader); - } else { - // Read a <composite><reference> - compositeReference = assemblyFactory.createCompositeReference(); - contract = compositeReference; - compositeReference.setName(getString(reader, NAME)); - readMultiplicity(compositeReference, reader); - readTargets(compositeReference, reader); - String promote = getString(reader, Constants.PROMOTE); - if (promote != null) { - for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) { - String refName = tokens.nextToken(); - Component promotedComponent = assemblyFactory.createComponent(); - int index = refName.indexOf('/'); - if (index == -1) { - error(monitor, "Invalid reference name", compositeReference, refName); - } - String promotedComponentName = refName.substring(0, index); - promotedComponent.setName(promotedComponentName); - promotedComponent.setUnresolved(true); - compositeReference.getPromotedComponents().add(promotedComponent); - ComponentReference promotedReference = - assemblyFactory.createComponentReference(); - promotedReference.setUnresolved(true); - promotedReference.setName(refName); - compositeReference.getPromotedReferences().add(promotedReference); - } - } - compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL)); - - //handle extension attributes - this.readExtendedAttributes(reader, - name, - compositeReference, - extensionAttributeProcessor, context); - - composite.getReferences().add(compositeReference); - policyProcessor.readPolicies(contract, reader); - } - - // set the parent model so that binding processing can - // detect it they're being read as part of a reference - // or a service - context.setParentModel(contract); - - } else if (PROPERTY_QNAME.equals(name)) { - if (component != null) { - - // Read a <component><property> - componentProperty = assemblyFactory.createComponentProperty(); - property = componentProperty; - String source = getURIString(reader, SOURCE); - if (source != null) { - source = source.trim(); - } - componentProperty.setSource(source); - if (source != null) { - String xPath = prepareSourceXPathString( source ); - - try { - componentProperty.setSourceXPathExpression(xpathHelper.compile(reader - .getNamespaceContext(), xPath)); - } catch (XPathExpressionException e) { - ContributionReadException ce = new ContributionReadException(e); - error(monitor, "ContributionReadException", source, ce); - //throw ce; - } - } - componentProperty.setFile(getURIString(reader, FILE)); - - //handle extension attributes - this.readExtendedAttributes(reader, - name, - componentProperty, - extensionAttributeProcessor, context); - - policyProcessor.readPolicies(property, reader); - readAbstractProperty(componentProperty, reader, context); - - // Read the property value - Document value = - readPropertyValue(property.getXSDElement(), property.getXSDType(), property - .isMany(), reader, context); - property.setValue(value); - - component.getProperties().add(componentProperty); - } else { - - // Read a <composite><property> - property = assemblyFactory.createProperty(); - policyProcessor.readPolicies(property, reader); - readAbstractProperty(property, reader, context); - - // Read the property value - Document value = - readPropertyValue(property.getXSDElement(), property.getXSDType(), property - .isMany(), reader, context); - property.setValue(value); - - composite.getProperties().add(property); - } - - // TUSCANY-1949 - // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue - if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) { - property = null; - componentProperty = null; - } - - } else if (COMPONENT_QNAME.equals(name)) { - - // Read a <component> - component = assemblyFactory.createComponent(); - component.setName(getString(reader, NAME)); - if (isSet(reader, AUTOWIRE)) { - component.setAutowire(getBoolean(reader, AUTOWIRE)); - } - if (isSet(reader, URI)) { - component.setURI(getURIString(reader, URI)); - } - - //handle extension attributes - this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor, context); - - composite.getComponents().add(component); - policyProcessor.readPolicies(component, reader); - - } else if (WIRE_QNAME.equals(name)) { - - // Read a <wire> - wire = assemblyFactory.createWire(); - ComponentReference source = assemblyFactory.createComponentReference(); - source.setUnresolved(true); - source.setName(getURIString(reader, SOURCE)); - wire.setSource(source); - - ComponentService target = assemblyFactory.createComponentService(); - target.setUnresolved(true); - target.setName(getURIString(reader, TARGET)); - wire.setTarget(target); - - // Read @replace - String replace = reader.getAttributeValue(null, REPLACE); - if (replace != null) { - wire.setReplace(Boolean.parseBoolean(replace)); - } - - //handle extension attributes - this.readExtendedAttributes(reader, name, wire, extensionAttributeProcessor, context); - - composite.getWires().add(wire); - policyProcessor.readPolicies(wire, reader); - - } else if (CALLBACK_QNAME.equals(name)) { - - // Read a <callback> - callback = assemblyFactory.createCallback(); - contract.setCallback(callback); - callback.setParentContract(contract); - - //handle extension attributes - this.readExtendedAttributes(reader, name, callback, extensionAttributeProcessor, context); - - policyProcessor.readPolicies(callback, reader); - - // set the parent model so that binding processing can - // detect it they're being read as part of a callback - context.setParentModel(callback); - - } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) { - - // Read an implementation.composite - Composite implementation = assemblyFactory.createComposite(); - implementation.setName(getQName(reader, NAME)); - implementation.setUnresolved(true); - - //handle extension attributes - this.readExtendedAttributes(reader, name, implementation, extensionAttributeProcessor, context); - - component.setImplementation(implementation); - policyProcessor.readPolicies(implementation, reader); - } else if (REQUIRES_QNAME.equals(name)) { - List<QName> intents = getQNames(reader, INTENTS); - for (QName i : intents) { - Intent intent = policyFactory.createIntent(); - intent.setName(i); - if (composite != null) { - composite.getRequiredIntents().add(intent); - } else if (component != null) { - component.getRequiredIntents().add(intent); - } else if (contract != null) { - contract.getRequiredIntents().add(intent); - } else if (callback != null) { - callback.getRequiredIntents().add(intent); - } - } - } else if (POLICY_SET_ATTACHMENT_QNAME.equals(name)) { - QName ps = getQName(reader, NAME); - if (ps != null) { - PolicySet policySet = policyFactory.createPolicySet(); - policySet.setName(ps); - if (composite != null) { - composite.getPolicySets().add(policySet); - } else if (component != null) { - component.getPolicySets().add(policySet); - } else if (contract != null) { - contract.getPolicySets().add(policySet); - } else if (callback != null) { - callback.getPolicySets().add(policySet); - } - } - } else if(EXTENSION_QNAME.equals(name)) { - // Handle <extension> - //ignore element as this is a wrapper for extensibility - break; - } else { - - // Read an extension element - Object extension = extensionProcessor.read(reader, context); - if (extension != null) { - if (extension instanceof InterfaceContract) { - - // <service><interface> and - // <reference><interface> - if (contract != null) { - contract.setInterfaceContract((InterfaceContract)extension); - } else { - if (name.getNamespaceURI().equals(SCA11_NS)) { - error(monitor, "UnexpectedInterfaceElement", extension); - //throw new ContributionReadException("Unexpected <interface> element found. It should appear inside a <service> or <reference> element"); - } else { - composite.getExtensions().add(extension); - } - } - } else if (extension instanceof Binding) { - if (extension instanceof PolicySubject) { - ExtensionType bindingType = intentAttachPointTypeFactory.createBindingType(); - bindingType.setType(name); - bindingType.setUnresolved(true); - ((PolicySubject)extension).setExtensionType(bindingType); - } - // <service><binding> and - // <reference><binding> - if (callback != null) { - callback.getBindings().add((Binding)extension); - } else { - if (contract != null) { - contract.getBindings().add((Binding)extension); - } else { - if (name.getNamespaceURI().equals(SCA11_NS)) { - error(monitor, "UnexpectedBindingElement", extension); - //throw new ContributionReadException("Unexpected <binding> element found. It should appear inside a <service> or <reference> element"); - } else { - composite.getExtensions().add(extension); - } - } - } - - } else if (extension instanceof Implementation) { - if (extension instanceof PolicySubject) { - ExtensionType implType = - intentAttachPointTypeFactory.createImplementationType(); - implType.setType(name); - implType.setUnresolved(true); - ((PolicySubject)extension).setExtensionType(implType); - } - // <component><implementation> - if (component != null) { - component.setImplementation((Implementation)extension); - } else { - if (name.getNamespaceURI().equals(SCA11_NS)) { - error(monitor, "UnexpectedImplementationElement", extension); - //throw new ContributionReadException("Unexpected <implementation> element found. It should appear inside a <component> element"); - } else { - composite.getExtensions().add(extension); - } - } - } else { - - // Add the extension element to the current - // element - if (callback != null) { - callback.getExtensions().add(extension); - } else if (contract != null) { - contract.getExtensions().add(extension); - } else if (property != null) { - property.getExtensions().add(extension); - } else if (component != null) { - component.getExtensions().add(extension); - } else { - composite.getExtensions().add(extension); - } - } - } - } - break; - - case XMLStreamConstants.CHARACTERS: - break; - - case END_ELEMENT: - name = reader.getName(); - - // Clear current state when reading reaching end element - if (SERVICE_QNAME.equals(name)) { - componentService = null; - compositeService = null; - contract = null; - } else if (INCLUDE_QNAME.equals(name)) { - include = null; - } else if (REFERENCE_QNAME.equals(name)) { - componentReference = null; - compositeReference = null; - contract = null; - } else if (PROPERTY_QNAME.equals(name)) { - componentProperty = null; - property = null; - } else if (COMPONENT_QNAME.equals(name)) { - component = null; - } else if (WIRE_QNAME.equals(name)) { - wire = null; - } else if (CALLBACK_QNAME.equals(name)) { - callback = null; - } - break; - } - - // Read the next element - if (reader.hasNext()) { - reader.next(); - } - } - } catch (XMLStreamException e) { - ContributionReadException ex = new ContributionReadException(e); - error(monitor, "XMLStreamException", reader, ex); - } - - return composite; - } - - /** - * Prepares the property @source XPath expression - * - * The form of the @source attribute in the composite file must take one of the forms - * $propertyName - * $propertyName/expression - * $propertyName[n] - * $propertyName[n]/expression - * Property values are stored as <sca:property> elements with one or more <sca:value> subelements or one or more - * global element subelements. The XPath constructed is designed to work against this XML structure and aims to - * retrieve one or more of the subelements or subportions of those subelements (eg some text content). - * Thus the XPath: - * - starts with "*", which means "all the child elements of the root" where root = the <property/> element - * - may then be followed by [xxx] (typically [n] to select one of the child elements) if the source string has [xxx] - * following the propertyName - * - may then be followed by /expression, if the source contains an expression, which will typically select some subportion - * of the child element(s) - * - * @param source - the @source attribute string from a <sca:property> element - * @return the XPath string to use for the source property - */ - private String prepareSourceXPathString( String source ) { - String output = null; - // Expression must begin with '$' - if( source.charAt(0) != '$' ) return output; - - int slash = source.indexOf('/'); - int bracket = source.indexOf('['); - if (slash == -1) { - // Form is $propertyName or $propertyName[n] - output = "*"; - if( bracket != -1 ) { - output = "*" + source.substring(bracket); - } - } else { - // Form is $propertyName/exp or $propertyName[n]/exp - output = "*/" + source.substring(slash + 1); - if( bracket != -1 && bracket < slash ) { - output = "*" + source.substring(bracket); - } - } // end if - - return output; - } // end method prepareSourceXPathString( source ) - - public void write(Composite composite, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, - XMLStreamException { - - // Write <composite> element - writeStartDocument(writer, - COMPOSITE, - new XAttr(TARGET_NAMESPACE, composite.getName().getNamespaceURI()), - new XAttr(NAME, composite.getName().getLocalPart()), - new XAttr(LOCAL, composite.isLocal() ? Boolean.TRUE : null), - new XAttr(AUTOWIRE, composite.getAutowire()), - policyProcessor.writePolicies(composite)); - - //write extended attributes - this.writeExtendedAttributes(writer, composite, extensionAttributeProcessor, context); - - // Write <include> elements - for (Composite include : composite.getIncludes()) { - String uri = include.isUnresolved() ? include.getURI() : null; - writeStart(writer, INCLUDE, new XAttr(NAME, include.getName()), new XAttr(URI, uri)); - - //write extended attributes - this.writeExtendedAttributes(writer, include, extensionAttributeProcessor, context); - - writeEnd(writer); - } - - // Write <service> elements - for (Service service : composite.getServices()) { - CompositeService compositeService = (CompositeService)service; - Component promotedComponent = compositeService.getPromotedComponent(); - ComponentService promotedService = compositeService.getPromotedService(); - String promote; - if (promotedService != null) { - if (promotedService.getName() != null) { - promote = promotedComponent.getName() + '/' + promotedService.getName(); - } else { - promote = promotedComponent.getName(); - } - } else { - promote = null; - } - writeStart(writer, - SERVICE, - new XAttr(NAME, service.getName()), - new XAttr(PROMOTE, promote), - policyProcessor.writePolicies(service)); - - //write extended attributes - this.writeExtendedAttributes(writer, service, extensionAttributeProcessor, context); - - // Write service interface - extensionProcessor.write(service.getInterfaceContract(), writer, context); - - // Write bindings - for (Binding binding : service.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - // Write <callback> element - if (service.getCallback() != null) { - Callback callback = service.getCallback(); - writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); - - //write extended attributes - this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context); - - // Write callback bindings - for (Binding binding : callback.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - // Write extensions - this.writeExtendedElements(writer, service, extensionProcessor, context); - - writeEnd(writer); - } - - // Write extensions - this.writeExtendedElements(writer, service, extensionProcessor, context); - - writeEnd(writer); - } - - // Write <component> elements - for (Component component : composite.getComponents()) { - writeStart(writer, - COMPONENT, - new XAttr(NAME, component.getName()), - new XAttr(URI, component.getURI()), - new XAttr(AUTOWIRE, component.getAutowire()), - policyProcessor.writePolicies(component)); - - //write extended attributes - this.writeExtendedAttributes(writer, component, extensionAttributeProcessor, context); - - // Write the component implementation - Implementation implementation = component.getImplementation(); - if (implementation instanceof Composite) { - writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, ((Composite)implementation).getName())); - - //write extended attributes - this.writeExtendedAttributes(writer, (Composite)implementation, extensionAttributeProcessor, context); - - writeEnd(writer); - } else { - extensionProcessor.write(component.getImplementation(), writer, context); - } - - for (Object extension : component.getExtensions()) { - extensionProcessor.write(extension, writer, context); - } - - // Write <service> elements - for (ComponentService service : component.getServices()) { - writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), policyProcessor.writePolicies(service)); - - //write extended attributes - this.writeExtendedAttributes(writer, service, extensionAttributeProcessor, context); - - // Write service interface - extensionProcessor.write(service.getInterfaceContract(), writer, context); - - // Write bindings - for (Binding binding : service.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - // Write <callback> element - if (service.getCallback() != null) { - Callback callback = service.getCallback(); - writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); - - //write extended attributes - this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context); - - // Write bindings - for (Binding binding : callback.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - // Write extensions - this.writeExtendedElements(writer, callback, extensionProcessor, context); - - writeEnd(writer); - } - - // Write extensions - this.writeExtendedElements(writer, service, extensionProcessor, context); - - writeEnd(writer); - } - - // Write <reference> elements - for (ComponentReference reference : component.getReferences()) { - writeStart(writer, - REFERENCE, - new XAttr(NAME, reference.getName()), - new XAttr(AUTOWIRE, reference.getAutowire()), - (reference.isNonOverridable() ? new XAttr(NONOVERRIDABLE, true) : null), - writeMultiplicity(reference), - writeTargets(reference), - policyProcessor.writePolicies(reference)); - - //write extended attributes - this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor, context); - - // Write reference interface - extensionProcessor.write(reference.getInterfaceContract(), writer, context); - - // Write bindings - for (Binding binding : reference.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - // Write callback - if (reference.getCallback() != null) { - Callback callback = reference.getCallback(); - writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback)); - - //write extended attributes - this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context); - - // Write callback bindings - for (Binding binding : callback.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - // Write extensions - this.writeExtendedElements(writer, callback, extensionProcessor, context); - - writeEnd(writer); - } - - // Write extensions - this.writeExtendedElements(writer, reference, extensionProcessor, context); - - writeEnd(writer); - } - - // Write <property> elements - for (ComponentProperty property : component.getProperties()) { - writeStart(writer, - PROPERTY, - new XAttr(NAME, property.getName()), - new XAttr(MUST_SUPPLY, property.isMustSupply()), - new XAttr(MANY, property.isMany()), - new XAttr(TYPE, property.getXSDType()), - new XAttr(ELEMENT, property.getXSDElement()), - new XAttr(SOURCE, property.getSource()), - new XAttr(FILE, property.getFile()), - policyProcessor.writePolicies(property)); - - //write extended attributes - this.writeExtendedAttributes(writer, property, extensionAttributeProcessor, context); - - // Write property value - writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer); - - // Write extensions - for (Object extension : property.getExtensions()) { - extensionProcessor.write(extension, writer, context); - } - - writeEnd(writer); - } - - writeEnd(writer); - } - - // Write <reference> elements - for (Reference reference : composite.getReferences()) { - CompositeReference compositeReference = (CompositeReference)reference; - - // Write list of promoted references - List<String> promote = new ArrayList<String>(); - for (ComponentReference promoted : compositeReference.getPromotedReferences()) { - promote.add(promoted.getName()); - } - - // Write <reference> element - writeStart(writer, - REFERENCE, - new XAttr(NAME, reference.getName()), - new XAttr(PROMOTE, promote), - writeMultiplicity(reference), - policyProcessor.writePolicies(reference)); - - //write extended attributes - this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor, context); - - // Write reference interface - extensionProcessor.write(reference.getInterfaceContract(), writer, context); - - // Write bindings - for (Binding binding : reference.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - // Write <callback> element - if (reference.getCallback() != null) { - Callback callback = reference.getCallback(); - writeStart(writer, CALLBACK); - - //write extended attributes - this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context); - - // Write callback bindings - for (Binding binding : callback.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - // Write extensions - this.writeExtendedElements(writer, callback, extensionProcessor, context); - - writeEnd(writer); - } - - // Write extensions - this.writeExtendedElements(writer, reference, extensionProcessor, context); - - writeEnd(writer); - } - - // Write <property> elements - for (Property property : composite.getProperties()) { - writeStart(writer, - PROPERTY, - new XAttr(NAME, property.getName()), - new XAttr(MUST_SUPPLY, property.isMustSupply()), - new XAttr(MANY, property.isMany()), - new XAttr(TYPE, property.getXSDType()), - new XAttr(ELEMENT, property.getXSDElement()), - policyProcessor.writePolicies(property)); - - //write extended attributes - this.writeExtendedAttributes(writer, property, extensionAttributeProcessor, context); - - // Write property value - writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer); - - // Write extensions - for (Object extension : property.getExtensions()) { - extensionProcessor.write(extension, writer, context); - } - - writeEnd(writer); - } - - // Write <wire> elements - for (Wire wire : composite.getWires()) { - writeStart(writer, WIRE, new XAttr(SOURCE, wire.getSource().getName()), new XAttr(TARGET, wire.getTarget() - .getName()), wire.isReplace() ? new XAttr(Constants.REPLACE, true) : null); - - //write extended attributes - this.writeExtendedAttributes(writer, wire, extensionAttributeProcessor, context); - - // Write extensions - for (Object extension : wire.getExtensions()) { - extensionProcessor.write(extension, writer, context); - } - writeEnd(writer); - } - - for (Object extension : composite.getExtensions()) { - extensionProcessor.write(extension, writer, context); - } - - writeEndDocument(writer); - } - - public void resolve(Composite composite, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - - Monitor monitor = context.getMonitor(); - try { - monitor.pushContext("Composite: " + composite.getName()); - - // Resolve includes in the composite - for (int i = 0, n = composite.getIncludes().size(); i < n; i++) { - Composite include = composite.getIncludes().get(i); - if (include != null) { - Composite resolved = resolver.resolveModel(Composite.class, include, context); - if (!resolved.isUnresolved()) { - if ((composite.isLocal() && resolved.isLocal()) || (!composite.isLocal() && !resolved.isLocal())) { - composite.getIncludes().set(i, resolved); - } else { - ContributionResolveException ce = - new ContributionResolveException("[ASM60041] Error: Composite " + composite.getName() - + " can only include another composite with the identical @local attribute value"); - error(monitor, "ContributionResolveException", include, ce); - } - } else { - ContributionResolveException ce = - new ContributionResolveException("[ASM60042] Error: Composite " + include.getName() - + " is not a valid composite within the domain"); - error(monitor, "ContributionResolveException", include, ce); - } - } - } - - // Resolve extensions - for (Object extension : composite.getExtensions()) { - if (extension != null) { - extensionProcessor.resolve(extension, resolver, context); - } - } - - //Resolve composite services and references - resolveContracts(composite, composite.getServices(), resolver, context); - resolveContracts(composite, composite.getReferences(), resolver, context); - - for (Property property : composite.getProperties()){ - resolvePropertyType("composite " + composite.getName().toString(), - property, - context.getContribution(), context); - } - - // Resolve component implementations, services and references - for (Component component : composite.getComponents()) { - - //resolve component services and references - resolveContracts(component, component.getServices(), resolver, context); - resolveContracts(component, component.getReferences(), resolver, context); - - for (ComponentProperty componentProperty : component.getProperties()) { - // resolve a reference to a property file - if (componentProperty.getFile() != null) { - Artifact artifact = contributionFactory.createArtifact(); - artifact.setURI(componentProperty.getFile()); - artifact = resolver.resolveModel(Artifact.class, artifact, context); - if (artifact.getLocation() != null) { - componentProperty.setFile(artifact.getLocation()); - } - } - - // resolve the reference to a complex property - resolvePropertyType("component " + component.getName(), - componentProperty, - context.getContribution(), context); - } - - //resolve component implementation - Implementation implementation = component.getImplementation(); - if (implementation != null) { - //now resolve the implementation so that even if there is a shared instance - //for this that is resolved, the specified intents and policysets are safe in the - //component and not lost - List<Intent> intents = implementation.getRequiredIntents(); - List<PolicySet> policySets = implementation.getPolicySets(); - - - implementation = resolveImplementation(implementation, resolver, context); - - implementation.getPolicySets().clear(); - implementation.getPolicySets().addAll(policySets); - implementation.getRequiredIntents().clear(); - implementation.getRequiredIntents().addAll(intents); - - component.setImplementation(implementation); - } - - //add model resolver to component - if (component instanceof ResolverExtension) { - ((ResolverExtension)component).setModelResolver(resolver); - } - } - - // Add model resolver to promoted components - for (Service service : composite.getServices()) { - CompositeService compositeService = (CompositeService)service; - Component promotedComponent = compositeService.getPromotedComponent(); - if (promotedComponent instanceof ResolverExtension) { - ((ResolverExtension)promotedComponent).setModelResolver(resolver); - } - } // end for - - } finally { - // Pop context - monitor.popContext(); - } // end try - } - - public QName getArtifactType() { - return COMPOSITE_QNAME; - } - - public Class<Composite> getModelType() { - return Composite.class; - } - - /** - * Write the value of a property - override to use correct method of creating an XMLStreamReader - * @param document - * @param element - * @param type - * @param writer - * @throws XMLStreamException - */ - @Override - protected void writePropertyValue(Object propertyValue, QName element, QName type, XMLStreamWriter writer) - throws XMLStreamException { - - if (propertyValue instanceof Document) { - Document document = (Document)propertyValue; - NodeList nodeList = document.getDocumentElement().getChildNodes(); - - for (int item = 0; item < nodeList.getLength(); ++item) { - Node node = nodeList.item(item); - int nodeType = node.getNodeType(); - if (nodeType == Node.ELEMENT_NODE) { - // Correct way to create a reader for a node object... - XMLStreamReader reader = staxHelper.createXMLStreamReader(node); - - while (reader.hasNext()) { - switch (reader.next()) { - case XMLStreamConstants.START_ELEMENT: - QName name = reader.getName(); - writer.writeStartElement(name.getPrefix(), name.getLocalPart(), name.getNamespaceURI()); - - int namespaces = reader.getNamespaceCount(); - for (int i = 0; i < namespaces; i++) { - String prefix = reader.getNamespacePrefix(i); - String ns = reader.getNamespaceURI(i); - writer.writeNamespace(prefix, ns); - } - - if (!"".equals(name.getNamespaceURI())) { - writer.writeNamespace(name.getPrefix(), name.getNamespaceURI()); - } - - // add the attributes for this element - namespaces = reader.getAttributeCount(); - for (int i = 0; i < namespaces; i++) { - String ns = reader.getAttributeNamespace(i); - String prefix = reader.getAttributePrefix(i); - String qname = reader.getAttributeLocalName(i); - String value = reader.getAttributeValue(i); - - writer.writeAttribute(prefix, ns, qname, value); - } - - break; - case XMLStreamConstants.CDATA: - writer.writeCData(reader.getText()); - break; - case XMLStreamConstants.CHARACTERS: - writer.writeCharacters(reader.getText()); - break; - case XMLStreamConstants.END_ELEMENT: - writer.writeEndElement(); - break; - } - } - } else { - writer.writeCharacters(node.getTextContent()); - } - } - } - } // end method writePropertyValue - - - /** - * Returns the model factory extension point to use. - * - * @param extensionPoints - * @return - */ - private static FactoryExtensionPoint modelFactories(ExtensionPointRegistry extensionPoints) { - return extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - } - - /** - * Property elements can have XSD types attributes so, in the case of a complex type, we need to find - * the XSD definition that defines that type in the contribution while we still have access to the - * contribution. Later, in the builder, we use this XSD definition to ensure that the property value - * is of the correct type - * - * @param property - * @param contribution - */ - private void resolvePropertyType(String parentName, Property property, Contribution contribution, ProcessorContext context){ - // resolve the reference to a complex property - // we ignore any types in the schema namespace - if (property.getXSDType() != null && - property.getXSDType().getNamespaceURI().equals("http://www.w3.org/2001/XMLSchema") != true){ - XSDefinition xsdDefinition = xsdFactory.createXSDefinition(); - xsdDefinition.setUnresolved(true); - xsdDefinition.setNamespace(property.getXSDType().getNamespaceURI()); - // some unit tests don't set up contribution and model resolvers properly - if (contribution != null && contribution.getModelResolver() != null) { - XSDefinition resolved = contribution.getModelResolver().resolveModel(XSDefinition.class, xsdDefinition, context); - if (resolved == null || resolved.isUnresolved()){ - // raise an error - // [rfeng] The XSD might be not available if we use JAXB annotated classes, report it as a warning for now - warning(context.getMonitor(), "PropertyTypeNotFound", property, property.getXSDType().toString(), property.getName(), parentName); - } else { - // store the schema in the property - property.setXSDDefinition(resolved); - } - } - } - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java deleted file mode 100644 index 9930096a26..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/ConfiguredOperationProcessor.java +++ /dev/null @@ -1,108 +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.assembly.xml; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.assembly.AssemblyFactory; -import org.apache.tuscany.sca.assembly.ConfiguredOperation; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.policy.PolicyFactory; - -/** - * Processor for dealing with 'operation' elements from composite definitions - * - * @version $Rev$ $Date$ - * @tuscany.spi.extension.asclient - */ -public class ConfiguredOperationProcessor implements StAXArtifactProcessor<ConfiguredOperation>, Constants{ - - private AssemblyFactory assemblyFactory; - private PolicySubjectProcessor policyProcessor; - private PolicyFactory policyFactory; - - - public ConfiguredOperationProcessor(FactoryExtensionPoint modelFactories) { - this.assemblyFactory = modelFactories.getFactory(AssemblyFactory.class); - this.policyFactory = modelFactories.getFactory(PolicyFactory.class); - this.policyProcessor = new PolicySubjectProcessor(policyFactory); - } - - public ConfiguredOperation read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { - ConfiguredOperation configuredOp = assemblyFactory.createConfiguredOperation(); - - //Read an <operation> - configuredOp.setName(reader.getAttributeValue(null, NAME)); - configuredOp.setContractName(reader.getAttributeValue(null, SERVICE)); - configuredOp.setUnresolved(true); - - // Read policies - policyProcessor.readPolicies(configuredOp, reader); - - //Skip to end element - while (reader.hasNext()) { - if (reader.next() == END_ELEMENT && OPERATION_QNAME.equals(reader.getName())) { - break; - } - } - - return configuredOp; - } - - public void write(ConfiguredOperation configuredOperation, XMLStreamWriter writer, ProcessorContext context) - throws ContributionWriteException, XMLStreamException { - - // Write an <operation> - writer.writeStartElement(Constants.SCA11_NS, OPERATION); - policyProcessor.writePolicyAttributes(configuredOperation, writer); - - writer.writeAttribute(NAME, configuredOperation.getName()); - if ( configuredOperation.getContractName() != null ) { - writer.writeAttribute(SERVICE, configuredOperation.getContractName()); - } - writer.writeEndElement(); - } - - public void resolve(ConfiguredOperation configuredOperation, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - } - - public QName getArtifactType() { - return OPERATION_QNAME; - } - - public Class<ConfiguredOperation> getModelType() { - return ConfiguredOperation.class; - } - -} - - diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java deleted file mode 100644 index 0c88a01b19..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Constants.java +++ /dev/null @@ -1,181 +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.assembly.xml; - -import javax.xml.namespace.QName; - -/** - * Constants used in SCA assembly XML files. - * - * @version $Rev$ $Date$ - * @tuscany.spi.extension - */ -public interface Constants { - String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912"; - String SCA11_TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; - - String COMPONENT_TYPE = "componentType"; - QName COMPONENT_TYPE_QNAME = new QName(SCA11_NS, COMPONENT_TYPE); - - String SERVICE = "service"; - QName SERVICE_QNAME = new QName(SCA11_NS, SERVICE); - - String REFERENCE = "reference"; - QName REFERENCE_QNAME = new QName(SCA11_NS, REFERENCE); - - String PROPERTY = "property"; - QName PROPERTY_QNAME = new QName(SCA11_NS, PROPERTY); - - String COMPOSITE = "composite"; - QName COMPOSITE_QNAME = new QName(SCA11_NS, COMPOSITE); - - String INCLUDE = "include"; - QName INCLUDE_QNAME = new QName(SCA11_NS, INCLUDE); - - String COMPONENT = "component"; - QName COMPONENT_QNAME = new QName(SCA11_NS, COMPONENT); - - String WIRE = "wire"; - QName WIRE_QNAME = new QName(SCA11_NS, WIRE); - - String OPERATION = "operation"; - QName OPERATION_QNAME = new QName(SCA11_NS, OPERATION); - - String CALLBACK = "callback"; - QName CALLBACK_QNAME = new QName(SCA11_NS, CALLBACK); - - String IMPLEMENTATION_COMPOSITE = "implementation.composite"; - QName IMPLEMENTATION_COMPOSITE_QNAME = new QName(SCA11_NS, IMPLEMENTATION_COMPOSITE); - - String IMPLEMENTATION = "implementation"; - QName IMPLEMENTATION_QNAME = new QName(SCA11_NS, IMPLEMENTATION); - - String BINDING_SCA = "binding.sca"; - QName BINDING_SCA_QNAME = new QName(Constants.SCA11_NS, BINDING_SCA); - - String EXTENSION = "extensions"; - QName EXTENSION_QNAME = new QName(Constants.SCA11_NS, EXTENSION); - - String NAME = "name"; - String VALUE = "value"; - QName VALUE_QNAME = new QName(SCA11_NS, VALUE); - - String POLICY_SET_ATTACHMENT = "policySetAttachment"; - QName POLICY_SET_ATTACHMENT_QNAME = new QName(SCA11_NS, POLICY_SET_ATTACHMENT); - - String TARGET_NAMESPACE = "targetNamespace"; - String LOCAL = "local"; - String AUTOWIRE = "autowire"; - String NONOVERRIDABLE = "nonOverridable"; - String REPLACE = "replace"; - String REQUIRES = "requires"; - QName REQUIRES_QNAME = new QName(SCA11_NS, REQUIRES); - String INTENTS = "intents"; - - String POLICY_SETS = "policySets"; - String PROMOTE = "promote"; - String TARGET = "target"; - String WIRED_BY_IMPL = "wiredByImpl"; - String MULTIPLICITY = "multiplicity"; - String TYPE = "type"; - String ELEMENT = "element"; - String MANY = "many"; - String MUST_SUPPLY = "mustSupply"; - String SOURCE = "source"; - String FILE = "file"; - String URI = "uri"; - String ZERO_ONE = "0..1"; - String ZERO_N = "0..n"; - String ONE_ONE = "1..1"; - String ONE_N = "1..n"; - - String SERVER_AUTHENTICATION = "serverAuthentication"; - QName SERVER_AUTHENTICATION_INTENT = new QName(SCA11_NS, SERVER_AUTHENTICATION); - String SERVER_AUTHENTICATION_TRANSPORT = "serverAuthentication.transport"; - QName SERVER_AUTHENTICATION_TRANSPORT_INTENT = new QName(SCA11_NS, SERVER_AUTHENTICATION_TRANSPORT); - String SERVER_AUTHENTICATION_MESSAGE = "serverAuthentication.message"; - QName SERVER_AUTHENTICATION_MESSAGE_INTENT = new QName(SCA11_NS, SERVER_AUTHENTICATION_MESSAGE); - - String CLIENT_AUTHENTICATION = "clientAuthentication"; - QName CLIENT_AUTHENTICATION_INTENT = new QName(SCA11_NS, CLIENT_AUTHENTICATION); - String CLIENT_AUTHENTICATION_TRANSPORT = "clientAuthentication.transport"; - QName CLIENT_AUTHENTICATION_TRANSPORT_INTENT = new QName(SCA11_NS, CLIENT_AUTHENTICATION_TRANSPORT); - String CLIENT_AUTHENTICATION_MESSAGE = "clientAuthentication.message"; - QName CLIENT_AUTHENTICATION_MESSAGE_INTENT = new QName(SCA11_NS, CLIENT_AUTHENTICATION_MESSAGE); - - String AUTHENTICATION = "authentication"; - QName AUTHENTICATION_INTENT = new QName(SCA11_NS, AUTHENTICATION); - - String MUTUAL_AUTHENTICATION = "mutualAuthentication"; - QName MUTUAL_AUTHENTICATION_INTENT = new QName(SCA11_NS, MUTUAL_AUTHENTICATION); - - String CONFIDENTIALITY = "confidentiality"; - QName CONFIDENTIALITY_INTENT = new QName(SCA11_NS, CONFIDENTIALITY); - String CONFIDENTIALITY_TRANSPORT = "confidentiality.transport"; - QName CONFIDENTIALITY_TRANSPORT_INTENT = new QName(SCA11_NS, CONFIDENTIALITY_TRANSPORT); - String CONFIDENTIALITY_MESSAGE = "confidentiality.message"; - QName CONFIDENTIALITY_MESSAGE_INTENT = new QName(SCA11_NS, CONFIDENTIALITY_MESSAGE); - - String INTEGRITY = "integrity"; - QName INTEGRITY_INTENT = new QName(SCA11_NS, "INTEGRITY"); - String INTEGRITY_TRANSPORT = "integrity.transport"; - QName INTEGRITY_TRANSPORT_INTENT = new QName(SCA11_NS, INTEGRITY_TRANSPORT); - String INTEGRITY_MESSAGE = "integrity.message"; - QName INTEGRITY_MESSAGE_INTENT = new QName(SCA11_NS, INTEGRITY_MESSAGE); - - String AUTHORIZATION = "authorization"; - QName AUTHORIZATION_INTENT = new QName(SCA11_NS, "INTEGRITY"); - String AUTHORIZATION_FINE_GRAIN = "authorization.fineGrain"; - QName AUTHORIZATION_FINE_GRAIN_INTENT = new QName(SCA11_NS, AUTHORIZATION_FINE_GRAIN); - - String MANAGED_TRANSACTION = "managedTransaction"; - QName MANAGED_TRANSACTION_INTENT = new QName(SCA11_NS, MANAGED_TRANSACTION); - - String NO_MANAGED_TRANSACTION = "noManagedTransaction"; - QName NO_MANAGED_TRANSACTION_INTENT = new QName(SCA11_NS, NO_MANAGED_TRANSACTION); - - String MANAGED_TRANSACTION_LOCAL = "managedTransaction.local"; - QName MANAGED_TRANSACTION_LOCAL_INTENT = new QName(SCA11_NS, MANAGED_TRANSACTION_LOCAL); - - String MANAGED_TRANSACTION_GLOBAL = "managedTransaction.global"; - QName MANAGED_TRANSACTION_GLOBAL_INTENT = new QName(SCA11_NS, MANAGED_TRANSACTION_GLOBAL); - - String PROPAGATES_TRANSACTION = "propagatesTransaction"; - QName PROPAGATES_TRANSACTION_INTENT = new QName(SCA11_NS, PROPAGATES_TRANSACTION); - - String SUSPENDS_TRANSACTION = "suspendsTransaction"; - QName SUSPENDS_TRANSACTION_INTENT = new QName(SCA11_NS, SUSPENDS_TRANSACTION); - - String TRANSACTED_ONE_WAY = "transactedOneWay"; - QName TRANSACTED_ONE_WAY_INTENT = new QName(SCA11_NS, TRANSACTED_ONE_WAY); - - String IMMEDIATE_ONE_WAY = "immediateOneWay"; - QName IMMEDIATE_ONE_WAY_INTENT = new QName(SCA11_NS, IMMEDIATE_ONE_WAY); - - String NOLISTENER = "noListener"; - QName NOLISTENER_INTENT = new QName(SCA11_NS, NOLISTENER); - - String SOAP = "SOAP"; - QName SOAP_INTENT = new QName(SCA11_NS, SOAP); - String SOAP11 = "SOAP.v1_1"; - QName SOAP11_INTENT = new QName(SCA11_NS, SOAP11); - String SOAP12 = "SOAP.v1_2"; - QName SOAP12_INTENT = new QName(SCA11_NS, SOAP12); -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java deleted file mode 100644 index e6e172a44b..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/DefaultBeanModelProcessor.java +++ /dev/null @@ -1,257 +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.assembly.xml; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.assembly.Base; -import org.apache.tuscany.sca.assembly.ComponentType; -import org.apache.tuscany.sca.assembly.Implementation; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.policy.PolicySubject; - -/** - * Default Model Processor for beans. - * - * @version $Rev$ $Date$ - */ -public class DefaultBeanModelProcessor<T> extends BaseAssemblyProcessor implements StAXArtifactProcessor<T> { - - private QName artifactType; - private Class<T> modelClass; - private Object modelFactory; - private Method factoryMethod; - private Map<String, Method> setterMethods = new HashMap<String, Method>(); - private Map<String, Method> getterMethods = new HashMap<String, Method>(); - - public DefaultBeanModelProcessor(FactoryExtensionPoint modeFactories, - QName artifactType, - Class<T> modelClass, - Object modelFactory) { - super(modeFactories, null); - this.artifactType = artifactType; - this.modelClass = modelClass; - this.modelFactory = modelFactory; - - // Introspect the factory class and bean model class - if (modelFactory != null) { - - // Find the model create method - for (Method method: modelFactory.getClass().getMethods()) { - if (method.getName().startsWith("create") && method.getReturnType() == modelClass) { - factoryMethod = method; - break; - } - } - } - - // Index the bean's setter methods - for (Method method: modelClass.getMethods()) { - Method getter; - String name = method.getName(); - if (name.startsWith("set") && name.length() > 3) { - - // Get the corresponding getter method - try { - getter = modelClass.getMethod("get" + name.substring(3)); - } catch (Exception e) { - getter = null; - continue; - } - - // Get the property name - name = name.substring(3); - if (name.length() > 1) { - if (!name.toUpperCase().equals(name)) { - name = name.substring(0, 1).toLowerCase() + name.substring(1); - } - } - } else { - continue; - } - - // Map an uppercase property name to a lowercase attribute name - if (name.toUpperCase().equals(name)) { - name = name.toLowerCase(); - } - - // Trim trailing _ from property names - if (name.endsWith("_")) { - name = name.substring(0, name.length()-1); - } - setterMethods.put(name, method); - getterMethods.put(name, getter); - } - } - - public T read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { - - // Read an element - try { - - // Create a new instance of the model - Object model; - if (modelFactory != null) { - // Invoke the factory create method - model = factoryMethod.invoke(modelFactory); - } else { - // Invoke the model bean class default constructor - model = modelClass.newInstance(); - } - - // Initialize the bean properties with the attributes found in the - // XML element - for (int i = 0, n = reader.getAttributeCount(); i < n; i++) { - String attributeName = reader.getAttributeLocalName(i); - Method setter = setterMethods.get(attributeName); - if (setter != null) { - String value = null; - if (attributeName.equals("uri")){ - value = getURIString(reader, "uri"); - } else { - value = reader.getAttributeValue(i); - } - setter.invoke(model, value); - } - } - - // Read policies - policyProcessor.readPolicies(model, reader); - - // FIXME read extension elements - - // By default mark the model object unresolved - if (model instanceof Base) { - ((Base)model).setUnresolved(true); - } - - // Skip to end element - while (reader.hasNext()) { - if (reader.next() == END_ELEMENT && artifactType.equals(reader.getName())) { - break; - } - } - return (T) model; - - } catch (Exception e) { - ContributionReadException ce = new ContributionReadException(e); - error(context.getMonitor(), "ContributionReadException", reader, ce); - throw ce; - } - } - - public void write(T bean, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { - try { - // Write the bean properties as attributes - List<XAttr> attrs = new ArrayList<XAttr>(); - for (Map.Entry<String, Method> entry: getterMethods.entrySet()) { - if (entry.getValue().getReturnType() == String.class) { - String value = (String)entry.getValue().invoke(bean); - attrs.add(new XAttr(entry.getKey(), value)); - } - } - - // Write element - writeStart(writer, artifactType.getNamespaceURI(), artifactType.getLocalPart(), - policyProcessor.writePolicies(bean), new XAttr(null, attrs)); - - writeEnd(writer); - - } catch (Exception e) { - ContributionWriteException ce = new ContributionWriteException(e); - error(context.getMonitor(), "ContributionWriteException", writer, ce); - throw ce; - } - } - - public void resolve(T bean, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - - // Resolve and merge the component type associated with an - // implementation model - if (bean instanceof Implementation) { - Implementation implementation = (Implementation)bean; - String uri = implementation.getURI(); - if (uri != null) { - int d = uri.lastIndexOf('.'); - if (d != -1) { - uri = uri.substring(0, d) + ".componentType"; - - // Resolve the component type - ComponentType componentType = assemblyFactory.createComponentType(); - componentType.setURI(uri); - componentType.setUnresolved(true); - - componentType = resolver.resolveModel(ComponentType.class, componentType, context); - if (componentType != null && !componentType.isUnresolved()) { - - // We found a component type, merge it into the implementation model - implementation.getServices().addAll(componentType.getServices()); - implementation.getReferences().addAll(componentType.getReferences()); - implementation.getProperties().addAll(componentType.getProperties()); - - if (implementation instanceof PolicySubject && - componentType instanceof PolicySubject ) { - PolicySubject policiedImpl = (PolicySubject)implementation; - PolicySubject policiedCompType = (PolicySubject)componentType; - - if ( policiedImpl.getPolicySets() != null) { - policiedImpl.getPolicySets().addAll(policiedCompType.getPolicySets()); - } - if (policiedImpl.getRequiredIntents() != null) { - policiedImpl.getRequiredIntents().addAll(policiedCompType.getRequiredIntents()); - } - } - } - } - } - } - - // Mark the model resolved - if (bean instanceof Base) { - ((Base)bean).setUnresolved(false); - } - } - - public QName getArtifactType() { - return artifactType; - } - - public Class<T> getModelType() { - return modelClass; - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointProcessor.java deleted file mode 100644 index d128897df0..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointProcessor.java +++ /dev/null @@ -1,132 +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.assembly.xml; - -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.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -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.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; - -/** - * - */ -public class EndpointProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<Endpoint> { - private final static String ENDPOINT = "endpoint"; - private final static QName ENDPOINT_QNAME = new QName(Constants.SCA11_TUSCANY_NS, ENDPOINT); - - private ExtensionPointRegistry registry; - - public EndpointProcessor(ExtensionPointRegistry registry, - StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor) { - - super(modelFactories(registry), extensionProcessor); - this.registry = registry; - } - - /** - * Returns the model factory extension point to use. - * - * @param extensionPoints - * @return - */ - private static FactoryExtensionPoint modelFactories(ExtensionPointRegistry extensionPoints) { - return extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - } - - public QName getArtifactType() { - return ENDPOINT_QNAME; - } - - public Endpoint read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { - Endpoint endpoint = assemblyFactory.createEndpoint(); - if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT) { - reader.nextTag(); - } - Object model = extensionProcessor.read(reader, context); - if (model instanceof Composite) { - Composite composite = (Composite)model; - Component component = composite.getComponents().get(0); - ComponentService service = component.getServices().get(0); - Binding binding = service.getBindings().get(0); - endpoint.setComponent(component); - endpoint.setService(service); - endpoint.setBinding(binding); - } - return endpoint; - } - - public void write(Endpoint model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { - // writeStart(writer, ENDPOINT_QNAME); - extensionProcessor.write(wrap(model), writer, context); - // writeEnd(writer); - } - - private Composite wrap(Endpoint endpoint) { - try { - Composite composite = assemblyFactory.createComposite(); - composite.setName(ENDPOINT_QNAME); - composite.setLocal(false); - if (endpoint.getComponent() != null) { - Component component = (Component)endpoint.getComponent().clone(); - component.setImplementation(null); - composite.getComponents().add(component); - component.getReferences().clear(); - component.getServices().clear(); - if (endpoint.getService() != null) { - ComponentService service = (ComponentService)endpoint.getService().clone(); - component.getServices().add(service); - service.getBindings().clear(); - service.setInterfaceContract(endpoint.getComponentServiceInterfaceContract()); - if (endpoint.getBinding() != null) { - Binding binding = (Binding)endpoint.getBinding().clone(); - service.getBindings().add(binding); - } - } - } - return composite; - } catch (CloneNotSupportedException e) { - return null; - } - } - - public Class<Endpoint> getModelType() { - return Endpoint.class; - } - - public void resolve(Endpoint model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointReferenceProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointReferenceProcessor.java deleted file mode 100644 index eda90c9d44..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/EndpointReferenceProcessor.java +++ /dev/null @@ -1,151 +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.assembly.xml; - -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.Binding; -import org.apache.tuscany.sca.assembly.Component; -import org.apache.tuscany.sca.assembly.ComponentReference; -import org.apache.tuscany.sca.assembly.ComponentService; -import org.apache.tuscany.sca.assembly.Composite; -import org.apache.tuscany.sca.assembly.Endpoint; -import org.apache.tuscany.sca.assembly.EndpointReference; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -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.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; - -/** - * - */ -public class EndpointReferenceProcessor extends BaseAssemblyProcessor implements StAXArtifactProcessor<EndpointReference> { - private final static String ENDPOINT_REFERENCE = "endpointReference"; - private final static QName ENDPOINT_REFERENCE_QNAME = new QName(Constants.SCA11_TUSCANY_NS, ENDPOINT_REFERENCE); - - private ExtensionPointRegistry registry; - - public EndpointReferenceProcessor(ExtensionPointRegistry registry, - StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor) { - - super(modelFactories(registry), extensionProcessor); - this.registry = registry; - } - - /** - * Returns the model factory extension point to use. - * - * @param extensionPoints - * @return - */ - private static FactoryExtensionPoint modelFactories(ExtensionPointRegistry extensionPoints) { - return extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); - } - - public QName getArtifactType() { - return ENDPOINT_REFERENCE_QNAME; - } - - public EndpointReference read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { - EndpointReference endpointReference = assemblyFactory.createEndpointReference(); - if (reader.getEventType() == XMLStreamConstants.START_DOCUMENT) { - reader.nextTag(); - } - Object model = extensionProcessor.read(reader, context); - if (model instanceof Composite) { - Composite composite = (Composite)model; - Component component = composite.getComponents().get(0); - ComponentReference reference = component.getReferences().get(0); - Binding binding = reference.getBindings().get(0); - endpointReference.setComponent(component); - endpointReference.setReference(reference); - reference.getEndpointReferences().add(endpointReference); - endpointReference.setBinding(binding); - - // set up the EPR so that resolution will happen - // at wire creation time if needs be - Endpoint endpoint = assemblyFactory.createEndpoint(); - endpointReference.setTargetEndpoint(endpoint); - - if (reference.getTargets().size() > 0){ - // create a dummy endpoint with the URI set so that - // the endpoint registry will be consulted - endpoint.setUnresolved(true); - endpoint.setURI(reference.getTargets().get(0).getName()); - endpointReference.setStatus(EndpointReference.Status.WIRED_TARGET_NOT_FOUND); - endpointReference.setUnresolved(true); - } else { - endpoint.setUnresolved(false); - endpoint.setBinding(reference.getBindings().get(0)); - endpointReference.setStatus(EndpointReference.Status.RESOLVED_BINDING); - endpointReference.setUnresolved(false); - } - } - return endpointReference; - } - - public void write(EndpointReference model, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { - extensionProcessor.write(wrap(model), writer, context); - } - - private Composite wrap(EndpointReference endpointReference) { - try { - Composite composite = assemblyFactory.createComposite(); - composite.setName(ENDPOINT_REFERENCE_QNAME); - composite.setLocal(false); - Component component = (Component)endpointReference.getComponent().clone(); - composite.getComponents().add(component); - component.getReferences().clear(); - component.getServices().clear(); - ComponentReference reference = (ComponentReference)endpointReference.getReference().clone(); - component.getReferences().add(reference); - reference.getBindings().clear(); - Binding binding = (Binding)endpointReference.getBinding().clone(); - reference.getBindings().add(binding); - //reference.setInterfaceContract(endpointReference.getInterfaceContract()); - if (endpointReference.getStatus() != EndpointReference.Status.RESOLVED_BINDING){ - ComponentService service = assemblyFactory.createComponentService(); - service.setName(endpointReference.getTargetEndpoint().getURI()); - reference.getTargets().clear(); - reference.getTargets().add(service); - } - return composite; - } catch (CloneNotSupportedException e) { - return null; - } - } - - public Class<EndpointReference> getModelType() { - return EndpointReference.class; - } - - public void resolve(EndpointReference model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Messages.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Messages.java deleted file mode 100644 index 0391acc676..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/Messages.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.assembly.xml; - -/** - * Constants for resource bundle names - * @tuscany.spi.extension - */ -public interface Messages { - String RESOURCE_BUNDLE = "org.apache.tuscany.sca.assembly.xml.assembly-xml-validation-messages"; -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicySubjectProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicySubjectProcessor.java deleted file mode 100644 index 286f109f44..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/PolicySubjectProcessor.java +++ /dev/null @@ -1,242 +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.assembly.xml; - -import static org.apache.tuscany.sca.assembly.xml.Constants.POLICY_SETS; -import static org.apache.tuscany.sca.assembly.xml.Constants.REQUIRES; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.PolicyFactory; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.PolicySubject; - -/** - * A Policy Attach Point processor. - * - * @version $Rev$ $Date$ - * @tuscany.spi.extension.asclient - */ -public class PolicySubjectProcessor extends BaseStAXArtifactProcessor { - - private PolicyFactory policyFactory; - - public PolicySubjectProcessor(PolicyFactory policyFactory) { - this.policyFactory = policyFactory; - } - - public PolicySubjectProcessor(ExtensionPointRegistry registry) { - FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class); - this.policyFactory = factories.getFactory(PolicyFactory.class); - } - - /** - * Read policy intents associated with an operation. - * @param subject - * @param operation - * @param reader - */ - private void readIntents(Object subject, Operation operation, XMLStreamReader reader) { - if (!(subject instanceof PolicySubject)) - return; - PolicySubject intentAttachPoint = (PolicySubject)subject; - String value = reader.getAttributeValue(null, REQUIRES); - if (value != null) { - List<Intent> requiredIntents = intentAttachPoint.getRequiredIntents(); - for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { - QName qname = getQNameValue(reader, tokens.nextToken()); - Intent intent = policyFactory.createIntent(); - intent.setName(qname); - if (operation != null) { - //FIXME Don't we need to handle intent specification - // on an operation basis? - //intent.getOperations().add(operation); - } - requiredIntents.add(intent); - } - } - } - - /** - * Reads policy intents and policy sets associated with an operation. - * @param subject - * @param operation - * @param reader - */ - public void readPolicies(Object subject, Operation operation, XMLStreamReader reader) { - readIntents(subject, operation, reader); - readPolicySets(subject, operation, reader); - } - - /** - * Reads policy intents and policy sets. - * @param subject - * @param reader - */ - public void readPolicies(Object subject, XMLStreamReader reader) { - readPolicies(subject, null, reader); - } - - /** - * Reads policy sets associated with an operation. - * @param subject - * @param operation - * @param reader - */ - private void readPolicySets(Object subject, Operation operation, XMLStreamReader reader) { - if (!(subject instanceof PolicySubject)) { - return; - } - PolicySubject policySubject = (PolicySubject)subject; - String value = reader.getAttributeValue(null, POLICY_SETS); - if (value != null) { - List<PolicySet> policySets = policySubject.getPolicySets(); - for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { - QName qname = getQNameValue(reader, tokens.nextToken()); - PolicySet policySet = policyFactory.createPolicySet(); - policySet.setName(qname); - if (operation != null) { - //FIXME Don't we need to handle policySet specification - // on an operation basis? - //policySet.getOperations().add(operation); - } - policySets.add(policySet); - } - } - } - - /** - * Write policies - * @param subject - * @return - */ - XAttr writePolicies(Object subject) throws XMLStreamException { - return writePolicies(subject, (Operation)null); - } - - /** - * Write policies - * @param subject - * @return - */ - public void writePolicyAttributes(Object subject, XMLStreamWriter writer) throws XMLStreamException { - writePolicyAttributes(subject, (Operation)null, writer); - } - - /** - * Write policies associated with an operation - * @param subject - * @param operation - * @return - */ - XAttr writePolicies(Object subject, Operation operation) { - List<XAttr> attrs =new ArrayList<XAttr>(); - attrs.add(writeIntents(subject, operation)); - attrs.add(writePolicySets(subject, operation)); - return new XAttr(null, attrs); - } - - /** - * Write policies - * @param subject - * @return - */ - public void writePolicyAttributes(Object subject, Operation operation, XMLStreamWriter writer) throws XMLStreamException { - XAttr attr = writePolicies(subject, operation); - attr.write(writer); - } - - /** - * Write policy intents associated with an operation. - * @param subject - * @param operation - */ - private XAttr writeIntents(Object subject, Operation operation) { - if (!(subject instanceof PolicySubject)) { - return null; - } - PolicySubject intentAttachPoint = (PolicySubject)subject; - List<QName> qnames = new ArrayList<QName>(); - for (Intent intent: intentAttachPoint.getRequiredIntents()) { - qnames.add(intent.getName()); - } - return new XAttr(Constants.REQUIRES, qnames); - } - - /** - * Write policy sets associated with an operation. - * @param subject - * @param operation - */ - private XAttr writePolicySets(Object subject, Operation operation) { - if (!(subject instanceof PolicySubject)) { - return null; - } - PolicySubject policySetAttachPoint = (PolicySubject)subject; - List<QName> qnames = new ArrayList<QName>(); - for (PolicySet policySet: policySetAttachPoint.getPolicySets()) { - qnames.add(policySet.getName()); - } - return new XAttr(Constants.POLICY_SETS, qnames); - } - - public void resolvePolicies(Object subject, ModelResolver resolver, ProcessorContext context) { - if ( subject instanceof PolicySubject ) { - PolicySubject policySetAttachPoint = (PolicySubject)subject; - - List<Intent> requiredIntents = new ArrayList<Intent>(); - Intent resolvedIntent = null; - - if ( policySetAttachPoint.getRequiredIntents() != null && policySetAttachPoint.getRequiredIntents().size() > 0 ) { - for ( Intent intent : policySetAttachPoint.getRequiredIntents() ) { - resolvedIntent = resolver.resolveModel(Intent.class, intent, context); - requiredIntents.add(resolvedIntent); - } - policySetAttachPoint.getRequiredIntents().clear(); - policySetAttachPoint.getRequiredIntents().addAll(requiredIntents); - } - - if ( policySetAttachPoint.getPolicySets() != null && policySetAttachPoint.getPolicySets().size() > 0 ) { - List<PolicySet> resolvedPolicySets = new ArrayList<PolicySet>(); - PolicySet resolvedPolicySet = null; - for ( PolicySet policySet : policySetAttachPoint.getPolicySets() ) { - resolvedPolicySet = resolver.resolveModel(PolicySet.class, policySet, context); - resolvedPolicySets.add(resolvedPolicySet); - } - policySetAttachPoint.getPolicySets().clear(); - policySetAttachPoint.getPolicySets().addAll(resolvedPolicySets); - } - } - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java deleted file mode 100644 index 28f4f9fb25..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/assembly/xml/SCABindingProcessor.java +++ /dev/null @@ -1,132 +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.assembly.xml; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.assembly.SCABinding; -import org.apache.tuscany.sca.assembly.SCABindingFactory; -import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.policy.ExtensionType; -import org.apache.tuscany.sca.policy.PolicyFactory; -import org.apache.tuscany.sca.policy.PolicySubject; - -/** - * A processor to read the XML that describes the SCA binding. - * - * @version $Rev$ $Date$ - */ - -public class SCABindingProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<SCABinding> { - private static final String NAME = "name"; - private static final String URI = "uri"; - - private static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912"; - private static final String BINDING_SCA = "binding.sca"; - private static final QName BINDING_SCA_QNAME = new QName(SCA11_NS, BINDING_SCA); - - private PolicyFactory policyFactory; - private SCABindingFactory scaBindingFactory; - private PolicySubjectProcessor policyProcessor; - private PolicyFactory intentAttachPointTypeFactory; - - - public SCABindingProcessor(FactoryExtensionPoint modelFactories) { - this.policyFactory = modelFactories.getFactory(PolicyFactory.class); - this.scaBindingFactory = modelFactories.getFactory(SCABindingFactory.class); - policyProcessor = new PolicySubjectProcessor(policyFactory); - this.intentAttachPointTypeFactory = modelFactories.getFactory(PolicyFactory.class); - } - - public QName getArtifactType() { - return BINDING_SCA_QNAME; - } - - public Class<SCABinding> getModelType() { - return SCABinding.class; - } - - public SCABinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { - SCABinding scaBinding = scaBindingFactory.createSCABinding(); - ExtensionType bindingType = intentAttachPointTypeFactory.createBindingType(); - bindingType.setType(getArtifactType()); - bindingType.setUnresolved(true); - ((PolicySubject)scaBinding).setExtensionType(bindingType); - - // Read policies - policyProcessor.readPolicies(scaBinding, reader); - - // Read binding name - String name = reader.getAttributeValue(null, NAME); - if (name != null) { - scaBinding.setName(name); - } - - // Read binding URI - String uri = getURIString(reader, URI); - if (uri != null) { - scaBinding.setURI(uri); - } - - // Skip to end element - while (reader.hasNext()) { - if (reader.next() == END_ELEMENT && BINDING_SCA_QNAME.equals(reader.getName())) { - break; - } - } - return scaBinding; - } - - public void resolve(SCABinding model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - policyProcessor.resolvePolicies(model, resolver, context); - } - - public void write(SCABinding scaBinding, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { - - // Write <binding.sca> - writer.writeStartElement(SCA11_NS, BINDING_SCA); - policyProcessor.writePolicyAttributes(scaBinding, writer); - - // Write binding name - if (scaBinding.getName() != null) { - writer.writeAttribute(NAME, scaBinding.getName()); - } - - // Write binding URI - if (scaBinding.getURI() != null) { - writer.writeAttribute(URI, scaBinding.getURI()); - } - - writer.writeEndElement(); - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefaultDefinitionsExtensionPoint.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefaultDefinitionsExtensionPoint.java deleted file mode 100644 index af59324c7c..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefaultDefinitionsExtensionPoint.java +++ /dev/null @@ -1,128 +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.definitions.xml; - -import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.UtilityExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.extensibility.ServiceDeclaration; -import org.apache.tuscany.sca.extensibility.ServiceDiscovery; -import org.apache.tuscany.sca.monitor.MonitorFactory; - -/** - * Default implementation of an extension point for XML definitionss. - * - * @version $Rev$ $Date$ - */ -public class DefaultDefinitionsExtensionPoint implements DefinitionsExtensionPoint { - private static final Logger logger = Logger.getLogger(DefaultDefinitionsExtensionPoint.class.getName()); - private static final URI DEFINITIONS_URI = URI.create("META-INF/definitions.xml"); - private ExtensionPointRegistry registry; - private MonitorFactory monitorFactory; - private Set<URL> documents = new HashSet<URL>(); - private List<Definitions> definitions = new ArrayList<Definitions>(); - private boolean documentsLoaded; - private boolean loaded; - - public DefaultDefinitionsExtensionPoint(ExtensionPointRegistry registry) { - this.registry = registry; - this.monitorFactory = registry.getExtensionPoint(UtilityExtensionPoint.class).getUtility(MonitorFactory.class); - } - - public void addDefinitionsDocument(URL url) { - documents.add(url); - } - - public void removeDefinitionsDocument(URL url) { - documents.remove(url); - } - - /** - * Load definitions declarations from META-INF/services/ - * org.apache.tuscany.sca.contribution.processor.Definitions files - */ - private synchronized void loadDefinitionsDocuments() { - if (documentsLoaded) - return; - - // Get the definitions declarations - Collection<ServiceDeclaration> definitionsDeclarations; - try { - definitionsDeclarations = registry.getServiceDiscovery().getServiceDeclarations(DEFINITIONS_FILE); - } catch (IOException e) { - throw new IllegalStateException(e); - } - - // Find each definitions - for (ServiceDeclaration definitionsDeclaration : definitionsDeclarations) { - URL url = definitionsDeclaration.getResource(definitionsDeclaration.getClassName()); - if (url == null) { - throw new IllegalArgumentException(definitionsDeclaration.getClassName() + " cannot be found"); - } - documents.add(url); - } - - documentsLoaded = true; - } - - public synchronized List<Definitions> getDefinitions() { - if (!loaded) { - loadDefinitionsDocuments(); - URLArtifactProcessorExtensionPoint processors = - registry.getExtensionPoint(URLArtifactProcessorExtensionPoint.class); - URLArtifactProcessor<Definitions> processor = processors.getProcessor(Definitions.class); - ProcessorContext context = new ProcessorContext(monitorFactory.createMonitor()); - for (URL url : documents) { - Definitions def; - try { - def = processor.read(null, DEFINITIONS_URI, url, context); - definitions.add(def); - } catch (ContributionReadException e) { - logger.log(Level.SEVERE, e.getMessage(), e); - } - } - loaded = true; - } - return definitions; - } - - public void addDefinitions(Definitions def) { - this.definitions.add(def); - } - - public void removeDefinitions(Definitions def) { - this.definitions.remove(def); - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsDocumentProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsDocumentProcessor.java deleted file mode 100644 index d0a42be34e..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsDocumentProcessor.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.definitions.xml; - -import java.io.IOException; -import java.io.InputStream; -import java.net.URI; -import java.net.URL; -import java.security.AccessController; -import java.security.PrivilegedActionException; -import java.security.PrivilegedExceptionAction; - -import javax.xml.stream.XMLInputFactory; -import javax.xml.stream.XMLStreamConstants; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; - -import org.apache.tuscany.sca.common.java.io.IOHelper; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ValidatingXMLInputFactory; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.definitions.DefinitionsFactory; -import org.apache.tuscany.sca.definitions.util.DefinitionsUtil; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.monitor.Problem; -import org.apache.tuscany.sca.monitor.Problem.Severity; - -/** - * A SCA Definitions Document processor. - * - * @version $Rev$ $Date$ - */ -public class DefinitionsDocumentProcessor implements URLArtifactProcessor<Definitions> { - private StAXArtifactProcessor<Object> extensionProcessor; - private XMLInputFactory inputFactory; - private DefinitionsFactory definitionsFactory; - - - - /** - * Constructs a new SCADefinitions processor. - * - * @param modelFactories - * @param staxProcessor - */ - public DefinitionsDocumentProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor<Object> staxProcessor) { - this.extensionProcessor = (StAXArtifactProcessor<Object>)staxProcessor; - this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class); - this.definitionsFactory = modelFactories.getFactory(DefinitionsFactory.class); - } - - /** - * Report a exception. - * - * @param problems - * @param message - * @param model - */ - private void error(Monitor monitor, String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - Messages.RESOURCE_BUNDLE, - Severity.ERROR, - model, - message, - ex); - monitor.problem(problem); - } - } - - public Definitions read(URL contributionURL, final URI uri, final URL url, ProcessorContext context) throws ContributionReadException { - InputStream urlStream = null; - Monitor monitor = context.getMonitor(); - monitor.pushContext("Definitions: " + url); - try { - // Allow privileged access to open URL stream. Add FilePermission to added to security - // policy file. - try { - urlStream = AccessController.doPrivileged(new PrivilegedExceptionAction<InputStream>() { - public InputStream run() throws IOException { - return IOHelper.openStream(url); - } - }); - } catch (PrivilegedActionException e) { - error(monitor, "PrivilegedActionException", url, (IOException)e.getException()); - throw (IOException)e.getException(); - } - - //urlStream = createInputStream(url); - XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream); - ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor()); - Definitions definitions = definitionsFactory.createDefinitions(); - int event = reader.getEventType(); - while (reader.hasNext()) { - event = reader.next(); - - // We only deal with the root element - if (event == XMLStreamConstants.START_ELEMENT) { - // QName name = reader.getName(); - Object model = extensionProcessor.read(reader, context); - if (model instanceof Definitions) { - DefinitionsUtil.aggregate((Definitions)model, definitions, monitor); - return definitions; - } else { - error(monitor, "ContributionReadException", model, null); - } - } - } - - return definitions; - } catch (XMLStreamException e) { - ContributionReadException ce = new ContributionReadException(e); - error(monitor, "ContributionReadException", inputFactory, ce); - throw ce; - } catch (IOException e) { - ContributionReadException ce = new ContributionReadException(e); - error(monitor, "ContributionReadException", inputFactory, ce); - throw ce; - } finally { - - try { - if (urlStream != null) { - urlStream.close(); - urlStream = null; - } - } catch (IOException ioe) { - //ignore - } - - monitor.popContext(); - } - } - - public void resolve(Definitions scaDefinitions, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - extensionProcessor.resolve(scaDefinitions, resolver, context); - } - - public String getArtifactType() { - return "/META-INF/definitions.xml"; - } - - public Class<Definitions> getModelType() { - return Definitions.class; - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsExtensionPoint.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsExtensionPoint.java deleted file mode 100644 index 3058b1f5b6..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsExtensionPoint.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.definitions.xml; - -import java.net.URL; -import java.util.List; - -import org.apache.tuscany.sca.definitions.Definitions; - -/** - * An extension point for built-in SCA intent/policySet definition files - * - * @version $Rev$ $Date$ - */ -public interface DefinitionsExtensionPoint { - String DEFINITIONS_FILE = "org.apache.tuscany.sca.definitions.xml.Definitions"; - - /** - * Add a definitions document - * - * @param url the URL of the definitions - */ - void addDefinitionsDocument(URL url); - - /** - * Remove a definitions document - * - * @param url the URL of the definitions - */ - void removeDefinitionsDocument(URL url); - - /** - * @param definitions - */ - void addDefinitions(Definitions definitions); - /** - * @param definitions - */ - void removeDefinitions(Definitions definitions); - - /** - * Get the list of definitions - * @return A list of definitions - */ - List<Definitions> getDefinitions(); - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsProcessor.java deleted file mode 100644 index 006b80ee31..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/DefinitionsProcessor.java +++ /dev/null @@ -1,292 +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.definitions.xml; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; - -import java.util.ArrayList; -import java.util.List; - -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.Binding; -import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.definitions.Definitions; -import org.apache.tuscany.sca.definitions.DefinitionsFactory; -import org.apache.tuscany.sca.monitor.Monitor; -import org.apache.tuscany.sca.policy.BindingType; -import org.apache.tuscany.sca.policy.ImplementationType; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.IntentMap; -import org.apache.tuscany.sca.policy.PolicyFactory; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.Qualifier; - -/** - * Processor for SCA Definitions - * - * @version $Rev$ $Date$ - */ -public class DefinitionsProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<Definitions> { - private ExtensionPointRegistry registry; - private StAXArtifactProcessorExtensionPoint processors; - private StAXArtifactProcessor<Object> extensionProcessor; - private DefinitionsFactory definitionsFactory; - private PolicyFactory policyFactory; - - public static final String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912"; - public static final String BINDING = "binding"; - public static final String IMPLEMENTATION = "implementation"; - public static final String DEFINITIONS = "definitions"; - public static final QName DEFINITIONS_QNAME = new QName(SCA11_NS, DEFINITIONS); - public static final String TARGET_NAMESPACE = "targetNamespace"; - public static final String NAME = "name"; - - public DefinitionsProcessor(ExtensionPointRegistry registry, - StAXArtifactProcessor<Object> extensionProcessor) { - this.registry = registry; - this.extensionProcessor = extensionProcessor; - this.processors = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class); - FactoryExtensionPoint factoryExtensionPoint = registry.getExtensionPoint(FactoryExtensionPoint.class); - this.definitionsFactory = factoryExtensionPoint.getFactory(DefinitionsFactory.class); - this.policyFactory = factoryExtensionPoint.getFactory(PolicyFactory.class); - } - - public Definitions read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { - QName name = null; - Definitions definitions = null; - String targetNamespace = null; - - while (reader.hasNext()) { - int event = reader.getEventType(); - switch (event) { - case START_ELEMENT: { - name = reader.getName(); - if (DEFINITIONS_QNAME.equals(name)) { - definitions = definitionsFactory.createDefinitions(); - targetNamespace = getURIString(reader, TARGET_NAMESPACE); - definitions.setTargetNamespace(targetNamespace); - } else { - Object extension = extensionProcessor.read(reader, context); - if (extension != null) { - if (extension instanceof Intent) { - Intent intent = (Intent)extension; - intent.setName(new QName(targetNamespace, intent.getName().getLocalPart())); - definitions.getIntents().add(intent); - for (Intent i : intent.getQualifiedIntents()) { - i.setName(new QName(targetNamespace, i.getName().getLocalPart())); - } - } else if (extension instanceof PolicySet) { - PolicySet policySet = (PolicySet)extension; - policySet.setName(new QName(targetNamespace, policySet.getName().getLocalPart())); - definitions.getPolicySets().add(policySet); - } else if (extension instanceof Binding) { - Binding binding = (Binding)extension; - definitions.getBindings().add(binding); - } else if (extension instanceof BindingType) { - definitions.getBindingTypes().add((BindingType)extension); - } else if (extension instanceof ImplementationType) { - definitions.getImplementationTypes().add((ImplementationType)extension); - } - } - break; - } - } - - case XMLStreamConstants.CHARACTERS: - break; - - case END_ELEMENT: - name = reader.getName(); - if (DEFINITIONS_QNAME.equals(name)) { - return definitions; - } - break; - } - - //Read the next element - if (reader.hasNext()) { - reader.next(); - } - } - return definitions; - } - - public void write(Definitions definitions, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, - XMLStreamException { - - writeStartDocument(writer, SCA11_NS, DEFINITIONS, new XAttr(TARGET_NAMESPACE, definitions.getTargetNamespace())); - - for (Intent policyIntent : definitions.getIntents()) { - extensionProcessor.write(policyIntent, writer, context); - } - - for (PolicySet policySet : definitions.getPolicySets()) { - extensionProcessor.write(policySet, writer, context); - } - - for (Binding binding : definitions.getBindings()) { - extensionProcessor.write(binding, writer, context); - } - - for (BindingType bindingType : definitions.getBindingTypes()) { - extensionProcessor.write(bindingType, writer, context); - } - - for (ImplementationType implType : definitions.getImplementationTypes()) { - extensionProcessor.write(implType, writer, context); - } - - writeEndDocument(writer); - } - - public void resolve(Definitions scaDefns, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - - // start by adding all of the top level artifacts into the resolver as there - // are many cross artifact references in a definitions file and we don't want - // to be dependent on the order things appear - - List<Intent> intents = new ArrayList<Intent>(); - List<PolicySet> policySets = new ArrayList<PolicySet>(); - List<PolicySet> referredPolicySets = new ArrayList<PolicySet>(); - - for (Intent intent : scaDefns.getIntents()) { - intents.add(intent); - resolver.addModel(intent, context); - for (Intent i : intent.getQualifiedIntents()) { - intents.add(i); - resolver.addModel(i, context); - } - } - - for (PolicySet policySet : scaDefns.getPolicySets()) { - if (policySet.getReferencedPolicySets().isEmpty()) { - policySets.add(policySet); - } else { - referredPolicySets.add(policySet); - } - - resolver.addModel(policySet, context); - } - - for (BindingType bindingType : scaDefns.getBindingTypes()) { - resolver.addModel(bindingType, context); - } - - for (ImplementationType implType : scaDefns.getImplementationTypes()) { - resolver.addModel(implType, context); - } - - // now resolve everything to ensure that any references between - // artifacts are satisfied - - for (Intent policyIntent : intents) - extensionProcessor.resolve(policyIntent, resolver, context); - - for (PolicySet policySet : policySets) - extensionProcessor.resolve(policySet, resolver, context); - - for (PolicySet policySet : referredPolicySets) - extensionProcessor.resolve(policySet, resolver, context); - - for (Binding binding : scaDefns.getBindings()) { - extensionProcessor.resolve(binding, resolver, context); - } - - for (BindingType bindingType : scaDefns.getBindingTypes()) { - extensionProcessor.resolve(bindingType, resolver, context); - if (processors.getProcessor(bindingType.getType()) == null){ - Monitor.error(context.getMonitor(), - this, - "org.apache.tuscany.sca.definitions.xml.definitions-xml-validation-messages", - "BindingTypeNotFound", - bindingType.getType().toString()); - } - } - - for (ImplementationType implementationType : scaDefns.getImplementationTypes()) { - extensionProcessor.resolve(implementationType, resolver, context); - if (processors.getProcessor(implementationType.getType()) == null){ - Monitor.error(context.getMonitor(), - this, - "org.apache.tuscany.sca.definitions.xml.definitions-xml-validation-messages", - "ImplementationTypeNotFound", - implementationType.getType().toString()); - } - } - - - // Flat intentMap structure by creating a policySet for each one - List<PolicySet> copy = new ArrayList<PolicySet>(scaDefns.getPolicySets()); - for (PolicySet policySet : copy) { - //[lresende] Do we need to remove the current policySet and just include the flat one based on qualifiers ? - //If we don't, the policy is being resolved to the one that has intentMap and no direct concrete policies - boolean remove = false; - - //process intent maps - for(IntentMap intentMap : policySet.getIntentMaps()) { - for(Qualifier qualifier : intentMap.getQualifiers()) { - remove = true; - - PolicySet qualifiedPolicySet = policyFactory.createPolicySet(); - qualifiedPolicySet.setAppliesTo(policySet.getAppliesTo()); - qualifiedPolicySet.setAppliesToXPathExpression(policySet.getAttachToXPathExpression()); - qualifiedPolicySet.setAttachTo(policySet.getAttachTo()); - qualifiedPolicySet.setAttachToXPathExpression(policySet.getAttachToXPathExpression()); - - qualifiedPolicySet.setName(qualifier.getIntent().getName()); - qualifiedPolicySet.getProvidedIntents().clear(); - qualifiedPolicySet.getProvidedIntents().add(qualifier.getIntent()); - qualifiedPolicySet.getPolicies().clear(); - qualifiedPolicySet.getPolicies().addAll(qualifier.getPolicies()); - - scaDefns.getPolicySets().add(qualifiedPolicySet); - } - } - - if(remove) { - scaDefns.getPolicySets().remove(policySet); - } - } - } - - public QName getArtifactType() { - return DEFINITIONS_QNAME; - } - - public Class<Definitions> getModelType() { - return Definitions.class; - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/Messages.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/Messages.java deleted file mode 100644 index 38cc4a9de2..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/definitions/xml/Messages.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.definitions.xml; - -/** - * Constants for resource bundle names - */ -public interface Messages { - String RESOURCE_BUNDLE = "org.apache.tuscany.sca.definitions.xml.definitions-xml-validation-messages"; -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java deleted file mode 100644 index 70c71c5f1f..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java +++ /dev/null @@ -1,65 +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.policy.xml; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.policy.BindingType; -import org.apache.tuscany.sca.policy.ExtensionType; -import org.apache.tuscany.sca.policy.PolicyFactory; - -/** - * Processor for handling XML models of BindingType meta data definitions - * - * @version $Rev$ $Date$ - */ -public class BindingTypeProcessor extends ExtensionTypeProcessor { - - public BindingTypeProcessor(PolicyFactory policyFactory, - StAXArtifactProcessor<Object> extensionProcessor) { - super(policyFactory, extensionProcessor); - } - - public BindingTypeProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor<Object> extensionProcessor) { - super(modelFactories.getFactory(PolicyFactory.class), extensionProcessor); - } - - public QName getArtifactType() { - return BINDING_TYPE_QNAME; - } - - @Override - protected ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - if (extnType instanceof BindingType) { - BindingType bindingType = (BindingType)extnType; - return resolver.resolveModel(BindingType.class, bindingType, context); - } else { - return extnType; - } - - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ExtensionTypeProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ExtensionTypeProcessor.java deleted file mode 100644 index 95d8e67bf7..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ExtensionTypeProcessor.java +++ /dev/null @@ -1,250 +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.policy.xml; - -import java.util.ArrayList; -import java.util.List; -import java.util.StringTokenizer; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -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.policy.BindingType; -import org.apache.tuscany.sca.policy.ExtensionType; -import org.apache.tuscany.sca.policy.ImplementationType; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.PolicyFactory; - -/** - * Processor for handling XML models of ExtensionType meta data definitions - * - * @version $Rev$ $Date$ - */ -abstract class ExtensionTypeProcessor extends BaseStAXArtifactProcessor implements - StAXArtifactProcessor<ExtensionType>, PolicyConstants { - - private PolicyFactory policyFactory; - - - protected abstract ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException; - - public ExtensionTypeProcessor(PolicyFactory policyFactory, - StAXArtifactProcessor<Object> extensionProcessor) { - this.policyFactory = policyFactory; - } - - /** - * Report a error. - * - * @param problems - * @param message - * @param model - */ - private void error(Monitor monitor, String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - Messages.RESOURCE_BUNDLE, - Severity.ERROR, - model, - message, - (Object[])messageParameters); - monitor.problem(problem); - } - } - - public ExtensionType read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { - QName extType = getArtifactType(); - QName type = getQName(reader, "type"); - - if (type != null) { - ExtensionType extensionType = null; - if (BINDING_TYPE_QNAME.equals(extType)) { - extensionType = policyFactory.createBindingType(); - } else if (IMPLEMENTATION_TYPE_QNAME.equals(extType)) { - extensionType = policyFactory.createImplementationType(); - } else { - error(context.getMonitor(), "UnrecognizedExtensionType", reader, type); - return null; - //throw new ContributionReadException("Unrecognized ExtensionType - " + type); - } - extensionType.setType(type); - extensionType.setUnresolved(true); - - readAlwaysProvidedIntents(extensionType, reader); - readMayProvideIntents(extensionType, reader); - return extensionType; - - } else { - error(context.getMonitor(), "RequiredAttributeMissing", reader, extType); - //throw new ContributionReadException("Required attribute '" + TYPE + - //"' missing from BindingType Definition"); - } - return null; - } - - private void readAlwaysProvidedIntents(ExtensionType extnType, XMLStreamReader reader) { - String value = reader.getAttributeValue(null, ALWAYS_PROVIDES); - if (value != null) { - List<Intent> alwaysProvided = extnType.getAlwaysProvidedIntents(); - for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { - QName qname = getQNameValue(reader, tokens.nextToken()); - Intent intent = policyFactory.createIntent(); - intent.setName(qname); - alwaysProvided.add(intent); - } - } - } - - private void readMayProvideIntents(ExtensionType extnType, XMLStreamReader reader) { - String value = reader.getAttributeValue(null, MAY_PROVIDE); - if (value != null) { - List<Intent> mayProvide = extnType.getMayProvidedIntents(); - for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { - QName qname = getQNameValue(reader, tokens.nextToken()); - Intent intent = policyFactory.createIntent(); - intent.setName(qname); - mayProvide.add(intent); - } - } - } - - public void write(ExtensionType extnType, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, - XMLStreamException { - - // Write an <sca:bindingType or sca:implementationType> - if (extnType instanceof BindingType) { - writer.writeStartElement(SCA11_NS, BINDING_TYPE); - } else if (extnType instanceof ImplementationType) { - writer.writeStartElement(SCA11_NS, IMPLEMENTATION_TYPE); - } - - writeAlwaysProvidesIntentsAttribute(extnType, writer); - writeMayProvideIntentsAttribute(extnType, writer); - - writer.writeEndElement(); - } - - private void writeMayProvideIntentsAttribute(ExtensionType extnType, XMLStreamWriter writer) - throws XMLStreamException { - StringBuffer sb = new StringBuffer(); - for (Intent intent : extnType.getMayProvidedIntents()) { - writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI()); - sb.append(intent.getName().getPrefix() + COLON + intent.getName().getLocalPart()); - sb.append(WHITE_SPACE); - } - - if (sb.length() > 0) { - writer.writeAttribute(MAY_PROVIDE, sb.toString()); - } - } - - private void writeAlwaysProvidesIntentsAttribute(ExtensionType extnType, XMLStreamWriter writer) - throws XMLStreamException { - StringBuffer sb = new StringBuffer(); - for (Intent intent : extnType.getAlwaysProvidedIntents()) { - writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI()); - sb.append(intent.getName().getPrefix() + COLON + intent.getName().getLocalPart()); - sb.append(WHITE_SPACE); - } - - if (sb.length() > 0) { - writer.writeAttribute(ALWAYS_PROVIDES, sb.toString()); - - } - } - - public void resolve(ExtensionType extnType, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - - if (extnType != null && extnType.isUnresolved()) { - resolveAlwaysProvidedIntents(extnType, resolver, context); - resolveMayProvideIntents(extnType, resolver, context); - extnType.setUnresolved(false); - //resolveExtensionType(extnType, resolver); - } - } - - private void resolveAlwaysProvidedIntents(ExtensionType extensionType, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - if (extensionType != null) { - // resolve all provided intents - List<Intent> alwaysProvided = new ArrayList<Intent>(); - for (Intent providedIntent : extensionType.getAlwaysProvidedIntents()) { - if (providedIntent.isUnresolved()) { - providedIntent = resolver.resolveModel(Intent.class, providedIntent, context); - if (!providedIntent.isUnresolved()) { - alwaysProvided.add(providedIntent); - } else { - error(context.getMonitor(), "AlwaysProvidedIntentNotFound", resolver, providedIntent, extensionType); - //throw new ContributionResolveException("Always Provided Intent - " + providedIntent - //+ " not found for ExtensionType " - //+ extensionType); - } - } else { - alwaysProvided.add(providedIntent); - } - } - extensionType.getAlwaysProvidedIntents().clear(); - extensionType.getAlwaysProvidedIntents().addAll(alwaysProvided); - } - } - - private void resolveMayProvideIntents(ExtensionType extensionType, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - if (extensionType != null) { - // resolve all provided intents - List<Intent> mayProvide = new ArrayList<Intent>(); - for (Intent providedIntent : extensionType.getMayProvidedIntents()) { - if (providedIntent.isUnresolved()) { - providedIntent = resolver.resolveModel(Intent.class, providedIntent, context); - if (!providedIntent.isUnresolved()) { - mayProvide.add(providedIntent); - } else { - error(context.getMonitor(), "MayProvideIntentNotFound", resolver, providedIntent, extensionType); - //throw new ContributionResolveException("May Provide Intent - " + providedIntent - //+ " not found for ExtensionType " - //+ extensionType); - } - } else { - mayProvide.add(providedIntent); - } - } - extensionType.getMayProvidedIntents().clear(); - extensionType.getMayProvidedIntents().addAll(mayProvide); - } - } - - public Class<ExtensionType> getModelType() { - return ExtensionType.class; - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java deleted file mode 100644 index ec4e17385f..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java +++ /dev/null @@ -1,65 +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.policy.xml; - -import javax.xml.namespace.QName; - -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -import org.apache.tuscany.sca.policy.ExtensionType; -import org.apache.tuscany.sca.policy.ImplementationType; -import org.apache.tuscany.sca.policy.PolicyFactory; - -/** - * Processor for handling XML models of ImplementationType meta data definitions - * - * @version $Rev$ $Date$ - */ -public class ImplementationTypeProcessor extends ExtensionTypeProcessor { - - public ImplementationTypeProcessor(PolicyFactory policyFactory, - StAXArtifactProcessor<Object> extensionProcessor) { - super(policyFactory, extensionProcessor); - } - - public ImplementationTypeProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor<Object> extensionProcessor) { - super(modelFactories.getFactory(PolicyFactory.class), extensionProcessor); - } - - public QName getArtifactType() { - return IMPLEMENTATION_TYPE_QNAME; - } - - @Override - protected ExtensionType resolveExtensionType(ExtensionType extnType, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - if (extnType instanceof ImplementationType) { - ImplementationType implType = (ImplementationType)extnType; - return resolver.resolveModel(ImplementationType.class, implType, context); - } else { - return extnType; - } - - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentProcessor.java deleted file mode 100644 index 296677d8b8..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentProcessor.java +++ /dev/null @@ -1,424 +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.policy.xml; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.StringTokenizer; - -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; - -import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -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.policy.ExtensionType; -import org.apache.tuscany.sca.policy.Intent; -import org.apache.tuscany.sca.policy.PolicyFactory; -import org.apache.tuscany.sca.policy.Intent.Type; - -/** - * Processor for handling XML models of PolicyIntent definitions - * - * @version $Rev$ $Date$ - */ -public class IntentProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<Intent>, - PolicyConstants { - - private PolicyFactory policyFactory; - - - public IntentProcessor(FactoryExtensionPoint modelFactories) { - this.policyFactory = modelFactories.getFactory(PolicyFactory.class); - } - - public IntentProcessor(PolicyFactory policyFactory) { - this.policyFactory = policyFactory; - } - - /** - * Report a error. - * - * @param problems - * @param message - * @param model - */ - private void error(Monitor monitor, String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - Messages.RESOURCE_BUNDLE, - Severity.ERROR, - model, - message, - messageParameters); - monitor.problem(problem); - } - } - - private void warn(Monitor monitor, String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - Messages.RESOURCE_BUNDLE, - Severity.WARNING, - model, - message, - messageParameters); - monitor.problem(problem); - } - } - - public Intent read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { - Intent intent = null; - String intentLocalName = reader.getAttributeValue(null, NAME); - if (intentLocalName == null) { - error(context.getMonitor(), "IntentNameMissing", reader); - return null; - } - - String intentType = reader.getAttributeValue(null, INTENT_TYPE); - if (intentType == null) { - intentType = Intent.Type.interaction.name(); - } - - intent = policyFactory.createIntent(); - - // [rfeng] the target namespace is not available, set the local part for now - // This will be changed in the definitions processor - intent.setName(new QName(intentLocalName)); - intent.setType(Type.valueOf(intentType)); - - readRequiredIntents(intent, reader, context); - readExcludedIntents(intent, reader); - - readConstrainedTypes(intent, reader); - - Intent current = intent; - int event = reader.getEventType(); - QName name = null; - while (reader.hasNext()) { - event = reader.getEventType(); - switch (event) { - case START_ELEMENT: { - name = reader.getName(); - if (DESCRIPTION_QNAME.equals(name)) { - String text = reader.getElementText(); - if (text != null) { - text = text.trim(); - } - current.setDescription(text); - } else if (INTENT_QUALIFIER_QNAME.equals(name)) { - String qualifierName = reader.getAttributeValue(null, NAME); - String defaultQ = reader.getAttributeValue(null, DEFAULT); - boolean isDefault = defaultQ == null ? false : Boolean.parseBoolean(defaultQ); - String qualifiedIntentName = intentLocalName + QUALIFIER + qualifierName; - Intent qualified = policyFactory.createIntent(); - qualified.setType(intent.getType()); - qualified.setName(new QName(qualifiedIntentName)); - if (isDefault) { - if (intent.getDefaultQualifiedIntent() == null){ - intent.setDefaultQualifiedIntent(qualified); - } else { - Monitor.error(context.getMonitor(), - this, - Messages.RESOURCE_BUNDLE, - "MultipleDefaultQualifiers", - intent.getName().toString()); - } - } - - // check that the qualifier is unique - if ( !intent.getQualifiedIntents().contains(qualified)){ - intent.getQualifiedIntents().add(qualified); - } else { - Monitor.error(context.getMonitor(), - this, - Messages.RESOURCE_BUNDLE, - "QualifierIsNotUnique", - intent.getName().toString(), - qualifierName); - } - - qualified.setQualifiableIntent(intent); - current = qualified; - } - break; - } - case END_ELEMENT: { - name = reader.getName(); - if (INTENT_QUALIFIER_QNAME.equals(name)) { - current = intent; - } - break; - } - } - if (event == END_ELEMENT && POLICY_INTENT_QNAME.equals(reader.getName())) { - break; - } - - //Read the next element - if (reader.hasNext()) { - reader.next(); - } - } - // REVIEW: [rfeng] What's going to happen if there is only one qualified intent - if (intent.getQualifiedIntents().size() == 1) { - intent.setDefaultQualifiedIntent(intent.getQualifiedIntents().get(0)); - } - return intent; - } - - public void write(Intent intent, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { - // Write an <sca:intent> - writer.writeStartElement(PolicyConstants.SCA11_NS, INTENT); - writer.writeNamespace(intent.getName().getPrefix(), intent.getName().getNamespaceURI()); - writer.writeAttribute(PolicyConstants.NAME, intent.getName().getPrefix() + COLON - + intent.getName().getLocalPart()); - if (intent.getRequiredIntents() != null && intent.getRequiredIntents().size() > 0) { - StringBuffer sb = new StringBuffer(); - for (Intent requiredIntents : intent.getRequiredIntents()) { - sb.append(requiredIntents.getName()); - sb.append(" "); - } - writer.writeAttribute(PolicyConstants.REQUIRES, sb.toString()); - } - - if (intent.getExcludedIntents() != null && intent.getExcludedIntents().size() > 0) { - StringBuffer sb = new StringBuffer(); - for (Intent excludedIntents : intent.getExcludedIntents()) { - sb.append(excludedIntents.getName()); - sb.append(" "); - } - writer.writeAttribute(PolicyConstants.EXCLUDES, sb.toString()); - } - - if (intent.getConstrainedTypes() != null && intent.getConstrainedTypes().size() > 0) { - StringBuffer sb = new StringBuffer(); - for (ExtensionType contrainedArtifact : intent.getConstrainedTypes()) { - sb.append(contrainedArtifact.getType().getPrefix()); - sb.append(':').append(contrainedArtifact.getType().getLocalPart()); - sb.append(" "); - } - writer.writeAttribute(CONSTRAINS, sb.toString()); - } - - if (intent.getDescription() != null && intent.getDescription().length() > 0) { - writer.writeStartElement(PolicyConstants.SCA11_NS, DESCRIPTION); - writer.writeCData(intent.getDescription()); - writer.writeEndElement(); - } - - writer.writeEndElement(); - } - - private void resolveContrainedTypes(Intent intent, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - Collection<ExtensionType> resolvedTypes = new HashSet<ExtensionType>(); - for (ExtensionType extensionType : intent.getConstrainedTypes()) { - if (ExtensionType.BINDING_BASE.equals(extensionType.getType()) || ExtensionType.IMPLEMENTATION_BASE - .equals(extensionType.getType())) { - // HACK: Mark sca:binding and sca:implementation as resolved - extensionType.setUnresolved(false); - resolvedTypes.add(extensionType); - } else { - ExtensionType resolved = resolver.resolveModel(ExtensionType.class, extensionType, context); - if (!resolved.isUnresolved() || resolved != extensionType) { - resolvedTypes.add(resolved); - } else { - warn(context.getMonitor(), "ConstrainedTypeNotFound", intent, extensionType, intent); - } - } - } - intent.getConstrainedTypes().clear(); - intent.getConstrainedTypes().addAll(resolvedTypes); - } - - private void resolveProfileIntent(Intent intent, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - Monitor monitor = context.getMonitor(); - // FIXME: Need to check for cyclic references first i.e an A requiring B - // and then B requiring A... - if (intent != null && !intent.getRequiredIntents().isEmpty()) { - // resolve all required intents - List<Intent> requiredIntents = new ArrayList<Intent>(); - for (Intent required : intent.getRequiredIntents()) { - if (required.isUnresolved()) { - Intent resolved = resolver.resolveModel(Intent.class, required, context); - // At this point, when the required intent is not resolved, it does not mean - // its undeclared, chances are that their dependency are not resolved yet. - // Lets try to resolve them first. - if (resolved.isUnresolved()) { - if (((resolved).getRequiredIntents()).contains(intent)) { - error(monitor, "CyclicReferenceFound", resolver, required, intent); - return; - } - } - - if (!resolved.isUnresolved() || resolved != required) { - requiredIntents.add(resolved); - } else { - error(monitor, "RequiredIntentNotFound", resolver, required, intent); - return; - //throw new ContributionResolveException("Required Intent - " + requiredIntent - //+ " not found for Intent " + policyIntent); - } - } else { - requiredIntents.add(required); - } - } - intent.getRequiredIntents().clear(); - intent.getRequiredIntents().addAll(requiredIntents); - } - } - - private void resolveQualifiedIntent(Intent qualifed, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - if (qualifed != null) { - //resolve the qualifiable intent - Intent parent = qualifed.getQualifiableIntent(); - if (parent == null) { - return; - } - if (parent.isUnresolved()) { - Intent resolved = resolver.resolveModel(Intent.class, parent, context); - // At this point, when the qualifiable intent is not resolved, it does not mean - // its undeclared, chances are that their dependency are not resolved yet. - // Lets try to resolve them first. - - if (!resolved.isUnresolved() || resolved != qualifed) { - qualifed.setQualifiableIntent(resolved); - } else { - error(context.getMonitor(), "QualifiableIntentNotFound", resolver, parent, qualifed); - //throw new ContributionResolveException("Qualifiable Intent - " + qualifiableIntent - //+ " not found for Intent " + policyIntent); - } - } - } - } - - public void resolve(Intent intent, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - if (intent != null && intent.isUnresolved()) { - resolveProfileIntent(intent, resolver, context); - resolveExcludedIntents(intent, resolver, context); - resolveQualifiedIntent(intent, resolver, context); - resolveContrainedTypes(intent, resolver, context); - intent.setUnresolved(false); - } - } - - public QName getArtifactType() { - return POLICY_INTENT_QNAME; - } - - private void readConstrainedTypes(Intent policyIntent, XMLStreamReader reader) throws ContributionReadException { - String value = reader.getAttributeValue(null, CONSTRAINS); - if (value != null) { - List<ExtensionType> constrainedTypes = policyIntent.getConstrainedTypes(); - for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { - QName qname = getQNameValue(reader, tokens.nextToken()); - ExtensionType extensionType = policyFactory.createExtensionType(); - extensionType.setType(qname); - constrainedTypes.add(extensionType); - } - } - } - - private void readRequiredIntents(Intent intent, XMLStreamReader reader, ProcessorContext context) { - String value = reader.getAttributeValue(null, REQUIRES); - if (value != null) { - List<Intent> requiredIntents = intent.getRequiredIntents(); - for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { - QName qname = getQNameValue(reader, tokens.nextToken()); - Intent required = policyFactory.createIntent(); - required.setName(qname); - required.setUnresolved(true); - requiredIntents.add(required); - } - - // Check that a profile intent does not have "." in its name - if (requiredIntents.size() > 0) { - if (intent.getName().getLocalPart().contains(".")){ - Monitor.error(context.getMonitor(), - this, - Messages.RESOURCE_BUNDLE, - "ProfileIntentNameWithPeriod", - intent.getName().toString()); - } - } - } - } - - private void readExcludedIntents(Intent intent, XMLStreamReader reader) { - String value = reader.getAttributeValue(null, EXCLUDES); - if (value != null) { - List<Intent> excludedIntents = intent.getExcludedIntents(); - for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { - QName qname = getQNameValue(reader, tokens.nextToken()); - Intent excluded = policyFactory.createIntent(); - excluded.setName(qname); - excluded.setUnresolved(true); - excludedIntents.add(excluded); - } - } - } - - private void resolveExcludedIntents(Intent policyIntent, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - if (policyIntent != null) { - // resolve all excluded intents - List<Intent> excludedIntents = new ArrayList<Intent>(); - for (Intent excludedIntent : policyIntent.getExcludedIntents()) { - if (excludedIntent.isUnresolved()) { - Intent resolvedExcludedIntent = resolver.resolveModel(Intent.class, excludedIntent, context); - if (!resolvedExcludedIntent.isUnresolved() || resolvedExcludedIntent != excludedIntent) { - excludedIntents.add(resolvedExcludedIntent); - } else { - error(context.getMonitor(), "ExcludedIntentNotFound", resolver, excludedIntent, policyIntent); - return; - //throw new ContributionResolveException("Excluded Intent " + excludedIntent - //+ " not found for intent " + policyIntent); - } - } else { - excludedIntents.add(excludedIntent); - } - } - policyIntent.getExcludedIntents().clear(); - policyIntent.getExcludedIntents().addAll(excludedIntents); - } - } - - public Class<Intent> getModelType() { - return Intent.class; - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/Messages.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/Messages.java deleted file mode 100644 index ee8b5274cc..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/Messages.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.policy.xml; - -/** - * Constants for resource bundle names - */ -public interface Messages { - String RESOURCE_BUNDLE = "org.apache.tuscany.sca.policy.xml.policy-xml-validation-messages"; -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java deleted file mode 100644 index 69c5a11e9b..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java +++ /dev/null @@ -1,74 +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.policy.xml; - -import javax.xml.namespace.QName; - -/** - * constants related to policy framework - * - * @version $Rev$ $Date$ - */ -public interface PolicyConstants { - String WHITE_SPACE = " "; - String COLON = ":"; - String SCA11_NS = "http://docs.oasis-open.org/ns/opencsa/sca/200912"; - String TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.1"; - String INTENT = "intent"; - String POLICY_SET = "policySet"; - String POLICY_SET_REFERENCE = "policySetReference"; - String INTENT_MAP = "intentMap"; - String NAME = "name"; - String TARGET_NAMESPACE = "targetNamespace"; - String SCA_DEFINITIONS = "definitions"; - String CONSTRAINS = "constrains"; - String DESCRIPTION = "description"; - String PROVIDES = "provides"; - String APPLIES_TO = "appliesTo"; - String ATTACH_TO = "attachTo"; - String ALWAYS_APPLIES_TO = "alwaysAppliesTo"; - String QUALIFIER = "."; - String INTENT_QUALIFIER = "qualifier"; - String INTENT_MAP_QUALIFIER = "qualifier"; - String REQUIRES = "requires"; - String EXCLUDES = "excludes"; - String DEFAULT = "default"; - - String ALWAYS_PROVIDES = "alwaysProvides"; - String MAY_PROVIDE = "mayProvide"; - String INTENT_TYPE = "intentType"; - String IMPLEMENTATION_TYPE = "implementationType"; - String BINDING_TYPE = "bindingType"; - QName IMPLEMENTATION_TYPE_QNAME = new QName(SCA11_NS, IMPLEMENTATION_TYPE); - QName BINDING_TYPE_QNAME = new QName(SCA11_NS, BINDING_TYPE); - String BINDING = "binding"; - String IMPLEMENTATION = "implementation"; - - QName POLICY_INTENT_QNAME = new QName(SCA11_NS, INTENT); - QName POLICY_SET_QNAME = new QName(SCA11_NS, POLICY_SET); - QName POLICY_INTENT_MAP_QNAME = new QName(SCA11_NS, INTENT_MAP); - QName SCA_DEFINITIONS_QNAME = new QName(SCA11_NS, SCA_DEFINITIONS); - QName DESCRIPTION_QNAME = new QName(SCA11_NS, DESCRIPTION); - QName POLICY_INTENT_MAP_QUALIFIER_QNAME = new QName(SCA11_NS, INTENT_MAP_QUALIFIER); - QName POLICY_SET_REFERENCE_QNAME = new QName(SCA11_NS, POLICY_SET_REFERENCE); - QName INTENT_QUALIFIER_QNAME = new QName(SCA11_NS, INTENT_QUALIFIER); - - String QUALIFIED_INTENT_CONSTRAINS_ERROR = " - Qualified Intents must not specify 'constrains' attribute"; - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java deleted file mode 100644 index 68475a208b..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java +++ /dev/null @@ -1,572 +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.policy.xml; - -import static javax.xml.stream.XMLStreamConstants.END_ELEMENT; -import static javax.xml.stream.XMLStreamConstants.START_ELEMENT; -import static org.apache.tuscany.sca.policy.xml.PolicyConstants.SCA11_NS; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.StringTokenizer; - -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamReader; -import javax.xml.stream.XMLStreamWriter; -import javax.xml.xpath.XPath; -import javax.xml.xpath.XPathExpression; -import javax.xml.xpath.XPathExpressionException; - -import org.apache.tuscany.sca.common.xml.xpath.XPathHelper; -import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.processor.ContributionReadException; -import org.apache.tuscany.sca.contribution.processor.ContributionResolveException; -import org.apache.tuscany.sca.contribution.processor.ContributionWriteException; -import org.apache.tuscany.sca.contribution.processor.ProcessorContext; -import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; -import org.apache.tuscany.sca.contribution.resolver.ModelResolver; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.core.FactoryExtensionPoint; -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.policy.Intent; -import org.apache.tuscany.sca.policy.IntentMap; -import org.apache.tuscany.sca.policy.PolicyExpression; -import org.apache.tuscany.sca.policy.PolicyFactory; -import org.apache.tuscany.sca.policy.PolicySet; -import org.apache.tuscany.sca.policy.Qualifier; - -/** - * Processor for handling XML models of PolicySet definitions - * - * @version $Rev$ $Date$ - */ -public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<PolicySet>, - PolicyConstants { - - private PolicyFactory policyFactory; - private StAXArtifactProcessor<Object> extensionProcessor; - private XPathHelper xpathHelper; - - // private XPathFactory xpathFactory; - - public PolicySetProcessor(ExtensionPointRegistry registry, StAXArtifactProcessor<Object> extensionProcessor) { - FactoryExtensionPoint modelFactories = registry.getExtensionPoint(FactoryExtensionPoint.class); - this.policyFactory = modelFactories.getFactory(PolicyFactory.class); - this.extensionProcessor = extensionProcessor; - this.xpathHelper = XPathHelper.getInstance(registry); - } - - /** - * Report a exception. - * - * @param problems - * @param message - * @param model - */ - private void error(Monitor monitor, String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - Messages.RESOURCE_BUNDLE, - Severity.ERROR, - model, - message, - ex); - monitor.problem(problem); - } - } - - /** - * Report a error. - * - * @param problems - * @param message - * @param model - */ - private void error(Monitor monitor, String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = - monitor.createProblem(this.getClass().getName(), - Messages.RESOURCE_BUNDLE, - Severity.ERROR, - model, - message, - (Object[])messageParameters); - monitor.problem(problem); - } - } - - public PolicySet read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, - XMLStreamException { - PolicySet policySet = null; - Monitor monitor = context.getMonitor(); - String policySetName = reader.getAttributeValue(null, NAME); - String appliesTo = reader.getAttributeValue(null, APPLIES_TO); - if (policySetName == null || appliesTo == null) { - if (policySetName == null) - error(monitor, "PolicySetNameMissing", reader); - if (appliesTo == null) - error(monitor, "PolicySetAppliesToMissing", reader); - return policySet; - } - - policySet = policyFactory.createPolicySet(); - policySet.setName(new QName(policySetName)); - - //TODO: with 1.0 version of specs the applies to xpath is given related to the immediate - //parent whereas the runtime evaluates the xpath aginst the composite element. What the runtime - //is doing is what the future version of the specs could be tending towards. When that happens - //this 'if' must be deleted - if (appliesTo != null && !appliesTo.startsWith("/")) { - appliesTo = "//" + appliesTo; - } - - policySet.setAppliesTo(appliesTo); - - if (appliesTo != null) { - try { - XPath path = xpathHelper.newXPath(); - NamespaceContext nsContext = xpathHelper.getNamespaceContext(appliesTo, reader.getNamespaceContext()); - // path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(context)); - XPathExpression expression = xpathHelper.compile(path, nsContext, appliesTo); - policySet.setAppliesToXPathExpression(expression); - } catch (XPathExpressionException e) { - ContributionReadException ce = new ContributionReadException(e); - error(monitor, "ContributionReadException", policySet, ce); - //throw ce; - } - } - - String attachTo = reader.getAttributeValue(null, ATTACH_TO); - if (attachTo != null) { - try { - XPath path = xpathHelper.newXPath(); - NamespaceContext nsContext = xpathHelper.getNamespaceContext(attachTo, reader.getNamespaceContext()); - path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(nsContext)); - - attachTo = PolicyXPathFunction.normalize(attachTo,getSCAPrefix(nsContext)); - XPathExpression expression = xpathHelper.compile(path, nsContext, attachTo); - policySet.setAttachTo(attachTo); - policySet.setAttachToXPathExpression(expression); - } catch (XPathExpressionException e) { - ContributionReadException ce = new ContributionReadException(e); - error(monitor, "ContributionReadException", policySet, ce); - //throw ce; - } - - } - - readProvidedIntents(policySet, reader); - - int event = reader.getEventType(); - QName name = null; - reader.next(); - while (reader.hasNext()) { - event = reader.getEventType(); - switch (event) { - case START_ELEMENT: { - name = reader.getName(); - if (POLICY_INTENT_MAP_QNAME.equals(name)) { - Intent mappedIntent = policyFactory.createIntent(); - String provides = reader.getAttributeValue(null, PROVIDES); - if (provides != null) { - mappedIntent.setName(getQName(reader, PROVIDES)); - if (policySet.getProvidedIntents().contains(mappedIntent)) { - readIntentMap(reader, policySet, mappedIntent, context); - } else { - error(monitor, "IntentNotSpecified", policySet, policySetName); - } - } else { - error(monitor, "IntentMapProvidesMissing", reader, policySetName); - } - } else if (POLICY_SET_REFERENCE_QNAME.equals(name)) { - PolicySet referredPolicySet = policyFactory.createPolicySet(); - String referencename = reader.getAttributeValue(null, NAME); - if (referencename != null) { - referredPolicySet.setName(getQName(reader, NAME)); - policySet.getReferencedPolicySets().add(referredPolicySet); - } else { - error(monitor, "PolicySetReferenceNameMissing", reader, policySetName); - } - } /*else if ( WS_POLICY_QNAME.equals(name) ) { - OMElement policyElement = loadElement(reader); - org.apache.neethi.Policy wsPolicy = PolicyEngine.getPolicy(policyElement); - policySet.getPolicies().add(wsPolicy); - } */else { - Object extension = extensionProcessor.read(reader, context); - if (extension != null) { - PolicyExpression exp = policyFactory.createPolicyExpression(); - exp.setName(name); - exp.setPolicy(extension); - // check that all the policies in the policy set are - // expressed in the same language. Compare against the - // first expression we added - if ((policySet.getPolicies().size() > 0) && (!policySet.getPolicies().get(0).getName() - .equals(name))) { - error(monitor, "PolicyLanguageMissmatch", reader, policySet.getName(), policySet - .getPolicies().get(0).getName(), name); - } else { - policySet.getPolicies().add(exp); - } - } - } - break; - } - } - if (event == END_ELEMENT) { - if (POLICY_SET_QNAME.equals(reader.getName())) { - break; - } - } - - //Read the next element - if (reader.hasNext()) { - reader.next(); - } - } - return policySet; - } - - private String getSCAPrefix(NamespaceContext nsContext) { - - Iterator<String> iter = nsContext.getPrefixes(SCA11_NS); - while (iter.hasNext()) { - String prefix = iter.next(); - if (!prefix.equals(XMLConstants.DEFAULT_NS_PREFIX)) { - return prefix; - } - } - - return "__sca"; - } - - public void readIntentMap(XMLStreamReader reader, PolicySet policySet, Intent mappedIntent, ProcessorContext context) - throws ContributionReadException { - Monitor monitor = context.getMonitor(); - QName name = reader.getName(); - if (POLICY_INTENT_MAP_QNAME.equals(name)) { - - IntentMap intentMap = policyFactory.createIntentMap(); - QName intentName = getQName(reader, INTENT_MAP); - intentMap.setProvidedIntent(mappedIntent); - - if (!policySet.getIntentMaps().contains(intentMap)) { - policySet.getIntentMaps().add(intentMap); - } else { - Monitor.error(context.getMonitor(), this, Messages.RESOURCE_BUNDLE, "IntentMapIsNotUnique", policySet - .getName().toString(), mappedIntent.getName().getLocalPart()); - } - - String qualifierName = null; - String qualfiedIntentName = null; - Intent qualifiedIntent = null; - - Qualifier qualifier = null; - - int event = reader.getEventType(); - try { - reader.next(); - while (reader.hasNext()) { - event = reader.getEventType(); - switch (event) { - case START_ELEMENT: { - name = reader.getName(); - if (POLICY_INTENT_MAP_QUALIFIER_QNAME.equals(name)) { - qualifierName = getString(reader, NAME); - if (qualifierName != null) { - qualfiedIntentName = - mappedIntent.getName().getLocalPart() + QUALIFIER + qualifierName; - qualifiedIntent = policyFactory.createIntent(); - qualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(), - qualfiedIntentName)); - qualifier = policyFactory.createQualifier(); - qualifier.setIntent(qualifiedIntent); - intentMap.getQualifiers().add(qualifier); - - } else { - error(monitor, "QualifierNameMissing", reader, policySet.getName()); - } - } else if (POLICY_INTENT_MAP_QNAME.equals(name)) { - QName providedIntent = getQName(reader, PROVIDES); - if (qualifierName.equals(providedIntent.getLocalPart())) { - readIntentMap(reader, policySet, qualifiedIntent, context); - } else { - error(monitor, - "IntentMapDoesNotMatch", - providedIntent, - providedIntent, - qualifierName, - policySet); - //throw new ContributionReadException("Intent provided by IntentMap " + - //providedIntent + " does not match parent qualifier " + qualifierName + - //" in policyset - " + policySet); - } - } else { - Object extension = extensionProcessor.read(reader, context); - if (extension != null && qualifier != null) { - PolicyExpression exp = policyFactory.createPolicyExpression(); - exp.setName(name); - exp.setPolicy(extension); - qualifier.getPolicies().add(exp); - } - } - break; - } - } - if (event == END_ELEMENT && POLICY_INTENT_MAP_QNAME.equals(reader.getName())) { - break; - } - //Read the next element - if (reader.hasNext()) { - reader.next(); - } - } - } catch (XMLStreamException e) { - ContributionReadException ce = new ContributionReadException(e); - error(monitor, "ContributionReadException", reader, ce); - throw ce; - } - } - } - - public void write(PolicySet policySet, XMLStreamWriter writer, ProcessorContext context) - throws ContributionWriteException, XMLStreamException { - - // Write an <sca:policySet> - writer.writeStartElement(SCA11_NS, POLICY_SET); - writer.writeNamespace(policySet.getName().getPrefix(), policySet.getName().getNamespaceURI()); - writer.writeAttribute(NAME, policySet.getName().getPrefix() + COLON + policySet.getName().getLocalPart()); - writer.writeAttribute(APPLIES_TO, policySet.getAppliesTo()); - writer.writeAttribute(ATTACH_TO, policySet.getAttachTo()); - - writeProvidedIntents(policySet, writer); - - writer.writeEndElement(); - } - - private void readProvidedIntents(PolicySet policySet, XMLStreamReader reader) { - String value = reader.getAttributeValue(null, PROVIDES); - if (value != null) { - List<Intent> providedIntents = policySet.getProvidedIntents(); - for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { - QName qname = getQNameValue(reader, tokens.nextToken()); - Intent intent = policyFactory.createIntent(); - intent.setName(qname); - providedIntents.add(intent); - } - } - } - - private void writeProvidedIntents(PolicySet policySet, XMLStreamWriter writer) throws XMLStreamException { - if (!policySet.getProvidedIntents().isEmpty()) { - StringBuffer sb = new StringBuffer(); - for (Intent providedIntents : policySet.getProvidedIntents()) { - sb.append(getQualifiedName(providedIntents.getName(), writer)); - sb.append(" "); - } - // Remove the last space - sb.deleteCharAt(sb.length() - 1); - writer.writeAttribute(PolicyConstants.PROVIDES, sb.toString()); - } - } - - private String getQualifiedName(QName name, XMLStreamWriter writer) throws XMLStreamException { - String local = name.getLocalPart(); - String prefix = writer.getPrefix(name.getNamespaceURI()); - if (prefix != null && prefix.length() > 0) { - return prefix + ':' + local; - } else { - return local; - } - } - - private void resolvePolicies(PolicySet policySet, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - boolean unresolved = false; - if (policySet != null) { - for (Object o : policySet.getPolicies()) { - extensionProcessor.resolve(o, resolver, context); - /*if ( o instanceof Policy && ((Policy)o).isUnresolved() ) { - unresolved = true; - }*/ - } - policySet.setUnresolved(unresolved); - } - } - - public QName getArtifactType() { - return POLICY_SET_QNAME; - } - - public Class<PolicySet> getModelType() { - return PolicySet.class; - } - - private void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - if (policySet != null) { - //resolve all provided intents - List<Intent> providedIntents = new ArrayList<Intent>(); - for (Intent providedIntent : policySet.getProvidedIntents()) { - if (providedIntent.isUnresolved()) { - Intent resolved = resolver.resolveModel(Intent.class, providedIntent, context); - if (!resolved.isUnresolved() || resolved != providedIntent) { - providedIntents.add(resolved); - } else { - error(context.getMonitor(), "ProvidedIntentNotFound", policySet, providedIntent, policySet); - return; - //throw new ContributionResolveException("Provided Intent - " + providedIntent - //+ " not found for PolicySet " + policySet); - } - } else { - providedIntents.add(providedIntent); - } - } - policySet.getProvidedIntents().clear(); - policySet.getProvidedIntents().addAll(providedIntents); - } - } - - private void resolveIntentsInMappedPolicies(PolicySet policySet, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - Monitor monitor = context.getMonitor(); - for (IntentMap intentMap : policySet.getIntentMaps()) { - Intent intent = intentMap.getProvidedIntent(); - if (intent.isUnresolved()) { - Intent resolved = resolver.resolveModel(Intent.class, intent, context); - if (!resolved.isUnresolved() || resolved != intent) { - intentMap.setProvidedIntent(resolved); - } else { - error(monitor, "MappedIntentNotFound", policySet, intent, policySet); - return; - //throw new ContributionResolveException("Mapped Intent - " + mappedIntent - //+ " not found for PolicySet " + policySet); - } - } - for (Qualifier qualifier : intentMap.getQualifiers()) { - intent = qualifier.getIntent(); - if (intent.isUnresolved()) { - Intent resolved = resolver.resolveModel(Intent.class, intent, context); - if (!resolved.isUnresolved() || resolved != intent) { - qualifier.setIntent(resolved); - } else { - error(monitor, "MappedIntentNotFound", policySet, intent, policySet); - return; - //throw new ContributionResolveException("Mapped Intent - " + mappedIntent - //+ " not found for PolicySet " + policySet); - } - } - for (PolicyExpression exp : qualifier.getPolicies()) { - // FIXME: How to resolve the policies? - } - } - // validate that the intent map has a qualifier for each - // intent qualifier. The above code has already checked that the - // qualifiers that are there are resolved - Intent providedIntent = intentMap.getProvidedIntent(); - if (intentMap.getQualifiers().size() != providedIntent.getQualifiedIntents().size()) { - String missingQualifiers = ""; - for (Intent loopQualifiedIntent : providedIntent.getQualifiedIntents()) { - boolean found = false; - for (Qualifier loopQualifier : intentMap.getQualifiers()) { - if (loopQualifier.getIntent().getName().equals(loopQualifiedIntent.getName())) { - found = true; - break; - } - } - if (!found) { - missingQualifiers += loopQualifiedIntent.getName().getLocalPart() + " "; - } - } - if (missingQualifiers.length() > 0) { - Monitor.error(context.getMonitor(), - this, - Messages.RESOURCE_BUNDLE, - "IntentMapMissingQualifiers", - policySet.getName().toString(), - providedIntent.getName().getLocalPart(), - missingQualifiers); - } - } - } - - } - - private void resolveReferredPolicySets(PolicySet policySet, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - - List<PolicySet> referredPolicySets = new ArrayList<PolicySet>(); - for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { - if (referredPolicySet.isUnresolved()) { - PolicySet resolved = resolver.resolveModel(PolicySet.class, referredPolicySet, context); - if (!resolved.isUnresolved() || resolved != referredPolicySet) { - referredPolicySets.add(resolved); - } else { - error(context.getMonitor(), "ReferredPolicySetNotFound", policySet, referredPolicySet, policySet); - return; - //throw new ContributionResolveException("Referred PolicySet - " + referredPolicySet - //+ "not found for PolicySet - " + policySet); - } - } else { - referredPolicySets.add(referredPolicySet); - } - } - policySet.getReferencedPolicySets().clear(); - policySet.getReferencedPolicySets().addAll(referredPolicySets); - } - - private void includeReferredPolicySets(PolicySet policySet, PolicySet referredPolicySet) { - for (PolicySet furtherReferredPolicySet : referredPolicySet.getReferencedPolicySets()) { - includeReferredPolicySets(referredPolicySet, furtherReferredPolicySet); - } - policySet.getPolicies().addAll(referredPolicySet.getPolicies()); - policySet.getIntentMaps().addAll(referredPolicySet.getIntentMaps()); - } - - public void resolve(PolicySet policySet, ModelResolver resolver, ProcessorContext context) - throws ContributionResolveException { - if (policySet != null && policySet.isUnresolved()) { - resolveProvidedIntents(policySet, resolver, context); - resolveIntentsInMappedPolicies(policySet, resolver, context); - resolveReferredPolicySets(policySet, resolver, context); - - for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { - includeReferredPolicySets(policySet, referredPolicySet); - } - - if (policySet.isUnresolved()) { - //resolve the policy attachments - resolvePolicies(policySet, resolver, context); - - /*if ( !policySet.isUnresolved() ) { - resolver.addModel(policySet); - }*/ - } - - policySet.setUnresolved(false); - } - } -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java deleted file mode 100644 index d0b45b2d7d..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunction.java +++ /dev/null @@ -1,294 +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.policy.xml; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionException; - -import org.w3c.dom.Document; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; - -/** - * The SCA-defined XPath function - */ -public class PolicyXPathFunction implements XPathFunction { - private static Logger logger = Logger.getLogger(PolicyXPathFunction.class.getName()); - - static final QName InterfaceRef = new QName(PolicyConstants.SCA11_NS, "InterfaceRef"); - static final QName OperationRef = new QName(PolicyConstants.SCA11_NS, "OperationRef"); - static final QName MessageRef = new QName(PolicyConstants.SCA11_NS, "MessageRef"); - static final QName IntentRefs = new QName(PolicyConstants.SCA11_NS, "IntentRefs"); - static final QName URIRef = new QName(PolicyConstants.SCA11_NS, "URIRef"); - - static final Set<QName> functions = - new HashSet<QName>(Arrays.asList(InterfaceRef, OperationRef, MessageRef, IntentRefs, URIRef)); - - private NamespaceContext namespaceContext; - private final QName functionName; - - public PolicyXPathFunction(NamespaceContext namespaceContext, QName functionName) { - super(); - this.namespaceContext = namespaceContext; - this.functionName = functionName; - } - - private Node getContextNode(List args) { - if (args.size() >= 2) { - NodeList nodeList = (NodeList)args.get(1); - if (nodeList.getLength() > 0) { - return nodeList.item(0); - } - } - return null; - } - - public Object evaluate(List args) throws XPathFunctionException { - if (logger.isLoggable(Level.FINE)) { - logger.fine(functionName + "(" + args + ")"); - } - - String arg = (String)args.get(0); - Node node = getContextNode(args); - /** - * If the xpath expression that contains the function does not select any nodes - * (eg IntentRefs('someIntent')), the context node passed in will be a Document. - * In this case we need to iterate over every Node in the Document and evaluate it. - * - * If the xpath expression does select nodes (eg //sca:component[IntentRefs('someIntent')]) - * then xpath will call evaluate for each node and we only need to return the result for that - * node. - */ - if ( node instanceof Document ) - return evaluateDocument(arg, (Document)node); - else - return evaluateNode(arg, node); - } - - public Object evaluateNode(String arg, Node node) { - if (InterfaceRef.equals(functionName)) { - return evaluateInterface(arg, node); - } else if (OperationRef.equals(functionName)) { - String[] params = arg.split("/"); - if (params.length != 2) { - throw new IllegalArgumentException("Invalid argument: " + arg); - } - String interfaceName = params[0]; - String operationName = params[1]; - return evaluateOperation(interfaceName, operationName, node); - } else if (MessageRef.equals(functionName)) { - String[] params = arg.split("/"); - if (params.length != 3) { - throw new IllegalArgumentException("Invalid argument: " + arg); - } - String interfaceName = params[0]; - String operationName = params[1]; - String messageName = params[2]; - return evaluateMessage(interfaceName, operationName, messageName, node); - } else if (URIRef.equals(functionName)) { - return evaluateURI(arg, node); - } else if (IntentRefs.equals(functionName)) { - String[] intents = arg.split("(\\s)+"); - return evaluateIntents(intents, node); - } else { - return Boolean.FALSE; - } - } - - private class NodeListImpl implements NodeList { - - private ArrayList<Node> list; - - public NodeListImpl() { - this.list = new ArrayList<Node>(); - } - public int getLength() { - return this.list.size(); - } - - public Node item(int index) { - return this.list.get(index); - } - public boolean add(Node node) { - return this.list.add(node); - - } - - } - private Object evaluateDocument(String arg, Document doc) { - NodeListImpl retList = new NodeListImpl(); - NodeList elements = doc.getElementsByTagName("*"); - for ( int i=0; i < elements.getLength(); i++) { - Object node = evaluateNode(arg, elements.item(i)); - if ( node != null ) - retList.add((Node)node); - } - return retList; - } - - private Boolean evaluateInterface(String interfaceName, Node node) { - return Boolean.FALSE; - } - - private Boolean evaluateOperation(String interfaceName, String operationName, Node node) { - return Boolean.FALSE; - } - - private Boolean evaluateMessage(String interfaceName, String operationName, String messageName, Node node) { - return Boolean.FALSE; - } - - private Boolean evaluateURI(String uri, Node node) { - return Boolean.FALSE; - } - - /** - * Evaluates a single node for the given intents. - * @param intents - * @param node - * @return - */ - private Object evaluateIntents(String[] intents, Node node) { - if ( node == null ) - return false; - - if ( node.getAttributes() != null ) { - for ( int i=0; i < node.getAttributes().getLength(); i++) { - Node attr = node.getAttributes().item(i); - - if ( "requires".equalsIgnoreCase(attr.getNodeName())) { - - for ( int j = 0; j < intents.length; j++ ) { - // Check negative intents - if ( intents[j].startsWith("!")) { - if ( matchIntent(intents[j].substring(1), attr, node.getNamespaceURI())) - return null; - } else if ( !matchIntent(intents[j], attr, node.getNamespaceURI())){ - return null; - } - } - return node; - } - - } - } - - return null; - } - - - - /** - * Determine whether the given intent is present in the "requires" attribute - * @param intent - * @param node - * @param namespaceURI - * @return - */ - private boolean matchIntent(String intent, Node node, String namespaceURI) { - String[] requires = node.getNodeValue().split("(\\s)+"); - QName intentName = getStringAsQName(intent); - - - for ( int i=0; i < requires.length; i++ ) { - QName nodeName = null; - int idx = requires[i].indexOf(':'); - - // No prefix specified - if ( idx == -1 ) { - nodeName = new QName(namespaceURI, requires[i]); - } else { - String prefix = requires[i].substring(0, idx); - String name = requires[i].substring(idx + 1); - String ns = node.lookupNamespaceURI(prefix); - nodeName = new QName(ns, name, prefix); - } - if ( intentName.equals(nodeName)) - return true; - } - return false; - } - - - private QName getStringAsQName(String intent) { - int idx = intent.indexOf(':'); - if (idx == -1) - return new QName(intent); - - String prefix = intent.substring(0, idx); - intent = intent.substring(idx + 1); - - return new QName(namespaceContext.getNamespaceURI(prefix), intent, prefix); - - } - - - private static Pattern FUNCTION; - static { - String functionPattern = "(URIRef|InterfaceRef|OperationRef|MessageRef|IntentRefs)\\s*\\(([^\\)]*)\\)"; - FUNCTION = Pattern.compile(functionPattern); - } - - /** Adds the node as an argument to the XPath function. - * Required in order to have access to the NodeList within the function - */ - public static String normalize(String attachTo, String scaPrefix) { - // Get rid of any whitespace - attachTo = attachTo.trim(); - - Matcher matcher = FUNCTION.matcher(attachTo); - boolean result = matcher.find(); - if (result) { - StringBuffer sb = new StringBuffer(); - do { - String function = matcher.group(1); - String args = matcher.group(2); - if ( (matcher.start() == 0) || (attachTo.charAt( matcher.start() -1) != ':' )) { - function = scaPrefix + ":" + function; - } - String replacement = null; - if (args.trim().length() > 0) { - replacement = function + "(" + args + "," + "self::node())"; - } else { - replacement = function + "(self::node())"; - } - matcher.appendReplacement(sb, replacement); - result = matcher.find(); - } while (result); - - matcher.appendTail(sb); - return sb.toString(); - } - return attachTo; - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java deleted file mode 100644 index ca44667903..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyXPathFunctionResolver.java +++ /dev/null @@ -1,72 +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.policy.xml; - -import javax.xml.namespace.NamespaceContext; -import javax.xml.namespace.QName; -import javax.xml.xpath.XPathFunction; -import javax.xml.xpath.XPathFunctionResolver; - -/** - * A resolver that handles SCA-defined XPath functions - * - * Interface Related Functions - * <ul> - * <li>InterfaceRef( InterfaceName ) - * <li>OperationRef( InterfaceName/OperationName ) - * <li>MessageRef( InterfaceName/OperationName/MessageName ) - * </ul> - * - * Intent Related Functions - * <ul> - * <li>IntentRefs( IntentList ) - * </ul> - * - * URI Based Function - * <ul> - * <li>URIRef( URI ) - * </ul> - */ -public class PolicyXPathFunctionResolver implements XPathFunctionResolver { - private NamespaceContext namespaceContext; - - public PolicyXPathFunctionResolver(NamespaceContext namespaceContext) { - super(); - this.namespaceContext = namespaceContext; - } - - public XPathFunction resolveFunction(QName functionName, int arity) { - if (functionName == null) { - throw new NullPointerException("Function name is null"); - } - if (PolicyXPathFunction.functions.contains(functionName)) { - if (arity >= 1) { - // We are relaxing the arity here so that we can pass in the context node - // by modifying the original xpath so that sca functions take self::node() - // as the 2nd argument - return new PolicyXPathFunction(namespaceContext, functionName); - } else { - throw new IllegalArgumentException("Invalid number of arguments: " + arity); - } - } - return null; - } - -} diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/sca-policy-1.1-intents-definitions-cd03.xml b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/sca-policy-1.1-intents-definitions-cd03.xml deleted file mode 100644 index 58770f71a0..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/sca-policy-1.1-intents-definitions-cd03.xml +++ /dev/null @@ -1,242 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- Copyright(C) OASIS(R) 2005,2009. All Rights Reserved. - OASIS trademark, IPR and other policies apply. --> -<sca:definitions xmlns:sca="http://docs.oasis-open.org/ns/opencsa/sca/200912" - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - targetNamespace="http://docs.oasis-open.org/ns/opencsa/sca/200912"> - - <!-- Security related intents --> - <sca:intent name="serverAuthentication" constrains="sca:binding" - intentType="interaction"> - <sca:description> - Communication through the binding requires that the - server is authenticated by the client - </sca:description> - <sca:qualifier name="transport" default="true"/> - <sca:qualifier name="message"/> - </sca:intent> - - <sca:intent name="clientAuthentication" constrains="sca:binding" - intentType="interaction"> - <sca:description> - Communication through the binding requires that the - client is authenticated by the server - </sca:description> - <sca:qualifier name="transport" default="true"/> - <sca:qualifier name="message"/> - </sca:intent> - - <sca:intent name="authentication" requires="sca:clientAuthentication"> - <sca:description> - A convenience intent to help migration - </sca:description> - </sca:intent> - - <sca:intent name="mutualAuthentication" - requires="sca:clientAuthentication sca:serverAuthentication"> - <sca:description> - Communication through the binding requires that the - client and server to authenticate each other - </sca:description> - </sca:intent> - - <sca:intent name="confidentiality" constrains="sca:binding" - intentType="interaction"> - <sca:description> - Communication through the binding prevents unauthorized - users from reading the messages - </sca:description> - <sca:qualifier name="transport" default="true"/> - <sca:qualifier name="message"/> - </sca:intent> - - <sca:intent name="integrity" constrains="sca:binding" - intentType="interaction"> - <sca:description> - Communication through the binding prevents tampering - with the messages sent between the client and the service. - </sca:description> - <sca:qualifier name="transport" default="true"/> - <sca:qualifier name="message"/> - </sca:intent> - - <sca:intent name="authorization" constrains="sca:implementation" - intentType="implementation"> - <sca:description> - Ensures clients are authorized to use services. - </sca:description> - <sca:qualifier name="fineGrain" default="true"/> - </sca:intent> - - - <!-- Reliable messaging related intents --> - <sca:intent name="atLeastOnce" constrains="sca:binding" - intentType="interaction"> - <sca:description> - This intent is used to indicate that a message sent - by a client is always delivered to the component. - </sca:description> - </sca:intent> - - <sca:intent name="atMostOnce" constrains="sca:binding" - intentType="interaction"> - <sca:description> - This intent is used to indicate that a message that was - successfully sent by a client is not delivered more than - once to the component. - </sca:description> - </sca:intent> - - <sca:intent name="exactlyOnce" requires="sca:atLeastOnce sca:atMostOnce" - constrains="sca:binding" intentType="interaction"> - <sca:description> - This profile intent is used to indicate that a message sent - by a client is always delivered to the component. It also - indicates that duplicate messages are not delivered to the - component. - </sca:description> - </sca:intent> - - <sca:intent name="ordered" constrains="sca:binding" - intentType="interaction"> - <sca:description> - This intent is used to indicate that all the messages are - delivered to the component in the order they were sent by - the client. - </sca:description> - </sca:intent> - - <!-- Transaction related intents --> - <sca:intent name="managedTransaction" excludes="sca:noManagedTransaction" - mutuallyExclusive="true" constrains="sca:implementation" - intentType="implementation"> - <sca:description> - A managed transaction environment is necessary in order to - run the component. The specific type of managed transaction - needed is not constrained. - </sca:description> - <sca:qualifier name="global" default="true"> - <sca:description> - For a component marked with managedTransaction.global - a global transaction needs to be present before dispatching - any method on the component - using any transaction - propagated from the client or else beginning and completing - a new transaction. - </sca:description> - </sca:qualifier> - <sca:qualifier name="local"> - <sca:description> - A component marked with managedTransaction.local needs to - run within a local transaction containment (LTC) that - is started and ended by the SCA runtime. - </sca:description> - </sca:qualifier> - </sca:intent> - - <sca:intent name="noManagedTransaction" excludes="sca:managedTransaction" - constrains="sca:implementation" intentType="implementation"> - <sca:description> - A component marked with noManagedTransaction needs to run without - a managed transaction, under neither a global transaction nor - an LTC. A transaction propagated to the hosting SCA runtime - is not joined by the hosting runtime on behalf of a - component marked with noManagedtransaction. - </sca:description> - </sca:intent> - - <sca:intent name="transactedOneWay" excludes="sca:immediateOneWay" - constrains="sca:binding" intentType="implementation"> - <sca:description> - For a reference marked as transactedOneWay any OneWay invocation - messages are transacted as part of a client global - transaction. - For a service marked as transactedOneWay any OneWay invocation - message are received from the transport binding in a - transacted fashion, under the service’s global transaction. - </sca:description> - </sca:intent> - - <sca:intent name="immediateOneWay" excludes="sca:transactedOneWay" - constrains="sca:binding" intentType="implementation"> - <sca:description> - For a reference indicates that any OneWay invocation messages - are sent immediately regardless of any client transaction. - For a service indicates that any OneWay invocation is - received immediately regardless of any target service - transaction. - </sca:description> - </sca:intent> - - <sca:intent name="propagatesTransaction" excludes="sca:suspendsTransaction" - constrains="sca:binding" intentType="interaction"> - <sca:description> - A service marked with propagatesTransaction is dispatched - under any propagated (client) transaction and the service binding - needs to be capable of receiving a transaction context. - A reference marked with propagatesTransaction propagates any - transaction context under which the client runs when the - reference is used for a request-response interaction and the - binding of a reference marked with propagatesTransaction needs to - be capable of propagating a transaction context. - </sca:description> - </sca:intent> - - <sca:intent name="suspendsTransaction" excludes="sca:propagatesTransaction" - constrains="sca:binding" intentType="interaction"> - <sca:description> - A service marked with suspendsTransaction is not dispatched - under any propagated (client) transaction. - A reference marked with suspendsTransaction does not propagate - any transaction context under which the client runs when the - reference is used. - </sca:description> - </sca:intent> - - <sca:intent name="managedSharedTransaction" - requires="sca:managedTransaction.global sca:propagatesTransaction"> - <sca:description> - Used to indicate that the component requires both the - managedTransaction.global and the propagatesTransactions - intents - </sca:description> - </sca:intent> - - <!-- Miscellaneous intents --> - <sca:intent name="asyncInvocation" excludes="sca:propagatesTransaction" constrains="sca:binding" - intentType="interaction"> - <sca:description> - Indicates that request/response operations for the - interface of this wire are "long running" and must be - treated as two separate message transmissions - </sca:description> - </sca:intent> - - <sca:intent name="SOAP" constrains="sca:binding" intentType="interaction" mutuallyExclusive="true"> - <sca:description> - Specifies that the SOAP messaging model is used for delivering - messages. - </sca:description> - <sca:qualifier name="v1_1" default="true"/> - <sca:qualifier name="v1_2"/> - </sca:intent> - - <sca:intent name="JMS" constrains="sca:binding" intentType="interaction"> - <sca:description> - Requires that the messages are delivered and received via the - JMS API. - </sca:description> - </sca:intent> - - <sca:intent name="noListener" constrains="sca:binding" - intentType="interaction"> - <sca:description> - This intent can only be used on a reference. Indicates that the - client is not able to handle new inbound connections. The binding - and callback binding are configured so that any - response or callback comes either through a back channel of the - connection from the client to the server or by having the client - poll the server for messages. - </sca:description> - </sca:intent> - -</sca:definitions> diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor deleted file mode 100644 index 7982dc123c..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor +++ /dev/null @@ -1,29 +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.
-
-# Implementation class for the artifact processor extension
-org.apache.tuscany.sca.assembly.xml.ComponentTypeProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#componentType,model=org.apache.tuscany.sca.assembly.ComponentType
-org.apache.tuscany.sca.assembly.xml.CompositeProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#composite,model=org.apache.tuscany.sca.assembly.Composite
-org.apache.tuscany.sca.assembly.xml.SCABindingProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#binding.sca,model=org.apache.tuscany.sca.assembly.SCABinding
-org.apache.tuscany.sca.assembly.xml.EndpointProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#endpoint,model=org.apache.tuscany.sca.assembly.Endpoint
-org.apache.tuscany.sca.assembly.xml.EndpointReferenceProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#endpointReference,model=org.apache.tuscany.sca.assembly.EndpointReference
-org.apache.tuscany.sca.definitions.xml.DefinitionsProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#definitions,model=org.apache.tuscany.sca.definitions.Definitions
-org.apache.tuscany.sca.policy.xml.BindingTypeProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#bindingType,model=org.apache.tuscany.sca.policy.BindingType
-org.apache.tuscany.sca.policy.xml.ImplementationTypeProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#implementationType,model=org.apache.tuscany.sca.policy.ImplementationType
-org.apache.tuscany.sca.policy.xml.IntentProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#intent,model=org.apache.tuscany.sca.policy.Intent
-org.apache.tuscany.sca.policy.xml.PolicySetProcessor;qname=http://docs.oasis-open.org/ns/opencsa/sca/200912#policySet,model=org.apache.tuscany.sca.policy.PolicySet
-
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor deleted file mode 100644 index f8d1e11ef3..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.URLArtifactProcessor +++ /dev/null @@ -1,22 +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. - -# Implementation class for the artifact processor extension -org.apache.tuscany.sca.assembly.xml.ComponentTypeDocumentProcessor;type=.componentType,model=org.apache.tuscany.sca.assembly.ComponentType -org.apache.tuscany.sca.assembly.xml.CompositeDocumentProcessor;type=.composite,model=org.apache.tuscany.sca.assembly.Composite -org.apache.tuscany.sca.definitions.xml.DefinitionsDocumentProcessor;type=/META-INF/definitions.xml,model=org.apache.tuscany.sca.definitions.Definitions -
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver deleted file mode 100644 index f8e4d5bbd4..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.resolver.ModelResolver +++ /dev/null @@ -1,21 +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.
-
-org.apache.tuscany.sca.assembly.xml.CompositeModelResolver;model=org.apache.tuscany.sca.assembly.Composite
-org.apache.tuscany.sca.assembly.xml.ComponentTypeModelResolver;model=org.apache.tuscany.sca.assembly.ComponentType
-org.apache.tuscany.sca.contribution.resolver.DefaultModelResolver;model=org.apache.tuscany.sca.policy.Intent
-
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions deleted file mode 100644 index 381c0ba23b..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.Definitions +++ /dev/null @@ -1,17 +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.
-META-INF/sca-policy-1.1-intents-definitions-cd03.xml
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint deleted file mode 100644 index 45b3512614..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/META-INF/services/org.apache.tuscany.sca.definitions.xml.DefinitionsExtensionPoint +++ /dev/null @@ -1,17 +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.
-org.apache.tuscany.sca.definitions.xml.DefaultDefinitionsExtensionPoint
diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/org/apache/tuscany/sca/assembly/xml/assembly-xml-validation-messages.properties b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/org/apache/tuscany/sca/assembly/xml/assembly-xml-validation-messages.properties deleted file mode 100644 index 8ad5f88892..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/org/apache/tuscany/sca/assembly/xml/assembly-xml-validation-messages.properties +++ /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. -# -# -NoCompositeNamespace = No namespace found: Composite = {0} -UnexpectedInterfaceElement = Unexpected <interface> element found. It should appear inside a <service> or <reference> element. -UnexpectedBindingElement = Unexpected <binding> element found. It should appear inside a <service> or <reference> element. -UnexpectedImplementationElement = Unexpected <implementation> element found. It should appear inside a <component> element. -PolicyImplValidationException = PolicyValidation exception when processing implementation of component {0} due to {1}. -PolicyServiceValidationException = PolicyValidation exceptions when processing service/reference {0} in {1}. Error is {2} -ContributionReadException = ContributionReadException occured due to : {0} -ContributionResolveException = ContributionResolveException occured due to : {0} -ContributionWriteException = ContributionWriteException occured due to : {0} -XMLStreamException = XMLStreamException occured due to : {0} -DuplicateCompositeName = [ASM_6001] More than one composite with the same name {0} found in contribution {1} -PropertyTypeNotFound = The type {0} specified on property {1} of {2} can't be found in any loaded contribution (makes sure the .xsd file is in a contribution, that the contribution is being loaded and that contribution imports and exports are correct) diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/org/apache/tuscany/sca/definitions/xml/definitions-xml-validation-messages.properties b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/org/apache/tuscany/sca/definitions/xml/definitions-xml-validation-messages.properties deleted file mode 100644 index de27c0bd31..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/org/apache/tuscany/sca/definitions/xml/definitions-xml-validation-messages.properties +++ /dev/null @@ -1,24 +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. -# -# -ContributionReadException = ContributionReadException occured due to : -PrivilegedActionException = Privileged Action Exception occured due to FilePermission in security policy file: -ImplementationTypeNotFound = [POL50001] An extension to support the implementation type {0} can't be found in the domain -BindingTypeNotFound = An extension to support the binding type {0} can't be found in the domain
\ No newline at end of file diff --git a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/org/apache/tuscany/sca/policy/xml/policy-xml-validation-messages.properties b/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/org/apache/tuscany/sca/policy/xml/policy-xml-validation-messages.properties deleted file mode 100644 index 08ef6bb5e9..0000000000 --- a/sca-java-2.x/branches/2.0-Beta1/modules/assembly-xml/src/main/resources/org/apache/tuscany/sca/policy/xml/policy-xml-validation-messages.properties +++ /dev/null @@ -1,50 +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. -# -# -ReferredPolicySetNotFound = Referred PolicySet - {0} not found for PolicySet - {1} -MappedIntentNotFound = Mapped Intent - {0} not found for PolicySet {1} -ProvidedIntentNotFound = Provided Intent - {0} not found for PolicySet {1} -UnableToMapPolicies = Unable to map policies for default qualifier in IntentMap for - {0} in policy set - {1} -IntentMapDoesNotMatch = Intent provided by IntentMap {0} does not match parent qualifier {1} in policyset - {2} -IntentNotSpecified = [POL30021] Intent Map provides for Intent not specified as provided by parent PolicySet - {0} -ContrainsAttributeMissing = Constrains attribute missing from Policy Intent Definition {0} -RequiredIntentNotFound = [POL30015] Required Intent - {0} not found for ProfileIntent {1} -QualifiableIntentNotFound = Qualifiable Intent - {0} not found for QualifiedIntent {1} -ErrorInPolicyIntentDefinition = Error in PolicyIntent Definition - {0} {1} -ExcludedIntentNotFound = [POL30016] Excluded Intent {0} not found for intent {1} -UnrecognizedIntentAttachPointType = Unrecognized IntentAttachPointType - {0} -RequiredAttributeMissing = Required attribute {0} missing from extension type definition -AlwaysProvidedIntentNotFound = Always Provided Intent - {0} not found for ExtensionType {1} -MayProvideIntentNotFound = May Provide Intent - {0} not found for ExtensionType {1} -ContributionReadException = ContributionReadException occurred due to: {0} -CyclicReferenceFound = Cyclic reference detected in required attributes of ProfileIntents {0} and {1} -IntentNameMissing = Required attribute "name" missing for Intent Definition -PolicySetReferenceNameMissing = Required attribute "name" missing for PolicySetReference in PolicySet : {0} -PolicySetNameMissing = Required attribute "name" missing for PolicySet Definition -PolicySetAppliesToMissing = Required attribute "appliesTo" missing for PolicySet Definition -IntentMapProvidesMissing = Required attribute "provides" missing for IntentMap in PolicySet : {0} -QualifierNameMissing = Required attribute "name" missing for qualifier definition in PolicySet : {0} -ConstrainedTypeNotFound = Unable to find the extension type {0} constrained by intent: {1} -MultipleDefaultQualifiers = [POL30004] Intent {0} has more than one qualifier marked as the default qualifier -QualifierIsNotUnique = [POL30005] The intent {0} has more than one qualifier with the name {1} -ProfileIntentNameWithPeriod = [POL30006] The profile intent name {0} must not have the character "." in it -IntentMapIsNotUnique = [POL30010] The policy set {0} has more than one intent map with the name {1} -IntentMapMissingQualifiers = [POL30020] The policy set {0} intent map {1} has missing qualifiers: {2} The intent map qualifiers must match the provided intent qualifiers. -PolicyLanguageMissmatch = Policy set {0} contains policy expressions from more than on language, languages {1} and {2} found |