author | sspitsyn |
Wed, 07 Sep 2016 03:35:45 +0000 | |
changeset 40963 | c7c990c4ec68 |
parent 32029 | a5538163e144 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
package javax.naming.spi; |
|
26 |
||
27 |
import javax.naming.*; |
|
28 |
import javax.naming.directory.Attributes; |
|
29 |
import java.util.Hashtable; |
|
30 |
||
31 |
/** |
|
32 |
* This interface represents a factory for obtaining the state of an |
|
33 |
* object and corresponding attributes for binding. |
|
34 |
*<p> |
|
35 |
* The JNDI framework allows for object implementations to |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
36 |
* be loaded in dynamically via {@code object factories}. |
2 | 37 |
* <p> |
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
38 |
* A {@code DirStateFactory} extends {@code StateFactory} |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
39 |
* by allowing an {@code Attributes} instance |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
40 |
* to be supplied to and be returned by the {@code getStateToBind()} method. |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
41 |
* {@code DirStateFactory} implementations are intended to be used by |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
42 |
* {@code DirContext} service providers. |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
43 |
* When a caller binds an object using {@code DirContext.bind()}, |
2 | 44 |
* he might also specify a set of attributes to be bound with the object. |
45 |
* The object and attributes to be bound are passed to |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
46 |
* the {@code getStateToBind()} method of a factory. |
2 | 47 |
* If the factory processes the object and attributes, it returns |
48 |
* a corresponding pair of object and attributes to be bound. |
|
49 |
* If the factory does not process the object, it must return null. |
|
50 |
*<p> |
|
51 |
* For example, a caller might bind a printer object with some printer-related |
|
52 |
* attributes. |
|
53 |
*<blockquote><pre> |
|
54 |
* ctx.rebind("inky", printer, printerAttrs); |
|
55 |
*</pre></blockquote> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
56 |
* An LDAP service provider for {@code ctx} uses a {@code DirStateFactory} |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
57 |
* (indirectly via {@code DirectoryManager.getStateToBind()}) |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
58 |
* and gives it {@code printer} and {@code printerAttrs}. A factory for |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
59 |
* an LDAP directory might turn {@code printer} into a set of attributes |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
60 |
* and merge that with {@code printerAttrs}. The service provider then |
2 | 61 |
* uses the resulting attributes to create an LDAP entry and updates |
62 |
* the directory. |
|
63 |
* |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
64 |
* <p> Since {@code DirStateFactory} extends {@code StateFactory}, it |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
65 |
* has two {@code getStateToBind()} methods, where one |
2 | 66 |
* differs from the other by the attributes |
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
67 |
* argument. {@code DirectoryManager.getStateToBind()} will only use |
2 | 68 |
* the form that accepts the attributes argument, while |
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
69 |
* {@code NamingManager.getStateToBind()} will only use the form that |
2 | 70 |
* does not accept the attributes argument. |
71 |
* |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
72 |
* <p> Either form of the {@code getStateToBind()} method of a |
2 | 73 |
* DirStateFactory may be invoked multiple times, possibly using different |
74 |
* parameters. The implementation is thread-safe. |
|
75 |
* |
|
76 |
* @author Rosanna Lee |
|
77 |
* @author Scott Seligman |
|
78 |
* |
|
79 |
* @see DirectoryManager#getStateToBind |
|
80 |
* @see DirObjectFactory |
|
81 |
* @since 1.3 |
|
82 |
*/ |
|
83 |
public interface DirStateFactory extends StateFactory { |
|
84 |
/** |
|
85 |
* Retrieves the state of an object for binding given the object and attributes |
|
86 |
* to be transformed. |
|
87 |
*<p> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
88 |
* {@code DirectoryManager.getStateToBind()} |
2 | 89 |
* successively loads in state factories. If a factory implements |
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
90 |
* {@code DirStateFactory}, {@code DirectoryManager} invokes this method; |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
91 |
* otherwise, it invokes {@code StateFactory.getStateToBind()}. |
2 | 92 |
* It does this until a factory produces a non-null answer. |
93 |
*<p> |
|
94 |
* When an exception is thrown by a factory, |
|
95 |
* the exception is passed on to the caller |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
96 |
* of {@code DirectoryManager.getStateToBind()}. The search for other factories |
2 | 97 |
* that may produce a non-null answer is halted. |
98 |
* A factory should only throw an exception if it is sure that |
|
99 |
* it is the only intended factory and that no other factories |
|
100 |
* should be tried. |
|
101 |
* If this factory cannot create an object using the arguments supplied, |
|
102 |
* it should return null. |
|
103 |
* <p> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
104 |
* The {@code name} and {@code nameCtx} parameters may |
2 | 105 |
* optionally be used to specify the name of the object being created. |
106 |
* See the description of "Name and Context Parameters" in |
|
107 |
* {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()} |
|
108 |
* for details. |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
109 |
* If a factory uses {@code nameCtx} it should synchronize its use |
2 | 110 |
* against concurrent access, since context implementations are not |
111 |
* guaranteed to be thread-safe. |
|
112 |
*<p> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
113 |
* The {@code name}, {@code inAttrs}, and {@code environment} parameters |
2 | 114 |
* are owned by the caller. |
115 |
* The implementation will not modify these objects or keep references |
|
116 |
* to them, although it may keep references to clones or copies. |
|
117 |
* The object returned by this method is owned by the caller. |
|
118 |
* The implementation will not subsequently modify it. |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
119 |
* It will contain either a new {@code Attributes} object that is |
2 | 120 |
* likewise owned by the caller, or a reference to the original |
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
121 |
* {@code inAttrs} parameter. |
2 | 122 |
* |
123 |
* @param obj A possibly null object whose state is to be retrieved. |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
124 |
* @param name The name of this object relative to {@code nameCtx}, |
2 | 125 |
* or null if no name is specified. |
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
126 |
* @param nameCtx The context relative to which the {@code name} |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
127 |
* parameter is specified, or null if {@code name} is |
2 | 128 |
* relative to the default initial context. |
129 |
* @param environment The possibly null environment to |
|
130 |
* be used in the creation of the object's state. |
|
131 |
* @param inAttrs The possibly null attributes to be bound with the object. |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
132 |
* The factory must not modify {@code inAttrs}. |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
133 |
* @return A {@code Result} containing the object's state for binding |
2 | 134 |
* and the corresponding |
135 |
* attributes to be bound; null if the object don't use this factory. |
|
136 |
* @exception NamingException If this factory encountered an exception |
|
137 |
* while attempting to get the object's state, and no other factories are |
|
138 |
* to be tried. |
|
139 |
* |
|
140 |
* @see DirectoryManager#getStateToBind |
|
141 |
*/ |
|
142 |
public Result getStateToBind(Object obj, Name name, Context nameCtx, |
|
143 |
Hashtable<?,?> environment, |
|
144 |
Attributes inAttrs) |
|
145 |
throws NamingException; |
|
146 |
||
147 |
||
148 |
/** |
|
149 |
* An object/attributes pair for returning the result of |
|
150 |
* DirStateFactory.getStateToBind(). |
|
151 |
*/ |
|
152 |
public static class Result { |
|
153 |
/** |
|
154 |
* The possibly null object to be bound. |
|
155 |
*/ |
|
156 |
private Object obj; |
|
157 |
||
158 |
||
159 |
/** |
|
160 |
* The possibly null attributes to be bound. |
|
161 |
*/ |
|
162 |
private Attributes attrs; |
|
163 |
||
164 |
/** |
|
165 |
* Constructs an instance of Result. |
|
166 |
* |
|
167 |
* @param obj The possibly null object to be bound. |
|
168 |
* @param outAttrs The possibly null attributes to be bound. |
|
169 |
*/ |
|
170 |
public Result(Object obj, Attributes outAttrs) { |
|
171 |
this.obj = obj; |
|
172 |
this.attrs = outAttrs; |
|
173 |
} |
|
174 |
||
175 |
/** |
|
176 |
* Retrieves the object to be bound. |
|
177 |
* @return The possibly null object to be bound. |
|
178 |
*/ |
|
179 |
public Object getObject() { return obj; }; |
|
180 |
||
181 |
/** |
|
182 |
* Retrieves the attributes to be bound. |
|
183 |
* @return The possibly null attributes to be bound. |
|
184 |
*/ |
|
185 |
public Attributes getAttributes() { return attrs; }; |
|
186 |
||
187 |
} |
|
188 |
} |