src/java.naming/share/classes/javax/naming/spi/ResolveResult.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 25859 jdk/src/java.naming/share/classes/javax/naming/spi/ResolveResult.java@3317bb8137f4
child 58531 9b40d05c9f66
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.naming.spi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.naming.Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.naming.Context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.naming.CompositeName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.naming.InvalidNameException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  * This class represents the result of resolution of a name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  * It contains the object to which name was resolved, and the portion
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  * of the name that has not been resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  * A ResolveResult instance is not synchronized against concurrent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * multithreaded access. Multiple threads trying to access and modify
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  * a single ResolveResult instance should lock the object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  * @author Scott Seligman
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  * @since 1.3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
public class ResolveResult implements java.io.Serializable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     * Field containing the Object that was resolved to successfully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     * It can be null only when constructed using a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     * Constructors should always initialize this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    protected Object resolvedObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * Field containing the remaining name yet to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * It can be null only when constructed using a subclass.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * Constructors should always initialize this.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    protected Name remainingName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
      * Constructs an instance of ResolveResult with the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
      * resolved object and remaining name both initialized to null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    protected ResolveResult() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        resolvedObj = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        remainingName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
      * Constructs a new instance of ResolveResult consisting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
      * the resolved object and the remaining unresolved component.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
      * @param robj The non-null object resolved to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
      * @param rcomp The single remaining name component that has yet to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
      *                 resolved. Cannot be null (but can be empty).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public ResolveResult(Object robj, String rcomp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        resolvedObj = robj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        remainingName = new CompositeName(rcomp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
//          remainingName.appendComponent(rcomp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            // ignore; shouldn't happen
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
      * Constructs a new instance of ResolveResult consisting of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
      * the resolved Object and the remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
      * @param robj The non-null Object resolved to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
      * @param rname The non-null remaining name that has yet to be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    public ResolveResult(Object robj, Name rname) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        resolvedObj = robj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        setRemainingName(rname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * Retrieves the remaining unresolved portion of the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * @return The remaining unresolved portion of the name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *          Cannot be null but empty OK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @see #appendRemainingName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * @see #appendRemainingComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see #setRemainingName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    public Name getRemainingName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        return this.remainingName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Retrieves the Object to which resolution was successful.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @return The Object to which resolution was successful. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
      * @see #setResolvedObj
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    public Object getResolvedObj() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return this.resolvedObj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
      * Sets the remaining name field of this result to name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
      * A copy of name is made so that modifying the copy within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
      * this ResolveResult does not affect <code>name</code> and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
      * vice versa.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
      * @param name The name to set remaining name to. Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
      * @see #getRemainingName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
      * @see #appendRemainingName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
      * @see #appendRemainingComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    public void setRemainingName(Name name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (name != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            this.remainingName = (Name)(name.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            // ??? should throw illegal argument exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            this.remainingName = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
      * Adds components to the end of remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
      * @param name The components to add. Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
      * @see #getRemainingName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
      * @see #setRemainingName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
      * @see #appendRemainingComponent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    public void appendRemainingName(Name name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
//      System.out.println("appendingRemainingName: " + name.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
//      Exception e = new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
//      e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            if (this.remainingName != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    this.remainingName.addAll(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                    // ignore; shouldn't happen for composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                this.remainingName = (Name)(name.clone());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
      * Adds a single component to the end of remaining name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
      * @param name The component to add. Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
      * @see #getRemainingName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
      * @see #appendRemainingName
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public void appendRemainingComponent(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (name != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            CompositeName rname = new CompositeName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                rname.add(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            } catch (InvalidNameException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                // ignore; shouldn't happen for empty composite name
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            appendRemainingName(rname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
      * Sets the resolved Object field of this result to obj.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
      *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
      * @param obj The object to use for setting the resolved obj field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
      *            Cannot be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
      * @see #getResolvedObj
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
      */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
    public void setResolvedObj(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        this.resolvedObj = obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        // ??? should check for null?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    private static final long serialVersionUID = -4552108072002407559L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
}