src/java.naming/share/classes/javax/naming/spi/DirStateFactory.java
author herrick
Tue, 24 Sep 2019 13:41:16 -0400
branchJDK-8200758-branch
changeset 58301 e0efb29609bd
parent 47216 71c04702a3d5
permissions -rw-r--r--
8225249 : LinuxDebBundler and LinuxRpmBundler should share more code Submitted-by: asemenyuk Reviewed-by: herrick, almatvee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2004, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.naming.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.naming.directory.Attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
  * This interface represents a factory for obtaining the state of an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  * object and corresponding attributes for binding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  * he might also specify a set of attributes to be bound with the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  * If the factory processes the object and attributes, it returns
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  * a corresponding pair of object and attributes to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  * If the factory does not process the object, it must return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  * For example, a caller might bind a printer object with some printer-related
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  * attributes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
  *<blockquote><pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
  * ctx.rebind("inky", printer, printerAttrs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
  * uses the resulting attributes to create an LDAP entry and updates
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
  * the directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  * does not accept the attributes argument.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  * DirStateFactory may be invoked multiple times, possibly using different
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
  * parameters.  The implementation is thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  * @see DirectoryManager#getStateToBind
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
  * @see DirObjectFactory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
public interface DirStateFactory extends StateFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Retrieves the state of an object for binding given the object and attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * to be transformed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * It does this until a factory produces a non-null answer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * When an exception is thrown by a factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * that may produce a non-null answer is halted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * A factory should only throw an exception if it is sure that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * it is the only intended factory and that no other factories
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * should be tried.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * If this factory cannot create an object using the arguments supplied,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * it should return null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * optionally be used to specify the name of the object being created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * See the description of "Name and Context Parameters" in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * {@link ObjectFactory#getObjectInstance ObjectFactory.getObjectInstance()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * against concurrent access, since context implementations are not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 * guaranteed to be thread-safe.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * are owned by the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * The implementation will not modify these objects or keep references
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * to them, although it may keep references to clones or copies.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * The object returned by this method is owned by the caller.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 *              relative to the default initial context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * @param environment The possibly null environment to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *              be used in the creation of the object's state.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * and the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * attributes to be bound; null if the object don't use this factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * @exception NamingException If this factory encountered an exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * while attempting to get the object's state, and no other factories are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * to be tried.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * @see DirectoryManager#getStateToBind
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    public Result getStateToBind(Object obj, Name name, Context nameCtx,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                                 Hashtable<?,?> environment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
                                 Attributes inAttrs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        throws NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         * An object/attributes pair for returning the result of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
         * DirStateFactory.getStateToBind().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public static class Result {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * The possibly null object to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        private Object obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         * The possibly null attributes to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        private Attributes attrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
          * Constructs an instance of Result.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
          *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
          * @param obj The possibly null object to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
          * @param outAttrs The possibly null attributes to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
          */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        public Result(Object obj, Attributes outAttrs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            this.obj = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            this.attrs = outAttrs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         * Retrieves the object to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
         * @return The possibly null object to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        public Object getObject() { return obj; };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
         * Retrieves the attributes to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
         * @return The possibly null attributes to be bound.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        public Attributes getAttributes() { return attrs; };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
}