0N/A/*
2362N/A * Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.naming;
0N/A
0N/A/**
0N/A * This class represents the binary form of the address of
0N/A * a communications end-point.
0N/A *<p>
0N/A * A BinaryRefAddr consists of a type that describes the communication mechanism
0N/A * and an opaque buffer containing the address description
0N/A * specific to that communication mechanism. The format and interpretation of
0N/A * the address type and the contents of the opaque buffer are based on
0N/A * the agreement of three parties: the client that uses the address,
0N/A * the object/server that can be reached using the address,
0N/A * and the administrator or program that creates the address.
0N/A *<p>
0N/A * An example of a binary reference address is an BER X.500 presentation address.
0N/A * Another example of a binary reference address is a serialized form of
0N/A * a service's object handle.
0N/A *<p>
0N/A * A binary reference address is immutable in the sense that its fields
0N/A * once created, cannot be replaced. However, it is possible to access
0N/A * the byte array used to hold the opaque buffer. Programs are strongly
0N/A * recommended against changing this byte array. Changes to this
0N/A * byte array need to be explicitly synchronized.
0N/A *
0N/A * @author Rosanna Lee
0N/A * @author Scott Seligman
0N/A *
0N/A * @see RefAddr
0N/A * @see StringRefAddr
0N/A * @since 1.3
0N/A */
0N/A
0N/A /*
0N/A * The serialized form of a BinaryRefAddr object consists of its type
0N/A * name String and a byte array containing its "contents".
0N/A */
0N/A
0N/Apublic class BinaryRefAddr extends RefAddr {
0N/A /**
0N/A * Contains the bytes of the address.
0N/A * This field is initialized by the constructor and returned
0N/A * using getAddressBytes() and getAddressContents().
0N/A * @serial
0N/A */
0N/A private byte[] buf = null;
0N/A
0N/A /**
0N/A * Constructs a new instance of BinaryRefAddr using its address type and a byte
0N/A * array for contents.
0N/A *
0N/A * @param addrType A non-null string describing the type of the address.
0N/A * @param src The non-null contents of the address as a byte array.
0N/A * The contents of src is copied into the new BinaryRefAddr.
0N/A */
0N/A public BinaryRefAddr(String addrType, byte[] src) {
0N/A this(addrType, src, 0, src.length);
0N/A }
0N/A
0N/A /**
0N/A * Constructs a new instance of BinaryRefAddr using its address type and
0N/A * a region of a byte array for contents.
0N/A *
0N/A * @param addrType A non-null string describing the type of the address.
0N/A * @param src The non-null contents of the address as a byte array.
0N/A * The contents of src is copied into the new BinaryRefAddr.
0N/A * @param offset The starting index in src to get the bytes.
0N/A * 0 <= offset <= src.length.
0N/A * @param count The number of bytes to extract from src.
0N/A * 0 <= count <= src.length-offset.
0N/A */
0N/A public BinaryRefAddr(String addrType, byte[] src, int offset, int count) {
0N/A super(addrType);
0N/A buf = new byte[count];
0N/A System.arraycopy(src, offset, buf, 0, count);
0N/A }
0N/A
0N/A /**
0N/A * Retrieves the contents of this address as an Object.
0N/A * The result is a byte array.
0N/A * Changes to this array will affect this BinaryRefAddr's contents.
0N/A * Programs are recommended against changing this array's contents
0N/A * and to lock the buffer if they need to change it.
0N/A *
0N/A * @return The non-null buffer containing this address's contents.
0N/A */
0N/A public Object getContent() {
0N/A return buf;
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Determines whether obj is equal to this address. It is equal if
0N/A * it contains the same address type and their contents are byte-wise
0N/A * equivalent.
0N/A * @param obj The possibly null object to check.
0N/A * @return true if the object is equal; false otherwise.
0N/A */
0N/A public boolean equals(Object obj) {
0N/A if ((obj != null) && (obj instanceof BinaryRefAddr)) {
0N/A BinaryRefAddr target = (BinaryRefAddr)obj;
0N/A if (addrType.compareTo(target.addrType) == 0) {
0N/A if (buf == null && target.buf == null)
0N/A return true;
0N/A if (buf == null || target.buf == null ||
0N/A buf.length != target.buf.length)
0N/A return false;
0N/A for (int i = 0; i < buf.length; i++)
0N/A if (buf[i] != target.buf[i])
0N/A return false;
0N/A return true;
0N/A }
0N/A }
0N/A return false;
0N/A }
0N/A
0N/A /**
0N/A * Computes the hash code of this address using its address type and contents.
0N/A * Two BinaryRefAddrs have the same hash code if they have
0N/A * the same address type and the same contents.
0N/A * It is also possible for different BinaryRefAddrs to have
0N/A * the same hash code.
0N/A *
0N/A * @return The hash code of this address as an int.
0N/A */
0N/A public int hashCode() {
0N/A int hash = addrType.hashCode();
0N/A for (int i = 0; i < buf.length; i++) {
0N/A hash += buf[i]; // %%% improve later
0N/A }
0N/A return hash;
0N/A }
0N/A
0N/A /**
0N/A * Generates the string representation of this address.
0N/A * The string consists of the address's type and contents with labels.
0N/A * The first 32 bytes of contents are displayed (in hexadecimal).
0N/A * If there are more than 32 bytes, "..." is used to indicate more.
0N/A * This string is meant to used for debugging purposes and not
0N/A * meant to be interpreted programmatically.
0N/A * @return The non-null string representation of this address.
0N/A */
0N/A public String toString(){
0N/A StringBuffer str = new StringBuffer("Address Type: " + addrType + "\n");
0N/A
0N/A str.append("AddressContents: ");
0N/A for (int i = 0; i<buf.length && i < 32; i++) {
0N/A str.append(Integer.toHexString(buf[i]) +" ");
0N/A }
0N/A if (buf.length >= 32)
0N/A str.append(" ...\n");
0N/A return (str.toString());
0N/A }
0N/A
0N/A /**
0N/A * Use serialVersionUID from JNDI 1.1.1 for interoperability
0N/A */
0N/A private static final long serialVersionUID = -3415254970957330361L;
0N/A}