Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/sun/xacml/cond/SetFunction.java


1   
2   /*
3    * @(#)SetFunction.java
4    *
5    * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved.
6    *
7    * Redistribution and use in source and binary forms, with or without
8    * modification, are permitted provided that the following conditions are met:
9    *
10   *   1. Redistribution of source code must retain the above copyright notice,
11   *      this list of conditions and the following disclaimer.
12   * 
13   *   2. Redistribution in binary form must reproduce the above copyright
14   *      notice, this list of conditions and the following disclaimer in the
15   *      documentation and/or other materials provided with the distribution.
16   *
17   * Neither the name of Sun Microsystems, Inc. or the names of contributors may
18   * be used to endorse or promote products derived from this software without
19   * specific prior written permission.
20   * 
21   * This software is provided "AS IS," without a warranty of any kind. ALL
22   * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING
23   * ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
24   * OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN MICROSYSTEMS, INC. ("SUN")
25   * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE
26   * AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR ITS
27   * DERIVATIVES. IN NO EVENT WILL SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST
28   * REVENUE, PROFIT OR DATA, OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL,
29   * INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY
30   * OF LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
31   * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
32   *
33   * You acknowledge that this software is not designed or intended for use in
34   * the design, construction, operation or maintenance of any nuclear facility.
35   */
36  
37  package com.sun.xacml.cond;
38  
39  import com.sun.xacml.EvaluationCtx;
40  
41  import com.sun.xacml.attr.AnyURIAttribute;
42  import com.sun.xacml.attr.AttributeValue;
43  import com.sun.xacml.attr.BagAttribute;
44  import com.sun.xacml.attr.Base64BinaryAttribute;
45  import com.sun.xacml.attr.BooleanAttribute;
46  import com.sun.xacml.attr.DateAttribute;
47  import com.sun.xacml.attr.DateTimeAttribute;
48  import com.sun.xacml.attr.DayTimeDurationAttribute;
49  import com.sun.xacml.attr.DoubleAttribute;
50  import com.sun.xacml.attr.HexBinaryAttribute;
51  import com.sun.xacml.attr.IntegerAttribute;
52  import com.sun.xacml.attr.RFC822NameAttribute;
53  import com.sun.xacml.attr.StringAttribute;
54  import com.sun.xacml.attr.TimeAttribute;
55  import com.sun.xacml.attr.X500NameAttribute;
56  import com.sun.xacml.attr.YearMonthDurationAttribute;
57  
58  import java.util.HashSet;
59  import java.util.Set;
60  
61  
62  /**
63   * Represents all of the Set functions, though the actual implementations
64   * are in two sub-classes specific to the condition and general set
65   * functions.
66   *
67   * @since 1.0
68   * @author Seth Proctor
69   */
70  public abstract class SetFunction extends FunctionBase
71  {
72  
73      /**
74       * Base name for the type-intersection funtions. To get the standard
75       * identifier for a given type, use <code>FunctionBase.FUNCTION_NS</code>
76       * + the datatype's base name (e.g., <code>string</code>) +
77       * </code>NAME_BASE_INTERSECTION</code>.
78       */
79      public static final String NAME_BASE_INTERSECTION =
80          "-intersection";
81  
82      /**
83       * Base name for the type-at-least-one-member-of funtions. To get the
84       * standard identifier for a given type, use
85       * <code>FunctionBase.FUNCTION_NS</code> + the datatype's base name
86       * (e.g., <code>string</code>) +
87       * </code>NAME_BASE_AT_LEAST_ONE_MEMBER_OF</code>.
88       */
89      public static final String NAME_BASE_AT_LEAST_ONE_MEMBER_OF =
90          "-at-least-one-member-of";
91  
92      /**
93       * Base name for the type-union funtions. To get the standard
94       * identifier for a given type, use <code>FunctionBase.FUNCTION_NS</code>
95       * + the datatype's base name (e.g., <code>string</code>) +
96       * </code>NAME_BASE_UNION</code>.
97       */
98      public static final String NAME_BASE_UNION =
99          "-union";
100 
101     /**
102      * Base name for the type-subset funtions. To get the standard
103      * identifier for a given type, use <code>FunctionBase.FUNCTION_NS</code>
104      * + the datatype's base name (e.g., <code>string</code>) +
105      * </code>NAME_BASE_SUBSET</code>.
106      */
107     public static final String NAME_BASE_SUBSET =
108         "-subset";
109 
110     /**
111      * Base name for the type-set-equals funtions. To get the standard
112      * identifier for a given type, use <code>FunctionBase.FUNCTION_NS</code>
113      * + the datatype's base name (e.g., <code>string</code>) +
114      * </code>NAME_BASE_SET_EQUALS</code>.
115      */
116     public static final String NAME_BASE_SET_EQUALS =
117         "-set-equals";
118 
119     /**
120      * A complete list of all the XACML datatypes supported by the Set
121      * functions
122      */
123     protected static String baseTypes [] = {
124         StringAttribute.identifier,
125         BooleanAttribute.identifier,
126         IntegerAttribute.identifier,
127         DoubleAttribute.identifier,
128         DateAttribute.identifier,
129         DateTimeAttribute.identifier,
130         TimeAttribute.identifier,
131         AnyURIAttribute.identifier,
132         HexBinaryAttribute.identifier,
133         Base64BinaryAttribute.identifier,
134         DayTimeDurationAttribute.identifier,
135         YearMonthDurationAttribute.identifier,
136         X500NameAttribute.identifier,
137         RFC822NameAttribute.identifier
138     };
139 
140     /**
141      * A complete list of all the XACML datatypes supported by the Set
142      * functions, using the "simple" form of the names (eg, string
143      * instead of http://www.w3.org/2001/XMLSchema#string)
144      */
145     protected static String simpleTypes [] = {
146         "string", "boolean", "integer", "double", "date", "dateTime",
147         "time", "anyURI", "hexBinary", "base64Binary", "dayTimeDuration",
148         "yearMonthDuration", "x500Name", "rfc822Name"
149     };
150 
151     /**
152      * Creates a new instance of the intersection set function.
153      * This should be used to create support for any new attribute types
154      * and then the new <code>SetFunction</code> object should be added
155      * to the factory (all set functions for the base types are already
156      * installed in the factory).
157      *
158      * @param functionName the name of the function
159      * @param argumentType the attribute type this function will work with
160      *
161      * @return a new <code>SetFunction</code> for the given type
162      */
163     public static SetFunction getIntersectionInstance(String functionName,
164                                                       String argumentType) {
165         return new GeneralSetFunction(functionName, argumentType,
166                                       NAME_BASE_INTERSECTION);
167     }
168 
169     /**
170      * Creates a new instance of the at-least-one-member-of set function.
171      * This should be used to create support for any new attribute types
172      * and then the new <code>SetFunction</code> object should be added
173      * to the factory (all set functions for the base types are already
174      * installed in the factory).
175      *
176      * @param functionName the name of the function
177      * @param argumentType the attribute type this function will work with
178      *
179      * @return a new <code>SetFunction</code> for the given type
180      */
181     public static SetFunction getAtLeastOneInstance(String functionName,
182                                                     String argumentType) {
183         return new ConditionSetFunction(functionName, argumentType,
184                                         NAME_BASE_AT_LEAST_ONE_MEMBER_OF);
185     }
186 
187     /**
188      * Creates a new instance of the union set function.
189      * This should be used to create support for any new attribute types
190      * and then the new <code>SetFunction</code> object should be added
191      * to the factory (all set functions for the base types are already
192      * installed in the factory).
193      *
194      * @param functionName the name of the function
195      * @param argumentType the attribute type this function will work with
196      *
197      * @return a new <code>SetFunction</code> for the given type
198      */
199     public static SetFunction getUnionInstance(String functionName,
200                                                String argumentType) {
201         return new GeneralSetFunction(functionName, argumentType,
202                                       NAME_BASE_UNION);
203     }
204 
205     /**
206      * Creates a new instance of the subset set function.
207      * This should be used to create support for any new attribute types
208      * and then the new <code>SetFunction</code> object should be added
209      * to the factory (all set functions for the base types are already
210      * installed in the factory).
211      *
212      * @param functionName the name of the function
213      * @param argumentType the attribute type this function will work with
214      *
215      * @return a new <code>SetFunction</code> for the given type
216      */
217     public static SetFunction getSubsetInstance(String functionName,
218                                                 String argumentType) {
219         return new ConditionSetFunction(functionName, argumentType,
220                                         NAME_BASE_SUBSET);
221     }
222 
223     /**
224      * Creates a new instance of the equals set function.
225      * This should be used to create support for any new attribute types
226      * and then the new <code>SetFunction</code> object should be added
227      * to the factory (all set functions for the base types are already
228      * installed in the factory).
229      *
230      * @param functionName the name of the function
231      * @param argumentType the attribute type this function will work with
232      *
233      * @return a new <code>SetFunction</code> for the given type
234      */
235     public static SetFunction getSetEqualsInstance(String functionName,
236                                                    String argumentType) {
237         return new ConditionSetFunction(functionName, argumentType,
238                                         NAME_BASE_SET_EQUALS);
239     }
240 
241     /**
242      * Protected constuctor used by the general and condition subclasses.
243      * If you need to create a new <code>SetFunction</code> instance you
244      * should either use one of the <code>getInstance</code> methods or
245      * construct one of the sub-classes directly.
246      *
247      * @param functionName the identitifer for the function
248      * @param functionId an optional, internal numeric identifier
249      * @param argumentType the datatype this function accepts
250      * @param returnType the datatype this function returns
251      * @param returnsBag whether this function returns bags
252      */
253     protected SetFunction(String functionName, int functionId,
254                           String argumentType, String returnType,
255                           boolean returnsBag) {
256         super(functionName, functionId, argumentType, true, 2, returnType,
257               returnsBag);
258     }
259 
260     /**
261      * Returns a <code>Set</code> containing all the function identifiers
262      * supported by this class.
263      *
264      * @return a <code>Set</code> of <code>String</code>s
265      */
266     public static Set getSupportedIdentifiers() {
267         Set set = new HashSet();
268 
269         set.addAll(ConditionSetFunction.getSupportedIdentifiers());
270         set.addAll(GeneralSetFunction.getSupportedIdentifiers());
271 
272         return set;
273     }
274 
275 }