harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r557139 [2/2] - in /harmony/enhanced/classlib/branches/java6: ./ make/ modules/beans/META-INF/ modules/beans/src/main/java/java/beans/ modules/beans/src/main/java/java/beans/beancontext/ modules/beans/src/main/java/org/apache/harmony/beans/...
Date Wed, 18 Jul 2007 04:05:11 GMT
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLEncoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLEncoder.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLEncoder.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLEncoder.java Tue Jul 17 21:05:08 2007
@@ -15,603 +15,888 @@
  *  limitations under the License.
  */
 
+
 package java.beans;
 
-import java.io.IOException;
+import java.awt.SystemColor;
+import java.awt.font.TextAttribute;
 import java.io.OutputStream;
-import java.util.Enumeration;
-import java.util.HashMap;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.io.UnsupportedEncodingException;
+import java.lang.reflect.Array;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.IdentityHashMap;
 import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Vector;
-
-import org.apache.harmony.beans.ObjectNode;
-import org.apache.harmony.beans.internal.nls.Messages;
+import java.util.List;
 
+/**
+ * <code>XMLEncoder</code> exnteds <code>Encoder</code> to write out the
+ * encoded statements and expressions in xml format. The xml can be read by
+ * <code>XMLDecoder</code> later to restore objects and their states.
+ * <p>
+ * The API is similar to <code>ObjectOutputStream</code>.
+ * </p>
+ * 
+ */
 public class XMLEncoder extends Encoder {
 
-    private OutputStream out;
+	/*
+	 * Every object written by the encoder has a record.
+	 */
+	private static class Record {
+		boolean born = false;
+
+		// The expression by which the object is created or obtained.
+		Expression exp = null;
 
-    private Object owner;
+		// Id of the object, if it is referenced more than once.
+		String id = null;
 
-    private final Vector<ObjectNode> printed = new Vector<ObjectNode>();
+		// Count of the references of the object.
+		int refCount = 0;
 
-    public XMLEncoder(OutputStream out) {
-        this.out = out;
-        this.owner = null;
-    }
-
-    @Override
-    public void writeObject(Object object) {
-        super.writeObject(object);
-    }
-
-    public void setOwner(Object owner) {
-        this.owner = owner;
-    }
-
-    public Object getOwner() {
-        return owner;
-    }
-    
-    @Override
-    public void writeExpression(Expression oldExp) {
+		// A list of statements that execute on the object.
+		ArrayList stats = new ArrayList();
+	}
 
-		Object oldValue = null;
-		try {
-			oldValue = oldExp.getValue();
-		} catch (Exception e) {
-			getExceptionListener()
-					.exceptionThrown(
-							new Exception("failed to execute expression: "
-									+ oldExp, e));
+	private static final int INDENT_UNIT = 1;
+
+	private static final boolean isStaticConstantsSupported = true;
+
+	// the main record of all root objects
+	private ArrayList flushPending = new ArrayList();
+
+	// the record of root objects with a void tag
+	private ArrayList flushPendingStat = new ArrayList();
+
+	// keep the pre-required objects for each root object
+	private ArrayList flushPrePending = new ArrayList();
+
+	private boolean hasXmlHeader = false;
+
+	private int idSerialNo = 0;
+
+	/*
+	 * if any expression or statement references owner, it is set true in method
+	 * recordStatement() or recordExpressions(), and, at the first time
+	 * flushObject() meets an owner object, it calls the flushOwner() method and
+	 * then set needOwner to false, so that all succeeding flushing of owner
+	 * will call flushExpression() or flushStatement() normally, which will get
+	 * a reference of the owner property.
+	 */
+	private boolean needOwner = false;
+
+	private PrintWriter out;
+
+	private Object owner = null;
+
+	private IdentityHashMap records = new IdentityHashMap();
+
+	private boolean writingObject = false;
+
+	/**
+	 * Construct a <code>XMLEncoder</code>.
+	 * 
+	 * @param out
+	 *            the output stream where xml is writtern to
+	 */
+	public XMLEncoder(OutputStream out) {
+		if (null != out) {
+            try {
+                this.out = new PrintWriter(
+                        new OutputStreamWriter(out, "UTF-8"), true);
+            } catch (UnsupportedEncodingException e) {
+                // never occur
+                e.printStackTrace();
+            }
+        }
+	}
+
+	/**
+	 * Call <code>flush()</code> first, then write out xml footer and close
+	 * the underlying output stream.
+	 */
+	public void close() {
+		flush();
+		out.println("</java>");
+		out.close();
+	}
+
+	private StringBuffer decapitalize(String s) {
+		StringBuffer buf = new StringBuffer(s);
+		buf.setCharAt(0, Character.toLowerCase(buf.charAt(0)));
+		return buf;
+	}
+
+	/**
+	 * Writes out all objects since last flush to the output stream.
+	 * <p>
+	 * The implementation write the xml header first if it has not been
+	 * writtern. Then all pending objects since last flush are writtern.
+	 * </p>
+	 */
+	public void flush() {
+		synchronized (this) {
+			// write xml header
+			if (!hasXmlHeader) {
+				out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+				out.println("<java version=\""
+						+ System.getProperty("java.version")
+						+ "\" class=\"java.beans.XMLDecoder\">");
+				hasXmlHeader = true;
+			}
+
+			// preprocess pending objects
+			for (Iterator iter = flushPending.iterator(); iter.hasNext();) {
+				Object o = iter.next();
+				Record rec = (Record) records.get(o);
+				if (rec != null) {
+					preprocess(o, rec);
+				}
+			}
+
+			// flush pending objects
+			for (Iterator iter = flushPending.iterator(); iter.hasNext();) {
+				Object o = iter.next();
+				flushObject(o, INDENT_UNIT);
+				// remove flushed obj
+				iter.remove();
+			}
+
+			// clear statement records
+			records.clear();
+			flushPendingStat.clear();
+
+			// remove all old->new mappings
+			super.clear();
+		}
+	}
+
+	private void flushBasicObject(Object obj, int indent) {
+		if( obj instanceof Proxy) {
 			return;
 		}
-		
-		if (get(oldValue) != null) {
+		flushIndent(indent);
+		if (obj == null) {
+			out.println("<null />");
+		} else if (obj instanceof String) {
+			Record rec = (Record) records.get(obj);
+			if( null != rec) {
+				if (flushPendingStat.contains(obj)) {
+					flushExpression(obj, rec, indent - 3, true);
+				} else {
+					flushExpression(obj, rec, indent - 3, false);
+				}
+				return;
+			}
+			out.print("<string>");
+			flushString((String) obj);
+			out.println("</string>");
+		} else if (obj instanceof Class) {
+			out.print("<class>");
+			out.print(((Class) obj).getName());
+			out.println("</class>");
+		} else if (obj instanceof Boolean) {
+			out.print("<boolean>");
+			out.print(obj);
+			out.println("</boolean>");
+		} else if (obj instanceof Byte) {
+			out.print("<byte>");
+			out.print(obj);
+			out.println("</byte>");
+		} else if (obj instanceof Character) {
+			out.print("<char>");
+			out.print(obj);
+			out.println("</char>");
+		} else if (obj instanceof Double) {
+			out.print("<double>");
+			out.print(obj);
+			out.println("</double>");
+		} else if (obj instanceof Float) {
+			out.print("<float>");
+			out.print(obj);
+			out.println("</float>");
+		} else if (obj instanceof Integer) {
+			out.print("<int>");
+			out.print(obj);
+			out.println("</int>");
+		} else if (obj instanceof Long) {
+			out.print("<long>");
+			out.print(obj);
+			out.println("</long>");
+		} else if (obj instanceof Short) {
+			out.print("<short>");
+			out.print(obj);
+			out.println("</short>");
+		} else {
+			getExceptionListener().exceptionThrown(
+					new Exception("Unknown basic object: " + obj));
+		}
+	}
+
+	private void flushExpression(Object obj, Record rec, int indent,
+			boolean asStatement) {
+		// not first time, use idref
+		if (rec.id != null) {
+			flushIndent(indent);
+			out.print("<object idref=\"");
+			out.print(rec.id);
+			out.println("\" />");
 			return;
 		}
-		
-		Object oldTarget = oldExp.getTarget();
 
-		ObjectNode valueNode = null;
-		Class<?> valueType = null;
+		// generate id, if necessary
+		if (rec.refCount > 1) {
+			rec.id = nameForClass(obj.getClass()) + idSerialNo;
+			idSerialNo++;
+		}
 
-		// write target
-		if (!Statement.isPDConstructor(oldExp)
-				&& !Statement.isStaticMethodCall(oldExp)) {
-			ObjectNode parent;
+		// flush
+		Statement stat = asStatement ? new Statement(rec.exp.getTarget(),
+				rec.exp.getMethodName(), rec.exp.getArguments()) : rec.exp;
+		flushStatement(stat, rec.id, rec.stats, indent);
+	}
 
-			// XXX investigate
-			// write(oldTarget);
-			parent = nodes.get(oldTarget);
-			if (parent != null) {
-				parent.addExpression(oldExp);
-			}
+	private void flushIndent(int indent) {
+		for (int i = 0; i < indent; i++) {
+			out.print(" ");
 		}
+	}
 
-		// write value
-		valueType = oldValue.getClass();
-		valueNode = nodes.get(oldValue);
+	private void flushObject(Object obj, int indent) {
+		Record rec = (Record) records.get(obj);
+		if (rec == null && !isBasicType(obj))
+			return;
 
-		if (valueNode == null) {
+		if (obj == owner && this.needOwner) {
+			flushOwner(obj, rec, indent);
+			this.needOwner = false;
+			return;
+		}
 
-			if (isNull(valueType) || isPrimitive(valueType)
-					|| isString(valueType)) {
-				valueNode = new ObjectNode(oldExp);
+		if (isBasicType(obj)) {
+			flushBasicObject(obj, indent);
+		} else {
+			if (flushPendingStat.contains(obj)) {
+				flushExpression(obj, rec, indent, true);
 			} else {
-				try {
-					write((Object[])oldExp.getArguments());
-				} catch (Exception e) {
-					getExceptionListener().exceptionThrown(e);
-				}
-				valueNode = new ObjectNode(oldExp, nodes);
+				flushExpression(obj, rec, indent, false);
 			}
-
-			nodes.put(oldValue, valueNode);
-		} else if (oldExp.getMethodName().equals("new")) { //$NON-NLS-1$
-			valueNode.addReference();
-		} else {
-			// XXX the information about referencedExpressions is not
-			// being used by anyone
-			// node.addReferencedExpression(oldExp);
 		}
-		super.writeExpression(oldExp);
 	}
 
-    @Override
-    public void writeStatement(Statement oldStm) {
-        try {
-            super.writeStatement(oldStm);
-        } catch (NullPointerException ignore) {
-            // ignore exception like RI does
-            ignore.printStackTrace();
-        }
-    }
+	private void flushOwner(Object obj, Record rec, int indent) {
+		if (rec.refCount > 1) {
+			rec.id = nameForClass(obj.getClass()) + idSerialNo;
+			idSerialNo++;
+		}
 
-    public void flush() {
-        writeAll();
-    }
-
-    public void close() {
-        try {
-            flush();
-            out.close();
-        } catch (Exception e) {
-            getExceptionListener().exceptionThrown(e);
-        }
-    }
+		flushIndent(indent);
+		String tagName = "void";
+		out.print("<");
+		out.print(tagName);
+
+		// id attribute
+		if (rec.id != null) {
+			out.print(" id=\"");
+			out.print(rec.id);
+			out.print("\"");
+		}
 
-    private void writeAll() {
-        Tag mainTag = new Tag("java"); //$NON-NLS-1$
-        Enumeration<Object> e;
+		out.print(" property=\"owner\"");
 
-        printed.clear();
-        NameMaker.clear();
+		// open tag, end
+		if (rec.exp.getArguments().length == 0 && rec.stats.isEmpty()) {
+			out.println("/>");
+			return;
+		}
+		out.println(">");
 
-        mainTag.addAttr("version", System.getProperty("java.version")); //$NON-NLS-1$ //$NON-NLS-2$
-        mainTag.addAttr("class", "java.beans.XMLDecoder"); //$NON-NLS-1$ //$NON-NLS-2$
+		// arguments
+		for (int i = 0; i < rec.exp.getArguments().length; i++) {
+			flushObject(rec.exp.getArguments()[i], indent + INDENT_UNIT);
+		}
 
-        printBytes(0, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); //$NON-NLS-1$
-        printBytes(0, mainTag.toStringOnOpen());
+		// sub statements
+		flushSubStatements(rec.stats, indent);
 
-        e = roots.elements();
-        while (e.hasMoreElements()) {
-            Object object = e.nextElement();
+		// close tag
+		flushIndent(indent);
+		out.print("</");
+		out.print(tagName);
+		out.println(">");
+	}
 
-            if (object != null) {
-                ObjectNode node = nodes.get(object);
+	private void flushStatArray(Statement stat, String id, List subStats,
+			int indent) {
+		// open tag, begin
+		flushIndent(indent);
+		out.print("<array");
+
+		// id attribute
+		if (id != null) {
+			out.print(" id=\"");
+			out.print(id);
+			out.print("\"");
+		}
 
-                printObjectTag(1, object, node);
-            } else {
-                printNullTag(1);
-            }
-        }
+		// class & length
+		out.print(" class=\"");
+		out.print(((Class) stat.getArguments()[0]).getName());
+		out.print("\" length=\"");
+		out.print(stat.getArguments()[1]);
+		out.print("\"");
+
+		// open tag, end
+		if (subStats.isEmpty()) {
+			out.println("/>");
+			return;
+		}
+		out.println(">");
 
-        printBytes(0, mainTag.toStringOnClose());
-    }
+		// sub statements
+		flushSubStatements(subStats, indent);
 
-    // FIXME processing of default constructor: investigate
-    private void printObjectTag(int tabCount, Object object, ObjectNode node) {
-        Class<?> nodeType = null;
-
-        try {
-            nodeType = node.getObjectType();
-        } catch (Exception e) {
-            Exception e2 = new Exception(Messages.getString(
-                    "beans.3B", node.getInitializer())); //$NON-NLS-1$
-
-            e2.initCause(e);
-            getExceptionListener().exceptionThrown(e2);
-            return;
-        }
+		// close tag
+		flushIndent(indent);
+		out.println("</array>");
+	}
 
-        if (isPrimitive(nodeType) || isString(nodeType) || isClass(nodeType)) {
-            String tagName = getPrimitiveName(nodeType);
-            Object arg = node.getObjectArguments()[0];
-            Tag tag = new Tag(tagName, arg.toString());
-
-            printBytes(tabCount, tag.toString());
-        } else { // if array or complex object
-            Tag tag = null;
-            Object[] arguments = node.getObjectArguments();
-            boolean objectPrinted = false;
-            boolean isReferenced = node.getReferencesNumber() > 0;
-
-            if (isArray(nodeType)) {
-                tag = new Tag("array"); //$NON-NLS-1$
-            } else {
-                tag = new Tag("object"); //$NON-NLS-1$
-            }
+	private void flushStatCommon(Statement stat, String id, List subStats,
+			int indent) {
+		// open tag, begin
+		flushIndent(indent);
+		String tagName = stat instanceof Expression ? "object" : "void";
+		out.print("<");
+		out.print(tagName);
+
+		// id attribute
+		if (id != null) {
+			out.print(" id=\"");
+			out.print(id);
+			out.print("\"");
+		}
 
-            // check if the object presents references
-            if (isReferenced) {
-                if (printed.contains(node)) {
-                    String nodeId = node.getId();
-
-                    if (nodeId != null) {
-                        tag.addAttr("idref", node.getId()); //$NON-NLS-1$
-                    }
-
-                    objectPrinted = true;
-                } else { // if(printed.contains(node) == false
-                    try {
-                        Class<?> type = node.getObjectType();
-
-                        if (type != null) {
-                            // check if it is necessary to assign
-                            // and display *id* attribute to the object
-                            String objectName = NameMaker.getInstanceName(type);
-
-                            node.setId(objectName);
-                            tag.addAttr("id", objectName); //$NON-NLS-1$
-                        }
-                    } catch (Exception e) {
-                        getExceptionListener().exceptionThrown(e);
-                    }
-                }
-            }
+		// special class attribute
+		if (stat.getTarget() instanceof Class) {
+			out.print(" class=\"");
+			out.print(((Class) stat.getTarget()).getName());
+			out.print("\"");
+		}
 
-            if (!objectPrinted) {
-                try {
-                    if (isArray(nodeType)) {
-                        tag.addAttr("class", ((Class) arguments[0]).getName()); //$NON-NLS-1$
-                        tag.addAttr("length", ((Integer) arguments[1]) //$NON-NLS-1$
-                                .toString());
-                    } else {
-                        tag.addAttr("class", ((Class)node.getInitializer().getTarget()).getName()); //$NON-NLS-1$
-                        tag.addAttr("method", node.getInitializer().getMethodName());
-                    }
-                } catch (Exception e) {
-                    getExceptionListener().exceptionThrown(e);
-                }
-            }
+		// method attribute
+		if (!"new".equals(stat.getMethodName())) {
+			out.print(" method=\"");
+			out.print(stat.getMethodName());
+			out.print("\"");
+		}
 
-            // preprocessing is done, print it!
-            if (objectPrinted) {
-                // if object has already been printed then only print the
-                // reference
-                printBytes(tabCount, tag.toStringShortForm());
-            } else if (isArray(nodeType) && !node.statements().hasNext()) {
-                // if we have an empty array
-                printBytes(tabCount, tag.toStringShortForm());
-            } else if (arguments.length == 0 && !node.statements().hasNext()
-                    && !node.expressions().hasNext()) {
-                // if given tag has no children print the short form of the tag
-                printBytes(tabCount, tag.toStringShortForm());
-            } else {
-                // the tag has not been printed and contains children,
-                // let's print them
-
-                printBytes(tabCount, tag.toStringOnOpen());
-
-                printed.add(node);
-
-                if (isArray(nodeType)) { // if array
-                    Iterator<Statement> it = node.statements();
-
-                    while (it.hasNext()) {
-                        Statement s = it.next();
-
-                        printVoidTag(++tabCount, s);
-                        --tabCount;
-                    }
-                } else { // if object
-                    Iterator<Expression> i1;
-                    Iterator<Statement> i2;
-
-                    for (Object element : arguments) {
-                        if (element != null) {
-                            ObjectNode succNode = nodes.get(element);
-
-                            printObjectTag(++tabCount, element, succNode);
-                        } else {
-                            printNullTag(++tabCount);
-                        }
-
-                        --tabCount;
-                    }
-
-                    i1 = node.expressions();
-                    while (i1.hasNext()) {
-                        Expression e = i1.next();
-
-                        printVoidTag(++tabCount, e);
-                        --tabCount;
-                    }
-
-                    i2 = node.statements();
-                    while (i2.hasNext()) {
-                        Statement s = i2.next();
-
-                        printVoidTag(++tabCount, s);
-                        --tabCount;
-                    }
-                } // if object
+		// open tag, end
+		if (stat.getArguments().length == 0 && subStats.isEmpty()) {
+			out.println("/>");
+			return;
+		}
+		out.println(">");
 
-                printBytes(tabCount, tag.toStringOnClose());
-            }
-        } // if node is of non-trivial type
-    }
+		// arguments
+		for (int i = 0; i < stat.getArguments().length; i++) {
+			flushObject(stat.getArguments()[i], indent + INDENT_UNIT);
+		}
 
-    private void printVoidTag(int tabCount, Expression expr) {
-        Object exprValue = null;
+		// sub statements
+		flushSubStatements(subStats, indent);
 
-        try {
-            Enumeration<ObjectNode> enumeration;
-            Tag tag;
-            String objectName;
-            String methodName;
-            ObjectNode node;
-            Object[] args;
-
-            exprValue = expr.getValue();
-
-            // find out, if this object is already printed
-            enumeration = printed.elements();
-            while (enumeration.hasMoreElements()) {
-                ObjectNode node2 = enumeration.nextElement();
-
-                if (node2.getObjectValue() == exprValue) {
-                    return;
-                }
-            }
+		// close tag
+		flushIndent(indent);
+		out.print("</");
+		out.print(tagName);
+		out.println(">");
+	}
 
-            node = nodes.get(exprValue);
+	private void flushStatement(Statement stat, String id, List subStats,
+			int indent) {
+		Object target = stat.getTarget();
+		String method = stat.getMethodName();
+		Object args[] = stat.getArguments();
+
+		// special case for array
+		if (Array.class == target && "newInstance".equals(method)) {
+			flushStatArray(stat, id, subStats, indent);
+			return;
+		}
+		// special case for get(int) and set(int, Object)
+		if (isGetArrayStat(target, method, args)
+				|| isSetArrayStat(target, method, args)) {
+			flushStatIndexed(stat, id, subStats, indent);
+			return;
+		}
+		// special case for getProperty() and setProperty(Object)
+		if (isGetPropertyStat(method, args) || isSetPropertyStat(method, args)) {
+			flushStatGetterSetter(stat, id, subStats, indent);
+			return;
+		}
 
-            // find out, if this object has no references to be printed
-            // System.out.println("---- node.getReferencesNumber() = " +
-            // node.getReferencesNumber());
-            // System.out.println("---- node.getReferencedExpressionsNumber() =
-            // " + node.getReferencedExpressionsNumber());
+		if (isStaticConstantsSupported
+				&& "getField".equals(stat.getMethodName())) {
+			flushStatField(stat, id, subStats, indent);
+			return;
+		}
 
-            if (node.getReferencesNumber() == 0) {
-                return;
-            }
+		// common case
+		flushStatCommon(stat, id, subStats, indent);
+	}
 
-            tag = new Tag("void"); //$NON-NLS-1$
-            objectName = NameMaker.getInstanceName(exprValue.getClass());
+	private void flushStatField(Statement stat, String id, List subStats,
+			int indent) {
+		// open tag, begin
+		flushIndent(indent);
+		String tagName = "object";
+		out.print("<");
+		out.print(tagName);
+
+		// id attribute
+		if (id != null) {
+			out.print(" id=\"");
+			out.print(id);
+			out.print("\"");
+		}
 
-            node.setId(objectName);
-            tag.addAttr("id", objectName); //$NON-NLS-1$
+		// special class attribute
+		if (stat.getTarget() instanceof Class) {
+			out.print(" class=\"");
+			out.print(((Class) stat.getTarget()).getName());
+			out.print("\"");
+		}
 
-            methodName = expr.getMethodName();
-            args = expr.getArguments();
+		Object target = stat.getTarget();
+		if(target == SystemColor.class || target == TextAttribute.class) {
+			out.print(" field=\"");
+			out.print(stat.getArguments()[0]);
+			out.print("\"");
+			out.println("/>");
 
-            if (methodName.startsWith("get") //$NON-NLS-1$
-                    && (args.length == 0 || args.length == 1
-                            && args[0].getClass() == Integer.class)
-                    || methodName.startsWith("set") //$NON-NLS-1$
-                    && (args.length == 1 || args.length == 2
-                            && args[0].getClass() == Integer.class)) {
-                String propertyName = methodName.substring(3);
-
-                if (propertyName.length() > 0) {
-                    tag.addAttr("property", Introspector //$NON-NLS-1$
-                            .decapitalize(propertyName));
-                }
-
-                if (methodName.startsWith("get") && args.length == 1 //$NON-NLS-1$
-                        || methodName.startsWith("set") && args.length == 2) { //$NON-NLS-1$
-                    tag.addAttr("index", args[0].toString()); //$NON-NLS-1$
-                }
-            } else {
-                tag.addAttr("method", expr.getMethodName()); //$NON-NLS-1$
-            }
+		}
+		else {
+			out.print(" method=\"");
+			out.print(stat.getMethodName());
+			out.print("\"");
+			out.println(">");
+			Object fieldName = (String) stat.getArguments()[0];
+			flushObject(fieldName, indent + INDENT_UNIT);
+			flushIndent(indent);
+			out.println("</object>");
+		}
+	}
 
-            printBytes(tabCount, tag.toStringOnOpen());
+	private void flushStatGetterSetter(Statement stat, String id,
+			List subStats, int indent) {
+		// open tag, begin
+		flushIndent(indent);
+		String tagName = stat instanceof Expression ? "object" : "void";
+		out.print("<");
+		out.print(tagName);
+
+		// id attribute
+		if (id != null) {
+			out.print(" id=\"");
+			out.print(id);
+			out.print("\"");
+		}
 
-            for (int i = tag.hasAttr("index") ? 1 : 0; i < args.length; ++i) { //$NON-NLS-1$
-                if (args[i] != null) {
-                    ObjectNode node2 = nodes.get(args[i]);
-
-                    printObjectTag(++tabCount, args[i], node2);
-                } else {
-                    printNullTag(++tabCount);
-                }
+		// special class attribute
+		if (stat.getTarget() instanceof Class) {
+			out.print(" class=\"");
+			out.print(((Class) stat.getTarget()).getName());
+			out.print("\"");
+		}
 
-                --tabCount;
-            }
+		// property attribute
+		out.print(" property=\"");
+		out.print(decapitalize(stat.getMethodName().substring(3)));
+		out.print("\"");
+
+		// open tag, end
+		if (stat.getArguments().length == 0 && subStats.isEmpty()) {
+			out.println("/>");
+			return;
+		}
+		out.println(">");
 
-            printBytes(tabCount, tag.toStringOnClose());
+		// arguments
+		for (int i = 0; i < stat.getArguments().length; i++) {
+			flushObject(stat.getArguments()[i], indent + INDENT_UNIT);
+		}
 
-            printed.add(node);
-        } catch (Exception e) {
-            // TODO - signal problem with expr.getValue()
-        }
+		// sub statements
+		flushSubStatements(subStats, indent);
 
-    }
+		// close tag
+		flushIndent(indent);
+		out.print("</");
+		out.print(tagName);
+		out.println(">");
+	}
 
-    private void printVoidTag(int tabCount, Statement stat) {
-        Tag tag = new Tag("void"); //$NON-NLS-1$
+	private void flushStatIndexed(Statement stat, String id, List subStats,
+			int indent) {
+		// open tag, begin
+		flushIndent(indent);
+		String tagName = stat instanceof Expression ? "object" : "void";
+		out.print("<");
+		out.print(tagName);
+
+		// id attribute
+		if (id != null) {
+			out.print(" id=\"");
+			out.print(id);
+			out.print("\"");
+		}
 
-        String methodName = stat.getMethodName();
-        Object[] args = stat.getArguments();
+		// special class attribute
+		if (stat.getTarget() instanceof Class) {
+			out.print(" class=\"");
+			out.print(((Class) stat.getTarget()).getName());
+			out.print("\"");
+		}
 
-        if (methodName.startsWith("get") //$NON-NLS-1$
-                && (args.length == 0 || args.length == 1
-                        && args[0].getClass() == Integer.class)
-                || methodName.startsWith("set") //$NON-NLS-1$
-                && (args.length == 1 || args.length == 2
-                        && args[0].getClass() == Integer.class)) {
-            String propertyName = methodName.substring(3);
-
-            if (propertyName.length() > 0) {
-                tag.addAttr("property", Introspector //$NON-NLS-1$
-                        .decapitalize(propertyName));
-            }
+		// index attribute
+		out.print(" index=\"");
+		out.print(stat.getArguments()[0]);
+		out.print("\"");
+
+		// open tag, end
+		if (stat.getArguments().length == 1 && subStats.isEmpty()) {
+			out.println("/>");
+			return;
+		}
+		out.println(">");
 
-            if (methodName.startsWith("get") && args.length == 1 //$NON-NLS-1$
-                    || methodName.startsWith("set") && args.length == 2) { //$NON-NLS-1$
-                tag.addAttr("index", args[0].toString()); //$NON-NLS-1$
-            }
-        } else {
-            tag.addAttr("method", stat.getMethodName()); //$NON-NLS-1$
-        }
+		// arguments
+		for (int i = 1; i < stat.getArguments().length; i++) {
+			flushObject(stat.getArguments()[i], indent + INDENT_UNIT);
+		}
 
-        printBytes(tabCount, tag.toStringOnOpen());
+		// sub statements
+		flushSubStatements(subStats, indent);
 
-        for (int i = tag.hasAttr("index") ? 1 : 0; i < args.length; ++i) { //$NON-NLS-1$
-            if (args[i] != null) {
-                ObjectNode node = nodes.get(args[i]);
-
-                printObjectTag(++tabCount, args[i], node);
-            } else {
-                printNullTag(++tabCount);
-            }
+		// close tag
+		flushIndent(indent);
+		out.print("</");
+		out.print(tagName);
+		out.println(">");
+	}
 
-            --tabCount;
-        }
+	private void flushString(String s) {
+		char c;
+		for (int i = 0; i < s.length(); i++) {
+			c = s.charAt(i);
+			if (c == '<') {
+				out.print("&lt;");
+			} else if (c == '>') {
+				out.print("&gt;");
+			} else if (c == '&') {
+				out.print("&amp;");
+			} else if (c == '\'') {
+				out.print("&apos;");
+			} else if (c == '"') {
+				out.print("&quot;");
+			} else {
+				out.print(c);
+			}
+		}
+	}
 
-        printBytes(tabCount, tag.toStringOnClose());
-    }
+	private void flushSubStatements(List subStats, int indent) {
+		for (int i = 0; i < subStats.size(); i++) {
+			Statement subStat = (Statement) subStats.get(i);
+			try {
+				if (subStat instanceof Expression) {
+					Expression subExp = (Expression) subStat;
+					Object obj = subExp.getValue();
+					Record rec = (Record) records.get(obj);
+					flushExpression(obj, rec, indent + INDENT_UNIT, true);
+				} else {
+					flushStatement(subStat, null, Collections.EMPTY_LIST,
+							indent + INDENT_UNIT);
+				}
+			} catch (Exception e) {
+				// should not happen
+				getExceptionListener().exceptionThrown(e);
+			}
+		}
+	}
 
-    private void printNullTag(int tabCount) {
-        printBytes(tabCount, "<null/>"); //$NON-NLS-1$
-    }
-
-    private void printBytes(int tabCount, String s) {
-        try {
-            String result = ""; //$NON-NLS-1$
+	/**
+	 * Returns the owner of this encoder.
+	 * 
+	 * @return the owner of this encoder
+	 */
+	public Object getOwner() {
+		return owner;
+	}
 
-            for (int i = 0; i < tabCount; ++i) {
-                result += ' ';
-            }
-            result = result + s + "\n"; //$NON-NLS-1$
-            out.write(result.getBytes("UTF-8")); //$NON-NLS-1$
-        } catch (IOException ioe) {
-            ExceptionListener listener = getExceptionListener();
+	private boolean isBasicType(Object value) {
+		return value == null || value instanceof Boolean
+				|| value instanceof Byte || value instanceof Character
+				|| value instanceof Class || value instanceof Double
+				|| value instanceof Float || value instanceof Integer
+				|| value instanceof Long || value instanceof Short
+				|| value instanceof String || value instanceof Proxy;
+	}
 
-            if (listener != null) {
-                listener.exceptionThrown(ioe);
-            }
-        }
-    }
+	private boolean isGetArrayStat(Object target, String method, Object[] args) {
+		return ("get".equals(method) && args.length == 1
+				&& args[0] instanceof Integer && target.getClass().isArray());
+	}
 
-    /**
-     * Escapes '&', '<', '>', '\'', '"' chars.
-     * 
-     * @param input
-     *            input string to be escaped
-     * @return string with escaped characters
-     */
-    static String escapeChars(String input) {
-        StringBuffer sb = new StringBuffer();
-
-        for (int i = 0; i < input.length(); i++) {
-            char c = input.charAt(i);
-
-            switch (c) {
-                case '&':
-                    sb.append("&amp;"); //$NON-NLS-1$
-                    break;
-                case '<':
-                    sb.append("&lt;"); //$NON-NLS-1$
-                    break;
-                case '>':
-                    sb.append("&gt;"); //$NON-NLS-1$
-                    break;
-                case '\'':
-                    sb.append("&apos;"); //$NON-NLS-1$
-                    break;
-                case '"':
-                    sb.append("&quot;"); //$NON-NLS-1$
-                    break;
-                default:
-                    sb.append(c);
-                    break;
-            }
-        }
-        return sb.toString();
-    }
+	private boolean isGetPropertyStat(String method, Object[] args) {
+		return (method.startsWith("get") && method.length() > 3 && args.length == 0);
+	}
 
-    /**
-     * This class is used by XMLEncoder to store XML tag information.
-     */
-    static class Tag {
+	private boolean isSetArrayStat(Object target, String method, Object[] args) {
+		return ("set".equals(method) && args.length == 2
+				&& args[0] instanceof Integer && target.getClass().isArray());
+	}
 
-        String name;
+	private boolean isSetPropertyStat(String method, Object[] args) {
+		return (method.startsWith("set") && method.length() > 3 && args.length == 1);
+	}
 
-        LinkedHashMap<String, String> attrs;
+	private String nameForClass(Class c) {
+		if (c.isArray()) {
+			return nameForClass(c.getComponentType()) + "Array";
+		} else {
+			String name = c.getName();
+			int i = name.lastIndexOf('.');
+			if (-1 == i) {
+				return name;
+			} else {
+				return name.substring(i + 1);
+			}
+		}
+	}
 
-        String characters;
+	/*
+	 * The preprocess removes unused statements and counts references of every
+	 * object
+	 */
+	private void preprocess(Object obj, Record rec) {
+		if (isBasicType(obj) && writingObject) {
+			return;
+		}
 
-        public Tag(String name) {
-            this.name = name;
-            this.attrs = new LinkedHashMap<String, String>();
-            this.characters = null;
-        }
+		// count reference
+		rec.refCount++;
 
-        public Tag(String name, String characters) {
-            this.name = name;
-            this.attrs = new LinkedHashMap<String, String>();
-            this.characters = characters;
-        }
+		// do things only one time for each record
+		if (rec.refCount > 1) {
+			return;
+		}
 
-        public boolean hasAttr(String attrName) {
-            return attrs.get(attrName) != null;
-        }
+		// deal with 'field' property
+		try {
+			if (isStaticConstantsSupported
+					&& "getField".equals(((Record) records.get(rec.exp
+							.getTarget())).exp.getMethodName())) {
+				records.remove(obj);
+			}
+		} catch (NullPointerException e) {
+			// do nothing, safely
+		}
 
-        public void addAttr(String attrName, String attrValue) {
-            attrs.put(attrName, attrValue);
-        }
+		// do it recursively
+		if (null != rec.exp) {
+			Object args[] = rec.exp.getArguments();
+			for (int i = 0; i < args.length; i++) {
+				Record argRec = (Record) records.get(args[i]);
+				if (argRec != null) {
+					preprocess(args[i], argRec);
+				}
+			}
+		}
 
-        public String toStringOnOpenUnfinished() {
-            String result = "<" + name; //$NON-NLS-1$
-            Iterator<String> i = attrs.keySet().iterator();
-
-            while (i.hasNext()) {
-                String attrName = i.next();
-                String attrValue = attrs.get(attrName);
+		for (Iterator iter = rec.stats.iterator(); iter.hasNext();) {
+			Statement subStat = (Statement) iter.next();
+			if (subStat instanceof Expression) {
+				try {
+					Expression subExp = (Expression) subStat;
+					Record subRec = (Record) records.get(subExp.getValue());
+					if (subRec == null || subRec.exp == null
+							|| subRec.exp != subExp) {
+						iter.remove();
+						continue;
+					}
+					preprocess(subExp.getValue(), subRec);
+					if (subRec.stats.isEmpty()) {
+						if (isGetArrayStat(subExp.getTarget(), subExp
+								.getMethodName(), subExp.getArguments())
+								|| isGetPropertyStat(subExp.getMethodName(),
+										subExp.getArguments())) {
+							iter.remove();
+							continue;
+						}
+					}
+				} catch (Exception e) {
+					getExceptionListener().exceptionThrown(e);
+					iter.remove();
+				}
+				continue;
+			}
 
-                result += " " + attrName + "=\"" + attrValue + "\""; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-            }
-            return result;
-        }
+			Object subStatArgs[] = subStat.getArguments();
+			for (int i = 0; i < subStatArgs.length; i++) {
+				Record argRec = (Record) records.get(subStatArgs[i]);
+				if (argRec != null) {
+					preprocess(subStatArgs[i], argRec);
+				}
+			}
+		}
+	}
 
-        public String toStringOnOpen() {
-            return toStringOnOpenUnfinished() + ">"; //$NON-NLS-1$
-        }
+	private void recordExpression(Object value, Expression exp) {
+		// record how a new object is created or obtained
+		Record rec = (Record) records.get(value);
+		if (rec == null) {
+			rec = new Record();
+			records.put(value, rec);
+		}
 
-        public String toStringShortForm() {
-            return toStringOnOpenUnfinished() + "/>"; //$NON-NLS-1$
-        }
+		if (rec.exp == null) {
+			// it is generated by its sub stats
+			for (Iterator iter = rec.stats.iterator(); iter.hasNext();) {
+				Statement stat = (Statement) iter.next();
+				try {
+					if (stat instanceof Expression) {
+						Expression expr = (Expression) stat;
+						Object subObj = expr.getValue();
+						// if(expr.getTarget().getClass() ==
+						// Class.class.getClass())
+						flushPrePending.add(value);
+					}
+				} catch (Exception e) {
+					e.printStackTrace();
+				}
 
-        public String toStringOnClose() {
-            return "</" + name + ">"; //$NON-NLS-1$ //$NON-NLS-2$
-        }
+			}
+		}
 
-        public String toStringOnCharacters() {
-            return XMLEncoder.escapeChars(characters);
-        }
+		rec.exp = exp;
 
-        @Override
-        public String toString() {
-            return toStringOnOpen() + toStringOnCharacters()
-                    + toStringOnClose();
-        }
-    }
+		// deal with 'owner' property
+		if (value == owner && owner != null) {
+			needOwner = true;
+		}
 
-    static class NameMaker {
+		// also record as a statement
+		recordStatement(exp);
+	}
 
-        private static final HashMap<String, Integer> numOfExemplars = new HashMap<String, Integer>();
+	private void recordStatement(Statement stat) {
+		// deal with 'owner' property
+		if (stat.getTarget() == owner && owner != null) {
+			needOwner = true;
+		}
 
-        public static void clear() {
-            numOfExemplars.clear();
-        }
+		// record how a statement affects the target object
+		Record rec = (Record) records.get(stat.getTarget());
+		if (rec == null) {
+			rec = new Record();
+			records.put(stat.getTarget(), rec);
+		}
+		rec.stats.add(stat);
+	}
 
-        private static String getCompName(Class<?> clz) {
-            if (clz.isArray()) {
-                return getCompName(clz.getComponentType()) + "Array"; //$NON-NLS-1$
-            }
-            return clz.getName().substring(clz.getName().lastIndexOf(".") + 1); //$NON-NLS-1$
-        }
+	/**
+	 * Sets the owner of this encoder.
+	 * 
+	 * @param owner
+	 *            the owner to set
+	 */
+	public void setOwner(Object owner) {
+		this.owner = owner;
+	}
+
+	/**
+	 * Records the expression so that it can be writtern out later, then calls
+	 * super implementation.
+	 */
+	public void writeExpression(Expression oldExp) {
+	    boolean oldWritingObject = writingObject;
+	    writingObject = true;
+		// get expression value
+		Object oldValue = null;
+		try {
+			oldValue = oldExp.getValue();
+		} catch (Exception e) {
+			getExceptionListener()
+					.exceptionThrown(
+							new Exception("failed to execute expression: "
+									+ oldExp, e));
+			return;
+		}
+
+		// check existence
+		if (get(oldValue) != null && (!(oldValue instanceof String) || oldWritingObject)) {
+			return;
+		}
 
-        public static String getInstanceName(Class<?> type) {
-            String result = null;
+		// record how the object is obtained
+		if (!isBasicType(oldValue) || (oldValue instanceof String && !oldWritingObject)) {
+			recordExpression(oldValue, oldExp);
+		}
 
-            String fullName;
-            String shortName;
-            Integer iNum;
-
-            if (type.isArray()) {
-                fullName = getCompName(type);
-                shortName = fullName;
-            } else {
-                fullName = type.getName();
-                shortName = fullName.substring(fullName.lastIndexOf(".") + 1); //$NON-NLS-1$
-            }
-            iNum = numOfExemplars.get(shortName);
-            if (iNum == null) {
-                numOfExemplars.put(shortName, new Integer(0));
-                result = shortName + "0"; //$NON-NLS-1$
-            } else {
-                int newValue = iNum.intValue() + 1;
+		super.writeExpression(oldExp);
+		writingObject = oldWritingObject;
+	}
+
+	/**
+	 * Records the object so that it can be writtern out later, then calls super
+	 * implementation.
+	 */
+	public void writeObject(Object o) {
+		synchronized (this) {
+			boolean oldWritingObject = writingObject;
+			writingObject = true;
+			try {
+				super.writeObject(o);
+			} finally {
+				writingObject = oldWritingObject;
+			}
+
+			// root object?
+			if (!writingObject) {
+				// add to pending
+				flushPending.addAll(flushPrePending);
+				flushPendingStat.addAll(flushPrePending);
+				flushPrePending.clear();
+				if (flushPending.contains(o)) {
+					flushPrePending.remove(o);
+					flushPendingStat.remove(o);
+				} else {
+					flushPending.add(o);
+				}
+				if (needOwner) {
+					this.flushPending.remove(owner);
+					this.flushPending.add(0, owner);
+				}
+			}
+		}
+	}
+
+	/**
+	 * Records the statement so that it can be writtern out later, then calls
+	 * super implementation.
+	 */
+	public void writeStatement(Statement oldStat) {
+		// record how the object is changed
+		recordStatement(oldStat);
+
+		super.writeStatement(oldStat);
+	}
 
-                result = shortName + Integer.toString(newValue);
-                numOfExemplars.put(shortName, new Integer(newValue));
-            }
-            return result;
-        }
-    }
 }
+
+

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java Tue Jul 17 21:05:08 2007
@@ -926,7 +926,7 @@
      * @throws IllegalArgumentException if the child is null
      * @throws IllegalStateException if the child is not valid to remove
      */
-    public boolean remove(Object child, boolean setChildBC) {
+    protected boolean remove(Object child, boolean setChildBC) {
         if (child == null) {
             throw new IllegalArgumentException("null child");
         }

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties Tue Jul 17 21:05:08 2007
@@ -102,3 +102,14 @@
 beans.54=listenerType is null
 beans.55=Method is null
 beans.56=Provider does not match
+beans.57=Property type is incompatible with the indexed property type
+beans.58=No such indexed read method
+beans.59=Security violation accessing indexed read method
+beans.5A=Indexed read method is not compatible with indexed write method
+beans.5B=Indexed read method must take a single int argument
+beans.5C=Security violation accessing indexed write method
+beans.5D=No such indexed write method
+beans.5E=Indexed method is not compatible with non indexed method
+beans.5F=Indexed write method must take a two arguments
+beans.60=Indexed write method must take an int as its first argument
+beans.61=Indexed write method is not compatible with indexed read method

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/BeansTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/BeansTest.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/BeansTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/BeansTest.java Tue Jul 17 21:05:08 2007
@@ -17,6 +17,7 @@
 
 package org.apache.harmony.beans.tests.java.beans;
 
+import java.applet.Applet;
 import java.awt.Component;
 import java.beans.AppletInitializer;
 import java.beans.Beans;
@@ -444,6 +445,13 @@
             // expected
         }
     }
+    
+    //Regression for HARMONY-3777
+    public void test_instantiate_with_applet() throws Exception{
+		Applet applet = (Applet) Beans.instantiate(null, "java.applet.Applet");
+		assertNotNull(applet.getAppletContext());
+		assertTrue(applet.isActive());
+	}
 
     /**
      * 

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IndexedPropertyDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IndexedPropertyDescriptorTest.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IndexedPropertyDescriptorTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IndexedPropertyDescriptorTest.java Tue Jul 17 21:05:08 2007
@@ -19,6 +19,7 @@
 
 import java.beans.IndexedPropertyDescriptor;
 import java.beans.IntrospectionException;
+import java.beans.PropertyDescriptor;
 import java.lang.reflect.Method;
 
 import junit.framework.TestCase;
@@ -413,6 +414,22 @@
         assertEquals(String.class, ipd.getIndexedPropertyType());
     }
 
+    private class MyClass {
+        private int[] a;
+
+        public void setA(int v, int i) {
+            a[i] = v;
+        }
+
+        public void setA(int[] a) {
+            this.a = a;
+        }
+
+        public int[] getA() {
+            return a;
+        }
+    }
+    
     /*
      * Class under test for void IndexedPropertyDescriptor(String, Class,
      * String, String, String, String)
@@ -457,7 +474,59 @@
         assertFalse(ipd.isExpert());
         assertFalse(ipd.isHidden());
         assertFalse(ipd.isPreferred());
-
+        
+        //empty method name
+        new IndexedPropertyDescriptor(
+                propertyName, beanClass, "get" + propertyName, "set"
+                        + propertyName, "", "set"
+                        + propertyName);
+        
+        try {
+            new IndexedPropertyDescriptor("a", MyClass.class, "getA", "setA",
+                    "", "setA");
+            fail("Shoule throw exception");
+        } catch (IntrospectionException e) {
+        	// expected
+        }
+        
+        try {
+            new IndexedPropertyDescriptor(propertyName, beanClass, "",
+                    "set" + propertyName, "get" + propertyName, "set"
+                            + propertyName);
+            fail("Shoule throw exception");
+        } catch (IntrospectionException e) {
+        	// expected
+        }
+        try {
+            new IndexedPropertyDescriptor(propertyName, beanClass, "get"
+                    + propertyName, "", "get" + propertyName, "set"
+                    + propertyName);
+            fail("Shoule throw exception");
+        } catch (IntrospectionException e) {
+        	// expected
+        }
+        try {
+            new IndexedPropertyDescriptor(propertyName, beanClass, "get"
+                    + propertyName, "set" + propertyName, "get" + propertyName,
+                    "");
+            fail("Shoule throw exception");
+        } catch (IntrospectionException e) {
+        	// expected
+        }
+        
+        //null method name
+        new IndexedPropertyDescriptor(
+                propertyName, beanClass, "get" + propertyName, "set"
+                        + propertyName, null, "set" + propertyName);
+        new IndexedPropertyDescriptor(
+                propertyName, beanClass, null, "set" + propertyName, "get"
+                        + propertyName, "set" + propertyName);
+        new IndexedPropertyDescriptor(
+                propertyName, beanClass, "get" + propertyName, null, "get"
+                        + propertyName, "set" + propertyName);
+        new IndexedPropertyDescriptor(
+                propertyName, beanClass, "get" + propertyName, "set"
+                        + propertyName, "get" + propertyName, null);
     }
 
     public void testIndexedPropertyDescriptorStringClassStringStringStringString_propNull()
@@ -534,6 +603,16 @@
         assertNotNull(ipd.getReadMethod());
         assertNull(ipd.getWriteMethod());
         assertEquals(String.class, ipd.getIndexedPropertyType());
+        
+        new IndexedPropertyDescriptor(
+                propertyName, beanClass, "get" + propertyName, "set"+propertyName, "", "set" + propertyName);
+        
+        try{
+            new IndexedPropertyDescriptor(
+                propertyName, beanClass, "get" + propertyName, "set"+propertyName, "get" + propertyName, "");
+        fail();
+        }catch(Exception e){
+        }
     }
 
     public void testIndexedPropertyDescriptorStringClassStringStringStringString_IndexedReadMethodNull()
@@ -987,7 +1066,17 @@
         assertEquals(propertyName, ipd.getName());
         assertEquals(String[].class, ipd.getPropertyType());
         assertEquals(String.class, ipd.getIndexedPropertyType());
-
+        
+        indexedReadMethod = beanClass.getMethod("get" + anotherProp,
+                new Class[] { Integer.TYPE, Integer.TYPE });
+        try {
+            new IndexedPropertyDescriptor(
+                    propertyName, readMethod, writeMethod, indexedReadMethod,
+                    indexedWriteMethod);
+            fail("should throw IntrosecptionException");
+        } catch (IntrospectionException e) {
+        	// expected
+        }
     }
 
     public void testSetIndexedReadMethod() throws SecurityException,
@@ -1290,6 +1379,69 @@
             fail("Should throw IntrospectionException");
         } catch (IntrospectionException e) {
         }
+        
+        ipd = new IndexedPropertyDescriptor("data", NormalBean.class);
+        ipd.setIndexedReadMethod(null);
+        try {
+            ipd.setIndexedWriteMethod(NormalBean.class.getMethod("setData", Integer.TYPE, Integer.TYPE));
+            fail("should throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            // expected
+        }
+    }
+    
+    public void testSetIndexedMethodNullNull() throws Exception {
+        try {
+            IndexedPropertyDescriptor i = new IndexedPropertyDescriptor("a",
+                    NormalBean.class, "getData", "setData", null,
+                    "setData");
+            i.setIndexedWriteMethod(null);
+            fail("should throw IntrospectionException.");
+        } catch (IntrospectionException e) {
+            // expected
+        }
+        try {
+            IndexedPropertyDescriptor i = new IndexedPropertyDescriptor("a",
+                    NormalBean.class, "getData", "setData",
+                    "getData", null);
+            i.setIndexedReadMethod(null);
+            fail("should throw IntrospectionException.");
+        } catch (IntrospectionException e) {
+            // expected
+        }
+    }
+
+    
+    public void testSetIndexedReadMethodFollowANullValue() throws Exception {
+        try {
+            IndexedPropertyDescriptor i = new IndexedPropertyDescriptor("a",
+                    DummyBean.class, "readMethod", "writeMethod", null,
+                    "indexedReadMethod");
+            Method irm = DummyBean.class.getDeclaredMethod("indexedReadMethod",
+                    Integer.TYPE);
+            i.setIndexedReadMethod(irm);
+            fail("should throw IntrospectionException.");
+        } catch (IntrospectionException e) {
+            // expected
+        }
+    }
+
+    static class DummyBean {
+
+        public int[] readMehtod() {
+            return null;
+        }
+
+        public void writeMethod(int[] a) {
+        }
+
+        public double indexedReadMethod(int i) {
+            return 0;
+        }
+
+        public void indexedWriteMethod(int i, int j) {
+        }
+
     }
 
     class NotJavaBean {
@@ -1319,5 +1471,114 @@
             this.propertyOne[i] = value;
         }
 
+    }
+    
+    //Regression Test
+    class InCompatibleGetterSetterBean
+    {
+        private Object[] data = new Object[10];
+        public void setData(Object[] data) {
+            this.data = data;
+        }
+        public Object[] getDate() {
+            return data;
+        }
+        public void setData(int index, Object o) {
+            this.data[index] = o;
+        }
+    }
+    
+    public void testInCompatibleGetterSetterBean() {
+        try {
+            new IndexedPropertyDescriptor("data",
+                    InCompatibleGetterSetterBean.class);
+            fail("should throw IntrospectionException");
+        } catch (IntrospectionException e) {
+            // expected
+        }
+    }
+    
+    class NormalBean {
+        private Object[] data = new Object[10];
+
+        public Object[] getData() {
+            return data;
+        }
+
+        public void setData(Object[] data) {
+            this.data = data;
+        }
+
+        public void setData(int index, Object o) {
+            data[index] = o;
+        }
+        
+        public void setData(int index, int value) {
+            // do nothing
+        }
+
+        public Object getData(int index) {
+            return data[index];
+        }
+    }
+    
+    public void testEquals_superClass() throws Exception {
+        PropertyDescriptor propertyDescriptor = new PropertyDescriptor("data",
+                NormalBean.class);
+        IndexedPropertyDescriptor indexedPropertyDescriptor = new IndexedPropertyDescriptor(
+                "data", NormalBean.class);
+        assertFalse(indexedPropertyDescriptor.equals(propertyDescriptor));
+        assertTrue(propertyDescriptor.equals(indexedPropertyDescriptor));
+    }
+    
+    public void testHashCode() throws Exception {
+        String propertyName = "PropertyFour";
+        Class<MockJavaBean> beanClass = MockJavaBean.class;
+
+        Method readMethod = beanClass.getMethod("get" + propertyName,
+                (Class[]) null);
+        Method writeMethod = beanClass.getMethod("set" + propertyName,
+                new Class[] { String[].class });
+        Method indexedReadMethod = beanClass.getMethod("get" + propertyName,
+                new Class[] { Integer.TYPE });
+        Method indexedWriteMethod = beanClass.getMethod("set" + propertyName,
+                new Class[] { Integer.TYPE, String.class });
+
+        IndexedPropertyDescriptor ipd = new IndexedPropertyDescriptor(
+                propertyName, readMethod, writeMethod, indexedReadMethod,
+                indexedWriteMethod);
+
+        IndexedPropertyDescriptor ipd2 = new IndexedPropertyDescriptor(
+                propertyName, beanClass);
+
+        assertEquals(ipd, ipd2);
+        assertEquals(ipd.hashCode(), ipd2.hashCode());
+    }
+    
+    public void testIncompatibleGetterAndIndexedGetterBean() {
+        try {
+            new IndexedPropertyDescriptor("data",
+                    IncompatibleGetterAndIndexedGetterBean.class);
+            fail("should throw IntrospectionException");
+
+        } catch (IntrospectionException e) {
+            //expected
+        }
+    }
+
+    private class IncompatibleGetterAndIndexedGetterBean {
+        private int[] data;
+
+        public int getData() {
+            return data[0];
+        }
+
+        public int getData(int index) {
+            return data[index];
+        }
+        
+        public void setData(int index, int data) {
+            this.data[index] = data;
+        }
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java Tue Jul 17 21:05:08 2007
@@ -31,6 +31,7 @@
 import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.EmptyStackException;
+import java.util.LinkedList;
 import java.util.Stack;
 
 import junit.framework.TestCase;
@@ -266,6 +267,27 @@
         assertEquals(method, aMethod);
         assertEquals(method.getName(), aMethod.getName());
         assertEquals("barTalk", aMethod.getName());
+    }
+    
+    public void test_writeObject_java_util_Collection() {
+        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+        XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+            byteArrayOutputStream));
+        LinkedList<Integer> list = new LinkedList<Integer>();
+        list.add(10);
+        list.addFirst(2);
+        System.out.println(encoder.getPersistenceDelegate(LinkedList.class));
+
+        encoder.writeObject(list);
+        encoder.close();
+        DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+                byteArrayOutputStream.toByteArray()));
+        XMLDecoder decoder = new XMLDecoder(stream);
+        LinkedList<Integer> l = (LinkedList<Integer>) decoder.readObject();
+        assertEquals(list, l);
+        assertEquals(2, l.size());
+        assertEquals(new Integer(10), l.get(1));
+        
     }
 
     // <--

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java Tue Jul 17 21:05:08 2007
@@ -232,8 +232,75 @@
         assertFalse(pd.isExpert());
         assertFalse(pd.isHidden());
         assertFalse(pd.isPreferred());
-    }
+        
+        propertyName = "propertyWithoutGet";
+        try{
+            new PropertyDescriptor(propertyName, beanClass);
+            fail("Should throw IntrospectionException");
+        }catch(IntrospectionException e){
+        }
+        
+        try{
+            new PropertyDescriptor(propertyName, beanClass, "getPropertyWithoutGet", "setPropertyWithoutGet");
+            fail("Should throw IntrospectionException");
+        }catch(IntrospectionException e){
+        }
+        
+        propertyName = "propertyWithoutSet";
+        beanClass = MockJavaBean.class;
+        try{
+            new PropertyDescriptor(propertyName, beanClass);
+            fail("Should throw IntrospectionException");
+        }catch(IntrospectionException e){
+        }
+        
+        propertyName = "propertyWithDifferentGetSet";
+        try{
+            new PropertyDescriptor(propertyName, beanClass);
+            fail("Should throw IntrospectionException");
+        }catch(IntrospectionException e){
+        }
+        
+        propertyName = "propertyWithInvalidGet";
+            new PropertyDescriptor(propertyName, beanClass);
+        
+        propertyName = "propertyWithoutPublicGet";
+        try{
+            new PropertyDescriptor(propertyName, beanClass);
+            fail("Should throw IntrospectionException");
+        }catch(IntrospectionException e){
+        }
+        
+        propertyName = "propertyWithGet1Param";
+        try{
+            new PropertyDescriptor(propertyName, beanClass);
+            fail("Should throw IntrospectionException");
+        }catch(IntrospectionException e){
+        }
+        
+        propertyName = "propertyWithIs1Param";
+        PropertyDescriptor pd2 = new PropertyDescriptor(propertyName, beanClass);
+        assertEquals("getPropertyWithIs1Param", pd2.getReadMethod().getName());
+
+        propertyName = "propertyWithSet2Param";
+        try {
+            new PropertyDescriptor(propertyName, beanClass);
+            fail("Should throw IntrospectionException");
+        } catch (IntrospectionException e) {
+        }
 
+        propertyName = "propertyWithIsGet";
+        PropertyDescriptor pd3 = new PropertyDescriptor(propertyName, beanClass);
+        assertEquals("isPropertyWithIsGet", pd3.getReadMethod().getName());
+
+        propertyName = "propertyWithVoidGet";
+        try {
+            new PropertyDescriptor(propertyName, beanClass);
+            fail("Should throw IntrospectionException");
+        } catch (IntrospectionException e) {
+        }
+    }
+    
     public void testPropertyDescriptorStringClass_PropertyNameCapital()
             throws IntrospectionException {
         String propertyName = "PropertyOne";
@@ -369,18 +436,23 @@
         assertFalse(pd.isExpert());
         assertFalse(pd.isHidden());
         assertFalse(pd.isPreferred());
+        
+        try{
+            pd = new PropertyDescriptor(propertyName, beanClass,
+                "", "set" + propertyName);
+            fail("should throw exception");
+        }catch(IntrospectionException e){
+        }
     }
 
     public void testPropertyDescriptorStringClassStringString_ReadMethodInvalid()
             throws IntrospectionException {
-        String propertyName = "PropertyTwo";
+        String propertyName = "booleanProperty";
         Class<MockJavaBean> beanClass = MockJavaBean.class;
-        try {
-            new PropertyDescriptor(propertyName, beanClass, "getXX", "set"
-                    + propertyName);
-            fail("Should throw IntrospectionException.");
-        } catch (IntrospectionException e) {
-        }
+        PropertyDescriptor pd = new PropertyDescriptor(propertyName, beanClass, "getXX", "set"
+                + propertyName);
+        assertEquals("getBooleanProperty", pd.getReadMethod().getName());
+        assertEquals("setbooleanProperty", pd.getWriteMethod().getName());
     }
 
     public void testPropertyDescriptorStringClassStringString_WriteMethodNull()

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java Tue Jul 17 21:05:08 2007
@@ -105,4 +105,13 @@
             //expected.
         }
     }
+    String[] defaultSearchPath;
+    
+    public void setUp(){
+        defaultSearchPath = PropertyEditorManager.getEditorSearchPath();
+    }
+    
+    public void tearDown(){
+        PropertyEditorManager.setEditorSearchPath(defaultSearchPath);
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java Tue Jul 17 21:05:08 2007
@@ -724,4 +724,14 @@
         assertNotNull("No property editor found", pe);
         assertTrue(pe instanceof AnotherSamplePropertyEditor);
     }
+    
+    String[] defaultSearchPath;
+    
+    public void setUp(){
+        defaultSearchPath = PropertyEditorManager.getEditorSearchPath();
+    }
+    
+    public void tearDown(){
+        PropertyEditorManager.setEditorSearchPath(defaultSearchPath);
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockJavaBean.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockJavaBean.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockJavaBean.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockJavaBean.java Tue Jul 17 21:05:08 2007
@@ -38,8 +38,40 @@
     private String[] propertyFive;
 
     private Integer[] propertySix;
+    
+    private String[] propertySeven;
 
     private String protectedProp;
+    
+    private String propertyWithoutSet;
+    
+    private boolean booleanProperty;
+    
+    private int propertyWithoutGet;
+    
+    private String propertyWithDifferentGetSet;
+    
+    private int propertyWithInvalidGet;
+    
+    private int propertyWithoutPublicGet;
+    
+    private int propertyWithGet1Param;
+
+    private int propertyWithIs1Param;
+    
+    private int propertyWithSet2Param;
+    
+    private int propertyWithIsGet;
+    
+    private int propertyWithVoidGet;
+
+    public Void getPropertyWithVoidGet() {
+        return null;
+    }
+
+    public void setPropertyWithVoidGet(int propertyWithVoidGet) {
+        this.propertyWithVoidGet = propertyWithVoidGet;
+    }
 
     public MockJavaBean() {
         this.beanName = getClass().getName();
@@ -48,6 +80,34 @@
     public MockJavaBean(String beanName) {
         this.beanName = beanName;
     }
+    
+    public String getXXX(){
+        return propertyThree;
+    }
+    
+    public String getPropertyWithDifferentGetSet(){
+        return propertyWithDifferentGetSet;
+    }
+    
+    public void setPropertyWithDifferentGetSet(int value){
+        this.propertyWithDifferentGetSet = String.valueOf(value);
+    }
+    
+    public String getPropertyWithoutSet(){
+        return propertyWithoutSet;
+    }
+    
+    public void setPropertyWithoutGet(int value){
+        this.propertyWithoutGet = value;
+    }
+    
+    public String getPropertyWithInvalidGet(){
+        return String.valueOf(propertyWithInvalidGet);
+    }
+    
+    public void setPropertyWithInvalidGet(String value){
+        propertyWithInvalidGet = Integer.valueOf(value);
+    }
 
     /**
      * @return Returns the beanName.
@@ -78,7 +138,7 @@
     public void setPropertyOne(String propertyOne) {
         this.propertyOne = propertyOne;
     }
-
+    
     /**
      * @return Returns the propertyTwo.
      */
@@ -137,6 +197,10 @@
     public String getPropertyFour(int i) {
         return getPropertyFour()[i];
     }
+    
+    public String getPropertyFive(int i, int j) {
+        return getPropertyFour()[i];
+    }
 
     public void getPropertyFourInvalid(int i) {
 
@@ -227,5 +291,85 @@
     public void removeMockPropertyChangeListener(
             MockPropertyChangeListener listener) {
 
+    }
+    
+    int isPropertyWithoutPublicGet() {
+        return propertyWithoutPublicGet;
+    }
+
+    int getPropertyWithoutPublicGet() {
+        return propertyWithoutPublicGet;
+    }
+
+    public void setPropertyWithoutPublicGet(int propertyWithoutPublicGet) {
+        this.propertyWithoutPublicGet = propertyWithoutPublicGet;
+    }
+    
+    public int isPropertyWithIs1Param(int i) {
+        return propertyWithIs1Param;
+    }
+    
+    public int getPropertyWithIs1Param() {
+        return propertyWithIs1Param;
+    }
+
+    public void setPropertyWithIs1Param(int value) {
+        this.propertyWithIs1Param = value;
+    }
+
+    public int getPropertyWithGet1Param(int i) {
+        return propertyWithGet1Param;
+    }
+
+    public void setPropertyWithGet1Param(int propertyWithGet1Param) {
+        this.propertyWithGet1Param = propertyWithGet1Param;
+    }
+
+    public int getPropertyWithSet2Param() {
+        return propertyWithSet2Param;
+    }
+
+    public void setPropertyWithSet2Param(int propertyWithSet2Param, int j) {
+        this.propertyWithSet2Param = propertyWithSet2Param;
+    }
+
+    public int isPropertyWithIsGet() {
+        return propertyWithIsGet;
+    }
+    
+    public int getPropertyWithIsGet() {
+        return propertyWithIsGet;
+    }
+
+    public void setPropertyWithIsGet(int propertyWithIsGet) {
+        this.propertyWithIsGet = propertyWithIsGet;
+    }
+
+    public boolean isBooleanProperty() {
+        return booleanProperty;
+    }
+    
+    public boolean getBooleanProperty() {
+        return booleanProperty;
+    }
+
+    public void setbooleanProperty(boolean booleanProperty) {
+        this.booleanProperty = booleanProperty;
+    }
+    
+    public Integer getPropertySeven(int i){
+        return Integer.valueOf(propertySeven[i]);
+    }
+    
+    public void setPropertySeven(int i, Integer I){
+        propertySeven[i] = String.valueOf(I);
+    }
+
+    public String[] getPropertySeven() {
+        return propertySeven;
+    }
+
+    public void setPropertySeven(String[] propertySeven) {
+        this.propertySeven = propertySeven;
     }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/javax/naming/ldap/SortControl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/javax/naming/ldap/SortControl.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/javax/naming/ldap/SortControl.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/javax/naming/ldap/SortControl.java Tue Jul 17 21:05:08 2007
@@ -18,6 +18,7 @@
 package javax.naming.ldap;
 
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 
 import org.apache.harmony.security.asn1.ASN1Boolean;
@@ -61,7 +62,12 @@
         public void getValues(Object object, Object values[]) {
             SortKey sk = (SortKey) object;
 
-            values[0] = sk.getAttributeID().getBytes();
+            try {
+                values[0] = sk.getAttributeID().getBytes("utf-8");
+            } catch (UnsupportedEncodingException e) {
+                //FIXME: is this right thing to do?
+                values[0] = sk.getAttributeID().getBytes();
+            }
             values[1] = sk.getMatchingRuleID();
             values[2] = Boolean.valueOf(!sk.isAscending());
         }
@@ -93,7 +99,11 @@
         super(OID, criticality, null);
         ArrayList<SortKey> list = new ArrayList<SortKey>();
         for (int i = 0; i < sortBy.length; i++) {
-            list.add(new SortKey(sortBy[i], true, null));
+            if(sortBy[i] != null){
+                list.add(new SortKey(sortBy[i], true, null));
+            }else{
+                list.add(new SortKey("", true, null));
+            }
         }
         value = ASN1_SORTKEYLIST.encode(list);
     }

Modified: harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java Tue Jul 17 21:05:08 2007
@@ -84,6 +84,32 @@
         assertEquals("30 10 30 0e 04 04 70 65 70 65 80 03 6c 65 6f 81 01 ff",
                 toHexString(sc.getEncodedValue()));
     }
+    
+    public void testEncodedValueOfSortControlNull() throws Exception{
+        String[] sk = {"pepe", null, "", "haha" };
+
+        SortControl sc = new SortControl(sk, true);
+        assertEquals("30 18 30 06 04 04 70 65 70 65 30 02 04 00 30 02 04 00 30 06 04 04 68 61 68 61",
+                toHexString(sc.getEncodedValue()));
+        
+        String[] sk2 = {"pepe", "", "haha" };
+        sc = new SortControl(sk2, true);
+        assertEquals("30 14 30 06 04 04 70 65 70 65 30 02 04 00 30 06 04 04 68 61 68 61",
+                toHexString(sc.getEncodedValue()));
+        
+        SortKey[] sk3 = {new SortKey("pepe", false, "haha"), null, new SortKey("", true, "haha2"), new SortKey("haah", true, "pepe")};
+        try{
+            sc = new SortControl(sk3, true);
+            fail("should throw NPE");
+        }catch(NullPointerException e){
+        }
+        
+        SortKey[] sk4 = {new SortKey("pepe", false, "haha"), new SortKey("", true, "haha2"), new SortKey("haah", true, "pepe")};
+        sc = new SortControl(sk4, true);
+        assertEquals("30 2a 30 0f 04 04 70 65 70 65 80 04 68 61 68 61 81 01 ff 30 09 04 00 80 05 68 61 68 61 32 30 0c 04 04 68 61 61 68 80 04 70 65 70 65",
+                toHexString(sc.getEncodedValue()));
+
+    }
 
     /**
      * <p>

Modified: harmony/enhanced/classlib/branches/java6/modules/lang-management/make/exclude.common
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/lang-management/make/exclude.common?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/lang-management/make/exclude.common (original)
+++ harmony/enhanced/classlib/branches/java6/modules/lang-management/make/exclude.common Tue Jul 17 21:05:08 2007
@@ -1 +1,7 @@
 org/apache/harmony/lang/management/tests/java/lang/management/ThreadMXBeanTest.java
+
+# The following tests crash on heavy loaded machines. 
+# Excluded till the further investigation.
+org/apache/harmony/lang/management/ThreadMXBeanImplTest.java
+org/apache/harmony/lang/management/tests/java/lang/management/ManagementFactoryTest.java
+

Modified: harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicSliderUI.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicSliderUI.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicSliderUI.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicSliderUI.java Tue Jul 17 21:05:08 2007
@@ -167,15 +167,19 @@
         private Point mousePoint = new Point();
 
         public TrackListener() {
+            
             trackTimer = new Timer(150, new ActionListener() {
+            
                 public void actionPerformed(final ActionEvent e) {
+                
                     Point current = new Point(thumbRect.x, thumbRect.y);
                     Point next = new Point(currentMouseX, currentMouseY);
                     int dir = calculateDirection(current, next);
-
-                    if (!thumbRect.contains(currentMouseX, currentMouseY)) {
+                    //Changed in H-4480
+                    if (shouldScroll(dir)) {
                         scrollDueToClickInTrack(dir);
                     }
+                    
                 }
             });
         }
@@ -232,24 +236,38 @@
         }
 
         public boolean shouldScroll(final int direction) {
+            // The class has been unused in TrackListener before H4480
+            // Now the behaviour has been changed and this method used in timer
             if (slider.getOrientation() == JSlider.HORIZONTAL) {
+              
                 if (direction == POSITIVE_SCROLL) {
-                    return mousePoint.x - (thumbRect.x + getThumbSize().width / 2) > 1;
+                
+                    return mousePoint.x
+                            - (thumbRect.x + computeIncrement() + getThumbSize().width) > 1;
                 }
+                
                 if (direction == NEGATIVE_SCROLL) {
-                    return mousePoint.x - (thumbRect.x + getThumbSize().width / 2) < -1;
+                
+                    return mousePoint.x - (thumbRect.x - computeIncrement()) < -1;
                 }
+                
             } else {
+               
                 if (direction == POSITIVE_SCROLL) {
-                    return mousePoint.y - (thumbRect.y - getThumbSize().height / 2) > 1;
+                
+                    return mousePoint.y
+                            - (thumbRect.y + computeIncrement() + getThumbSize().height / 2) > 1;
                 }
+                
                 if (direction == NEGATIVE_SCROLL) {
-                    return mousePoint.y - (thumbRect.y - getThumbSize().height / 2) < -1;
+                
+                    return mousePoint.y
+                            - (thumbRect.y + computeIncrement() + getThumbSize().height / 2) < -1;
                 }
             }
             return false;
         }
-
+        
         @Override
         public void mouseDragged(final MouseEvent e) {
             mousePoint = e.getPoint();
@@ -669,13 +687,17 @@
     protected void calculateTrackBuffer() {
         if (slider.getPaintLabels()) {
             if ((slider.getOrientation() == JSlider.HORIZONTAL)) {
-                trackBuffer = getWidthOfHighValueLabel() > getWidthOfLowValueLabel()
-                                                ? getWidthOfHighValueLabel() / 2
-                                                : getWidthOfLowValueLabel() / 2;
+                int widthOfHighValueLabel = getWidthOfHighValueLabel();
+                int widthOfLowValueLabel = getWidthOfLowValueLabel();
+                trackBuffer = widthOfHighValueLabel > widthOfLowValueLabel 
+                                                ? widthOfHighValueLabel / 2
+                                                : widthOfLowValueLabel / 2;
             } else {
-                trackBuffer = getHeightOfHighValueLabel() > getHeightOfLowValueLabel()
-                                                ? getHeightOfHighValueLabel() / 2
-                                                : getHeightOfLowValueLabel() / 2;
+                int heightOfHighValueLabel = getHeightOfHighValueLabel();
+                int heightOfLowValueLabel = getHeightOfLowValueLabel();
+                trackBuffer = heightOfHighValueLabel > heightOfLowValueLabel
+                                                ? heightOfHighValueLabel / 2
+                                                : heightOfLowValueLabel / 2;
             }
         } else {
             trackBuffer = (slider.getOrientation() == JSlider.HORIZONTAL)
@@ -789,19 +811,27 @@
     }
 
     protected int getWidthOfHighValueLabel() {
-        return getHighestValueLabel() == null ? 0 : getHighestValueLabel().getWidth();
+        Component label = getHighestValueLabel();
+
+        return label == null? 0: label.getWidth();
     }
 
-    protected int getWidthOfLowValueLabel() {
-        return getLowestValueLabel() == null ? 0 : getLowestValueLabel().getWidth();
+    protected int getWidthOfLowValueLabel() {        
+        Component label = getLowestValueLabel();
+
+        return label == null? 0: label.getWidth();
     }
 
     protected int getHeightOfHighValueLabel() {
-        return getHighestValueLabel() == null ? 0 : getHighestValueLabel().getHeight();
+        Component label = getHighestValueLabel();
+
+        return label == null? 0: label.getHeight();
     }
 
-    protected int getHeightOfLowValueLabel() {
-        return getLowestValueLabel() == null ? 0 : getLowestValueLabel().getHeight();
+    protected int getHeightOfLowValueLabel() {        
+        Component label = getLowestValueLabel();
+
+        return label == null? 0: label.getHeight();
     }
 
     protected Component getLowestValueLabel() {
@@ -1027,18 +1057,25 @@
         thumbRect.setLocation(x, y);
     }
 
-    public void scrollByBlock(final int direction) {
-        int increment;
+    int computeIncrement() {
+        
         if (slider.getMajorTickSpacing() != 0) {
-            increment = slider.getMajorTickSpacing();
+            
+            return slider.getMajorTickSpacing();
+            
         } else {
-            increment = (slider.getMaximum() - slider.getMinimum()) / 10;
+            
+            int increment = (slider.getMaximum() - slider.getMinimum()) / 10;
             if (increment <= 0) {
                 increment = 1;
             }
+            return increment;
         }
+    }
 
-        scrollByIncrement(direction, increment);
+    public void scrollByBlock(final int direction) {
+        //Changed in H-4480
+        scrollByIncrement(direction, computeIncrement());
     }
 
     public void scrollByUnit(final int direction) {



Mime
View raw message