Source Code Cross Referenced for VariableBinding.java in  » Net » snmp4j » org » snmp4j » smi » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » snmp4j » org.snmp4j.smi 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*_############################################################################
002:          _##
003:          _##  SNMP4J - VariableBinding.java
004:          _##
005:          _##  Copyright (C) 2003-2008  Frank Fock and Jochen Katz (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.smi;
022:
023:        import java.io.Serializable;
024:        import org.snmp4j.asn1.*;
025:        import java.io.IOException;
026:        import java.io.OutputStream;
027:
028:        /**
029:         * A <code>VariableBinding</code> is an association of a object instance
030:         * identifier ({@link OID}) and the instance's value ({@link Variable}).
031:         *
032:         * @author Frank Fock
033:         * @version 1.9
034:         */
035:        public class VariableBinding implements  Serializable, BERSerializable,
036:                Cloneable {
037:
038:            private static final long serialVersionUID = 1032709950031514113L;
039:
040:            private OID oid;
041:            private Variable variable;
042:
043:            /**
044:             * Creates a variable binding with a zero length OID and a {@link Null} value.
045:             */
046:            public VariableBinding() {
047:                oid = new OID();
048:                this .variable = new Null();
049:            }
050:
051:            /**
052:             * Creates a variable binding with the supplied object instance identifier
053:             * and a {@link Null} value.
054:             * @param oid
055:             *    the OID for the new variable binding.
056:             */
057:            public VariableBinding(OID oid) {
058:                setOid(oid);
059:                this .variable = new Null();
060:            }
061:
062:            /**
063:             * Creates a variable binding with the supplied OID and value.
064:             * @param oid
065:             *    the OID for the new variable binding (must not be <code>null</code>).
066:             * @param variable
067:             *    the value for the new variable binding (must not be <code>null</code>).
068:             */
069:            public VariableBinding(OID oid, Variable variable) {
070:                setOid(oid);
071:                setVariable(variable);
072:            }
073:
074:            /**
075:             * Gets the object instance identifier of the variable binding.
076:             * @return
077:             *    an <code>OID</code>.
078:             */
079:            public OID getOid() {
080:                return oid;
081:            }
082:
083:            /**
084:             * Sets the object instance identifier for the variable binding.
085:             * @param oid
086:             *    an OID (must not be <code>null</code>) that is cloned when added to
087:             *    this binding.
088:             */
089:            public void setOid(OID oid) {
090:                if (oid == null) {
091:                    throw new IllegalArgumentException(
092:                            "OID of a VariableBinding must not be null");
093:                }
094:                this .oid = (OID) oid.clone();
095:            }
096:
097:            /**
098:             * Sets the value of the variable binding.
099:             *
100:             * @param variable
101:             *    a <code>Variable</code> (must not be <code>null</code>) that is cloned
102:             *    when added to this binding.
103:             */
104:            public void setVariable(Variable variable) {
105:                if (variable == null) {
106:                    throw new IllegalArgumentException(
107:                            "Variable of a VariableBinding must not be null");
108:                }
109:                this .variable = (Variable) variable.clone();
110:            }
111:
112:            /**
113:             * Gets the value of the variable binding.
114:             * @return
115:             *   a <code>Variable</code> instance.
116:             */
117:            public Variable getVariable() {
118:                return variable;
119:            }
120:
121:            /**
122:             * Gets the syntax of the variable bindings value.
123:             * @return
124:             *   a SMI syntax identifier (see {@link SMIConstants}).
125:             */
126:            public final int getSyntax() {
127:                return variable.getSyntax();
128:            }
129:
130:            /**
131:             * Returns whether the variable bindings value has an exception syntax.
132:             * @see Variable
133:             * @return
134:             *    <code>true</code> if the syntax of this variable is an instance of
135:             *    <code>Null</code> and its syntax equals one of the following:
136:             *    <UL>
137:             *    <LI>{@link SMIConstants#EXCEPTION_NO_SUCH_OBJECT}</LI>
138:             *    <LI>{@link SMIConstants#EXCEPTION_NO_SUCH_INSTANCE}</LI>
139:             *    <LI>{@link SMIConstants#EXCEPTION_END_OF_MIB_VIEW}</LI>
140:             *    </UL>
141:             */
142:            public boolean isException() {
143:                return variable.isException();
144:            }
145:
146:            public final int getBERPayloadLength() {
147:                return oid.getBERLength() + variable.getBERLength();
148:            }
149:
150:            public final int getBERLength() {
151:                int length = getBERPayloadLength();
152:                // add type byte and length of length
153:                length += BER.getBERLengthOfLength(length) + 1;
154:                return length;
155:            }
156:
157:            public final void decodeBER(BERInputStream inputStream)
158:                    throws IOException {
159:                BER.MutableByte type = new BER.MutableByte();
160:                int length = BER.decodeHeader(inputStream, type);
161:                long startPos = inputStream.getPosition();
162:                if (type.getValue() != BER.SEQUENCE) {
163:                    throw new IOException("Invalid sequence encoding: "
164:                            + type.getValue());
165:                }
166:                oid.decodeBER(inputStream);
167:                variable = AbstractVariable.createFromBER(inputStream);
168:                if (BER.isCheckSequenceLength()) {
169:                    BER.checkSequenceLength(length, (int) (inputStream
170:                            .getPosition() - startPos), this );
171:                }
172:            }
173:
174:            public final void encodeBER(OutputStream outputStream)
175:                    throws IOException {
176:                int length = getBERPayloadLength();
177:                BER.encodeHeader(outputStream, BER.SEQUENCE, length);
178:                oid.encodeBER(outputStream);
179:                variable.encodeBER(outputStream);
180:            }
181:
182:            /**
183:             * Gets a string representation of this variable binding.
184:             * @return
185:             *    a string of the form <code>&lt;OID&gt; = &lt;Variable&gt;</code>.
186:             */
187:            public String toString() {
188:                return oid.toString() + " = " + variable;
189:            }
190:
191:            public Object clone() {
192:                return new VariableBinding((OID) oid.clone(),
193:                        (Variable) variable.clone());
194:            }
195:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.