KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > jmx > snmp > IPAcl > GroupImpl


1 /*
2  * @(#)file GroupImpl.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 4.9
5  * @(#)date 08/02/09
6  *
7  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
8  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
9  *
10  */

11
12
13 package com.sun.jmx.snmp.IPAcl;
14
15
16
17 import java.util.Vector JavaDoc;
18 import java.util.Enumeration JavaDoc;
19 import java.io.Serializable JavaDoc;
20 import java.net.UnknownHostException JavaDoc;
21
22
23 import java.security.Principal JavaDoc;
24 import java.security.acl.Group JavaDoc;
25
26
27 /**
28  * This class is used to represent a subnet mask (a group of hosts
29  * matching the same
30  * IP mask).
31  *
32  * @version 4.9 12/19/03
33  * @author Sun Microsystems, Inc
34  */

35
36 class GroupImpl extends PrincipalImpl implements Group JavaDoc, Serializable JavaDoc {
37   
38   /**
39    * Constructs an empty group.
40    * @exception UnknownHostException Not implemented
41    */

42   public GroupImpl () throws UnknownHostException JavaDoc {
43   }
44   
45   /**
46    * Constructs a group using the specified subnet mask.
47    *
48    * @param mask The subnet mask to use to build the group.
49    * @exception UnknownHostException if the subnet mask cann't be built.
50    */

51   public GroupImpl (String JavaDoc mask) throws UnknownHostException JavaDoc {
52     super(mask);
53   }
54   
55     /**
56      * Adds the specified member to the group.
57      *
58      * @param p the principal to add to this group.
59      * @return true if the member was successfully added, false if the
60      * principal was already a member.
61      */

62     public boolean addMember(Principal JavaDoc p) {
63     // we don't need to add members because the ip address is a
64
// subnet mask
65
return true;
66     }
67
68   public int hashCode() {
69     return super.hashCode();
70   }
71   
72   /**
73    * Compares this group to the specified object. Returns true if the object
74    * passed in matches the group represented.
75    *
76    * @param p the object to compare with.
77    * @return true if the object passed in matches the subnet mask,
78    * false otherwise.
79    */

80   public boolean equals (Object JavaDoc p) {
81     if (p instanceof PrincipalImpl || p instanceof GroupImpl){
82       if ((super.hashCode() & p.hashCode()) == p.hashCode()) return true;
83       else return false;
84     } else {
85       return false;
86     }
87   }
88   
89   /**
90    * Returns true if the passed principal is a member of the group.
91    *
92    * @param p the principal whose membership is to be checked.
93    * @return true if the principal is a member of this group, false otherwise.
94    */

95   public boolean isMember(Principal JavaDoc p) {
96     if ((p.hashCode() & super.hashCode()) == p.hashCode()) return true;
97     else return false;
98   }
99   
100   /**
101    * Returns an enumeration which contains the subnet mask.
102    *
103    * @return an enumeration which contains the subnet mask.
104    */

105   public Enumeration JavaDoc members(){
106     Vector JavaDoc v = new Vector JavaDoc(1);
107     v.addElement(this);
108     return v.elements();
109   }
110   
111   /**
112    * Removes the specified member from the group. (Not implemented)
113    *
114    * @param p the principal to remove from this group.
115    * @return allways return true.
116    */

117   public boolean removeMember(Principal JavaDoc p) {
118     return true;
119   }
120   
121   /**
122    * Prints a string representation of this group.
123    *
124    * @return a string representation of this group.
125    */

126   public String JavaDoc toString() {
127     return ("GroupImpl :"+super.getAddress().toString());
128   }
129 }
130
131
132
Popular Tags