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

Quick Search    Search Deep

Source code: com/sun/xacml/attr/StandardAttributeFactory.java


1   
2   /*
3    * @(#)StandardAttributeFactory
4    *
5    * Copyright 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.attr;
38  
39  import com.sun.xacml.attr.proxy.AnyURIAttributeProxy;
40  import com.sun.xacml.attr.proxy.Base64BinaryAttributeProxy;
41  import com.sun.xacml.attr.proxy.BooleanAttributeProxy;
42  import com.sun.xacml.attr.proxy.DateAttributeProxy;
43  import com.sun.xacml.attr.proxy.DateTimeAttributeProxy;
44  import com.sun.xacml.attr.proxy.DayTimeDurationAttributeProxy;
45  import com.sun.xacml.attr.proxy.DoubleAttributeProxy;
46  import com.sun.xacml.attr.proxy.HexBinaryAttributeProxy;
47  import com.sun.xacml.attr.proxy.IntegerAttributeProxy;
48  import com.sun.xacml.attr.proxy.RFC822NameAttributeProxy;
49  import com.sun.xacml.attr.proxy.StringAttributeProxy;
50  import com.sun.xacml.attr.proxy.TimeAttributeProxy;
51  import com.sun.xacml.attr.proxy.YearMonthDurationAttributeProxy;
52  import com.sun.xacml.attr.proxy.X500NameAttributeProxy;
53  
54  import java.util.Collections;
55  import java.util.HashMap;
56  import java.util.Iterator;
57  import java.util.Map;
58  
59  import java.util.logging.Logger;
60  
61  import org.w3c.dom.Node;
62  
63  
64  /**
65   * This factory supports the standard set of datatypes specified in XACML
66   * 1.0 and 1.1. It is the default factory used by the system, and imposes
67   * a singleton pattern insuring that there is only ever one instance of
68   * this class.
69   * <p>
70   * Note that because this supports only the standard datatypes, this
71   * factory does not allow the addition of any other datatypes. If you call
72   * <code>addDatatype</code> on an instance of this class, an exception
73   * will be thrown. If you need a standard factory that is modifiable, you
74   * should create a new <code>BaseAttributeFactory</code> (or some other
75   * <code>AttributeFactory</code>) and configure it with the standard
76   * datatypes using <code>addStandardDatatypes</code> (or, in the case of
77   * <code>BaseAttributeFactory</code>, by providing the datatypes in the
78   * constructor).
79   *
80   * @since 1.2
81   * @author Seth Proctor
82   */
83  public class StandardAttributeFactory extends BaseAttributeFactory
84  {
85  
86      // the one instance of this factory
87      private static StandardAttributeFactory factoryInstance = null;
88  
89      // the datatypes supported by this factory
90      private static Map supportedDatatypes = null;
91  
92      // the logger we'll use for all messages
93      private static final Logger logger =
94          Logger.getLogger(StandardAttributeFactory.class.getName());
95  
96      /**
97       * Private constructor that sets up proxies for all of the standard
98       * datatypes.
99       */
100     private StandardAttributeFactory() {
101         super(supportedDatatypes);
102     }
103 
104     /**
105      * Private initializer for the supported datatypes. This isn't called
106      * until something needs these values, and is only called once.
107      */
108     private static void initDatatypes() {
109         logger.config("Initializing standard datatypes");
110 
111         supportedDatatypes = new HashMap();
112 
113         supportedDatatypes.put(BooleanAttribute.identifier,
114                                new BooleanAttributeProxy());
115         supportedDatatypes.put(StringAttribute.identifier,
116                                new StringAttributeProxy());
117         supportedDatatypes.put(DateAttribute.identifier,
118                                new DateAttributeProxy());
119         supportedDatatypes.put(TimeAttribute.identifier,
120                                new TimeAttributeProxy());
121         supportedDatatypes.put(DateTimeAttribute.identifier,
122                                new DateTimeAttributeProxy());
123         supportedDatatypes.put(DayTimeDurationAttribute.identifier,
124                                new DayTimeDurationAttributeProxy());
125         supportedDatatypes.put(YearMonthDurationAttribute.identifier,
126                                new YearMonthDurationAttributeProxy());
127         supportedDatatypes.put(DoubleAttribute.identifier,
128                                new DoubleAttributeProxy());
129         supportedDatatypes.put(IntegerAttribute.identifier,
130                                new IntegerAttributeProxy());
131         supportedDatatypes.put(AnyURIAttribute.identifier,
132                                new AnyURIAttributeProxy());
133         supportedDatatypes.put(HexBinaryAttribute.identifier,
134                                new HexBinaryAttributeProxy());
135         supportedDatatypes.put(Base64BinaryAttribute.identifier,
136                                new Base64BinaryAttributeProxy());
137         supportedDatatypes.put(X500NameAttribute.identifier,
138                                new X500NameAttributeProxy());
139         supportedDatatypes.put(RFC822NameAttribute.identifier,
140                                new RFC822NameAttributeProxy());
141     }
142 
143     /**
144      * Returns an instance of this factory. This method enforces a singleton
145      * model, meaning that this always returns the same instance, creating
146      * the factory if it hasn't been requested before. This is the default
147      * model used by the <code>AttributeFactory</code>, ensuring quick
148      * access to this factory.
149      *
150      * @return the factory instance
151      */
152     public static StandardAttributeFactory getFactory() {
153         if (factoryInstance == null) {
154             synchronized (StandardAttributeFactory.class) {
155                 if (factoryInstance == null) {
156                     initDatatypes();
157                     factoryInstance = new StandardAttributeFactory();
158                 }
159             }
160         }
161 
162         return factoryInstance;
163     }
164 
165     /**
166      * Returns the set of datatypes that this standard factory supports.
167      *
168      * @return a <code>Map</code> of <code>String</code> to
169      *         <code>AttributeProxy</code>s
170      */
171     public Map getStandardDatatypes() {
172         return Collections.unmodifiableMap(supportedDatatypes);
173     }
174 
175     /**
176      * Throws an <code>UnsupportedOperationException</code> since you are not
177      * allowed to modify what a standard factory supports.
178      *
179      * @param id the name of the attribute type
180      * @param proxy the proxy used to create new attributes of the given type
181      *
182      * @throws UnsupportedOperationException always
183      */
184     public void addDatatype(String id, AttributeProxy proxy) {
185         throw new UnsupportedOperationException("a standard factory cannot " +
186                                                 "support new datatypes");
187     }
188 
189 }