0N/A/*
2362N/A * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage com.sun.jndi.ldap;
0N/A
0N/Aimport javax.naming.directory.SearchControls;
0N/Aimport javax.naming.event.*;
0N/A
0N/A/**
0N/A * This class holds the information in an event registration/deregistration
0N/A * request. This includes the name, filter, search controls and
0N/A * the different interfaces that the listener implements. This last piece
0N/A * of information determines which event(s) the listener is interested in.
0N/A *<p>
0N/A * It overrides equals() and hashCode() to use all these pieces of
0N/A * information so that it can be used correctly in a hashtable.
0N/A *
0N/A * @author Rosanna Lee
0N/A */
0N/Afinal class NotifierArgs {
0N/A static final int ADDED_MASK = 0x1;
0N/A static final int REMOVED_MASK = 0x2;
0N/A static final int CHANGED_MASK = 0x4;
0N/A static final int RENAMED_MASK = 0x8;
0N/A
0N/A // these fields are package private; used by NamingEventNotifier
0N/A String name;
0N/A String filter;
0N/A SearchControls controls;
0N/A int mask;
0N/A
0N/A // package private
0N/A NotifierArgs(String name, int scope, NamingListener l) {
0N/A this(name, "(objectclass=*)", null, l);
0N/A
0N/A // if scope is not default, create search ctl and set it
0N/A if (scope != EventContext.ONELEVEL_SCOPE) {
0N/A controls = new SearchControls();
0N/A controls.setSearchScope(scope);
0N/A }
0N/A }
0N/A
0N/A // package private
0N/A NotifierArgs(String name, String filter, SearchControls ctls,
0N/A NamingListener l) {
0N/A this.name = name;
0N/A this.filter = filter;
0N/A this.controls = ctls;
0N/A
0N/A if (l instanceof NamespaceChangeListener) {
0N/A mask |= ADDED_MASK|REMOVED_MASK|RENAMED_MASK;
0N/A }
0N/A if (l instanceof ObjectChangeListener) {
0N/A mask |= CHANGED_MASK;
0N/A }
0N/A }
0N/A
0N/A // checks name, filter, controls
0N/A public boolean equals(Object obj) {
0N/A if (obj instanceof NotifierArgs) {
0N/A NotifierArgs target = (NotifierArgs)obj;
0N/A return mask == target.mask &&
0N/A name.equals(target.name) && filter.equals(target.filter) &&
0N/A checkControls(target.controls);
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A private boolean checkControls(SearchControls ctls) {
0N/A if ((controls == null || ctls == null)) {
0N/A return ctls == controls;
0N/A }
0N/A // ctls are nonempty
0N/A
0N/A return (controls.getSearchScope() == ctls.getSearchScope()) &&
0N/A (controls.getTimeLimit() == ctls.getTimeLimit()) &&
0N/A (controls.getDerefLinkFlag() == ctls.getDerefLinkFlag()) &&
0N/A (controls.getReturningObjFlag() == ctls.getReturningObjFlag()) &&
0N/A (controls.getCountLimit() == ctls.getCountLimit()) &&
0N/A checkStringArrays(controls.getReturningAttributes(),
0N/A ctls.getReturningAttributes());
0N/A }
0N/A
0N/A private static boolean checkStringArrays(String[] s1, String[] s2) {
0N/A if ((s1 == null) || (s2 == null)) {
0N/A return s1 == s2;
0N/A }
0N/A
0N/A // both are nonnull
0N/A if (s1.length != s2.length) {
0N/A return false;
0N/A }
0N/A
0N/A for (int i = 0; i < s1.length; i++) {
0N/A if (!s1[i].equals(s2[i])) {
0N/A return false;
0N/A }
0N/A }
0N/A return true;
0N/A }
0N/A
0N/A // save from having to recalculate each time
0N/A private int sum = -1;
0N/A public int hashCode() {
0N/A if (sum == -1)
0N/A sum = mask + name.hashCode() + filter.hashCode() + controlsCode();
0N/A return sum;
0N/A }
0N/A
0N/A // used in calculating hash code
0N/A private int controlsCode() {
0N/A if (controls == null) return 0;
0N/A
0N/A int total = (int)controls.getTimeLimit() + (int)controls.getCountLimit() +
0N/A (controls.getDerefLinkFlag() ? 1 : 0) +
0N/A (controls.getReturningObjFlag() ? 1 : 0);
0N/A
0N/A String[] attrs = controls.getReturningAttributes();
0N/A if (attrs != null) {
0N/A for (int i = 0; i < attrs.length; i++) {
0N/A total += attrs[i].hashCode();
0N/A }
0N/A }
0N/A
0N/A return total;
0N/A }
0N/A}