diff --git a/jdk/src/share/classes/com/sun/beans/ObjectHandler.java b/jdk/src/share/classes/com/sun/beans/ObjectHandler.java
deleted file mode 100644
index 6daeab953a2..00000000000
--- a/jdk/src/share/classes/com/sun/beans/ObjectHandler.java
+++ /dev/null
@@ -1,479 +0,0 @@
-/*
- * Copyright 2003-2006 Sun Microsystems, Inc. All Rights Reserved.
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- *
- * This code is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License version 2 only, as
- * published by the Free Software Foundation. Sun designates this
- * particular file as subject to the "Classpath" exception as provided
- * by Sun in the LICENSE file that accompanied this code.
- *
- * This code 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
- * version 2 for more details (a copy is included in the LICENSE file that
- * accompanied this code).
- *
- * You should have received a copy of the GNU General Public License version
- * 2 along with this work; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
- * CA 95054 USA or visit www.sun.com if you need additional information or
- * have any questions.
- */
-
-package com.sun.beans;
-
-import com.sun.beans.finder.ClassFinder;
-
-import java.beans.*;
-import java.util.*;
-
-import org.xml.sax.*;
-
-import static java.util.Locale.ENGLISH;
-
-/**
- * WARNING: This class is an implementation detail and only meant
- * for use within the core platform. You should NOT depend upon it! This
- * API may change drastically between dot dot release, and it may even be
- * removed.
- *
- * @see java.beans.XMLEncoder
- * @see java.io.ObjectInputStream
- *
- * @since 1.4
- *
- * @author Philip Milne
- */
-public class ObjectHandler extends HandlerBase {
-
- public static Class typeNameToClass(String typeName) {
- typeName = typeName.intern();
- if (typeName == "boolean") return Boolean.class;
- if (typeName == "byte") return Byte.class;
- if (typeName == "char") return Character.class;
- if (typeName == "short") return Short.class;
- if (typeName == "int") return Integer.class;
- if (typeName == "long") return Long.class;
- if (typeName == "float") return Float.class;
- if (typeName == "double") return Double.class;
- if (typeName == "void") return Void.class;
- return null;
- }
-
- public static Class typeNameToPrimitiveClass(String typeName) {
- typeName = typeName.intern();
- if (typeName == "boolean") return boolean.class;
- if (typeName == "byte") return byte.class;
- if (typeName == "char") return char.class;
- if (typeName == "short") return short.class;
- if (typeName == "int") return int.class;
- if (typeName == "long") return long.class;
- if (typeName == "float") return float.class;
- if (typeName == "double") return double.class;
- if (typeName == "void") return void.class;
- return null;
- }
-
- /**
- * Returns the Class object associated with
- * the class or interface with the given string name,
- * using the default class loader.
- *
- * @param name fully qualified name of the desired class
- * @param cl class loader from which the class must be loaded
- * @return class object representing the desired class
- *
- * @exception ClassNotFoundException if the class cannot be located
- * by the specified class loader
- *
- * @deprecated As of JDK version 7, replaced by
- * {@link ClassFinder#resolveClass(String)}.
- */
- @Deprecated
- public static Class classForName(String name) throws ClassNotFoundException {
- return ClassFinder.resolveClass(name);
- }
-
- /**
- * Returns the Class object associated with
- * the class or interface with the given string name,
- * using the given class loader.
- *
- * @param name fully qualified name of the desired class
- * @param cl class loader from which the class must be loaded
- * @return class object representing the desired class
- *
- * @exception ClassNotFoundException if the class cannot be located
- * by the specified class loader
- *
- * @deprecated As of JDK version 7, replaced by
- * {@link ClassFinder#resolveClass(String,ClassLoader)}.
- */
- @Deprecated
- public static Class classForName(String name, ClassLoader cl)
- throws ClassNotFoundException {
- return ClassFinder.resolveClass(name, cl);
- }
-
- private Hashtable environment;
- private Vector expStack;
- private StringBuffer chars;
- private XMLDecoder is;
- private ClassLoader ldr;
- private int itemsRead = 0;
- private boolean isString;
-
- public ObjectHandler() {
- environment = new Hashtable();
- expStack = new Vector();
- chars = new StringBuffer();
- }
-
- public ObjectHandler(XMLDecoder is) {
- this();
- this.is = is;
- }
-
- /* loader can be null */
- public ObjectHandler(XMLDecoder is, ClassLoader loader) {
- this(is);
- this.ldr = loader;
- }
-
-
- public void reset() {
- expStack.clear();
- chars.setLength(0);
- MutableExpression e = new MutableExpression();
- e.setTarget(classForName2("java.lang.Object"));
- e.setMethodName("null");
- expStack.add(e);
- }
-
- private Object getValue(Expression exp) {
- try {
- return exp.getValue();
- }
- catch (Exception e) {
- if (is != null) {
- is.getExceptionListener().exceptionThrown(e);
- }
- return null;
- }
- }
-
- private void addArg(Object arg) {
- lastExp().addArg(arg);
- }
-
- private Object pop(Vector v) {
- int last = v.size()-1;
- Object result = v.get(last);
- v.remove(last);
- return result;
- }
-
- private Object eval() {
- return getValue(lastExp());
- }
-
- private MutableExpression lastExp() {
- return (MutableExpression)expStack.lastElement();
- }
-
- public Object dequeueResult() {
- Object[] results = lastExp().getArguments();
- return results[itemsRead++];
- }
-
- private boolean isPrimitive(String name) {
- return name != "void" && typeNameToClass(name) != null;
- }
-
- private void simulateException(String message) {
- Exception e = new Exception(message);
- e.fillInStackTrace();
- if (is != null) {
- is.getExceptionListener().exceptionThrown(e);
- }
- }
-
- private Class classForName2(String name) {
- try {
- return ClassFinder.resolveClass(name, this.ldr);
- }
- catch (ClassNotFoundException e) {
- if (is != null) {
- is.getExceptionListener().exceptionThrown(e);
- }
- }
- return null;
- }
-
- private HashMap getAttributes(AttributeList attrs) {
- HashMap attributes = new HashMap();
- if (attrs != null && attrs.getLength() > 0) {
- for(int i = 0; i < attrs.getLength(); i++) {
- attributes.put(attrs.getName(i), attrs.getValue(i));
- }
- }
- return attributes;
- }
-
- public void startElement(String name, AttributeList attrs) throws SAXException {
- name = name.intern(); // Xerces parser does not supply unique tag names.
- if (this.isString) {
- parseCharCode(name, getAttributes(attrs));
- return;
- }
- chars.setLength(0);
-
- HashMap attributes = getAttributes(attrs);
- MutableExpression e = new MutableExpression();
-
- // Target
- String className = (String)attributes.get("class");
- if (className != null) {
- e.setTarget(classForName2(className));
- }
-
- // Property
- Object property = attributes.get("property");
- String index = (String)attributes.get("index");
- if (index != null) {
- property = new Integer(index);
- e.addArg(property);
- }
- e.setProperty(property);
-
- // Method
- String methodName = (String)attributes.get("method");
- if (methodName == null && property == null) {
- methodName = "new";
- }
- e.setMethodName(methodName);
-
- // Tags
- if (name == "string") {
- e.setTarget(String.class);
- e.setMethodName("new");
- this.isString = true;
- }
- else if (isPrimitive(name)){
- Class wrapper = typeNameToClass(name);
- e.setTarget(wrapper);
- e.setMethodName("new");
- parseCharCode(name, attributes);
- }
- else if (name == "class") {
- e.setTarget(Class.class);
- e.setMethodName("forName");
- }
- else if (name == "null") {
- // Create an arbitrary expression that has a value of null - for
- // consistency.
- e.setTarget(Object.class);
- e.setMethodName("getSuperclass");
- e.setValue(null);
- }
- else if (name == "void") {
- if (e.getTarget() == null) { // this check is for "void class="foo" method= ..."
- e.setTarget(eval());
- }
- }
- else if (name == "array") {
- // The class attribute means sub-type for arrays.
- String subtypeName = (String)attributes.get("class");
- Class subtype = (subtypeName == null) ? Object.class : classForName2(subtypeName);
- String length = (String)attributes.get("length");
- if (length != null) {
- e.setTarget(java.lang.reflect.Array.class);
- e.addArg(subtype);
- e.addArg(new Integer(length));
- }
- else {
- Class arrayClass = java.lang.reflect.Array.newInstance(subtype, 0).getClass();
- e.setTarget(arrayClass);
- }
- }
- else if (name == "java") {
- e.setValue(is); // The outermost scope is the stream itself.
- }
- else if (name == "object") {
- }
- else {
- simulateException("Unrecognized opening tag: " + name + " " + attrsToString(attrs));
- return;
- }
-
- // ids
- String idName = (String)attributes.get("id");
- if (idName != null) {
- environment.put(idName, e);
- }
-
- // idrefs
- String idrefName = (String)attributes.get("idref");
- if (idrefName != null) {
- e.setValue(lookup(idrefName));
- }
-
- // fields
- String fieldName = (String)attributes.get("field");
- if (fieldName != null) {
- e.setValue(getFieldValue(e.getTarget(), fieldName));
- }
- expStack.add(e);
- }
-
- private Object getFieldValue(Object target, String fieldName) {
- try {
- Class type = target.getClass();
- if (type == Class.class) {
- type = (Class)target;
- }
- java.lang.reflect.Field f = sun.reflect.misc.FieldUtil.getField(type, fieldName);
- return f.get(target);
- }
- catch (Exception e) {
- if (is != null) {
- is.getExceptionListener().exceptionThrown(e);
- }
- return null;
- }
- }
-
- private String attrsToString(AttributeList attrs) {
- StringBuffer b = new StringBuffer();
- for (int i = 0; i < attrs.getLength (); i++) {
- b.append(attrs.getName(i)+"=\""+attrs.getValue(i)+"\" ");
- }
- return b.toString();
- }
-
- public void characters(char buf [], int offset, int len) throws SAXException {
- chars.append(new String(buf, offset, len));
- }
-
- private void parseCharCode(String name, Map map) {
- if (name == "char") {
- String value = (String) map.get("code");
- if (value != null) {
- int code = Integer.decode(value);
- for (char ch : Character.toChars(code)) {
- this.chars.append(ch);
- }
- }
- }
- }
-
- public Object lookup(String s) {
- Expression e = (Expression)environment.get(s);
- if (e == null) {
- simulateException("Unbound variable: " + s);
- }
- return getValue(e);
- }
-
- public void register(String id, Object value) {
- Expression e = new MutableExpression();
- e.setValue(value);
- environment.put(id, e);
- }
-
- public void endElement(String name) throws SAXException {
- name = name.intern(); // Xerces parser does not supply unique tag names.
- if (name == "string") {
- this.isString = false;
- } else if (this.isString) {
- return;
- }
- if (name == "java") {
- return;
- }
- if (isPrimitive(name) || name == "string" || name == "class") {
- addArg(chars.toString());
- }
- if (name == "object" || name == "array" || name == "void" ||
- isPrimitive(name) || name == "string" || name == "class" ||
- name == "null") {
- Expression e = (Expression)pop(expStack);
- Object value = getValue(e);
- if (name != "void") {
- addArg(value);
- }
- }
- else {
- simulateException("Unrecognized closing tag: " + name);
- }
- }
-}
-
-
-class MutableExpression extends Expression {
- private Object target;
- private String methodName;
-
- private Object property;
- private Vector argV = new Vector();
-
- private String capitalize(String propertyName) {
- if (propertyName.length() == 0) {
- return propertyName;
- }
- return propertyName.substring(0, 1).toUpperCase(ENGLISH) + propertyName.substring(1);
- }
-
- public MutableExpression() {
- super(null, null, null);
- }
-
- public Object[] getArguments() {
- return argV.toArray();
- }
-
- public String getMethodName() {
- if (property == null) {
- return methodName;
- }
- int setterArgs = (property instanceof String) ? 1 : 2;
- String methodName = (argV.size() == setterArgs) ? "set" : "get";
- if (property instanceof String) {
- return methodName + capitalize((String)property);
- }
- else {
- return methodName;
- }
- }
-
- public void addArg(Object arg) {
- argV.add(arg);
- }
-
- public void setTarget(Object target) {
- this.target = target;
- }
-
- public Object getTarget() {
- return target;
- }
-
- public void setMethodName(String methodName) {
- this.methodName = methodName;
- }
-
- public void setProperty(Object property) {
- this.property = property;
- }
-
- public void setValue(Object value) {
- super.setValue(value);
- }
-
- public Object getValue() throws Exception {
- return super.getValue();
- }
-}
diff --git a/jdk/src/share/classes/com/sun/beans/decoder/AccessorElementHandler.java b/jdk/src/share/classes/com/sun/beans/decoder/AccessorElementHandler.java
new file mode 100644
index 00000000000..d34fce45635
--- /dev/null
+++ b/jdk/src/share/classes/com/sun/beans/decoder/AccessorElementHandler.java
@@ -0,0 +1,105 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This is base class that simplifies access to entities (fields or properties).
+ * The {@code name} attribute specifies the name of the accessible entity.
+ * The element defines getter if it contains no argument
+ * or setter if it contains one argument.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+abstract class AccessorElementHandler extends ElementHandler {
+ private String name;
+ private ValueObject value;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ *
+ *
name
+ *
the name of the accessible entity
+ *
id
+ *
the identifier of the variable that is intended to store the result
+ *
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("name")) { // NON-NLS: the attribute name
+ this.name = value;
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Adds the argument that is used to set the value of this element.
+ *
+ * @param argument the value of the element that contained in this one
+ */
+ @Override
+ protected final void addArgument(Object argument) {
+ if (this.value != null) {
+ throw new IllegalStateException("Could not add argument to evaluated element");
+ }
+ setValue(this.name, argument);
+ this.value = ValueObjectImpl.VOID;
+ }
+
+ /**
+ * Returns the value of this element.
+ *
+ * @return the value of this element
+ */
+ @Override
+ protected final ValueObject getValueObject() {
+ if (this.value == null) {
+ this.value = ValueObjectImpl.create(getValue(this.name));
+ }
+ return this.value;
+ }
+
+ /**
+ * Returns the value of the entity with specified {@code name}.
+ *
+ * @param name the name of the accessible entity
+ * @return the value of the specified entity
+ */
+ protected abstract Object getValue(String name);
+
+ /**
+ * Sets the new value for the entity with specified {@code name}.
+ *
+ * @param name the name of the accessible entity
+ * @param value the new value for the specified entity
+ */
+ protected abstract void setValue(String name, Object value);
+}
diff --git a/jdk/src/share/classes/com/sun/beans/decoder/ArrayElementHandler.java b/jdk/src/share/classes/com/sun/beans/decoder/ArrayElementHandler.java
new file mode 100644
index 00000000000..0bfcec6e46a
--- /dev/null
+++ b/jdk/src/share/classes/com/sun/beans/decoder/ArrayElementHandler.java
@@ -0,0 +1,133 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.beans.decoder;
+
+import java.lang.reflect.Array;
+
+/**
+ * This class is intended to handle <array> element,
+ * that is used to array creation.
+ * The {@code length} attribute specifies the length of the array.
+ * The {@code class} attribute specifies the elements type.
+ * The {@link Object} type is used by default.
+ * For example:
+ * <array length="10"/>
+ * is equivalent to {@code new Component[10]} in Java code.
+ * The {@code set} and {@code get} methods,
+ * as defined in the {@link java.util.List} interface,
+ * can be used as if they could be applied to array instances.
+ * The {@code index} attribute can thus be used with arrays.
+ * For example:
+ * String[] s = new String[3];
+ * s[1] = "Hello, world";
+ * It is possible to omit the {@code length} attribute and
+ * specify the values directly, without using {@code void} tags.
+ * The length of the array is equal to the number of values specified.
+ * For example:
+ * is equivalent to {@code int[] array = {123, 456}} in Java code.
+ *
The following atributes are supported:
+ *
+ *
length
+ *
the array length
+ *
class
+ *
the type of object for instantiation
+ *
id
+ *
the identifier of the variable that is intended to store the result
+ *
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class ArrayElementHandler extends NewElementHandler {
+ private Integer length;
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ *
+ *
length
+ *
the array length
+ *
class
+ *
the type of object for instantiation
+ *
id
+ *
the identifier of the variable that is intended to store the result
+ *
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("length")) { // NON-NLS: the attribute name
+ this.length = Integer.valueOf(value);
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Calculates the value of this element
+ * if the lentgh attribute is set.
+ */
+ @Override
+ public void startElement() {
+ if (this.length != null) {
+ getValueObject();
+ }
+ }
+
+ /**
+ * Creates an instance of the array.
+ *
+ * @param type the base class
+ * @param args the array of arguments
+ * @return the value of this element
+ */
+ @Override
+ protected ValueObject getValueObject(Class> type, Object[] args) {
+ if (type == null) {
+ type = Object.class;
+ }
+ if (this.length != null) {
+ return ValueObjectImpl.create(Array.newInstance(type, this.length));
+ }
+ Object array = Array.newInstance(type, args.length);
+ for (int i = 0; i < args.length; i++) {
+ Array.set(array, i, args[i]);
+ }
+ return ValueObjectImpl.create(array);
+ }
+}
diff --git a/jdk/src/share/classes/com/sun/beans/decoder/BooleanElementHandler.java b/jdk/src/share/classes/com/sun/beans/decoder/BooleanElementHandler.java
new file mode 100644
index 00000000000..a5f401b5f49
--- /dev/null
+++ b/jdk/src/share/classes/com/sun/beans/decoder/BooleanElementHandler.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <boolean> element.
+ * This element specifies {@code boolean} values.
+ * The class {@link Boolean} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:
+ * which is equivalent to {@code Boolean.valueOf("true")} in Java code.
+ *
The following atribute is supported:
+ *
+ *
id
+ *
the identifier of the variable that is intended to store the result
+ *
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class BooleanElementHandler extends StringElementHandler {
+
+ /**
+ * Creates {@code boolean} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code boolean} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ if (Boolean.TRUE.toString().equalsIgnoreCase(argument)) {
+ return Boolean.TRUE;
+ }
+ if (Boolean.FALSE.toString().equalsIgnoreCase(argument)) {
+ return Boolean.FALSE;
+ }
+ throw new IllegalArgumentException("Unsupported boolean argument: " + argument);
+ }
+}
diff --git a/jdk/src/share/classes/com/sun/beans/decoder/ByteElementHandler.java b/jdk/src/share/classes/com/sun/beans/decoder/ByteElementHandler.java
new file mode 100644
index 00000000000..d7d458f0104
--- /dev/null
+++ b/jdk/src/share/classes/com/sun/beans/decoder/ByteElementHandler.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <byte> element.
+ * This element specifies {@code byte} values.
+ * The class {@link Byte} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:
+ * which is equivalent to {@code Byte.decode("127")} in Java code.
+ *
The following atribute is supported:
+ *
+ *
id
+ *
the identifier of the variable that is intended to store the result
+ *
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class ByteElementHandler extends StringElementHandler {
+
+ /**
+ * Creates {@code byte} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code byte} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ return Byte.decode(argument);
+ }
+}
diff --git a/jdk/src/share/classes/com/sun/beans/decoder/CharElementHandler.java b/jdk/src/share/classes/com/sun/beans/decoder/CharElementHandler.java
new file mode 100644
index 00000000000..910b5a63f70
--- /dev/null
+++ b/jdk/src/share/classes/com/sun/beans/decoder/CharElementHandler.java
@@ -0,0 +1,92 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <char> element.
+ * This element specifies {@code char} values.
+ * The class {@link Character} is used as wrapper for these values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:
+ * <char>X</char>
+ * which is equivalent to {@code Character.valueOf('X')} in Java code.
+ *
The following atributes are supported:
+ *
+ *
code
+ *
this attribute specifies character code
+ *
id
+ *
the identifier of the variable that is intended to store the result
+ *
+ * The {@code code} attribute can be used for characters
+ * that are illegal in XML document, for example:
+ * <char code="0"/>
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class CharElementHandler extends StringElementHandler {
+
+ /**
+ * Parses attributes of the element.
+ * The following atributes are supported:
+ *
+ *
code
+ *
this attribute specifies character code
+ *
id
+ *
the identifier of the variable that is intended to store the result
+ *
+ *
+ * @param name the attribute name
+ * @param value the attribute value
+ */
+ @Override
+ public void addAttribute(String name, String value) {
+ if (name.equals("code")) { // NON-NLS: the attribute name
+ int code = Integer.decode(value);
+ for (char ch : Character.toChars(code)) {
+ addCharacter(ch);
+ }
+ } else {
+ super.addAttribute(name, value);
+ }
+ }
+
+ /**
+ * Creates {@code char} value from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code char} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ if (argument.length() != 1) {
+ throw new IllegalArgumentException("Wrong characters count");
+ }
+ return Character.valueOf(argument.charAt(0));
+ }
+}
diff --git a/jdk/src/share/classes/com/sun/beans/decoder/ClassElementHandler.java b/jdk/src/share/classes/com/sun/beans/decoder/ClassElementHandler.java
new file mode 100644
index 00000000000..c6ca9856416
--- /dev/null
+++ b/jdk/src/share/classes/com/sun/beans/decoder/ClassElementHandler.java
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.beans.decoder;
+
+/**
+ * This class is intended to handle <class> element.
+ * This element specifies {@link Class} values.
+ * The result value is created from text of the body of this element.
+ * The body parsing is described in the class {@link StringElementHandler}.
+ * For example:
+ * which is equivalent to {@code Class.forName("java.lang.Class")} in Java code.
+ *
The following atribute is supported:
+ *
+ *
id
+ *
the identifier of the variable that is intended to store the result
+ *
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ */
+final class ClassElementHandler extends StringElementHandler {
+
+ /**
+ * Creates class by the name from
+ * the text of the body of this element.
+ *
+ * @param argument the text of the body
+ * @return evaluated {@code Class} value
+ */
+ @Override
+ public Object getValue(String argument) {
+ return getOwner().findClass(argument);
+ }
+}
diff --git a/jdk/src/share/classes/com/sun/beans/decoder/DocumentHandler.java b/jdk/src/share/classes/com/sun/beans/decoder/DocumentHandler.java
new file mode 100644
index 00000000000..4c409a12a9b
--- /dev/null
+++ b/jdk/src/share/classes/com/sun/beans/decoder/DocumentHandler.java
@@ -0,0 +1,389 @@
+/*
+ * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation. Sun designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Sun in the LICENSE file that accompanied this code.
+ *
+ * This code 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
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+package com.sun.beans.decoder;
+
+import com.sun.beans.finder.ClassFinder;
+
+import java.beans.ExceptionListener;
+
+import java.io.IOException;
+
+import java.lang.ref.Reference;
+import java.lang.ref.WeakReference;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+import org.xml.sax.helpers.DefaultHandler;
+
+/**
+ * The main class to parse JavaBeans XML archive.
+ *
+ * @since 1.7
+ *
+ * @author Sergey A. Malenkov
+ *
+ * @see ElementHandler
+ */
+public final class DocumentHandler extends DefaultHandler {
+ private final Map> handlers = new HashMap>();
+
+ private final Map environment = new HashMap();
+
+ private final List