You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by sm...@apache.org on 2013/10/05 01:45:53 UTC
svn commit: r1529349 [2/44] - in /pivot/trunk:
charts/src/org/apache/pivot/charts/
charts/src/org/apache/pivot/charts/skin/ core/src/org/apache/pivot/beans/
core/src/org/apache/pivot/collections/
core/src/org/apache/pivot/collections/adapter/ core/src/...
Modified: pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/beans/BXMLSerializer.java Fri Oct 4 23:45:40 2013
@@ -67,16 +67,9 @@ import org.apache.pivot.util.Vote;
* Loads an object hierarchy from an XML document.
*/
public class BXMLSerializer implements Serializer<Object>, Resolvable {
- private static class Element {
+ private static class Element {
public enum Type {
- INSTANCE,
- READ_ONLY_PROPERTY,
- WRITABLE_PROPERTY,
- LISTENER_LIST_PROPERTY,
- INCLUDE,
- SCRIPT,
- DEFINE,
- REFERENCE
+ INSTANCE, READ_ONLY_PROPERTY, WRITABLE_PROPERTY, LISTENER_LIST_PROPERTY, INCLUDE, SCRIPT, DEFINE, REFERENCE
}
public final Element parent;
@@ -126,8 +119,7 @@ public class BXMLSerializer implements S
}
@Override
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result = null;
String methodName = method.getName();
@@ -163,8 +155,7 @@ public class BXMLSerializer implements S
}
@Override
- public Object invoke(Object proxy, Method method, Object[] args)
- throws Throwable {
+ public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result = null;
String methodName = method.getName();
@@ -172,7 +163,7 @@ public class BXMLSerializer implements S
if (bindings.containsKey(methodName)) {
Invocable invocable;
try {
- invocable = (Invocable)scriptEngine;
+ invocable = (Invocable) scriptEngine;
} catch (ClassCastException exception) {
throw new SerializationException(exception);
}
@@ -210,7 +201,7 @@ public class BXMLSerializer implements S
if (bindings.containsKey(functionName)) {
Invocable invocable;
try {
- invocable = (Invocable)scriptEngine;
+ invocable = (Invocable) scriptEngine;
} catch (ClassCastException exception) {
throw new RuntimeException(exception);
}
@@ -223,7 +214,8 @@ public class BXMLSerializer implements S
throw new RuntimeException(exception);
}
} else {
- throw new RuntimeException("Mapping function \"" + functionName + "\" is not defined.");
+ throw new RuntimeException("Mapping function \"" + functionName
+ + "\" is not defined.");
}
return result;
@@ -247,8 +239,7 @@ public class BXMLSerializer implements S
private LinkedList<Attribute> namespaceBindingAttributes = new LinkedList<>();
private static HashMap<String, String> fileExtensions = new HashMap<>();
- private static HashMap<String, Class<? extends Serializer<?>>> mimeTypes =
- new HashMap<>();
+ private static HashMap<String, Class<? extends Serializer<?>>> mimeTypes = new HashMap<>();
public static final char URL_PREFIX = '@';
public static final char RESOURCE_KEY_PREFIX = '%';
@@ -296,7 +287,8 @@ public class BXMLSerializer implements S
fileExtensions.put(CSVSerializer.CSV_EXTENSION, CSVSerializer.MIME_TYPE);
fileExtensions.put(JSONSerializer.JSON_EXTENSION, JSONSerializer.MIME_TYPE);
- fileExtensions.put(PropertiesSerializer.PROPERTIES_EXTENSION, PropertiesSerializer.MIME_TYPE);
+ fileExtensions.put(PropertiesSerializer.PROPERTIES_EXTENSION,
+ PropertiesSerializer.MIME_TYPE);
}
public BXMLSerializer() {
@@ -394,25 +386,24 @@ public class BXMLSerializer implements S
/** DO NOT USE. see https://issues.apache.org/jira/browse/PIVOT-742 */
@Deprecated
- public BXMLSerializer(@SuppressWarnings("unused") final ClassLoader classLoader) {
+ public BXMLSerializer(@SuppressWarnings("unused")
+ final ClassLoader classLoader) {
throw new UnsupportedOperationException("https://issues.apache.org/jira/browse/PIVOT-742");
}
/**
- * Deserializes an object hierarchy from a BXML resource.
- * <p>
- * This is the base version of the method. It does not set the "location" or "resources"
- * properties. Callers that wish to use this version of the method to load BXML that uses
- * location or resource resolution must manually set these properties via a call to
- * {@link #setLocation(URL)} or {@link #setResources(Resources)}, respectively, before calling
- * this method.
- *
- * @return
- * The deserialized object hierarchy.
+ * Deserializes an object hierarchy from a BXML resource. <p> This is the
+ * base version of the method. It does not set the "location" or "resources"
+ * properties. Callers that wish to use this version of the method to load
+ * BXML that uses location or resource resolution must manually set these
+ * properties via a call to {@link #setLocation(URL)} or
+ * {@link #setResources(Resources)}, respectively, before calling this
+ * method.
+ *
+ * @return The deserialized object hierarchy.
*/
@Override
- public Object readObject(InputStream inputStream)
- throws IOException, SerializationException {
+ public Object readObject(InputStream inputStream) throws IOException, SerializationException {
if (inputStream == null) {
throw new IllegalArgumentException("inputStream is null.");
}
@@ -473,7 +464,7 @@ public class BXMLSerializer implements S
// Apply the namespace bindings
for (Attribute attribute : namespaceBindingAttributes) {
Element elementLocal = attribute.element;
- String sourcePath = (String)attribute.value;
+ String sourcePath = (String) attribute.value;
NamespaceBinding.BindMapping bindMapping;
int i = sourcePath.indexOf(BIND_MAPPING_DELIMITER);
@@ -482,7 +473,8 @@ public class BXMLSerializer implements S
} else {
String bindFunction = sourcePath.substring(0, i);
sourcePath = sourcePath.substring(i + 1);
- bindMapping = new ScriptBindMapping(scriptEngineManager.getEngineByName(language), bindFunction);
+ bindMapping = new ScriptBindMapping(scriptEngineManager.getEngineByName(language),
+ bindFunction);
}
switch (elementLocal.type) {
@@ -495,23 +487,25 @@ public class BXMLSerializer implements S
}
String targetPath = elementLocal.id + "." + attribute.name;
- NamespaceBinding namespaceBinding = new NamespaceBinding(namespace, sourcePath, targetPath,
- bindMapping);
+ NamespaceBinding namespaceBinding = new NamespaceBinding(namespace, sourcePath,
+ targetPath, bindMapping);
namespaceBinding.bind();
break;
}
case READ_ONLY_PROPERTY: {
- // Bind to <parent element ID>.<element name>.<attribute name>
+ // Bind to <parent element ID>.<element name>.<attribute
+ // name>
if (elementLocal.parent.id == null) {
elementLocal.parent.id = INTERNAL_ID_PREFIX + Integer.toString(nextID++);
namespace.put(elementLocal.parent.id, elementLocal.parent.value);
}
- String targetPath = elementLocal.parent.id + "." + elementLocal.name + "." + attribute.name;
- NamespaceBinding namespaceBinding = new NamespaceBinding(namespace, sourcePath, targetPath,
- bindMapping);
+ String targetPath = elementLocal.parent.id + "." + elementLocal.name + "."
+ + attribute.name;
+ NamespaceBinding namespaceBinding = new NamespaceBinding(namespace, sourcePath,
+ targetPath, bindMapping);
namespaceBinding.bind();
break;
@@ -533,7 +527,7 @@ public class BXMLSerializer implements S
type = type.getSuperclass();
}
- Bindable bindable = (Bindable)root;
+ Bindable bindable = (Bindable) root;
bindable.initialize(namespace, location, resources);
}
@@ -542,33 +536,27 @@ public class BXMLSerializer implements S
/**
* Deserializes an object hierarchy from a BXML resource.
- *
+ *
* @see #readObject(Class, String, boolean)
*/
- public final Object readObject(Class<?> baseType, String resourceName)
- throws IOException, SerializationException {
+ public final Object readObject(Class<?> baseType, String resourceName) throws IOException,
+ SerializationException {
return readObject(baseType, resourceName, false);
}
/**
- * Deserializes an object hierarchy from a BXML resource.
- * <p>
- * The location of the resource is determined by a call to
- * {@link Class#getResource(String)} on the given base type, passing the given
- * resource name as an argument. If the resources is localized, the base type
- * is also used as the base name of the resource bundle.
- *
- * @param baseType
- * The base type.
- *
- * @param resourceName
- * The name of the BXML resource.
- *
- * @param localize
- * If <tt>true</tt>, the deserialized resource will be localized using the resource
- * bundle specified by the base type. Otherwise, it will not be localized, and any
- * use of the resource resolution operator will result in a serialization exception.
- *
+ * Deserializes an object hierarchy from a BXML resource. <p> The location
+ * of the resource is determined by a call to
+ * {@link Class#getResource(String)} on the given base type, passing the
+ * given resource name as an argument. If the resources is localized, the
+ * base type is also used as the base name of the resource bundle.
+ *
+ * @param baseType The base type.
+ * @param resourceName The name of the BXML resource.
+ * @param localize If <tt>true</tt>, the deserialized resource will be
+ * localized using the resource bundle specified by the base type.
+ * Otherwise, it will not be localized, and any use of the resource
+ * resolution operator will result in a serialization exception.
* @see #readObject(URL, Resources)
*/
public final Object readObject(Class<?> baseType, String resourceName, boolean localize)
@@ -590,33 +578,25 @@ public class BXMLSerializer implements S
}
/**
- * Deserializes an object hierarchy from a BXML resource.
- * <p>
- * This version of the method does not set the "resources" property. Callers
- * that wish to use this version of the method to load BXML that uses resource
- * resolution must manually set this property via a call to
+ * Deserializes an object hierarchy from a BXML resource. <p> This version
+ * of the method does not set the "resources" property. Callers that wish to
+ * use this version of the method to load BXML that uses resource resolution
+ * must manually set this property via a call to
* {@link #setResources(Resources)} before calling this method.
- *
- * @param locationArgument
- * The location of the BXML resource.
- *
+ *
+ * @param locationArgument The location of the BXML resource.
* @see #readObject(URL, Resources)
*/
- public final Object readObject(URL locationArgument)
- throws IOException, SerializationException {
+ public final Object readObject(URL locationArgument) throws IOException, SerializationException {
return readObject(locationArgument, null);
}
/**
* Deserializes an object hierarchy from a BXML resource.
- *
- * @param locationArgument
- * The location of the BXML resource.
- *
- * @param resourcesArgument
- * The resources that will be used to localize the deserialized resource.
- *
- * #see readObject(InputStream)
+ *
+ * @param locationArgument The location of the BXML resource.
+ * @param resourcesArgument The resources that will be used to localize the
+ * deserialized resource. #see readObject(InputStream)
*/
public final Object readObject(URL locationArgument, Resources resourcesArgument)
throws IOException, SerializationException {
@@ -664,7 +644,7 @@ public class BXMLSerializer implements S
switch (element.type) {
case INSTANCE: {
if (element.value instanceof Sequence<?>) {
- Sequence<Object> sequence = (Sequence<Object>)element.value;
+ Sequence<Object> sequence = (Sequence<Object>) element.value;
try {
Method addMethod = sequence.getClass().getMethod("add", String.class);
@@ -690,8 +670,8 @@ public class BXMLSerializer implements S
}
default: {
- throw new SerializationException("Unexpected characters in "
- + element.type + " element.");
+ throw new SerializationException("Unexpected characters in " + element.type
+ + " element.");
}
}
}
@@ -712,8 +692,7 @@ public class BXMLSerializer implements S
// Some stream readers incorrectly report an empty string as the prefix
// for the default namespace
- if (prefix != null
- && prefix.length() == 0) {
+ if (prefix != null && prefix.length() == 0) {
prefix = null;
}
@@ -725,8 +704,7 @@ public class BXMLSerializer implements S
Class<?> propertyClass = null;
Object value = null;
- if (prefix != null
- && prefix.equals(BXML_PREFIX)) {
+ if (prefix != null && prefix.equals(BXML_PREFIX)) {
// The element represents a BXML operation
if (element == null) {
throw new SerializationException("Invalid root element.");
@@ -748,8 +726,7 @@ public class BXMLSerializer implements S
} else {
if (Character.isUpperCase(localName.charAt(0))) {
int i = localName.indexOf('.');
- if (i != -1
- && Character.isLowerCase(localName.charAt(i + 1))) {
+ if (i != -1 && Character.isLowerCase(localName.charAt(i + 1))) {
// The element represents an attached property
elementType = Element.Type.WRITABLE_PROPERTY;
name = localName.substring(i + 1);
@@ -782,7 +759,8 @@ public class BXMLSerializer implements S
} else {
// The element represents a property
if (prefix != null) {
- throw new SerializationException("Property elements cannot have a namespace prefix.");
+ throw new SerializationException(
+ "Property elements cannot have a namespace prefix.");
}
if (element.value instanceof Dictionary<?, ?>) {
@@ -794,8 +772,7 @@ public class BXMLSerializer implements S
Class<?> propertyType = beanAdapter.getType(localName);
if (propertyType == null) {
throw new SerializationException("\"" + localName
- + "\" is not a valid property of element "
- + element.name + ".");
+ + "\" is not a valid property of element " + element.name + ".");
}
if (ListenerList.class.isAssignableFrom(propertyType)) {
@@ -822,8 +799,7 @@ public class BXMLSerializer implements S
// Load the include
if (!element.properties.containsKey(INCLUDE_SRC_ATTRIBUTE)) {
throw new SerializationException(INCLUDE_SRC_ATTRIBUTE
- + " attribute is required for " + BXML_PREFIX + ":" + INCLUDE_TAG
- + " tag.");
+ + " attribute is required for " + BXML_PREFIX + ":" + INCLUDE_TAG + " tag.");
}
String src = element.properties.get(INCLUDE_SRC_ATTRIBUTE);
@@ -859,8 +835,8 @@ public class BXMLSerializer implements S
}
if (mimeType == null) {
- throw new SerializationException("Cannot determine MIME type of include \""
- + src + "\".");
+ throw new SerializationException("Cannot determine MIME type of include \"" + src
+ + "\".");
}
boolean inline = false;
@@ -895,7 +871,7 @@ public class BXMLSerializer implements S
// Set optional resolution properties
if (serializer instanceof Resolvable) {
- Resolvable resolvable = (Resolvable)serializer;
+ Resolvable resolvable = (Resolvable) serializer;
if (inline) {
resolvable.setNamespace(namespace);
}
@@ -915,8 +891,7 @@ public class BXMLSerializer implements S
// Dereference the value
if (!element.properties.containsKey(REFERENCE_ID_ATTRIBUTE)) {
throw new SerializationException(REFERENCE_ID_ATTRIBUTE
- + " attribute is required for " + BXML_PREFIX + ":" + REFERENCE_TAG
- + " tag.");
+ + " attribute is required for " + BXML_PREFIX + ":" + REFERENCE_TAG + " tag.");
}
String id = element.properties.get(REFERENCE_ID_ATTRIBUTE);
@@ -951,13 +926,12 @@ public class BXMLSerializer implements S
String localName = xmlStreamReader.getAttributeLocalName(i);
String value = xmlStreamReader.getAttributeValue(i);
- if (prefix != null
- && prefix.equals(BXML_PREFIX)) {
+ if (prefix != null && prefix.equals(BXML_PREFIX)) {
// The attribute represents an internal value
if (localName.equals(ID_ATTRIBUTE)) {
- if (value.length() == 0
- || value.contains(".")) {
- throw new IllegalArgumentException("\"" + value + "\" is not a valid ID value.");
+ if (value.length() == 0 || value.contains(".")) {
+ throw new IllegalArgumentException("\"" + value
+ + "\" is not a valid ID value.");
}
if (namespace.containsKey(value)) {
@@ -966,7 +940,8 @@ public class BXMLSerializer implements S
if (element.type != Element.Type.INSTANCE
&& element.type != Element.Type.INCLUDE) {
- throw new SerializationException("An ID cannot be assigned to this element.");
+ throw new SerializationException(
+ "An ID cannot be assigned to this element.");
}
element.id = value;
@@ -981,8 +956,7 @@ public class BXMLSerializer implements S
case INCLUDE: {
property = (localName.equals(INCLUDE_SRC_ATTRIBUTE)
|| localName.equals(INCLUDE_RESOURCES_ATTRIBUTE)
- || localName.equals(INCLUDE_MIME_TYPE_ATTRIBUTE)
- || localName.equals(INCLUDE_INLINE_ATTRIBUTE));
+ || localName.equals(INCLUDE_MIME_TYPE_ATTRIBUTE) || localName.equals(INCLUDE_INLINE_ATTRIBUTE));
break;
}
@@ -1008,7 +982,8 @@ public class BXMLSerializer implements S
Class<?> propertyClass = null;
if (Character.isUpperCase(localName.charAt(0))) {
- // The attribute represents a static property or listener list
+ // The attribute represents a static property or
+ // listener list
int j = localName.indexOf('.');
name = localName.substring(j + 1);
@@ -1032,7 +1007,8 @@ public class BXMLSerializer implements S
&& value.endsWith(NAMESPACE_BINDING_SUFFIX)) {
// The attribute represents a namespace binding
if (propertyClass != null) {
- throw new SerializationException("Namespace binding is not supported for static properties.");
+ throw new SerializationException(
+ "Namespace binding is not supported for static properties.");
}
namespaceBindingAttributes.add(new Attribute(element, name, propertyClass,
@@ -1050,7 +1026,8 @@ public class BXMLSerializer implements S
attribute.value = value;
} else {
if (location == null) {
- throw new IllegalStateException("Base location is undefined.");
+ throw new IllegalStateException(
+ "Base location is undefined.");
}
try {
@@ -1060,7 +1037,8 @@ public class BXMLSerializer implements S
}
}
} else {
- throw new SerializationException("Invalid URL resolution argument.");
+ throw new SerializationException(
+ "Invalid URL resolution argument.");
}
} else if (value.charAt(0) == RESOURCE_KEY_PREFIX) {
value = value.substring(1);
@@ -1069,15 +1047,15 @@ public class BXMLSerializer implements S
if (value.charAt(0) == RESOURCE_KEY_PREFIX) {
attribute.value = value;
} else {
- if (resources != null
- && JSON.containsKey(resources, value)) {
+ if (resources != null && JSON.containsKey(resources, value)) {
attribute.value = JSON.get(resources, value);
} else {
attribute.value = value;
}
}
} else {
- throw new SerializationException("Invalid resource resolution argument.");
+ throw new SerializationException(
+ "Invalid resource resolution argument.");
}
} else if (value.charAt(0) == OBJECT_REFERENCE_PREFIX) {
value = value.substring(1);
@@ -1090,14 +1068,16 @@ public class BXMLSerializer implements S
attribute.value = null;
} else {
if (!JSON.containsKey(namespace, value)) {
- throw new SerializationException("Value \"" + value + "\" is not defined.");
+ throw new SerializationException("Value \"" + value
+ + "\" is not defined.");
}
attribute.value = JSON.get(namespace, value);
}
}
} else {
- throw new SerializationException("Invalid object resolution argument.");
+ throw new SerializationException(
+ "Invalid object resolution argument.");
}
}
}
@@ -1123,7 +1103,7 @@ public class BXMLSerializer implements S
if (attribute.propertyClass == null) {
Dictionary<String, Object> dictionary;
if (element.value instanceof Dictionary<?, ?>) {
- dictionary = (Dictionary<String, Object>)element.value;
+ dictionary = (Dictionary<String, Object>) element.value;
} else {
dictionary = new BeanAdapter(element.value);
}
@@ -1158,12 +1138,11 @@ public class BXMLSerializer implements S
// Create an invocation handler for this listener
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
- AttributeInvocationHandler handler =
- new AttributeInvocationHandler(scriptEngine, attribute.name,
- (String)attribute.value);
+ AttributeInvocationHandler handler = new AttributeInvocationHandler(
+ scriptEngine, attribute.name, (String) attribute.value);
Object listener = Proxy.newProxyInstance(classLoader,
- new Class<?>[]{attribute.propertyClass}, handler);
+ new Class<?>[] { attribute.propertyClass }, handler);
// Add the listener
Class<?> listenerListClass = listenerList.getClass();
@@ -1191,18 +1170,20 @@ public class BXMLSerializer implements S
if (element.parent != null) {
if (element.parent.type == Element.Type.WRITABLE_PROPERTY) {
- // Set this as the property value; it will be applied later in the
+ // Set this as the property value; it will be applied
+ // later in the
// parent's closing tag
element.parent.value = element.value;
} else if (element.parent.value != null) {
- // If the parent element has a default property, use it; otherwise, if the
+ // If the parent element has a default property, use it;
+ // otherwise, if the
// parent is a sequence, add the element to it
Class<?> parentType = element.parent.value.getClass();
DefaultProperty defaultProperty = parentType.getAnnotation(DefaultProperty.class);
if (defaultProperty == null) {
if (element.parent.value instanceof Sequence<?>) {
- Sequence<Object> sequence = (Sequence<Object>)element.parent.value;
+ Sequence<Object> sequence = (Sequence<Object>) element.parent.value;
sequence.add(element.value);
} else {
throw new SerializationException(element.parent.value.getClass()
@@ -1214,7 +1195,7 @@ public class BXMLSerializer implements S
Object defaultPropertyValue = beanAdapter.get(defaultPropertyName);
if (defaultPropertyValue instanceof Sequence<?>) {
- Sequence<Object> sequence = (Sequence<Object>)defaultPropertyValue;
+ Sequence<Object> sequence = (Sequence<Object>) defaultPropertyValue;
try {
sequence.add(element.value);
} catch (UnsupportedOperationException uoe) {
@@ -1233,7 +1214,7 @@ public class BXMLSerializer implements S
case READ_ONLY_PROPERTY: {
Dictionary<String, Object> dictionary;
if (element.value instanceof Dictionary<?, ?>) {
- dictionary = (Dictionary<String, Object>)element.value;
+ dictionary = (Dictionary<String, Object>) element.value;
} else {
dictionary = new BeanAdapter(element.value);
}
@@ -1255,7 +1236,7 @@ public class BXMLSerializer implements S
if (element.propertyClass == null) {
Dictionary<String, Object> dictionary;
if (element.parent.value instanceof Dictionary) {
- dictionary = (Dictionary<String, Object>)element.parent.value;
+ dictionary = (Dictionary<String, Object>) element.parent.value;
} else {
dictionary = new BeanAdapter(element.parent.value);
}
@@ -1270,8 +1251,8 @@ public class BXMLSerializer implements S
throw new SerializationException("Parent value is null.");
}
- setStaticProperty(element.parent.value, element.propertyClass,
- element.name, element.value);
+ setStaticProperty(element.parent.value, element.propertyClass, element.name,
+ element.value);
}
break;
@@ -1279,13 +1260,15 @@ public class BXMLSerializer implements S
case LISTENER_LIST_PROPERTY: {
// Evaluate the script
- String script = (String)element.value;
+ String script = (String) element.value;
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
if (scriptEngine == null) {
- throw new SerializationException("Script engine for \"" + language + "\" not found.");
+ throw new SerializationException("Script engine for \"" + language
+ + "\" not found.");
}
- // Don't pollute the engine namespace with the listener functions
+ // Don't pollute the engine namespace with the listener
+ // functions
scriptEngine.setBindings(new SimpleBindings(), ScriptContext.ENGINE_SCOPE);
try {
@@ -1297,11 +1280,11 @@ public class BXMLSerializer implements S
// Create the listener and add it to the list
BeanAdapter beanAdapter = new BeanAdapter(element.parent.value);
- ListenerList<?> listenerList = (ListenerList<?>)beanAdapter.get(element.name);
+ ListenerList<?> listenerList = (ListenerList<?>) beanAdapter.get(element.name);
Class<?> listenerListClass = listenerList.getClass();
java.lang.reflect.Type[] genericInterfaces = listenerListClass.getGenericInterfaces();
- Class<?> listenerClass = (Class<?>)genericInterfaces[0];
+ Class<?> listenerClass = (Class<?>) genericInterfaces[0];
ElementInvocationHandler handler = new ElementInvocationHandler(scriptEngine);
@@ -1313,7 +1296,7 @@ public class BXMLSerializer implements S
}
Object listener = Proxy.newProxyInstance(classLoader,
- new Class<?>[]{listenerClass}, handler);
+ new Class<?>[] { listenerClass }, handler);
try {
addMethod.invoke(listenerList, listener);
@@ -1335,8 +1318,8 @@ public class BXMLSerializer implements S
if (src != null) {
int i = src.lastIndexOf(".");
if (i == -1) {
- throw new SerializationException("Cannot determine type of script \""
- + src + "\".");
+ throw new SerializationException("Cannot determine type of script \"" + src
+ + "\".");
}
String extension = src.substring(i + 1);
@@ -1347,7 +1330,8 @@ public class BXMLSerializer implements S
+ " extension " + extension + ".");
}
- scriptEngine.setBindings(scriptEngineManager.getBindings(), ScriptContext.ENGINE_SCOPE);
+ scriptEngine.setBindings(scriptEngineManager.getBindings(),
+ ScriptContext.ENGINE_SCOPE);
try {
URL scriptLocation;
@@ -1359,9 +1343,10 @@ public class BXMLSerializer implements S
BufferedReader scriptReader = null;
try {
- scriptReader = new BufferedReader(new InputStreamReader(scriptLocation.openStream()));
+ scriptReader = new BufferedReader(new InputStreamReader(
+ scriptLocation.openStream()));
scriptEngine.eval(scriptReader);
- } catch(ScriptException exception) {
+ } catch (ScriptException exception) {
exception.printStackTrace();
} finally {
if (scriptReader != null) {
@@ -1375,7 +1360,7 @@ public class BXMLSerializer implements S
if (element.value != null) {
// Evaluate the script
- String script = (String)element.value;
+ String script = (String) element.value;
ScriptEngine scriptEngine = scriptEngineManager.getEngineByName(language);
if (scriptEngine == null) {
@@ -1383,7 +1368,8 @@ public class BXMLSerializer implements S
+ " language \"" + language + "\".");
}
- scriptEngine.setBindings(scriptEngineManager.getBindings(), ScriptContext.ENGINE_SCOPE);
+ scriptEngine.setBindings(scriptEngineManager.getBindings(),
+ ScriptContext.ENGINE_SCOPE);
try {
scriptEngine.eval(script);
@@ -1415,9 +1401,10 @@ public class BXMLSerializer implements S
}
/**
- * Return the current location of the XML parser. Useful to ascertain the
- * location where an error occurred (if the error was not an XMLStreamException,
- * which has its own {@link XMLStreamException#getLocation} method).
+ * Return the current location of the XML parser. Useful to ascertain the
+ * location where an error occurred (if the error was not an
+ * XMLStreamException, which has its own
+ * {@link XMLStreamException#getLocation} method).
*/
public Location getCurrentLocation() {
return xmlStreamReader.getLocation();
@@ -1450,10 +1437,9 @@ public class BXMLSerializer implements S
/**
* Retrieves the root of the object hierarchy most recently processed by
* this serializer.
- *
- * @return
- * The root object, or <tt>null</tt> if this serializer has not yet read an
- * object from an input stream.
+ *
+ * @return The root object, or <tt>null</tt> if this serializer has not yet
+ * read an object from an input stream.
*/
public Object getRoot() {
return root;
@@ -1495,9 +1481,8 @@ public class BXMLSerializer implements S
/**
* Applies BXML binding annotations to an object.
- *
+ *
* @param object
- *
* @see #bind(Object, Class)
*/
public void bind(Object object) {
@@ -1509,16 +1494,13 @@ public class BXMLSerializer implements S
}
/**
- * Applies BXML binding annotations to an object.
- * <p>
- * NOTE This method uses reflection to set internal member variables. As
- * a result, it may only be called from trusted code.
- *
+ * Applies BXML binding annotations to an object. <p> NOTE This method uses
+ * reflection to set internal member variables. As a result, it may only be
+ * called from trusted code.
+ *
* @param object
* @param type
- *
- * @throws BindException
- * If an error occurs during binding
+ * @throws BindException If an error occurs during binding
*/
public void bind(Object object, Class<?> type) throws BindException {
if (object == null) {
@@ -1576,9 +1558,8 @@ public class BXMLSerializer implements S
* implementation simply calls {@code Class.newInstance()}. Subclasses may
* override this method to provide an alternate instantiation mechanism,
* such as dependency-injected construction.
- *
- * @param type
- * The type of serializer being requested.
+ *
+ * @param type The type of serializer being requested.
*/
protected Serializer<?> newIncludeSerializer(Class<? extends Serializer<?>> type)
throws InstantiationException, IllegalAccessException {
@@ -1586,16 +1567,15 @@ public class BXMLSerializer implements S
}
/**
- * Creates a new typed object as part of the deserialization process.
- * The base implementation simply calls {@code Class.newInstance()}.
- * Subclasses may override this method to provide an alternate instantiation
- * mechanism, such as dependency-injected construction.
- *
- * @param type
- * The type of object being requested.
+ * Creates a new typed object as part of the deserialization process. The
+ * base implementation simply calls {@code Class.newInstance()}. Subclasses
+ * may override this method to provide an alternate instantiation mechanism,
+ * such as dependency-injected construction.
+ *
+ * @param type The type of object being requested.
*/
- protected Object newTypedObject(Class<?> type)
- throws InstantiationException, IllegalAccessException {
+ protected Object newTypedObject(Class<?> type) throws InstantiationException,
+ IllegalAccessException {
return type.newInstance();
}
@@ -1625,9 +1605,9 @@ public class BXMLSerializer implements S
/**
* Returns the file extension/MIME type map. This map associates file
- * extensions with MIME types, which are used to automatically determine
- * an appropriate serializer to use for an include based on file extension.
- *
+ * extensions with MIME types, which are used to automatically determine an
+ * appropriate serializer to use for an include based on file extension.
+ *
* @see #getMimeTypes()
*/
public static Map<String, String> getFileExtensions() {
@@ -1635,9 +1615,10 @@ public class BXMLSerializer implements S
}
/**
- * Returns the MIME type/serializer class map. This map associates MIME types
- * with serializer classes. The serializer for a given MIME type will be used
- * to deserialize the data for an include that references the MIME type.
+ * Returns the MIME type/serializer class map. This map associates MIME
+ * types with serializer classes. The serializer for a given MIME type will
+ * be used to deserialize the data for an include that references the MIME
+ * type.
*/
public static Map<String, Class<? extends Serializer<?>>> getMimeTypes() {
return mimeTypes;
@@ -1649,16 +1630,15 @@ public class BXMLSerializer implements S
if (objectType != null) {
try {
- method = propertyClass.getMethod(BeanAdapter.GET_PREFIX
- + propertyName, objectType);
+ method = propertyClass.getMethod(BeanAdapter.GET_PREFIX + propertyName, objectType);
} catch (NoSuchMethodException exception) {
// No-op
}
if (method == null) {
try {
- method = propertyClass.getMethod(BeanAdapter.IS_PREFIX
- + propertyName, objectType);
+ method = propertyClass.getMethod(BeanAdapter.IS_PREFIX + propertyName,
+ objectType);
} catch (NoSuchMethodException exception) {
// No-op
}
@@ -1691,11 +1671,11 @@ public class BXMLSerializer implements S
// signature with the corresponding primitive type
try {
Field primitiveTypeField = propertyValueType.getField("TYPE");
- Class<?> primitivePropertyValueType = (Class<?>)primitiveTypeField.get(null);
+ Class<?> primitivePropertyValueType = (Class<?>) primitiveTypeField.get(null);
try {
- method = propertyClass.getMethod(methodName,
- objectType, primitivePropertyValueType);
+ method = propertyClass.getMethod(methodName, objectType,
+ primitivePropertyValueType);
} catch (NoSuchMethodException exception) {
// No-op
}
@@ -1716,21 +1696,21 @@ public class BXMLSerializer implements S
}
private static void setStaticProperty(Object object, Class<?> propertyClass,
- final String propertyName, final Object value)
- throws SerializationException {
+ final String propertyName, final Object value) throws SerializationException {
Class<?> objectType = object.getClass();
- String propertyNameUpdated =
- Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1);
+ String propertyNameUpdated = Character.toUpperCase(propertyName.charAt(0))
+ + propertyName.substring(1);
Object valueToAssign = value;
Method setterMethod = null;
if (valueToAssign != null) {
- setterMethod = getStaticSetterMethod(propertyClass, propertyNameUpdated,
- objectType, valueToAssign.getClass());
+ setterMethod = getStaticSetterMethod(propertyClass, propertyNameUpdated, objectType,
+ valueToAssign.getClass());
}
if (setterMethod == null) {
- Method getterMethod = getStaticGetterMethod(propertyClass, propertyNameUpdated, objectType);
+ Method getterMethod = getStaticGetterMethod(propertyClass, propertyNameUpdated,
+ objectType);
if (getterMethod != null) {
Class<?> propertyType = getterMethod.getReturnType();
@@ -1738,16 +1718,14 @@ public class BXMLSerializer implements S
objectType, propertyType);
if (valueToAssign instanceof String) {
- valueToAssign = BeanAdapter.coerce((String)valueToAssign, propertyType);
+ valueToAssign = BeanAdapter.coerce((String) valueToAssign, propertyType);
}
}
}
if (setterMethod == null) {
- throw new SerializationException(propertyClass.getName()
- + "." + propertyNameUpdated
- + " is not valid static property."
- );
+ throw new SerializationException(propertyClass.getName() + "." + propertyNameUpdated
+ + " is not valid static property.");
}
// Invoke the setter
Modified: pivot/trunk/core/src/org/apache/pivot/beans/BeanAdapter.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/beans/BeanAdapter.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/beans/BeanAdapter.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/beans/BeanAdapter.java Fri Oct 4 23:45:40 2013
@@ -34,24 +34,18 @@ import org.apache.pivot.collections.MapL
import org.apache.pivot.util.ListenerList;
/**
- * Exposes Java bean properties of an object via the {@link Map}
- * interface. A call to {@link Map#get(Object)} invokes the getter for
- * the corresponding property, and a call to
- * {@link Map#put(Object, Object)} invokes the property's setter.
- * <p>
- * Properties may provide multiple setters; the appropriate setter to invoke
- * is determined by the type of the value being set. If the value is
- * <tt>null</tt>, the return type of the getter method is used.
- *
- * <p> Getter methods must be named "getProperty" where "property" is
- * the property name. If there is no "get" method, then an "isProperty"
- * method can also be used. Setter methods (if present) must be named
- * "setProperty".
- *
- * <p> Getter and setter methods are checked before straight fields
- * named "property" in order to support proper data encapsulation.
- * And only <code>public</code> and non-<code>static</code> methods
- * and fields can be accessed.
+ * Exposes Java bean properties of an object via the {@link Map} interface. A
+ * call to {@link Map#get(Object)} invokes the getter for the corresponding
+ * property, and a call to {@link Map#put(Object, Object)} invokes the
+ * property's setter. <p> Properties may provide multiple setters; the
+ * appropriate setter to invoke is determined by the type of the value being
+ * set. If the value is <tt>null</tt>, the return type of the getter method is
+ * used. <p> Getter methods must be named "getProperty" where "property" is the
+ * property name. If there is no "get" method, then an "isProperty" method can
+ * also be used. Setter methods (if present) must be named "setProperty". <p>
+ * Getter and setter methods are checked before straight fields named "property"
+ * in order to support proper data encapsulation. And only <code>public</code>
+ * and non-<code>static</code> methods and fields can be accessed.
*/
public class BeanAdapter implements Map<String, Object> {
/**
@@ -93,8 +87,7 @@ public class BeanAdapter implements Map<
private void nextProperty() {
nextProperty = null;
- while (i < methods.length
- && nextProperty == null) {
+ while (i < methods.length && nextProperty == null) {
Method method = methods[i++];
if (method.getParameterTypes().length == 0
@@ -120,8 +113,7 @@ public class BeanAdapter implements Map<
}
}
- if (nextProperty != null
- && ignoreReadOnlyProperties
+ if (nextProperty != null && ignoreReadOnlyProperties
&& isReadOnly(nextProperty)) {
nextProperty = null;
}
@@ -129,18 +121,15 @@ public class BeanAdapter implements Map<
}
if (nextProperty == null) {
- while (j < fields.length
- && nextProperty == null) {
+ while (j < fields.length && nextProperty == null) {
Field field = fields[j++];
int modifiers = field.getModifiers();
- if ((modifiers & Modifier.PUBLIC) != 0
- && (modifiers & Modifier.STATIC) == 0) {
+ if ((modifiers & Modifier.PUBLIC) != 0 && (modifiers & Modifier.STATIC) == 0) {
nextProperty = field.getName();
}
- if (nextProperty != null
- && ignoreReadOnlyProperties
+ if (nextProperty != null && ignoreReadOnlyProperties
&& (modifiers & Modifier.FINAL) != 0) {
nextProperty = null;
}
@@ -165,29 +154,24 @@ public class BeanAdapter implements Map<
private static final String ENUM_VALUE_OF_METHOD_NAME = "valueOf";
- private static final String ILLEGAL_ACCESS_EXCEPTION_MESSAGE_FORMAT =
- "Unable to access property \"%s\" for type %s.";
- private static final String ENUM_COERCION_EXECPTION_MESSAGE =
- "Unable to coerce %s (\"%s\") to %s.\nValid enum constants - %s";
+ private static final String ILLEGAL_ACCESS_EXCEPTION_MESSAGE_FORMAT = "Unable to access property \"%s\" for type %s.";
+ private static final String ENUM_COERCION_EXECPTION_MESSAGE = "Unable to coerce %s (\"%s\") to %s.\nValid enum constants - %s";
/**
* Creates a new bean dictionary.
- *
- * @param bean
- * The bean object to wrap.
+ *
+ * @param bean The bean object to wrap.
*/
public BeanAdapter(Object bean) {
this(bean, false);
}
/**
- * Creates a new bean dictionary which can ignore readonly fields
- * (that is, straight fields marked as <code>final</code> or bean
- * properties where there is a "get" method but no corresponding
- * "set" method).
- *
- * @param bean
- * The bean object to wrap.
+ * Creates a new bean dictionary which can ignore readonly fields (that is,
+ * straight fields marked as <code>final</code> or bean properties where
+ * there is a "get" method but no corresponding "set" method).
+ *
+ * @param bean The bean object to wrap.
*/
public BeanAdapter(Object bean, boolean ignoreReadOnlyProperties) {
if (bean == null) {
@@ -200,9 +184,8 @@ public class BeanAdapter implements Map<
/**
* Returns the bean object this dictionary wraps.
- *
- * @return
- * The bean object, or <tt>null</tt> if no bean has been set.
+ *
+ * @return The bean object, or <tt>null</tt> if no bean has been set.
*/
public Object getBean() {
return bean;
@@ -210,13 +193,10 @@ public class BeanAdapter implements Map<
/**
* Invokes the getter method for the given property.
- *
- * @param key
- * The property name.
- *
- * @return
- * The value returned by the method, or <tt>null</tt> if no such method
- * exists.
+ *
+ * @param key The property name.
+ * @return The value returned by the method, or <tt>null</tt> if no such
+ * method exists.
*/
@Override
public Object get(String key) {
@@ -239,8 +219,9 @@ public class BeanAdapter implements Map<
try {
value = field.get(bean);
} catch (IllegalAccessException exception) {
- throw new RuntimeException(String.format(ILLEGAL_ACCESS_EXCEPTION_MESSAGE_FORMAT,
- key, bean.getClass().getName()), exception);
+ throw new RuntimeException(String.format(
+ ILLEGAL_ACCESS_EXCEPTION_MESSAGE_FORMAT, key, bean.getClass().getName()),
+ exception);
}
}
} else {
@@ -250,8 +231,9 @@ public class BeanAdapter implements Map<
throw new RuntimeException(String.format(ILLEGAL_ACCESS_EXCEPTION_MESSAGE_FORMAT,
key, bean.getClass().getName()), exception);
} catch (InvocationTargetException exception) {
- throw new RuntimeException(String.format("Error getting property \"%s\" for type %s.",
- key, bean.getClass().getName()), exception.getCause());
+ throw new RuntimeException(String.format(
+ "Error getting property \"%s\" for type %s.", key, bean.getClass().getName()),
+ exception.getCause());
}
}
@@ -259,22 +241,17 @@ public class BeanAdapter implements Map<
}
/**
- * Invokes the setter method for the given property. The method
- * signature is determined by the type of the value. If the value is
- * <tt>null</tt>, the return type of the getter method is used.
- *
- * @param key
- * The property name.
- *
- * @param value
- * The new property value.
- *
- * @return
- * Returns <tt>null</tt>, since returning the previous value would require
- * a call to the getter method, which may not be an efficient operation.
- *
- * @throws PropertyNotFoundException
- * If the given property does not exist or is read-only.
+ * Invokes the setter method for the given property. The method signature is
+ * determined by the type of the value. If the value is <tt>null</tt>, the
+ * return type of the getter method is used.
+ *
+ * @param key The property name.
+ * @param value The new property value.
+ * @return Returns <tt>null</tt>, since returning the previous value would
+ * require a call to the getter method, which may not be an efficient
+ * operation.
+ * @throws PropertyNotFoundException If the given property does not exist or
+ * is read-only.
*/
@Override
public Object put(final String key, final Object value) {
@@ -328,13 +305,14 @@ public class BeanAdapter implements Map<
}
} else {
try {
- setterMethod.invoke(bean, new Object[] {valueUpdated});
+ setterMethod.invoke(bean, new Object[] { valueUpdated });
} catch (IllegalAccessException exception) {
throw new RuntimeException(String.format(ILLEGAL_ACCESS_EXCEPTION_MESSAGE_FORMAT,
key, bean.getClass().getName()), exception);
} catch (InvocationTargetException exception) {
- throw new RuntimeException(String.format("Error setting property \"%s\" for type %s to value \"%s\"",
- key, bean.getClass().getName(), "" + valueUpdated), exception.getCause());
+ throw new RuntimeException(String.format(
+ "Error setting property \"%s\" for type %s to value \"%s\"", key,
+ bean.getClass().getName(), "" + valueUpdated), exception.getCause());
}
}
@@ -346,16 +324,14 @@ public class BeanAdapter implements Map<
}
/**
- * Invokes the setter methods for all the given properties that are
- * present in the map. The method signatures are determined by the
- * type of the values. If any value is <tt>null</tt>, the return
- * type of the getter method is used.
- *
- * @param valueMap
- * The map of keys and values to be set.
- *
- * @throws PropertyNotFoundException
- * If any of the given properties do not exist or are read-only.
+ * Invokes the setter methods for all the given properties that are present
+ * in the map. The method signatures are determined by the type of the
+ * values. If any value is <tt>null</tt>, the return type of the getter
+ * method is used.
+ *
+ * @param valueMap The map of keys and values to be set.
+ * @throws PropertyNotFoundException If any of the given properties do not
+ * exist or are read-only.
*/
public void putAll(Map<String, ?> valueMap) {
for (String key : valueMap) {
@@ -364,31 +340,26 @@ public class BeanAdapter implements Map<
}
/**
- * Invokes the setter methods for all the given properties that are
- * present in the map. The method signatures are determined by the
- * type of the values. If any value is <tt>null</tt>, the return
- * type of the getter method is used. There is an option to ignore
- * (that is, not throw) exceptions during the process, but to
- * return status if any exceptions were caught and ignored.
- *
- * @param valueMap
- * The map of keys and values to be set.
- *
- * @param ignoreErrors
- * If <code>true</code> then any {@link PropertyNotFoundException}
- * thrown by the {@link #put put()} method will be caught and ignored.
- *
- * @return
- * <code>true</code> if any exceptions were caught, <code>false</code>
- * if not.
+ * Invokes the setter methods for all the given properties that are present
+ * in the map. The method signatures are determined by the type of the
+ * values. If any value is <tt>null</tt>, the return type of the getter
+ * method is used. There is an option to ignore (that is, not throw)
+ * exceptions during the process, but to return status if any exceptions
+ * were caught and ignored.
+ *
+ * @param valueMap The map of keys and values to be set.
+ * @param ignoreErrors If <code>true</code> then any
+ * {@link PropertyNotFoundException} thrown by the {@link #put put()} method
+ * will be caught and ignored.
+ * @return <code>true</code> if any exceptions were caught,
+ * <code>false</code> if not.
*/
public boolean putAll(Map<String, ?> valueMap, boolean ignoreErrors) {
boolean anyErrors = false;
for (String key : valueMap) {
try {
put(key, valueMap.get(key));
- }
- catch (PropertyNotFoundException ex) {
+ } catch (PropertyNotFoundException ex) {
if (!ignoreErrors)
throw ex;
anyErrors = true;
@@ -398,8 +369,7 @@ public class BeanAdapter implements Map<
}
/**
- * @throws UnsupportedOperationException
- * This method is not supported.
+ * @throws UnsupportedOperationException This method is not supported.
*/
@Override
public Object remove(String key) {
@@ -407,8 +377,7 @@ public class BeanAdapter implements Map<
}
/**
- * @throws UnsupportedOperationException
- * This method is not supported.
+ * @throws UnsupportedOperationException This method is not supported.
*/
@Override
public synchronized void clear() {
@@ -418,12 +387,9 @@ public class BeanAdapter implements Map<
/**
* Verifies the existence of a property. The property must have a getter
* method; write-only properties are not supported.
- *
- * @param key
- * The property name.
- *
- * @return
- * <tt>true</tt> if the property exists; <tt>false</tt>, otherwise.
+ *
+ * @param key The property name.
+ * @return <tt>true</tt> if the property exists; <tt>false</tt>, otherwise.
*/
@Override
public boolean containsKey(String key) {
@@ -445,8 +411,7 @@ public class BeanAdapter implements Map<
}
/**
- * @throws UnsupportedOperationException
- * This method is not supported.
+ * @throws UnsupportedOperationException This method is not supported.
*/
@Override
public boolean isEmpty() {
@@ -454,8 +419,7 @@ public class BeanAdapter implements Map<
}
/**
- * @throws UnsupportedOperationException
- * This method is not supported.
+ * @throws UnsupportedOperationException This method is not supported.
*/
@Override
public int getCount() {
@@ -468,8 +432,7 @@ public class BeanAdapter implements Map<
}
/**
- * @throws UnsupportedOperationException
- * This method is not supported.
+ * @throws UnsupportedOperationException This method is not supported.
*/
@Override
public void setComparator(Comparator<String> comparator) {
@@ -478,12 +441,10 @@ public class BeanAdapter implements Map<
/**
* Tests the read-only state of a property.
- *
- * @param key
- * The property name.
- *
- * @return
- * <tt>true</tt> if the property is read-only; <tt>false</tt>, otherwise.
+ *
+ * @param key The property name.
+ * @return <tt>true</tt> if the property is read-only; <tt>false</tt>,
+ * otherwise.
*/
public boolean isReadOnly(String key) {
return isReadOnly(bean.getClass(), key);
@@ -491,12 +452,9 @@ public class BeanAdapter implements Map<
/**
* Returns the type of a property.
- *
- * @param key
- * The property name.
- *
- * @see
- * #getType(Class, String)
+ *
+ * @param key The property name.
+ * @see #getType(Class, String)
*/
public Class<?> getType(String key) {
return getType(bean.getClass(), key);
@@ -504,12 +462,9 @@ public class BeanAdapter implements Map<
/**
* Returns the generic type of a property.
- *
- * @param key
- * The property name.
- *
- * @see
- * #getGenericType(Class, String)
+ *
+ * @param key The property name.
+ * @see #getGenericType(Class, String)
*/
public Type getGenericType(String key) {
return getGenericType(bean.getClass(), key);
@@ -517,9 +472,8 @@ public class BeanAdapter implements Map<
/**
* Returns an iterator over the bean's properties.
- *
- * @return
- * A property iterator for this bean.
+ *
+ * @return A property iterator for this bean.
*/
@Override
public Iterator<String> iterator() {
@@ -533,12 +487,9 @@ public class BeanAdapter implements Map<
/**
* Returns the getter method for a property.
- *
- * @param key
- * The property name.
- *
- * @return
- * The getter method, or <tt>null</tt> if the method does not exist.
+ *
+ * @param key The property name.
+ * @return The getter method, or <tt>null</tt> if the method does not exist.
*/
private Method getGetterMethod(String key) {
return getGetterMethod(bean.getClass(), key);
@@ -546,12 +497,9 @@ public class BeanAdapter implements Map<
/**
* Returns the setter method for a property.
- *
- * @param key
- * The property name.
- *
- * @return
- * The getter method, or <tt>null</tt> if the method does not exist.
+ *
+ * @param key The property name.
+ * @return The getter method, or <tt>null</tt> if the method does not exist.
*/
private Method getSetterMethod(String key, Class<?> valueType) {
return getSetterMethod(bean.getClass(), key, valueType);
@@ -560,12 +508,9 @@ public class BeanAdapter implements Map<
/**
* Returns the public, non-static field for a property. Note that fields
* will only be consulted for bean properties after bean methods.
- *
- * @param fieldName
- * The property name
- *
- * @return
- * The field, or <tt>null</tt> if the field does not exist, or is
+ *
+ * @param fieldName The property name
+ * @return The field, or <tt>null</tt> if the field does not exist, or is
* non-public or static
*/
private Field getField(String fieldName) {
@@ -580,15 +525,11 @@ public class BeanAdapter implements Map<
* Tests the read-only state of a property. Note that if no such property
* exists, this method will return <tt>true</tt> (it will <u>not</u> throw
* an exception).
- *
- * @param beanClass
- * The bean class.
- *
- * @param key
- * The property name.
- *
- * @return
- * <tt>true</tt> if the property is read-only; <tt>false</tt>, otherwise.
+ *
+ * @param beanClass The bean class.
+ * @param key The property name.
+ * @return <tt>true</tt> if the property is read-only; <tt>false</tt>,
+ * otherwise.
*/
public static boolean isReadOnly(Class<?> beanClass, String key) {
if (beanClass == null) {
@@ -621,16 +562,11 @@ public class BeanAdapter implements Map<
/**
* Returns the type of a property.
- *
- * @param beanClass
- * The bean class.
- *
- * @param key
- * The property name.
- *
- * @return
- * The type of the property, or <tt>null</tt> if no such bean property
- * exists.
+ *
+ * @param beanClass The bean class.
+ * @param key The property name.
+ * @return The type of the property, or <tt>null</tt> if no such bean
+ * property exists.
*/
public static Class<?> getType(Class<?> beanClass, String key) {
if (beanClass == null) {
@@ -664,16 +600,11 @@ public class BeanAdapter implements Map<
/**
* Returns the generic type of a property.
- *
- * @param beanClass
- * The bean class.
- *
- * @param key
- * The property name.
- *
- * @return
- * The generic type of the property, or <tt>null</tt> if no such
- * bean property exists. If the type is a generic, an instance of
+ *
+ * @param beanClass The bean class.
+ * @param key The property name.
+ * @return The generic type of the property, or <tt>null</tt> if no such bean
+ * property exists. If the type is a generic, an instance of
* {@link java.lang.reflect.ParameterizedType} will be returned. Otherwise,
* an instance of {@link java.lang.Class} will be returned.
*/
@@ -710,15 +641,10 @@ public class BeanAdapter implements Map<
/**
* Returns the public, non-static fields for a property. Note that fields
* will only be consulted for bean properties after bean methods.
- *
- * @param beanClass
- * The bean class.
- *
- * @param key
- * The property name.
- *
- * @return
- * The field, or <tt>null</tt> if the field does not exist, or is
+ *
+ * @param beanClass The bean class.
+ * @param key The property name.
+ * @return The field, or <tt>null</tt> if the field does not exist, or is
* non-public or static.
*/
public static Field getField(Class<?> beanClass, String key) {
@@ -742,8 +668,7 @@ public class BeanAdapter implements Map<
int modifiers = field.getModifiers();
// Exclude non-public and static fields
- if ((modifiers & Modifier.PUBLIC) == 0
- || (modifiers & Modifier.STATIC) > 0) {
+ if ((modifiers & Modifier.PUBLIC) == 0 || (modifiers & Modifier.STATIC) > 0) {
field = null;
}
} catch (NoSuchFieldException exception) {
@@ -755,15 +680,10 @@ public class BeanAdapter implements Map<
/**
* Returns the getter method for a property.
- *
- * @param beanClass
- * The bean class.
- *
- * @param key
- * The property name.
- *
- * @return
- * The getter method, or <tt>null</tt> if the method does not exist.
+ *
+ * @param beanClass The bean class.
+ * @param key The property name.
+ * @return The getter method, or <tt>null</tt> if the method does not exist.
*/
public static Method getGetterMethod(final Class<?> beanClass, final String key) {
if (beanClass == null) {
@@ -801,17 +721,13 @@ public class BeanAdapter implements Map<
/**
* Returns the setter method for a property.
- *
- * @param beanClass
- * The bean class.
- *
- * @param key
- * The property name.
- *
- * @return
- * The getter method, or <tt>null</tt> if the method does not exist.
+ *
+ * @param beanClass The bean class.
+ * @param key The property name.
+ * @return The getter method, or <tt>null</tt> if the method does not exist.
*/
- public static Method getSetterMethod(final Class<?> beanClass, final String key, final Class<?> valueType) {
+ public static Method getSetterMethod(final Class<?> beanClass, final String key,
+ final Class<?> valueType) {
if (beanClass == null) {
throw new IllegalArgumentException("beanClass is null.");
}
@@ -849,7 +765,7 @@ public class BeanAdapter implements Map<
// signature with the corresponding primitive type
try {
Field primitiveTypeField = valueType.getField("TYPE");
- Class<?> primitiveValueType = (Class<?>)primitiveTypeField.get(null);
+ Class<?> primitiveValueType = (Class<?>) primitiveTypeField.get(null);
try {
setterMethod = beanClass.getMethod(methodName, primitiveValueType);
@@ -859,8 +775,9 @@ public class BeanAdapter implements Map<
} catch (NoSuchFieldException exception) {
// No-op
} catch (IllegalAccessException exception) {
- throw new RuntimeException(String.format(ILLEGAL_ACCESS_EXCEPTION_MESSAGE_FORMAT,
- keyUpdated, beanClass.getName()), exception);
+ throw new RuntimeException(String.format(
+ ILLEGAL_ACCESS_EXCEPTION_MESSAGE_FORMAT, keyUpdated, beanClass.getName()),
+ exception);
}
}
@@ -869,8 +786,7 @@ public class BeanAdapter implements Map<
Class<?>[] interfaces = valueType.getInterfaces();
int i = 0, n = interfaces.length;
- while (setterMethod == null
- && i < n) {
+ while (setterMethod == null && i < n) {
Class<?> interfaceType = interfaces[i++];
setterMethod = getSetterMethod(beanClass, keyUpdated, interfaceType);
}
@@ -882,12 +798,10 @@ public class BeanAdapter implements Map<
/**
* Coerces a value to a given type.
- *
+ *
* @param value
* @param type
- *
- * @return
- * The coerced value.
+ * @return The coerced value.
*/
@SuppressWarnings("unchecked")
public static <T> T coerce(Object value, Class<? extends T> type) {
@@ -935,73 +849,65 @@ public class BeanAdapter implements Map<
// Coerce the value to the requested type
if (type == String.class) {
coercedValue = value.toString();
- } else if (type == Boolean.class
- || type == Boolean.TYPE) {
+ } else if (type == Boolean.class || type == Boolean.TYPE) {
coercedValue = Boolean.parseBoolean(value.toString());
- } else if (type == Character.class
- || type == Character.TYPE) {
+ } else if (type == Character.class || type == Character.TYPE) {
coercedValue = value.toString().charAt(0);
- } else if (type == Byte.class
- || type == Byte.TYPE) {
+ } else if (type == Byte.class || type == Byte.TYPE) {
if (value instanceof Number) {
- coercedValue = ((Number)value).byteValue();
+ coercedValue = ((Number) value).byteValue();
} else {
coercedValue = Byte.parseByte(value.toString());
}
- } else if (type == Short.class
- || type == Short.TYPE) {
+ } else if (type == Short.class || type == Short.TYPE) {
if (value instanceof Number) {
- coercedValue = ((Number)value).shortValue();
+ coercedValue = ((Number) value).shortValue();
} else {
coercedValue = Short.parseShort(value.toString());
}
- } else if (type == Integer.class
- || type == Integer.TYPE) {
+ } else if (type == Integer.class || type == Integer.TYPE) {
if (value instanceof Number) {
- coercedValue = ((Number)value).intValue();
+ coercedValue = ((Number) value).intValue();
} else {
coercedValue = Integer.parseInt(value.toString());
}
- } else if (type == Long.class
- || type == Long.TYPE) {
+ } else if (type == Long.class || type == Long.TYPE) {
if (value instanceof Number) {
- coercedValue = ((Number)value).longValue();
+ coercedValue = ((Number) value).longValue();
} else {
coercedValue = Long.parseLong(value.toString());
}
- } else if (type == Float.class
- || type == Float.TYPE) {
+ } else if (type == Float.class || type == Float.TYPE) {
if (value instanceof Number) {
- coercedValue = ((Number)value).floatValue();
+ coercedValue = ((Number) value).floatValue();
} else {
coercedValue = Float.parseFloat(value.toString());
}
- } else if (type == Double.class
- || type == Double.TYPE) {
+ } else if (type == Double.class || type == Double.TYPE) {
if (value instanceof Number) {
- coercedValue = ((Number)value).doubleValue();
+ coercedValue = ((Number) value).doubleValue();
} else {
coercedValue = Double.parseDouble(value.toString());
}
} else if (type == BigInteger.class) {
if (value instanceof Number) {
- coercedValue = new BigInteger(((Number)value).toString());
+ coercedValue = new BigInteger(((Number) value).toString());
} else {
coercedValue = new BigInteger(value.toString());
}
} else if (type == BigDecimal.class) {
if (value instanceof Number) {
- coercedValue = new BigDecimal(((Number)value).toString());
+ coercedValue = new BigDecimal(((Number) value).toString());
} else {
coercedValue = new BigDecimal(value.toString());
}
} else {
- throw new IllegalArgumentException("Unable to coerce " + value.getClass().getName()
- + " to " + type + ".");
+ throw new IllegalArgumentException("Unable to coerce "
+ + value.getClass().getName() + " to " + type + ".");
}
}
}
- return (T)coercedValue;
+ return (T) coercedValue;
}
}
Modified: pivot/trunk/core/src/org/apache/pivot/beans/BeanMonitor.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/beans/BeanMonitor.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/beans/BeanMonitor.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/beans/BeanMonitor.java Fri Oct 4 23:45:40 2013
@@ -58,8 +58,8 @@ public class BeanMonitor {
}
}
- private class PropertyChangeListenerList extends ListenerList<PropertyChangeListener>
- implements PropertyChangeListener {
+ private class PropertyChangeListenerList extends ListenerList<PropertyChangeListener> implements
+ PropertyChangeListener {
@Override
public void add(PropertyChangeListener listener) {
if (isEmpty()) {
@@ -112,11 +112,11 @@ public class BeanMonitor {
if (ListenerList.class.isAssignableFrom(method.getReturnType())
&& (method.getModifiers() & Modifier.STATIC) == 0) {
- ParameterizedType genericType = (ParameterizedType)method.getGenericReturnType();
+ ParameterizedType genericType = (ParameterizedType) method.getGenericReturnType();
Type[] typeArguments = genericType.getActualTypeArguments();
if (typeArguments.length == 1) {
- Class<?> listenerInterface = (Class<?>)typeArguments[0];
+ Class<?> listenerInterface = (Class<?>) typeArguments[0];
if (!listenerInterface.isInterface()) {
throw new RuntimeException(listenerInterface.getName()
@@ -151,12 +151,9 @@ public class BeanMonitor {
/**
* Tests whether a property fires change events.
- *
- * @param key
- * The property name.
- *
- * @return
- * <tt>true</tt> if the property fires change events; <tt>false</tt>
+ *
+ * @param key The property name.
+ * @return <tt>true</tt> if the property fires change events; <tt>false</tt>
* otherwise.
*/
public boolean isNotifying(String key) {
@@ -176,11 +173,11 @@ public class BeanMonitor {
if (ListenerList.class.isAssignableFrom(method.getReturnType())
&& (method.getModifiers() & Modifier.STATIC) == 0) {
- ParameterizedType genericType = (ParameterizedType)method.getGenericReturnType();
+ ParameterizedType genericType = (ParameterizedType) method.getGenericReturnType();
Type[] typeArguments = genericType.getActualTypeArguments();
if (typeArguments.length == 1) {
- Class<?> listenerInterface = (Class<?>)typeArguments[0];
+ Class<?> listenerInterface = (Class<?>) typeArguments[0];
// Get the listener list
Object listenerList;
@@ -195,8 +192,9 @@ public class BeanMonitor {
// Get the listener for this interface
Object listener = beanListenerProxies.get(listenerInterface);
if (listener == null) {
- listener = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
- new Class<?>[]{listenerInterface}, invocationHandler);
+ listener = Proxy.newProxyInstance(
+ Thread.currentThread().getContextClassLoader(),
+ new Class<?>[] { listenerInterface }, invocationHandler);
beanListenerProxies.put(listenerInterface, listener);
}
@@ -205,13 +203,13 @@ public class BeanMonitor {
Method addMethod;
try {
addMethod = listenerListClass.getMethod("add",
- new Class<?>[] {Object.class});
+ new Class<?>[] { Object.class });
} catch (NoSuchMethodException exception) {
throw new RuntimeException(exception);
}
try {
- addMethod.invoke(listenerList, new Object[] {listener});
+ addMethod.invoke(listenerList, new Object[] { listener });
} catch (IllegalAccessException exception) {
throw new RuntimeException(exception);
} catch (InvocationTargetException exception) {
@@ -233,11 +231,11 @@ public class BeanMonitor {
if (ListenerList.class.isAssignableFrom(method.getReturnType())
&& (method.getModifiers() & Modifier.STATIC) == 0) {
- ParameterizedType genericType = (ParameterizedType)method.getGenericReturnType();
+ ParameterizedType genericType = (ParameterizedType) method.getGenericReturnType();
Type[] typeArguments = genericType.getActualTypeArguments();
if (typeArguments.length == 1) {
- Class<?> listenerInterface = (Class<?>)typeArguments[0];
+ Class<?> listenerInterface = (Class<?>) typeArguments[0];
// Get the listener list
Object listenerList;
@@ -260,13 +258,13 @@ public class BeanMonitor {
Method removeMethod;
try {
removeMethod = listenerListClass.getMethod("remove",
- new Class<?>[] {Object.class});
+ new Class<?>[] { Object.class });
} catch (NoSuchMethodException exception) {
throw new RuntimeException(exception);
}
try {
- removeMethod.invoke(listenerList, new Object[] {listener});
+ removeMethod.invoke(listenerList, new Object[] { listener });
} catch (IllegalAccessException exception) {
throw new RuntimeException(exception);
} catch (InvocationTargetException exception) {
Modified: pivot/trunk/core/src/org/apache/pivot/beans/Bindable.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/beans/Bindable.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/beans/Bindable.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/beans/Bindable.java Fri Oct 4 23:45:40 2013
@@ -22,26 +22,22 @@ import org.apache.pivot.collections.Map;
import org.apache.pivot.util.Resources;
/**
- * Allows {@link BXMLSerializer} to initialize an instance of a deserialized class.
+ * Allows {@link BXMLSerializer} to initialize an instance of a deserialized
+ * class.
*/
public interface Bindable {
/**
- * Called to initialize the class after it has been completely
- * processed and bound by the serializer.
- *
- * @param namespace
- * The serializer's namespace. The bindable object can use this to extract named
- * values defined in the BXML file. Alternatively, the {@link BXML} annotation
- * can be used by trusted code to automatically map namespace values to member
- * variables.
- *
- * @param location
- * The location of the BXML source. May be <tt>null</tt> if the location of the
- * source is not known.
- *
- * @param resources
- * The resources that were used to localize the deserialized content. May be
- * <tt>null</tt> if no resources were specified.
+ * Called to initialize the class after it has been completely processed and
+ * bound by the serializer.
+ *
+ * @param namespace The serializer's namespace. The bindable object can use
+ * this to extract named values defined in the BXML file. Alternatively, the
+ * {@link BXML} annotation can be used by trusted code to automatically map
+ * namespace values to member variables.
+ * @param location The location of the BXML source. May be <tt>null</tt> if
+ * the location of the source is not known.
+ * @param resources The resources that were used to localize the deserialized
+ * content. May be <tt>null</tt> if no resources were specified.
*/
public void initialize(Map<String, Object> namespace, URL location, Resources resources);
}
Modified: pivot/trunk/core/src/org/apache/pivot/beans/NamespaceBinding.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/beans/NamespaceBinding.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/beans/NamespaceBinding.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/beans/NamespaceBinding.java Fri Oct 4 23:45:40 2013
@@ -33,7 +33,7 @@ public class NamespaceBinding {
public interface BindMapping {
/**
* Transforms a source value during a bind operation.
- *
+ *
* @param value
*/
public Object evaluate(Object value);
@@ -59,8 +59,7 @@ public class NamespaceBinding {
private MapListener<String, Object> sourceMapListener = new MapListener.Adapter<String, Object>() {
@Override
public void valueUpdated(Map<String, Object> map, String key, Object previousValue) {
- if (key.equals(sourceKey)
- && !updating) {
+ if (key.equals(sourceKey) && !updating) {
updating = true;
targetDictionary.put(targetKey, getTransformedSourceValue());
updating = false;
@@ -71,8 +70,7 @@ public class NamespaceBinding {
private PropertyChangeListener sourcePropertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChanged(Object bean, String propertyName) {
- if (propertyName.equals(sourceKey)
- && !updating) {
+ if (propertyName.equals(sourceKey) && !updating) {
updating = true;
targetDictionary.put(targetKey, getTransformedSourceValue());
updating = false;
@@ -110,7 +108,7 @@ public class NamespaceBinding {
source = JSON.get(namespace, sourceKeys);
if (source instanceof Map<?, ?>) {
- sourceMap = (Map<String, Object>)source;
+ sourceMap = (Map<String, Object>) source;
sourceMonitor = null;
} else {
sourceMap = new BeanAdapter(source);
@@ -122,8 +120,7 @@ public class NamespaceBinding {
+ "\" does not exist.");
}
- if (sourceMonitor != null
- && !sourceMonitor.isNotifying(sourceKey)) {
+ if (sourceMonitor != null && !sourceMonitor.isNotifying(sourceKey)) {
throw new IllegalArgumentException("\"" + sourceKey + "\" is not a notifying property.");
}
@@ -135,7 +132,7 @@ public class NamespaceBinding {
target = JSON.get(namespace, targetKeys);
if (target instanceof Dictionary<?, ?>) {
- targetDictionary = (Dictionary<String, Object>)target;
+ targetDictionary = (Dictionary<String, Object>) target;
} else {
targetDictionary = new BeanAdapter(target);
}
@@ -203,10 +200,9 @@ public class NamespaceBinding {
/**
* Returns the bind mapping.
- *
- * @return
- * The bind mapping to use during binding, or <tt>null</tt> if no bind
- * mapping is specified.
+ *
+ * @return The bind mapping to use during binding, or <tt>null</tt> if no
+ * bind mapping is specified.
*/
public BindMapping getBindMapping() {
return bindMapping;
@@ -247,12 +243,11 @@ public class NamespaceBinding {
boolean equals = false;
if (o instanceof NamespaceBinding) {
- NamespaceBinding namespaceBinding = (NamespaceBinding)o;
+ NamespaceBinding namespaceBinding = (NamespaceBinding) o;
equals = (source == namespaceBinding.source
&& sourceKey.equals(namespaceBinding.sourceKey)
- && target == namespaceBinding.target
- && targetKey.equals(namespaceBinding.targetKey));
+ && target == namespaceBinding.target && targetKey.equals(namespaceBinding.targetKey));
}
return equals;
Modified: pivot/trunk/core/src/org/apache/pivot/beans/PropertyChangeListener.java
URL: http://svn.apache.org/viewvc/pivot/trunk/core/src/org/apache/pivot/beans/PropertyChangeListener.java?rev=1529349&r1=1529348&r2=1529349&view=diff
==============================================================================
--- pivot/trunk/core/src/org/apache/pivot/beans/PropertyChangeListener.java (original)
+++ pivot/trunk/core/src/org/apache/pivot/beans/PropertyChangeListener.java Fri Oct 4 23:45:40 2013
@@ -22,7 +22,7 @@ package org.apache.pivot.beans;
public interface PropertyChangeListener {
/**
* Called when a Java bean property has changed.
- *
+ *
* @param bean
* @param propertyName
*/