author | sspitsyn |
Wed, 07 Sep 2016 03:35:45 +0000 | |
changeset 40963 | c7c990c4ec68 |
parent 36511 | 9d0388c6b336 |
child 45132 | db2f2d72cd4f |
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 |
||
26 |
package javax.naming.spi; |
|
27 |
||
28 |
import java.util.Hashtable; |
|
29 |
||
30 |
import javax.naming.*; |
|
31 |
||
32 |
/** |
|
33 |
* This interface represents a factory for creating an object. |
|
34 |
*<p> |
|
35 |
* The JNDI framework allows for object implementations to |
|
36 |
* be loaded in dynamically via <em>object factories</em>. |
|
37 |
* For example, when looking up a printer bound in the name space, |
|
38 |
* if the print service binds printer names to References, the printer |
|
39 |
* Reference could be used to create a printer object, so that |
|
40 |
* the caller of lookup can directly operate on the printer object |
|
41 |
* after the lookup. |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
42 |
* <p>An {@code ObjectFactory} is responsible |
2 | 43 |
* for creating objects of a specific type. In the above example, |
44 |
* you may have a PrinterObjectFactory for creating Printer objects. |
|
45 |
*<p> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
46 |
* An object factory must implement the {@code ObjectFactory} interface. |
2 | 47 |
* In addition, the factory class must be public and must have a |
48 |
* public constructor that accepts no parameters. |
|
36511 | 49 |
* Note that in cases where the factory is in a named module then it must be |
50 |
* in a package which is exported by that module to the {@code java.naming} |
|
51 |
* module. |
|
2 | 52 |
*<p> |
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
53 |
* The {@code getObjectInstance()} method of an object factory may |
2 | 54 |
* be invoked multiple times, possibly using different parameters. |
55 |
* The implementation is thread-safe. |
|
56 |
*<p> |
|
57 |
* The mention of URL in the documentation for this class refers to |
|
58 |
* a URL string as defined by RFC 1738 and its related RFCs. It is |
|
59 |
* any string that conforms to the syntax described therein, and |
|
60 |
* may not always have corresponding support in the java.net.URL |
|
61 |
* class or Web browsers. |
|
62 |
* |
|
63 |
* @author Rosanna Lee |
|
64 |
* @author Scott Seligman |
|
65 |
* |
|
66 |
* @see NamingManager#getObjectInstance |
|
67 |
* @see NamingManager#getURLContext |
|
68 |
* @see ObjectFactoryBuilder |
|
69 |
* @see StateFactory |
|
70 |
* @since 1.3 |
|
71 |
*/ |
|
72 |
||
73 |
public interface ObjectFactory { |
|
74 |
/** |
|
75 |
* Creates an object using the location or reference information |
|
76 |
* specified. |
|
77 |
* <p> |
|
78 |
* Special requirements of this object are supplied |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
79 |
* using {@code environment}. |
2 | 80 |
* An example of such an environment property is user identity |
81 |
* information. |
|
82 |
*<p> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
83 |
* {@code NamingManager.getObjectInstance()} |
2 | 84 |
* successively loads in object factories and invokes this method |
85 |
* on them until one produces a non-null answer. When an exception |
|
86 |
* is thrown by an object factory, 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
|
87 |
* of {@code NamingManager.getObjectInstance()} |
2 | 88 |
* (and no search is made for other factories |
89 |
* that may produce a non-null answer). |
|
90 |
* An object factory should only throw an exception if it is sure that |
|
91 |
* it is the only intended factory and that no other object factories |
|
92 |
* should be tried. |
|
93 |
* If this factory cannot create an object using the arguments supplied, |
|
94 |
* it should return null. |
|
95 |
*<p> |
|
96 |
* A <em>URL context factory</em> is a special ObjectFactory that |
|
97 |
* creates contexts for resolving URLs or objects whose locations |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
98 |
* are specified by URLs. The {@code getObjectInstance()} method |
2 | 99 |
* of a URL context factory will obey the following rules. |
100 |
* <ol> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
101 |
* <li>If {@code obj} is null, create a context for resolving URLs of the |
2 | 102 |
* scheme associated with this factory. The resulting context is not tied |
103 |
* to a specific URL: it is able to handle arbitrary URLs with this factory's |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
104 |
* scheme id. For example, invoking {@code getObjectInstance()} with |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
105 |
* {@code obj} set to null on an LDAP URL context factory would return a |
2 | 106 |
* context that can resolve LDAP URLs |
107 |
* such as "ldap://ldap.wiz.com/o=wiz,c=us" and |
|
108 |
* "ldap://ldap.umich.edu/o=umich,c=us". |
|
109 |
* <li> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
110 |
* If {@code obj} is a URL string, create an object (typically a context) |
2 | 111 |
* identified by the URL. For example, suppose this is an LDAP URL context |
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
112 |
* factory. If {@code obj} is "ldap://ldap.wiz.com/o=wiz,c=us", |
2 | 113 |
* getObjectInstance() would return the context named by the distinguished |
114 |
* name "o=wiz, c=us" at the LDAP server ldap.wiz.com. This context can |
|
115 |
* then be used to resolve LDAP names (such as "cn=George") |
|
116 |
* relative to that context. |
|
117 |
* <li> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
118 |
* If {@code obj} is an array of URL strings, the assumption is that the |
2 | 119 |
* URLs are equivalent in terms of the context to which they refer. |
120 |
* Verification of whether the URLs are, or need to be, equivalent is up |
|
121 |
* to the context factory. The order of the URLs in the array is |
|
122 |
* not significant. |
|
123 |
* The object returned by getObjectInstance() is like that of the single |
|
124 |
* URL case. It is the object named by the URLs. |
|
125 |
* <li> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
126 |
* If {@code obj} is of any other type, the behavior of |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
127 |
* {@code getObjectInstance()} is determined by the context factory |
2 | 128 |
* implementation. |
129 |
* </ol> |
|
130 |
* |
|
131 |
* <p> |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
132 |
* The {@code name} and {@code environment} parameters |
2 | 133 |
* are owned by the caller. |
134 |
* The implementation will not modify these objects or keep references |
|
135 |
* to them, although it may keep references to clones or copies. |
|
136 |
* |
|
137 |
* <p> |
|
138 |
* <b>Name and Context Parameters.</b> |
|
139 |
* <a name=NAMECTX></a> |
|
140 |
* |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
141 |
* The {@code name} and {@code nameCtx} parameters may |
2 | 142 |
* optionally be used to specify the name of the object being created. |
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
143 |
* {@code name} is the name of the object, relative to context |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
144 |
* {@code nameCtx}. |
2 | 145 |
* If there are several possible contexts from which the object |
146 |
* could be named -- as will often be the case -- it is up to |
|
147 |
* the caller to select one. A good rule of thumb is to select the |
|
148 |
* "deepest" context available. |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
149 |
* If {@code nameCtx} is null, {@code name} is relative |
2 | 150 |
* to the default initial context. If no name is being specified, the |
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
151 |
* {@code name} parameter should be null. |
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
152 |
* If a factory uses {@code nameCtx} it should synchronize its use |
2 | 153 |
* against concurrent access, since context implementations are not |
154 |
* guaranteed to be thread-safe. |
|
155 |
* |
|
156 |
* @param obj The possibly null object containing location or reference |
|
157 |
* information that can be used in creating an object. |
|
32029
a5538163e144
8132877: docs: replace <tt> tags (obsolete in html5) for javax.naming
avstepan
parents:
25859
diff
changeset
|
158 |
* @param name The name of this object relative to {@code nameCtx}, |
2 | 159 |
* 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
|
160 |
* @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
|
161 |
* parameter is specified, or null if {@code name} is |
2 | 162 |
* relative to the default initial context. |
163 |
* @param environment The possibly null environment that is used in |
|
164 |
* creating the object. |
|
165 |
* @return The object created; null if an object cannot be created. |
|
166 |
* @exception Exception if this object factory encountered an exception |
|
167 |
* while attempting to create an object, and no other object factories are |
|
168 |
* to be tried. |
|
169 |
* |
|
170 |
* @see NamingManager#getObjectInstance |
|
171 |
* @see NamingManager#getURLContext |
|
172 |
*/ |
|
173 |
public Object getObjectInstance(Object obj, Name name, Context nameCtx, |
|
174 |
Hashtable<?,?> environment) |
|
175 |
throws Exception; |
|
176 |
} |