Source Code Cross Referenced for SnmpValue.java in  » EJB-Server-resin-3.1.5 » resin » com » caucho » server » snmp » types » 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 » EJB Server resin 3.1.5 » resin » com.caucho.server.snmp.types 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003:         *
004:         * This file is part of Resin(R) Open Source
005:         *
006:         * Each copy or derived work must preserve the copyright notice and this
007:         * notice unmodified.
008:         *
009:         * Resin Open Source is free software; you can redistribute it and/or modify
010:         * it under the terms of the GNU General Public License as published by
011:         * the Free Software Foundation; either version 2 of the License, or
012:         * (at your option) any later version.
013:         *
014:         * Resin Open Source is distributed in the hope that it will be useful,
015:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
016:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017:         * of NON-INFRINGEMENT.  See the GNU General Public License for more
018:         * details.
019:         *
020:         * You should have received a copy of the GNU General Public License
021:         * along with Resin Open Source; if not, write to the
022:         *
023:         *   Free Software Foundation, Inc.
024:         *   59 Temple Place, Suite 330
025:         *   Boston, MA 02111-1307  USA
026:         *
027:         * @author Nam Nguyen
028:         */
029:
030:        package com.caucho.server.snmp.types;
031:
032:        /*
033:         * SNMP type
034:         */
035:        abstract public class SnmpValue {
036:            public static final int EOC = 0x00;
037:            public static final int INTEGER = 0x02;
038:            public static final int OCTET_STRING = 0x04;
039:            public static final int NULL = 0x05;
040:            public static final int OBJECT_IDENTIFIER = 0x06;
041:            public static final int SEQUENCE = 0x30;
042:            public static final int IP_ADDRESS = 0x40;
043:            public static final int COUNTER = 0x41;
044:            public static final int GAUGE = 0x42;
045:            public static final int TIME_TICKS = 0x43;
046:            public static final int OPAQUE = 0x44;
047:            public static final int GET_REQUEST_PDU = 0xA0;
048:            public static final int GET_NEXT_REQUEST_PDU = 0xA1;
049:            public static final int GET_RESPONSE_PDU = 0xA2;
050:            public static final int SET_REQUEST_PDU = 0xA3;
051:            public static final int TRAP_PDU = 0xA4;
052:
053:            abstract public void toAsn1(StringBuilder sb);
054:
055:            abstract public int getType();
056:
057:            public static SnmpValue create(Object obj) {
058:                if (obj instanceof  Number)
059:                    return new IntegerValue(((Number) obj).intValue());
060:                else if (obj instanceof  Boolean)
061:                    return new IntegerValue(((Boolean) obj).booleanValue() ? 1
062:                            : 0);
063:                else
064:                    return new OctetStringValue(obj.toString());
065:            }
066:
067:            public static SnmpValue create(Object obj, String typeStr) {
068:                if (typeStr == null)
069:                    return create(obj);
070:
071:                int type = SnmpValue.OCTET_STRING;
072:
073:                if (typeStr.equalsIgnoreCase("INTEGER"))
074:                    type = INTEGER;
075:                else if (typeStr.equalsIgnoreCase("TIME_TICKS"))
076:                    type = TIME_TICKS;
077:                else if (typeStr.equalsIgnoreCase("GAUGE"))
078:                    type = GAUGE;
079:                else if (typeStr.equalsIgnoreCase("COUNTER"))
080:                    type = COUNTER;
081:                else if (typeStr.equalsIgnoreCase("OBJECT_IDENTIFIER"))
082:                    type = OBJECT_IDENTIFIER;
083:
084:                return create(obj, type);
085:            }
086:
087:            public static SnmpValue create(Object obj, int type) {
088:                if (obj instanceof  Number) {
089:                    switch (type) {
090:                    case INTEGER:
091:                        return new IntegerValue(((Number) obj).intValue());
092:                    case COUNTER:
093:                        return new CounterValue(((Number) obj).longValue());
094:                    case GAUGE:
095:                        return new GaugeValue(((Number) obj).longValue());
096:                    case TIME_TICKS:
097:                        // time ticks are in hundredths of a second
098:                        return new TimeTicksValue(
099:                                ((Number) obj).longValue() / 10);
100:                    }
101:                }
102:
103:                switch (type) {
104:                case OBJECT_IDENTIFIER:
105:                    return new ObjectIdentifierValue(obj.toString());
106:                case IP_ADDRESS:
107:                    return new IpAddressValue(obj.toString());
108:                }
109:
110:                return new OctetStringValue(obj.toString());
111:            }
112:
113:            public final String toAsn1() {
114:                StringBuilder sb = new StringBuilder();
115:
116:                toAsn1(sb);
117:
118:                return sb.toString();
119:            }
120:
121:            final protected void header(StringBuilder sb, int len) {
122:                sb.append((char) getType());
123:
124:                if (len < 0x7F) {
125:                    sb.append((char) len);
126:                    return;
127:                }
128:
129:                int bytes = 1;
130:
131:                if ((len >> 24) > 0)
132:                    bytes = 4;
133:                else if ((len >> 16) > 0)
134:                    bytes = 3;
135:                else if ((len >> 8) > 0)
136:                    bytes = 2;
137:
138:                // size of length field
139:                sb.append((char) (0x80 | bytes));
140:
141:                while (bytes > 0) {
142:                    switch (bytes) {
143:                    case 1:
144:                        sb.append((char) (len & 0xFF));
145:                        break;
146:                    case 2:
147:                        sb.append((char) ((len >> 8) & 0xFF));
148:                        break;
149:                    case 3:
150:                        sb.append((char) ((len >> 16) & 0xFF));
151:                        break;
152:                    case 4:
153:                        sb.append((char) ((len >> 24) & 0xFF));
154:                        break;
155:                    }
156:
157:                    bytes--;
158:                }
159:
160:            }
161:
162:            public long getLong() {
163:                throw new UnsupportedOperationException();
164:            }
165:
166:            public String getString() {
167:                throw new UnsupportedOperationException();
168:            }
169:
170:            public static String typeName(int identifier) {
171:                switch (identifier) {
172:                case EOC:
173:                    return "EOC";
174:                case INTEGER:
175:                    return "INTEGER";
176:                case OCTET_STRING:
177:                    return "OCTET_STRING";
178:                case NULL:
179:                    return "NULL";
180:                case OBJECT_IDENTIFIER:
181:                    return "OBJECT_IDENTIFIER";
182:                case SEQUENCE:
183:                    return "SEQUENCE";
184:                case IP_ADDRESS:
185:                    return "IP_ADDRESS";
186:                case COUNTER:
187:                    return "COUNTER";
188:                case GAUGE:
189:                    return "GAUGE";
190:                case TIME_TICKS:
191:                    return "TIME_TICKS";
192:                case OPAQUE:
193:                    return "OPAQUE";
194:                case GET_REQUEST_PDU:
195:                    return "GET_REQUEST_PDU";
196:                case GET_NEXT_REQUEST_PDU:
197:                    return "GET_NEXT_REQUEST_PDU";
198:                case GET_RESPONSE_PDU:
199:                    return "GET_RESPONSE_PDU";
200:                case SET_REQUEST_PDU:
201:                    return "SET_REQUEST_PDU";
202:                case TRAP_PDU:
203:                    return "TRAP_PDU";
204:                default:
205:                    return "UNKNOWN";
206:                }
207:            }
208:
209:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.