}
}
public PolicySet read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException,
XMLStreamException {
PolicySet policySet = null;
Monitor monitor = context.getMonitor();
String policySetName = reader.getAttributeValue(null, NAME);
String appliesTo = reader.getAttributeValue(null, APPLIES_TO);
if (policySetName == null || appliesTo == null) {
if (policySetName == null)
error(monitor, "PolicySetNameMissing", reader);
if (appliesTo == null)
error(monitor, "PolicySetAppliesToMissing", reader);
return policySet;
}
policySet = policyFactory.createPolicySet();
policySet.setName(new QName(policySetName));
//TODO: with 1.0 version of specs the applies to xpath is given related to the immediate
//parent whereas the runtime evaluates the xpath aginst the composite element. What the runtime
//is doing is what the future version of the specs could be tending towards. When that happens
//this 'if' must be deleted
if (appliesTo != null && !appliesTo.startsWith("/")) {
appliesTo = "//" + appliesTo;
}
policySet.setAppliesTo(appliesTo);
if (appliesTo != null) {
try {
XPath path = xpathHelper.newXPath();
NamespaceContext nsContext = xpathHelper.getNamespaceContext(appliesTo, reader.getNamespaceContext());
// path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(context));
XPathExpression expression = xpathHelper.compile(path, nsContext, appliesTo);
policySet.setAppliesToXPathExpression(expression);
} catch (XPathExpressionException e) {
ContributionReadException ce = new ContributionReadException(e);
error(monitor, "ContributionReadException", policySet, ce);
//throw ce;
}
}
String attachTo = reader.getAttributeValue(null, ATTACH_TO);
if (attachTo != null) {
try {
XPath path = xpathHelper.newXPath();
NamespaceContext nsContext = xpathHelper.getNamespaceContext(attachTo, reader.getNamespaceContext());
path.setXPathFunctionResolver(new PolicyXPathFunctionResolver(nsContext));
attachTo = PolicyXPathFunction.normalize(attachTo,getSCAPrefix(nsContext));
XPathExpression expression = xpathHelper.compile(path, nsContext, attachTo);
policySet.setAttachTo(attachTo);
policySet.setAttachToXPathExpression(expression);
} catch (XPathExpressionException e) {
ContributionReadException ce = new ContributionReadException(e);
error(monitor, "ContributionReadException", policySet, ce);
//throw ce;
}
}
readProvidedIntents(policySet, reader);
int event = reader.getEventType();
QName name = null;
reader.next();
while (reader.hasNext()) {
event = reader.getEventType();
switch (event) {
case START_ELEMENT: {
name = reader.getName();
if (POLICY_INTENT_MAP_QNAME.equals(name)) {
Intent mappedIntent = policyFactory.createIntent();
String provides = reader.getAttributeValue(null, PROVIDES);
if (provides != null) {
mappedIntent.setName(getQName(reader, PROVIDES));
if (policySet.getProvidedIntents().contains(mappedIntent)) {
readIntentMap(reader, policySet, mappedIntent, context);
} else {
error(monitor, "IntentNotSpecified", policySet, policySetName);
}
} else {
error(monitor, "IntentMapProvidesMissing", reader, policySetName);
}
} else if (POLICY_SET_REFERENCE_QNAME.equals(name)) {
PolicySet referredPolicySet = policyFactory.createPolicySet();
String referencename = reader.getAttributeValue(null, NAME);
if (referencename != null) {
referredPolicySet.setName(getQName(reader, NAME));
policySet.getReferencedPolicySets().add(referredPolicySet);
} else {
error(monitor, "PolicySetReferenceNameMissing", reader, policySetName);
}
} /*else if ( WS_POLICY_QNAME.equals(name) ) {