Source Code Cross Referenced for BinaryRefAddr.java in  » Apache-Harmony-Java-SE » javax-package » javax » naming » 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 » javax package » javax.naming 
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:        package javax.naming;
019:
020:        import java.util.Arrays;
021:
022:        /**
023:         * A <code>BinaryRefAddr</code> refers to an address which is represented by a
024:         * binary address.
025:         */
026:        public class BinaryRefAddr extends RefAddr {
027:
028:            private static final long serialVersionUID = -3415254970957330361L;
029:
030:            /**
031:             * The buffer for the binary address itself.
032:             * 
033:             * @serial
034:             */
035:            private byte[] buf;
036:
037:            /**
038:             * Constructs a <code>BinaryRefAddr</code> using the specified address
039:             * type and the full details of the supplied byte array.
040:             * 
041:             * @param type
042:             *            the address type which cannot be null
043:             * @param address
044:             *            the address itself which cannot be null
045:             */
046:            public BinaryRefAddr(String type, byte[] address) {
047:                this (type, address, 0, address.length);
048:            }
049:
050:            /**
051:             * Constructs a <code>BinaryRefAddr</code> using the specified address
052:             * type and part of the supplied byte array. The number of bytes to be taken
053:             * is specified by <code>size</code>. Additionally these bytes are taken
054:             * from a starting point specified by <code>index</code>.
055:             * 
056:             * @param type
057:             *            the address type. It cannot be null.
058:             * @param address
059:             *            the address itself. It cannot be null.
060:             * @param index
061:             *            the starting point to copy bytes from. It must be greater than
062:             *            or equal to zero and must be less than or equal to the size of
063:             *            the byte array.
064:             * @param size
065:             *            the number of bytes to copy. It must be greater than or equal
066:             *            to zero and must be less than or equal to the size of the byte
067:             *            array less the starting position.
068:             * @throws ArrayIndexOutOfBoundsException
069:             *             If <code>size</code> or <code>index</code> does not meet
070:             *             the constraints.
071:             */
072:            public BinaryRefAddr(String type, byte[] address, int index,
073:                    int size) {
074:                super (type);
075:                this .buf = new byte[size];
076:                System.arraycopy(address, index, this .buf, 0, size);
077:            }
078:
079:            /**
080:             * Gets the content of this address.
081:             * 
082:             * @return an array of bytes containing the address. It cannot be null.
083:             */
084:            @Override
085:            public Object getContent() {
086:                return buf;
087:            }
088:
089:            /**
090:             * Returns true if this address is equal to the supplied object
091:             * <code>o</code>. They are considered equal if the address types are
092:             * equal and the data in the buffers is of the same length and contains the
093:             * same bytes.
094:             * 
095:             * @param o
096:             *            the object to compare with
097:             * @return true if this address is equal to <code>o</code>, otherwise
098:             *         false
099:             */
100:            @Override
101:            public boolean equals(Object o) {
102:                if (o instanceof  BinaryRefAddr) {
103:                    BinaryRefAddr a = (BinaryRefAddr) o;
104:                    return this .addrType.equals(a.addrType)
105:                            && Arrays.equals(this .buf, a.buf);
106:                }
107:                return false;
108:            }
109:
110:            /**
111:             * Returns the hashcode of this address. The result is the hashcode of the
112:             * address type added to each byte from the data buffer.
113:             * 
114:             * @return the hashcode of this address
115:             */
116:            @Override
117:            public int hashCode() {
118:                int i = this .addrType.hashCode();
119:
120:                for (byte element : this .buf) {
121:                    i += element;
122:                }
123:                return i;
124:            }
125:
126:            /**
127:             * Returns the string representation of this address. The string includes
128:             * the address type and a maximum of 128 bytes address content expressed in
129:             * hexadecimal form.
130:             * 
131:             * @return the string representation of this address
132:             */
133:            @Override
134:            public String toString() {
135:                String s = "The type of the address is: " //$NON-NLS-1$
136:                        + this .addrType + "\nThe content of the address is: "; //$NON-NLS-1$
137:                int max = this .buf.length > 128 ? 128 : this .buf.length;
138:
139:                for (int i = 0; i < max; i++) {
140:                    s += Integer.toHexString(this .buf[i]) + " "; //$NON-NLS-1$
141:                }
142:                s = s.substring(0, s.length() - 1) + "\n"; //$NON-NLS-1$
143:
144:                return s;
145:            }
146:
147:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.