From 16f7dac7f50249b115103ce71cf55301b1c35538 Mon Sep 17 00:00:00 2001 From: Mark Wielaard Date: Fri, 19 Oct 2001 20:36:07 +0000 Subject: [PATCH] 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 --- libjava/ChangeLog | 12 + libjava/javax/naming/BinaryRefAddr.java | 144 +++++++++ libjava/javax/naming/InitialContext.java | 4 +- .../javax/naming/InvalidNameException.java | 45 ++- libjava/javax/naming/Name.java | 182 ++++++++++- libjava/javax/naming/NamingException.java | 285 +++++++++++++++++- .../OperationNotSupportedException.java | 4 +- libjava/javax/naming/RefAddr.java | 128 +++++++- libjava/javax/naming/StringRefAddr.java | 61 +++- .../naming/directory/InitialDirContext.java | 10 + 10 files changed, 823 insertions(+), 52 deletions(-) create mode 100644 libjava/javax/naming/BinaryRefAddr.java diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 6e3b562ad67..2554add64f4 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,15 @@ +2001-10-19 Mark Wielaard + + * 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 * java/io/BufferedWriter.java (write(String,int,int)): Correctly diff --git a/libjava/javax/naming/BinaryRefAddr.java b/libjava/javax/naming/BinaryRefAddr.java new file mode 100644 index 00000000000..f44e43fd007 --- /dev/null +++ b/libjava/javax/naming/BinaryRefAddr.java @@ -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 + * getType() plus the hashCode of the byte array returned by + * getContent. 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(); + } +} diff --git a/libjava/javax/naming/InitialContext.java b/libjava/javax/naming/InitialContext.java index a670d7b204e..6ee6a9a8e54 100644 --- a/libjava/javax/naming/InitialContext.java +++ b/libjava/javax/naming/InitialContext.java @@ -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 diff --git a/libjava/javax/naming/InvalidNameException.java b/libjava/javax/naming/InvalidNameException.java index c1ccb19aefa..cedce55e115 100644 --- a/libjava/javax/naming/InvalidNameException.java +++ b/libjava/javax/naming/InvalidNameException.java @@ -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 Name. + * Thrown when a Name or component of a name is encountered that + * does not follow the syntactic rules of a particular Name 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); diff --git a/libjava/javax/naming/Name.java b/libjava/javax/naming/Name.java index 5fe612a2acc..1f13e3ce331 100644 --- a/libjava/javax/naming/Name.java +++ b/libjava/javax/naming/Name.java @@ -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 Strings 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 Strings or + * Names and a component can be removed from any position in the + * Name. + * A Name can be compared to another Name and it can + * be checked if a particular Name starts or ends with the same + * components as another Name. Finally Names can be + * serialized and cloned. + *

+ * Since Names can be empty (have no components) methods that + * return a Name will never return null. + * + * @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 Name. + * The returned number can be zero. + */ public int size(); + + /** + * Returns true if the number of components of this + * Name is zero, false otherwise. + */ public boolean isEmpty(); + + /** + * Returns a non-null (but possibly empty) Enumeration of the + * components of the Name as Strings. + */ 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 size(). + */ + public String get(int i); + + /** + * Returns the components till the given index as a Name. + * The returned Name can be modified without changing the + * original. + * + * @exception ArrayIndexOutOfBoundsException if the given index is smaller + * then zero or greater then or equal to size(). + */ + public Name getPrefix(int i); + + /** + * Returns the components from the given index till the end as a + * Name. + * The returned Name can be modified without changing the + * original. + * + * @exception ArrayIndexOutOfBoundsException if the given index is smaller + * then zero or greater then or equal to size(). + */ + public Name getSuffix(int i); + + /** + * Adds the given String component to the end of this + * Name. The method modifies the current Name and + * then returns it. + * + * @exception InvalidNameException if the given String is not a + * valid component for this Name. + */ public Name add(String comp) throws InvalidNameException; + + /** + * Inserts the given String component to this Name + * at the given index. The method modifies the current Name and + * then returns it. + * + * @exception ArrayIndexOutOfBoundsException if the given index is smaller + * then zero or greater then or equal to size(). + * @exception InvalidNameException if the given String is not a + * valid component for this Name. + */ public Name add(int posn, String comp) throws InvalidNameException; + + /** + * Adds all the components of the given Name to the end of this + * Name. The method modifies the current Name and + * then returns it. + * + * @exception InvalidNameException if any of the given components is not a + * valid component for this Name. + */ + public Name addAll(Name suffix) throws InvalidNameException; + + /** + * Inserts all the components of the given Name to this + * Name at the given index. The method modifies the current + * Name and then returns it. + * + * @exception ArrayIndexOutOfBoundsException if the given index is smaller + * then zero or greater then or equal to size(). + * @exception InvalidNameException if any of the given components is not a + * valid component for this Name. + */ + public Name addAll(int posn, Name n) throws InvalidNameException; + + /** + * Removes the component at the given index from this Name. + * The method modifies the current Name and then returns it. + * + * @exception InvalidNameException if the given String is not a + * valid component for this Name. + */ public Object remove(int posn) throws InvalidNameException; + + /** + * Returns true if this Name starts with the + * components of the given Name, false otherwise. + */ + public boolean startsWith(Name name); + + /** + * Returns true if this Name ends with the + * components of the given Name, false otherwise. + */ + public boolean endsWith(Name name); + + /** + * Compares the given object to this Name. + * Returns a negative value if the given Object is smaller then + * this Name, a positive value if the Object is + * bigger, and zero if the are equal. If the Object is not of + * a class that can be compared to the class of this Name then + * a ClassCastException is thrown. Note that it is not + * guaranteed that Names 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 Name. It will be a deep copy of + * all the components of the Name so that changes to components + * of the components does not change the component in this Name. + */ + public Object clone(); } diff --git a/libjava/javax/naming/NamingException.java b/libjava/javax/naming/NamingException.java index 4cd87061123..b214f19f519 100644 --- a/libjava/javax/naming/NamingException.java +++ b/libjava/javax/naming/NamingException.java @@ -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 + * NamingException), the part of the Name that + * could be resolved (including the Object it resolved to) + * and the part of the Name 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 + * setRootCause(), can be accessed by calling + * getRootCause(). + */ protected Throwable rootException; - public NamingException() + /** + * If the exception was caused while resolving a Name then + * this field contains that part of the name that could be resolved. + * Field might be null. Set by calling setResolvedName(). + * Can be accessed by calling getResolvedName. + */ + protected Name resolvedName; + + /** + * If the exception was caused while resolving a Name then + * this field contains the object that part of the name could be resolved to. + * Field might be null. Set by calling setResolvedObj(). + * Can be accessed by calling getResolvedObj. + */ + protected Object resolvedObj; + + /** + * If the exception was caused while resolving a Name then + * this field contains that part of the name that could not be resolved. + * Field might be null. Set by calling setRemainingName(). + * The field can be extended by calling appendRemainingName() + * or appendRemainingComponent(). + * Can be accessed by calling getRemainingName. + */ + protected Name remainingName; + + /** + * Creates a new NamingException without a message. Does not set any of the + * rootException, resolvedName, + * resolvedObj or remainingObject, 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 rootException, resolvedName, + * resolvedObj or remainingObject, fields. + * These fields can be set later. + */ + public NamingException (String msg) { super(msg); } + /** + * Gets the root cause field rootException of this Exception. + */ public Throwable getRootCause () { return rootException; } + /** + * Sets the root cause field rootException 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 resolvedName 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 resolvedName 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 resolvedObj 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 resolvedObj 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 remainingName 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 resolvedName field of this Exception. + * The field can be extended by calling appendRemainingName() + * or appendRemainingComponent(). + */ + public void setRemainingName (Name name) + { + remainingName = name; + } + + /** + * Adds the given Name to the remainingName field. + * Does nothing when name is null or when a + * InvalidNameException 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 String to the remainingName field. + * Does nothing when name is null or when a + * InvalidNameException 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 toString(false). + */ + 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 PrintStream. + */ + 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 PrintWriter. + */ + public void printStackTrace(PrintWriter pw) + { + Throwable cause = getRootCause(); + if (cause != null) + cause.printStackTrace(pw); + else + super.printStackTrace(pw); + } } + diff --git a/libjava/javax/naming/OperationNotSupportedException.java b/libjava/javax/naming/OperationNotSupportedException.java index 0c154ebfd68..6259b1ee535 100644 --- a/libjava/javax/naming/OperationNotSupportedException.java +++ b/libjava/javax/naming/OperationNotSupportedException.java @@ -8,9 +8,7 @@ details. */ package javax.naming; -import java.lang.Exception; - -public class OperationNotSupportedException extends Exception +public class OperationNotSupportedException extends NamingException { public OperationNotSupportedException() { diff --git a/libjava/javax/naming/RefAddr.java b/libjava/javax/naming/RefAddr.java index 1973efba29e..4c1659cbc26 100644 --- a/libjava/javax/naming/RefAddr.java +++ b/libjava/javax/naming/RefAddr.java @@ -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 Reference object contains a Vector of + * RefAddrs which are used to reference/address the object. + * This abstract superclass keeps track of the type of address, which will be + * returned by getType(). And defines a abstract method + * getContent() which must be implemented in concrete subclasses + * such as BinaryRefAddr and StringRefAddr. + * + * @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 + * getType() plus the hashCode of the Object returned by + * getContent (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() + ']'; + } } diff --git a/libjava/javax/naming/StringRefAddr.java b/libjava/javax/naming/StringRefAddr.java index 7ceffa34f74..b813be720f3 100644 --- a/libjava/javax/naming/StringRefAddr.java +++ b/libjava/javax/naming/StringRefAddr.java @@ -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. -package javax.naming; +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. */ -import java.io.Serializable; +package javax.naming; +/** + * 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; } } diff --git a/libjava/javax/naming/directory/InitialDirContext.java b/libjava/javax/naming/directory/InitialDirContext.java index 2e8915066cc..a63160f2ea1 100644 --- a/libjava/javax/naming/directory/InitialDirContext.java +++ b/libjava/javax/naming/directory/InitialDirContext.java @@ -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"); + } } -- 2.30.2