Author: tchemit Date: 2009-11-05 03:21:58 +0100 (Thu, 05 Nov 2009) New Revision: 1629 Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java Log: Anomalie #120: NPE sur un removeDataBinding Modified: branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java =================================================================== --- branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2009-11-04 21:13:46 UTC (rev 1628) +++ branches/jaxx-2.X/jaxx-compiler/src/main/java/jaxx/compiler/tags/DefaultObjectHandler.java 2009-11-05 02:21:58 UTC (rev 1629) @@ -61,6 +61,7 @@ import java.util.List; import java.util.Map; import java.util.WeakHashMap; + import org.apache.commons.lang.StringUtils; /** @@ -164,7 +165,8 @@ /** * Performs introspection on the beanClass and stores the results. * - * @throws java.beans.IntrospectionException if any pb + * @throws java.beans.IntrospectionException + * if any pb */ protected void init() throws IntrospectionException { if (jaxxBeanInfo == null) { @@ -215,7 +217,8 @@ * * @param beanClass the bean class for which to retrieve <code>JAXXBeanInfo</code> * @return the class' <code>JAXXBeanInfo</code> - * @throws java.beans.IntrospectionException if any pb + * @throws java.beans.IntrospectionException + * if any pb */ public static JAXXBeanInfo getJAXXBeanInfo(ClassDescriptor beanClass) throws IntrospectionException { return JAXXIntrospector.getJAXXBeanInfo(beanClass); @@ -403,7 +406,12 @@ String modelMemberName = eventInfo.modelName != null ? "get" + StringUtils.capitalize(eventInfo.modelName) : null; String modelClassName = modelMemberName != null ? getBeanClass().getMethodDescriptor(modelMemberName).getReturnType().getName() : JAXXCompiler.getCanonicalName(getBeanClass()); String code = objectCode + (eventInfo.modelName != null ? "." + modelMemberName + "()" : ""); - result.append("((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\")).").append(eventInfo.removeMethod).append("((").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(") jaxx.runtime.Util.getEventListener(").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(compiler.getJavaCode(methodName)).append("));\n"); + String eol = JAXXCompiler.getLineSeparator(); + result.append(modelClassName).append(" $target = ((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\"));").append(eol); + result.append("if ($target != null) {").append(eol); + result.append(" $target.").append(eventInfo.removeMethod).append("(jaxx.runtime.Util.getEventListener(").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(compiler.getJavaCode(methodName)).append("));").append(eol); + result.append("}").append(eol); +// result.append("((").append(modelClassName).append(") $bindingSources.remove(\"").append(code).append("\")).").append(eventInfo.removeMethod).append("((").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(") jaxx.runtime.Util.getEventListener(").append(JAXXCompiler.getCanonicalName(eventInfo.listenerClass)).append(".class, ").append(compiler.getRootObject().getJavaCode()).append(", ").append(compiler.getJavaCode(methodName)).append("));\n"); if (eventInfo.modelName != null) { result.append(getRemoveMemberListenerCode(objectCode, dataBinding, "get" + StringUtils.capitalize(eventInfo.modelName), Util.class.getName() + ".getDataBindingUpdateListener(this, \"" + dataBinding + "\")", @@ -504,7 +512,7 @@ // TODO: remove this temporary method, complete switchover to ClassDescriptors public void addProxyEventInfo(String memberName, Class<?> listenerClass, - String modelName, String addMethod, String removeMethod) { + String modelName, String addMethod, String removeMethod) { try { addProxyEventInfo(memberName, ClassDescriptorLoader.getClassDescriptor(listenerClass.getName()), modelName, addMethod, removeMethod); } catch (ClassNotFoundException e) { @@ -540,7 +548,7 @@ * @param removeMethod remove method name */ public void addProxyEventInfo(String memberName, ClassDescriptor listenerClass, - String modelName, String addMethod, String removeMethod) { + String modelName, String addMethod, String removeMethod) { ProxyEventInfo info = new ProxyEventInfo(); info.memberName = memberName; info.listenerClass = listenerClass; @@ -614,7 +622,7 @@ } /** - * Initializes the default settings of the object, prior to setting its + * Initializes the default settings of the object, prior to setting its * attribute values. The default implementation does nothing. * * @param object the object to initialize @@ -935,7 +943,7 @@ String id = isRoot ? object.getId() + ' ' + descriptor.getId() : "( " + object.getId() + " ) " + descriptor.getId(); CompiledObject child = new CompiledObject(id, "((" + JAXXCompiler.getCanonicalName(classDescriptor) + ") " + - object.getJavaCode() + ".getObjectById(" + compiler.getJavaCode(descriptor.getId()) + "))", + object.getJavaCode() + ".getObjectById(" + compiler.getJavaCode(descriptor.getId()) + "))", classDescriptor, compiler, true);