From 28d9bc59aa4522f08b23baf37745fd8cd6b74d9d Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Sat, 13 Sep 2008 22:17:41 +0000 Subject: Renamed modules to match the structure in r643746 and make it possible to create a patch on top of that revision. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@695044 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/policy/xml/BindingTypeProcessor.java | 56 +++ .../policy/xml/ImplementationTypeProcessor.java | 56 +++ .../policy/xml/IntentAttachPointTypeProcessor.java | 219 ++++++++++ .../tuscany/sca/policy/xml/PolicyConstants.java | 77 ++++ .../sca/policy/xml/PolicyIntentProcessor.java | 302 +++++++++++++ .../tuscany/sca/policy/xml/PolicySetProcessor.java | 479 +++++++++++++++++++++ .../sca/policy/xml/ProfileIntentProcessor.java | 38 ++ .../sca/policy/xml/QualifiedIntentProcessor.java | 43 ++ .../sca/policy/xml/SimpleIntentProcessor.java | 38 ++ 9 files changed, 1308 insertions(+) create mode 100644 branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java create mode 100644 branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java create mode 100644 branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java create mode 100644 branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java create mode 100644 branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java create mode 100644 branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java create mode 100644 branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java create mode 100644 branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java create mode 100644 branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java (limited to 'branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml') diff --git a/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java new file mode 100644 index 0000000000..b54adf492b --- /dev/null +++ b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java @@ -0,0 +1,56 @@ +/* + * 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.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.impl.BindingTypeImpl; + + +/** + * Processor for handling XML models of BindingType meta data definitions + */ +public class BindingTypeProcessor extends IntentAttachPointTypeProcessor { + + public BindingTypeProcessor(PolicyFactory policyFactory, IntentAttachPointTypeFactory intentAttachPointTypeFactory, StAXArtifactProcessor extensionProcessor) { + super(policyFactory, intentAttachPointTypeFactory, extensionProcessor); + } + + public QName getArtifactType() { + return BINDING_TYPE_QNAME; + } + + @Override + protected IntentAttachPointType resolveExtensionType(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException { + if ( extnType instanceof BindingTypeImpl ) { + BindingTypeImpl bindingType = (BindingTypeImpl)extnType; + return resolver.resolveModel(BindingTypeImpl.class, bindingType); + } else { + return extnType; + } + + } +} diff --git a/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java new file mode 100644 index 0000000000..e588f93663 --- /dev/null +++ b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java @@ -0,0 +1,56 @@ +/* + * 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.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.impl.ImplementationTypeImpl; + + +/** + * Processor for handling XML models of ImplementationType meta data definitions + */ +public class ImplementationTypeProcessor extends IntentAttachPointTypeProcessor { + + public ImplementationTypeProcessor(PolicyFactory policyFactory, IntentAttachPointTypeFactory intentAttachPointTypeFactory, StAXArtifactProcessor extensionProcessor) { + super(policyFactory, intentAttachPointTypeFactory, extensionProcessor); + } + + public QName getArtifactType() { + return IMPLEMENTATION_TYPE_QNAME; + } + + @Override + protected IntentAttachPointType resolveExtensionType(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException { + if ( extnType instanceof ImplementationTypeImpl ) { + ImplementationTypeImpl implType = (ImplementationTypeImpl)extnType; + return resolver.resolveModel(ImplementationTypeImpl.class, implType); + } else { + return extnType; + } + + } +} diff --git a/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java new file mode 100644 index 0000000000..a69e3aca3a --- /dev/null +++ b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java @@ -0,0 +1,219 @@ +/* + * 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.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.IntentAttachPointType; +import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.impl.BindingTypeImpl; +import org.apache.tuscany.sca.policy.impl.ImplementationTypeImpl; + + +/** + * Processor for handling XML models of ExtensionType meta data definitions + */ +public abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor, PolicyConstants { + + private IntentAttachPointTypeFactory attachPointTypeFactory; + private PolicyFactory policyFactory; + + protected abstract IntentAttachPointType resolveExtensionType(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException; + + public IntentAttachPointTypeProcessor(PolicyFactory policyFactory, IntentAttachPointTypeFactory attachPointTypeFactory, StAXArtifactProcessor extensionProcessor) { + this.policyFactory = policyFactory; + this.attachPointTypeFactory = attachPointTypeFactory; + } + + public IntentAttachPointType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + QName type = getQName(reader, TYPE); + + if ( type != null ) { + if ( type.getLocalPart().startsWith(BINDING) ) { + IntentAttachPointType bindingType = attachPointTypeFactory.createBindingType(); + bindingType.setName(type); + bindingType.setUnresolved(true); + + readAlwaysProvidedIntents(bindingType, reader); + readMayProvideIntents(bindingType, reader); + return bindingType; + } else if ( type.getLocalPart().startsWith(IMPLEMENTATION) ) { + IntentAttachPointType implType = attachPointTypeFactory.createImplementationType(); + implType.setName(type); + implType.setUnresolved(true); + + readAlwaysProvidedIntents(implType, reader); + readMayProvideIntents(implType, reader); + return implType; + } else { + throw new ContributionReadException("Unrecognized IntentAttachPointType - " + type); + } + } else { + throw new ContributionReadException("Required attribute '" + TYPE + + "' missing from BindingType Definition"); + } + } + + private void readAlwaysProvidedIntents(IntentAttachPointType extnType, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, ALWAYS_PROVIDES); + if (value != null) { + List 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(IntentAttachPointType extnType, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, MAY_PROVIDE); + if (value != null) { + List mayProvide = extnType.getMayProvideIntents(); + 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(IntentAttachPointType extnType, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write an + if ( extnType instanceof BindingTypeImpl ) { + writer.writeStartElement(SCA10_NS, BINDING_TYPE); + } else if ( extnType instanceof ImplementationTypeImpl ) { + writer.writeStartElement(SCA10_NS, IMPLEMENTATION_TYPE); + } + + writeAlwaysProvidesIntentsAttribute(extnType, writer); + writeMayProvideIntentsAttribute(extnType, writer); + + writer.writeEndElement(); + } + + private void writeMayProvideIntentsAttribute(IntentAttachPointType extnType, XMLStreamWriter writer) throws XMLStreamException { + StringBuffer sb = new StringBuffer(); + for ( Intent intent : extnType.getMayProvideIntents() ) { + 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(IntentAttachPointType 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(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException { + resolveAlwaysProvidedIntents(extnType, resolver); + resolveMayProvideIntents(extnType, resolver); + extnType.setUnresolved(false); + //resolveExtensionType(extnType, resolver); + } + + private void resolveAlwaysProvidedIntents(IntentAttachPointType extensionType, + ModelResolver resolver) throws ContributionResolveException { + if (extensionType != null) { + // resolve all provided intents + List alwaysProvided = new ArrayList(); + for (Intent providedIntent : extensionType.getAlwaysProvidedIntents()) { + if (providedIntent.isUnresolved()) { + providedIntent = resolver.resolveModel(Intent.class, providedIntent); + if (!providedIntent.isUnresolved()) { + alwaysProvided.add(providedIntent); + } else { + 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(IntentAttachPointType extensionType, + ModelResolver resolver) throws ContributionResolveException { + if (extensionType != null) { + // resolve all provided intents + List mayProvide = new ArrayList(); + for (Intent providedIntent : extensionType.getMayProvideIntents()) { + if (providedIntent.isUnresolved()) { + providedIntent = resolver.resolveModel(Intent.class, providedIntent); + if (!providedIntent.isUnresolved()) { + mayProvide.add(providedIntent); + } else { + throw new ContributionResolveException( + "May Provide Intent - " + providedIntent + + " not found for ExtensionType " + + extensionType); + + } + } else { + mayProvide.add(providedIntent); + } + } + extensionType.getMayProvideIntents().clear(); + extensionType.getMayProvideIntents().addAll(mayProvide); + } + } + + public Class getModelType() { + return IntentAttachPointType.class; + } +} diff --git a/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java new file mode 100644 index 0000000000..655b592665 --- /dev/null +++ b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java @@ -0,0 +1,77 @@ +/* + * 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 + * + */ +public interface PolicyConstants { + String WHITE_SPACE = " "; + String COLON = ":"; + String SCA10_NS = "http://www.osoa.org/xmlns/sca/1.0"; + String TUSCANY_NS = "http://tuscany.apache.org/xmlns/sca/1.0"; + 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 ALWAYS_APPLIES_TO = "alwaysAppliesTo"; + String QUALIFIER = "."; + String INTENT_MAP_QUALIFIER = "qualifier"; + String REQUIRES = "requires"; + String DEFAULT = "default"; + + String WS_POLICY_NS = "http://schemas.xmlsoap.org/ws/2004/09/policy"; + String WS_POLICY = "Policy"; + + String ALWAYS_PROVIDES = "alwaysProvides"; + String MAY_PROVIDE = "mayProvide"; + String TYPE = "type"; + String IMPLEMENTATION_TYPE = "implementationType"; + String BINDING_TYPE = "bindingType"; + QName IMPLEMENTATION_TYPE_QNAME = new QName(SCA10_NS, IMPLEMENTATION_TYPE); + QName BINDING_TYPE_QNAME = new QName(SCA10_NS, BINDING_TYPE); + String BINDING = "binding"; + String IMPLEMENTATION = "implementation"; + + QName POLICY_INTENT_QNAME = new QName(SCA10_NS, INTENT); + QName POLICY_SET_QNAME = new QName(SCA10_NS, POLICY_SET); + QName POLICY_INTENT_MAP_QNAME = new QName(SCA10_NS, INTENT_MAP); + QName SCA_DEFINITIONS_QNAME = new QName(SCA10_NS, SCA_DEFINITIONS); + QName DESCRIPTION_QNAME = new QName(SCA10_NS, DESCRIPTION); + QName POLICY_INTENT_MAP_QUALIFIER_QNAME = new QName(SCA10_NS, INTENT_MAP_QUALIFIER); + QName POLICY_SET_REFERENCE_QNAME = new QName(SCA10_NS, POLICY_SET_REFERENCE); + QName WS_POLICY_QNAME = new QName(WS_POLICY_NS, WS_POLICY); + + String QUALIFIED_INTENT_CONSTRAINS_ERROR = " - Qualified Intents must not specify 'constrains' attribute"; + + + + + +} diff --git a/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java new file mode 100644 index 0000000000..53231f704e --- /dev/null +++ b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java @@ -0,0 +1,302 @@ +/* + * 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.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.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.ProfileIntent; +import org.apache.tuscany.sca.policy.QualifiedIntent; + +/* * + * Processor for handling XML models of PolicyIntent definitions + */ + +public abstract class PolicyIntentProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor, PolicyConstants { + + private PolicyFactory policyFactory; + + public PolicyIntentProcessor(ModelFactoryExtensionPoint modelFactories) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + } + + public PolicyIntentProcessor(PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) { + this.policyFactory = policyFactory; + } + + public T read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + Intent policyIntent = null; + String policyIntentName = reader.getAttributeValue(null, NAME); + // Read an + if (reader.getAttributeValue(null, REQUIRES) != null) { + policyIntent = policyFactory.createProfileIntent(); + } else if ( policyIntentName != null && policyIntentName.indexOf(QUALIFIER) != -1) { + policyIntent = policyFactory.createQualifiedIntent(); + + int qualifierIndex = policyIntentName.lastIndexOf(QUALIFIER); + Intent qualifiableIntent = policyFactory.createIntent(); + qualifiableIntent.setUnresolved(true); + qualifiableIntent.setName(new QName(policyIntentName.substring(0, qualifierIndex))); + + ((QualifiedIntent)policyIntent).setQualifiableIntent(qualifiableIntent); + } else { + policyIntent = policyFactory.createIntent(); + } + policyIntent.setName(new QName(policyIntentName)); + + if ( policyIntent instanceof ProfileIntent ) { + readRequiredIntents((ProfileIntent)policyIntent, reader); + } + + readConstrainedArtifacts(policyIntent, reader); + + 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)) { + policyIntent.setDescription(reader.getElementText()); + } + break; + } + } + if (event == END_ELEMENT && POLICY_INTENT_QNAME.equals(reader.getName())) { + break; + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + return (T)policyIntent; + } + + public void write(T policyIntent, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + // Write an + writer.writeStartElement(PolicyConstants.SCA10_NS, INTENT); + writer.writeNamespace(policyIntent.getName().getPrefix(), policyIntent.getName().getNamespaceURI()); + writer.writeAttribute(PolicyConstants.NAME, + policyIntent.getName().getPrefix() + COLON + policyIntent.getName().getLocalPart()); + if (policyIntent instanceof ProfileIntent) { + ProfileIntent profileIntent = (ProfileIntent)policyIntent; + if (profileIntent.getRequiredIntents() != null && + profileIntent.getRequiredIntents().size() > 0) { + StringBuffer sb = new StringBuffer(); + for (Intent requiredIntents : profileIntent.getRequiredIntents()) { + sb.append(requiredIntents.getName()); + sb.append(" "); + } + writer.writeAttribute(PolicyConstants.REQUIRES, sb.toString()); + } + } + + if (!(policyIntent instanceof QualifiedIntent) ) { + if (policyIntent.getConstrains() != null && + policyIntent.getConstrains().size() > 0) { + StringBuffer sb = new StringBuffer(); + for (QName contrainedArtifact : policyIntent.getConstrains()) { + sb.append(contrainedArtifact.toString()); + sb.append(" "); + } + writer.writeAttribute(CONSTRAINS, sb.toString()); + } else { + throw new ContributionWriteException("Contrains attribute missing from " + + "Policy Intent Definition" + policyIntent.getName()); + } + } + + if ( policyIntent.getDescription() != null && policyIntent.getDescription().length() > 0) { + writer.writeStartElement(PolicyConstants.SCA10_NS, DESCRIPTION); + writer.writeCData(policyIntent.getDescription()); + writer.writeEndElement(); + } + + writer.writeEndElement(); + } + + //FIXME This method is never used +// private Intent resolveRequiredIntents(ProfileIntent policyIntent, ModelResolver resolver) throws ContributionResolveException { +// boolean isUnresolved = false; +// //FIXME: Need to check for cyclic references first i.e an A requiring B and then B requiring A... +// if (policyIntent != null && policyIntent.isUnresolved()) { +// +// //resolve all required intents +// List requiredIntents = new ArrayList(); +// for (Intent requiredIntent : policyIntent.getRequiredIntents()) { +// if ( requiredIntent.isUnresolved() ) { +// //policyIntent.getRequiredIntents().remove(requiredIntent); +// requiredIntent = resolver.resolveModel(Intent.class, requiredIntent); +// requiredIntents.add(requiredIntent); +// if (requiredIntent.isUnresolved()) { +// isUnresolved = true; +// } +// } +// } +// policyIntent.getRequiredIntents().clear(); +// policyIntent.getRequiredIntents().addAll(requiredIntents); +// } +// policyIntent.setUnresolved(isUnresolved); +// +// return policyIntent; +// } + + //FIXME This method is never used +// private Intent resolveQualifiableIntent(QualifiedIntent policyIntent, ModelResolver resolver) throws ContributionResolveException { +// boolean isUnresolved = false; +// +// if (policyIntent != null && policyIntent.isUnresolved()) { +// //resolve the qualifiable intent +// Intent qualifiableIntent = +// resolver.resolveModel(Intent.class, policyIntent.getQualifiableIntent()); +// policyIntent.setQualifiableIntent(qualifiableIntent); +// isUnresolved = qualifiableIntent.isUnresolved(); +// } +// policyIntent.setUnresolved(isUnresolved); +// +// return policyIntent; +// } + + private void resolveContrainedArtifacts(Intent policyIntent, ModelResolver resolver) { + //FIXME : need to figure out this resolution. + policyIntent.setUnresolved(false); + } + + private void resolveProfileIntent(ProfileIntent policyIntent, ModelResolver resolver) + throws ContributionResolveException { + // FIXME: Need to check for cyclic references first i.e an A requiring B + // and then B requiring A... + if (policyIntent != null) { + // resolve all required intents + List requiredIntents = new ArrayList(); + for (Intent requiredIntent : policyIntent.getRequiredIntents()) { + if (requiredIntent.isUnresolved()) { + Intent resolvedRequiredIntent = resolver.resolveModel(Intent.class, requiredIntent); + if (resolvedRequiredIntent != null) { + requiredIntents.add(resolvedRequiredIntent); + } else { + throw new ContributionResolveException( + "Required Intent - " + requiredIntent + + " not found for ProfileIntent " + + policyIntent); + + } + } else { + requiredIntents.add(requiredIntent); + } + } + policyIntent.getRequiredIntents().clear(); + policyIntent.getRequiredIntents().addAll(requiredIntents); + } + } + + private void resolveQualifiedIntent(QualifiedIntent policyIntent, ModelResolver resolver) + throws ContributionResolveException { + if (policyIntent != null) { + //resolve the qualifiable intent + Intent qualifiableIntent = policyIntent.getQualifiableIntent(); + if (qualifiableIntent.isUnresolved()) { + Intent resolvedQualifiableIntent = resolver.resolveModel(Intent.class, qualifiableIntent); + + if (resolvedQualifiableIntent != null) { + policyIntent.setQualifiableIntent(resolvedQualifiableIntent); + } else { + throw new ContributionResolveException("Qualifiable Intent - " + qualifiableIntent + + " not found for QualifiedIntent " + + policyIntent); + } + + } + } + } + + public void resolve(T policyIntent, ModelResolver resolver) throws ContributionResolveException { + if (policyIntent instanceof ProfileIntent) { + resolveProfileIntent((ProfileIntent)policyIntent, resolver); + } + + if (policyIntent instanceof QualifiedIntent) { + resolveQualifiedIntent((QualifiedIntent)policyIntent, resolver); + } + + resolveContrainedArtifacts(policyIntent, resolver); + + if ( !policyIntent.isUnresolved() ) { + resolver.addModel(policyIntent); + } + } + + public QName getArtifactType() { + return POLICY_INTENT_QNAME; + } + + private void readConstrainedArtifacts(Intent policyIntent, XMLStreamReader reader) throws ContributionReadException { + String value = reader.getAttributeValue(null, CONSTRAINS); + if ( policyIntent instanceof QualifiedIntent && value != null) { + String errorMsg = + "Error in PolicyIntent Definition - " + policyIntent.getName() + QUALIFIED_INTENT_CONSTRAINS_ERROR; + throw new ContributionReadException(errorMsg); + } else { + if (value != null) { + List constrainedArtifacts = policyIntent.getConstrains(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + constrainedArtifacts.add(qname); + } + } + } + } + + private void readRequiredIntents(ProfileIntent policyIntent, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, REQUIRES); + if (value != null) { + List requiredIntents = policyIntent.getRequiredIntents(); + for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) { + QName qname = getQNameValue(reader, tokens.nextToken()); + Intent intent = policyFactory.createIntent(); + intent.setName(qname); + intent.setUnresolved(true); + requiredIntents.add(intent); + } + } + } + +} diff --git a/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java new file mode 100644 index 0000000000..cf58964a89 --- /dev/null +++ b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java @@ -0,0 +1,479 @@ +/* + * 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.Hashtable; +import java.util.List; +import java.util.Map; +import java.util.StringTokenizer; + +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 javax.xml.xpath.XPath; +import javax.xml.xpath.XPathExpressionException; +import javax.xml.xpath.XPathFactory; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMElement; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.om.OMNamespace; +import org.apache.neethi.Policy; +import org.apache.neethi.PolicyEngine; +import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.resolver.ModelResolver; +import org.apache.tuscany.sca.contribution.service.ContributionReadException; +import org.apache.tuscany.sca.contribution.service.ContributionResolveException; +import org.apache.tuscany.sca.contribution.service.ContributionWriteException; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.PolicySet; + + +/** + * Processor for handling XML models of PolicySet definitions + */ +public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor, PolicyConstants { + + private PolicyFactory policyFactory; + private StAXArtifactProcessor extensionProcessor; + // private XPathFactory xpathFactory = XPathFactory.newInstance(); + + public PolicySetProcessor(ModelFactoryExtensionPoint modelFactories) { + this.policyFactory = modelFactories.getFactory(PolicyFactory.class); + } + + public PolicySetProcessor(PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) { + this.policyFactory = policyFactory; + this.extensionProcessor = extensionProcessor; + } + + public PolicySet read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { + throw new IllegalArgumentException("not implemented in Android"); + /*String policySetName = reader.getAttributeValue(null, NAME); + + PolicySet policySet = policyFactory.createPolicySet(); + policySet.setName(new QName(policySetName)); + String appliesTo = reader.getAttributeValue(null, APPLIES_TO); + String alwaysAppliesTo = reader.getAttributeValue(TUSCANY_NS, ALWAYS_APPLIES_TO); + + //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; + } + + if ( alwaysAppliesTo != null && !alwaysAppliesTo.startsWith("/") ) { + alwaysAppliesTo = "//" + alwaysAppliesTo; + } + + policySet.setAppliesTo(appliesTo); + policySet.setAlwaysAppliesTo(alwaysAppliesTo); + + XPath path = xpathFactory.newXPath(); + path.setNamespaceContext(reader.getNamespaceContext()); + try { + if (appliesTo != null) { + policySet.setAppliesToXPathExpression(path.compile(appliesTo)); + } + if (alwaysAppliesTo != null) { + policySet.setAlwaysAppliesToXPathExpression(path.compile(alwaysAppliesTo)); + } + } catch (XPathExpressionException e) { + throw new ContributionReadException(e); + } + + 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(); + mappedIntent.setName(getQName(reader, PROVIDES)); + if ( policySet.getProvidedIntents().contains(mappedIntent) ) { + readIntentMap(reader, policySet, mappedIntent); + } else { + throw new ContributionReadException("Intent Map provides for Intent not spcified as provided by parent PolicySet - " + policySetName); + } + } else if ( POLICY_SET_REFERENCE_QNAME.equals(name) ) { + PolicySet referredPolicySet = policyFactory.createPolicySet(); + referredPolicySet.setName(getQName(reader, NAME)); + policySet.getReferencedPolicySets().add(referredPolicySet); + } 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); + if ( extension != null ) { + policySet.getPolicies().add(extension); + } + } + break; + } + } + if ( event == END_ELEMENT ) { + if ( POLICY_SET_QNAME.equals(reader.getName()) ) { + break; + } + } + + //Read the next element + if (reader.hasNext()) { + reader.next(); + } + } + return policySet; + } + + + public void readIntentMap(XMLStreamReader reader, PolicySet policySet, Intent mappedIntent) throws ContributionReadException { + QName name = reader.getName(); + Map> mappedPolicies = policySet.getMappedPolicies(); + if ( POLICY_INTENT_MAP_QNAME.equals(name) ) { + //Intent mappedIntent = policyFactory.createIntent(); + //mappedIntent.setName(getQName(reader, PROVIDES)); + String defaultQualifier = getString(reader, DEFAULT); + + String qualifierName = null; + String qualfiedIntentName = null; + Intent qualifiedIntent = 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); + qualfiedIntentName = mappedIntent.getName().getLocalPart() + + QUALIFIER + qualifierName; + qualifiedIntent = policyFactory.createIntent(); + qualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(), + qualfiedIntentName)); + } else if ( POLICY_INTENT_MAP_QNAME.equals(name) ) { + QName providedIntent = getQName(reader, PROVIDES); + if ( qualifierName.equals(providedIntent.getLocalPart()) ) { + readIntentMap(reader, policySet, qualifiedIntent); + } else { + throw new ContributionReadException("Intent provided by IntentMap " + + providedIntent + " does not match parent qualifier " + qualifierName + + " in policyset - " + policySet); + } + } else if ( WS_POLICY_QNAME.equals(name) ) { + OMElement policyElement = loadElement(reader); + Policy wsPolicy = PolicyEngine.getPolicy(policyElement); + policySet.getPolicies().add(wsPolicy); + + List policyList = mappedPolicies.get(qualifiedIntent); + if ( policyList == null ) { + policyList = new ArrayList(); + mappedPolicies.put(qualifiedIntent, policyList); + + if (qualifierName.equals(defaultQualifier)) { + mappedPolicies.put(mappedIntent, policyList); + } + } + policyList.add((Policy)wsPolicy); + } else { + Object extension = extensionProcessor.read(reader); + if ( extension != null ) { + List policyList = mappedPolicies.get(qualifiedIntent); + if ( policyList == null ) { + policyList = new ArrayList(); + mappedPolicies.put(qualifiedIntent, policyList); + + if (qualifierName.equals(defaultQualifier)) { + mappedPolicies.put(mappedIntent, policyList); + } + } + policyList.add(extension); + } + } + break; + } + case END_ELEMENT : { + if ( POLICY_INTENT_MAP_QNAME.equals(reader.getName()) ) { + if ( defaultQualifier != null ) { + String qualifiedIntentName = mappedIntent.getName().getLocalPart() + QUALIFIER + defaultQualifier; + Intent defaultQualifiedIntent = policyFactory.createIntent(); + defaultQualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(), + qualifiedIntentName)); + List policyList = mappedPolicies.get(defaultQualifiedIntent); + if ( policyList != null ) { + mappedPolicies.put(mappedIntent, policyList); + } else { + throw new ContributionReadException("Unable to map policies for default qualifier in IntentMap for - " + + mappedIntent + " in policy set - " + policySet); + } + defaultQualifier = null; + } + } + 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) { + throw new ContributionReadException(e); + } + }*/ + } + + public void write(PolicySet policySet, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + // Write an + writer.writeStartElement(SCA10_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(TUSCANY_NS, ALWAYS_APPLIES_TO, policySet.getAlwaysAppliesTo()); + + writeProvidedIntents(policySet, writer); + + writer.writeEndElement(); + } + + private void readProvidedIntents(PolicySet policySet, XMLStreamReader reader) { + String value = reader.getAttributeValue(null, PROVIDES); + if (value != null) { + List 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() != null && + policySet.getProvidedIntents().size() > 0) { + StringBuffer sb = new StringBuffer(); + for (Intent providedIntents : policySet.getProvidedIntents()) { + sb.append(providedIntents.getName()); + sb.append(" "); + } + writer.writeAttribute(PolicyConstants.PROVIDES, sb.toString()); + } + } + + private void resolvePolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { + boolean unresolved = false; + for ( Object o : policySet.getPolicies() ) { + extensionProcessor.resolve(o, resolver); + /*if ( o instanceof Policy && ((Policy)o).isUnresolved() ) { + unresolved = true; + }*/ + } + policySet.setUnresolved(unresolved); + } + + + + public QName getArtifactType() { + return POLICY_SET_QNAME; + } + + public Class getModelType() { + return PolicySet.class; + } + + private OMElement loadElement(XMLStreamReader reader) throws XMLStreamException { + OMFactory fac = OMAbstractFactory.getOMFactory(); + OMElement head = fac.createOMElement(reader.getName()); + OMElement current = head; + + while (true) { + switch (reader.next()) { + case XMLStreamConstants.START_ELEMENT: + QName name = reader.getName(); + OMElement child = fac.createOMElement(name, current); + + int count = reader.getNamespaceCount(); + for (int i = 0; i < count; i++) { + String prefix = reader.getNamespacePrefix(i); + String ns = reader.getNamespaceURI(i); + child.declareNamespace(ns, prefix); + } + + if(!"".equals(name.getNamespaceURI())) { + child.declareNamespace(name.getNamespaceURI(), name.getPrefix()); + } + + // add the attributes for this element + count = reader.getAttributeCount(); + for (int i = 0; i < count; i++) { + OMNamespace omNs = null; + String ns = reader.getAttributeNamespace(i); + String prefix = reader.getAttributePrefix(i); + String qname = reader.getAttributeLocalName(i); + String value = reader.getAttributeValue(i); + + if ( ns != null ) { + omNs = fac.createOMNamespace(ns, prefix); + } + + child.addAttribute(qname, value, omNs); + if (ns != null) { + child.declareNamespace(ns, prefix); + } + } + current = child; + break; + case XMLStreamConstants.CDATA: + fac.createOMText(current, reader.getText()); + break; + case XMLStreamConstants.CHARACTERS: + fac.createOMText(current, reader.getText()); + break; + case XMLStreamConstants.END_ELEMENT: + if ( current == head ) { + return head; + } else { + current = (OMElement)current.getParent(); + } + } + } + } + + private void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { + if (policySet != null) { + //resolve all provided intents + List providedIntents = new ArrayList(); + for (Intent providedIntent : policySet.getProvidedIntents()) { + if (providedIntent.isUnresolved()) { + Intent resolvedProvidedIntent = resolver.resolveModel(Intent.class, providedIntent); + if (resolvedProvidedIntent != null) { + providedIntents.add(resolvedProvidedIntent); + } else { + 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) throws ContributionResolveException { + Map> mappedPolicies = new Hashtable>(); + for (Map.Entry> entry : policySet.getMappedPolicies().entrySet()) { + Intent mappedIntent = entry.getKey(); + if (mappedIntent.isUnresolved()) { + Intent resolvedMappedIntent = resolver.resolveModel(Intent.class, mappedIntent); + + if (resolvedMappedIntent != null) { + mappedPolicies.put(resolvedMappedIntent, entry.getValue()); + } else { + throw new ContributionResolveException("Mapped Intent - " + mappedIntent + + " not found for PolicySet " + + policySet); + + } + } else { + mappedPolicies.put(mappedIntent, entry.getValue()); + } + } + + policySet.getMappedPolicies().clear(); + policySet.getMappedPolicies().putAll(mappedPolicies); + } + + private void resolveReferredPolicySets(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { + + List referredPolicySets = new ArrayList(); + for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { + if (referredPolicySet.isUnresolved()) { + PolicySet resolvedReferredPolicySet = resolver.resolveModel(PolicySet.class, referredPolicySet); + if (resolvedReferredPolicySet != null) { + referredPolicySets.add(resolvedReferredPolicySet); + } else { + 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.getMappedPolicies().putAll(referredPolicySet.getMappedPolicies()); + } + + public void resolve(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { + resolveProvidedIntents(policySet, resolver); + resolveIntentsInMappedPolicies(policySet, resolver); + resolveReferredPolicySets(policySet, resolver); + + for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { + includeReferredPolicySets(policySet, referredPolicySet); + } + + if ( policySet.isUnresolved() ) { + //resolve the policy attachments + resolvePolicies(policySet, resolver); + + if ( !policySet.isUnresolved() ) { + resolver.addModel(policySet); + } + } + } + } diff --git a/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java new file mode 100644 index 0000000000..4ad09baf55 --- /dev/null +++ b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java @@ -0,0 +1,38 @@ +/* + * 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 org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.ProfileIntent; + +/** + * Processor for handling XML models of PolicyIntent definitions that are ProfileIntents + */ +public class ProfileIntentProcessor extends PolicyIntentProcessor { + + public ProfileIntentProcessor(PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) { + super(policyFactory, extensionProcessor); + } + + public Class getModelType() { + return ProfileIntent.class; + } +} diff --git a/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java new file mode 100644 index 0000000000..cf4eef074f --- /dev/null +++ b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java @@ -0,0 +1,43 @@ +/* + * 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 org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.policy.PolicyFactory; +import org.apache.tuscany.sca.policy.QualifiedIntent; + +/* + * Processor for handling XML models of PolicyIntent definitions that are QualifiedIntents + */ +public class QualifiedIntentProcessor extends PolicyIntentProcessor { + + public QualifiedIntentProcessor(ModelFactoryExtensionPoint modelFactories) { + super(modelFactories.getFactory(PolicyFactory.class), null); + } + + public QualifiedIntentProcessor(PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) { + super(policyFactory, extensionProcessor); + } + + public Class getModelType() { + return QualifiedIntent.class; + } +} diff --git a/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java new file mode 100644 index 0000000000..1977e544c4 --- /dev/null +++ b/branches/sca-android/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/SimpleIntentProcessor.java @@ -0,0 +1,38 @@ +/* + * 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 org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.policy.Intent; +import org.apache.tuscany.sca.policy.PolicyFactory; + +/* + * Processor for handling XML models of PolicyIntent definitions + */ +public class SimpleIntentProcessor extends PolicyIntentProcessor { + + public SimpleIntentProcessor(PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) { + super(policyFactory, extensionProcessor); + } + + public Class getModelType() { + return Intent.class; + } +} -- cgit v1.2.3