import java.io.StringReader;
import java.io.StringWriter;

import javax.xml.bind.JAXB;

import oasis.names.tc.xacml._3_0.core.schema.wd_17.DecisionType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.RequestType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ResponseType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.ResultType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.StatusType;



public class XacmlMarshallUtil {

    public static Result extractResultFromXacmlResponseString(String xacmlResponseAsString) {
        
        StringReader reader = new StringReader(xacmlResponseAsString); 
        ResponseType responseType = JAXB.unmarshal(reader, ResponseType.class);
        ResultType resultType = responseType.getResult().get(0);
        DecisionType decision = resultType.getDecision();
        StatusType status = resultType.getStatus();

        Result result = mapToOurResult(decision, status);

        return result;
    }