01: /*_############################################################################
02: _##
03: _## SNMP4J - SecurityModels.java
04: _##
05: _## Copyright (C) 2003-2008 Frank Fock and Jochen Katz (SNMP4J.org)
06: _##
07: _## Licensed under the Apache License, Version 2.0 (the "License");
08: _## you may not use this file except in compliance with the License.
09: _## 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: package org.snmp4j.security;
22:
23: import java.util.*;
24: import org.snmp4j.smi.Integer32;
25:
26: /**
27: * The <code>SecurityModels</code> class is a collection of all
28: * supported security models of a SNMP entity.
29: *
30: * @author Jochen Katz & Frank Fock
31: * @version 1.0a
32: */
33: public class SecurityModels {
34:
35: private Hashtable securityModels = new Hashtable(3);
36:
37: private static SecurityModels instance = null;
38:
39: protected SecurityModels() {
40: }
41:
42: /**
43: * Gets the security singleton instance.
44: * @return
45: * the <code>SecurityModels</code> instance.
46: */
47: public synchronized static SecurityModels getInstance() {
48: if (instance == null) {
49: instance = new SecurityModels();
50: }
51: return instance;
52: }
53:
54: /**
55: * Adds a security model to the central repository of security models.
56: * @param model
57: * a <code>SecurityModel</code>. If a security model with the same ID
58: * already
59: */
60: public void addSecurityModel(SecurityModel model) {
61: securityModels.put(new Integer32(model.getID()), model);
62: }
63:
64: /**
65: * Removes a security model from the central repository of security models.
66: * @param id
67: * the <code>Integer32</code> ID of the security model to remove.
68: * @return
69: * the removed <code>SecurityModel</code> or <code>null</code> if
70: * <code>id</code> is not registered.
71: */
72: public SecurityModel removeSecurityModel(Integer32 id) {
73: return (SecurityModel) securityModels.remove(id);
74: }
75:
76: /**
77: * Returns a security model from the central repository of security models.
78: * @param id
79: * the <code>Integer32</code> ID of the security model to return.
80: * @return
81: * the with <code>id</code> associated <code>SecurityModel</code> or
82: * <code>null</code> if no such model is registered.
83: */
84: public SecurityModel getSecurityModel(Integer32 id) {
85: return (SecurityModel) securityModels.get(id);
86: }
87: }
|