001: /*_############################################################################
002: _##
003: _## SNMP4J-Agent - SimMOFactory.java
004: _##
005: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## Licensed under the Apache License, Version 2.0 (the "License");
008: _## you may not use this file except in compliance with the License.
009: _## You may obtain a copy of the License at
010: _##
011: _## http://www.apache.org/licenses/LICENSE-2.0
012: _##
013: _## Unless required by applicable law or agreed to in writing, software
014: _## distributed under the License is distributed on an "AS IS" BASIS,
015: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: _## See the License for the specific language governing permissions and
017: _## limitations under the License.
018: _##
019: _##########################################################################*/
020:
021: package org.snmp4j.agent.mo.ext;
022:
023: import org.snmp4j.agent.mo.*;
024: import org.snmp4j.agent.MOAccess;
025: import java.util.Map;
026: import java.util.HashMap;
027:
028: /**
029: * A <code>SimMOFactory</code> object can be used to create non-default MOAccess
030: * instances which support an agent simulation mode which allows the
031: * modification of MIB objects at runtime via SNMP that are not writable in
032: * normal operation but writable in a special config mode (see
033: * AGENTPP-SIMULATION-MIB).
034: * <p>
035: * By creating the ManagedObject instances for a MIB module based on this
036: * factory the injected special MOAccess instances support changing the
037: * operation mode for these instances from normal operation to simulation
038: * mode. In simulation mode, an agent can be filled with data via SNMP
039: * regardless whether the objects are defined as writable or not. Such a
040: * simulation agent can be used for testing/developing management applications
041: * when real agents are not (physically) available.
042: *
043: * @author Frank Fock
044: * @version 1.0
045: */
046: public class SimMOFactory extends DefaultMOFactory {
047:
048: private Map accessModes = new HashMap();
049:
050: private static boolean simulationModeEnabled;
051: private static SimMOFactory instance;
052:
053: private SimMOFactory() {
054: }
055:
056: public synchronized static MOFactory getInstance() {
057: if (instance == null) {
058: instance = new SimMOFactory();
059: }
060: return instance;
061: }
062:
063: public static void setSimulationModeEnabled(boolean simulationMode) {
064: simulationModeEnabled = simulationMode;
065: }
066:
067: public static boolean isSimulationModeEnabled() {
068: return simulationModeEnabled;
069: }
070:
071: public synchronized MOAccess createAccess(int moAccess) {
072: MOAccess accessObj = (MOAccess) accessModes.get(new Integer(
073: moAccess));
074: if (accessObj == null) {
075: accessObj = new SimMOAccess(moAccess);
076: accessModes.put(new Integer(moAccess), accessObj);
077: }
078: return accessObj;
079: }
080:
081: public class SimMOAccess extends MOAccessImpl {
082:
083: public SimMOAccess(int moAccess) {
084: super (moAccess);
085: }
086:
087: public boolean isAccessibleForCreate() {
088: if (isSimulationModeEnabled()) {
089: return true;
090: }
091: return super .isAccessibleForCreate();
092: }
093:
094: public boolean isAccessibleForWrite() {
095: if (isSimulationModeEnabled()) {
096: return true;
097: }
098: return super.isAccessibleForWrite();
099: }
100: }
101: }
|