KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > snmp4j > security > SecurityModels


1 /*_############################################################################
2   _##
3   _## SNMP4J - SecurityModels.java
4   _##
5   _## Copyright 2003-2007 Frank Fock and Jochen Katz (SNMP4J.org)
6   _##
7   _## Licensed under the Apache License, Version 2.0 (the "License");
8   _## you may not use this file except in compliance with the License.
9   _## You may obtain a copy of the License at
10   _##
11   _## http://www.apache.org/licenses/LICENSE-2.0
12   _##
13   _## Unless required by applicable law or agreed to in writing, software
14   _## distributed under the License is distributed on an "AS IS" BASIS,
15   _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   _## See the License for the specific language governing permissions and
17   _## limitations under the License.
18   _##
19   _##########################################################################*/

20
21
22
23
24
25 package org.snmp4j.security;
26
27 import java.util.*;
28 import org.snmp4j.smi.Integer32;
29
30 /**
31  * The <code>SecurityModels</code> class is a collection of all
32  * supported security models of a SNMP entity.
33  *
34  * @author Jochen Katz & Frank Fock
35  * @version 1.0a
36  */

37 public class SecurityModels {
38
39   private Hashtable securityModels = new Hashtable(3);
40
41   private static SecurityModels instance = null;
42
43   protected SecurityModels() {
44   }
45
46   /**
47    * Gets the security singleton instance.
48    * @return
49    * the <code>SecurityModels</code> instance.
50    */

51   public synchronized static SecurityModels getInstance() {
52     if (instance == null) {
53       instance = new SecurityModels();
54     }
55     return instance;
56   }
57
58   /**
59    * Adds a security model to the central repository of security models.
60    * @param model
61    * a <code>SecurityModel</code>. If a security model with the same ID
62    * already
63    */

64   public void addSecurityModel(SecurityModel model) {
65     securityModels.put(new Integer32(model.getID()), model);
66   }
67
68   /**
69    * Removes a security model from the central repository of security models.
70    * @param id
71    * the <code>Integer32</code> ID of the security model to remove.
72    * @return
73    * the removed <code>SecurityModel</code> or <code>null</code> if
74    * <code>id</code> is not registered.
75    */

76   public SecurityModel removeSecurityModel(Integer32 id) {
77     return (SecurityModel)securityModels.remove(id);
78   }
79
80   /**
81    * Returns a security model from the central repository of security models.
82    * @param id
83    * the <code>Integer32</code> ID of the security model to return.
84    * @return
85    * the with <code>id</code> associated <code>SecurityModel</code> or
86    * <code>null</code> if no such model is registered.
87    */

88   public SecurityModel getSecurityModel(Integer32 id) {
89     return (SecurityModel)securityModels.get(id);
90   }
91 }
92
93
Popular Tags