}
public PolicySet read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
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);