BinaryRefAddr.java: New file

* javax/naming/BinaryRefAddr.java: New file
	* javax/naming/InitialContext.java: Compile fix
	* javax/naming/InvalidNameException.java: Add comments
	* javax/naming/Name.java: Ditto
	* javax/naming/NamingException.java: Implement
	* javax/naming/OperationNotSupportedException.java: Compile fix
	* javax/naming/RefAddr.java: Implement
	* javax/naming/StringRefAddr.java: Add comments and implement
	* javax/naming/directory/InitialDirContext.java: Compile fix

From-SVN: r46364
This commit is contained in:
Mark Wielaard 2001-10-19 20:36:07 +00:00 committed by Mark Wielaard
parent 03bf2c237c
commit 16f7dac7f5
10 changed files with 823 additions and 52 deletions

View File

@ -1,3 +1,15 @@
2001-10-19 Mark Wielaard <mark@klomp.org>
* javax/naming/BinaryRefAddr.java: New file
* javax/naming/InitialContext.java: Compile fix
* javax/naming/InvalidNameException.java: Add comments
* javax/naming/Name.java: Ditto
* javax/naming/NamingException.java: Implement
* javax/naming/OperationNotSupportedException.java: Compile fix
* javax/naming/RefAddr.java: Implement
* javax/naming/StringRefAddr.java: Add comments and implement
* javax/naming/directory/InitialDirContext.java: Compile fix
2001-10-18 Tom Tromey <tromey@redhat.com>
* java/io/BufferedWriter.java (write(String,int,int)): Correctly

View File

@ -0,0 +1,144 @@
/* BinaryRefAddr.java -- RefAddr that uses a byte array as content.
Copyright (C) 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package javax.naming;
import java.util.Arrays;
/**
* RefAddr that uses a byte array as content.
* This can be used to reference objects that can only be represented as
* byte arrays.
*
* @see Reference
* @since 1.3
* @author Mark Wielaard (mark@klomp.org)
*/
public class BinaryRefAddr extends RefAddr
{
/**
* The possibly null content of this RefAddr.
* Set by the constructor and returned by getContent.
*/
private final byte[] buf;
/**
* Contructs a new BinaryRefAddr with the given type and content.
* The complete content of the byte array is copied to a new array.
*/
public BinaryRefAddr (String addrType, byte[] buf)
{
this(addrType, buf, 0, buf.length);
}
/**
* Contructs a new BinaryRefAddr with the given type and the content
* taken from the given byte array.
* The content of the byte array is copied to a new array.
*/
public BinaryRefAddr (String addrType, byte[] buf, int off, int length)
{
super(addrType);
this.buf = new byte[length];
System.arraycopy(buf, off, this.buf, 0, length);
}
/**
* Returns the byte array contents as given to the constructor.
* The returned byte array is shared with this object and other callers.
* Changing the content of the buffer is discouraged and should only be
* done when the byte array is locked.
*/
public Object getContent ()
{
return buf;
}
/**
* Checks if the object is a BinaryRefAddr with the same type and with the
* same bytes in the content.
*
* @return true if the given object is an instance of BinaryRefAddr,
* the addrType is the same as this addrType and the bytes of the
* content are the same.
*/
public boolean equal(Object o)
{
if (o instanceof BinaryRefAddr)
{
BinaryRefAddr refAddr = (BinaryRefAddr) o;
if (this.getType().equals(refAddr.getType()))
{
byte[] c1 = (byte[]) this.getContent();
byte[] c2 = (byte[]) refAddr.getContent();
return Arrays.equals(c1, c2);
}
}
return false;
}
/**
* Returns the hashCode which is the hasCode of the String returned by
* <code>getType()</code> plus the hashCode of the byte array returned by
* <code>getContent</code>. The hashCode of the byte array is calculated
* by taking the xor of all the bytes in the array, or zero when there are
* no bytes in the array.
*/
public int hashCode()
{
int result = 0;
byte[] b = (byte[]) getContent();
for (int i=0; i < b.length; i++)
result = result^b[i];
return getType().hashCode() + result;
}
private static char[] hex = {'0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
/**
* Returns a String representation of the RefAddr. Only the first 32 bytes
* of the content are added as hex encoded characters.
* Should only be used for debugging purposes.
*/
public String toString()
{
StringBuffer sb = new StringBuffer("[RefAddr type: ");
sb.append(getType());
sb.append(" content: 0x");
byte[] b = (byte[]) getContent();
for (int i=0; i < b.length && i < 32; i++)
{
sb.append(hex[(b[i]&0xf0)>>4]);
sb.append(hex[b[i]&0x0f]);
}
if (b.length > 32)
sb.append("...");
sb.append("]");
return sb.toString();
}
}

View File

@ -308,12 +308,12 @@ public class InitialContext implements Context
public Object addToEnvironment (String propName,
Object propVal) throws NamingException
{
myProps.put (propName, propVal);
return myProps.put (propName, propVal);
}
public Object removeFromEnvironment (String propName) throws NamingException
{
myProps.remove (propName);
return myProps.remove (propName);
}
public Hashtable getEnvironment () throws NamingException

View File

@ -1,22 +1,53 @@
/* Copyright (C) 2000 Free Software Foundation
/* InvalidNameException.java -- Exception indicating an invalid component/name
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package javax.naming;
import java.lang.Exception;
/**
* Exception indicating an invalid component or <code>Name</code>.
* Thrown when a <code>Name</code> or component of a name is encountered that
* does not follow the syntactic rules of a particular <code>Name</code> class.
*
* @author Anthony Green (green@redhat.com)
* @author Mark Wielaard (mark@klomp.org)
*/
public class InvalidNameException extends NamingException
{
/**
* Creates a new exception without setting any of its fields.
*/
public InvalidNameException ()
{
super ();
}
/**
* Creates a new exception and sets the detailed message field.
* All other fields are not set.
*/
public InvalidNameException (String msg)
{
super (msg);

View File

@ -1,31 +1,185 @@
/* Copyright (C) 2000 Free Software Foundation
/* Name.java -- Name build up from different components
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package javax.naming;
import java.util.Enumeration;
import java.io.Serializable;
/**
* Interface descriping a name build up from different components.
* The components are represented as <code>String</code>s which are
* ordered from most significant to least significant. There are methods to
* get the number of components. Methods to get a particular component or group
* of components. Components can be added as <code>String</code>s or
* <code>Name</code>s and a component can be removed from any position in the
* <code>Name</code>.
* A <code>Name</code> can be compared to another <code>Name</code> and it can
* be checked if a particular <code>Name</code> starts or ends with the same
* components as another <code>Name</code>. Finally <code>Name</code>s can be
* serialized and cloned.
* <p>
* Since <code>Name</code>s can be empty (have no components) methods that
* return a <code>Name</code> will never return <code>null</code>.
*
* @since 1.3
* @author Anthony Green (green@redhat.com)
* @author Mark Wielaard (mark@klomp.org)
*/
public interface Name extends Cloneable, Serializable
{
public Object clone();
public int compareTo(Object obj);
/**
* Returns the number of components of this <code>Name</code>.
* The returned number can be zero.
*/
public int size();
/**
* Returns <code>true</code> if the number of components of this
* <code>Name</code> is zero, <code>false</code> otherwise.
*/
public boolean isEmpty();
/**
* Returns a non-null (but possibly empty) <code>Enumeration</code> of the
* components of the <code>Name</code> as <code>String</code>s.
*/
public Enumeration getAll();
public String get(int posn);
public Name getPrefix(int posn);
public Name getSuffix(int posn);
public boolean startsWith(Name n);
public boolean endsWith(Name n);
public Name addAll(Name suffix) throws InvalidNameException;
public Name addAll(int posn, Name n) throws InvalidNameException;
/**
* Gets the component at the given index.
*
* @exception ArrayIndexOutOfBoundsException if the given index is smaller
* then zero or greater then or equal to <code>size()</code>.
*/
public String get(int i);
/**
* Returns the components till the given index as a <code>Name</code>.
* The returned <code>Name</code> can be modified without changing the
* original.
*
* @exception ArrayIndexOutOfBoundsException if the given index is smaller
* then zero or greater then or equal to <code>size()</code>.
*/
public Name getPrefix(int i);
/**
* Returns the components from the given index till the end as a
* <code>Name</code>.
* The returned <code>Name</code> can be modified without changing the
* original.
*
* @exception ArrayIndexOutOfBoundsException if the given index is smaller
* then zero or greater then or equal to <code>size()</code>.
*/
public Name getSuffix(int i);
/**
* Adds the given <code>String</code> component to the end of this
* <code>Name</code>. The method modifies the current <code>Name</code> and
* then returns it.
*
* @exception InvalidNameException if the given <code>String</code> is not a
* valid component for this <code>Name</code>.
*/
public Name add(String comp) throws InvalidNameException;
/**
* Inserts the given <code>String</code> component to this <code>Name</code>
* at the given index. The method modifies the current <code>Name</code> and
* then returns it.
*
* @exception ArrayIndexOutOfBoundsException if the given index is smaller
* then zero or greater then or equal to <code>size()</code>.
* @exception InvalidNameException if the given <code>String</code> is not a
* valid component for this <code>Name</code>.
*/
public Name add(int posn, String comp) throws InvalidNameException;
/**
* Adds all the components of the given <code>Name</code> to the end of this
* <code>Name</code>. The method modifies the current <code>Name</code> and
* then returns it.
*
* @exception InvalidNameException if any of the given components is not a
* valid component for this <code>Name</code>.
*/
public Name addAll(Name suffix) throws InvalidNameException;
/**
* Inserts all the components of the given <code>Name</code> to this
* <code>Name</code> at the given index. The method modifies the current
* <code>Name</code> and then returns it.
*
* @exception ArrayIndexOutOfBoundsException if the given index is smaller
* then zero or greater then or equal to <code>size()</code>.
* @exception InvalidNameException if any of the given components is not a
* valid component for this <code>Name</code>.
*/
public Name addAll(int posn, Name n) throws InvalidNameException;
/**
* Removes the component at the given index from this <code>Name</code>.
* The method modifies the current <code>Name</code> and then returns it.
*
* @exception InvalidNameException if the given <code>String</code> is not a
* valid component for this <code>Name</code>.
*/
public Object remove(int posn) throws InvalidNameException;
/**
* Returns <code>true</code> if this <code>Name</code> starts with the
* components of the given <code>Name</code>, <code>false</code> otherwise.
*/
public boolean startsWith(Name name);
/**
* Returns <code>true</code> if this <code>Name</code> ends with the
* components of the given <code>Name</code>, <code>false</code> otherwise.
*/
public boolean endsWith(Name name);
/**
* Compares the given object to this <code>Name</code>.
* Returns a negative value if the given <code>Object</code> is smaller then
* this <code>Name</code>, a positive value if the <code>Object</code> is
* bigger, and zero if the are equal. If the <code>Object</code> is not of
* a class that can be compared to the class of this <code>Name</code> then
* a <code>ClassCastException</code> is thrown. Note that it is not
* guaranteed that <code>Name</code>s implemented in different classes can
* be compared. The definition of smaller, bigger and equal is up to the
* actual implementing class.
*/
public int compareTo(Object obj);
/**
* Returns a clone of this <code>Name</code>. It will be a deep copy of
* all the components of the <code>Name</code> so that changes to components
* of the components does not change the component in this <code>Name</code>.
*/
public Object clone();
}

View File

@ -1,36 +1,303 @@
/* Copyright (C) 2000 Free Software Foundation
/* NamingException.java -- Superclass of all naming Exceptions
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package javax.naming;
import java.lang.Exception;
import java.io.PrintStream;
import java.io.PrintWriter;
/**
* Superclass of all naming Exceptions.
* Can contain extra information about the root cause of this exception
* (for example when the original exception was not a subclass of
* <code>NamingException</code>), the part of the <code>Name</code> that
* could be resolved (including the <code>Object</code> it resolved to)
* and the part of the <code>Name</code> that could not be resolved when
* the exception occured.
*
* @since 1.3
* @author Anthony Green (green@redhat.com)
* @author Mark Wielaard (mark@klomp.org)
*/
public class NamingException extends Exception
{
/**
* The root cause of this exception. Might be null. Set by calling
* <code>setRootCause()</code>, can be accessed by calling
* <code>getRootCause()</code>.
*/
protected Throwable rootException;
public NamingException()
/**
* If the exception was caused while resolving a <code>Name</code> then
* this field contains that part of the name that could be resolved.
* Field might be null. Set by calling <code>setResolvedName()</code>.
* Can be accessed by calling <code>getResolvedName</code>.
*/
protected Name resolvedName;
/**
* If the exception was caused while resolving a <code>Name</code> then
* this field contains the object that part of the name could be resolved to.
* Field might be null. Set by calling <code>setResolvedObj()</code>.
* Can be accessed by calling <code>getResolvedObj</code>.
*/
protected Object resolvedObj;
/**
* If the exception was caused while resolving a <code>Name</code> then
* this field contains that part of the name that could not be resolved.
* Field might be null. Set by calling <code>setRemainingName()</code>.
* The field can be extended by calling <code>appendRemainingName()</code>
* or <code>appendRemainingComponent()</code>.
* Can be accessed by calling <code>getRemainingName</code>.
*/
protected Name remainingName;
/**
* Creates a new NamingException without a message. Does not set any of the
* <code>rootException</code>, <code>resolvedName</code>,
* <code>resolvedObj</code> or <code>remainingObject,<code> fields.
* These fields can be set later.
*/
public NamingException ()
{
super();
}
public NamingException(String msg)
/**
* Creates a new NamingException with a detailed message. Does not set
* the <code>rootException</code>, <code>resolvedName</code>,
* <code>resolvedObj</code> or <code>remainingObject,<code> fields.
* These fields can be set later.
*/
public NamingException (String msg)
{
super(msg);
}
/**
* Gets the root cause field <code>rootException</code> of this Exception.
*/
public Throwable getRootCause ()
{
return rootException;
}
/**
* Sets the root cause field <code>rootException</code> of this Exception.
*/
public void setRootCause (Throwable e)
{
rootException = e;
}
/**
* Gets the part of the name that could be resolved before this exception
* happend. Returns the <code>resolvedName</code> field of this Exception.
*/
public Name getResolvedName ()
{
return resolvedName;
}
/**
* Sets the part of the name that could be resolved before this exception
* happend. Sets the <code>resolvedName</code> field of this Exception.
*/
public void setResolvedName (Name name)
{
resolvedName = name;
}
/**
* Gets the Object to which (part of) the name could be resolved before this
* exception happend. Returns the <code>resolvedObj</code> field of this
* Exception.
*/
public Object getResolvedObj ()
{
return resolvedObj;
}
/**
* Sets the Object to which (part of) the name could be resolved before this
* exception happend. Sets the <code>resolvedObj</code> field of this
* Exception.
*/
public void setResolvedObj (Object o)
{
resolvedObj = o;
}
/**
* Gets the part of the name that could not be resolved before this exception
* happend. Returns the <code>remainingName</code> field of this Exception.
*/
public Name getRemainingName ()
{
return remainingName;
}
/**
* Sets the part of the name that could be resolved before this exception
* happend. Sets the <code>resolvedName</code> field of this Exception.
* The field can be extended by calling <code>appendRemainingName()</code>
* or <code>appendRemainingComponent()</code>.
*/
public void setRemainingName (Name name)
{
remainingName = name;
}
/**
* Adds the given <code>Name</code> to the <code>remainingName</code> field.
* Does nothing when <code>name</code> is null or when a
* <code>InvalidNameException</code> is thrown when adding the name.
*
* @see Name#addAll(Name)
*/
public void appendRemainingName (Name name)
{
if (name != null)
try
{
remainingName.addAll(name);
}
catch(InvalidNameException ine) { /* ignored */ }
}
/**
* Adds the given <code>String</code> to the <code>remainingName</code> field.
* Does nothing when <code>name</code> is null or when a
* <code>InvalidNameException</code> is thrown when adding the component.
*
* @see Name#add(String)
*/
public void appendRemainingComponent (String name)
{
if (name != null)
try
{
remainingName.add(name);
}
catch(InvalidNameException ine) { /* ignored */ }
}
/**
* Gets the message given to the constructor or null if no message was given.
*
* @see Throwable#getMessage();
*/
public String getExplanation()
{
return getMessage();
}
/**
* Returns a String representation of this exception and possibly including
* the part object that could be resolved if the given flag is set to true.
* Always includes the root cause and the remaining name if not null.
*/
public String toString(boolean objectInfo)
{
StringBuffer sb = new StringBuffer(super.toString());
Throwable cause = getRootCause();
if (cause != null)
{
sb.append(" caused by ");
sb.append(cause);
}
Name remaining = getRemainingName();
if (remaining != null)
{
sb.append(" [remainingName: ");
sb.append(remaining);
}
Object resolved = getResolvedObj();
if (objectInfo && resolved != null)
{
if (remainingName == null)
sb.append(" [");
else
sb.append(", ");
sb.append("resolvedObj: ");
sb.append(resolved);
}
if ((remaining != null) || (objectInfo && resolved != null))
sb.append(']');
return sb.toString();
}
/**
* Returns a string representation of this exception.
* Calls <code>toString(false)</code>.
*/
public String toString()
{
return toString(false);
}
/**
* Prints the stacktrace of this exception or of the root cause if not null.
*/
public void printStackTrace()
{
Throwable cause = getRootCause();
if (cause != null)
cause.printStackTrace();
else
super.printStackTrace();
}
/**
* Prints the stacktrace of this exception or of the root cause if not null
* to the given <code>PrintStream</code>.
*/
public void printStackTrace(PrintStream ps)
{
Throwable cause = getRootCause();
if (cause != null)
cause.printStackTrace(ps);
else
super.printStackTrace(ps);
}
/**
* Prints the stacktrace of this exception or of the root cause if not null
* to the given <code>PrintWriter</code>.
*/
public void printStackTrace(PrintWriter pw)
{
Throwable cause = getRootCause();
if (cause != null)
cause.printStackTrace(pw);
else
super.printStackTrace(pw);
}
}

View File

@ -8,9 +8,7 @@ details. */
package javax.naming;
import java.lang.Exception;
public class OperationNotSupportedException extends Exception
public class OperationNotSupportedException extends NamingException
{
public OperationNotSupportedException()
{

View File

@ -1,15 +1,131 @@
/* Copyright (C) 2000 Free Software Foundation
/* RefAddr.java -- Abstract superclass of addresses used in References
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package javax.naming;
import java.io.Serializable;
public class RefAddr implements Serializable
/**
* Abstract superclass of addresses used in References.
* A <code>Reference</code> object contains a <code>Vector</code> of
* <code>RefAddr</code>s which are used to reference/address the object.
* This abstract superclass keeps track of the type of address, which will be
* returned by <code>getType()</code>. And defines a abstract method
* <code>getContent()</code> which must be implemented in concrete subclasses
* such as <code>BinaryRefAddr</code> and <code>StringRefAddr</code>.
*
* @see Reference
* @see BinaryRefAddr
* @see StringRefAddr
* @since 1.3
* @author Anthony Green (green@redhat.com)
* @author Mark Wielaard (mark@klomp.org)
*/
public abstract class RefAddr implements Serializable
{
/**
* The string resprenstation of the type of address.
* Set by the constructor and returned by the getType() method.
*/
protected final String addrType;
/**
* Protected constructor for use by subclasses.
* Sets the addrType field of this object to the supplied String.
*
* @exception NullPointerException if the supplied String is null.
*/
protected RefAddr(String addrType)
{
if (addrType == null)
throw new NullPointerException("addrType cannot be null");
this.addrType = addrType;
}
/**
* Returns the non-null address type given to the constructor.
*/
public String getType()
{
return addrType;
}
/**
* Returns the possibly null content of this RefAddr.
* The actual value is defined by the non-abstract subclass.
*/
public abstract Object getContent();
/**
* Checks if the object is a RefAddr with the same type and content.
*
* @return true if the given object is an instance of RefAddr, the addrType
* is the same as this addrType and the content is equals to the
* content of this object.
*/
public boolean equal(Object o)
{
if (o instanceof RefAddr)
{
RefAddr refAddr = (RefAddr) o;
if (this.getType().equals(refAddr.getType()))
{
Object c1 = this.getContent();
Object c2 = refAddr.getContent();
if (c1 == null)
return c2 == null;
else
return c1.equals(c2);
}
}
return false;
}
/**
* Returns the hashCode which is the hasCode of the String returned by
* <code>getType()</code> plus the hashCode of the Object returned by
* <code>getContent</code> (when not null).
*/
public int hashCode()
{
int result = getType().hashCode();
Object o = getContent();
if (o != null)
result += o.hashCode();
return result;
}
/**
* Returns a String representation of the RefAddr.
* Should only be used for debugging purposes.
*/
public String toString()
{
return "[RefAddr type: " + getType() + " content: " + getContent() + ']';
}
}

View File

@ -1,24 +1,63 @@
/* Copyright (C) 2000 Free Software Foundation
/* StringRefAddr.java -- RefAddr that uses a String as content.
Copyright (C) 2000, 2001 Free Software Foundation, Inc.
This file is part of libgcj.
This file is part of GNU Classpath.
This software is copyrighted work licensed under the terms of the
Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
details. */
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA.
As a special exception, if you link this library with other files to
produce an executable, this library does not by itself cause the
resulting executable to be covered by the GNU General Public License.
This exception does not however invalidate any other reasons why the
executable file might be covered by the GNU General Public License. */
package javax.naming;
import java.io.Serializable;
/**
* RefAddr that uses a String as content.
* This can for example be used to address things through URLs.
*
* @see Reference
* @since 1.3
* @author Anthony Green (green@redhat.com)
* @author Mark Wielaard (mark@klomp.org)
*/
public class StringRefAddr extends RefAddr
{
public StringRefAddr (String addrType, String addr)
/**
* The possibly null content of this RefAddr.
* Set by the constructor and returned by getContent.
*/
private final String contents;
/**
* Contructs a new StringRefAddr with the given type and content.
*/
public StringRefAddr (String addrType, String contents)
{
throw new Error ("javax.naming.StringRefAddr not implemented");
super(addrType);
this.contents = contents;
}
/**
* Returns the String contents as given to the constructor.
*/
public Object getContent ()
{
throw new Error ("javax.naming.StringRefAddr.getContent not implemented");
return contents;
}
}

View File

@ -17,4 +17,14 @@ public class InitialDirContext extends InitialContext implements DirContext
{
throw new Error ("javax.naming.directory.InitialDirContext not implemented");
}
public Attributes getAttributes (String name)
{
throw new Error ("getAttributes not implemented");
}
public Attributes getAttributes (String name, String[] attrIds)
{
throw new Error ("getAttributes not implemented");
}
}