use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class AttributeImpl method processElement.
private void processElement(Element element) throws XACMLException {
String value = null;
if (element == null) {
XACMLSDKUtils.debug.error("AttributeImpl.processElement(): invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
// First check that we're really parsing an Attribute
if (!element.getLocalName().equals(XACMLConstants.ATTRIBUTE)) {
XACMLSDKUtils.debug.error("AttributeImpl.processElement(): invalid root element");
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("invalid_element"));
}
NamedNodeMap attrs = element.getAttributes();
try {
id = new URI(attrs.getNamedItem(XACMLConstants.ATTRIBUTE_ID).getNodeValue());
} catch (Exception e) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("attribute_not_uri"));
}
if (id == null) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_attribute"));
}
try {
type = new URI(attrs.getNamedItem(XACMLConstants.DATATYPE).getNodeValue());
} catch (Exception e) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("attribute_not_uri"));
}
if (type == null) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_attribute"));
}
try {
Node issuerNode = attrs.getNamedItem(XACMLConstants.ISSUER);
if (issuerNode != null)
issuer = issuerNode.getNodeValue();
} catch (Exception e) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("attribute_parsing_error"));
}
// now we get the attribute value
NodeList nodes = element.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
Node node = nodes.item(i);
if ((node.getNodeType() == Node.ELEMENT_NODE) || (node.getNodeType() == Node.ATTRIBUTE_NODE)) {
if (node.getLocalName().equals(XACMLConstants.ATTRIBUTE_VALUE)) {
if (values == null) {
values = new ArrayList();
}
values.add(node);
}
}
}
// make sure we got a value
if (values == null || values.isEmpty()) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("missing_attribute_value"));
}
}
use of com.sun.identity.xacml.common.XACMLException in project OpenAM by OpenRock.
the class AttributeImpl method setAttributeStringValues.
/**
* Sets the attribute values for this object
*
* @param stringValues a <code>List</code> containing
* <code>String<code> values of this object.
* @throws XACMLException if the object is immutable
* An object is considered <code>immutable</code> if <code>
* makeImmutable()</code> has been invoked on it. It can
* be determined by calling <code>isMutable</code> on the object.
*/
public void setAttributeStringValues(List stringValues) throws XACMLException {
if (!isMutable) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("objectImmutable"));
}
if (this.values == null) {
this.values = new ArrayList();
}
if (stringValues == null || stringValues.isEmpty()) {
throw new XACMLException(XACMLSDKUtils.xacmlResourceBundle.getString("null_not_valid"));
}
for (int i = 0; i < stringValues.size(); i++) {
String value = (String) (stringValues.get(i));
StringBuffer sb = new StringBuffer(200);
sb.append("<").append(XACMLConstants.ATTRIBUTE_VALUE).append(">").append(value).append("</").append(XACMLConstants.ATTRIBUTE_VALUE).append(">\n");
Document document = XMLUtils.toDOMDocument(sb.toString(), XACMLSDKUtils.debug);
Element element = null;
if (document != null) {
element = document.getDocumentElement();
}
if (element != null) {
this.values.add(element);
}
}
}
Aggregations