src/java.naming/share/classes/com/sun/jndi/ldap/NamingEventNotifier.java
author rriggs
Fri, 07 Dec 2018 11:51:17 -0500
changeset 52902 e3398b2e1ab0
parent 47216 71c04702a3d5
permissions -rw-r--r--
8214971: Replace use of string.equals("") with isEmpty() Reviewed-by: jlaskey, prappo, lancea, dfuchs, redestad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
     2
 * Copyright (c) 1999, 2011, 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 com.sun.jndi.ldap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import javax.naming.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import javax.naming.directory.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import javax.naming.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import javax.naming.ldap.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import javax.naming.ldap.LdapName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jndi.toolkit.ctx.Continuation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  * Gathers information to generate events by using the Persistent Search
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  * control.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  *<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  * This class maintains a list of listeners all interested in the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  * "search" request. It creates a thread that does the persistent search
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  * and blocks, collecting the results of the search.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  * For each result that it receives from the search, it fires the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  * corresponding event to its listeners. If an exception is encountered,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
  * it fires a NamingExceptionEvent.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  * @author Rosanna Lee
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
final class NamingEventNotifier implements Runnable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private final static boolean debug = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    53
    private Vector<NamingListener> namingListeners;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    private Thread worker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    private LdapCtx context;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    private EventContext eventSrc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    private EventSupport support;
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    58
    private NamingEnumeration<SearchResult> results;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // package private; used by EventSupport to remove it
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    NotifierArgs info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    NamingEventNotifier(EventSupport support, LdapCtx ctx, NotifierArgs info,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        NamingListener firstListener) throws NamingException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        this.info = info;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        this.support = support;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        Control psearch;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            psearch = new PersistentSearchControl(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
                info.mask,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                true /* no info about original entry(s) */,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
                true /* additional info about changes */,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                Control.CRITICAL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        } catch (java.io.IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            NamingException ne = new NamingException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
                "Problem creating persistent search control");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            ne.setRootCause(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            throw ne;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        // Add psearch control to existing list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        context = (LdapCtx)ctx.newInstance(new Control[]{psearch});
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        eventSrc = ctx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
    86
        namingListeners = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        namingListeners.addElement(firstListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        worker = Obj.helper.createThread(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        worker.setDaemon(true);  // not a user thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        worker.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    // package private; used by EventSupport; namingListener already synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    void addNamingListener(NamingListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        namingListeners.addElement(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    // package private; used by EventSupport; namingListener already synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    void removeNamingListener(NamingListener l) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        namingListeners.removeElement(l);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    // package private; used by EventSupport; namingListener already synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    boolean hasNamingListeners() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        return namingListeners.size() > 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Execute "persistent search".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * For each result, create the appropriate NamingEvent and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * queue to be dispatched to listeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            Continuation cont = new Continuation();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            cont.setError(this, info.name);
52902
e3398b2e1ab0 8214971: Replace use of string.equals("") with isEmpty()
rriggs
parents: 47216
diff changeset
   118
            Name nm = (info.name == null || info.name.isEmpty()) ?
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                new CompositeName() : new CompositeName().add(info.name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            results = context.searchAux(nm, info.filter, info.controls,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
                true, false, cont);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            // Change root of search results so that it will generate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            // names relative to the event context instead of that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            // named by nm
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   127
            ((LdapSearchEnumeration)(NamingEnumeration)results)
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   128
                    .setStartName(context.currentParsedDN);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            SearchResult si;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            Control[] respctls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            EntryChangeResponseControl ec;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            long changeNum;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            while (results.hasMore()) {
10324
e28265130e4f 7072353: JNDI libraries do not build with javac -Xlint:all -Werror
jjg
parents: 5506
diff changeset
   136
                si = results.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                respctls = (si instanceof HasControls) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                    ((HasControls) si).getControls() : null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                if (debug) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
                    System.err.println("notifier: " + si);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                    System.err.println("respCtls: " + respctls);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                // Just process ECs; ignore all the rest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                if (respctls != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                    for (int i = 0; i < respctls.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
                        // %%% Should be checking OID instead of class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                        // %%% in case using someone else's  EC ctl
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                        if (respctls[i] instanceof EntryChangeResponseControl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                            ec = (EntryChangeResponseControl)respctls[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                            changeNum = ec.getChangeNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                            switch (ec.getChangeType()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                            case EntryChangeResponseControl.ADD:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                                fireObjectAdded(si, changeNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                            case EntryChangeResponseControl.DELETE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                fireObjectRemoved(si, changeNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                            case EntryChangeResponseControl.MODIFY:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                                fireObjectChanged(si, changeNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                            case EntryChangeResponseControl.RENAME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                                fireObjectRenamed(si, ec.getPreviousDN(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                                    changeNum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        } catch (InterruptedNamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            if (debug) System.err.println("NamingEventNotifier Interrupted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            // Fire event to notify NamingExceptionEvent listeners
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            fireNamingException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            // This notifier is no longer valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            support.removeDeadNotifier(info);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            cleanup();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        if (debug) System.err.println("NamingEventNotifier finished");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    private void cleanup() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        if (debug) System.err.println("NamingEventNotifier cleanup");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            if (results != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                if (debug) System.err.println("NamingEventNotifier enum closing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                results.close(); // this will abandon the search
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                results = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            if (context != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                if (debug) System.err.println("NamingEventNotifier ctx closing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                context.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                context = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        } catch (NamingException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * Stop the dispatcher so we can be destroyed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * package private; used by EventSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    void stop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        if (debug) System.err.println("NamingEventNotifier being stopping");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (worker != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            worker.interrupt(); // kill our thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            worker = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * Fire an "object added" event to registered NamingListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    private void fireObjectAdded(Binding newBd, long changeID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (namingListeners == null || namingListeners.size() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        NamingEvent e = new NamingEvent(eventSrc, NamingEvent.OBJECT_ADDED,
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 10324
diff changeset
   224
            newBd, null, changeID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        support.queueEvent(e, namingListeners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * Fire an "object removed" event to registered NamingListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private void fireObjectRemoved(Binding oldBd, long changeID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (namingListeners == null || namingListeners.size() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        NamingEvent e = new NamingEvent(eventSrc, NamingEvent.OBJECT_REMOVED,
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 10324
diff changeset
   236
            null, oldBd, changeID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        support.queueEvent(e, namingListeners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * Fires an "object changed" event to registered NamingListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    private void fireObjectChanged(Binding newBd, long changeID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        if (namingListeners == null || namingListeners.size() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        // Name hasn't changed; construct old binding using name from new binding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        Binding oldBd = new Binding(newBd.getName(), null, newBd.isRelative());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        NamingEvent e = new NamingEvent(
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 10324
diff changeset
   251
            eventSrc, NamingEvent.OBJECT_CHANGED, newBd, oldBd, changeID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        support.queueEvent(e, namingListeners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * Fires an "object renamed" to registered NamingListeners.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    private void fireObjectRenamed(Binding newBd, String oldDN, long changeID) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        if (namingListeners == null || namingListeners.size() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        Binding oldBd = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            LdapName dn = new LdapName(oldDN);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            if (dn.startsWith(context.currentParsedDN)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
                String relDN = dn.getSuffix(context.currentParsedDN.size()).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                oldBd = new Binding(relDN, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        } catch (NamingException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        if (oldBd == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            oldBd = new Binding(oldDN, null, false /* not relative name */);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        NamingEvent e = new NamingEvent(
25186
63e1a2ec30f5 8048267: Replace uses of 'new Long()' with appropriate alternative across core classes
prappo
parents: 10324
diff changeset
   276
            eventSrc, NamingEvent.OBJECT_RENAMED, newBd, oldBd, changeID);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        support.queueEvent(e, namingListeners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    private void fireNamingException(NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (namingListeners == null || namingListeners.size() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        NamingExceptionEvent evt = new NamingExceptionEvent(eventSrc, e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        support.queueEvent(evt, namingListeners);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
}