Package ca.ucalgary.ispia.rebac

Examples of ca.ucalgary.ispia.rebac.Policy


   * {@link Negation}, {@link True} , {@link False}, {@link At} and {@link Bind}
   * @param tPolicy The policy to be translated.
   * @return A policy composed of only primitive operators.
   */
  public static Policy translate(Policy tPolicy){
    Policy translatedPolicy;

    if (tPolicy instanceof VariableImpl){
      //Already primitive.
      translatedPolicy = tPolicy;
    }
   
    else if (tPolicy == FalseImpl.getInstance()){
      // Already primitive
      translatedPolicy = tPolicy;
    }
    else if (tPolicy ==TrueImpl.getInstance()){
      // Already primitive
      translatedPolicy = tPolicy;
    }
   
    else if(tPolicy instanceof NegationImpl){
      // Already primitive. Recurse on contained policy.
      NegationImpl temp = (NegationImpl) tPolicy;
      // Get contained fields
      Policy tempA = temp.getPolicy();
      // Translate contained policy
      tempA = translate(tempA);
      // Create translated policy
      translatedPolicy = new NegationImpl (tempA);
    }
   
    else if (tPolicy instanceof ConjunctionImpl){
      // Already primitive. Recurse on contained policies.
     
      ConjunctionImpl temp = (ConjunctionImpl) tPolicy;
      // Get contained fields
      Policy tempA = temp.getPolicyA();
      Policy tempB = temp.getPolicyB();
      // Translate contained fields
      tempA = translate(tempA);
      tempB = translate(tempB);
      // Create translated policy
      translatedPolicy = new ConjunctionImpl(tempA, tempB);
    }
   
    else if (tPolicy instanceof DisjunctionImpl){
      // Disjunction(policyA, policyB) =
      //  Negation(Conjunction((Negation(policyA)), (Negation(policyB))))
     
      DisjunctionImpl temp = (DisjunctionImpl) tPolicy;
      // Get contained fields
      Policy tempA = temp.getPolicyA();
      Policy tempB = temp.getPolicyB();
      // Translate contained policies
      tempA = new NegationImpl (translate(tempA));
      tempB = new NegationImpl (translate(tempB));
      // Create translated policy
      Policy tempC = new ConjunctionImpl(tempA, tempB);
      translatedPolicy = new NegationImpl (tempC);
     
    }
   
    else if (tPolicy instanceof BoxImpl){
      // Box(policy) = Negation(Diamond(Negation(policy)))

      BoxImpl temp = (BoxImpl) tPolicy;
     
      // Get contained fields
      Policy tempA = temp.getPolicy();
      Object relationID = temp.getRelationIdentifier();
      Direction direction = temp.getDirection();
      // Translate contained policy
      tempA = new NegationImpl (translate(tempA));
      // Create translated policy
      Policy tempB = new DiamondImpl(tempA, relationID, direction);   
      translatedPolicy = new NegationImpl (tempB);
    }
   
    else if (tPolicy instanceof DiamondImpl){
      // Already primitive. Recurse on contained policy.
     
      DiamondImpl temp = (DiamondImpl) tPolicy;
      // Get contained fields
      Policy tempA = temp.getPolicy();
      Object relationID = temp.getRelationIdentifier();
      Direction direction = temp.getDirection();
      // Translate contained policy
      tempA = translate(tempA);
      // Create translated policy
      translatedPolicy = new DiamondImpl(tempA, relationID, direction);
    }
   
    else if (tPolicy instanceof BindImpl){
      //Already primitive. Recurse on contained policy
     
      BindImpl temp= (BindImpl) tPolicy;
      Policy tempA = temp.getPolicy();
      Object var = temp.getVariable();
     
      //translate contained policy
      tempA=translate(tempA);
      // Create translated policy
      translatedPolicy = new BindImpl(var, tempA);
    }
   
    else if (tPolicy instanceof AtImpl){
      //Already primitive. Recurse on contained policy
     
      AtImpl temp = (AtImpl) tPolicy;
      Policy tempA = temp.getPolicy();
      Object var = temp.getVariable();
     
      //translate contained policy
      tempA=translate(tempA);
      // Create translated policy
View Full Code Here


     * {@link NegationImpl}, and {@link TrueImpl}
     * @param tPolicy The policy to be translated.
     * @return A policy composed of only primitive operators.
     */
    public static Policy translate(Policy tPolicy){
      Policy translatedPolicy;
     
      if (tPolicy == RequestorImpl.getInstance()){
        // For requestor variant
        translatedPolicy = tPolicy;
      }
     
      else if (tPolicy instanceof BoxImpl){
        // Box(policy) = Negation(Diamond(Negation(policy)))
 
        BoxImpl temp = (BoxImpl) tPolicy;
       
        // Get contained fields
        Policy tempA = temp.policy;
        Object relationID = temp.relationIdentifier;
        Direction direction = temp.direction;
        // Translate contained policy
        tempA = new NegationImpl (translate(tempA));
        // Create translated policy
        Policy tempB = new DiamondImpl(tempA, relationID, direction);   
        translatedPolicy = new NegationImpl (tempB);
      }
     
      else if (tPolicy instanceof ConjunctionImpl){
        // Conjunction(policyA, policyB) =
        //            Negation(Disjunction((Negation(policyA)), (Negation(policyB))))
       
        ConjunctionImpl temp = (ConjunctionImpl) tPolicy;
        // Get contained fields
        Policy tempA = temp.policyA;
        Policy tempB = temp.policyB;
        // Translate contained policies
        tempA = new NegationImpl (translate(tempA));
        tempB = new NegationImpl (translate(tempB));
        // Create translated policy
        Policy tempC = new DisjunctionImpl(tempA, tempB);
        translatedPolicy = new NegationImpl (tempC);
       
      }
         
      else if (tPolicy instanceof DiamondImpl){
        // Already primitive. Recurse on contained policy.
       
        DiamondImpl temp = (DiamondImpl) tPolicy;
        // Get contained fields
        Policy tempA = temp.policy;
        Object relationID = temp.relationIdentifier;
        Direction direction = temp.direction;
        // Translate contained policy
        tempA = translate(tempA);
        // Create translated policy
        translatedPolicy = new DiamondImpl(tempA, relationID, direction);
      }
         
      else if (tPolicy instanceof DisjunctionImpl){
        // Already primitive. Recurse on contained policies.
       
        DisjunctionImpl temp = (DisjunctionImpl) tPolicy;
        // Get contained fields
        Policy tempA = temp.policyA;
        Policy tempB = temp.policyB;
        // Translate contained fields
        tempA = translate(tempA);
        tempB = translate(tempB);
        // Create translated policy
        translatedPolicy = new DisjunctionImpl(tempA, tempB);
      }
     
      else if (tPolicy == FalseImpl.getInstance()){
        // False = Negation(True)
       
        // Create translated policy
        translatedPolicy = new NegationImpl(TrueImpl.getInstance());
      }
     
      else if(tPolicy instanceof NegationImpl){
        // Already primitive. Recurse on contained policy.
        NegationImpl temp = (NegationImpl) tPolicy;
        // Get contained fields
        Policy tempA = temp.policy;
        // Translate contained policy
        tempA = translate(tempA);
        // Create translated policy
        translatedPolicy = new NegationImpl (tempA);
      }
View Full Code Here

          if (nNode.getNodeType() == Node.ELEMENT_NODE){
            // Find the Element type node (represents some policy variant)
            Element eElement = (Element) nNode;
            // Parse the element representing the policy and
            // add it to the policies list
            Policy tempPolicy = parsePolicy(eElement);
            policiesObj.add(tempPolicy);           
          }
        }
      }
    }
View Full Code Here

   * 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("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();
View Full Code Here

   */

  public static Policy translate(Policy tPolicy){

    Policy translatedPolicy;



    if (tPolicy instanceof VariableImpl){

      //Already primitive.

      translatedPolicy = tPolicy;

    }

    else if (tPolicy instanceof OwnerImpl){
   
      //Translate the Owner variant to a variable
      translatedPolicy = new VariableImpl(Constants.owner);
     
    }
    else if (tPolicy instanceof RequestorImpl){
   
      //Translate the Requestor variant to a variable
      translatedPolicy = new VariableImpl(Constants.requestor);
    }

    else if (tPolicy == FalseImpl.getInstance()){

      // Already primitive

      translatedPolicy = tPolicy;

    }

    else if (tPolicy ==TrueImpl.getInstance()){

      // Already primitive

      translatedPolicy = tPolicy;

    }

   

    else if(tPolicy instanceof NegationImpl){

      // Already primitive. Recurse on contained policy.

      NegationImpl temp = (NegationImpl) tPolicy;

      // Get contained fields

      Policy tempA = temp.getPolicy();

      // Translate contained policy

      tempA = translate(tempA);

      // Create translated policy

      translatedPolicy = new NegationImpl (tempA);

    }

   

    else if (tPolicy instanceof ConjunctionImpl){

      // Already primitive. Recurse on contained policies.

     

      ConjunctionImpl temp = (ConjunctionImpl) tPolicy;

      // Get contained fields

      Policy tempA = temp.getPolicyA();

      Policy tempB = temp.getPolicyB();

      // Translate contained fields

      tempA = translate(tempA);

      tempB = translate(tempB);

      // Create translated policy

      translatedPolicy = new ConjunctionImpl(tempA, tempB);

    }

   

    else if (tPolicy instanceof DisjunctionImpl){

      // Disjunction(policyA, policyB) =

      //  Negation(Conjunction((Negation(policyA)), (Negation(policyB))))

     

      DisjunctionImpl temp = (DisjunctionImpl) tPolicy;

      // Get contained fields

      Policy tempA = temp.getPolicyA();

      Policy tempB = temp.getPolicyB();

      // Translate contained policies

      tempA = new NegationImpl (translate(tempA));

      tempB = new NegationImpl (translate(tempB));

      // Create translated policy

      Policy tempC = new ConjunctionImpl(tempA, tempB);

      translatedPolicy = new NegationImpl (tempC);

     

    }

   

    else if (tPolicy instanceof BoxImpl){

      // Box(policy) = Negation(Diamond(Negation(policy)))



      BoxImpl temp = (BoxImpl) tPolicy;

     

      // Get contained fields

      Policy tempA = temp.getPolicy();

      Object relationID = temp.getRelationIdentifier();

      Direction direction = temp.getDirection();

      // Translate contained policy

      tempA = new NegationImpl (translate(tempA));

      // Create translated policy

      Policy tempB = new DiamondImpl(tempA, relationID, direction);   

      translatedPolicy = new NegationImpl (tempB);

    }

   

    else if (tPolicy instanceof DiamondImpl){

      // Already primitive. Recurse on contained policy.

     

      DiamondImpl temp = (DiamondImpl) tPolicy;

      // Get contained fields

      Policy tempA = temp.getPolicy();

      Object relationID = temp.getRelationIdentifier();

      Direction direction = temp.getDirection();

      // Translate contained policy

      tempA = translate(tempA);

      // Create translated policy

      translatedPolicy = new DiamondImpl(tempA, relationID, direction);

    }

   

    else if (tPolicy instanceof BindImpl){

      //Already primitive. Recurse on contained policy

     

      BindImpl temp= (BindImpl) tPolicy;

      Policy tempA = temp.getPolicy();

      Object var = temp.getVariable();

     

      //translate contained policy

      tempA=translate(tempA);

      // Create translated policy

      translatedPolicy = new BindImpl(var, tempA);

    }

   

    else if (tPolicy instanceof AtImpl){

      //Already primitive. Recurse on contained policy

     

      AtImpl temp = (AtImpl) tPolicy;

      Policy tempA = temp.getPolicy();

      Object var = temp.getVariable();

     

View Full Code Here

          if (nNode.getNodeType() == Node.ELEMENT_NODE){
            // Find the Element type node (represents some policy variant)
            Element eElement = (Element) nNode;
            // Parse the element representing the policy and
            // add it to the policies list
            Policy tempPolicy = parsePolicy(eElement);
            policiesObj.add(tempPolicy);           
          }
        }
      }
    }
View Full Code Here

   * 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();
View Full Code Here

   */

  public static Policy translate(Policy tPolicy){

    Policy translatedPolicy;



    if (tPolicy instanceof VariableImpl){

      //Already primitive.

      translatedPolicy = tPolicy;

    }

    else if (tPolicy instanceof OwnerImpl){
   
      //Translate the Owner variant to a variable
      translatedPolicy = new VariableImpl(Constants.owner);
     
    }
    else if (tPolicy instanceof RequestorImpl){
   
      //Translate the Requestor variant to a variable
      translatedPolicy = new VariableImpl(Constants.requestor);
    }
    else if (tPolicy instanceof ResourceImpl){
      //Translate the Resource variant to ta variable
      translatedPolicy = new VariableImpl(Constants.resource);
    }

    else if (tPolicy == FalseImpl.getInstance()){

      // Already primitive

      translatedPolicy = tPolicy;

    }

    else if (tPolicy ==TrueImpl.getInstance()){

      // Already primitive

      translatedPolicy = tPolicy;

    }

   

    else if(tPolicy instanceof NegationImpl){

      // Already primitive. Recurse on contained policy.

      NegationImpl temp = (NegationImpl) tPolicy;

      // Get contained fields

      Policy tempA = temp.getPolicy();

      // Translate contained policy

      tempA = translate(tempA);

      // Create translated policy

      translatedPolicy = new NegationImpl (tempA);

    }

   

    else if (tPolicy instanceof ConjunctionImpl){

      // Already primitive. Recurse on contained policies.

     

      ConjunctionImpl temp = (ConjunctionImpl) tPolicy;

      // Get contained fields

      Policy tempA = temp.getPolicyA();

      Policy tempB = temp.getPolicyB();

      // Translate contained fields

      tempA = translate(tempA);

      tempB = translate(tempB);

      // Create translated policy

      translatedPolicy = new ConjunctionImpl(tempA, tempB);

    }

   

    else if (tPolicy instanceof DisjunctionImpl){

      // Disjunction(policyA, policyB) =

      //  Negation(Conjunction((Negation(policyA)), (Negation(policyB))))

     

      DisjunctionImpl temp = (DisjunctionImpl) tPolicy;

      // Get contained fields

      Policy tempA = temp.getPolicyA();

      Policy tempB = temp.getPolicyB();

      // Translate contained policies

      tempA = new NegationImpl (translate(tempA));

      tempB = new NegationImpl (translate(tempB));

      // Create translated policy

      Policy tempC = new ConjunctionImpl(tempA, tempB);

      translatedPolicy = new NegationImpl (tempC);

     

    }

   

    else if (tPolicy instanceof BoxImpl){

      // Box(policy) = Negation(Diamond(Negation(policy)))



      BoxImpl temp = (BoxImpl) tPolicy;

     

      // Get contained fields

      Policy tempA = temp.getPolicy();

      Object relationID = temp.getRelationIdentifier();

      Direction direction = temp.getDirection();

      // Translate contained policy

      tempA = new NegationImpl (translate(tempA));

      // Create translated policy

      Policy tempB = new DiamondImpl(tempA, relationID, direction);   

      translatedPolicy = new NegationImpl (tempB);

    }

   

    else if (tPolicy instanceof DiamondImpl){

      // Already primitive. Recurse on contained policy.

     

      DiamondImpl temp = (DiamondImpl) tPolicy;

      // Get contained fields

      Policy tempA = temp.getPolicy();

      Object relationID = temp.getRelationIdentifier();

      Direction direction = temp.getDirection();

      // Translate contained policy

      tempA = translate(tempA);

      // Create translated policy

      translatedPolicy = new DiamondImpl(tempA, relationID, direction);

    }

   

    else if (tPolicy instanceof BindImpl){

      //Already primitive. Recurse on contained policy

     

      BindImpl temp= (BindImpl) tPolicy;

      Policy tempA = temp.getPolicy();

      Object var = temp.getVariable();

     

      //translate contained policy

      tempA=translate(tempA);

      // Create translated policy

      translatedPolicy = new BindImpl(var, tempA);

    }

   

    else if (tPolicy instanceof AtImpl){

      //Already primitive. Recurse on contained policy

     

      AtImpl temp = (AtImpl) tPolicy;

      Policy tempA = temp.getPolicy();

      Object var = temp.getVariable();

     

View Full Code Here

          if (nNode.getNodeType() == Node.ELEMENT_NODE){
            // Find the Element type node (represents some policy variant)
            Element eElement = (Element) nNode;
            // Parse the element representing the policy and
            // add it to the policies list
            Policy tempPolicy = parsePolicy(eElement);
            policiesObj.add(tempPolicy);           
          }
        }
      }
    }
View Full Code Here

   * 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("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();
View Full Code Here

TOP

Related Classes of ca.ucalgary.ispia.rebac.Policy

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.