Source code: com/sun/xacml/cond/BagFunction.java
1
2 /*
3 * @(#)BagFunction.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.attr.AnyURIAttribute;
40 import com.sun.xacml.attr.Base64BinaryAttribute;
41 import com.sun.xacml.attr.BooleanAttribute;
42 import com.sun.xacml.attr.DateAttribute;
43 import com.sun.xacml.attr.DateTimeAttribute;
44 import com.sun.xacml.attr.DayTimeDurationAttribute;
45 import com.sun.xacml.attr.DoubleAttribute;
46 import com.sun.xacml.attr.HexBinaryAttribute;
47 import com.sun.xacml.attr.IntegerAttribute;
48 import com.sun.xacml.attr.RFC822NameAttribute;
49 import com.sun.xacml.attr.StringAttribute;
50 import com.sun.xacml.attr.TimeAttribute;
51 import com.sun.xacml.attr.X500NameAttribute;
52 import com.sun.xacml.attr.YearMonthDurationAttribute;
53
54 import java.util.HashSet;
55 import java.util.Set;
56
57
58 /**
59 * Represents all of the Bag functions, though the actual implementations
60 * are in two sub-classes specific to the condition and general bag
61 * functions.
62 *
63 * @since 1.0
64 * @author Seth Proctor
65 */
66 public abstract class BagFunction extends FunctionBase
67 {
68
69 /**
70 * Base name for the type-one-and-only funtions. To get the standard
71 * identifier for a given type, use <code>FunctionBase.FUNCTION_NS</code>
72 * + the datatype's base name (e.g., <code>string</code>) +
73 * </code>NAME_BASE_ONE_AND_ONLY</code>.
74 */
75 public static final String NAME_BASE_ONE_AND_ONLY =
76 "-one-and-only";
77
78 /**
79 * Base name for the type-bag-size funtions. To get the standard
80 * identifier for a given type, use <code>FunctionBase.FUNCTION_NS</code>
81 * + the datatype's base name (e.g., <code>string</code>) +
82 * </code>NAME_BASE_BAG_SIZE</code>.
83 */
84 public static final String NAME_BASE_BAG_SIZE =
85 "-bag-size";
86
87 /**
88 * Base name for the type-is-in. To get the standard
89 * identifier for a given type, use <code>FunctionBase.FUNCTION_NS</code>
90 * + the datatype's base name (e.g., <code>string</code>) +
91 * </code>NAME_BASE_IS_IN</code>.
92 */
93 public static final String NAME_BASE_IS_IN =
94 "-is-in";
95
96 /**
97 * Base name for the type-bag funtions. To get the standard
98 * identifier for a given type, use <code>FunctionBase.FUNCTION_NS</code>
99 * + the datatype's base name (e.g., <code>string</code>) +
100 * </code>NAME_BASE_BAG</code>.
101 */
102 public static final String NAME_BASE_BAG =
103 "-bag";
104
105 // bag parameter info for the functions that accept multiple args
106 private static final boolean bagParams [] = { false, true };
107
108 /**
109 * A complete list of all the XACML datatypes supported by the Bag
110 * functions
111 */
112 protected static String baseTypes [] = {
113 StringAttribute.identifier,
114 BooleanAttribute.identifier,
115 IntegerAttribute.identifier,
116 DoubleAttribute.identifier,
117 DateAttribute.identifier,
118 DateTimeAttribute.identifier,
119 TimeAttribute.identifier,
120 AnyURIAttribute.identifier,
121 HexBinaryAttribute.identifier,
122 Base64BinaryAttribute.identifier,
123 DayTimeDurationAttribute.identifier,
124 YearMonthDurationAttribute.identifier,
125 X500NameAttribute.identifier,
126 RFC822NameAttribute.identifier
127 };
128
129 /**
130 * A complete list of all the XACML datatypes supported by the Bag
131 * functions, using the "simple" form of the names (eg, string
132 * instead of http://www.w3.org/2001/XMLSchema#string)
133 */
134 protected static String simpleTypes [] = {
135 "string", "boolean", "integer", "double", "date", "dateTime",
136 "time", "anyURI", "hexBinary", "base64Binary", "dayTimeDuration",
137 "yearMonthDuration", "x500Name", "rfc822Name"
138 };
139
140 /**
141 * Returns a new <code>BagFunction</code> that provides the
142 * type-one-and-only functionality over the given attribute type.
143 * This should be used to create new function instances for any new
144 * attribute types, and the resulting object should be put into
145 * the <code>FunctionFactory</code> (instances already exist in the
146 * factory for the standard attribute types).
147 *
148 * @param functionName the name to use for the function
149 * @param argumentType the type to operate on
150 *
151 * @return a new <code>BagFunction</code>
152 */
153 public static BagFunction getOneAndOnlyInstance(String functionName,
154 String argumentType) {
155 return new GeneralBagFunction(functionName, argumentType,
156 NAME_BASE_ONE_AND_ONLY);
157 }
158
159 /**
160 * Returns a new <code>BagFunction</code> that provides the
161 * type-bag-size functionality over the given attribute type. This
162 * should be used to create new function instances for any new
163 * attribute types, and the resulting object should be put into
164 * the <code>FunctionFactory</code> (instances already exist in the
165 * factory for the standard attribute types).
166 *
167 * @param functionName the name to use for the function
168 * @param argumentType the type to operate on
169 *
170 * @return a new <code>BagFunction</code>
171 */
172 public static BagFunction getBagSizeInstance(String functionName,
173 String argumentType) {
174 return new GeneralBagFunction(functionName, argumentType,
175 NAME_BASE_BAG_SIZE);
176 }
177
178 /**
179 * Returns a new <code>BagFunction</code> that provides the
180 * type-is-in functionality over the given attribute type. This
181 * should be used to create new function instances for any new
182 * attribute types, and the resulting object should be put into
183 * the <code>FunctionFactory</code> (instances already exist in the
184 * factory for the standard attribute types).
185 *
186 * @param functionName the name to use for the function
187 * @param argumentType the type to operate on
188 *
189 * @return a new <code>BagFunction</code>
190 */
191 public static BagFunction getIsInInstance(String functionName,
192 String argumentType) {
193 return new ConditionBagFunction(functionName, argumentType);
194 }
195
196 /**
197 * Returns a new <code>BagFunction</code> that provides the
198 * type-bag functionality over the given attribute type. This
199 * should be used to create new function instances for any new
200 * attribute types, and the resulting object should be put into
201 * the <code>FunctionFactory</code> (instances already exist in the
202 * factory for the standard attribute types).
203 *
204 * @param functionName the name to use for the function
205 * @param argumentType the type to operate on
206 *
207 * @return a new <code>BagFunction</code>
208 */
209 public static BagFunction getBagInstance(String functionName,
210 String argumentType) {
211 return new GeneralBagFunction(functionName, argumentType,
212 NAME_BASE_BAG);
213 }
214
215 /**
216 * Protected constuctor used by the general and condition subclasses
217 * to create a non-boolean function with parameters of the same datatype.
218 * If you need to create a new <code>BagFunction</code> instance you
219 * should either use one of the <code>getInstance</code> methods or
220 * construct one of the sub-classes directly.
221 *
222 * @param functionName the identitifer for the function
223 * @param functionId an optional, internal numeric identifier
224 * @param paramType the datatype this function accepts
225 * @param paramIsBag whether the parameters are bags
226 * @param numParams number of parameters allowed or -1 for any number
227 * @param returnType the datatype this function returns
228 * @param returnsBag whether this function returns bags
229 */
230 protected BagFunction(String functionName, int functionId,
231 String paramType, boolean paramIsBag, int numParams,
232 String returnType, boolean returnsBag) {
233 super(functionName, functionId, paramType, paramIsBag, numParams,
234 returnType, returnsBag);
235 }
236
237 /**
238 * Protected constuctor used by the general and condition subclasses
239 * to create a boolean function with parameters of different datatypes.
240 * If you need to create a new <code>BagFunction</code> instance you
241 * should either use one of the <code>getInstance</code> methods or
242 * construct one of the sub-classes directly.
243 *
244 * @param functionName the identitifer for the function
245 * @param functionId an optional, internal numeric identifier
246 * @param paramTypes the datatype of each parameter
247 */
248 protected BagFunction(String functionName, int functionId,
249 String [] paramTypes) {
250 super(functionName, functionId, paramTypes, bagParams,
251 BooleanAttribute.identifier, false);
252 }
253
254 /**
255 * Returns a <code>Set</code> containing all the function identifiers
256 * supported by this class.
257 *
258 * @return a <code>Set</code> of <code>String</code>s
259 */
260 public static Set getSupportedIdentifiers() {
261 Set set = new HashSet();
262
263 set.addAll(ConditionBagFunction.getSupportedIdentifiers());
264 set.addAll(GeneralBagFunction.getSupportedIdentifiers());
265
266 return set;
267 }
268
269 }