// // This function is the recursive search of groups for this // implementation of the Group. The search proceeds building up // a vector of already seen groups. Only new groups are considered, // thereby avoiding loops. // boolean isMemberRecurse(Principal member, Vector<Group> alreadySeen) { Enumeration<? extends Principal> e = members(); while (e.hasMoreElements()) { boolean mem = false; Principal p = (Principal) e.nextElement(); // if the member is in this collection, return true if (p.equals(member)) { return true; } else if (p instanceof GroupImpl) { // // if not recurse if the group has not been checked already. // Can call method in this package only if the object is an // instance of this class. Otherwise call the method defined // in the interface. (This can lead to a loop if a mixture of // implementations form a loop, but we live with this improbable // case rather than clutter the interface by forcing the // implementation of this method.) // GroupImpl g = (GroupImpl) p; alreadySeen.addElement(this); if (!alreadySeen.contains(g)) mem = g.isMemberRecurse(member, alreadySeen); } else if (p instanceof Group) { Group g = (Group) p; if (!alreadySeen.contains(g)) mem = g.isMember(member); } if (mem) return mem; } return false; }
public final void addLineListener(LineListener listener) { synchronized (listeners) { if (!(listeners.contains(listener))) { listeners.addElement(listener); } } }
/** * adds the specified member to the group. * * @param user The principal to add to the group. * @return true if the member was added - false if the member could not be added. */ public boolean addMember(Principal user) { if (groupMembers.contains(user)) return false; // do not allow groups to be added to itself. if (group.equals(user.toString())) throw new IllegalArgumentException(); groupMembers.addElement(user); return true; }
/** * Enables all the attribute change notifications the attribute name of which equals the specified * name to be sent to the listener. <br> * If the specified name is already in the list of enabled attribute names, this method has no * effect. * * @param name The attribute name. * @exception j86.java.lang.IllegalArgumentException The attribute name parameter is null. */ public synchronized void enableAttribute(String name) throws j86.java.lang.IllegalArgumentException { if (name == null) { throw new j86.java.lang.IllegalArgumentException("The name cannot be null."); } if (!enabledAttributes.contains(name)) { enabledAttributes.addElement(name); } }
/** * Invoked before sending the specified notification to the listener. <br> * This filter compares the attribute name of the specified attribute change notification with * each enabled attribute name. If the attribute name equals one of the enabled attribute names, * the notification must be sent to the listener and this method returns <CODE>true</CODE>. * * @param notification The attribute change notification to be sent. * @return <CODE>true</CODE> if the notification has to be sent to the listener, <CODE>false * </CODE> otherwise. */ public synchronized boolean isNotificationEnabled(Notification notification) { String type = notification.getType(); if ((type == null) || (type.equals(AttributeChangeNotification.ATTRIBUTE_CHANGE) == false) || (!(notification instanceof AttributeChangeNotification))) { return false; } String attributeName = ((AttributeChangeNotification) notification).getAttributeName(); return enabledAttributes.contains(attributeName); }
/** * returns true if the passed principal is a member of the group. * * @param member The principal whose membership must be checked for. * @return true if the principal is a member of this group, false otherwise */ public boolean isMember(Principal member) { // // if the member is part of the group (common case), return true. // if not, recursively search depth first in the group looking for the // principal. // if (groupMembers.contains(member)) { return true; } else { Vector<Group> alreadySeen = new Vector<>(10); return isMemberRecurse(member, alreadySeen); } }