Index: make/depends.xml =================================================================== --- make/depends.xml (revision 417984) +++ make/depends.xml (working copy) @@ -67,6 +67,10 @@ + + + + Index: modules/beans/src/main/java/java/beans/BeanDescriptor.java =================================================================== --- modules/beans/src/main/java/java/beans/BeanDescriptor.java (revision 417984) +++ modules/beans/src/main/java/java/beans/BeanDescriptor.java (working copy) @@ -102,6 +102,7 @@ if (beanClass != null) { String beanClassName = beanClass.getName(); int idx = beanClassName.lastIndexOf("."); + result = (idx == -1) ? beanClassName : beanClassName .substring(idx + 1); } Index: modules/beans/src/main/java/java/beans/BeanInfoImpl.java =================================================================== --- modules/beans/src/main/java/java/beans/BeanInfoImpl.java (revision 417984) +++ modules/beans/src/main/java/java/beans/BeanInfoImpl.java (working copy) @@ -43,10 +43,10 @@ public PropertyDescriptor[] getPropertyDescriptors() { if (propertyDescriptors == null) { HashMap result = new HashMap(); - + if (beanClass != null) { List beanClassMethodsArrayList = getPublicMethods(beanClass); - + ArrayList setters = new ArrayList(); ArrayList getters = new ArrayList(); ArrayList booleanGetters = new ArrayList(); @@ -54,10 +54,13 @@ ArrayList indexedGetters = new ArrayList(); Iterator iterator = beanClassMethodsArrayList.iterator(); + Object[] values; + while (iterator.hasNext()) { Method method = (Method) iterator.next(); - + int methodType = getMethodType(method); + if (methodType == MT_SETTER) { setters.add(method); } else if (methodType == MT_GETTER) { @@ -81,10 +84,10 @@ addPropertyDescriptorsFromMethodList(result, getters, true); } catch (Exception e) { } - - Object[] values = result.values().toArray(); + + values = result.values().toArray(); propertyDescriptors = new PropertyDescriptor[values.length]; - for(int k = 0; k < propertyDescriptors.length; ++k) { + for (int k = 0; k < propertyDescriptors.length; ++k) { propertyDescriptors[k] = (PropertyDescriptor) values[k]; } } @@ -94,56 +97,59 @@ } public MethodDescriptor[] getMethodDescriptors() { - if(methodDescriptors == null) { + if (methodDescriptors == null) { List result = new ArrayList(); List beanClassMethodsArrayList = getPublicMethods(beanClass); - + Iterator iterator = beanClassMethodsArrayList.iterator(); + while (iterator.hasNext()) { Method method = (Method) iterator.next(); result.add(new MethodDescriptor(method)); } - + methodDescriptors = new MethodDescriptor[result.size()]; - for(int i = 0; i < methodDescriptors.length; ++i) { + for (int i = 0; i < methodDescriptors.length; ++i) { methodDescriptors[i] = (MethodDescriptor) result.get(i); } - + } - + return methodDescriptors; } public EventSetDescriptor[] getEventSetDescriptors() { - if(eventSetDescriptors == null) { + if (eventSetDescriptors == null) { Map result = new HashMap(); List beanClassMethodsArrayList = getPublicMethods(beanClass); - + Iterator iterator = beanClassMethodsArrayList.iterator(); - while(iterator.hasNext()) { + + while (iterator.hasNext()) { Method method = (Method) iterator.next(); String methodName = method.getName(); String listenerName = null; - if(methodName.endsWith("Listener")) { + + if (methodName.endsWith("Listener")) { listenerName = methodName.substring(0, methodName.lastIndexOf("Listener")); - - if(methodName.startsWith("add")) { + + if (methodName.startsWith("add")) { listenerName = listenerName.substring(3); - } else if(methodName.startsWith("remove")) { + } else if (methodName.startsWith("remove")) { listenerName = listenerName.substring(6); } else { continue; } - - if(result.get(listenerName) == null) { + + if (result.get(listenerName) == null) { Class[] parameterTypes = method.getParameterTypes(); - - if(parameterTypes.length == 1) { + + if (parameterTypes.length == 1) { Class listenerType = parameterTypes[0]; - + // full and short names of classes String listenerTypeName = listenerType.getName(); @@ -152,20 +158,22 @@ String listenerNameFromParam = listenerTypeName.substring( listenerTypeName.lastIndexOf(".") + 1); - + String listenerNameFromMethod = listenerName + "Listener"; - if(!listenerNameFromParam.equals( + + if (!listenerNameFromParam.equals( listenerNameFromMethod)) { continue; } - + String eventTypeName = listenerTypeName.substring(0, listenerTypeName.lastIndexOf(".") + 1) + listenerName + "Event"; - + // classes generated from classes names Class eventType = null; + try { eventType = Class.forName(eventTypeName, true, beanClass.getClassLoader()); @@ -177,23 +185,26 @@ continue; } } - + Method[] methods = listenerType.getMethods(); - Vector listenerMethodsVec = new Vector(); - for(int i = 0; i < methods.length; ++i) { + Vector listenerMethodsVec = + new Vector(); + for (int i = 0; i < methods.length; ++i) { Class[] listenerMethodParams = - methods[i].getParameterTypes(); - if(listenerMethodParams.length == 1 - && listenerMethodParams[0] == eventType) { + methods[i].getParameterTypes(); + + if (listenerMethodParams.length == 1 + && listenerMethodParams[0] == eventType) + { listenerMethodsVec.add(methods[i]); } } - + Method[] listenerMethods = new Method[listenerMethodsVec.size()]; Iterator iter = listenerMethodsVec.iterator(); int idx2 = 0; - while(iter.hasNext()) { + while (iter.hasNext()) { listenerMethods[idx2] = (Method) iter.next(); idx2++; } @@ -221,7 +232,7 @@ // no remover found continue; } - + Method getListenerMethod = null; String getListenerMethodName = "get" + listenerName + "Listeners"; @@ -248,17 +259,18 @@ "Cannot generate event set descriptor " + "for name" + listenerName + "."); } - + } } } } - + String[] eventSetDescriptorNames = new String[result.keySet().size()]; Iterator i = result.keySet().iterator(); int idx = 0; - while(i.hasNext()) { + + while (i.hasNext()) { eventSetDescriptorNames[idx++] = ((EventSetDescriptor) result.get( (String) i.next())).getName(); @@ -268,11 +280,11 @@ eventSetDescriptors = new EventSetDescriptor[eventSetDescriptorNames.length]; - for(int j = 0; j < eventSetDescriptors.length; ++j) { + for (int j = 0; j < eventSetDescriptors.length; ++j) { eventSetDescriptors[j] = (EventSetDescriptor) result.get( eventSetDescriptorNames[j]); } - + } return eventSetDescriptors; } @@ -304,12 +316,12 @@ int result = MT_OTHER; try { int modifiers = method.getModifiers(); - - if(Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) { + + if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)) { Class[] parameterTypes = method.getParameterTypes(); Class returnType = method.getReturnType(); - if(name.startsWith("get") && (parameterTypes.length == 0) + if (name.startsWith("get") && (parameterTypes.length == 0) && (returnType != void.class) && (name.length() > 3)) { result = MT_GETTER; } else if(name.startsWith("is") && (parameterTypes.length == 0) @@ -334,14 +346,14 @@ } catch (Exception e) { result = MT_OTHER; } - + return result; } private static String extractPropertyName(String methodName) throws Exception { String result = null; - + if ( methodName.startsWith("set") || methodName.startsWith("get") ) { result = methodName.substring(3); result = Introspector.decapitalize(result); @@ -349,20 +361,20 @@ result = methodName.substring(2); result = Introspector.decapitalize(result); } - + return result; } private static List getPublicMethods(Class theClass) { List result = new ArrayList(); + Method[] beanClassMethods = theClass.getDeclaredMethods(); - Method[] beanClassMethods = theClass.getDeclaredMethods(); for (int i = 0; i < beanClassMethods.length; ++i) { if(Modifier.isPublic(beanClassMethods[i].getModifiers())) { result.add(beanClassMethods[i]); } } - + return result; } @@ -374,8 +386,12 @@ for (Method method : methods) { String methodName = method.getName(); String propertyName = extractPropertyName(methodName); - if ((!checkExisting) || (hmPropertyDescriptors.get(propertyName) == null)) { + + if ((!checkExisting) || + (hmPropertyDescriptors.get(propertyName) == null)) + { PropertyDescriptor propertyDescriptor = null; + try { propertyDescriptor = new PropertyDescriptor(propertyName, beanClass); hmPropertyDescriptors.put(propertyName, propertyDescriptor); @@ -394,8 +410,12 @@ for (Method method : methods) { String methodName = method.getName(); String propertyName = extractPropertyName(methodName); - if ((!checkExisting) || (hmPropertyDescriptors.get(propertyName) == null)) { + + if ((!checkExisting) || + (hmPropertyDescriptors.get(propertyName) == null)) + { IndexedPropertyDescriptor indexedPropertyDescriptor = null; + try { indexedPropertyDescriptor = new IndexedPropertyDescriptor( propertyName, beanClass); Index: modules/beans/src/main/java/java/beans/BeanInfoWrapper.java =================================================================== --- modules/beans/src/main/java/java/beans/BeanInfoWrapper.java (revision 417984) +++ modules/beans/src/main/java/java/beans/BeanInfoWrapper.java (working copy) @@ -39,15 +39,16 @@ PropertyDescriptor[] result = null; PropertyDescriptor[] infoResult = null; - if(info != null) { + if (info != null) { + BeanInfo[] infos = info.getAdditionalBeanInfo(); + infoResult = info.getPropertyDescriptors(); - - BeanInfo[] infos = info.getAdditionalBeanInfo(); - if(infos != null) { - for(int i = 0; i < infos.length; ++i) { + + if (infos != null) { + for (int i = 0; i < infos.length; ++i) { BeanInfo additionalInfo = infos[i]; - - if(infoResult == null) { + + if (infoResult == null) { infoResult = additionalInfo.getPropertyDescriptors(); } else { infoResult = concatArraysToOneArray(infoResult, @@ -56,27 +57,30 @@ } } } - - if(info == null || infoResult == null) { + + if (info == null || infoResult == null) { PropertyDescriptor[] implResult = impl.getPropertyDescriptors(); - + // merge with parent info - if(parentBeanInfoWrapper != null) { + if (parentBeanInfoWrapper != null) { PropertyDescriptor[] parentResult = parentBeanInfoWrapper.getPropertyDescriptors(); - Map hm = concatArraysUniqueByName(implResult, parentResult); - + Map hm = + concatArraysUniqueByName(implResult, parentResult); + Collection values = hm.values(); - + Iterator iterator; + int idx = 0; + result = new PropertyDescriptor[values.size()]; - int idx = 0; - Iterator iterator = values.iterator(); - while(iterator.hasNext()) { + iterator = values.iterator(); + while (iterator.hasNext()) { result[idx++] = (PropertyDescriptor) iterator.next(); } - + Arrays.sort(result, new Comparator() { - public int compare(PropertyDescriptor pd1, PropertyDescriptor pd2) { + public int compare(PropertyDescriptor pd1, + PropertyDescriptor pd2) { return pd1.getName().compareTo(pd2.getName()); } public boolean equals(Object o) { @@ -97,15 +101,16 @@ MethodDescriptor[] result = null; MethodDescriptor[] infoResult = null; - if(info != null) { + if (info != null) { + BeanInfo[] infos = info.getAdditionalBeanInfo(); + infoResult = info.getMethodDescriptors(); - - BeanInfo[] infos = info.getAdditionalBeanInfo(); - if(infos != null) { - for(int i = 0; i < infos.length; ++i) { + + if (infos != null) { + for (int i = 0; i < infos.length; ++i) { BeanInfo additionalInfo = infos[i]; - - if(infoResult == null) { + + if (infoResult == null) { infoResult = additionalInfo.getMethodDescriptors(); } else { infoResult = concatArraysToOneArray(infoResult, @@ -114,14 +119,15 @@ } } } - - if(info == null || infoResult == null) { + + if (info == null || infoResult == null) { MethodDescriptor[] implResult = impl.getMethodDescriptors(); - + // merge with parent info - if(parentBeanInfoWrapper != null) { + if (parentBeanInfoWrapper != null) { MethodDescriptor[] parentResult = parentBeanInfoWrapper.getMethodDescriptors(); + result = concatArraysToOneArray(implResult, parentResult); } else { result = implResult; @@ -130,7 +136,7 @@ result = infoResult; } - if(result != null) { + if (result != null) { Arrays.sort(result, new Comparator() { public int compare(MethodDescriptor md1, MethodDescriptor md2) { return md1.getName().compareTo(md2.getName()); @@ -147,16 +153,17 @@ public EventSetDescriptor[] getEventSetDescriptors() { EventSetDescriptor[] result = null; EventSetDescriptor[] infoResult = null; - - if(info != null) { + + if (info != null) { + BeanInfo[] infos = info.getAdditionalBeanInfo(); + infoResult = info.getEventSetDescriptors(); - - BeanInfo[] infos = info.getAdditionalBeanInfo(); - if(infos != null) { - for(int i = 0; i < infos.length; ++i) { + + if (infos != null) { + for (int i = 0; i < infos.length; ++i) { BeanInfo additionalInfo = infos[i]; - - if(infoResult == null) { + + if (infoResult == null) { infoResult = additionalInfo.getEventSetDescriptors(); } else { infoResult = concatArraysToOneArray(infoResult, @@ -165,27 +172,30 @@ } } } - - if(info == null || infoResult == null) { + + if (info == null || infoResult == null) { EventSetDescriptor[] implResult = impl.getEventSetDescriptors(); - + // merge with parent info - if(parentBeanInfoWrapper != null) { + if (parentBeanInfoWrapper != null) { EventSetDescriptor[] parentResult = parentBeanInfoWrapper.getEventSetDescriptors(); - Map hm = concatArraysUniqueByName(implResult, parentResult); + Map hm = concatArraysUniqueByName( + implResult, parentResult); Collection values = hm.values(); + Iterator iterator; + int idx = 0; result = new EventSetDescriptor[values.size()]; - int idx = 0; - Iterator iterator = values.iterator(); - while(iterator.hasNext()) { + iterator = values.iterator(); + while (iterator.hasNext()) { result[idx++] = (EventSetDescriptor) iterator.next(); } Arrays.sort(result, new Comparator() { - public int compare(EventSetDescriptor esd1, EventSetDescriptor esd2) { + public int compare(EventSetDescriptor esd1, + EventSetDescriptor esd2) { return esd1.getName().compareTo(esd2.getName()); } public boolean equals(Object o) { @@ -198,69 +208,69 @@ } else { result = infoResult; } - + return result; } public BeanInfo[] getAdditionalBeanInfo() { BeanInfo[] result = null; - - if(info != null) { + + if (info != null) { result = info.getAdditionalBeanInfo(); } - + return result; } public BeanDescriptor getBeanDescriptor() { BeanDescriptor result = null; - - if(info != null) { + + if (info != null) { result = info.getBeanDescriptor(); } - - if(info == null || result == null) { + + if (info == null || result == null) { result = impl.getBeanDescriptor(); } - + return result; } public Image getIcon(int iconKind) { Image result = null; - - if(info != null) { + + if (info != null) { result = info.getIcon(iconKind); } - + return result; } public int getDefaultPropertyIndex() { int result = -1; - - if(info != null) { + + if (info != null) { result = info.getDefaultPropertyIndex(); } - - if(info == null || result == -1) { + + if (info == null || result == -1) { result = impl.getDefaultPropertyIndex(); } - + return result; } public int getDefaultEventIndex() { int result = -1; - - if(info != null) { + + if (info != null) { result = info.getDefaultEventIndex(); } - if(info == null || result == -1) { + if (info == null || result == -1) { result = impl.getDefaultEventIndex(); } - + return result; } @@ -268,41 +278,46 @@ this.parentBeanInfoWrapper = parentBeanInfoWrapper; } - private static Map concatArraysUniqueByName(FeatureDescriptor[] childs, - FeatureDescriptor[] parents) { - Map result = new HashMap(); - - if(childs != null) { - for(int i = 0; i < childs.length; ++i) { + private static Map + concatArraysUniqueByName(FeatureDescriptor[] childs, + FeatureDescriptor[] parents) + { + Map result = + new HashMap(); + + if (childs != null) { + for (int i = 0; i < childs.length; ++i) { result.put(childs[i].getName(), childs[i]); } } - - if(parents != null) { - for(int j = 0; j < parents.length; ++j) { - if(result.get(parents[j].getName()) == null) { + + if (parents != null) { + for (int j = 0; j < parents.length; ++j) { + if (result.get(parents[j].getName()) == null) { result.put(parents[j].getName(), parents[j]); } } } - + return result; } private static PropertyDescriptor[] concatArraysToOneArray( PropertyDescriptor[] childs, PropertyDescriptor[] parents) { - if(childs != null || parents != null) { - Map hm = concatArraysUniqueByName(childs, parents); + if (childs != null || parents != null) { + Map hm = concatArraysUniqueByName( + childs, parents); PropertyDescriptor[] result = new PropertyDescriptor[hm.size()]; - + Iterator iterator = hm.keySet().iterator(); int idx = 0; - - while(iterator.hasNext()) { + + while (iterator.hasNext()) { String name = (String) iterator.next(); + result[idx++] = (PropertyDescriptor) hm.get(name); } - + return result; } else { return null; @@ -313,51 +328,54 @@ MethodDescriptor[] childs, MethodDescriptor[] parents) { MethodDescriptor[] result = null; - if(childs != null || parents != null) { + if (childs != null || parents != null) { int resultLength = 0; - - if(childs != null) { + + if (childs != null) { resultLength = childs.length; } - - if(parents != null) { + + if (parents != null) { resultLength += parents.length; } - + result = new MethodDescriptor[resultLength]; - if(childs != null) { - for(int i = 0; i < childs.length; ++i) { + if (childs != null) { + for (int i = 0; i < childs.length; ++i) { result[i] = childs[i]; } } - if(parents != null) { - int shift = (childs == null) ? 0 : childs.length; - for(int i = 0; i < parents.length; ++i) { + if (parents != null) { + int shift = (childs == null) ? 0 : childs.length; + + for (int i = 0; i < parents.length; ++i) { result[shift + i] = parents[i]; } } } - + return result; } private static EventSetDescriptor[] concatArraysToOneArray( EventSetDescriptor[] childs, EventSetDescriptor[] parents) { - if(childs != null || parents != null) { - Map hm = concatArraysUniqueByName(childs, parents); + if (childs != null || parents != null) { + Map hm = + concatArraysUniqueByName(childs, parents); EventSetDescriptor[] result = new EventSetDescriptor[hm.size()]; - + Iterator iterator = hm.keySet().iterator(); int idx = 0; - - while(iterator.hasNext()) { + + while (iterator.hasNext()) { String name = (String) iterator.next(); + result[idx++] = (EventSetDescriptor) hm.get(name); } - + return result; } else { return null; Index: modules/beans/src/main/java/java/beans/Beans.java =================================================================== --- modules/beans/src/main/java/java/beans/Beans.java (revision 417984) +++ modules/beans/src/main/java/java/beans/Beans.java (working copy) @@ -53,11 +53,11 @@ throws IOException, ClassNotFoundException { Object result = instantiate(cls, beanName, beanContext); - - if(result instanceof Applet) { + + if (result instanceof Applet) { initializer.initialize((Applet) result, beanContext); } - + return result; } @@ -70,11 +70,11 @@ throws IOException, ClassNotFoundException { Object result = instantiate(cls, beanName); - - if(beanContext != null) { + + if (beanContext != null) { beanContext.add(result); } - + return result; } @@ -89,14 +89,14 @@ String beanResourceName = getBeanResourceName(beanName); InputStream is = (cls == null) ? - ClassLoader.getSystemResourceAsStream(beanResourceName) : - cls.getResourceAsStream(beanResourceName); + ClassLoader.getSystemResourceAsStream(beanResourceName) : + cls.getResourceAsStream(beanResourceName); if(is != null) { try { ObjectInputStream ois = (cls == null) ? - new ObjectInputStream(is) : - new CustomizedObjectInputStream(is, cls); + new ObjectInputStream(is) : + new CustomizedObjectInputStream(is, cls); try { result = ois.readObject(); @@ -118,6 +118,7 @@ if (result instanceof Applet) { Applet applet = (Applet) result; + applet.init(); } } catch (IllegalAccessException iae) { @@ -187,7 +188,7 @@ private static void checkPropertiesAccess() throws SecurityException { SecurityManager sm = System.getSecurityManager(); - + if (sm != null) { sm.checkPropertiesAccess(); } @@ -199,10 +200,10 @@ } -/* - Customized object input stream that allows - to read objects by specified class loader -*/ +/** + * Customized object input stream that allows + * to read objects by specified class loader + */ class CustomizedObjectInputStream extends ObjectInputStream { private ClassLoader cls; @@ -217,21 +218,20 @@ throws IOException, ClassNotFoundException { String className = desc.getName(); - - if(className.startsWith("[")) { + + if (className.startsWith("[")) { int idx = className.lastIndexOf("["); - String prefix = className.substring(0, idx + 1); - int[] dimensions = new int[prefix.length()]; - for(int i = 0; i < dimensions.length; ++i) { + String postfix; + Class componentType = null; + + for (int i = 0; i < dimensions.length; ++i) { dimensions[i] = 0; } - - String postfix = className.substring(idx + 1); - - Class componentType = null; - if(postfix.equals("Z")) { + + postfix = className.substring(idx + 1); + if (postfix.equals("Z")) { componentType = boolean.class; } else if(postfix.equals("B")) { componentType = byte.class; @@ -256,7 +256,7 @@ throw new IllegalArgumentException("Illegal class name: " + className); } - + return Array.newInstance(componentType, dimensions).getClass(); } else { return Class.forName(className, true, cls); Index: modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java =================================================================== --- modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java (revision 417984) +++ modules/beans/src/main/java/java/beans/DefaultPersistenceDelegate.java (working copy) @@ -53,36 +53,39 @@ try { PropertyDescriptor[] pds = Introspector.getBeanInfo(type).getPropertyDescriptors(); - - for(int i = 0; i < pds.length; ++i) { + + for (int i = 0; i < pds.length; ++i) { PropertyDescriptor pd = pds[i]; - - if(!isTransient(pd)) { + + if (!isTransient(pd)) { Method getter = pd.getReadMethod(); - - if(getter != null) { - Method setter = pd.getWriteMethod(); - - if(setter != null) { - Object oldValue = getter.invoke(oldInstance, - null); - Object newValue = getter.invoke(newInstance, - null); - - if(oldValue != null && !oldValue.equals(newValue) - || oldValue == null && newValue != null) - { - String setterName = setter.getName(); - Statement s = new Statement(oldInstance, - setterName, - new Object[] { oldValue } ); - out.writeStatement(s); - } - } else { - // commented since the process should be continued even if no setter is found - // throw new Exception("no setter for " + pd.getName() + " property."); - continue; - } + + if (getter != null) { + Method setter = pd.getWriteMethod(); + + if (setter != null) { + Object oldValue = getter.invoke(oldInstance, + null); + Object newValue = getter.invoke(newInstance, + null); + + if (oldValue != null + && !oldValue.equals(newValue) + || oldValue == null && newValue != null) + { + String setterName = setter.getName(); + Statement s = new Statement(oldInstance, + setterName, + new Object[] { oldValue } ); + + out.writeStatement(s); + } + } else { + // commented since the process should be + // continued even if no setter is found + // throw new Exception("no setter for " + pd.getName() + " property."); + continue; + } } } } @@ -103,35 +106,37 @@ args = new Object[] {}; } else { args = new Object[constructorPropertyNames.length]; - + try { PropertyDescriptor[] pds = Introspector.getBeanInfo( oldInstance.getClass()).getPropertyDescriptors(); - for(int i = 0; i < constructorPropertyNames.length; ++i) { - + for (int i = 0; i < constructorPropertyNames.length; ++i) { + boolean found = false; - - for(int j = 0; j < pds.length; ++j) { - - if(constructorPropertyNames[i].equals(pds[j].getName())) { + + for (int j = 0; j < pds.length; ++j) { + + if (constructorPropertyNames[i] + .equals(pds[j].getName())) + { Method getter = pds[j].getReadMethod(); - - if(getter != null) { + + if (getter != null) { args[i] = getter.invoke(oldInstance, null); found = true; break; } else { throw new Exception("no getter for " + - pds[j].getName() + " property"); + pds[j].getName() + " property"); } - + } } // for j - if(found == false) { + if (found == false) { throw new Exception("no property for name " + - constructorPropertyNames[i] + " is found"); + constructorPropertyNames[i] + " is found"); } } // for i @@ -141,7 +146,7 @@ } } - + return new Expression(oldInstance, oldInstance.getClass(), "new", args); } @@ -149,18 +154,21 @@ * @com.intel.drl.spec_ref */ protected boolean mutatesTo(Object oldInstance, Object newInstance) { - if(oldInstance != null) { + if (oldInstance != null) { try { Method equalsMethod = oldInstance.getClass().getMethod( "equals", new Class[] { Object.class }); - if(equalsMethod != null) { + + if (equalsMethod != null) { Object result = equalsMethod.invoke(oldInstance, new Object[] { newInstance } ); - return ((Boolean) result).booleanValue(); + + return ((Boolean) result).booleanValue(); } } catch(Exception e) { System.out.println("in DefaultPersistenceDelegate.mutatesTo() " + e.getClass() + " :" + e.getMessage()); + return false; } } @@ -169,6 +177,7 @@ private static boolean isTransient(PropertyDescriptor pd) { Boolean isTransient = (Boolean) pd.getValue("transient"); + return (isTransient != null) && isTransient.equals(Boolean.TRUE); } } Index: modules/beans/src/main/java/java/beans/XMLDecoder.java =================================================================== --- modules/beans/src/main/java/java/beans/XMLDecoder.java (revision 417984) +++ modules/beans/src/main/java/java/beans/XMLDecoder.java (working copy) @@ -68,19 +68,23 @@ /** * @com.intel.drl.spec_ref */ - public XMLDecoder(InputStream is) { this.is = is; } + public XMLDecoder(InputStream is) { + this.is = is; + } /** * @com.intel.drl.spec_ref */ - public void setOwner(Object owner) { this.owner = owner; } + public void setOwner(Object owner) { + this.owner = owner; + } /** * @com.intel.drl.spec_ref */ public Object readObject() { try { - if(iterator == null) { + if (iterator == null) { initialize(); } return iterator.next(); @@ -92,7 +96,9 @@ /** * @com.intel.drl.spec_ref */ - public Object getOwner() { return owner; } + public Object getOwner() { + return owner; + } /** * @com.intel.drl.spec_ref @@ -129,7 +135,8 @@ try { String saxParserClassName = System.getProperty( "org.xml.sax.driver"); - if(saxParserClassName == null) { + + if (saxParserClassName == null) { saxParserClassName = "org.apache.xerces.parsers.SAXParser"; } XMLReader xmlReader = XMLReaderFactory.createXMLReader( Index: modules/beans/src/main/java/java/beans/XMLEncoder.java =================================================================== --- modules/beans/src/main/java/java/beans/XMLEncoder.java (revision 417984) +++ modules/beans/src/main/java/java/beans/XMLEncoder.java (working copy) @@ -104,21 +104,25 @@ } private void writeAll() { + Tag mainTag = new Tag("java"); + Enumeration e; + printed.clear(); NameMaker.clear(); - - Tag mainTag = new Tag("java"); + mainTag.addAttr("version", System.getProperty("java.version")); mainTag.addAttr("class", "java.beans.XMLDecoder"); printBytes(0, ""); printBytes(0, mainTag.toStringOnOpen()); - - Enumeration e = roots.elements(); - while(e.hasMoreElements()) { + + e = roots.elements(); + while (e.hasMoreElements()) { Object object = (Object) e.nextElement(); - if(object != null) { + + if (object != null) { ObjectNode node = (ObjectNode) nodes.get(object); + printObjectTag(0, object, node); } else { printNullTag(0); @@ -135,13 +139,15 @@ try { nodeType = node.getObjectType(); } catch (Exception e) { - getExceptionListener().exceptionThrown(e); - getExceptionListener().exceptionThrown(new Exception( - "skipping expression " + node.getInitializer() + "...")); + Exception e2 = new Exception( + "skipping expression " + node.getInitializer() + "..."); + + e2.initCause(e); + getExceptionListener().exceptionThrown(e2); return; } - if(isPrimitive(nodeType) || isString(nodeType) || isClass(nodeType)) { + if (isPrimitive(nodeType) || isString(nodeType) || isClass(nodeType)) { String tagName = getPrimitiveName(nodeType); Object arg = node.getObjectArguments()[0]; Tag tag = new Tag(tagName, arg.toString()); @@ -152,28 +158,28 @@ Object[] arguments = node.getObjectArguments(); boolean objectPrinted = false; boolean isReferenced = node.getReferencesNumber() > 0; - + if (isArray(nodeType)) { tag = new Tag("array"); } else { tag = new Tag("object"); } - + // check if the object presents references - if(isReferenced) { - if(printed.contains(node)) { + if (isReferenced) { + if (printed.contains(node)) { String nodeId = node.getId(); - - if(nodeId != null) { + + if (nodeId != null) { tag.addAttr("idref", node.getId()); } - + objectPrinted = true; } else { // if(printed.contains(node) == false try { Class type = node.getObjectType(); - - if(type != null) { + + if (type != null) { // check if it is necessary to assign // and display *id* attribute to the object String objectName = NameMaker.getInstanceName(type); @@ -187,7 +193,7 @@ } } - if(!objectPrinted) { + if (!objectPrinted) { try { if (isArray(nodeType)) { tag.addAttr("class", ((Class) arguments[0]).getName()); @@ -222,13 +228,13 @@ // let's print them printBytes(tabCount, tag.toStringOnOpen()); - + printed.add(node); - + if (isArray(nodeType)) { // if array Iterator it = node.statements(); - while(it.hasNext()) { + while (it.hasNext()) { Statement s = it.next(); printVoidTag(++tabCount, s); @@ -237,9 +243,9 @@ } else { // if object Iterator i1; Iterator i2; - - for(int i = 0; i < arguments.length; ++i) { - if(arguments[i] != null) { + + for (int i = 0; i < arguments.length; ++i) { + if (arguments[i] != null) { ObjectNode succNode = nodes.get(arguments[i]); printObjectTag(++tabCount, arguments[i], succNode); @@ -249,24 +255,24 @@ --tabCount; } - + i1 = node.expressions(); - while(i1.hasNext()) { + while (i1.hasNext()) { Expression e = i1.next(); - + printVoidTag(++tabCount, e); --tabCount; } - + i2 = node.statements(); - while(i2.hasNext()) { + while (i2.hasNext()) { Statement s = i2.next(); - + printVoidTag(++tabCount, s); --tabCount; } } // if object - + printBytes(tabCount, tag.toStringOnClose()); } } // if node is of non-trivial type @@ -274,38 +280,47 @@ private void printVoidTag(int tabCount, Expression expr) { Object exprValue = null; + try { + Enumeration enumeration; + Tag tag; + String objectName; + String methodName; + ObjectNode node; + Object[] args; + exprValue = expr.getValue(); - + // find out, if this object is already printed - Enumeration enumeration = printed.elements(); - while(enumeration.hasMoreElements()) { - ObjectNode node = (ObjectNode) enumeration.nextElement(); - if(node.getObjectValue() == exprValue) { + enumeration = printed.elements(); + while (enumeration.hasMoreElements()) { + ObjectNode node2 = (ObjectNode) enumeration.nextElement(); + + if (node2.getObjectValue() == exprValue) { return; } } - - ObjectNode node = (ObjectNode) nodes.get(exprValue); - + + node = (ObjectNode) nodes.get(exprValue); + // find out, if this object has no references to be printed // System.out.println("---- node.getReferencesNumber() = " + node.getReferencesNumber()); // System.out.println("---- node.getReferencedExpressionsNumber() = " + node.getReferencedExpressionsNumber()); - if(node.getReferencesNumber() == 0) { + if (node.getReferencesNumber() == 0) { return; } - - Tag tag = new Tag("void"); - - String objectName = NameMaker.getInstanceName(exprValue.getClass()); - + + tag = new Tag("void"); + objectName = NameMaker.getInstanceName(exprValue.getClass()); + node.setId(objectName); tag.addAttr("id", objectName); - - String methodName = expr.getMethodName(); - Object[] args = expr.getArguments(); - if(methodName.startsWith("get") + + methodName = expr.getMethodName(); + args = expr.getArguments(); + + if (methodName.startsWith("get") && (args.length == 0 || args.length == 1 && args[0].getClass() == Integer.class) || methodName.startsWith("set") @@ -313,12 +328,13 @@ && args[0].getClass() == Integer.class)) { String propertyName = methodName.substring(3); - if(propertyName.length() > 0) { + + if (propertyName.length() > 0) { tag.addAttr("property", Introspector.decapitalize( propertyName)); } - - if(methodName.startsWith("get") && args.length == 1 || + + if (methodName.startsWith("get") && args.length == 1 || methodName.startsWith("set") && args.length == 2) { tag.addAttr("index", args[0].toString()); @@ -326,23 +342,23 @@ } else { tag.addAttr("method", expr.getMethodName()); } - + printBytes(tabCount, tag.toStringOnOpen()); - - for(int i = tag.hasAttr("index") ? 1 : 0; i < args.length; ++i) { - if(args[i] != null) { + + for (int i = tag.hasAttr("index") ? 1 : 0; i < args.length; ++i) { + if (args[i] != null) { ObjectNode node2 = nodes.get(args[i]); printObjectTag(++tabCount, args[i], node2); } else { printNullTag(++tabCount); } - + --tabCount; } printBytes(tabCount, tag.toStringOnClose()); - + printed.add(node); } catch (Exception e) { //TODO - signal problem with expr.getValue() @@ -352,10 +368,11 @@ private void printVoidTag(int tabCount, Statement stat) { Tag tag = new Tag("void"); - + String methodName = stat.getMethodName(); Object[] args = stat.getArguments(); - if(methodName.startsWith("get") + + if (methodName.startsWith("get") && (args.length == 0 || args.length == 1 && args[0].getClass() == Integer.class) || methodName.startsWith("set") @@ -363,12 +380,13 @@ && args[0].getClass() == Integer.class)) { String propertyName = methodName.substring(3); - if(propertyName.length() > 0) { + + if (propertyName.length() > 0) { tag.addAttr("property", Introspector.decapitalize( propertyName)); } - if(methodName.startsWith("get") && args.length == 1 || + if (methodName.startsWith("get") && args.length == 1 || methodName.startsWith("set") && args.length == 2) { tag.addAttr("index", args[0].toString()); @@ -377,17 +395,18 @@ tag.addAttr("method", stat.getMethodName()); } - + printBytes(tabCount, tag.toStringOnOpen()); - - for(int i = tag.hasAttr("index") ? 1 : 0; i < args.length; ++i) { - if(args[i] != null) { + + for (int i = tag.hasAttr("index") ? 1 : 0; i < args.length; ++i) { + if (args[i] != null) { ObjectNode node = (ObjectNode) nodes.get(args[i]); + printObjectTag(++tabCount, args[i], node); } else { printNullTag(++tabCount); } - + --tabCount; } @@ -403,7 +422,7 @@ try { String result = ""; - for(int i = 0; i < tabCount; ++i) { + for (int i = 0; i < tabCount; ++i) { result += '\t'; } result = result + s + "\n"; @@ -411,7 +430,7 @@ } catch (IOException ioe) { ExceptionListener listener = getExceptionListener(); - if(listener != null) { + if (listener != null) { listener.exceptionThrown(ioe); } } @@ -459,32 +478,32 @@ String name; LinkedHashMap attrs; String characters; - + public Tag(String name) { this.name = name; this.attrs = new LinkedHashMap(); this.characters = null; } - + public Tag(String name, String characters) { this.name = name; this.attrs = new LinkedHashMap(); this.characters = characters; } - + public boolean hasAttr(String attrName) { return attrs.get(attrName) != null; } - + public void addAttr(String attrName, String attrValue) { attrs.put(attrName, attrValue); } - + public String toStringOnOpenUnfinished() { String result = "<" + name; Iterator i = attrs.keySet().iterator(); - while(i.hasNext()) { + while (i.hasNext()) { String attrName = (String) i.next(); String attrValue = (String) attrs.get(attrName); @@ -496,19 +515,19 @@ public String toStringOnOpen() { return toStringOnOpenUnfinished() + ">"; } - + public String toStringShortForm() { return toStringOnOpenUnfinished() + "/>"; } - + public String toStringOnClose() { return ""; } - + public String toStringOnCharacters() { return XMLEncoder.escapeChars(characters); } - + public String toString() { return toStringOnOpen() + toStringOnCharacters() + toStringOnClose(); @@ -547,7 +566,7 @@ shortName = fullName.substring(fullName.lastIndexOf(".") + 1); } iNum = (Integer) numOfExemplars.get(shortName); - if(iNum == null) { + if (iNum == null) { numOfExemplars.put(shortName, new Integer(0)); result = shortName + "0"; } else {