Java 类javax.naming.event.ObjectChangeListener 实例源码

项目:astor    文件:EventUtilsTest.java   
@Test
public void testAddEventListenerWithNoAddMethod()
{
    final PropertyChangeSource src = new PropertyChangeSource();
    final EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
    final ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class);
    try
    {
        EventUtils.addEventListener(src, ObjectChangeListener.class, listener);
        fail("Should not be allowed to add a listener to an object that doesn't support it.");
    }
    catch (final IllegalArgumentException e)
    {
        assertEquals("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".", e.getMessage());
    }
}
项目:astor    文件:EventUtilsTest.java   
@Test
public void testAddEventListenerWithNoAddMethod()
{
    final PropertyChangeSource src = new PropertyChangeSource();
    EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
    ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class);
    try
    {
        EventUtils.addEventListener(src, ObjectChangeListener.class, listener);
        fail("Should not be allowed to add a listener to an object that doesn't support it.");
    }
    catch (IllegalArgumentException e)
    {
        assertEquals("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".", e.getMessage());
    }
}
项目:astor    文件:EventUtilsTest.java   
public void testAddEventListenerWithNoAddMethod()
{
    final PropertyChangeSource src = new PropertyChangeSource();
    EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
    ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class);
    try
    {
        EventUtils.addEventListener(src, ObjectChangeListener.class, listener);
        fail("Should not be allowed to add a listener to an object that doesn't support it.");
    }
    catch (IllegalArgumentException e)
    {
        assertEquals("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".", e.getMessage());
    }
}
项目:gwt-commons-lang3    文件:EventUtilsTest.java   
@Test
public void testAddEventListenerWithNoAddMethod() {
    final PropertyChangeSource src = new PropertyChangeSource();
    final EventCountingInvociationHandler handler = new EventCountingInvociationHandler();
    final ObjectChangeListener listener = handler.createListener(ObjectChangeListener.class);
    expectedException.expect(IllegalArgumentException.class);
    expectedException.expectMessage("Class " + src.getClass().getName() + " does not have a public add" + ObjectChangeListener.class.getSimpleName() + " method which takes a parameter of type " + ObjectChangeListener.class.getName() + ".");
    EventUtils.addEventListener(src, ObjectChangeListener.class, listener);
}
项目:cn1    文件:LdapContextImpl.java   
public void addNamingListener(Name name, String filter,
        Object[] filterArgs, SearchControls searchControls,
        NamingListener namingListener) throws NamingException {
    checkName(name);

    if (namingListener == null) {
        return;
    }

    if (!(name instanceof LdapName)) {
        if (name instanceof CompositeName && name.size() == 1) {
            name = name.getPrefix(1);
        } else {
            // FIXME: read message from file
            throw new InvalidNameException(
                    "Target cannot span multiple namespaces: "
                            + name.toString());
        }
    }

    if (namingListener instanceof UnsolicitedNotificationListener) {
        if (unls == null) {
            unls = new ArrayList<UnsolicitedNotificationListener>();
            addUnsolicitedListener();
        }

        unls.add((UnsolicitedNotificationListener) namingListener);

        if (!(namingListener instanceof NamespaceChangeListener)
                && !(namingListener instanceof ObjectChangeListener)) {
            return;
        }
    }

    if (searchControls == null) {
        searchControls = new SearchControls();
    }

    Filter f = LdapUtils.parseFilter(filter, filterArgs);

    String targetDN = getTargetDN(name, contextDn);

    Name tempName = new LdapName(contextDn.toString());
    tempName.addAll(name);
    String baseDN = tempName.toString();

    int messageId = doPersistentSearch(targetDN, baseDN, f, searchControls,
            namingListener);

    if (listeners == null) {
        listeners = new HashMap<NamingListener, List<Integer>>();
    }

    List<Integer> idList = listeners.get(namingListener);
    if (idList == null) {
        idList = new ArrayList<Integer>();
    }

    idList.add(Integer.valueOf(messageId));
}
项目:cn1    文件:LdapContextImpl.java   
public void addNamingListener(Name name, int scope,
        NamingListener namingListener) throws NamingException {
    checkName(name);

    if (namingListener == null) {
        return;
    }

    // only ldap name is supportted
    if (!(name instanceof LdapName)) {
        if (name instanceof CompositeName && name.size() == 1) {
            name = name.getPrefix(0);
        } else {
            // ldap.32=Target cannot span multiple namespaces: {0}
            throw new InvalidNameException(Messages.getString("ldap.32", //$NON-NLS-1$
                    new Object[] { name.toString() }));
        }
    }

    if (namingListener instanceof UnsolicitedNotificationListener) {
        if (unls == null) {
            unls = new ArrayList<UnsolicitedNotificationListener>();
            addUnsolicitedListener();
        }

        unls.add((UnsolicitedNotificationListener) namingListener);

        if (!(namingListener instanceof NamespaceChangeListener)
                && !(namingListener instanceof ObjectChangeListener)) {
            return;
        }
    }

    // ri is silent in this case
    if (scope != EventContext.OBJECT_SCOPE
            && scope != EventContext.ONELEVEL_SCOPE
            && scope != EventContext.SUBTREE_SCOPE) {
        // ldap.33=Scope should be one of 'OBJECT_SCOPE', 'ONELEVEL_SCOPE'
        // or 'SUBTREE_SCOPE'
        throw new IllegalArgumentException(Messages.getString("ldap.33")); //$NON-NLS-1$
    }

    String targetDN = getTargetDN(name, contextDn);

    Filter filter = new Filter(Filter.PRESENT_FILTER);
    filter.setValue("objectClass");

    SearchControls controls = new SearchControls();
    controls.setSearchScope(scope);

    Name tempName = new LdapName(contextDn.toString());
    tempName.addAll(name);
    String baseDN = tempName.toString();

    int messageId = doPersistentSearch(targetDN, baseDN, filter, controls,
            namingListener);

    if (listeners == null) {
        listeners = new HashMap<NamingListener, List<Integer>>();
    }

    List<Integer> idList = listeners.get(namingListener);
    if (idList == null) {
        idList = new ArrayList<Integer>();
        listeners.put(namingListener, idList);
    }

    idList.add(Integer.valueOf(messageId));

}
项目:nextop-client    文件:LdapContextImpl.java   
public void addNamingListener(Name name, String filter,
        Object[] filterArgs, SearchControls searchControls,
        NamingListener namingListener) throws NamingException {
    checkName(name);

    if (namingListener == null) {
        return;
    }

    if (!(name instanceof LdapName)) {
        if (name instanceof CompositeName && name.size() == 1) {
            name = name.getPrefix(1);
        } else {
            // FIXME: read message from file
            throw new InvalidNameException(
                    "Target cannot span multiple namespaces: "
                            + name.toString());
        }
    }

    if (namingListener instanceof UnsolicitedNotificationListener) {
        if (unls == null) {
            unls = new ArrayList<UnsolicitedNotificationListener>();
            addUnsolicitedListener();
        }

        unls.add((UnsolicitedNotificationListener) namingListener);

        if (!(namingListener instanceof NamespaceChangeListener)
                && !(namingListener instanceof ObjectChangeListener)) {
            return;
        }
    }

    if (searchControls == null) {
        searchControls = new SearchControls();
    }

    Filter f = LdapUtils.parseFilter(filter, filterArgs);

    String targetDN = getTargetDN(name, contextDn);

    Name tempName = new LdapName(contextDn.toString());
    tempName.addAll(name);
    String baseDN = tempName.toString();

    int messageId = doPersistentSearch(targetDN, baseDN, f, searchControls,
            namingListener);

    if (listeners == null) {
        listeners = new HashMap<NamingListener, List<Integer>>();
    }

    List<Integer> idList = listeners.get(namingListener);
    if (idList == null) {
        idList = new ArrayList<Integer>();
    }

    idList.add(Integer.valueOf(messageId));
}
项目:nextop-client    文件:LdapContextImpl.java   
public void addNamingListener(Name name, int scope,
        NamingListener namingListener) throws NamingException {
    checkName(name);

    if (namingListener == null) {
        return;
    }

    // only ldap name is supportted
    if (!(name instanceof LdapName)) {
        if (name instanceof CompositeName && name.size() == 1) {
            name = name.getPrefix(0);
        } else {
            // ldap.32=Target cannot span multiple namespaces: {0}
            throw new InvalidNameException(Messages.getString("ldap.32", //$NON-NLS-1$
                    new Object[] { name.toString() }));
        }
    }

    if (namingListener instanceof UnsolicitedNotificationListener) {
        if (unls == null) {
            unls = new ArrayList<UnsolicitedNotificationListener>();
            addUnsolicitedListener();
        }

        unls.add((UnsolicitedNotificationListener) namingListener);

        if (!(namingListener instanceof NamespaceChangeListener)
                && !(namingListener instanceof ObjectChangeListener)) {
            return;
        }
    }

    // ri is silent in this case
    if (scope != EventContext.OBJECT_SCOPE
            && scope != EventContext.ONELEVEL_SCOPE
            && scope != EventContext.SUBTREE_SCOPE) {
        // ldap.33=Scope should be one of 'OBJECT_SCOPE', 'ONELEVEL_SCOPE'
        // or 'SUBTREE_SCOPE'
        throw new IllegalArgumentException(Messages.getString("ldap.33")); //$NON-NLS-1$
    }

    String targetDN = getTargetDN(name, contextDn);

    Filter filter = new Filter(Filter.PRESENT_FILTER);
    filter.setValue("objectClass");

    SearchControls controls = new SearchControls();
    controls.setSearchScope(scope);

    Name tempName = new LdapName(contextDn.toString());
    tempName.addAll(name);
    String baseDN = tempName.toString();

    int messageId = doPersistentSearch(targetDN, baseDN, filter, controls,
            namingListener);

    if (listeners == null) {
        listeners = new HashMap<NamingListener, List<Integer>>();
    }

    List<Integer> idList = listeners.get(namingListener);
    if (idList == null) {
        idList = new ArrayList<Integer>();
        listeners.put(namingListener, idList);
    }

    idList.add(Integer.valueOf(messageId));

}
项目:freeVM    文件:LdapContextImpl.java   
public void addNamingListener(Name name, String filter,
        Object[] filterArgs, SearchControls searchControls,
        NamingListener namingListener) throws NamingException {
    checkName(name);

    if (namingListener == null) {
        return;
    }

    if (!(name instanceof LdapName)) {
        if (name instanceof CompositeName && name.size() == 1) {
            name = name.getPrefix(1);
        } else {
            // FIXME: read message from file
            throw new InvalidNameException(
                    "Target cannot span multiple namespaces: "
                            + name.toString());
        }
    }

    if (namingListener instanceof UnsolicitedNotificationListener) {
        if (unls == null) {
            unls = new ArrayList<UnsolicitedNotificationListener>();
            addUnsolicitedListener();
        }

        unls.add((UnsolicitedNotificationListener) namingListener);

        if (!(namingListener instanceof NamespaceChangeListener)
                && !(namingListener instanceof ObjectChangeListener)) {
            return;
        }
    }

    if (searchControls == null) {
        searchControls = new SearchControls();
    }

    Filter f = LdapUtils.parseFilter(filter, filterArgs);

    String targetDN = getTargetDN(name, contextDn);

    Name tempName = new LdapName(contextDn.toString());
    tempName.addAll(name);
    String baseDN = tempName.toString();

    int messageId = doPersistentSearch(targetDN, baseDN, f, searchControls,
            namingListener);

    if (listeners == null) {
        listeners = new HashMap<NamingListener, List<Integer>>();
    }

    List<Integer> idList = listeners.get(namingListener);
    if (idList == null) {
        idList = new ArrayList<Integer>();
    }

    idList.add(Integer.valueOf(messageId));
}
项目:freeVM    文件:LdapContextImpl.java   
public void addNamingListener(Name name, int scope,
        NamingListener namingListener) throws NamingException {
    checkName(name);

    if (namingListener == null) {
        return;
    }

    // only ldap name is supportted
    if (!(name instanceof LdapName)) {
        if (name instanceof CompositeName && name.size() == 1) {
            name = name.getPrefix(0);
        } else {
            // ldap.32=Target cannot span multiple namespaces: {0}
            throw new InvalidNameException(Messages.getString("ldap.32", //$NON-NLS-1$
                    new Object[] { name.toString() }));
        }
    }

    if (namingListener instanceof UnsolicitedNotificationListener) {
        if (unls == null) {
            unls = new ArrayList<UnsolicitedNotificationListener>();
            addUnsolicitedListener();
        }

        unls.add((UnsolicitedNotificationListener) namingListener);

        if (!(namingListener instanceof NamespaceChangeListener)
                && !(namingListener instanceof ObjectChangeListener)) {
            return;
        }
    }

    // ri is silent in this case
    if (scope != EventContext.OBJECT_SCOPE
            && scope != EventContext.ONELEVEL_SCOPE
            && scope != EventContext.SUBTREE_SCOPE) {
        // ldap.33=Scope should be one of 'OBJECT_SCOPE', 'ONELEVEL_SCOPE'
        // or 'SUBTREE_SCOPE'
        throw new IllegalArgumentException(Messages.getString("ldap.33")); //$NON-NLS-1$
    }

    String targetDN = getTargetDN(name, contextDn);

    Filter filter = new Filter(Filter.PRESENT_FILTER);
    filter.setValue("objectClass");

    SearchControls controls = new SearchControls();
    controls.setSearchScope(scope);

    Name tempName = new LdapName(contextDn.toString());
    tempName.addAll(name);
    String baseDN = tempName.toString();

    int messageId = doPersistentSearch(targetDN, baseDN, filter, controls,
            namingListener);

    if (listeners == null) {
        listeners = new HashMap<NamingListener, List<Integer>>();
    }

    List<Integer> idList = listeners.get(namingListener);
    if (idList == null) {
        idList = new ArrayList<Integer>();
        listeners.put(namingListener, idList);
    }

    idList.add(Integer.valueOf(messageId));

}