Exemple #1
0
  /**
   * Returns a <code>PolicyRequest</code> object constructed from a XML.
   *
   * @param pNode the XML DOM node for the <code>PolicyRequest</code> object.
   * @return constructed <code>PolicyRequest</code> object
   */
  public static PolicyRequest parseXML(Node pNode) throws PolicyEvaluationException {
    PolicyRequest preq = new PolicyRequest();

    String attr = XMLUtils.getNodeAttributeValue(pNode, APP_SSOTOKEN);
    if (attr == null) {
      debug.error("PolicyRequestparseXML(Node): missing attribute " + APP_SSOTOKEN);
      String objs[] = {APP_SSOTOKEN};
      throw new PolicyEvaluationException(ResBundleUtils.rbName, "missing_attribute", objs, null);
    }
    preq.setAppSSOToken(attr);
    attr = XMLUtils.getNodeAttributeValue(pNode, REQUEST_ID);

    if (attr == null) {
      debug.error("PolicyRequest.parseXML(Node): missing attribute " + REQUEST_ID);
      String objs[] = {REQUEST_ID};
      throw new PolicyEvaluationException(ResBundleUtils.rbName, "missing_attribute", objs, null);
    }
    preq.setRequestId(attr);

    Node node = XMLUtils.getChildNode(pNode, GET_RESOURCE_RESULTS);
    if (node != null) {
      ResourceResultRequest resourceResultReq = null;
      try {
        resourceResultReq = ResourceResultRequest.parseXML(node);
      } catch (PolicyEvaluationException pe) {
        throw new PolicyEvaluationException(pe, preq.getRequestId());
      }
      preq.setResourceResultRequest(resourceResultReq);
      preq.setMethodID(POLICY_REQUEST_GET_RESOURCE_RESULTS);
      return preq;
    }

    node = XMLUtils.getChildNode(pNode, ADD_POLICY_LISTENER);
    if (node != null) {
      PolicyListenerRequest plr = null;
      try {
        plr = PolicyListenerRequest.parseXML(node);
      } catch (PolicyEvaluationException pe) {
        throw new PolicyEvaluationException(pe, preq.getRequestId());
      }
      preq.setPolicyListenerRequest(plr);
      preq.setMethodID(POLICY_REQUEST_ADD_POLICY_LISTENER);
      return preq;
    }

    node = XMLUtils.getChildNode(pNode, REMOVE_POLICY_LISTENER);
    if (node != null) {
      RemoveListenerRequest rmListenerReq = null;
      try {
        rmListenerReq = RemoveListenerRequest.parseXML(node);
      } catch (PolicyEvaluationException pe) {
        throw new PolicyEvaluationException(pe, preq.getRequestId());
      }
      preq.setRemoveListenerRequest(rmListenerReq);
      preq.setMethodID(POLICY_REQUEST_REMOVE_POLICY_LISTENER);
      return preq;
    }

    node = XMLUtils.getChildNode(pNode, ADVICES_HANDLEABLE_BY_AM_REQUEST);
    if (node != null) {
      preq.setAdvicesHandleableByAMRequest(new AdvicesHandleableByAMRequest());
      preq.setMethodID(POLICY_REQUEST_ADVICES_HANDLEABLE_BY_AM_REQUEST);
      return preq;
    }

    /*
     * We reach here, there is no valid method name specified in
     * the xml docuemnt. Throw exception.
     */
    debug.error("PolicyRequest: invalid method specified");
    throw new PolicyEvaluationException(
        ResBundleUtils.rbName, "invalid_policy_request_method", null, null);
  }