001/** 002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 003 * 004 * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved 005 * 006 * The contents of this file are subject to the terms 007 * of the Common Development and Distribution License 008 * (the License). You may not use this file except in 009 * compliance with the License. 010 * 011 * You can obtain a copy of the License at 012 * https://opensso.dev.java.net/public/CDDLv1.0.html or 013 * opensso/legal/CDDLv1.0.txt 014 * See the License for the specific language governing 015 * permission and limitations under the License. 016 * 017 * When distributing Covered Code, include this CDDL 018 * Header Notice in each file and include the License file 019 * at opensso/legal/CDDLv1.0.txt. 020 * If applicable, add the following below the CDDL Header, 021 * with the fields enclosed by brackets [] replaced by 022 * your own identifying information: 023 * "Portions Copyrighted [year] [name of copyright owner]" 024 * 025 * $Id: PolicyFactory.java,v 1.2 2008/06/25 05:48:14 qcheng Exp $ 026 * 027 */ 028 029 030package com.sun.identity.xacml.policy; 031 032import org.w3c.dom.Element; 033import com.sun.identity.saml2.common.SAML2Exception; 034import com.sun.identity.xacml.common.XACMLException; 035import com.sun.identity.xacml.common.XACMLSDKUtils; 036import com.sun.identity.xacml.common.XACMLConstants; 037import com.sun.identity.xacml.policy.impl.ObligationImpl; 038import com.sun.identity.xacml.policy.impl.ObligationsImpl; 039 040/** 041 * This is the factory class to obtain instances of the objects defined 042 * in xacml context schema. 043 * There are three ways to obtain an instance of a object type: 044 * with no parameters, with a DOM tree element, or with an XML String. 045 * 046 * @supported.all.api 047 */ 048public class PolicyFactory { 049 050 private static PolicyFactory instance = new PolicyFactory(); 051 052 /** 053 * Sole Constructor. 054 */ 055 private PolicyFactory() { 056 } 057 058 /** 059 * Returns the instance of <code>ContextSchemaFactory</code>. 060 * 061 * @return <code>ContextSchemaFactory</code>. 062 * 063 */ 064 public static PolicyFactory getInstance() { 065 return instance; 066 } 067 068 /** 069 * Returns a new instance of <code>Obligation</code>. 070 * 071 * @return a new instance of <code>Obligation</code> 072 * 073 */ 074 public Obligation createObligation() { 075 Object obj = XACMLSDKUtils.getObjectInstance(XACMLConstants.REQUEST); 076 if (obj == null) { 077 return new ObligationImpl(); 078 } else { 079 return (Obligation) obj; 080 } 081 } 082 083 /** 084 * Returns a new instance of <code>Obligation</code>. 085 * The return object is immutable. 086 * 087 * @param elem a DOM Element representation of <code>Obligation</code> 088 * @return a new instance of <code>Obligation</code> 089 * @throws XACMLException if error occurs while processing the 090 * DOM Element 091 * 092 */ 093 public Obligation createObligation(Element elem) 094 throws XACMLException { 095 Object obj = XACMLSDKUtils.getObjectInstance( 096 XACMLConstants.REQUEST, elem); 097 if (obj == null) { 098 return new ObligationImpl(elem); 099 } else { 100 return (Obligation) obj; 101 } 102 } 103 104 /** 105 * Returns a new instance of <code>Obligation</code> 106 * The return object is immutable. 107 * 108 * @param xml a XML string representation of <code>Obligation</code> 109 * @return a new instance of <code>Resource</code> 110 * @throws XACMLException if error occurs while processing the 111 * XML string 112 * 113 */ 114 public Obligation createObligation(String xml) 115 throws XACMLException { 116 Object obj = XACMLSDKUtils.getObjectInstance( 117 XACMLConstants.REQUEST, xml); 118 if (obj == null) { 119 return new ObligationImpl(xml); 120 } else { 121 return (Obligation) obj; 122 } 123 } 124 125 126 /** 127 * Returns a new instance of <code>Obligations</code>. 128 * 129 * @return a new instance of <code>Obligations</code> 130 * 131 */ 132 public Obligations createObligations() { 133 Object obj = XACMLSDKUtils.getObjectInstance(XACMLConstants.RESOURCE); 134 if (obj == null) { 135 return new ObligationsImpl(); 136 } else { 137 return (Obligations) obj; 138 } 139 } 140 141 /** 142 * Returns a new instance of <code>Obligations</code>. 143 * The return object is immutable. 144 * 145 * @param elem a DOM Element representation of <code>Obligations</code> 146 * @return a new instance of <code>Obligations</code> 147 * @throws XACMLException if error occurs while processing the 148 * DOM Element 149 * 150 */ 151 public Obligations createObligations(Element elem) 152 throws XACMLException { 153 Object obj = XACMLSDKUtils.getObjectInstance( 154 XACMLConstants.RESOURCE, elem); 155 if (obj == null) { 156 return new ObligationsImpl(elem); 157 } else { 158 return (Obligations) obj; 159 } 160 } 161 162 /** 163 * Returns a new instance of <code>Obligations</code> 164 * The return object is immutable. 165 * 166 * @param xml a XML string representation of <code>Obligations</code> 167 * @return a new instance of <code>Obligations</code> 168 * @throws XACMLException if error occurs while processing the 169 * XML string 170 * 171 */ 172 public Obligations createObligations(String xml) 173 throws XACMLException { 174 Object obj = XACMLSDKUtils.getObjectInstance( 175 XACMLConstants.RESOURCE, xml); 176 if (obj == null) { 177 return new ObligationsImpl(xml); 178 } else { 179 return (Obligations) obj; 180 } 181 } 182 183}