Source code: com/sun/xacml/finder/ResourceFinderResult.java
1
2 /*
3 * @(#)ResourceFinderResult.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.finder;
38
39 import java.util.Collections;
40 import java.util.HashMap;
41 import java.util.HashSet;
42 import java.util.Map;
43 import java.util.Set;
44
45
46 /**
47 * This is used to return Resource Ids from the ResourceFinder. Unlike the
48 * PolicyFinder, this never returns an empty set, since it will always
49 * contain at least the original parent resource. This class will provide
50 * two sets of identifiers: those that were successfully resolved and those
51 * that had an error.
52 *
53 * @since 1.0
54 * @author Seth Proctor
55 */
56 public class ResourceFinderResult
57 {
58
59 // the set of resource identifiers
60 private Set resources;
61
62 // the map of failed identifiers to their failure status data
63 private Map failures;
64
65 // a flag specifying whether or not result contains resource listings
66 private boolean empty;
67
68 /**
69 * Creates an empty result.
70 */
71 public ResourceFinderResult() {
72 resources = Collections.unmodifiableSet(new HashSet());
73 failures = Collections.unmodifiableMap(new HashMap());
74 empty = true;
75 }
76
77 /**
78 * Creates a result containing the given <code>Set</code> of resource
79 * identifiers. The <code>Set</code>must not be null. The new
80 * <code>ResourceFinderResult</code> represents a resource retrieval that
81 * encountered no errors.
82 *
83 * @param resources a non-null <code>Set</code> of
84 * <code>AttributeValue</code>s
85 */
86 public ResourceFinderResult(Set resources) {
87 this(resources, new HashMap());
88 }
89
90 /**
91 * Creates a result containing only Resource Ids that caused errors. The
92 * <code>Map</code> must not be null. The keys in the <code>Map</code>
93 * are <code>AttributeValue</code>s identifying the resources that could
94 * not be resolved, and they map to a <code>Status</code> object
95 * explaining the error. The new <code>ResourceFinderResult</code>
96 * represents a resource retrieval that did not succeed in finding any
97 * resource identifiers.
98 *
99 * @param failures a non-null <code>Map</code> mapping failed
100 * <code>AttributeValue</code> identifiers to their
101 * <code>Status</code>
102 */
103 public ResourceFinderResult(HashMap failures) {
104 this(new HashSet(), failures);
105 }
106
107 /**
108 * Creates a new result containing both successfully resolved Resource Ids
109 * and resources that caused errors.
110 *
111 * @param resources a non-null <code>Set</code> of
112 * <code>AttributeValue</code>s
113 * @param failures a non-null <code>Map</code> mapping failed
114 * <code>AttributeValue</code> identifiers to their
115 * <code>Status</code>
116 */
117 public ResourceFinderResult(Set resources, Map failures) {
118 this.resources = Collections.unmodifiableSet(new HashSet(resources));
119 this.failures = Collections.unmodifiableMap(new HashMap(failures));
120 empty = false;
121 }
122
123 /**
124 * Returns whether or not this result contains any Resource Id listings.
125 * This will return false if either the set of successfully resolved
126 * resource identifiers or the map of failed resources is not empty.
127 *
128 * @return false if this result names any resources, otherwise true
129 */
130 public boolean isEmpty() {
131 return empty;
132 }
133
134 /**
135 * Returns the <code>Set</code> of successfully resolved Resource Id
136 * <code>AttributeValue</code>s, which will be empty if no resources
137 * were successfully resolved.
138 *
139 * @return a <code>Set</code> of <code>AttributeValue</code>s
140 */
141 public Set getResources() {
142 return resources;
143 }
144
145 /**
146 * Returns the <code>Map</code> of Resource Ids that caused an error on
147 * resolution, which will be empty if no resources caused any error.
148 *
149 * @return a <code>Map</code> of <code>AttributeValue</code>s to
150 * <code>Status</code>
151 */
152 public Map getFailures() {
153 return failures;
154 }
155
156 }