KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * @(#)file Host.java
3  * @(#)author Sun Microsystems, Inc.
4  * @(#)version 4.14
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 // java import
18
//
19
import java.io.Serializable JavaDoc;
20 import java.net.InetAddress JavaDoc;
21 import java.net.UnknownHostException JavaDoc;
22 import java.util.Hashtable JavaDoc;
23 import java.util.Vector JavaDoc;
24 import java.security.acl.NotOwnerException JavaDoc;
25
26 // SNMP Runtime import
27
//
28
import com.sun.jmx.trace.Trace;
29   
30 /**
31  * The class defines an abstract representation of a host.
32  *
33  * @version 4.14 12/19/03
34  * @author Sun Microsystems, Inc.
35  */

36 abstract class Host extends SimpleNode implements Serializable JavaDoc {
37   
38     public Host(int id) {
39         super(id);
40     }
41
42     public Host(Parser p, int id) {
43         super(p, id);
44     }
45   
46     protected abstract PrincipalImpl createAssociatedPrincipal()
47         throws UnknownHostException JavaDoc;
48   
49     protected abstract String JavaDoc getHname();
50
51     public void buildAclEntries(PrincipalImpl owner, AclImpl acl) {
52         // Create a principal
53
//
54
PrincipalImpl p=null;
55         try {
56             p = createAssociatedPrincipal();
57         } catch(UnknownHostException JavaDoc e) {
58             if (isDebugOn()) {
59                 debug("buildAclEntries", "Cannot create ACL entry for " + e.getMessage());
60             }
61         throw new IllegalArgumentException JavaDoc("Cannot create ACL entry for " + e.getMessage());
62         }
63
64         // Create an AclEntry
65
//
66
AclEntryImpl entry= null;
67         try {
68             entry = new AclEntryImpl(p);
69             // Add permission
70
//
71
registerPermission(entry);
72             acl.addEntry(owner, entry);
73         } catch(UnknownHostException JavaDoc e) {
74             if (isDebugOn()) {
75                 debug("buildAclEntries", "Cannot create ACL entry for " + e.getMessage());
76             }
77             return;
78         } catch(NotOwnerException JavaDoc a) {
79             if (isDebugOn()) {
80                 debug("buildAclEntries", "Not owner of ACL " + a.getMessage());
81             }
82             return;
83         }
84     }
85     
86     private void registerPermission(AclEntryImpl entry) {
87         JDMHost host= (JDMHost) jjtGetParent();
88         JDMManagers manager= (JDMManagers) host.jjtGetParent();
89         JDMAclItem acl= (JDMAclItem) manager.jjtGetParent();
90         JDMAccess access= (JDMAccess) acl.getAccess();
91         access.putPermission(entry);
92         JDMCommunities comm= (JDMCommunities) acl.getCommunities();
93         comm.buildCommunities(entry);
94     }
95
96     public void buildTrapEntries(Hashtable JavaDoc dest) {
97         
98         JDMHostTrap host= (JDMHostTrap) jjtGetParent();
99         JDMTrapInterestedHost hosts= (JDMTrapInterestedHost) host.jjtGetParent();
100         JDMTrapItem trap = (JDMTrapItem) hosts.jjtGetParent();
101         JDMTrapCommunity community = (JDMTrapCommunity) trap.getCommunity();
102         String JavaDoc comm = community.getCommunity();
103     
104         InetAddress JavaDoc add = null;
105         try {
106             add = java.net.InetAddress.getByName(getHname());
107         } catch(UnknownHostException JavaDoc e) {
108             if (isDebugOn()) {
109                 debug("buildTrapEntries", "Cannot create TRAP entry for " + e.getMessage());
110             }
111             return;
112         }
113     
114         Vector JavaDoc list = null;
115         if (dest.containsKey(add)){
116             list = (Vector JavaDoc) dest.get(add);
117             if (!list.contains(comm)){
118                 list.addElement(comm);
119             }
120         } else {
121             list = new Vector JavaDoc();
122             list.addElement(comm);
123             dest.put(add,list);
124         }
125     }
126     
127     public void buildInformEntries(Hashtable JavaDoc dest) {
128     
129         JDMHostInform host= (JDMHostInform) jjtGetParent();
130         JDMInformInterestedHost hosts= (JDMInformInterestedHost) host.jjtGetParent();
131         JDMInformItem inform = (JDMInformItem) hosts.jjtGetParent();
132         JDMInformCommunity community = (JDMInformCommunity) inform.getCommunity();
133         String JavaDoc comm = community.getCommunity();
134     
135         InetAddress JavaDoc add = null;
136         try {
137             add = java.net.InetAddress.getByName(getHname());
138         } catch(UnknownHostException JavaDoc e) {
139             if (isDebugOn()) {
140                 debug("buildInformEntries", "Cannot create INFORM entry for " + e.getMessage());
141             }
142             return;
143         }
144     
145         Vector JavaDoc list = null;
146         if (dest.containsKey(add)){
147             list = (Vector JavaDoc) dest.get(add);
148             if (!list.contains(comm)){
149                 list.addElement(comm);
150             }
151         } else {
152             list = new Vector JavaDoc();
153             list.addElement(comm);
154             dest.put(add,list);
155         }
156     }
157     
158     // TRACES & DEBUG
159
//---------------
160

161     boolean isTraceOn() {
162         return Trace.isSelected(Trace.LEVEL_TRACE, Trace.INFO_SNMP);
163     }
164
165     void trace(String JavaDoc clz, String JavaDoc func, String JavaDoc info) {
166         Trace.send(Trace.LEVEL_TRACE, Trace.INFO_SNMP, clz, func, info);
167     }
168
169     void trace(String JavaDoc func, String JavaDoc info) {
170         trace(dbgTag, func, info);
171     }
172     
173     boolean isDebugOn() {
174         return Trace.isSelected(Trace.LEVEL_DEBUG, Trace.INFO_SNMP);
175     }
176
177     void debug(String JavaDoc clz, String JavaDoc func, String JavaDoc info) {
178         Trace.send(Trace.LEVEL_DEBUG, Trace.INFO_SNMP, clz, func, info);
179     }
180
181     void debug(String JavaDoc func, String JavaDoc info) {
182         debug(dbgTag, func, info);
183     }
184     
185     String JavaDoc dbgTag = "Host";
186 }
187
Popular Tags