* Recursively parses the policy where the root is the given element
* @param element The current element
* @return The policy created
*/
private Policy parsePolicy(Element element){
Policy newPolicy = null;
if(element.getNodeName().equals("true")){
// element represents the "true" variant
newPolicy = TrueImpl.getInstance();
}
else if (element.getNodeName().equals("false")){
// element represents the "false" variant
newPolicy = FalseImpl.getInstance();
}
else if (element.getNodeName().equals("requestor")){
// element represents the "requestor" variant
newPolicy = RequestorImpl.getInstance();
}
else if (element.getNodeName().equals("owner")){
// element represents the "owner" variant
newPolicy = OwnerImpl.getInstance();
}
else if (element.getNodeName().equals("variable")){
Object temp=null;
temp = new String (element.getFirstChild().getNodeValue());
newPolicy = new VariableImpl(temp);
}
else if (element.getNodeName().equals("at")||element.getNodeName().equals("bind")){
Policy policyA = null;
Object variable = null;
// Get the children nodes of element
NodeList nodeList = element.getChildNodes();
// Loop through the children nodes of element
for (int i=0; i < nodeList.getLength(); i++){
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE){
Element tempElement = (Element) node;
if (tempElement.getNodeName().equals("varID")){
variable = new String (tempElement.getFirstChild().getNodeValue());
}
else {
// Else the node represents the sub policy
// Parse and set the sub policy
policyA = parsePolicy(tempElement);
}
}
}
if (element.getNodeName().equals("at")){
// If element represented the at variant, then create new At object
newPolicy = new AtImpl(variable, policyA);
}
else {
// Else element represented the bind variant, then create new Bind object
newPolicy = new BindImpl(variable, policyA);
}
}
else if (element.getNodeName().equals("and") || element.getNodeName().equals("or")){
// element represents the "and" (Conjunction) or "or" (Disjunction) variant
// The case is combined since both behave similarly
// Initialize the sub policies
Policy policyA = null;
Policy policyB = null;
// Get the children nodes of element
NodeList nodeList = element.getChildNodes();
for (int i=0; i < nodeList.getLength(); i++){
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE){
// Find the Element type nodes
Element tempElement = (Element) node;
// First parse and set policyA, then parse and set policyB
if (policyA == null){
policyA = parsePolicy(tempElement);
}
else{
policyB = parsePolicy(tempElement);
break;
}
}
}
if (element.getNodeName().equals("and")){
// If element represents "and" variant, then create new Conjunction object
newPolicy = new ConjunctionImpl(policyA, policyB);
}
else {
// Else element represents "or" variant, create new Disjunction object
newPolicy = new DisjunctionImpl(policyA, policyB);
}
}
else if (element.getNodeName().equals("not")){
// element represents "not" (negation) variant
// Initialize the sub policy
Policy policyA = null;
// Get the children nodes of element
NodeList nodeList = element.getChildNodes();
// Loop through the children nodes of element
for (int i=0; i < nodeList.getLength(); i++){
Node node = nodeList.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE){
// Find the Element type node
Element tempElement = (Element) node;
// Parse and set the sub policy
policyA = parsePolicy(tempElement);
break;
}
}
// Create new Negation object
newPolicy = new NegationImpl(policyA);
}
else if (element.getNodeName().equals("box") || element.getNodeName().equals("diamond")){
// element represents the "box" or "diamond" variant
// The case is combined since both behave similarly
// Initialize the sub policy, relation identifier, and direction
Policy policyA = null;
Object relationIdentifier = null;
Direction direction = null;
// Get the children nodes of element
NodeList nodeList = element.getChildNodes();