PolicyReference is a wrapper that holds explict PolicyReferences.
| Method from org.apache.neethi.PolicyReference Detail: |
public boolean equal(PolicyComponent policyComponent) {
if (Constants.TYPE_POLICY_REF != policyComponent.getType()) {
return false;
}
String URI = ((PolicyReference) policyComponent).getURI();
if (URI != null && URI.length() != 0) {
return URI.equals(this.uri);
}
return false;
}
|
public OMElement getRemoteReferedElement(String uri) {
OMElement documentElement = null;
try{
//create java.net URL pointing to remote resource
URL url = new URL(uri);
URLConnection connection = url.openConnection();
connection.setDoInput(true);
//create stax parser with the url content
XMLStreamReader parser = XMLInputFactory.newInstance().
createXMLStreamReader(connection.getInputStream());
//get the root element (in this case the envelope)
StAXOMBuilder builder = new StAXOMBuilder(parser);
documentElement = builder.getDocumentElement();
}catch(XMLStreamException se){
throw new RuntimeException("Bad policy content: " + uri);
}catch(MalformedURLException mue){
throw new RuntimeException("Malformed uri: " + uri);
}catch(IOException ioe){
throw new RuntimeException("Cannot reach remote resource: " + uri);
}
return documentElement;
}
|
public Policy getRemoteReferencedPolicy(String uri) {
Policy policy = null;
//extract the remote resource contents
OMElement policyElement = getRemoteReferedElement(uri);
//call the policy engine with already extracted content
policy = PolicyEngine.getPolicy(policyElement);
return policy;
}
|
public short getType() {
return Constants.TYPE_POLICY_REF;
}
Returns short value of Constants.TYPE_POLICY_REF |
public String getURI() {
return uri;
}
Gets the Policy URI that is refered by self. |
public PolicyComponent normalize() {
throw new UnsupportedOperationException("PolicyReference.normalize() is meaningless");
}
Throws an UnsupportedOperationException since PolicyReference.normalize()
can't resolve the Policy that it refers to unless a PolicyRegistry is
provided. |
public PolicyComponent normalize(PolicyRegistry reg,
boolean deep) {
String key = getURI();
int pos = key.indexOf("#");
if (pos == 0) {
key = key.substring(1);
}else if(pos > 0){
key = key.substring(0, pos);
}
Policy policy = reg.lookup(key);
if (policy == null) {
policy = getRemoteReferencedPolicy(key);
if(policy == null){
throw new RuntimeException(key + " can't be resolved" );
}
reg.register(key, policy);
}
return policy.normalize(reg, deep);
}
Returns normalized version of the Policy that is refered by self. The specified
PolicyRegistry is used to lookup for the Policy that is refered and dee
indicates the level of normalization fo the returning Policy. |
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
String wspPrefix = writer.getPrefix(Constants.URI_POLICY_NS);
if (wspPrefix == null) {
wspPrefix = Constants.ATTR_WSP;
writer.setPrefix(wspPrefix, Constants.URI_POLICY_NS);
}
writer.writeStartElement(wspPrefix, Constants.ELEM_POLICY_REF, Constants.URI_POLICY_NS);
writer.writeNamespace(Constants.ATTR_WSP, Constants.URI_POLICY_NS);
writer.writeAttribute(Constants.ATTR_URI, getURI());
writer.writeEndElement();
}
|
public void setURI(String uri) {
this.uri = uri;
}
|