Source Code Cross Referenced for ObjectIdentifier.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » security » utils » 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 » Apache Harmony Java SE » org package » org.apache.harmony.security.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more
003:         *  contributor license agreements.  See the NOTICE file distributed with
004:         *  this work for additional information regarding copyright ownership.
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0
006:         *  (the "License"); you may not use this file except in compliance with
007:         *  the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *  See the License for the specific language governing permissions and
015:         *  limitations under the License.
016:         */
017:        /**
018:         * @author Alexander V. Esin, Stepan M. Mishura
019:         * @version $Revision$
020:         */package org.apache.harmony.security.utils;
021:
022:        import java.util.Arrays;
023:
024:        import org.apache.harmony.security.internal.nls.Messages;
025:
026:        /**
027:         * Instance of this class represents ObjectIdentifier (OID).
028:         * 
029:         * OID is represented as a sequence of subidentifier.
030:         * Each subidentifier is represented as non negative integer value.
031:         * There are at least 2 subidentifiers in the sequence.
032:         * 
033:         * Valid values for first subidentifier are 0, 1 and 2.
034:         * If the first subidentifier has 0 or 1 value the second
035:         * subidentifier MUST be less then 40.
036:         * 
037:         * @see http://asn1.elibel.tm.fr/en/standards/index.htm
038:         */
039:
040:        public final class ObjectIdentifier {
041:
042:            //OID as array of integers
043:            private final int[] oid;
044:
045:            //hash code
046:            private int hash = -1;
047:
048:            //OID as string
049:            private String soid;
050:
051:            // stores the following: "OID." + soid
052:            private String sOID;
053:
054:            // OID alias name
055:            private String name;
056:
057:            // OID's group
058:            private Object group;
059:
060:            /**
061:             * Creates ObjectIdentifier(OID) from array of integers.
062:             * 
063:             * @param oid - array of integers
064:             * @return - OID object
065:             * @throws NullPointerException     - if oid is null
066:             * @throws IllegalArgumentException - if oid is invalid
067:             */
068:            public ObjectIdentifier(int[] oid) {
069:
070:                validateOid(oid);
071:
072:                this .oid = oid;
073:            }
074:
075:            /**
076:             * Creates ObjectIdentifier(OID) from array of integers.
077:             * 
078:             * @param oid - array of integers
079:             * @param name - name of OID
080:             * @param oidGroup - OID's group. Is used to separate different OID's
081:             * @return - OID object
082:             * @throws NullPointerException     - if oid is null
083:             * @throws IllegalArgumentException - if oid is invalid
084:             */
085:            public ObjectIdentifier(int[] oid, String name, Object oidGroup) {
086:                this (oid);
087:
088:                if (oidGroup == null) {
089:                    throw new NullPointerException(Messages
090:                            .getString("security.172")); //$NON-NLS-1$
091:                }
092:                this .group = oidGroup;
093:
094:                this .name = name;
095:                toOIDString(); // init soid & sOID
096:            }
097:
098:            /**
099:             * Gets OID.
100:             * 
101:             * @return oid
102:             */
103:            public int[] getOid() {
104:                return oid;
105:            }
106:
107:            /**
108:             * Gets OID's name.
109:             * 
110:             * @return name
111:             */
112:            public String getName() {
113:                return name;
114:            }
115:
116:            /**
117:             * Gets OID's group.
118:             * 
119:             * @return group
120:             */
121:            public Object getGroup() {
122:                return group;
123:            }
124:
125:            /**
126:             * Compares object with OID for equality.
127:             * 
128:             * @return true if object is ObjectIdentifier and it has the same
129:             *         representation as array of integers, otherwise false
130:             */
131:            public boolean equals(Object o) {
132:                if (this  == o) {
133:                    return true;
134:                }
135:                if (o == null || this .getClass() != o.getClass()) {
136:                    return false;
137:                }
138:                return Arrays.equals(oid, ((ObjectIdentifier) o).oid);
139:            }
140:
141:            /**
142:             * Add "OID." to the beginning of string representation.
143:             * 
144:             * @return oid as string
145:             */
146:            public String toOIDString() {
147:                if (sOID == null) {
148:                    sOID = "OID." + toString(); //$NON-NLS-1$
149:                }
150:                return sOID;
151:            }
152:
153:            /**
154:             * Overrides Object.toString()
155:             * 
156:             * @return oid as string
157:             */
158:            public String toString() {
159:                if (soid == null) {
160:                    StringBuffer sb = new StringBuffer(4 * oid.length);
161:
162:                    for (int i = 0; i < oid.length - 1; ++i) {
163:                        sb.append(oid[i]);
164:                        sb.append('.');
165:                    }
166:                    sb.append(oid[oid.length - 1]);
167:                    soid = sb.toString();
168:                }
169:                return soid;
170:            }
171:
172:            /**
173:             * @see java.lang.Object#hashCode()
174:             */
175:            public int hashCode() {
176:                if (hash == -1) {
177:                    hash = hashIntArray(oid);
178:                }
179:                return hash;
180:            }
181:
182:            /**
183:             * Validates ObjectIdentifier (OID).
184:             * 
185:             * @param oid - oid as array of integers
186:             * @throws NullPointerException     - if oid is null
187:             * @throws IllegalArgumentException - if oid is invalid
188:             */
189:            public static void validateOid(int[] oid) {
190:
191:                if (oid == null) {
192:                    throw new NullPointerException(Messages
193:                            .getString("security.98")); //$NON-NLS-1$
194:                }
195:
196:                if (oid.length < 2) {
197:                    throw new IllegalArgumentException(Messages
198:                            .getString("security.99")); //$NON-NLS-1$
199:                }
200:
201:                if (oid[0] > 2) {
202:                    throw new IllegalArgumentException(Messages
203:                            .getString("security.9A")); //$NON-NLS-1$
204:                } else if (oid[0] != 2 && oid[1] > 39) {
205:                    throw new IllegalArgumentException(Messages
206:                            .getString("security.9B")); //$NON-NLS-1$
207:                }
208:            }
209:
210:            /**
211:             * Returns hash code for array of integers
212:             * 
213:             * @param oid - array of integers
214:             */
215:            public static int hashIntArray(int[] array) {
216:                int intHash = 0;
217:                for (int i = 0; i < array.length && i < 4; i++) {
218:                    intHash += array[i] << (8 * i); //TODO what about to find better one?
219:                }
220:                return intHash & 0x7FFFFFFF; // only positive
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.