r1724 - in trunk: jaxx-compiler/src/main/java/jaxx/compiler jaxx-compiler/src/main/java/jaxx/compiler/binding jaxx-compiler/src/main/java/jaxx/compiler/finalizers jaxx-compiler/src/main/java/jaxx/compiler/script jaxx-compiler/src/main/java/jaxx/compiler/tags jaxx-compiler/src/site/rst jaxx-demo/src/main/java/jaxx/demo jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation jaxx-runtime/src/main/java/jaxx/runtime jaxx-runtime/src/main/java/jaxx/runtime/context jaxx-runtime/src/main/java/ja
Author: sletellier Date: 2010-01-29 16:49:15 +0100 (Fri, 29 Jan 2010) New Revision: 1724 Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java Removed: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java trunk/jaxx-compiler/src/site/rst/BeanValidator.rst trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java trunk/src/site/rst/BeanValidator.rst Log: Revert Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/CompiledObject.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -460,8 +460,8 @@ MethodDescriptor addMethod = handler.getAddMethod(); ClassDescriptor listenerClass = addMethod.getParameterTypes()[0]; //TC-20091026 use 'this' instead of root object javaCode - //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple name - return getJavaCode() + '.' + addMethod.getName() + "(JAXXUtil.getEventListener(" + listenerClass.getSimpleName() + ".class, " + + //TC-20091105 Util.getEventListener is generic, no more need cast and use simple name + return getJavaCode() + '.' + addMethod.getName() + "(Util.getEventListener(" + listenerClass.getSimpleName() + ".class, " + TypeManager.getJavaCode(handler.getListenerMethod().getName()) + ", this, " + TypeManager.getJavaCode(compiler.getEventHandlerMethodName(handler)) + "));" + JAXXCompiler.getLineSeparator(); } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXCompiler.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -127,7 +127,7 @@ */ protected final IDHelper idHelper; /** - * Binding JAXXUtil + * Binding Util */ protected final DataBindingHelper bindingHelper; /** Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/JAXXEngine.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -651,7 +651,7 @@ "jaxx.runtime.swing.HBox", "jaxx.runtime.swing.VBox", "jaxx.runtime.swing.Table", - "jaxx.runtime.JAXXUtil", + "jaxx.runtime.Util", "jaxx.runtime.SwingUtil", "static org.nuiton.i18n.I18n._", "static jaxx.runtime.SwingUtil.createImageIcon") Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/binding/DataSource.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -37,7 +37,7 @@ import jaxx.compiler.tags.DefaultObjectHandler; import jaxx.compiler.tags.TagManager; import jaxx.compiler.types.TypeManager; -import jaxx.runtime.JAXXUtil; +import jaxx.runtime.Util; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.builder.ToStringBuilder; import org.apache.commons.lang.builder.ToStringStyle; @@ -620,12 +620,12 @@ } String code = objectCode + (eventInfo.getModelName() != null ? ".get" + StringUtils.capitalize(eventInfo.getModelName()) + "()" : ""); result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator()); - //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name - result.append(code).append('.').append(eventInfo.getAddMethod()).append("( JAXXUtil.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));"); + //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name + result.append(code).append('.').append(eventInfo.getAddMethod()).append("( Util.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));"); result.append(JAXXCompiler.getLineSeparator()); if (eventInfo.getModelName() != null) { result.append(getAddMemberListenerCode(handler, objectCode, "get" + StringUtils.capitalize(eventInfo.getModelName()), - JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(" + (compiler.getOutputClassName() + ".this") + ", " + constantId + ")", + Util.class.getSimpleName() + ".getDataBindingUpdateListener(" + (compiler.getOutputClassName() + ".this") + ", " + constantId + ")", compiler)); } return result.toString(); @@ -696,12 +696,12 @@ result.append(modelClassName).append(" $target = ((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\"));").append(eol); //TC-20091105 test if $target is not null result.append("if ($target != null) {").append(eol); - //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name - result.append(" $target.").append(eventInfo.getRemoveMethod()).append("( JAXXUtil.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol); + //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name + result.append(" $target.").append(eventInfo.getRemoveMethod()).append("( Util.getEventListener(").append(eventInfo.getListenerClass().getSimpleName()).append(".class, ").append("this").append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol); result.append("}").append(eol); if (eventInfo.getModelName() != null) { result.append(getRemoveMemberListenerCode(handler, objectCode, "get" + StringUtils.capitalize(eventInfo.getModelName()), - JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(" + compiler.getOutputClassName() + ".this, " + constantId + ")", + Util.class.getSimpleName() + ".getDataBindingUpdateListener(" + compiler.getOutputClassName() + ".this, " + constantId + ")", compiler)); } return result.toString(); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/finalizers/DefaultFinalizer.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -194,7 +194,7 @@ * */ protected static final JavaMethod GET_JAXX_OBJECT_DESCRIPTOR_METHOD = newMethod(PUBLIC | STATIC, "JAXXObjectDescriptor", METHOD_NAME_$GET_JAXXOBJECT_DESCRIPTOR, - "return JAXXUtil.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", false); + "return Util.decodeCompressedJAXXObjectDescriptor(" + FIELD_NAME_$JAXX_OBJECT_DESCRIPTOR + ");", false); /** * */ @@ -624,7 +624,7 @@ } } if (!superclassIsJAXXObject) { - code.append(JAXXUtil.class.getSimpleName()).append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");"); + code.append(Util.class.getSimpleName()).append(".initContext(this, " + PARAMETER_NAME_PARENT_CONTEXT + ");"); code.append(eol); } code.append(METHOD_NAME_$INITIALIZE + "();"); @@ -708,7 +708,7 @@ if (bindings.length > 0) { result.append(eol).append("// apply ").append(bindings.length).append(" data bindings").append(eol); - result.append(JAXXUtil.class.getSimpleName()).append("." + METHOD_NAME_APPLY_DATA_BINDING + "(this, " + FIELD_NAME_$BINDINGS + ".keySet());").append(eol); + result.append(Util.class.getSimpleName()).append("." + METHOD_NAME_APPLY_DATA_BINDING + "(this, " + FIELD_NAME_$BINDINGS + ".keySet());").append(eol); } bindings = compiler.getBindingHelper().getSimpleBindings(); Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/script/ScriptManager.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -133,7 +133,7 @@ for (FieldDescriptor field : fields) { if (field.getName().equals(lhs)) { //lhs.substring(lhs.lastIndexOf(".") + 1); - node.firstToken.image = "jaxx.runtime.JAXXUtil.assignment(" + node.firstToken.image; + node.firstToken.image = "jaxx.runtime.Util.assignment(" + node.firstToken.image; String outputClassName = compiler.getOutputClassName(); node.lastToken.image = node.lastToken.image + ", \"" + lhs + "\", " + outputClassName + ".this)"; } Modified: trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java =================================================================== --- trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -337,13 +337,13 @@ // } // String code = objectCode + (eventInfo.modelName != null ? ".get" + StringUtils.capitalize(eventInfo.modelName) + "()" : ""); // result.append("$bindingSources.put(\"").append(code).append("\", ").append(code).append(");").append(JAXXCompiler.getLineSeparator()); -// //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name -// result.append(code).append('.').append(eventInfo.addMethod).append("( JAXXUtil.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));"); +// //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name +// result.append(code).append('.').append(eventInfo.addMethod).append("( Util.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));"); // result.append(JAXXCompiler.getLineSeparator()); // if (eventInfo.modelName != null) { // result.append(getAddMemberListenerCode(objectCode, dataBinding, "get" + StringUtils.capitalize(eventInfo.modelName), -// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this , " + dataBinding + ")", -//// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this , \"" + dataBinding + "\")", +// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this , " + dataBinding + ")", +//// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this , \"" + dataBinding + "\")", // compiler)); // } // return result.toString(); @@ -407,14 +407,14 @@ // result.append(modelClassName).append(" $target = ((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\"));").append(eol); // //TC-20091105 test if $target is not null // result.append("if ($target != null) {").append(eol); -// //TC-20091105 JAXXUtil.getEventListener is generic, no more need cast and use simple listener name -// result.append(" $target.").append(eventInfo.removeMethod).append("( JAXXUtil.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol); +// //TC-20091105 Util.getEventListener is generic, no more need cast and use simple listener name +// result.append(" $target.").append(eventInfo.removeMethod).append("( Util.getEventListener(").append(eventInfo.listenerClass.getSimpleName()).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(TypeManager.getJavaCode(methodName)).append("));").append(eol); // result.append("}").append(eol); // if (eventInfo.modelName != null) { //// String bi = dataBinding.startsWith("this.") ? dataBinding : ("\"" + dataBinding + "\""); // result.append(getRemoveMemberListenerCode(objectCode, dataBinding, "get" + StringUtils.capitalize(eventInfo.modelName), -// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this, " + dataBinding + ")", -//// JAXXUtil.class.getSimpleName() + ".getDataBindingUpdateListener(this, \"" + dataBinding + "\")", +// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this, " + dataBinding + ")", +//// Util.class.getSimpleName() + ".getDataBindingUpdateListener(this, \"" + dataBinding + "\")", // compiler)); // } // return result.toString(); Modified: trunk/jaxx-compiler/src/site/rst/BeanValidator.rst =================================================================== --- trunk/jaxx-compiler/src/site/rst/BeanValidator.rst 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-compiler/src/site/rst/BeanValidator.rst 2010-01-29 15:49:15 UTC (rev 1724) @@ -170,7 +170,7 @@ :: - jaxx.runtime.JAXXUtil.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class); + jaxx.runtime.Util.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class); On obtiendra si une erreur de conversion intervient, une erreur dont le libellé est de la forme *error.convertor.XXX* Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoConfig.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -29,7 +29,7 @@ import java.util.Properties; import jaxx.demo.component.jaxx.navigation.FullNavigationTreeDemo; -import jaxx.runtime.JAXXUtil; +import jaxx.runtime.Util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -214,7 +214,7 @@ }; public void removeJaxxPropertyChangeListener() { - PropertyChangeListener[] toRemove = JAXXUtil.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners()); + PropertyChangeListener[] toRemove = Util.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners()); if (toRemove == null || toRemove.length == 0) { return; } Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoTreeHelper.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -37,7 +37,7 @@ import jaxx.demo.fun.LabelStyleDemo; import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXObject; -import jaxx.runtime.JAXXUtil; +import jaxx.runtime.Util; import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.swing.CardLayout2; import jaxx.runtime.swing.ErrorDialogUI; @@ -191,7 +191,7 @@ /** * la definition de l'unqiue object a partage */ - static private final JAXXContextEntryDef<DemoConfig> def = JAXXUtil.newContextEntryDef(DemoConfig.class); + static private final JAXXContextEntryDef<DemoConfig> def = Util.newContextEntryDef(DemoConfig.class); /** * la pile des noeuds parent */ Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/DemoUIHandler.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -21,7 +21,7 @@ package jaxx.demo; import jaxx.runtime.JAXXContext; -import jaxx.runtime.JAXXUtil; +import jaxx.runtime.Util; import jaxx.runtime.context.DefaultApplicationContext; import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.context.JAXXInitialContext; @@ -57,7 +57,7 @@ * to use log facility, just put in your code: log.info(\"...\"); */ static private Log log = LogFactory.getLog(DemoUIHandler.class); - static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = JAXXUtil.newContextEntryDef("mainui", DemoUI.class); + static final JAXXContextEntryDef<DemoUI> MAIN_UI_ENTRY_DEF = Util.newContextEntryDef("mainui", DemoUI.class); /** * Methode pour initialiser l'ui principale sans l'afficher. Modified: trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java =================================================================== --- trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-demo/src/main/java/jaxx/demo/component/jaxx/navigation/FullNavigationTreeHelper.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -22,7 +22,7 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXObject; -import jaxx.runtime.JAXXUtil; +import jaxx.runtime.Util; import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.swing.CardLayout2; import jaxx.runtime.swing.ErrorDialogUI; @@ -63,11 +63,11 @@ /** * where the movies are hold in context */ - static public final JAXXContextEntryDef<List<Movie>> MOVIES = JAXXUtil.newListContextEntryDef("movies"); + static public final JAXXContextEntryDef<List<Movie>> MOVIES = Util.newListContextEntryDef("movies"); /** * where the actors are hold in context */ - static public final JAXXContextEntryDef<List<People>> ACTORS = JAXXUtil.newListContextEntryDef("actors"); + static public final JAXXContextEntryDef<List<People>> ACTORS = Util.newListContextEntryDef("actors"); protected FullNavigationTreeModelBuilder builder; public FullNavigationTreeHelper() { Deleted: trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/JAXXUtil.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -1,516 +0,0 @@ -/* - * *##% - * JAXX Runtime - * Copyright (C) 2008 - 2009 CodeLutin - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * ##%* - */ -package jaxx.runtime; - -import jaxx.runtime.context.JAXXContextEntryDef; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeListenerProxy; -import java.io.IOException; -import java.lang.ref.WeakReference; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.*; - -public class JAXXUtil { - - // public static final String DEFAULT_ICON_PATH = "/icons/"; - // public static final String DEFAULT_ICON_PATH_PROPERTY = "default.icon.path"; - /** - * Logger - */ - static private final Log log = LogFactory.getLog(JAXXUtil.class); - public static final String PARENT = "parent"; - // Maps root objects to lists of event listeners - private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>(); - private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>> dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>(); - - private static class EventListenerDescriptor { - - Class<?> listenerClass; - String listenerMethodName; - String methodName; - Object eventListener; - } - - /** - * Decodes the serialized representation of a JAXXObjectDescriptor. The string must be a byte-to-character mapping - * of the binary serialization data for a JAXXObjectDescriptor. See the comments in JAXXCompiler.createJAXXObjectDescriptorField - * for the rationale behind this (admittedly ugly) approach. - * - * @param descriptor descriptor to decode - * @return the dedoced descriptor - */ - public static JAXXObjectDescriptor decodeJAXXObjectDescriptor(String descriptor) { - try { - return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, false); - /*byte[] data = new byte[descriptor.length()]; - // copy low-order bytes into the array. The high-order bytes should all be zero. - System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length); - //descriptor.getBytes(0, descriptor.length(), data, 0); - ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)); - return (JAXXObjectDescriptor) in.readObject();*/ - } catch (IOException e) { - throw new RuntimeException("Internal error: can't-happen error", e); - } catch (ClassNotFoundException e) { - throw new RuntimeException("Internal error: can't-happen error", e); - } - } - - public static JAXXObjectDescriptor decodeCompressedJAXXObjectDescriptor(String descriptor) { - try { - return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, true); - - /*byte[] data = new byte[descriptor.length()]; - // copy low-order bytes into the array. The high-order bytes should all be zero. - System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length); - //descriptor.getBytes(0, descriptor.length(), data, 0); - ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(data))); - return (JAXXObjectDescriptor) in.readObject();*/ - } catch (IOException e) { - throw new RuntimeException("Internal error: can't-happen error", e); - } catch (ClassNotFoundException e) { - throw new RuntimeException("Internal error: can't-happen error", e); - } - } - - public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) { - return newContextEntryDef(null, klass); - } - - public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) { - return new JAXXContextEntryDef<O>(name, klass); - } - - public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() { - return newListContextEntryDef(null); - } - - public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) { - Class<List<O>> castList = JAXXUtil.castList(); - JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name, castList); - return contextEntryDef; - } - -// public static DefaultJAXXBinding registerBinding(Map<String, DefaultJAXXBinding> bindings, DefaultJAXXBinding binding) { -// bindings.put(binding.getId(), binding); -//// binding.applyDataBinding(); -//// binding.processDataBinding(); -// return binding; -// } - -// /** -// * Return parent's container corresponding to the Class clazz -// * -// * @param <O> type of container to obtain from context -// * @param top the top container -// * @param clazz desired -// * @return parent's container -// */ -// @SuppressWarnings({"unchecked"}) -// public static <O extends Container> O getParentContainer(Object top, Class<O> clazz) { -// if (top == null) { -// throw new IllegalArgumentException("top parameter can not be null"); -// } -// if (!Container.class.isAssignableFrom(top.getClass())) { -// throw new IllegalArgumentException("top parameter " + top + " is not a " + Container.class); -// } -// Container parent = ((Container) top).getParent(); -// if (parent != null && !clazz.isAssignableFrom(parent.getClass())) { -// parent = getParentContainer(parent, clazz); -// } -// return (O) parent; -// } - - @SuppressWarnings({"unchecked"}) - protected static <O> Class<List<O>> castList() { - return (Class<List<O>>) Collections.emptyList().getClass(); - } - - /** - * Method to initialize the context of a ui. - * - * @param ui the ui - * @param parentContext the context to set in ui - */ - public static void initContext(JAXXObject ui, JAXXContext parentContext) { - - if (parentContext instanceof jaxx.runtime.context.JAXXInitialContext) { - ((jaxx.runtime.context.JAXXInitialContext) parentContext).to(ui); - } else { - ui.setContextValue(parentContext); - } - // if parentContext is a JAXXObject then - // add an special parent entry to can go up - if (parentContext instanceof JAXXObject) { - ui.setContextValue(parentContext, PARENT); - } - } - - public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) { - WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer); - List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null; - if (descriptors == null) { - descriptors = new ArrayList<EventListenerDescriptor>(); - eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors)); - } else { - for (EventListenerDescriptor descriptor : descriptors) { - if (listenerClass == descriptor.listenerClass && - (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) && - methodName.equals(descriptor.methodName)) { - return (E) descriptor.eventListener; - } - } - } - - // else we need to create a new listener - final EventListenerDescriptor descriptor = new EventListenerDescriptor(); - descriptor.listenerClass = listenerClass; - descriptor.listenerMethodName = listenerMethodName; - descriptor.methodName = methodName; - try { - final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods()); - Method listenerMethod = null; - if (listenerMethodName != null) { - for (Method listenerMethod1 : listenerMethods) { - if ((listenerMethod1).getName().equals(listenerMethodName)) { - listenerMethod = listenerMethod1; - break; - } - } - } - if (listenerMethodName != null && listenerMethod == null) { - throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName()); - } - Class<?>[] parameterTypes = listenerMethods.get(0).getParameterTypes(); - Class<?> methodContainerClass = methodContainer.getClass(); - final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes); - descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(), - new Class<?>[]{listenerClass}, - new InvocationHandler() { - - @Override - public Object invoke(Object proxy, Method method, Object[] args) { - String methodName = method.getName(); - if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) { - try { - targetMethod.setAccessible(true); - return targetMethod.invoke(methodContainer, args); - } catch (IllegalAccessException e) { - throw new RuntimeException("could not invoke on container " + methodContainer, e); - } catch (InvocationTargetException e) { - throw new RuntimeException(e); - } - } - if (methodName.equals("toString")) { - return toString(); - } - if (methodName.equals("equals")) { - return descriptor.eventListener == args[0]; - } - if (methodName.equals("hashCode")) { - return hashCode(); - } - return null; - } - }); - descriptors.add(descriptor); - return (E) descriptor.eventListener; - } catch (NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - - public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final Object methodContainer, final String methodName) { - return getEventListener(listenerClass, null, methodContainer, methodName); - } - - public static DataBindingUpdateListener getDataBindingUpdateListener(JAXXObject object, String bindingName) { - WeakReference<List<DataBindingUpdateListener>> ref = dataBindingUpdateListeners.get(object); - List<DataBindingUpdateListener> listeners = ref == null ? null : ref.get(); - if (listeners == null) { - listeners = new ArrayList<DataBindingUpdateListener>(); - dataBindingUpdateListeners.put(object, new WeakReference<List<DataBindingUpdateListener>>(listeners)); - } else { - for (DataBindingUpdateListener listener : listeners) { - if (bindingName.equals(listener.getBindingName())) { - return listener; - } - } - } - DataBindingUpdateListener listener = new DataBindingUpdateListener(object, bindingName); - listeners.add(listener); - return listener; - } - -// public static void setComponentWidth(Component component, int width) { -// component.setSize(width, component.getHeight()); -// if (component instanceof JComponent) { -// JComponent jcomponent = (JComponent) component; -// jcomponent.setPreferredSize(new Dimension(width, jcomponent.getPreferredSize().height)); -// jcomponent.setMinimumSize(new Dimension(width, jcomponent.getPreferredSize().height)); -// if (jcomponent.isDisplayable()) { -// jcomponent.revalidate(); -// } -// } -// } - -// public static void setComponentHeight(Component component, int height) { -// component.setSize(component.getWidth(), height); -// if (component instanceof JComponent) { -// JComponent jcomponent = (JComponent) component; -// jcomponent.setPreferredSize(new Dimension(jcomponent.getPreferredSize().width, height)); -// jcomponent.setMinimumSize(new Dimension(jcomponent.getPreferredSize().width, height)); -// if (jcomponent.isDisplayable()) { -// jcomponent.revalidate(); -// } -// } -// } - - public static boolean assignment(boolean value, String name, JAXXObject src) { - src.firePropertyChange(name.trim(), null, "dummy value"); - return value; - } - - public static byte assignment(byte value, String name, JAXXObject src) { - src.firePropertyChange(name.trim(), null, "dummy value"); - return value; - } - - public static short assignment(short value, String name, JAXXObject src) { - src.firePropertyChange(name.trim(), null, "dummy value"); - return value; - } - - public static int assignment(int value, String name, JAXXObject src) { - src.firePropertyChange(name.trim(), null, "dummy value"); - return value; - } - - public static long assignment(long value, String name, JAXXObject src) { - src.firePropertyChange(name.trim(), null, "dummy value"); - return value; - } - - public static float assignment(float value, String name, JAXXObject src) { - src.firePropertyChange(name.trim(), null, "dummy value"); - return value; - } - - public static double assignment(double value, String name, JAXXObject src) { - src.firePropertyChange(name.trim(), null, "dummy value"); - return value; - } - - public static char assignment(char value, String name, JAXXObject src) { - src.firePropertyChange(name.trim(), null, "dummy value"); - return value; - } - - public static java.lang.Object assignment(java.lang.Object value, String name, JAXXObject src) { - src.firePropertyChange(name.trim(), null, "dummy value"); - return value; - } - - /** - * Compute the string representation of an object. - * <p/> - * Return empty string if given object is null - * - * @param value the value to write - * @return the string representation of the given object or an empty string if object is null. - */ - public static String getStringValue(Object value) { - String result; - result = value == null ? "" : value.toString(); - return result; - } - - /** - * Test if a type of entry exists in a given context and throw an IllegalArgumentException if not found. - * <p/> - * If entry is found, return his value in context. - * - * @param <T> the type of required data - * @param context the context to test - * @param def the definition of the entry to seek in context - * @return the value from the context - * @throws IllegalArgumentException if the entry is not found in context. - */ - public static <T> T checkJAXXContextEntry(JAXXContext context, JAXXContextEntryDef<T> def) throws IllegalArgumentException { - - T value = def.getContextValue(context); - - if (value == null) { - throw new IllegalArgumentException("the context entry [" + def + "] ] was not found in context " + context); - } - - return value; - } - - /** - * Convinient method to apply more than one binding on a JAXX ui. - * - * @param src the ui to treate - * @param bindings the list of binding to process. - */ - public static void applyDataBinding(JAXXObject src, String... bindings) { - for (String binding : bindings) { - src.applyDataBinding(binding); - } - } - /** - * Convinient method to apply more than one binding on a JAXX ui. - * - * @param src the ui to treate - * @param bindings the list of binding to process. - */ - public static void applyDataBinding(JAXXObject src, Collection<String> bindings) { - for (String binding : bindings) { - src.applyDataBinding(binding); - } - } - - /** - * Convinient method to process more than one binding on a JAXX ui. - * - * @param src the ui to treate - * @param bindings the list of binding to process. - */ - public static void processDataBinding(JAXXObject src, String... bindings) { - for (String binding : bindings) { - src.processDataBinding(binding); - } - } - - /** - * Convinient method to remove more than one binding on a JAXX ui. - * - * @param src the ui to treate - * @param bindings the list of binding to process. - */ - public static void removeDataBinding(JAXXObject src, String... bindings) { - for (String binding : bindings) { - src.removeDataBinding(binding); - } - } - -// public static ImageIcon createIcon(String path) { -// java.net.URL imgURL = JAXXUtil.class.getResource(path); -// if (imgURL != null) { -// return new ImageIcon(imgURL); -// } else { -// throw new IllegalArgumentException("could not find icon " + path); -// } -// } - -// /** -// * @param path the location of icons in root directory icons -// * @return the icon at {@link #getIconPath()}+path -// */ -// public static ImageIcon createImageIcon(String path) { -// String iconPath = getIconPath(); -// return createIcon(iconPath + path); -// } -// -// /** -// * @param key the key of the icon to retreave from {@link UIManager} -// * @return the icon, or <code>null if no icon found in {@link UIManager} -// */ -// public static Icon getUIManagerIcon(String key) { -// return UIManager.getIcon(key); -// } -// -// /** -// * retreave for the {@link UIManager} the icon prefixed by <code>action.</code> -// * -// * @param key the key of the action icon to retreave from {@link UIManager} -// * @return the icon, or <code>null if no icon found in {@link UIManager} -// */ -// public static Icon getUIManagerActionIcon(String key) { -// return getUIManagerIcon("action." + key); -// } -// -// public static ImageIcon createActionIcon(String name) { -// String iconPath = getIconPath(); -// return createIcon(iconPath + "action-" + name + ".png"); -// } -// -// public static ImageIcon createI18nIcon(String name) { -// String iconPath = getIconPath(); -// return createIcon(iconPath + "i18n/" + name + ".png"); -// } - - /** - * detects all PropertychangedListener added by Jaxx uis - * (should be a {@link DataBindingListener} - * - * @param propertyNames the array of property names to find - * @param listeners the array of listeners to filter - * @return the filtered listeners - */ - public static PropertyChangeListener[] findJaxxPropertyChangeListener(String[] propertyNames, PropertyChangeListener... listeners) { - if (listeners == null || listeners.length == 0) { - return new PropertyChangeListener[0]; - } - List<String> pNames = Arrays.asList(propertyNames); - - List<PropertyChangeListener> toRemove = new ArrayList<PropertyChangeListener>(); - - for (PropertyChangeListener listener : listeners) { - String pName = null; - PropertyChangeListenerProxy plistener = null; - if (listener instanceof PropertyChangeListenerProxy) { - plistener = (PropertyChangeListenerProxy) listener; - if (!pNames.contains(plistener.getPropertyName())) { - // not on the good property - continue; - } - listener = (PropertyChangeListener) plistener.getListener(); - pName = plistener.getPropertyName(); - } - if (plistener != null && pName != null && listener instanceof DataBindingListener) { - if (log.isDebugEnabled()) { - log.debug("find config listener to remove [" + pName + "] : " + listener); - } - toRemove.add(plistener); - //toRemove.add(listener); - } - } - return toRemove.toArray(new PropertyChangeListener[toRemove.size()]); - } - -// private static String getIconPath() { -// String iconPath = UIManager.getString(DEFAULT_ICON_PATH_PROPERTY); -// if (iconPath == null) { -// iconPath = DEFAULT_ICON_PATH; -// } else { -// if (!iconPath.endsWith("/")) { -// iconPath += "/"; -// } -// } -// return iconPath; -// } -} Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/SwingUtil.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -79,7 +79,7 @@ * @author tony * @since 1.2 */ -public class SwingUtil extends JAXXUtil { +public class SwingUtil extends Util { /** * to use log facility, just put in your code: log.info(\"...\"); @@ -861,7 +861,7 @@ } public static ImageIcon createIcon(String path) { - java.net.URL imgURL = JAXXUtil.class.getResource(path); + java.net.URL imgURL = Util.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { Added: trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java (rev 0) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/Util.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -0,0 +1,516 @@ +/* + * *##% + * JAXX Runtime + * Copyright (C) 2008 - 2009 CodeLutin + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 Lesser Public License for more details. + * + * You should have received a copy of the GNU General Lesser Public + * License along with this program. If not, see + * <http://www.gnu.org/licenses/lgpl-3.0.html>. + * ##%* + */ +package jaxx.runtime; + +import jaxx.runtime.context.JAXXContextEntryDef; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeListenerProxy; +import java.io.IOException; +import java.lang.ref.WeakReference; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; +import java.util.*; + +public class Util { + + // public static final String DEFAULT_ICON_PATH = "/icons/"; + // public static final String DEFAULT_ICON_PATH_PROPERTY = "default.icon.path"; + /** + * Logger + */ + static private final Log log = LogFactory.getLog(Util.class); + public static final String PARENT = "parent"; + // Maps root objects to lists of event listeners + private static Map<Object, WeakReference<List<EventListenerDescriptor>>> eventListeners = new WeakHashMap<Object, WeakReference<List<EventListenerDescriptor>>>(); + private static Map<JAXXObject, WeakReference<List<DataBindingUpdateListener>>> dataBindingUpdateListeners = new WeakHashMap<JAXXObject, WeakReference<List<DataBindingUpdateListener>>>(); + + private static class EventListenerDescriptor { + + Class<?> listenerClass; + String listenerMethodName; + String methodName; + Object eventListener; + } + + /** + * Decodes the serialized representation of a JAXXObjectDescriptor. The string must be a byte-to-character mapping + * of the binary serialization data for a JAXXObjectDescriptor. See the comments in JAXXCompiler.createJAXXObjectDescriptorField + * for the rationale behind this (admittedly ugly) approach. + * + * @param descriptor descriptor to decode + * @return the dedoced descriptor + */ + public static JAXXObjectDescriptor decodeJAXXObjectDescriptor(String descriptor) { + try { + return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, false); + /*byte[] data = new byte[descriptor.length()]; + // copy low-order bytes into the array. The high-order bytes should all be zero. + System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length); + //descriptor.getBytes(0, descriptor.length(), data, 0); + ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(data)); + return (JAXXObjectDescriptor) in.readObject();*/ + } catch (IOException e) { + throw new RuntimeException("Internal error: can't-happen error", e); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Internal error: can't-happen error", e); + } + } + + public static JAXXObjectDescriptor decodeCompressedJAXXObjectDescriptor(String descriptor) { + try { + return (JAXXObjectDescriptor) Base64Coder.deserialize(descriptor, true); + + /*byte[] data = new byte[descriptor.length()]; + // copy low-order bytes into the array. The high-order bytes should all be zero. + System.arraycopy(descriptor.getBytes(), 0, data, 0, data.length); + //descriptor.getBytes(0, descriptor.length(), data, 0); + ObjectInputStream in = new ObjectInputStream(new GZIPInputStream(new ByteArrayInputStream(data))); + return (JAXXObjectDescriptor) in.readObject();*/ + } catch (IOException e) { + throw new RuntimeException("Internal error: can't-happen error", e); + } catch (ClassNotFoundException e) { + throw new RuntimeException("Internal error: can't-happen error", e); + } + } + + public static <O> JAXXContextEntryDef<O> newContextEntryDef(Class<O> klass) { + return newContextEntryDef(null, klass); + } + + public static <O> JAXXContextEntryDef<O> newContextEntryDef(String name, Class<O> klass) { + return new JAXXContextEntryDef<O>(name, klass); + } + + public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef() { + return newListContextEntryDef(null); + } + + public static <O> JAXXContextEntryDef<List<O>> newListContextEntryDef(String name) { + Class<List<O>> castList = Util.castList(); + JAXXContextEntryDef<List<O>> contextEntryDef = new JAXXContextEntryDef<List<O>>(name, castList); + return contextEntryDef; + } + +// public static DefaultJAXXBinding registerBinding(Map<String, DefaultJAXXBinding> bindings, DefaultJAXXBinding binding) { +// bindings.put(binding.getId(), binding); +//// binding.applyDataBinding(); +//// binding.processDataBinding(); +// return binding; +// } + +// /** +// * Return parent's container corresponding to the Class clazz +// * +// * @param <O> type of container to obtain from context +// * @param top the top container +// * @param clazz desired +// * @return parent's container +// */ +// @SuppressWarnings({"unchecked"}) +// public static <O extends Container> O getParentContainer(Object top, Class<O> clazz) { +// if (top == null) { +// throw new IllegalArgumentException("top parameter can not be null"); +// } +// if (!Container.class.isAssignableFrom(top.getClass())) { +// throw new IllegalArgumentException("top parameter " + top + " is not a " + Container.class); +// } +// Container parent = ((Container) top).getParent(); +// if (parent != null && !clazz.isAssignableFrom(parent.getClass())) { +// parent = getParentContainer(parent, clazz); +// } +// return (O) parent; +// } + + @SuppressWarnings({"unchecked"}) + protected static <O> Class<List<O>> castList() { + return (Class<List<O>>) Collections.emptyList().getClass(); + } + + /** + * Method to initialize the context of a ui. + * + * @param ui the ui + * @param parentContext the context to set in ui + */ + public static void initContext(JAXXObject ui, JAXXContext parentContext) { + + if (parentContext instanceof jaxx.runtime.context.JAXXInitialContext) { + ((jaxx.runtime.context.JAXXInitialContext) parentContext).to(ui); + } else { + ui.setContextValue(parentContext); + } + // if parentContext is a JAXXObject then + // add an special parent entry to can go up + if (parentContext instanceof JAXXObject) { + ui.setContextValue(parentContext, PARENT); + } + } + + public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final String listenerMethodName, final Object methodContainer, final String methodName) { + WeakReference<List<EventListenerDescriptor>> ref = eventListeners.get(methodContainer); + List<EventListenerDescriptor> descriptors = ref != null ? ref.get() : null; + if (descriptors == null) { + descriptors = new ArrayList<EventListenerDescriptor>(); + eventListeners.put(methodContainer, new WeakReference<List<EventListenerDescriptor>>(descriptors)); + } else { + for (EventListenerDescriptor descriptor : descriptors) { + if (listenerClass == descriptor.listenerClass && + (listenerMethodName == null ? descriptor.listenerMethodName == null : listenerMethodName.equals(descriptor.listenerMethodName)) && + methodName.equals(descriptor.methodName)) { + return (E) descriptor.eventListener; + } + } + } + + // else we need to create a new listener + final EventListenerDescriptor descriptor = new EventListenerDescriptor(); + descriptor.listenerClass = listenerClass; + descriptor.listenerMethodName = listenerMethodName; + descriptor.methodName = methodName; + try { + final List<Method> listenerMethods = Arrays.asList(listenerClass.getMethods()); + Method listenerMethod = null; + if (listenerMethodName != null) { + for (Method listenerMethod1 : listenerMethods) { + if ((listenerMethod1).getName().equals(listenerMethodName)) { + listenerMethod = listenerMethod1; + break; + } + } + } + if (listenerMethodName != null && listenerMethod == null) { + throw new IllegalArgumentException("no method named " + listenerMethodName + " found in class " + listenerClass.getName()); + } + Class<?>[] parameterTypes = listenerMethods.get(0).getParameterTypes(); + Class<?> methodContainerClass = methodContainer.getClass(); + final Method targetMethod = methodContainerClass.getMethod(methodName, parameterTypes); + descriptor.eventListener = Proxy.newProxyInstance(listenerClass.getClassLoader(), + new Class<?>[]{listenerClass}, + new InvocationHandler() { + + @Override + public Object invoke(Object proxy, Method method, Object[] args) { + String methodName = method.getName(); + if ((listenerMethodName == null && listenerMethods.contains(method)) || methodName.equals(listenerMethodName)) { + try { + targetMethod.setAccessible(true); + return targetMethod.invoke(methodContainer, args); + } catch (IllegalAccessException e) { + throw new RuntimeException("could not invoke on container " + methodContainer, e); + } catch (InvocationTargetException e) { + throw new RuntimeException(e); + } + } + if (methodName.equals("toString")) { + return toString(); + } + if (methodName.equals("equals")) { + return descriptor.eventListener == args[0]; + } + if (methodName.equals("hashCode")) { + return hashCode(); + } + return null; + } + }); + descriptors.add(descriptor); + return (E) descriptor.eventListener; + } catch (NoSuchMethodException e) { + throw new RuntimeException(e); + } + } + + public static <E extends EventListener> E getEventListener(Class<E> listenerClass, final Object methodContainer, final String methodName) { + return getEventListener(listenerClass, null, methodContainer, methodName); + } + + public static DataBindingUpdateListener getDataBindingUpdateListener(JAXXObject object, String bindingName) { + WeakReference<List<DataBindingUpdateListener>> ref = dataBindingUpdateListeners.get(object); + List<DataBindingUpdateListener> listeners = ref == null ? null : ref.get(); + if (listeners == null) { + listeners = new ArrayList<DataBindingUpdateListener>(); + dataBindingUpdateListeners.put(object, new WeakReference<List<DataBindingUpdateListener>>(listeners)); + } else { + for (DataBindingUpdateListener listener : listeners) { + if (bindingName.equals(listener.getBindingName())) { + return listener; + } + } + } + DataBindingUpdateListener listener = new DataBindingUpdateListener(object, bindingName); + listeners.add(listener); + return listener; + } + +// public static void setComponentWidth(Component component, int width) { +// component.setSize(width, component.getHeight()); +// if (component instanceof JComponent) { +// JComponent jcomponent = (JComponent) component; +// jcomponent.setPreferredSize(new Dimension(width, jcomponent.getPreferredSize().height)); +// jcomponent.setMinimumSize(new Dimension(width, jcomponent.getPreferredSize().height)); +// if (jcomponent.isDisplayable()) { +// jcomponent.revalidate(); +// } +// } +// } + +// public static void setComponentHeight(Component component, int height) { +// component.setSize(component.getWidth(), height); +// if (component instanceof JComponent) { +// JComponent jcomponent = (JComponent) component; +// jcomponent.setPreferredSize(new Dimension(jcomponent.getPreferredSize().width, height)); +// jcomponent.setMinimumSize(new Dimension(jcomponent.getPreferredSize().width, height)); +// if (jcomponent.isDisplayable()) { +// jcomponent.revalidate(); +// } +// } +// } + + public static boolean assignment(boolean value, String name, JAXXObject src) { + src.firePropertyChange(name.trim(), null, "dummy value"); + return value; + } + + public static byte assignment(byte value, String name, JAXXObject src) { + src.firePropertyChange(name.trim(), null, "dummy value"); + return value; + } + + public static short assignment(short value, String name, JAXXObject src) { + src.firePropertyChange(name.trim(), null, "dummy value"); + return value; + } + + public static int assignment(int value, String name, JAXXObject src) { + src.firePropertyChange(name.trim(), null, "dummy value"); + return value; + } + + public static long assignment(long value, String name, JAXXObject src) { + src.firePropertyChange(name.trim(), null, "dummy value"); + return value; + } + + public static float assignment(float value, String name, JAXXObject src) { + src.firePropertyChange(name.trim(), null, "dummy value"); + return value; + } + + public static double assignment(double value, String name, JAXXObject src) { + src.firePropertyChange(name.trim(), null, "dummy value"); + return value; + } + + public static char assignment(char value, String name, JAXXObject src) { + src.firePropertyChange(name.trim(), null, "dummy value"); + return value; + } + + public static java.lang.Object assignment(java.lang.Object value, String name, JAXXObject src) { + src.firePropertyChange(name.trim(), null, "dummy value"); + return value; + } + + /** + * Compute the string representation of an object. + * <p/> + * Return empty string if given object is null + * + * @param value the value to write + * @return the string representation of the given object or an empty string if object is null. + */ + public static String getStringValue(Object value) { + String result; + result = value == null ? "" : value.toString(); + return result; + } + + /** + * Test if a type of entry exists in a given context and throw an IllegalArgumentException if not found. + * <p/> + * If entry is found, return his value in context. + * + * @param <T> the type of required data + * @param context the context to test + * @param def the definition of the entry to seek in context + * @return the value from the context + * @throws IllegalArgumentException if the entry is not found in context. + */ + public static <T> T checkJAXXContextEntry(JAXXContext context, JAXXContextEntryDef<T> def) throws IllegalArgumentException { + + T value = def.getContextValue(context); + + if (value == null) { + throw new IllegalArgumentException("the context entry [" + def + "] ] was not found in context " + context); + } + + return value; + } + + /** + * Convinient method to apply more than one binding on a JAXX ui. + * + * @param src the ui to treate + * @param bindings the list of binding to process. + */ + public static void applyDataBinding(JAXXObject src, String... bindings) { + for (String binding : bindings) { + src.applyDataBinding(binding); + } + } + /** + * Convinient method to apply more than one binding on a JAXX ui. + * + * @param src the ui to treate + * @param bindings the list of binding to process. + */ + public static void applyDataBinding(JAXXObject src, Collection<String> bindings) { + for (String binding : bindings) { + src.applyDataBinding(binding); + } + } + + /** + * Convinient method to process more than one binding on a JAXX ui. + * + * @param src the ui to treate + * @param bindings the list of binding to process. + */ + public static void processDataBinding(JAXXObject src, String... bindings) { + for (String binding : bindings) { + src.processDataBinding(binding); + } + } + + /** + * Convinient method to remove more than one binding on a JAXX ui. + * + * @param src the ui to treate + * @param bindings the list of binding to process. + */ + public static void removeDataBinding(JAXXObject src, String... bindings) { + for (String binding : bindings) { + src.removeDataBinding(binding); + } + } + +// public static ImageIcon createIcon(String path) { +// java.net.URL imgURL = Util.class.getResource(path); +// if (imgURL != null) { +// return new ImageIcon(imgURL); +// } else { +// throw new IllegalArgumentException("could not find icon " + path); +// } +// } + +// /** +// * @param path the location of icons in root directory icons +// * @return the icon at {@link #getIconPath()}+path +// */ +// public static ImageIcon createImageIcon(String path) { +// String iconPath = getIconPath(); +// return createIcon(iconPath + path); +// } +// +// /** +// * @param key the key of the icon to retreave from {@link UIManager} +// * @return the icon, or <code>null if no icon found in {@link UIManager} +// */ +// public static Icon getUIManagerIcon(String key) { +// return UIManager.getIcon(key); +// } +// +// /** +// * retreave for the {@link UIManager} the icon prefixed by <code>action.</code> +// * +// * @param key the key of the action icon to retreave from {@link UIManager} +// * @return the icon, or <code>null if no icon found in {@link UIManager} +// */ +// public static Icon getUIManagerActionIcon(String key) { +// return getUIManagerIcon("action." + key); +// } +// +// public static ImageIcon createActionIcon(String name) { +// String iconPath = getIconPath(); +// return createIcon(iconPath + "action-" + name + ".png"); +// } +// +// public static ImageIcon createI18nIcon(String name) { +// String iconPath = getIconPath(); +// return createIcon(iconPath + "i18n/" + name + ".png"); +// } + + /** + * detects all PropertychangedListener added by Jaxx uis + * (should be a {@link DataBindingListener} + * + * @param propertyNames the array of property names to find + * @param listeners the array of listeners to filter + * @return the filtered listeners + */ + public static PropertyChangeListener[] findJaxxPropertyChangeListener(String[] propertyNames, PropertyChangeListener... listeners) { + if (listeners == null || listeners.length == 0) { + return new PropertyChangeListener[0]; + } + List<String> pNames = Arrays.asList(propertyNames); + + List<PropertyChangeListener> toRemove = new ArrayList<PropertyChangeListener>(); + + for (PropertyChangeListener listener : listeners) { + String pName = null; + PropertyChangeListenerProxy plistener = null; + if (listener instanceof PropertyChangeListenerProxy) { + plistener = (PropertyChangeListenerProxy) listener; + if (!pNames.contains(plistener.getPropertyName())) { + // not on the good property + continue; + } + listener = (PropertyChangeListener) plistener.getListener(); + pName = plistener.getPropertyName(); + } + if (plistener != null && pName != null && listener instanceof DataBindingListener) { + if (log.isDebugEnabled()) { + log.debug("find config listener to remove [" + pName + "] : " + listener); + } + toRemove.add(plistener); + //toRemove.add(listener); + } + } + return toRemove.toArray(new PropertyChangeListener[toRemove.size()]); + } + +// private static String getIconPath() { +// String iconPath = UIManager.getString(DEFAULT_ICON_PATH_PROPERTY); +// if (iconPath == null) { +// iconPath = DEFAULT_ICON_PATH; +// } else { +// if (!iconPath.endsWith("/")) { +// iconPath += "/"; +// } +// } +// return iconPath; +// } +} Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DataContext.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -21,7 +21,7 @@ package jaxx.runtime.context; import jaxx.runtime.JAXXContext; -import jaxx.runtime.JAXXUtil; +import jaxx.runtime.Util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -248,7 +248,7 @@ } public void removeJaxxPropertyChangeListener() { - PropertyChangeListener[] toRemove = JAXXUtil.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners()); + PropertyChangeListener[] toRemove = Util.findJaxxPropertyChangeListener(DEFAULT_JAXX_PCS, getPropertyChangeListeners()); if (toRemove == null || toRemove.length == 0) { return; } Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/context/DefaultJAXXContext.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -22,7 +22,7 @@ import jaxx.runtime.JAXXContext; import jaxx.runtime.JAXXObject; -import jaxx.runtime.JAXXUtil; +import jaxx.runtime.Util; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -47,7 +47,7 @@ /** * entry of the parent context */ - protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = JAXXUtil.newContextEntryDef(JAXXContext.class); + protected static final JAXXContextEntryDef<JAXXContext> PARENT_CONTEXT_ENTRY = Util.newContextEntryDef(JAXXContext.class); /** * Logger */ @@ -194,7 +194,7 @@ // } protected JAXXContextEntryDef<?> getKey(String name, Class<?> klass) { - return JAXXUtil.newContextEntryDef(name, klass); + return Util.newContextEntryDef(name, klass); } @SuppressWarnings({"unchecked"}) Modified: trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java =================================================================== --- trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-runtime/src/main/java/jaxx/runtime/swing/navigation/NavigationTreeContextHelper.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -23,7 +23,7 @@ import javax.swing.JTree; import jaxx.runtime.JAXXContext; -import jaxx.runtime.JAXXUtil; +import jaxx.runtime.Util; import jaxx.runtime.context.JAXXContextEntryDef; /** @@ -71,13 +71,13 @@ public NavigationTreeContextHelper(String prefix) { this.prefix = prefix; - treeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree", JTree.class); - treeModelContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-model", NavigationTreeModel.class); - treeHandlerContextEntry = JAXXUtil.newContextEntryDef(prefix + "-tree-handler", NavigationTreeHandler.class); - selectedBeanContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-bean", Object.class); - selectedNodeContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-node", NavigationTreeNode.class); - selectedPathContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-path", String.class); -// selectedUIContextEntry = JAXXUtil.newContextEntryDef(prefix + "-selected-ui", Component.class); + treeContextEntry = Util.newContextEntryDef(prefix + "-tree", JTree.class); + treeModelContextEntry = Util.newContextEntryDef(prefix + "-tree-model", NavigationTreeModel.class); + treeHandlerContextEntry = Util.newContextEntryDef(prefix + "-tree-handler", NavigationTreeHandler.class); + selectedBeanContextEntry = Util.newContextEntryDef(prefix + "-selected-bean", Object.class); + selectedNodeContextEntry = Util.newContextEntryDef(prefix + "-selected-node", NavigationTreeNode.class); + selectedPathContextEntry = Util.newContextEntryDef(prefix + "-selected-path", String.class); +// selectedUIContextEntry = Util.newContextEntryDef(prefix + "-selected-ui", Component.class); } public String getPrefix() { Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java =================================================================== --- trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/UtilTest.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -33,10 +33,10 @@ @Test public void testGetEventListener() { count = 0; - DocumentListener listener = (DocumentListener) JAXXUtil.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount"); + DocumentListener listener = (DocumentListener) Util.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount"); listener.insertUpdate(null); Assert.assertEquals(count, 1); - DocumentListener listener2 = (DocumentListener) JAXXUtil.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount"); + DocumentListener listener2 = (DocumentListener) Util.getEventListener(javax.swing.event.DocumentListener.class, this, "incCount"); listener2.removeUpdate(null); Assert.assertEquals(count, 2); //assertTrue("Received two different event listeners despite using identical parameters", listener == listener2); Modified: trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java =================================================================== --- trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/jaxx-runtime/src/test/java/jaxx/runtime/swing/navigation/NavigationTreeModelTest.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -20,7 +20,7 @@ */ package jaxx.runtime.swing.navigation; -import jaxx.runtime.JAXXUtil; +import jaxx.runtime.Util; import jaxx.runtime.context.DefaultJAXXContext; import jaxx.runtime.JAXXContext; import org.junit.Assert; @@ -164,10 +164,10 @@ NavigationTreeNode sonSonNode; NavigationTreeNode sonSonSonNode; - builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef("name", String.class), "name", null, null); - builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef("name2", String.class), "name2", null, null); + builder.build(rootNode, (String) null, Util.newContextEntryDef("name", String.class), "name", null, null); + builder.build(rootNode, (String) null, Util.newContextEntryDef("name2", String.class), "name2", null, null); - sonNode = builder.build(rootNode, (String) null, JAXXUtil.newContextEntryDef(Model.class), "model", null, null); + sonNode = builder.build(rootNode, (String) null, Util.newContextEntryDef(Model.class), "model", null, null); builder.build(sonNode, (String) null, "../name", "name", null, null); builder.build(sonNode, (String) null, "../integerValue", "integerValue", null, null); @@ -286,7 +286,7 @@ NavigationTreeNode sonSonSonNode; // first son is a list of models - sonNode = builder.build(rootNode, (String) null, JAXXUtil.newListContextEntryDef("models"), "models", null, null); + sonNode = builder.build(rootNode, (String) null, Util.newListContextEntryDef("models"), "models", null, null); // first son son is a model sonSonNode = builder.build(sonNode, (String) null, "..[1]", "0", null, null); Modified: trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java =================================================================== --- trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/maven-jaxx-plugin/src/test/java/org/nuiton/jaxx/plugin/Bug1750Test.java 2010-01-29 15:49:15 UTC (rev 1724) @@ -23,7 +23,7 @@ import jaxx.runtime.Base64Coder; import jaxx.compiler.JAXXCompiler; import jaxx.runtime.JAXXObjectDescriptor; -import jaxx.runtime.JAXXUtil; +import jaxx.runtime.Util; import org.junit.Test; import static org.junit.Assert.*; @@ -48,7 +48,7 @@ assertNotNull(descriptor2); assertEquals(descriptor.toString(), descriptor2.toString()); - descriptor2 = JAXXUtil.decodeJAXXObjectDescriptor(data); + descriptor2 = Util.decodeJAXXObjectDescriptor(data); assertNotNull(descriptor2); assertEquals(descriptor.toString(), descriptor2.toString()); @@ -58,7 +58,7 @@ assertNotNull(descriptor2); assertEquals(descriptor.toString(), descriptor2.toString()); - descriptor2 = JAXXUtil.decodeCompressedJAXXObjectDescriptor(data); + descriptor2 = Util.decodeCompressedJAXXObjectDescriptor(data); assertNotNull(descriptor2); assertEquals(descriptor.toString(), descriptor2.toString()); Modified: trunk/src/site/rst/BeanValidator.rst =================================================================== --- trunk/src/site/rst/BeanValidator.rst 2010-01-29 15:18:50 UTC (rev 1723) +++ trunk/src/site/rst/BeanValidator.rst 2010-01-29 15:49:15 UTC (rev 1724) @@ -170,7 +170,7 @@ :: - jaxx.runtime.JAXXUtil.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class); + jaxx.runtime.Util.convert(validator,"nomDeLaPropriété",widget.getText(),TypeDeLaProriete.class); On obtiendra si une erreur de conversion intervient, une erreur dont le libellé est de la forme *error.convertor.XXX*
participants (1)
-
sletellier@users.nuiton.org