feat(jdk8): move files to new folder to avoid resources compiled.
This commit is contained in:
105
jdkSrc/jdk8/com/sun/beans/decoder/AccessorElementHandler.java
Normal file
105
jdkSrc/jdk8/com/sun/beans/decoder/AccessorElementHandler.java
Normal file
@@ -0,0 +1,105 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.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 attributes are supported:
|
||||
* <dl>
|
||||
* <dt>name
|
||||
* <dd>the name of the accessible entity
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
147
jdkSrc/jdk8/com/sun/beans/decoder/ArrayElementHandler.java
Normal file
147
jdkSrc/jdk8/com/sun/beans/decoder/ArrayElementHandler.java
Normal file
@@ -0,0 +1,147 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.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:<pre>
|
||||
* <array length="10"/></pre>
|
||||
* 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:<pre>
|
||||
* <array length="3" class="java.lang.String">
|
||||
* <void index="1">
|
||||
* <string>Hello, world</string>
|
||||
* </void>
|
||||
* </array></pre>
|
||||
* is equivalent to the following Java code:<pre>
|
||||
* String[] s = new String[3];
|
||||
* s[1] = "Hello, world";</pre>
|
||||
* 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:<pre>
|
||||
* <array id="array" class="int">
|
||||
* <int>123</int>
|
||||
* <int>456</int>
|
||||
* </array></pre>
|
||||
* is equivalent to {@code int[] array = {123, 456}} in Java code.
|
||||
* <p>The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>length
|
||||
* <dd>the array length
|
||||
* <dt>class
|
||||
* <dd>the type of object for instantiation
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class ArrayElementHandler extends NewElementHandler {
|
||||
private Integer length;
|
||||
|
||||
/**
|
||||
* Parses attributes of the element.
|
||||
* The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>length
|
||||
* <dd>the array length
|
||||
* <dt>class
|
||||
* <dd>the type of object for instantiation
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the value of this element can be used
|
||||
* as an argument of the element that contained in this one.
|
||||
*
|
||||
* @return {@code true} if the value of this element can be used
|
||||
* as an argument of the element that contained in this one,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
@Override
|
||||
protected boolean isArgument() {
|
||||
return true; // hack for compatibility
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
}
|
||||
69
jdkSrc/jdk8/com/sun/beans/decoder/BooleanElementHandler.java
Normal file
69
jdkSrc/jdk8/com/sun/beans/decoder/BooleanElementHandler.java
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.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:<pre>
|
||||
* <boolean>true</boolean></pre>
|
||||
* is shortcut to<pre>
|
||||
* <method name="valueOf" class="java.lang.Boolean">
|
||||
* <string>true</string>
|
||||
* </method></pre>
|
||||
* which is equivalent to {@code Boolean.valueOf("true")} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
63
jdkSrc/jdk8/com/sun/beans/decoder/ByteElementHandler.java
Normal file
63
jdkSrc/jdk8/com/sun/beans/decoder/ByteElementHandler.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.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:<pre>
|
||||
* <byte>127</byte></pre>
|
||||
* is shortcut to<pre>
|
||||
* <method name="decode" class="java.lang.Byte">
|
||||
* <string>127</string>
|
||||
* </method></pre>
|
||||
* which is equivalent to {@code Byte.decode("127")} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
92
jdkSrc/jdk8/com/sun/beans/decoder/CharElementHandler.java
Normal file
92
jdkSrc/jdk8/com/sun/beans/decoder/CharElementHandler.java
Normal file
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.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:<pre>
|
||||
* <char>X</char></pre>
|
||||
* which is equivalent to {@code Character.valueOf('X')} in Java code.
|
||||
* <p>The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>code
|
||||
* <dd>this attribute specifies character code
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
* The {@code code} attribute can be used for characters
|
||||
* that are illegal in XML document, for example:<pre>
|
||||
* <char code="0"/></pre>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class CharElementHandler extends StringElementHandler {
|
||||
|
||||
/**
|
||||
* Parses attributes of the element.
|
||||
* The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>code
|
||||
* <dd>this attribute specifies character code
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @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));
|
||||
}
|
||||
}
|
||||
62
jdkSrc/jdk8/com/sun/beans/decoder/ClassElementHandler.java
Normal file
62
jdkSrc/jdk8/com/sun/beans/decoder/ClassElementHandler.java
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.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:<pre>
|
||||
* <class>java.lang.Class</class></pre>
|
||||
* is shortcut to<pre>
|
||||
* <method name="forName" class="java.lang.Class">
|
||||
* <string>java.lang.Class</string>
|
||||
* </method></pre>
|
||||
* which is equivalent to {@code Class.forName("java.lang.Class")} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
411
jdkSrc/jdk8/com/sun/beans/decoder/DocumentHandler.java
Normal file
411
jdkSrc/jdk8/com/sun/beans/decoder/DocumentHandler.java
Normal file
@@ -0,0 +1,411 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2012, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.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.io.StringReader;
|
||||
|
||||
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 java.security.AccessControlContext;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
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;
|
||||
|
||||
import sun.misc.SharedSecrets;
|
||||
|
||||
/**
|
||||
* 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 AccessControlContext acc = AccessController.getContext();
|
||||
private final Map<String, Class<? extends ElementHandler>> handlers = new HashMap<>();
|
||||
private final Map<String, Object> environment = new HashMap<>();
|
||||
private final List<Object> objects = new ArrayList<>();
|
||||
|
||||
private Reference<ClassLoader> loader;
|
||||
private ExceptionListener listener;
|
||||
private Object owner;
|
||||
|
||||
private ElementHandler handler;
|
||||
|
||||
/**
|
||||
* Creates new instance of document handler.
|
||||
*/
|
||||
public DocumentHandler() {
|
||||
setElementHandler("java", JavaElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("null", NullElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("array", ArrayElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("class", ClassElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("string", StringElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("object", ObjectElementHandler.class); // NON-NLS: the element name
|
||||
|
||||
setElementHandler("void", VoidElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("char", CharElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("byte", ByteElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("short", ShortElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("int", IntElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("long", LongElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("float", FloatElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("double", DoubleElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("boolean", BooleanElementHandler.class); // NON-NLS: the element name
|
||||
|
||||
// some handlers for new elements
|
||||
setElementHandler("new", NewElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("var", VarElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("true", TrueElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("false", FalseElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("field", FieldElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("method", MethodElementHandler.class); // NON-NLS: the element name
|
||||
setElementHandler("property", PropertyElementHandler.class); // NON-NLS: the element name
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the class loader used to instantiate objects.
|
||||
* If the class loader has not been explicitly set
|
||||
* then {@code null} is returned.
|
||||
*
|
||||
* @return the class loader used to instantiate objects
|
||||
*/
|
||||
public ClassLoader getClassLoader() {
|
||||
return (this.loader != null)
|
||||
? this.loader.get()
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the class loader used to instantiate objects.
|
||||
* If the class loader is not set
|
||||
* then default class loader will be used.
|
||||
*
|
||||
* @param loader a classloader to use
|
||||
*/
|
||||
public void setClassLoader(ClassLoader loader) {
|
||||
this.loader = new WeakReference<ClassLoader>(loader);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the exception listener for parsing.
|
||||
* The exception listener is notified
|
||||
* when handler catches recoverable exceptions.
|
||||
* If the exception listener has not been explicitly set
|
||||
* then default exception listener is returned.
|
||||
*
|
||||
* @return the exception listener for parsing
|
||||
*/
|
||||
public ExceptionListener getExceptionListener() {
|
||||
return this.listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the exception listener for parsing.
|
||||
* The exception listener is notified
|
||||
* when handler catches recoverable exceptions.
|
||||
*
|
||||
* @param listener the exception listener for parsing
|
||||
*/
|
||||
public void setExceptionListener(ExceptionListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the owner of this document handler.
|
||||
*
|
||||
* @return the owner of this document handler
|
||||
*/
|
||||
public Object getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the owner of this document handler.
|
||||
*
|
||||
* @param owner the owner of this document handler
|
||||
*/
|
||||
public void setOwner(Object owner) {
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the handler for the element with specified name.
|
||||
*
|
||||
* @param name the name of the element
|
||||
* @return the corresponding element handler
|
||||
*/
|
||||
public Class<? extends ElementHandler> getElementHandler(String name) {
|
||||
Class<? extends ElementHandler> type = this.handlers.get(name);
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("Unsupported element: " + name);
|
||||
}
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the handler for the element with specified name.
|
||||
*
|
||||
* @param name the name of the element
|
||||
* @param handler the corresponding element handler
|
||||
*/
|
||||
public void setElementHandler(String name, Class<? extends ElementHandler> handler) {
|
||||
this.handlers.put(name, handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicates whether the variable with specified identifier is defined.
|
||||
*
|
||||
* @param id the identifier
|
||||
* @return @{code true} if the variable is defined;
|
||||
* @{code false} otherwise
|
||||
*/
|
||||
public boolean hasVariable(String id) {
|
||||
return this.environment.containsKey(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the variable with specified identifier.
|
||||
*
|
||||
* @param id the identifier
|
||||
* @return the value of the variable
|
||||
*/
|
||||
public Object getVariable(String id) {
|
||||
if (!this.environment.containsKey(id)) {
|
||||
throw new IllegalArgumentException("Unbound variable: " + id);
|
||||
}
|
||||
return this.environment.get(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets new value of the variable with specified identifier.
|
||||
*
|
||||
* @param id the identifier
|
||||
* @param value new value of the variable
|
||||
*/
|
||||
public void setVariable(String id, Object value) {
|
||||
this.environment.put(id, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the array of readed objects.
|
||||
*
|
||||
* @return the array of readed objects
|
||||
*/
|
||||
public Object[] getObjects() {
|
||||
return this.objects.toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the object to the list of readed objects.
|
||||
*
|
||||
* @param object the object that is readed from XML document
|
||||
*/
|
||||
void addObject(Object object) {
|
||||
this.objects.add(object);
|
||||
}
|
||||
|
||||
/**
|
||||
* Disables any external entities.
|
||||
*/
|
||||
@Override
|
||||
public InputSource resolveEntity(String publicId, String systemId) {
|
||||
return new InputSource(new StringReader(""));
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepares this handler to read objects from XML document.
|
||||
*/
|
||||
@Override
|
||||
public void startDocument() {
|
||||
this.objects.clear();
|
||||
this.handler = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses opening tag of XML element
|
||||
* using corresponding element handler.
|
||||
*
|
||||
* @param uri the namespace URI, or the empty string
|
||||
* if the element has no namespace URI or
|
||||
* if namespace processing is not being performed
|
||||
* @param localName the local name (without prefix), or the empty string
|
||||
* if namespace processing is not being performed
|
||||
* @param qName the qualified name (with prefix), or the empty string
|
||||
* if qualified names are not available
|
||||
* @param attributes the attributes attached to the element
|
||||
*/
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
ElementHandler parent = this.handler;
|
||||
try {
|
||||
this.handler = getElementHandler(qName).newInstance();
|
||||
this.handler.setOwner(this);
|
||||
this.handler.setParent(parent);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
throw new SAXException(exception);
|
||||
}
|
||||
for (int i = 0; i < attributes.getLength(); i++)
|
||||
try {
|
||||
String name = attributes.getQName(i);
|
||||
String value = attributes.getValue(i);
|
||||
this.handler.addAttribute(name, value);
|
||||
}
|
||||
catch (RuntimeException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
|
||||
this.handler.startElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses closing tag of XML element
|
||||
* using corresponding element handler.
|
||||
*
|
||||
* @param uri the namespace URI, or the empty string
|
||||
* if the element has no namespace URI or
|
||||
* if namespace processing is not being performed
|
||||
* @param localName the local name (without prefix), or the empty string
|
||||
* if namespace processing is not being performed
|
||||
* @param qName the qualified name (with prefix), or the empty string
|
||||
* if qualified names are not available
|
||||
*/
|
||||
@Override
|
||||
public void endElement(String uri, String localName, String qName) {
|
||||
try {
|
||||
this.handler.endElement();
|
||||
}
|
||||
catch (RuntimeException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
finally {
|
||||
this.handler = this.handler.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses character data inside XML element.
|
||||
*
|
||||
* @param chars the array of characters
|
||||
* @param start the start position in the character array
|
||||
* @param length the number of characters to use
|
||||
*/
|
||||
@Override
|
||||
public void characters(char[] chars, int start, int length) {
|
||||
if (this.handler != null) {
|
||||
try {
|
||||
while (0 < length--) {
|
||||
this.handler.addCharacter(chars[start++]);
|
||||
}
|
||||
}
|
||||
catch (RuntimeException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles an exception using current exception listener.
|
||||
*
|
||||
* @param exception an exception to handle
|
||||
* @see #setExceptionListener
|
||||
*/
|
||||
public void handleException(Exception exception) {
|
||||
if (this.listener == null) {
|
||||
throw new IllegalStateException(exception);
|
||||
}
|
||||
this.listener.exceptionThrown(exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts parsing of the specified input source.
|
||||
*
|
||||
* @param input the input source to parse
|
||||
*/
|
||||
public void parse(final InputSource input) {
|
||||
if ((this.acc == null) && (null != System.getSecurityManager())) {
|
||||
throw new SecurityException("AccessControlContext is not set");
|
||||
}
|
||||
AccessControlContext stack = AccessController.getContext();
|
||||
SharedSecrets.getJavaSecurityAccess().doIntersectionPrivilege(new PrivilegedAction<Void>() {
|
||||
public Void run() {
|
||||
try {
|
||||
SAXParserFactory.newInstance().newSAXParser().parse(input, DocumentHandler.this);
|
||||
}
|
||||
catch (ParserConfigurationException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
catch (SAXException wrapper) {
|
||||
Exception exception = wrapper.getException();
|
||||
if (exception == null) {
|
||||
exception = wrapper;
|
||||
}
|
||||
handleException(exception);
|
||||
}
|
||||
catch (IOException exception) {
|
||||
handleException(exception);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}, stack, this.acc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves class by name using current class loader.
|
||||
* This method handles exception using current exception listener.
|
||||
*
|
||||
* @param name the name of the class
|
||||
* @return the object that represents the class
|
||||
*/
|
||||
public Class<?> findClass(String name) {
|
||||
try {
|
||||
return ClassFinder.resolveClass(name, getClassLoader());
|
||||
}
|
||||
catch (ClassNotFoundException exception) {
|
||||
handleException(exception);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
63
jdkSrc/jdk8/com/sun/beans/decoder/DoubleElementHandler.java
Normal file
63
jdkSrc/jdk8/com/sun/beans/decoder/DoubleElementHandler.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <double> element.
|
||||
* This element specifies {@code double} values.
|
||||
* The class {@link Double} 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:<pre>
|
||||
* <double>1.23e45</double></pre>
|
||||
* is shortcut to<pre>
|
||||
* <method name="valueOf" class="java.lang.Double">
|
||||
* <string>1.23e45</string>
|
||||
* </method></pre>
|
||||
* which is equivalent to {@code Double.valueOf("1.23e45")} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class DoubleElementHandler extends StringElementHandler {
|
||||
|
||||
/**
|
||||
* Creates {@code double} value from
|
||||
* the text of the body of this element.
|
||||
*
|
||||
* @param argument the text of the body
|
||||
* @return evaluated {@code double} value
|
||||
*/
|
||||
@Override
|
||||
public Object getValue(String argument) {
|
||||
return Double.valueOf(argument);
|
||||
}
|
||||
}
|
||||
224
jdkSrc/jdk8/com/sun/beans/decoder/ElementHandler.java
Normal file
224
jdkSrc/jdk8/com/sun/beans/decoder/ElementHandler.java
Normal file
@@ -0,0 +1,224 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* The base class for element handlers.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*
|
||||
* @see DocumentHandler
|
||||
*/
|
||||
public abstract class ElementHandler {
|
||||
private DocumentHandler owner;
|
||||
private ElementHandler parent;
|
||||
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Returns the document handler that creates this element handler.
|
||||
*
|
||||
* @return the owner document handler
|
||||
*/
|
||||
public final DocumentHandler getOwner() {
|
||||
return this.owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the document handler that creates this element handler.
|
||||
* The owner document handler should be set after instantiation.
|
||||
* Such approach is used to simplify the extensibility.
|
||||
*
|
||||
* @param owner the owner document handler
|
||||
* @see DocumentHandler#startElement
|
||||
*/
|
||||
final void setOwner(DocumentHandler owner) {
|
||||
if (owner == null) {
|
||||
throw new IllegalArgumentException("Every element should have owner");
|
||||
}
|
||||
this.owner = owner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the element handler that contains this one.
|
||||
*
|
||||
* @return the parent element handler
|
||||
*/
|
||||
public final ElementHandler getParent() {
|
||||
return this.parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the element handler that contains this one.
|
||||
* The parent element handler should be set after instantiation.
|
||||
* Such approach is used to simplify the extensibility.
|
||||
*
|
||||
* @param parent the parent element handler
|
||||
* @see DocumentHandler#startElement
|
||||
*/
|
||||
final void setParent(ElementHandler parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the variable with specified identifier.
|
||||
*
|
||||
* @param id the identifier
|
||||
* @return the value of the variable
|
||||
*/
|
||||
protected final Object getVariable(String id) {
|
||||
if (id.equals(this.id)) {
|
||||
ValueObject value = getValueObject();
|
||||
if (value.isVoid()) {
|
||||
throw new IllegalStateException("The element does not return value");
|
||||
}
|
||||
return value.getValue();
|
||||
}
|
||||
return (this.parent != null)
|
||||
? this.parent.getVariable(id)
|
||||
: this.owner.getVariable(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the parent element.
|
||||
*
|
||||
* @return the value of the parent element
|
||||
*/
|
||||
protected Object getContextBean() {
|
||||
if (this.parent != null) {
|
||||
ValueObject value = this.parent.getValueObject();
|
||||
if (!value.isVoid()) {
|
||||
return value.getValue();
|
||||
}
|
||||
throw new IllegalStateException("The outer element does not return value");
|
||||
} else {
|
||||
Object value = this.owner.getOwner();
|
||||
if (value != null) {
|
||||
return value;
|
||||
}
|
||||
throw new IllegalStateException("The topmost element does not have context");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parses attributes of the element.
|
||||
* By default, the following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @param name the attribute name
|
||||
* @param value the attribute value
|
||||
*/
|
||||
public void addAttribute(String name, String value) {
|
||||
if (name.equals("id")) { // NON-NLS: the attribute name
|
||||
this.id = value;
|
||||
} else {
|
||||
throw new IllegalArgumentException("Unsupported attribute: " + name);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called before parsing of the element's body.
|
||||
* All attributes are parsed at this point.
|
||||
* By default, do nothing.
|
||||
*/
|
||||
public void startElement() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is called after parsing of the element's body.
|
||||
* By default, it calculates the value of this element.
|
||||
* The following tasks are executing for any non-void value:
|
||||
* <ol>
|
||||
* <li>If the {@code id} attribute is set
|
||||
* the value of the variable with the specified identifier
|
||||
* is set to the value of this element.</li>
|
||||
* <li>This element is used as an argument of parent element if it is possible.</li>
|
||||
* </ol>
|
||||
*
|
||||
* @see #isArgument
|
||||
*/
|
||||
public void endElement() {
|
||||
// do nothing if no value returned
|
||||
ValueObject value = getValueObject();
|
||||
if (!value.isVoid()) {
|
||||
if (this.id != null) {
|
||||
this.owner.setVariable(this.id, value.getValue());
|
||||
}
|
||||
if (isArgument()) {
|
||||
if (this.parent != null) {
|
||||
this.parent.addArgument(value.getValue());
|
||||
} else {
|
||||
this.owner.addObject(value.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the character that contained in this element.
|
||||
* By default, only whitespaces are acceptable.
|
||||
*
|
||||
* @param ch the character
|
||||
*/
|
||||
public void addCharacter(char ch) {
|
||||
if ((ch != ' ') && (ch != '\n') && (ch != '\t') && (ch != '\r')) {
|
||||
throw new IllegalStateException("Illegal character with code " + (int) ch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the argument that is used to calculate the value of this element.
|
||||
* By default, no arguments are acceptable.
|
||||
*
|
||||
* @param argument the value of the element that contained in this one
|
||||
*/
|
||||
protected void addArgument(Object argument) {
|
||||
throw new IllegalStateException("Could not add argument to simple element");
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the value of this element can be used
|
||||
* as an argument of the element that contained in this one.
|
||||
*
|
||||
* @return {@code true} if the value of this element can be used
|
||||
* as an argument of the element that contained in this one,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
protected boolean isArgument() {
|
||||
return this.id == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this element.
|
||||
*
|
||||
* @return the value of this element
|
||||
*/
|
||||
protected abstract ValueObject getValueObject();
|
||||
}
|
||||
56
jdkSrc/jdk8/com/sun/beans/decoder/FalseElementHandler.java
Normal file
56
jdkSrc/jdk8/com/sun/beans/decoder/FalseElementHandler.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <false> element.
|
||||
* This element specifies {@code false} value.
|
||||
* It should not contain body or inner elements.
|
||||
* For example:<pre>
|
||||
* <false/></pre>
|
||||
* is equivalent to {@code false} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class FalseElementHandler extends NullElementHandler {
|
||||
|
||||
/**
|
||||
* Returns {@code Boolean.FALSE}
|
||||
* as a value of <false> element.
|
||||
*
|
||||
* @return {@code Boolean.FALSE} by default
|
||||
*/
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return Boolean.FALSE;
|
||||
}
|
||||
}
|
||||
189
jdkSrc/jdk8/com/sun/beans/decoder/FieldElementHandler.java
Normal file
189
jdkSrc/jdk8/com/sun/beans/decoder/FieldElementHandler.java
Normal file
@@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
import com.sun.beans.finder.FieldFinder;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <field> element.
|
||||
* This element simplifies access to the fields.
|
||||
* If the {@code class} attribute is specified
|
||||
* this element accesses static field of specified class.
|
||||
* This element defines getter if it contains no argument.
|
||||
* It returns the value of the field in this case.
|
||||
* For example:<pre>
|
||||
* <field name="TYPE" class="java.lang.Long"/></pre>
|
||||
* is equivalent to {@code Long.TYPE} in Java code.
|
||||
* This element defines setter if it contains one argument.
|
||||
* It does not return the value of the field in this case.
|
||||
* For example:<pre>
|
||||
* <field name="id"><int>0</int></field></pre>
|
||||
* is equivalent to {@code id = 0} in Java code.
|
||||
* <p>The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>name
|
||||
* <dd>the field name
|
||||
* <dt>class
|
||||
* <dd>the type is used for static fields only
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class FieldElementHandler extends AccessorElementHandler {
|
||||
private Class<?> type;
|
||||
|
||||
/**
|
||||
* Parses attributes of the element.
|
||||
* The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>name
|
||||
* <dd>the field name
|
||||
* <dt>class
|
||||
* <dd>the type is used for static fields only
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @param name the attribute name
|
||||
* @param value the attribute value
|
||||
*/
|
||||
@Override
|
||||
public void addAttribute(String name, String value) {
|
||||
if (name.equals("class")) { // NON-NLS: the attribute name
|
||||
this.type = getOwner().findClass(value);
|
||||
} else {
|
||||
super.addAttribute(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the value of this element can be used
|
||||
* as an argument of the element that contained in this one.
|
||||
*
|
||||
* @return {@code true} if the value of this element should be used
|
||||
* as an argument of the element that contained in this one,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
@Override
|
||||
protected boolean isArgument() {
|
||||
return super.isArgument() && (this.type != null); // only static accessor can be used an argument
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the context of the field.
|
||||
* The context of the static field is the class object.
|
||||
* The context of the non-static field is the value of the parent element.
|
||||
*
|
||||
* @return the context of the field
|
||||
*/
|
||||
@Override
|
||||
protected Object getContextBean() {
|
||||
return (this.type != null)
|
||||
? this.type
|
||||
: super.getContextBean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the field with specified {@code name}.
|
||||
*
|
||||
* @param name the name of the field
|
||||
* @return the value of the specified field
|
||||
*/
|
||||
@Override
|
||||
protected Object getValue(String name) {
|
||||
try {
|
||||
return getFieldValue(getContextBean(), name);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
getOwner().handleException(exception);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new value for the field with specified {@code name}.
|
||||
*
|
||||
* @param name the name of the field
|
||||
* @param value the new value for the specified field
|
||||
*/
|
||||
@Override
|
||||
protected void setValue(String name, Object value) {
|
||||
try {
|
||||
setFieldValue(getContextBean(), name, value);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
getOwner().handleException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the search of the field with specified {@code name}
|
||||
* in specified context and returns its value.
|
||||
*
|
||||
* @param bean the context bean that contains field
|
||||
* @param name the name of the field
|
||||
* @return the value of the field
|
||||
* @throws IllegalAccessException if the field is not accesible
|
||||
* @throws NoSuchFieldException if the field is not found
|
||||
*/
|
||||
static Object getFieldValue(Object bean, String name) throws IllegalAccessException, NoSuchFieldException {
|
||||
return findField(bean, name).get(bean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the search of the field with specified {@code name}
|
||||
* in specified context and updates its value.
|
||||
*
|
||||
* @param bean the context bean that contains field
|
||||
* @param name the name of the field
|
||||
* @param value the new value for the field
|
||||
* @throws IllegalAccessException if the field is not accesible
|
||||
* @throws NoSuchFieldException if the field is not found
|
||||
*/
|
||||
private static void setFieldValue(Object bean, String name, Object value) throws IllegalAccessException, NoSuchFieldException {
|
||||
findField(bean, name).set(bean, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the search of the field
|
||||
* with specified {@code name} in specified context.
|
||||
*
|
||||
* @param bean the context bean that contains field
|
||||
* @param name the name of the field
|
||||
* @return field object that represents found field
|
||||
* @throws NoSuchFieldException if the field is not found
|
||||
*/
|
||||
private static Field findField(Object bean, String name) throws NoSuchFieldException {
|
||||
return (bean instanceof Class<?>)
|
||||
? FieldFinder.findStaticField((Class<?>) bean, name)
|
||||
: FieldFinder.findField(bean.getClass(), name);
|
||||
}
|
||||
}
|
||||
63
jdkSrc/jdk8/com/sun/beans/decoder/FloatElementHandler.java
Normal file
63
jdkSrc/jdk8/com/sun/beans/decoder/FloatElementHandler.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <float> element.
|
||||
* This element specifies {@code float} values.
|
||||
* The class {@link Float} 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:<pre>
|
||||
* <float>-1.23</float></pre>
|
||||
* is shortcut to<pre>
|
||||
* <method name="valueOf" class="java.lang.Float">
|
||||
* <string>-1.23</string>
|
||||
* </method></pre>
|
||||
* which is equivalent to {@code Float.valueOf("-1.23")} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class FloatElementHandler extends StringElementHandler {
|
||||
|
||||
/**
|
||||
* Creates {@code float} value from
|
||||
* the text of the body of this element.
|
||||
*
|
||||
* @param argument the text of the body
|
||||
* @return evaluated {@code float} value
|
||||
*/
|
||||
@Override
|
||||
public Object getValue(String argument) {
|
||||
return Float.valueOf(argument);
|
||||
}
|
||||
}
|
||||
63
jdkSrc/jdk8/com/sun/beans/decoder/IntElementHandler.java
Normal file
63
jdkSrc/jdk8/com/sun/beans/decoder/IntElementHandler.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <int> element.
|
||||
* This element specifies {@code int} values.
|
||||
* The class {@link Integer} 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:<pre>
|
||||
* <int>-1</int></pre>
|
||||
* is shortcut to<pre>
|
||||
* <method name="decode" class="java.lang.Integer">
|
||||
* <string>-1</string>
|
||||
* </method></pre>
|
||||
* which is equivalent to {@code Integer.decode("-1")} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class IntElementHandler extends StringElementHandler {
|
||||
|
||||
/**
|
||||
* Creates {@code int} value from
|
||||
* the text of the body of this element.
|
||||
*
|
||||
* @param argument the text of the body
|
||||
* @return evaluated {@code int} value
|
||||
*/
|
||||
@Override
|
||||
public Object getValue(String argument) {
|
||||
return Integer.decode(argument);
|
||||
}
|
||||
}
|
||||
151
jdkSrc/jdk8/com/sun/beans/decoder/JavaElementHandler.java
Normal file
151
jdkSrc/jdk8/com/sun/beans/decoder/JavaElementHandler.java
Normal file
@@ -0,0 +1,151 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
import java.beans.XMLDecoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <java> element.
|
||||
* Each element that appears in the body of this element
|
||||
* is evaluated in the context of the decoder itself.
|
||||
* Typically this outer context is used to retrieve the owner of the decoder,
|
||||
* which can be set before reading the archive.
|
||||
* <p>The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>version
|
||||
* <dd>the Java version (not supported)
|
||||
* <dt>class
|
||||
* <dd>the type of preferable parser (not supported)
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @see DocumentHandler#getOwner
|
||||
* @see DocumentHandler#setOwner
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class JavaElementHandler extends ElementHandler {
|
||||
private Class<?> type;
|
||||
private ValueObject value;
|
||||
|
||||
/**
|
||||
* Parses attributes of the element.
|
||||
* The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>version
|
||||
* <dd>the Java version (not supported)
|
||||
* <dt>class
|
||||
* <dd>the type of preferable parser (not supported)
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @param name the attribute name
|
||||
* @param value the attribute value
|
||||
*/
|
||||
@Override
|
||||
public void addAttribute(String name, String value) {
|
||||
if (name.equals("version")) { // NON-NLS: the attribute name
|
||||
// unsupported attribute
|
||||
} else if (name.equals("class")) { // NON-NLS: the attribute name
|
||||
// check class for owner
|
||||
this.type = getOwner().findClass(value);
|
||||
} else {
|
||||
super.addAttribute(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the argument to the list of readed objects.
|
||||
*
|
||||
* @param argument the value of the element that contained in this one
|
||||
*/
|
||||
@Override
|
||||
protected void addArgument(Object argument) {
|
||||
getOwner().addObject(argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the value of this element can be used
|
||||
* as an argument of the element that contained in this one.
|
||||
*
|
||||
* @return {@code true} if the value of this element should be used
|
||||
* as an argument of the element that contained in this one,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
@Override
|
||||
protected boolean isArgument() {
|
||||
return false; // do not use owner as object
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this element.
|
||||
*
|
||||
* @return the value of this element
|
||||
*/
|
||||
@Override
|
||||
protected ValueObject getValueObject() {
|
||||
if (this.value == null) {
|
||||
this.value = ValueObjectImpl.create(getValue());
|
||||
}
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the owner of the owner document handler
|
||||
* as a value of <java> element.
|
||||
*
|
||||
* @return the owner of the owner document handler
|
||||
*/
|
||||
private Object getValue() {
|
||||
Object owner = getOwner().getOwner();
|
||||
if ((this.type == null) || isValid(owner)) {
|
||||
return owner;
|
||||
}
|
||||
if (owner instanceof XMLDecoder) {
|
||||
XMLDecoder decoder = (XMLDecoder) owner;
|
||||
owner = decoder.getOwner();
|
||||
if (isValid(owner)) {
|
||||
return owner;
|
||||
}
|
||||
}
|
||||
throw new IllegalStateException("Unexpected owner class: " + owner.getClass().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates the owner of the <java> element.
|
||||
* The owner is valid if it is {@code null} or an instance
|
||||
* of the class specified by the {@code class} attribute.
|
||||
*
|
||||
* @param owner the owner of the <java> element
|
||||
* @return {@code true} if the {@code owner} is valid;
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
private boolean isValid(Object owner) {
|
||||
return (owner == null) || this.type.isInstance(owner);
|
||||
}
|
||||
}
|
||||
63
jdkSrc/jdk8/com/sun/beans/decoder/LongElementHandler.java
Normal file
63
jdkSrc/jdk8/com/sun/beans/decoder/LongElementHandler.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <long> element.
|
||||
* This element specifies {@code long} values.
|
||||
* The class {@link Long} 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:<pre>
|
||||
* <long>0xFFFF</long></pre>
|
||||
* is shortcut to<pre>
|
||||
* <method name="decode" class="java.lang.Long">
|
||||
* <string>0xFFFF</string>
|
||||
* </method></pre>
|
||||
* which is equivalent to {@code Long.decode("0xFFFF")} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class LongElementHandler extends StringElementHandler {
|
||||
|
||||
/**
|
||||
* Creates {@code long} value from
|
||||
* the text of the body of this element.
|
||||
*
|
||||
* @param argument the text of the body
|
||||
* @return evaluated {@code long} value
|
||||
*/
|
||||
@Override
|
||||
public Object getValue(String argument) {
|
||||
return Long.decode(argument);
|
||||
}
|
||||
}
|
||||
111
jdkSrc/jdk8/com/sun/beans/decoder/MethodElementHandler.java
Normal file
111
jdkSrc/jdk8/com/sun/beans/decoder/MethodElementHandler.java
Normal file
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
import com.sun.beans.finder.MethodFinder;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import sun.reflect.misc.MethodUtil;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <method> element.
|
||||
* It describes invocation of the method.
|
||||
* The {@code name} attribute denotes
|
||||
* the name of the method to invoke.
|
||||
* If the {@code class} attribute is specified
|
||||
* this element invokes static method of specified class.
|
||||
* The inner elements specifies the arguments of the method.
|
||||
* For example:<pre>
|
||||
* <method name="valueOf" class="java.lang.Long">
|
||||
* <string>10</string>
|
||||
* </method></pre>
|
||||
* is equivalent to {@code Long.valueOf("10")} in Java code.
|
||||
* <p>The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>name
|
||||
* <dd>the method name
|
||||
* <dt>class
|
||||
* <dd>the type of object for instantiation
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class MethodElementHandler extends NewElementHandler {
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Parses attributes of the element.
|
||||
* The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>name
|
||||
* <dd>the method name
|
||||
* <dt>class
|
||||
* <dd>the type of object for instantiation
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of method execution.
|
||||
*
|
||||
* @param type the base class
|
||||
* @param args the array of arguments
|
||||
* @return the value of this element
|
||||
* @throws Exception if calculation is failed
|
||||
*/
|
||||
@Override
|
||||
protected ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
|
||||
Object bean = getContextBean();
|
||||
Class<?>[] types = getArgumentTypes(args);
|
||||
Method method = (type != null)
|
||||
? MethodFinder.findStaticMethod(type, this.name, types)
|
||||
: MethodFinder.findMethod(bean.getClass(), this.name, types);
|
||||
|
||||
if (method.isVarArgs()) {
|
||||
args = getArguments(args, method.getParameterTypes());
|
||||
}
|
||||
Object value = MethodUtil.invoke(method, bean, args);
|
||||
return method.getReturnType().equals(void.class)
|
||||
? ValueObjectImpl.VOID
|
||||
: ValueObjectImpl.create(value);
|
||||
}
|
||||
}
|
||||
205
jdkSrc/jdk8/com/sun/beans/decoder/NewElementHandler.java
Normal file
205
jdkSrc/jdk8/com/sun/beans/decoder/NewElementHandler.java
Normal file
@@ -0,0 +1,205 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
import com.sun.beans.finder.ConstructorFinder;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <new> element.
|
||||
* It describes instantiation of the object.
|
||||
* The {@code class} attribute denotes
|
||||
* the name of the class to instantiate.
|
||||
* The inner elements specifies the arguments of the constructor.
|
||||
* For example:<pre>
|
||||
* <new class="java.lang.Long">
|
||||
* <string>10</string>
|
||||
* </new></pre>
|
||||
* is equivalent to {@code new Long("10")} in Java code.
|
||||
* <p>The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>class
|
||||
* <dd>the type of object for instantiation
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
class NewElementHandler extends ElementHandler {
|
||||
private List<Object> arguments = new ArrayList<Object>();
|
||||
private ValueObject value = ValueObjectImpl.VOID;
|
||||
|
||||
private Class<?> type;
|
||||
|
||||
/**
|
||||
* Parses attributes of the element.
|
||||
* The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>class
|
||||
* <dd>the type of object for instantiation
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @param name the attribute name
|
||||
* @param value the attribute value
|
||||
*/
|
||||
@Override
|
||||
public void addAttribute(String name, String value) {
|
||||
if (name.equals("class")) { // NON-NLS: the attribute name
|
||||
this.type = getOwner().findClass(value);
|
||||
} else {
|
||||
super.addAttribute(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the argument to the list of arguments
|
||||
* that is used to calculate 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.arguments == null) {
|
||||
throw new IllegalStateException("Could not add argument to evaluated element");
|
||||
}
|
||||
this.arguments.add(argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the context of the method.
|
||||
* The context of the static method is the class object.
|
||||
* The context of the non-static method is the value of the parent element.
|
||||
*
|
||||
* @return the context of the method
|
||||
*/
|
||||
@Override
|
||||
protected final Object getContextBean() {
|
||||
return (this.type != null)
|
||||
? this.type
|
||||
: super.getContextBean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this element.
|
||||
*
|
||||
* @return the value of this element
|
||||
*/
|
||||
@Override
|
||||
protected final ValueObject getValueObject() {
|
||||
if (this.arguments != null) {
|
||||
try {
|
||||
this.value = getValueObject(this.type, this.arguments.toArray());
|
||||
}
|
||||
catch (Exception exception) {
|
||||
getOwner().handleException(exception);
|
||||
}
|
||||
finally {
|
||||
this.arguments = null;
|
||||
}
|
||||
}
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the value of this element
|
||||
* using the base class and the array of arguments.
|
||||
* By default, it creates an instance of the base class.
|
||||
* This method should be overridden in those handlers
|
||||
* that extend behavior of this element.
|
||||
*
|
||||
* @param type the base class
|
||||
* @param args the array of arguments
|
||||
* @return the value of this element
|
||||
* @throws Exception if calculation is failed
|
||||
*/
|
||||
ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
|
||||
if (type == null) {
|
||||
throw new IllegalArgumentException("Class name is not set");
|
||||
}
|
||||
Class<?>[] types = getArgumentTypes(args);
|
||||
Constructor<?> constructor = ConstructorFinder.findConstructor(type, types);
|
||||
if (constructor.isVarArgs()) {
|
||||
args = getArguments(args, constructor.getParameterTypes());
|
||||
}
|
||||
return ValueObjectImpl.create(constructor.newInstance(args));
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the array of arguments to the array of corresponding classes.
|
||||
* If argument is {@code null} the class is {@code null} too.
|
||||
*
|
||||
* @param arguments the array of arguments
|
||||
* @return the array of corresponding classes
|
||||
*/
|
||||
static Class<?>[] getArgumentTypes(Object[] arguments) {
|
||||
Class<?>[] types = new Class<?>[arguments.length];
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
if (arguments[i] != null) {
|
||||
types[i] = arguments[i].getClass();
|
||||
}
|
||||
}
|
||||
return types;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolves variable arguments.
|
||||
*
|
||||
* @param arguments the array of arguments
|
||||
* @param types the array of parameter types
|
||||
* @return the resolved array of arguments
|
||||
*/
|
||||
static Object[] getArguments(Object[] arguments, Class<?>[] types) {
|
||||
int index = types.length - 1;
|
||||
if (types.length == arguments.length) {
|
||||
Object argument = arguments[index];
|
||||
if (argument == null) {
|
||||
return arguments;
|
||||
}
|
||||
Class<?> type = types[index];
|
||||
if (type.isAssignableFrom(argument.getClass())) {
|
||||
return arguments;
|
||||
}
|
||||
}
|
||||
int length = arguments.length - index;
|
||||
Class<?> type = types[index].getComponentType();
|
||||
Object array = Array.newInstance(type, length);
|
||||
System.arraycopy(arguments, index, array, 0, length);
|
||||
|
||||
Object[] args = new Object[types.length];
|
||||
System.arraycopy(arguments, 0, args, 0, index);
|
||||
args[index] = array;
|
||||
return args;
|
||||
}
|
||||
}
|
||||
76
jdkSrc/jdk8/com/sun/beans/decoder/NullElementHandler.java
Normal file
76
jdkSrc/jdk8/com/sun/beans/decoder/NullElementHandler.java
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <null> element.
|
||||
* This element specifies {@code null} value.
|
||||
* It should not contain body or inner elements.
|
||||
* For example:<pre>
|
||||
* <null/></pre>
|
||||
* is equivalent to {@code null} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
class NullElementHandler extends ElementHandler implements ValueObject {
|
||||
|
||||
/**
|
||||
* Returns the value of this element.
|
||||
*
|
||||
* @return the value of this element
|
||||
*/
|
||||
@Override
|
||||
protected final ValueObject getValueObject() {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code null}
|
||||
* as a value of <null> element.
|
||||
* This method should be overridden in those handlers
|
||||
* that extend behavior of this element.
|
||||
*
|
||||
* @return {@code null} by default
|
||||
*/
|
||||
public Object getValue() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code void} state of this value object.
|
||||
*
|
||||
* @return {@code false} always
|
||||
*/
|
||||
public final boolean isVoid() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
168
jdkSrc/jdk8/com/sun/beans/decoder/ObjectElementHandler.java
Normal file
168
jdkSrc/jdk8/com/sun/beans/decoder/ObjectElementHandler.java
Normal file
@@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
import java.beans.Expression;
|
||||
|
||||
import static java.util.Locale.ENGLISH;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <object> element.
|
||||
* This element looks like <void> element,
|
||||
* but its value is always used as an argument for element
|
||||
* that contains this one.
|
||||
* <p>The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>class
|
||||
* <dd>the type is used for static methods and fields
|
||||
* <dt>method
|
||||
* <dd>the method name
|
||||
* <dt>property
|
||||
* <dd>the property name
|
||||
* <dt>index
|
||||
* <dd>the property index
|
||||
* <dt>field
|
||||
* <dd>the field name
|
||||
* <dt>idref
|
||||
* <dd>the identifier to refer to the variable
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
class ObjectElementHandler extends NewElementHandler {
|
||||
private String idref;
|
||||
private String field;
|
||||
private Integer index;
|
||||
private String property;
|
||||
private String method;
|
||||
|
||||
/**
|
||||
* Parses attributes of the element.
|
||||
* The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>class
|
||||
* <dd>the type is used for static methods and fields
|
||||
* <dt>method
|
||||
* <dd>the method name
|
||||
* <dt>property
|
||||
* <dd>the property name
|
||||
* <dt>index
|
||||
* <dd>the property index
|
||||
* <dt>field
|
||||
* <dd>the field name
|
||||
* <dt>idref
|
||||
* <dd>the identifier to refer to the variable
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @param name the attribute name
|
||||
* @param value the attribute value
|
||||
*/
|
||||
@Override
|
||||
public final void addAttribute(String name, String value) {
|
||||
if (name.equals("idref")) { // NON-NLS: the attribute name
|
||||
this.idref = value;
|
||||
} else if (name.equals("field")) { // NON-NLS: the attribute name
|
||||
this.field = value;
|
||||
} else if (name.equals("index")) { // NON-NLS: the attribute name
|
||||
this.index = Integer.valueOf(value);
|
||||
addArgument(this.index); // hack for compatibility
|
||||
} else if (name.equals("property")) { // NON-NLS: the attribute name
|
||||
this.property = value;
|
||||
} else if (name.equals("method")) { // NON-NLS: the attribute name
|
||||
this.method = value;
|
||||
} else {
|
||||
super.addAttribute(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the value of this element
|
||||
* if the field attribute or the idref attribute is set.
|
||||
*/
|
||||
@Override
|
||||
public final void startElement() {
|
||||
if ((this.field != null) || (this.idref != null)) {
|
||||
getValueObject();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the value of this element can be used
|
||||
* as an argument of the element that contained in this one.
|
||||
*
|
||||
* @return {@code true} if the value of this element can be used
|
||||
* as an argument of the element that contained in this one,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
@Override
|
||||
protected boolean isArgument() {
|
||||
return true; // hack for compatibility
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the value of this element.
|
||||
*
|
||||
* @param type the base class
|
||||
* @param args the array of arguments
|
||||
* @return the value of this element
|
||||
* @throws Exception if calculation is failed
|
||||
*/
|
||||
@Override
|
||||
protected final ValueObject getValueObject(Class<?> type, Object[] args) throws Exception {
|
||||
if (this.field != null) {
|
||||
return ValueObjectImpl.create(FieldElementHandler.getFieldValue(getContextBean(), this.field));
|
||||
}
|
||||
if (this.idref != null) {
|
||||
return ValueObjectImpl.create(getVariable(this.idref));
|
||||
}
|
||||
Object bean = getContextBean();
|
||||
String name;
|
||||
if (this.index != null) {
|
||||
name = (args.length == 2)
|
||||
? PropertyElementHandler.SETTER
|
||||
: PropertyElementHandler.GETTER;
|
||||
} else if (this.property != null) {
|
||||
name = (args.length == 1)
|
||||
? PropertyElementHandler.SETTER
|
||||
: PropertyElementHandler.GETTER;
|
||||
|
||||
if (0 < this.property.length()) {
|
||||
name += this.property.substring(0, 1).toUpperCase(ENGLISH) + this.property.substring(1);
|
||||
}
|
||||
} else {
|
||||
name = (this.method != null) && (0 < this.method.length())
|
||||
? this.method
|
||||
: "new"; // NON-NLS: the constructor marker
|
||||
}
|
||||
Expression expression = new Expression(bean, name, args);
|
||||
return ValueObjectImpl.create(expression.getValue());
|
||||
}
|
||||
}
|
||||
289
jdkSrc/jdk8/com/sun/beans/decoder/PropertyElementHandler.java
Normal file
289
jdkSrc/jdk8/com/sun/beans/decoder/PropertyElementHandler.java
Normal file
@@ -0,0 +1,289 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
import com.sun.beans.finder.MethodFinder;
|
||||
|
||||
import java.beans.IndexedPropertyDescriptor;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
import java.beans.PropertyDescriptor;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import sun.reflect.misc.MethodUtil;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <property> element.
|
||||
* This element simplifies access to the properties.
|
||||
* If the {@code index} attribute is specified
|
||||
* this element uses additional {@code int} parameter.
|
||||
* If the {@code name} attribute is not specified
|
||||
* this element uses method "get" as getter
|
||||
* and method "set" as setter.
|
||||
* This element defines getter if it contains no argument.
|
||||
* It returns the value of the property in this case.
|
||||
* For example:<pre>
|
||||
* <property name="object" index="10"/></pre>
|
||||
* is shortcut to<pre>
|
||||
* <method name="getObject">
|
||||
* <int>10</int>
|
||||
* </method></pre>
|
||||
* which is equivalent to {@code getObject(10)} in Java code.
|
||||
* This element defines setter if it contains one argument.
|
||||
* It does not return the value of the property in this case.
|
||||
* For example:<pre>
|
||||
* <property><int>0</int></property></pre>
|
||||
* is shortcut to<pre>
|
||||
* <method name="set">
|
||||
* <int>0</int>
|
||||
* </method></pre>
|
||||
* which is equivalent to {@code set(0)} in Java code.
|
||||
* <p>The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>name
|
||||
* <dd>the property name
|
||||
* <dt>index
|
||||
* <dd>the property index
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class PropertyElementHandler extends AccessorElementHandler {
|
||||
static final String GETTER = "get"; // NON-NLS: the getter prefix
|
||||
static final String SETTER = "set"; // NON-NLS: the setter prefix
|
||||
|
||||
private Integer index;
|
||||
|
||||
/**
|
||||
* Parses attributes of the element.
|
||||
* The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>name
|
||||
* <dd>the property name
|
||||
* <dt>index
|
||||
* <dd>the property index
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @param name the attribute name
|
||||
* @param value the attribute value
|
||||
*/
|
||||
@Override
|
||||
public void addAttribute(String name, String value) {
|
||||
if (name.equals("index")) { // NON-NLS: the attribute name
|
||||
this.index = Integer.valueOf(value);
|
||||
} else {
|
||||
super.addAttribute(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests whether the value of this element can be used
|
||||
* as an argument of the element that contained in this one.
|
||||
*
|
||||
* @return {@code true} if the value of this element should be used
|
||||
* as an argument of the element that contained in this one,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
@Override
|
||||
protected boolean isArgument() {
|
||||
return false; // non-static accessor cannot be used an argument
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the property with specified {@code name}.
|
||||
*
|
||||
* @param name the name of the property
|
||||
* @return the value of the specified property
|
||||
*/
|
||||
@Override
|
||||
protected Object getValue(String name) {
|
||||
try {
|
||||
return getPropertyValue(getContextBean(), name, this.index);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
getOwner().handleException(exception);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new value for the property with specified {@code name}.
|
||||
*
|
||||
* @param name the name of the property
|
||||
* @param value the new value for the specified property
|
||||
*/
|
||||
@Override
|
||||
protected void setValue(String name, Object value) {
|
||||
try {
|
||||
setPropertyValue(getContextBean(), name, this.index, value);
|
||||
}
|
||||
catch (Exception exception) {
|
||||
getOwner().handleException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the search of the getter for the property
|
||||
* with specified {@code name} in specified class
|
||||
* and returns value of the property.
|
||||
*
|
||||
* @param bean the context bean that contains property
|
||||
* @param name the name of the property
|
||||
* @param index the index of the indexed property
|
||||
* @return the value of the property
|
||||
* @throws IllegalAccessException if the property is not accesible
|
||||
* @throws IntrospectionException if the bean introspection is failed
|
||||
* @throws InvocationTargetException if the getter cannot be invoked
|
||||
* @throws NoSuchMethodException if the getter is not found
|
||||
*/
|
||||
private static Object getPropertyValue(Object bean, String name, Integer index) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException {
|
||||
Class<?> type = bean.getClass();
|
||||
if (index == null) {
|
||||
return MethodUtil.invoke(findGetter(type, name), bean, new Object[] {});
|
||||
} else if (type.isArray() && (name == null)) {
|
||||
return Array.get(bean, index);
|
||||
} else {
|
||||
return MethodUtil.invoke(findGetter(type, name, int.class), bean, new Object[] {index});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the search of the setter for the property
|
||||
* with specified {@code name} in specified class
|
||||
* and updates value of the property.
|
||||
*
|
||||
* @param bean the context bean that contains property
|
||||
* @param name the name of the property
|
||||
* @param index the index of the indexed property
|
||||
* @param value the new value for the property
|
||||
* @throws IllegalAccessException if the property is not accesible
|
||||
* @throws IntrospectionException if the bean introspection is failed
|
||||
* @throws InvocationTargetException if the setter cannot be invoked
|
||||
* @throws NoSuchMethodException if the setter is not found
|
||||
*/
|
||||
private static void setPropertyValue(Object bean, String name, Integer index, Object value) throws IllegalAccessException, IntrospectionException, InvocationTargetException, NoSuchMethodException {
|
||||
Class<?> type = bean.getClass();
|
||||
Class<?> param = (value != null)
|
||||
? value.getClass()
|
||||
: null;
|
||||
|
||||
if (index == null) {
|
||||
MethodUtil.invoke(findSetter(type, name, param), bean, new Object[] {value});
|
||||
} else if (type.isArray() && (name == null)) {
|
||||
Array.set(bean, index, value);
|
||||
} else {
|
||||
MethodUtil.invoke(findSetter(type, name, int.class, param), bean, new Object[] {index, value});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the search of the getter for the property
|
||||
* with specified {@code name} in specified class.
|
||||
*
|
||||
* @param type the class that contains method
|
||||
* @param name the name of the property
|
||||
* @param args the method arguments
|
||||
* @return method object that represents found getter
|
||||
* @throws IntrospectionException if the bean introspection is failed
|
||||
* @throws NoSuchMethodException if method is not found
|
||||
*/
|
||||
private static Method findGetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException {
|
||||
if (name == null) {
|
||||
return MethodFinder.findInstanceMethod(type, GETTER, args);
|
||||
}
|
||||
PropertyDescriptor pd = getProperty(type, name);
|
||||
if (args.length == 0) {
|
||||
Method method = pd.getReadMethod();
|
||||
if (method != null) {
|
||||
return method;
|
||||
}
|
||||
} else if (pd instanceof IndexedPropertyDescriptor) {
|
||||
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
|
||||
Method method = ipd.getIndexedReadMethod();
|
||||
if (method != null) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
throw new IntrospectionException("Could not find getter for the " + name + " property");
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the search of the setter for the property
|
||||
* with specified {@code name} in specified class.
|
||||
*
|
||||
* @param type the class that contains method
|
||||
* @param name the name of the property
|
||||
* @param args the method arguments
|
||||
* @return method object that represents found setter
|
||||
* @throws IntrospectionException if the bean introspection is failed
|
||||
* @throws NoSuchMethodException if method is not found
|
||||
*/
|
||||
private static Method findSetter(Class<?> type, String name, Class<?>...args) throws IntrospectionException, NoSuchMethodException {
|
||||
if (name == null) {
|
||||
return MethodFinder.findInstanceMethod(type, SETTER, args);
|
||||
}
|
||||
PropertyDescriptor pd = getProperty(type, name);
|
||||
if (args.length == 1) {
|
||||
Method method = pd.getWriteMethod();
|
||||
if (method != null) {
|
||||
return method;
|
||||
}
|
||||
} else if (pd instanceof IndexedPropertyDescriptor) {
|
||||
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
|
||||
Method method = ipd.getIndexedWriteMethod();
|
||||
if (method != null) {
|
||||
return method;
|
||||
}
|
||||
}
|
||||
throw new IntrospectionException("Could not find setter for the " + name + " property");
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs the search of the descriptor for the property
|
||||
* with specified {@code name} in specified class.
|
||||
*
|
||||
* @param type the class to introspect
|
||||
* @param name the property name
|
||||
* @return descriptor for the named property
|
||||
* @throws IntrospectionException if property descriptor is not found
|
||||
*/
|
||||
private static PropertyDescriptor getProperty(Class<?> type, String name) throws IntrospectionException {
|
||||
for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) {
|
||||
if (name.equals(pd.getName())) {
|
||||
return pd;
|
||||
}
|
||||
}
|
||||
throw new IntrospectionException("Could not find the " + name + " property descriptor");
|
||||
}
|
||||
}
|
||||
63
jdkSrc/jdk8/com/sun/beans/decoder/ShortElementHandler.java
Normal file
63
jdkSrc/jdk8/com/sun/beans/decoder/ShortElementHandler.java
Normal file
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <short> element.
|
||||
* This element specifies {@code short} values.
|
||||
* The class {@link Short} 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:<pre>
|
||||
* <short>200</short></pre>
|
||||
* is shortcut to<pre>
|
||||
* <method name="decode" class="java.lang.Short">
|
||||
* <string>200</string>
|
||||
* </method></pre>
|
||||
* which is equivalent to {@code Short.decode("200")} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class ShortElementHandler extends StringElementHandler {
|
||||
|
||||
/**
|
||||
* Creates {@code short} value from
|
||||
* the text of the body of this element.
|
||||
*
|
||||
* @param argument the text of the body
|
||||
* @return evaluated {@code short} value
|
||||
*/
|
||||
@Override
|
||||
public Object getValue(String argument) {
|
||||
return Short.decode(argument);
|
||||
}
|
||||
}
|
||||
116
jdkSrc/jdk8/com/sun/beans/decoder/StringElementHandler.java
Normal file
116
jdkSrc/jdk8/com/sun/beans/decoder/StringElementHandler.java
Normal file
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <string> element.
|
||||
* This element specifies {@link String} values.
|
||||
* The result value is created from text of the body of this element.
|
||||
* For example:<pre>
|
||||
* <string>description</string></pre>
|
||||
* is equivalent to {@code "description"} in Java code.
|
||||
* The value of inner element is calculated
|
||||
* before adding to the string using {@link String#valueOf(Object)}.
|
||||
* Note that all characters are used including whitespaces (' ', '\t', '\n', '\r').
|
||||
* So the value of the element<pre>
|
||||
* <string><true></string></pre>
|
||||
* is not equal to the value of the element<pre>
|
||||
* <string>
|
||||
* <true>
|
||||
* </string></pre>
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
public class StringElementHandler extends ElementHandler {
|
||||
private StringBuilder sb = new StringBuilder();
|
||||
private ValueObject value = ValueObjectImpl.NULL;
|
||||
|
||||
/**
|
||||
* Adds the character that contained in this element.
|
||||
*
|
||||
* @param ch the character
|
||||
*/
|
||||
@Override
|
||||
public final void addCharacter(char ch) {
|
||||
if (this.sb == null) {
|
||||
throw new IllegalStateException("Could not add chararcter to evaluated string element");
|
||||
}
|
||||
this.sb.append(ch);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the string value of the argument to the string 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.sb == null) {
|
||||
throw new IllegalStateException("Could not add argument to evaluated string element");
|
||||
}
|
||||
this.sb.append(argument);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this element.
|
||||
*
|
||||
* @return the value of this element
|
||||
*/
|
||||
@Override
|
||||
protected final ValueObject getValueObject() {
|
||||
if (this.sb != null) {
|
||||
try {
|
||||
this.value = ValueObjectImpl.create(getValue(this.sb.toString()));
|
||||
}
|
||||
catch (RuntimeException exception) {
|
||||
getOwner().handleException(exception);
|
||||
}
|
||||
finally {
|
||||
this.sb = null;
|
||||
}
|
||||
}
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the text of the body of this element.
|
||||
* This method evaluates value from text of the body,
|
||||
* and should be overridden in those handlers
|
||||
* that extend behavior of this element.
|
||||
*
|
||||
* @param argument the text of the body
|
||||
* @return evaluated value
|
||||
*/
|
||||
protected Object getValue(String argument) {
|
||||
return argument;
|
||||
}
|
||||
}
|
||||
56
jdkSrc/jdk8/com/sun/beans/decoder/TrueElementHandler.java
Normal file
56
jdkSrc/jdk8/com/sun/beans/decoder/TrueElementHandler.java
Normal file
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <true> element.
|
||||
* This element specifies {@code true} value.
|
||||
* It should not contain body or inner elements.
|
||||
* For example:<pre>
|
||||
* <true/></pre>
|
||||
* is equivalent to {@code true} in Java code.
|
||||
* <p>The following attribute is supported:
|
||||
* <dl>
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class TrueElementHandler extends NullElementHandler {
|
||||
|
||||
/**
|
||||
* Returns {@code Boolean.TRUE}
|
||||
* as a value of <true> element.
|
||||
*
|
||||
* @return {@code Boolean.TRUE} by default
|
||||
*/
|
||||
@Override
|
||||
public Object getValue() {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
}
|
||||
50
jdkSrc/jdk8/com/sun/beans/decoder/ValueObject.java
Normal file
50
jdkSrc/jdk8/com/sun/beans/decoder/ValueObject.java
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This interface represents the result of method execution.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
public interface ValueObject {
|
||||
|
||||
/**
|
||||
* Returns the result of method execution.
|
||||
*
|
||||
* @return the result of method execution
|
||||
*/
|
||||
Object getValue();
|
||||
|
||||
/**
|
||||
* Returns {@code void} state of this value object.
|
||||
*
|
||||
* @return {@code true} if value can be ignored,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
boolean isVoid();
|
||||
}
|
||||
88
jdkSrc/jdk8/com/sun/beans/decoder/ValueObjectImpl.java
Normal file
88
jdkSrc/jdk8/com/sun/beans/decoder/ValueObjectImpl.java
Normal file
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* Copyright (c) 2008, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This utility class provides {@code static} method
|
||||
* to create the object that contains the result of method execution.
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class ValueObjectImpl implements ValueObject {
|
||||
static final ValueObject NULL = new ValueObjectImpl(null);
|
||||
static final ValueObject VOID = new ValueObjectImpl();
|
||||
|
||||
/**
|
||||
* Returns the object that describes returning value.
|
||||
*
|
||||
* @param value the result of method execution
|
||||
* @return the object that describes value
|
||||
*/
|
||||
static ValueObject create(Object value) {
|
||||
return (value != null)
|
||||
? new ValueObjectImpl(value)
|
||||
: NULL;
|
||||
}
|
||||
|
||||
private Object value;
|
||||
private boolean isVoid;
|
||||
|
||||
/**
|
||||
* Creates the object that describes returning void value.
|
||||
*/
|
||||
private ValueObjectImpl() {
|
||||
this.isVoid = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the object that describes returning non-void value.
|
||||
*
|
||||
* @param value the result of method execution
|
||||
*/
|
||||
private ValueObjectImpl(Object value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the result of method execution.
|
||||
*
|
||||
* @return the result of method execution
|
||||
*/
|
||||
public Object getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@code void} state of this value object.
|
||||
*
|
||||
* @return {@code true} if value should be ignored,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
public boolean isVoid() {
|
||||
return this.isVoid;
|
||||
}
|
||||
}
|
||||
82
jdkSrc/jdk8/com/sun/beans/decoder/VarElementHandler.java
Normal file
82
jdkSrc/jdk8/com/sun/beans/decoder/VarElementHandler.java
Normal file
@@ -0,0 +1,82 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <var> element.
|
||||
* This element retrieves the value of specified variable.
|
||||
* For example:<pre>
|
||||
* <var id="id1" idref="id2"/></pre>
|
||||
* is equivalent to {@code id1 = id2} in Java code.
|
||||
* <p>The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>idref
|
||||
* <dd>the identifier to refer to the variable
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class VarElementHandler extends ElementHandler {
|
||||
private ValueObject value;
|
||||
|
||||
/**
|
||||
* Parses attributes of the element.
|
||||
* The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>idref
|
||||
* <dd>the identifier to refer to the variable
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @param name the attribute name
|
||||
* @param value the attribute value
|
||||
*/
|
||||
@Override
|
||||
public void addAttribute(String name, String value) {
|
||||
if (name.equals("idref")) { // NON-NLS: the attribute name
|
||||
this.value = ValueObjectImpl.create(getVariable(value));
|
||||
} else {
|
||||
super.addAttribute(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of this element.
|
||||
*
|
||||
* @return the value of this element
|
||||
*/
|
||||
@Override
|
||||
protected ValueObject getValueObject() {
|
||||
if (this.value == null) {
|
||||
throw new IllegalArgumentException("Variable name is not set");
|
||||
}
|
||||
return this.value;
|
||||
}
|
||||
}
|
||||
68
jdkSrc/jdk8/com/sun/beans/decoder/VoidElementHandler.java
Normal file
68
jdkSrc/jdk8/com/sun/beans/decoder/VoidElementHandler.java
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (c) 2008, 2013, Oracle and/or its affiliates. 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. Oracle designates this
|
||||
* particular file as subject to the "Classpath" exception as provided
|
||||
* by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
package com.sun.beans.decoder;
|
||||
|
||||
/**
|
||||
* This class is intended to handle <void> element.
|
||||
* This element looks like <object> element,
|
||||
* but its value is not used as an argument for element
|
||||
* that contains this one.
|
||||
* <p>The following attributes are supported:
|
||||
* <dl>
|
||||
* <dt>class
|
||||
* <dd>the type is used for static methods and fields
|
||||
* <dt>method
|
||||
* <dd>the method name
|
||||
* <dt>property
|
||||
* <dd>the property name
|
||||
* <dt>index
|
||||
* <dd>the property index
|
||||
* <dt>field
|
||||
* <dd>the field name
|
||||
* <dt>idref
|
||||
* <dd>the identifier to refer to the variable
|
||||
* <dt>id
|
||||
* <dd>the identifier of the variable that is intended to store the result
|
||||
* </dl>
|
||||
*
|
||||
* @since 1.7
|
||||
*
|
||||
* @author Sergey A. Malenkov
|
||||
*/
|
||||
final class VoidElementHandler extends ObjectElementHandler {
|
||||
|
||||
/**
|
||||
* Tests whether the value of this element can be used
|
||||
* as an argument of the element that contained in this one.
|
||||
*
|
||||
* @return {@code true} if the value of this element should be used
|
||||
* as an argument of the element that contained in this one,
|
||||
* {@code false} otherwise
|
||||
*/
|
||||
@Override
|
||||
protected boolean isArgument() {
|
||||
return false; // hack for compatibility
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user