From c9dbd184c6731e08baf3575a3e66e34993760b23 Mon Sep 17 00:00:00 2001 From: rfeng Date: Tue, 21 Oct 2008 20:31:48 +0000 Subject: Format the code git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@706758 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca/policy/xml/BindingTypeProcessor.java | 26 +- .../policy/xml/ImplementationTypeProcessor.java | 28 +- .../policy/xml/IntentAttachPointTypeProcessor.java | 133 +++++---- .../tuscany/sca/policy/xml/PolicyConstants.java | 14 +- .../sca/policy/xml/PolicyIntentProcessor.java | 207 +++++++------- .../tuscany/sca/policy/xml/PolicySetProcessor.java | 314 +++++++++++---------- .../sca/policy/xml/ProfileIntentProcessor.java | 2 +- .../sca/policy/xml/QualifiedIntentProcessor.java | 4 +- 8 files changed, 378 insertions(+), 350 deletions(-) (limited to 'branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany') diff --git a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java index a91a021c6a..ae6805c832 100644 --- a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java +++ b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/BindingTypeProcessor.java @@ -31,7 +31,6 @@ 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 * @@ -39,30 +38,33 @@ import org.apache.tuscany.sca.policy.impl.BindingTypeImpl; */ public class BindingTypeProcessor extends IntentAttachPointTypeProcessor { - public BindingTypeProcessor(PolicyFactory policyFactory, IntentAttachPointTypeFactory intentAttachPointTypeFactory, - StAXArtifactProcessor extensionProcessor, Monitor monitor) { + public BindingTypeProcessor(PolicyFactory policyFactory, + IntentAttachPointTypeFactory intentAttachPointTypeFactory, + StAXArtifactProcessor extensionProcessor, + Monitor monitor) { super(policyFactory, intentAttachPointTypeFactory, extensionProcessor, monitor); } - public BindingTypeProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor extensionProcessor, - Monitor monitor) { - super(modelFactories.getFactory(PolicyFactory.class), - modelFactories.getFactory(IntentAttachPointTypeFactory.class), extensionProcessor, monitor); + public BindingTypeProcessor(FactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + Monitor monitor) { + super(modelFactories.getFactory(PolicyFactory.class), modelFactories + .getFactory(IntentAttachPointTypeFactory.class), extensionProcessor, monitor); } public QName getArtifactType() { return BINDING_TYPE_QNAME; } - + @Override - protected IntentAttachPointType resolveExtensionType(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException { - if ( extnType instanceof BindingTypeImpl ) { + 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-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java index a794d7cf91..e405da21c7 100644 --- a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java +++ b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ImplementationTypeProcessor.java @@ -31,38 +31,40 @@ 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 * * @version $Rev$ $Date$ */ public class ImplementationTypeProcessor extends IntentAttachPointTypeProcessor { - - public ImplementationTypeProcessor(PolicyFactory policyFactory, IntentAttachPointTypeFactory intentAttachPointTypeFactory, - StAXArtifactProcessor extensionProcessor, Monitor monitor) { + + public ImplementationTypeProcessor(PolicyFactory policyFactory, + IntentAttachPointTypeFactory intentAttachPointTypeFactory, + StAXArtifactProcessor extensionProcessor, + Monitor monitor) { super(policyFactory, intentAttachPointTypeFactory, extensionProcessor, monitor); } - public ImplementationTypeProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor extensionProcessor, - Monitor monitor) { - super(modelFactories.getFactory(PolicyFactory.class), - modelFactories.getFactory(IntentAttachPointTypeFactory.class), extensionProcessor, monitor); + public ImplementationTypeProcessor(FactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + Monitor monitor) { + super(modelFactories.getFactory(PolicyFactory.class), modelFactories + .getFactory(IntentAttachPointTypeFactory.class), extensionProcessor, monitor); } public QName getArtifactType() { return IMPLEMENTATION_TYPE_QNAME; } - + @Override - protected IntentAttachPointType resolveExtensionType(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException { - if ( extnType instanceof ImplementationTypeImpl ) { + 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-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java index 3ad17c8404..a85ef28572 100644 --- a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java +++ b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/IntentAttachPointTypeProcessor.java @@ -37,7 +37,6 @@ 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.monitor.impl.ProblemImpl; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.IntentAttachPointType; import org.apache.tuscany.sca.policy.IntentAttachPointTypeFactory; @@ -45,29 +44,30 @@ 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 * * @version $Rev$ $Date$ */ -abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor, PolicyConstants { +abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor implements + StAXArtifactProcessor, PolicyConstants { private IntentAttachPointTypeFactory attachPointTypeFactory; private PolicyFactory policyFactory; private Monitor monitor; - - protected abstract IntentAttachPointType resolveExtensionType(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException; - public IntentAttachPointTypeProcessor(PolicyFactory policyFactory, - IntentAttachPointTypeFactory attachPointTypeFactory, - StAXArtifactProcessor extensionProcessor, - Monitor monitor) { + protected abstract IntentAttachPointType resolveExtensionType(IntentAttachPointType extnType, ModelResolver resolver) + throws ContributionResolveException; + + public IntentAttachPointTypeProcessor(PolicyFactory policyFactory, + IntentAttachPointTypeFactory attachPointTypeFactory, + StAXArtifactProcessor extensionProcessor, + Monitor monitor) { this.policyFactory = policyFactory; this.attachPointTypeFactory = attachPointTypeFactory; this.monitor = monitor; } - + /** * Report a error. * @@ -76,41 +76,47 @@ abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor * @param model */ private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "policy-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "policy-xml-validation-messages", + Severity.ERROR, + model, + message, + (Object[])messageParameters); + monitor.problem(problem); + } } - + public IntentAttachPointType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { QName type = getQName(reader, TYPE); - - if ( type != null ) { - if ( type.getLocalPart().startsWith(BINDING) ) { + + 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) ) { + 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 { - error("UnrecognizedIntentAttachPointType", reader, type); + error("UnrecognizedIntentAttachPointType", reader, type); //throw new ContributionReadException("Unrecognized IntentAttachPointType - " + type); } } else { - error("RequiredAttributeMissing", reader, TYPE); + error("RequiredAttributeMissing", reader, TYPE); //throw new ContributionReadException("Required attribute '" + TYPE + - //"' missing from BindingType Definition"); - } + //"' missing from BindingType Definition"); + } return null; } @@ -126,7 +132,7 @@ abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor } } } - + private void readMayProvideIntents(IntentAttachPointType extnType, XMLStreamReader reader) { String value = reader.getAttributeValue(null, MAY_PROVIDE); if (value != null) { @@ -139,61 +145,64 @@ abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor } } } - - public void write(IntentAttachPointType extnType, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + public void write(IntentAttachPointType extnType, XMLStreamWriter writer) throws ContributionWriteException, + XMLStreamException { // Write an - if ( extnType instanceof BindingTypeImpl ) { + if (extnType instanceof BindingTypeImpl) { writer.writeStartElement(SCA10_NS, BINDING_TYPE); - } else if ( extnType instanceof ImplementationTypeImpl ) { + } 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() ) { + + 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 ) { + + 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() ) { + + 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 ) { + + if (sb.length() > 0) { writer.writeAttribute(ALWAYS_PROVIDES, sb.toString()); - + } } - + public void resolve(IntentAttachPointType extnType, ModelResolver resolver) throws ContributionResolveException { - - if (extnType != null && extnType.isUnresolved()) { - resolveAlwaysProvidedIntents(extnType, resolver); + + if (extnType != null && extnType.isUnresolved()) { + resolveAlwaysProvidedIntents(extnType, resolver); resolveMayProvideIntents(extnType, resolver); extnType.setUnresolved(false); //resolveExtensionType(extnType, resolver); } } - private void resolveAlwaysProvidedIntents(IntentAttachPointType extensionType, - ModelResolver resolver) throws ContributionResolveException { + private void resolveAlwaysProvidedIntents(IntentAttachPointType extensionType, ModelResolver resolver) + throws ContributionResolveException { if (extensionType != null) { // resolve all provided intents List alwaysProvided = new ArrayList(); @@ -203,10 +212,10 @@ abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor if (!providedIntent.isUnresolved()) { alwaysProvided.add(providedIntent); } else { - error("AlwaysProvidedIntentNotFound", resolver, providedIntent, extensionType); + error("AlwaysProvidedIntentNotFound", resolver, providedIntent, extensionType); //throw new ContributionResolveException("Always Provided Intent - " + providedIntent - //+ " not found for ExtensionType " - //+ extensionType); + //+ " not found for ExtensionType " + //+ extensionType); } } else { alwaysProvided.add(providedIntent); @@ -216,9 +225,9 @@ abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor extensionType.getAlwaysProvidedIntents().addAll(alwaysProvided); } } - - private void resolveMayProvideIntents(IntentAttachPointType extensionType, - ModelResolver resolver) throws ContributionResolveException { + + private void resolveMayProvideIntents(IntentAttachPointType extensionType, ModelResolver resolver) + throws ContributionResolveException { if (extensionType != null) { // resolve all provided intents List mayProvide = new ArrayList(); @@ -228,10 +237,10 @@ abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor if (!providedIntent.isUnresolved()) { mayProvide.add(providedIntent); } else { - error("MayProvideIntentNotFound", resolver, providedIntent, extensionType); + error("MayProvideIntentNotFound", resolver, providedIntent, extensionType); //throw new ContributionResolveException("May Provide Intent - " + providedIntent - //+ " not found for ExtensionType " - //+ extensionType); + //+ " not found for ExtensionType " + //+ extensionType); } } else { mayProvide.add(providedIntent); @@ -241,7 +250,7 @@ abstract class IntentAttachPointTypeProcessor extends BaseStAXArtifactProcessor extensionType.getMayProvideIntents().addAll(mayProvide); } } - + public Class getModelType() { return IntentAttachPointType.class; } diff --git a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java index 3f1008e9a8..3f69df05d8 100644 --- a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java +++ b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyConstants.java @@ -47,7 +47,7 @@ public interface PolicyConstants { String REQUIRES = "requires"; String EXCLUDES = "excludes"; String DEFAULT = "default"; - + String ALWAYS_PROVIDES = "alwaysProvides"; String MAY_PROVIDE = "mayProvide"; String TYPE = "type"; @@ -57,19 +57,15 @@ public interface PolicyConstants { 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 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); - + String QUALIFIED_INTENT_CONSTRAINS_ERROR = " - Qualified Intents must not specify 'constrains' attribute"; - - - - - + } diff --git a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java index 78a59a7276..03cd635596 100644 --- a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java +++ b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicyIntentProcessor.java @@ -41,7 +41,6 @@ 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.monitor.impl.ProblemImpl; import org.apache.tuscany.sca.policy.Intent; import org.apache.tuscany.sca.policy.PolicyFactory; import org.apache.tuscany.sca.policy.ProfileIntent; @@ -52,7 +51,8 @@ import org.apache.tuscany.sca.policy.QualifiedIntent; * * @version $Rev$ $Date$ */ -abstract class PolicyIntentProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor, PolicyConstants { +abstract class PolicyIntentProcessor extends BaseStAXArtifactProcessor implements + StAXArtifactProcessor, PolicyConstants { private PolicyFactory policyFactory; private Monitor monitor; @@ -61,12 +61,12 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.monitor = monitor; } - + public PolicyIntentProcessor(PolicyFactory policyFactory, Monitor monitor) { this.policyFactory = policyFactory; this.monitor = monitor; } - + /** * Report a error. * @@ -75,10 +75,16 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP * @param model */ private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "policy-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "policy-xml-validation-messages", + Severity.ERROR, + model, + message, + (Object[])messageParameters); + monitor.problem(problem); + } } public T read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { @@ -88,31 +94,30 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP error("IntentNameMissing", reader); return (T)policyIntent; } - + // Read an if (reader.getAttributeValue(null, REQUIRES) != null) { policyIntent = policyFactory.createProfileIntent(); - } else if ( policyIntentName != null && policyIntentName.indexOf(QUALIFIER) != -1) { + } 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 ) { + + if (policyIntent instanceof ProfileIntent) { readRequiredIntents((ProfileIntent)policyIntent, reader); - } - else { + } else { readExcludedIntents(policyIntent, reader); } - + readConstrainedArtifacts(policyIntent, reader); int event = reader.getEventType(); @@ -120,7 +125,7 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP while (reader.hasNext()) { event = reader.getEventType(); switch (event) { - case START_ELEMENT : { + case START_ELEMENT: { name = reader.getName(); if (DESCRIPTION_QNAME.equals(name)) { policyIntent.setDescription(reader.getElementText()); @@ -131,7 +136,7 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP if (event == END_ELEMENT && POLICY_INTENT_QNAME.equals(reader.getName())) { break; } - + //Read the next element if (reader.hasNext()) { reader.next(); @@ -139,17 +144,16 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP } 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()); + 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) { + if (profileIntent.getRequiredIntents() != null && profileIntent.getRequiredIntents().size() > 0) { StringBuffer sb = new StringBuffer(); for (Intent requiredIntents : profileIntent.getRequiredIntents()) { sb.append(requiredIntents.getName()); @@ -157,10 +161,8 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP } writer.writeAttribute(PolicyConstants.REQUIRES, sb.toString()); } - } - else { - if (policyIntent.getExcludedIntents() != null && - policyIntent.getExcludedIntents().size() > 0) { + } else { + if (policyIntent.getExcludedIntents() != null && policyIntent.getExcludedIntents().size() > 0) { StringBuffer sb = new StringBuffer(); for (Intent excludedIntents : policyIntent.getExcludedIntents()) { sb.append(excludedIntents.getName()); @@ -169,10 +171,9 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP writer.writeAttribute(PolicyConstants.EXCLUDES, sb.toString()); } } - - if (!(policyIntent instanceof QualifiedIntent) ) { - if (policyIntent.getConstrains() != null && - policyIntent.getConstrains().size() > 0) { + + 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()); @@ -180,68 +181,68 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP } writer.writeAttribute(CONSTRAINS, sb.toString()); } else { - error("ContrainsAttributeMissing", policyIntent, policyIntent.getName()); + error("ContrainsAttributeMissing", policyIntent, policyIntent.getName()); //throw new ContributionWriteException("Contrains attribute missing from " + - //"Policy Intent Definition" + policyIntent.getName()); + //"Policy Intent Definition" + policyIntent.getName()); } } - - if ( policyIntent.getDescription() != null && policyIntent.getDescription().length() > 0) { + + 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; -// } - + // 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 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 @@ -264,14 +265,14 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP resolveDependent(resolvedRequiredIntent, resolver); } } - + if (!resolvedRequiredIntent.isUnresolved()) { requiredIntents.add(resolvedRequiredIntent); } else { - error("RequiredIntentNotFound", resolver, requiredIntent, policyIntent); - return; + error("RequiredIntentNotFound", resolver, requiredIntent, policyIntent); + return; //throw new ContributionResolveException("Required Intent - " + requiredIntent - //+ " not found for ProfileIntent " + policyIntent); + //+ " not found for ProfileIntent " + policyIntent); } } else { requiredIntents.add(requiredIntent); @@ -297,40 +298,39 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP resolveDependent(resolvedQualifiableIntent, resolver); } } - + if (!resolvedQualifiableIntent.isUnresolved()) { policyIntent.setQualifiableIntent(resolvedQualifiableIntent); } else { - error("QualifiableIntentNotFound", resolver, qualifiableIntent, policyIntent); + error("QualifiableIntentNotFound", resolver, qualifiableIntent, policyIntent); //throw new ContributionResolveException("Qualifiable Intent - " + qualifiableIntent - //+ " not found for QualifiedIntent " + policyIntent); - } + //+ " not found for QualifiedIntent " + policyIntent); + } } } } - + public void resolveDependent(Intent policyIntent, ModelResolver resolver) throws ContributionResolveException { if (policyIntent instanceof ProfileIntent) resolveProfileIntent((ProfileIntent)policyIntent, resolver); - + if (policyIntent instanceof QualifiedIntent) resolveQualifiedIntent((QualifiedIntent)policyIntent, resolver); - + resolveContrainedArtifacts(policyIntent, resolver); } - + public void resolve(T policyIntent, ModelResolver resolver) throws ContributionResolveException { if (policyIntent instanceof ProfileIntent) { resolveProfileIntent((ProfileIntent)policyIntent, resolver); - } - else { + } else { resolveExcludedIntents(policyIntent, resolver); } if (policyIntent instanceof QualifiedIntent) { resolveQualifiedIntent((QualifiedIntent)policyIntent, resolver); } - + resolveContrainedArtifacts(policyIntent, resolver); /* This is too late in the processing @@ -339,15 +339,18 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP } */ } - + 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) { - error("ErrorInPolicyIntentDefinition", policyIntent, policyIntent.getName(), QUALIFIED_INTENT_CONSTRAINS_ERROR); + if (policyIntent instanceof QualifiedIntent && value != null) { + error("ErrorInPolicyIntentDefinition", + policyIntent, + policyIntent.getName(), + QUALIFIED_INTENT_CONSTRAINS_ERROR); //String errorMsg = "Error in PolicyIntent Definition - " + policyIntent.getName() + QUALIFIED_INTENT_CONSTRAINS_ERROR; //throw new ContributionReadException(errorMsg); } else { @@ -360,7 +363,7 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP } } } - + private void readRequiredIntents(ProfileIntent policyIntent, XMLStreamReader reader) { String value = reader.getAttributeValue(null, REQUIRES); if (value != null) { @@ -396,14 +399,14 @@ abstract class PolicyIntentProcessor extends BaseStAXArtifactP List excludedIntents = new ArrayList(); for (Intent excludedIntent : policyIntent.getExcludedIntents()) { if (excludedIntent.isUnresolved()) { - Intent resolvedExcludedIntent = resolver.resolveModel(Intent.class, excludedIntent); + Intent resolvedExcludedIntent = resolver.resolveModel(Intent.class, excludedIntent); if (!resolvedExcludedIntent.isUnresolved()) { excludedIntents.add(resolvedExcludedIntent); } else { - error("ExcludedIntentNotFound", resolver, excludedIntent, policyIntent); - return; + error("ExcludedIntentNotFound", resolver, excludedIntent, policyIntent); + return; //throw new ContributionResolveException("Excluded Intent " + excludedIntent - //+ " not found for intent " + policyIntent); + //+ " not found for intent " + policyIntent); } } else { excludedIntents.add(excludedIntent); diff --git a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java index cf99b681ef..93a8433d65 100644 --- a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java +++ b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/PolicySetProcessor.java @@ -46,40 +46,39 @@ 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.monitor.impl.ProblemImpl; 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 * * @version $Rev$ $Date$ */ -public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor, PolicyConstants { +public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor, + PolicyConstants { private PolicyFactory policyFactory; private StAXArtifactProcessor extensionProcessor; private XPathFactory xpathFactory = XPathFactory.newInstance(); private Monitor monitor; - - public PolicySetProcessor(FactoryExtensionPoint modelFactories, - StAXArtifactProcessor extensionProcessor, - Monitor monitor) { + + public PolicySetProcessor(FactoryExtensionPoint modelFactories, + StAXArtifactProcessor extensionProcessor, + Monitor monitor) { this.policyFactory = modelFactories.getFactory(PolicyFactory.class); this.extensionProcessor = extensionProcessor; this.monitor = monitor; } - - public PolicySetProcessor(PolicyFactory policyFactory, - StAXArtifactProcessor extensionProcessor, - Monitor monitor) { + + public PolicySetProcessor(PolicyFactory policyFactory, + StAXArtifactProcessor extensionProcessor, + Monitor monitor) { this.policyFactory = policyFactory; this.extensionProcessor = extensionProcessor; this.monitor = monitor; } - + /** * Report a exception. * @@ -87,13 +86,19 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA * @param message * @param model */ - private void error(String message, Object model, Exception ex) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "policy-xml-validation-messages", Severity.ERROR, model, message, ex); - monitor.problem(problem); - } - } - + private void error(String message, Object model, Exception ex) { + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "policy-xml-validation-messages", + Severity.ERROR, + model, + message, + ex); + monitor.problem(problem); + } + } + /** * Report a error. * @@ -101,16 +106,22 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA * @param message * @param model */ - private void error(String message, Object model, Object... messageParameters) { - if (monitor != null) { - Problem problem = monitor.createProblem(this.getClass().getName(), "policy-xml-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters); - monitor.problem(problem); - } - } + private void error(String message, Object model, Object... messageParameters) { + if (monitor != null) { + Problem problem = + monitor.createProblem(this.getClass().getName(), + "policy-xml-validation-messages", + Severity.ERROR, + model, + message, + (Object[])messageParameters); + monitor.problem(problem); + } + } public PolicySet read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException { PolicySet policySet = null; - + String policySetName = reader.getAttributeValue(null, NAME); String appliesTo = reader.getAttributeValue(null, APPLIES_TO); if (policySetName == null || appliesTo == null) { @@ -120,27 +131,27 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA error("PolicySetAppliesToMissing", reader); return policySet; } - + policySet = policyFactory.createPolicySet(); policySet.setName(new QName(policySetName)); 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("/") ) { + if (appliesTo != null && !appliesTo.startsWith("/")) { appliesTo = "//" + appliesTo; } - - if ( alwaysAppliesTo != null && !alwaysAppliesTo.startsWith("/") ) { + + if (alwaysAppliesTo != null && !alwaysAppliesTo.startsWith("/")) { alwaysAppliesTo = "//" + alwaysAppliesTo; } - + policySet.setAppliesTo(appliesTo); policySet.setAlwaysAppliesTo(alwaysAppliesTo); - XPath path = xpathFactory.newXPath(); + XPath path = xpathFactory.newXPath(); path.setNamespaceContext(reader.getNamespaceContext()); try { if (appliesTo != null) { @@ -150,27 +161,27 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA policySet.setAlwaysAppliesToXPathExpression(path.compile(alwaysAppliesTo)); } } catch (XPathExpressionException e) { - ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", policySet, ce); + ContributionReadException ce = new ContributionReadException(e); + error("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 : { + case START_ELEMENT: { name = reader.getName(); - if ( POLICY_INTENT_MAP_QNAME.equals(name) ) { + 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) ) { + if (policySet.getProvidedIntents().contains(mappedIntent)) { readIntentMap(reader, policySet, mappedIntent); } else { error("IntentNotSpecified", policySet, policySetName); @@ -179,7 +190,7 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA } else { error("IntentMapProvidesMissing", reader, policySetName); } - } else if ( POLICY_SET_REFERENCE_QNAME.equals(name) ) { + } else if (POLICY_SET_REFERENCE_QNAME.equals(name)) { PolicySet referredPolicySet = policyFactory.createPolicySet(); String referencename = reader.getAttributeValue(null, NAME); if (referencename != null) { @@ -189,24 +200,24 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA error("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 { + 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 ) { + if (extension != null) { policySet.getPolicies().add(extension); } } break; } } - if ( event == END_ELEMENT ) { - if ( POLICY_SET_QNAME.equals(reader.getName()) ) { + if (event == END_ELEMENT) { + if (POLICY_SET_QNAME.equals(reader.getName())) { break; - } + } } - + //Read the next element if (reader.hasNext()) { reader.next(); @@ -214,72 +225,76 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA } return policySet; } - - - public void readIntentMap(XMLStreamReader reader, PolicySet policySet, Intent mappedIntent) throws ContributionReadException { + + 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) ) { + 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 : { + case START_ELEMENT: { name = reader.getName(); - if ( POLICY_INTENT_MAP_QUALIFIER_QNAME.equals(name)) { - qualifierName = getString(reader, NAME); + if (POLICY_INTENT_MAP_QUALIFIER_QNAME.equals(name)) { + qualifierName = getString(reader, NAME); if (qualifierName != null) { - qualfiedIntentName = mappedIntent.getName().getLocalPart() + - QUALIFIER + qualifierName; + qualfiedIntentName = + mappedIntent.getName().getLocalPart() + QUALIFIER + qualifierName; qualifiedIntent = policyFactory.createIntent(); qualifiedIntent.setName(new QName(mappedIntent.getName().getNamespaceURI(), - qualfiedIntentName)); + qualfiedIntentName)); } else { error("QualifierNameMissing", reader, policySet.getName()); } - } else if ( POLICY_INTENT_MAP_QNAME.equals(name) ) { + } else if (POLICY_INTENT_MAP_QNAME.equals(name)) { QName providedIntent = getQName(reader, PROVIDES); - if ( qualifierName.equals(providedIntent.getLocalPart()) ) { + if (qualifierName.equals(providedIntent.getLocalPart())) { readIntentMap(reader, policySet, qualifiedIntent); } else { - error("IntentMapDoesNotMatch", providedIntent, providedIntent, qualifierName, policySet); + error("IntentMapDoesNotMatch", + providedIntent, + providedIntent, + qualifierName, + policySet); //throw new ContributionReadException("Intent provided by IntentMap " + - //providedIntent + " does not match parent qualifier " + qualifierName + - //" in policyset - " + policySet); + //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 { + 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 && qualifiedIntent != null) { + if (extension != null && qualifiedIntent != null) { List policyList = mappedPolicies.get(qualifiedIntent); - if ( policyList == null ) { + if (policyList == null) { policyList = new ArrayList(); mappedPolicies.put(qualifiedIntent, policyList); - + if (qualifierName.equals(defaultQualifier)) { mappedPolicies.put(mappedIntent, policyList); } @@ -289,28 +304,29 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA } break; } - case END_ELEMENT : { - if ( POLICY_INTENT_MAP_QNAME.equals(reader.getName()) ) { - if ( defaultQualifier != null ) { - String qualifiedIntentName = mappedIntent.getName().getLocalPart() + QUALIFIER + defaultQualifier; + 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 ) { + if (policyList != null) { mappedPolicies.put(mappedIntent, policyList); } else { - error("UnableToMapPolicies", mappedPolicies, mappedIntent, policySet); + error("UnableToMapPolicies", mappedPolicies, mappedIntent, policySet); //throw new ContributionReadException("Unable to map policies for default qualifier in IntentMap for - " + - //mappedIntent + " in policy set - " + policySet); + //mappedIntent + " in policy set - " + policySet); } defaultQualifier = null; } - } + } break; } } - if ( event == END_ELEMENT && POLICY_INTENT_MAP_QNAME.equals(reader.getName()) ) { + if (event == END_ELEMENT && POLICY_INTENT_MAP_QNAME.equals(reader.getName())) { break; } //Read the next element @@ -318,29 +334,29 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA reader.next(); } } - } catch (XMLStreamException e) { - ContributionReadException ce = new ContributionReadException(e); - error("ContributionReadException", reader, ce); + } catch (XMLStreamException e) { + ContributionReadException ce = new ContributionReadException(e); + error("ContributionReadException", reader, ce); throw ce; } } } - - public void write(PolicySet policySet, XMLStreamWriter writer) throws ContributionWriteException, XMLStreamException { + + 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(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) { @@ -353,10 +369,9 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA } } } - + private void writeProvidedIntents(PolicySet policySet, XMLStreamWriter writer) throws XMLStreamException { - if (policySet.getProvidedIntents() != null && - policySet.getProvidedIntents().size() > 0) { + if (policySet.getProvidedIntents() != null && policySet.getProvidedIntents().size() > 0) { StringBuffer sb = new StringBuffer(); for (Intent providedIntents : policySet.getProvidedIntents()) { sb.append(providedIntents.getName()); @@ -366,30 +381,29 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA } } - private void resolvePolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { - boolean unresolved = false; - if (policySet != null) { - for ( Object o : policySet.getPolicies() ) { - extensionProcessor.resolve(o, resolver); - /*if ( o instanceof Policy && ((Policy)o).isUnresolved() ) { - unresolved = true; - }*/ - } - policySet.setUnresolved(unresolved); - } - } - - - + private void resolvePolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { + boolean unresolved = false; + if (policySet != null) { + 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 void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { + + private void resolveProvidedIntents(PolicySet policySet, ModelResolver resolver) + throws ContributionResolveException { if (policySet != null) { //resolve all provided intents List providedIntents = new ArrayList(); @@ -399,10 +413,10 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA if (!resolvedProvidedIntent.isUnresolved()) { providedIntents.add(resolvedProvidedIntent); } else { - error("ProvidedIntentNotFound", policySet, providedIntent, policySet); - return; + error("ProvidedIntentNotFound", policySet, providedIntent, policySet); + return; //throw new ContributionResolveException("Provided Intent - " + providedIntent - //+ " not found for PolicySet " + policySet); + //+ " not found for PolicySet " + policySet); } } else { providedIntents.add(providedIntent); @@ -411,9 +425,10 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA policySet.getProvidedIntents().clear(); policySet.getProvidedIntents().addAll(providedIntents); } - } - - private void resolveIntentsInMappedPolicies(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { + } + + private void resolveIntentsInMappedPolicies(PolicySet policySet, ModelResolver resolver) + throws ContributionResolveException { Map> mappedPolicies = new Hashtable>(); for (Map.Entry> entry : policySet.getMappedPolicies().entrySet()) { Intent mappedIntent = entry.getKey(); @@ -422,10 +437,10 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA if (!resolvedMappedIntent.isUnresolved()) { mappedPolicies.put(resolvedMappedIntent, entry.getValue()); } else { - error("MappedIntentNotFound", policySet, mappedIntent, policySet); - return; + error("MappedIntentNotFound", policySet, mappedIntent, policySet); + return; //throw new ContributionResolveException("Mapped Intent - " + mappedIntent - //+ " not found for PolicySet " + policySet); + //+ " not found for PolicySet " + policySet); } } else { mappedPolicies.put(mappedIntent, entry.getValue()); @@ -435,9 +450,10 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA policySet.getMappedPolicies().clear(); policySet.getMappedPolicies().putAll(mappedPolicies); } - - private void resolveReferredPolicySets(PolicySet policySet, ModelResolver resolver) throws ContributionResolveException { - + + private void resolveReferredPolicySets(PolicySet policySet, ModelResolver resolver) + throws ContributionResolveException { + List referredPolicySets = new ArrayList(); for (PolicySet referredPolicySet : policySet.getReferencedPolicySets()) { if (referredPolicySet.isUnresolved()) { @@ -445,10 +461,10 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA if (!resolvedReferredPolicySet.isUnresolved()) { referredPolicySets.add(resolvedReferredPolicySet); } else { - error("ReferredPolicySetNotFound", policySet, referredPolicySet, policySet); - return; + error("ReferredPolicySetNotFound", policySet, referredPolicySet, policySet); + return; //throw new ContributionResolveException("Referred PolicySet - " + referredPolicySet - //+ "not found for PolicySet - " + policySet); + //+ "not found for PolicySet - " + policySet); } } else { referredPolicySets.add(referredPolicySet); @@ -457,7 +473,7 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA policySet.getReferencedPolicySets().clear(); policySet.getReferencedPolicySets().addAll(referredPolicySets); } - + private void includeReferredPolicySets(PolicySet policySet, PolicySet referredPolicySet) { for (PolicySet furtherReferredPolicySet : referredPolicySet.getReferencedPolicySets()) { includeReferredPolicySets(referredPolicySet, furtherReferredPolicySet); @@ -465,23 +481,23 @@ public class PolicySetProcessor extends BaseStAXArtifactProcessor implements StA 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() ) { + + if (policySet.isUnresolved()) { //resolve the policy attachments resolvePolicies(policySet, resolver); - + /*if ( !policySet.isUnresolved() ) { resolver.addModel(policySet); }*/ } - } - } + } +} diff --git a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java index 656107b470..d0b19af129 100644 --- a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java +++ b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/ProfileIntentProcessor.java @@ -34,7 +34,7 @@ public class ProfileIntentProcessor extends PolicyIntentProcessor public ProfileIntentProcessor(PolicyFactory policyFactory, Monitor monitor) { super(policyFactory, monitor); } - + public ProfileIntentProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { super(modelFactories, monitor); } diff --git a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java index 7270dbe6db..50d8cb06e2 100644 --- a/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java +++ b/branches/sca-equinox/modules/policy-xml/src/main/java/org/apache/tuscany/sca/policy/xml/QualifiedIntentProcessor.java @@ -30,11 +30,11 @@ import org.apache.tuscany.sca.policy.QualifiedIntent; * @version $Rev$ $Date$ */ public class QualifiedIntentProcessor extends PolicyIntentProcessor { - + public QualifiedIntentProcessor(FactoryExtensionPoint modelFactories, Monitor monitor) { super(modelFactories, monitor); } - + public QualifiedIntentProcessor(PolicyFactory policyFactory, Monitor monitor) { super(policyFactory, monitor); } -- cgit v1.2.3