diff options
Diffstat (limited to 'plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm')
13 files changed, 0 insertions, 2619 deletions
diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/BaseBeanInfo.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/BaseBeanInfo.java deleted file mode 100644 index 4f8a589d2..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/BaseBeanInfo.java +++ /dev/null @@ -1,850 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2006 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.beaninfo.vm; - -/* - - - */ - -import java.awt.Image; -import java.beans.*; -import java.lang.reflect.*; - -import org.eclipse.jem.beaninfo.common.IBaseBeanInfoConstants; - - -/** - * A BaseBeanInfo that provides common support for BeanInfos within the JEM environment. - * - * @since 1.1.0 - */ -public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanInfoConstants { - - // Constants to use to create all descriptors etc. - protected static java.util.ResourceBundle RESBUNDLE = java.util.ResourceBundle.getBundle("org.eclipse.jem.beaninfo.vm.beaninfo"); //$NON-NLS-1$ - - /** - * Bound indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String BOUND = "bound";//$NON-NLS-1$ - - /** - * Constrained indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String CONSTRAINED = "constrained";//$NON-NLS-1$ - - /** - * Property editor class indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String PROPERTYEDITORCLASS = "propertyEditorClass";//$NON-NLS-1$ - - /** - * Read Method indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String READMETHOD = "readMethod";//$NON-NLS-1$ - - /** - * Write method indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String WRITEMETHOD = "writeMethod";//$NON-NLS-1$ - - /** - * Displayname indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String DISPLAYNAME = "displayName";//$NON-NLS-1$ - - /** - * Expert indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String EXPERT = "expert";//$NON-NLS-1$ - - /** - * Hidden indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String HIDDEN = "hidden";//$NON-NLS-1$ - - /** - * Preferred indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String PREFERRED = "preferred";//$NON-NLS-1$ - - /** - * Short description indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String SHORTDESCRIPTION = "shortDescription";//$NON-NLS-1$ - - /** - * Customizer class indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String CUSTOMIZERCLASS = "customizerClass";//$NON-NLS-1$ - - /** - * In Default eventset indicator for apply property arguments. - * - * @since 1.1.0 - */ - public static final String INDEFAULTEVENTSET = "inDefaultEventSet";//$NON-NLS-1$ - - /** - * This is a Feature Attribute Key. When this key exists, the value is a java.lang.reflect.Field. It means this property - * is a field and not a getter/setter. The getter/setter will be ignored and the property type will be the type of the field. - * <p> - * At this time, do not use field on an indexed property. This is currently an undefined situation. - * - * @since 1.1.0 - */ - public static final String FIELDPROPERTY = "field"; //$NON-NLS-1$ - - /** - * Obscure indicator for apply property arguments. Obsure is a pre-defined attribute name too. That is where the obscure setting is stored. - * <p> - * Obsure means most users don't need it. In the future such features won't even be cached so as to reduce the in-memory costs. Currently this - * flag is ignored. - * - * @since 1.1.0 - */ - public static final String OBSCURE = "ivjObscure";//$NON-NLS-1$ - - /** - * Design time indicator for apply property arguments. Design time is a pre-defined attribute name too. That is where the design time setting is - * stored. - * <p> - * Design time means: - * <ul> - * <li>Not set: Will be a property that can be connected to, and shows on property sheet (if not hidden). - * <li><code>true</code>: Special property (it will show on property sheet if not hidden), but it can't be connected to. Usually this is a - * property that is fluffed up for the IDE purposes but doesn't have a get/set method. This means it is a property for design time and not for - * runtime. - * <li><code>false</code>: This property will not show up on property sheet but it can be connected to. - * </ul> - * - * @since 1.1.0 - */ - public static final String DESIGNTIMEPROPERTY = "ivjDesignTimeProperty"; //$NON-NLS-1$ - - /** - * EventAdapterClass indicator for apply property arguments. Event adapter class is a pre-defined attribute name too. That is where the event - * adapter is stored. - * <p> - * Adapter class for eventSetDescriptors that provide default no-op implementation of the interface methods. For example - * <code>java.awt.event.WindowListener</code> has an adapter of <code>java.awt.event.WindowAdapter</code>. What is stored is actually the - * class name, not the class itself. - * - * @since 1.1.0 - */ - public static final String EVENTADAPTERCLASS = "eventAdapterClass"; //$NON-NLS-1$ - - - public static final boolean JVM_1_3 = System.getProperty("java.version", "").startsWith("1.3"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - /** - * Empty args list for those descriptors that don't have arguments. - * @since 1.1.0 - */ - public static final Object[] EMPTY_ARGS = new Object[0]; - - /** - * Capitalize the string. This uppercases only the first character. So if you have property name of "abc" it will become "Abc". - * - * @param s - * @return string with first letter capitalized. - * - * @since 1.1.0 - */ - public static String capitalize(String s) { - if (s.length() == 0) { return s; } - char chars[] = s.toCharArray(); - chars[0] = Character.toUpperCase(chars[0]); - return new String(chars); - } - - /** - * Create a BeanDescriptor object given an array of keyword/value arguments. Use the keywords defined in this class, e.g. BOUND, EXPERT, etc. - * - * @param cls - * bean for which the bean descriptor is being created. - * @param args - * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc. or null if no args - * @return new bean descriptor - * - * @since 1.1.0 - */ - public static BeanDescriptor createBeanDescriptor(Class cls, Object[] args) { - Class customizerClass = null; - - if (args != null) { - /* Find the specified customizerClass */ - for (int i = 0; i < args.length; i += 2) { - if (CUSTOMIZERCLASS.equals(args[i])) { - customizerClass = (Class) args[i + 1]; - break; - } - } - } - - BeanDescriptor bd = new BeanDescriptor(cls, customizerClass); - - if (args != null) { - for (int i = 0; i < args.length; i += 2) { - String key = (String) args[i]; - Object value = args[i + 1]; - setFeatureDescriptorValue(bd, key, value); - } - } - return bd; - } - - /** - * Create a beans EventSetDescriptor given the following: - * - * @param cls - * The bean class - * @param name - * Name of event set - * @param args - * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc. or null if no args. - * @param lmds - * array of MethodDescriptors defining the listener methods - * @param listenerType - * type of listener - * @param addListenerName - * add listener method name - * @param removeListenerNameremove - * listener method name - * @return new event set descriptor - * @since 1.1.0 - */ - public static EventSetDescriptor createEventSetDescriptor(Class cls, String name, Object[] args, MethodDescriptor[] lmds, Class listenerType, - String addListenerName, String removeListenerName) { - EventSetDescriptor esd = null; - Class[] paramTypes = { listenerType}; - try { - java.lang.reflect.Method addMethod = null; - java.lang.reflect.Method removeMethod = null; - try { - /* get addListenerMethod with parameter types. */ - addMethod = cls.getMethod(addListenerName, paramTypes); - } catch (Exception ie) { - throwError(ie, java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_get_the_meth1_EXC_"), //$NON-NLS-1$ - new Object[] { addListenerName})); - } - ; - try { - /* get removeListenerMethod with parameter types. */ - removeMethod = cls.getMethod(removeListenerName, paramTypes); - } catch (Exception ie) { - throwError(ie, java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_get_the_meth1_EXC_"), //$NON-NLS-1$ - new Object[] { removeListenerName})); - } - ; - - esd = new EventSetDescriptor(name, listenerType, lmds, addMethod, removeMethod); - } catch (Exception ie) { - throwError(ie, java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_create_the_E1_EXC_"), //$NON-NLS-1$ - new Object[] { name})); - } - ; - if (args != null) { - // set the event set descriptor properties - for (int i = 0; i < args.length; i += 2) { - String key = (String) args[i]; - Object value = args[i + 1]; - if (INDEFAULTEVENTSET.equals(key)) { - esd.setInDefaultEventSet(((Boolean) value).booleanValue()); - } else - setFeatureDescriptorValue(esd, key, value); - } - } - return esd; - } - - /** - * Create a bean's MethodDescriptor. - * - * @param cls - * class of the method. - * @param name - * name of the method. - * @param args - * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc. or null if no args - * @param params - * parameter descriptors or <code>null</code> if no parameter descriptors. - * @param paramTypes - * parameter types - * @return new method descriptor - * - * @since 1.1.0 - */ - public static MethodDescriptor createMethodDescriptor(Class cls, String name, Object[] args, ParameterDescriptor[] params, Class[] paramTypes) { - MethodDescriptor md = null; - try { - java.lang.reflect.Method aMethod = null; - try { - /* getMethod with parameter types. */ - aMethod = cls.getMethod(name, paramTypes); - } catch (Exception ie) { - throwError(ie, java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_get_the_meth1_EXC_"), //$NON-NLS-1$ - new Object[] { name})); - } - ; - if (params != null && params.length > 0) - md = new MethodDescriptor(aMethod, params); - else - md = new MethodDescriptor(aMethod); - } catch (Exception ie) { - throwError(ie, java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_create_Method_EXC_"), //$NON-NLS-1$ - new Object[] { name})); - } - ; - if (args != null) { - // set the method properties - for (int i = 0; i < args.length; i += 2) { - String key = (String) args[i]; - Object value = args[i + 1]; - setFeatureDescriptorValue(md, key, value); - } - } - return md; - } - - private static PropertyDescriptor createOtherPropertyDescriptor(String name, Class cls) throws IntrospectionException { - Method readMethod = null; - Method writeMethod = null; - String base = capitalize(name); - Class[] parameters = new Class[0]; - - // First we try boolean accessor pattern - try { - readMethod = cls.getMethod("is" + base, parameters);//$NON-NLS-1$ - } catch (Exception ex1) { - } - if (readMethod == null) { - try { - // Else we try the get accessor pattern. - readMethod = cls.getMethod("get" + base, parameters);//$NON-NLS-1$ - } catch (Exception ex2) { - // Find by matching methods of the class - readMethod = findMethod(cls, "get" + base, 0);//$NON-NLS-1$ - } - } - - if (readMethod == null) { - // For write-only properties, find the write method - writeMethod = findMethod(cls, "set" + base, 1);//$NON-NLS-1$ - } else { - // In Sun's code, reflection fails if there are two - // setters with the same name and the first setter located - // does not have the same return type of the getter. - // This fixes that. - parameters = new Class[1]; - parameters[0] = readMethod.getReturnType(); - try { - writeMethod = cls.getMethod("set" + base, parameters);//$NON-NLS-1$ - } catch (Exception ex3) { - } - } - // create the property descriptor - if ((readMethod != null) || (writeMethod != null)) { - return new PropertyDescriptor(name, readMethod, writeMethod); - } else { - throw new IntrospectionException(java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_find_the_acc1_EXC_"), //$NON-NLS-1$ - new Object[] { name})); - } - } - - /** - * Create a beans parameter descriptor. - * - * @param name - * name of parameter - * @param args - * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc. or null if no args - * @return new parameter descriptor - * - * @since 1.1.0 - */ - public static ParameterDescriptor createParameterDescriptor(String name, Object[] args) { - ParameterDescriptor pd = null; - try { - pd = new ParameterDescriptor(); - } catch (Exception ie) { - throwError(ie, java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_create_Param1_EXC_"), //$NON-NLS-1$ - new Object[] { name})); - } - ; - // set the name - pd.setName(name); - if (args != null) { - // set the method properties - for (int i = 0; i < args.length; i += 2) { - String key = (String) args[i]; - Object value = args[i + 1]; - setFeatureDescriptorValue(pd, key, value); - } - } - return pd; - } - - private static Method GETCLASS; - - static { - try { - GETCLASS = Object.class.getMethod("getClass", null); //$NON-NLS-1$ - } catch (SecurityException e) { - } catch (NoSuchMethodException e) { - } - } - /** - * Create a property descriptor describing a field property. - * <p> - * Note: This is non-standard. The VE knows how to handle this, but any one else using BeanInfo will see this as a property with - * no getter or setter. - * @param name - * @param field - * @param args arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc. or null if no args - * @return - * - * @since 1.1.0 - */ - public static PropertyDescriptor createFieldPropertyDescriptor(String name, Field field, Object[] args) { - try { - PropertyDescriptor pd = new PropertyDescriptor(name, null, null); - pd.setValue(FIELDPROPERTY, field); // Set the field property so we know it is a field. - applyFieldArguments(pd, args); - // Need to set in a phony read method because Introspector will throw it away otherwise. We just use Object.getClass for this. - // We will ignore the property type for fields. If used outside of VE then it will look like a class property. - pd.setReadMethod(GETCLASS); - return pd; - } catch (IntrospectionException e) { - throwError(e, java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_create_the_P1_EXC_"), //$NON-NLS-1$ - new Object[] { name})); - return null; - } - } - - /** - * Create a bean's property descriptor. - * - * @param cls - * class of who owns the property (usually the bean). It is used to look up get/set methods for the property. - * @param name - * name of the property. It will use get{Name} and set{Name} to find get/set methods. - * @param args - * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc. - * @return new property descriptor - * - * @since 1.1.0 - */ - public static PropertyDescriptor createPropertyDescriptor(Class cls, String name, Object[] args) { - PropertyDescriptor pd = null; - try { - // Create assuming that the getter/setter follows reflection patterns - pd = new PropertyDescriptor(name, cls); - } catch (IntrospectionException e) { - // Try creating a property descriptor for read-only, write-only - // or if Sun's reflection fails - try { - pd = createOtherPropertyDescriptor(name, cls); - } catch (IntrospectionException ie) { - throwError(ie, java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_create_the_P1_EXC_"), //$NON-NLS-1$ - new Object[] { name})); - } - } - - applyPropertyArguments(pd, args, cls); - - return pd; - } - - - /** - * Create a new PropertyDescriptor based upon the PD sent in. It will clone the sent in one, and apply the args to override any specific setting. - * Class cls is used for finding read/write methods, if any. - * - * This is used when wanting to override only a few specific settings from a property descriptor from the super class. - * - * @param fromPDS - * The PropertyDescriptor array to find the entry to clone. It will be changed in place in the array. - * @param name - * The name of the property to find and clone and override. - * @param cls - * The class to use to find read/write methods in args. If no read/write methods specified, then this may be null. - * @param args - * The arguments to override from fromPD. arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc. or null if none to override - */ - public void replacePropertyDescriptor(PropertyDescriptor[] pds, String name, Class cls, Object[] args) { - PropertyDescriptor pd = null; - int iPD = findPropertyDescriptor(pds, name); - if (iPD == -1) - return; - PropertyDescriptor fromPD = pds[iPD]; - try { - - pd = pds[iPD] = new PropertyDescriptor(fromPD.getName(), null, null); - } catch (IntrospectionException e) { - throwError(e, java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_create_the_P1_EXC_"), //$NON-NLS-1$ - new Object[] { fromPD.getName()})); - } - - // Now copy over the contents of fromPD. - clonePropertySettings(fromPD, pd); - - // Now apply the overrides - applyPropertyArguments(pd, args, cls); - return; - } - - private void clonePropertySettings(PropertyDescriptor fromPD, PropertyDescriptor pd) { - try { - pd.setReadMethod(fromPD.getReadMethod()); - pd.setWriteMethod(fromPD.getWriteMethod()); - pd.setPropertyEditorClass(fromPD.getPropertyEditorClass()); - pd.setBound(fromPD.isBound()); - pd.setConstrained(fromPD.isConstrained()); - cloneFeatureSettings(fromPD, pd); - } catch (IntrospectionException e) { - throwError(e, java.text.MessageFormat.format(RESBUNDLE.getString("Cannot_create_the_P1_EXC_"), //$NON-NLS-1$ - new Object[] { fromPD.getName()})); - } - } - - private void cloneFeatureSettings(FeatureDescriptor fromFD, FeatureDescriptor fd) { - fd.setExpert(fromFD.isExpert()); - fd.setHidden(fromFD.isHidden()); - fd.setPreferred(fromFD.isPreferred()); - fd.setShortDescription(fromFD.getShortDescription()); - fd.setDisplayName(fromFD.getDisplayName()); - - java.util.Enumeration keys = fromFD.attributeNames(); - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - Object value = fromFD.getValue(key); - fd.setValue(key, value); - } - } - - /* - * The common property arguments between field and standard properties. - */ - private static boolean applyCommonPropertyArguments(PropertyDescriptor pd, String key, Object value) { - if (BOUND.equals(key)) { - pd.setBound(((Boolean) value).booleanValue()); - } else if (CONSTRAINED.equals(key)) { - pd.setConstrained(((Boolean) value).booleanValue()); - } else if (PROPERTYEDITORCLASS.equals(key)) { - pd.setPropertyEditorClass((Class) value); - } else if (FIELDPROPERTY.equals(key)) - return true; // This should not be applied except through createFieldProperty. - else - return false; - return true; - - } - - private static void applyPropertyArguments(PropertyDescriptor pd, Object[] args, Class cls) { - if (args != null) { - for (int i = 0; i < args.length; i += 2) { - String key = (String) args[i]; - Object value = args[i + 1]; - - if (!applyCommonPropertyArguments(pd, key, value)) { - if (READMETHOD.equals(key)) { - String methodName = (String) value; - Method method; - try { - method = cls.getMethod(methodName, new Class[0]); - pd.setReadMethod(method); - } catch (Exception e) { - throwError(e, java.text.MessageFormat.format(RESBUNDLE.getString("{0}_no_read_method_EXC_"), //$NON-NLS-1$ - new Object[] { cls, methodName})); - } - } else if (WRITEMETHOD.equals(key)) { - String methodName = (String) value; - try { - if (methodName == null) { - pd.setWriteMethod(null); - } else { - Method method; - Class type = pd.getPropertyType(); - method = cls.getMethod(methodName, new Class[] { type}); - pd.setWriteMethod(method); - } - } catch (Exception e) { - throwError(e, java.text.MessageFormat.format(RESBUNDLE.getString("{0}_no_write_method_EXC_"), //$NON-NLS-1$ - new Object[] { cls, methodName})); - } - } else { - // arbitrary value - setFeatureDescriptorValue(pd, key, value); - } - } - } - } - } - - private static void applyFieldArguments(PropertyDescriptor pd, Object[] args) { - if (args != null) { - for (int i = 0; i < args.length; i += 2) { - String key = (String) args[i]; - Object value = args[i + 1]; - - if (!applyCommonPropertyArguments(pd, key, value)) { - if (READMETHOD.equals(key)) { - // ignored for field. - } else if (WRITEMETHOD.equals(key)) { - // ignored for field. - } else { - // arbitrary value - setFeatureDescriptorValue(pd, key, value); - } - } - } - } - } - - /** - * Find the method by comparing (name & parameter size) against the methods in the class. This is an expensive call and should be used only if - * getMethod with specific parameter types can't find method. - * - * @return java.lang.reflect.Method - * @param aClass - * java.lang.Class - * @param methodName - * java.lang.String - * @param parameterCount - * int - */ - public static java.lang.reflect.Method findMethod(java.lang.Class aClass, java.lang.String methodName, int parameterCount) { - try { - /* - * Since this method attempts to find a method by getting all methods from the class, this method should only be called if getMethod - * cannot find the method. - */ - java.lang.reflect.Method methods[] = aClass.getMethods(); - for (int index = 0; index < methods.length; index++) { - java.lang.reflect.Method method = methods[index]; - if ((method.getParameterTypes().length == parameterCount) && (method.getName().equals(methodName))) { return method; } - ; - } - ; - } catch (java.lang.Throwable exception) { - return null; - } - ; - return null; - } - - /** - * Find a property descriptor of a given name in the list. - * - * @param pds - * The array of property descriptors to search, may be null. - * @param name - * The name to search for. - * @return The found property descriptor index, or -1 if not found. - */ - public static int findPropertyDescriptor(PropertyDescriptor[] pds, String name) { - for (int i = 0; i < pds.length; i++) { - if (name.equals(pds[i].getName())) - return i; - } - return -1; - } - - /* - * (non-Javadoc) - * - * @see java.beans.BeanInfo#getDefaultEventIndex() - */ - public int getDefaultEventIndex() { - return -1; - } - - /* - * (non-Javadoc) - * - * @see java.beans.BeanInfo#getDefaultPropertyIndex() - */ - public int getDefaultPropertyIndex() { - return -1; - } - - - /* (non-Javadoc) - * @see java.beans.SimpleBeanInfo#getBeanDescriptor() - */ - public BeanDescriptor getBeanDescriptor() { - // Default is to create an empty one. - return createBeanDescriptor(getBeanClass(), EMPTY_ARGS); - } - - /** - * Implementation for BeanInfo. This implementation will return the BeanInfo of the superclass. - * - * @see BeanInfo#getAdditionalBeanInfo() - * @since 1.1.0 - */ - public BeanInfo[] getAdditionalBeanInfo() { - try { - BeanInfo[] result = new BeanInfo[] { Introspector.getBeanInfo(getBeanClass().getSuperclass())}; - PropertyDescriptor[] oPDs = result[0].getPropertyDescriptors(); - PropertyDescriptor[] nPDs = overridePropertyDescriptors(oPDs); - if (oPDs != nPDs) - result[0] = new OverridePDBeanInfo(result[0], nPDs); - return result; - } catch (IntrospectionException e) { - return new BeanInfo[0]; - } - } - - private static class OverridePDBeanInfo implements BeanInfo { - - private BeanInfo originalBeanInfo; - - private PropertyDescriptor[] overridePDs; - - public OverridePDBeanInfo(BeanInfo bi, PropertyDescriptor[] pds) { - originalBeanInfo = bi; - overridePDs = pds; - } - - public BeanInfo[] getAdditionalBeanInfo() { - return originalBeanInfo.getAdditionalBeanInfo(); - } - - public BeanDescriptor getBeanDescriptor() { - return originalBeanInfo.getBeanDescriptor(); - } - - public int getDefaultEventIndex() { - return originalBeanInfo.getDefaultEventIndex(); - } - - public int getDefaultPropertyIndex() { - return originalBeanInfo.getDefaultPropertyIndex(); - } - - public EventSetDescriptor[] getEventSetDescriptors() { - return originalBeanInfo.getEventSetDescriptors(); - } - - public Image getIcon(int iconKind) { - return originalBeanInfo.getIcon(iconKind); - } - - public MethodDescriptor[] getMethodDescriptors() { - return originalBeanInfo.getMethodDescriptors(); - } - - public PropertyDescriptor[] getPropertyDescriptors() { - return overridePDs; - } - } - - /** - * Allow overrides to parent beaninfo. Subclasses should override this method if they wish to override and change any inherited properties. This - * allows removal of inherited properties or changes of specific properties (such as change from hidden to not hidden). - * - * Note: If there any changes, this must return a DIFFERENT array. If it returns the same array, then the changes will not be accepted. If just - * overriding, should use pds.clone() to get the new array and then change the specific entries. - * - * @param pds - * @return The new changed array or the same array if no changes. - * @since 1.1.0 - */ - protected PropertyDescriptor[] overridePropertyDescriptors(PropertyDescriptor[] pds) { - return pds; - } - - /** - * Get the bean class this beaninfo is for. Used by subclasses to quickly get the bean class without having to code it over and over. - * - * @return bean class for this beaninfo. - * - * @since 1.1.0 - */ - public abstract Class getBeanClass(); - - /** - * Called whenever the bean information class throws an exception. By default it prints a message and then a stacktrace to sys err. - * - * @param exception - * java.lang.Throwable - * @since 1.1.0 - */ - public void handleException(Throwable exception) { - System.err.println(RESBUNDLE.getString("UNCAUGHT_EXC_")); //$NON-NLS-1$ - exception.printStackTrace(); - } - - private static void setFeatureDescriptorValue(FeatureDescriptor fd, String key, Object value) { - if (DISPLAYNAME.equals(key)) { - fd.setDisplayName((String) value); - } else if (EXPERT.equals(key)) { - fd.setExpert(((Boolean) value).booleanValue()); - } else if (HIDDEN.equals(key)) { - fd.setHidden(((Boolean) value).booleanValue()); - } else if (PREFERRED.equals(key)) { - fd.setPreferred(((Boolean) value).booleanValue()); - if (JVM_1_3) { - // Bug in 1.3 doesn't preserve the preferred flag, so we will put it into the attributes too. - fd.setValue(PREFERRED, value); - } - } else if (SHORTDESCRIPTION.equals(key)) { - fd.setShortDescription((String) value); - } - // Otherwise assume an arbitrary-named value - // Assume that the FeatureDescriptor private hashTable\ - // contains only arbitrary-named attributes - else { - fd.setValue(key, value); - } - } - - /** - * Fatal errors are handled by calling this method. By default it throws an Error exception. - * - * @param e - * exception exception message placed into the new Error thrown. - * @param s - * message added to exception message. <code>null</code> if nothing to add. - * - * @throws Error - * turns exception into an Error. - * @since 1.1.0 - */ - protected static void throwError(Exception e, String s) { - throw new Error(e.toString() + " " + s);//$NON-NLS-1$ - } -} diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/basebeaninfonls.properties b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/basebeaninfonls.properties deleted file mode 100644 index 820de973a..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/basebeaninfonls.properties +++ /dev/null @@ -1,31 +0,0 @@ -############################################################################### -# Copyright (c) 2003, 2005 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -# -# $Source: /cvsroot/webtools/jeetools.move/webtools.javaee.git/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/Attic/basebeaninfonls.properties,v $ -# $Revision: 1.1 $ $Date: 2007/03/14 03:13:03 $ -# - - -# -# Properties for the IvjBeanInfo -# - -# -# IvjBeanInfo Strings -# -Cannot_get_the_meth1_EXC_ = IWAV0011E Cannot get the method {0}. -Cannot_create_the_E1_EXC_ = IWAV0012E Cannot create the EventSetDescriptor for {0}. -Cannot_create_Method_EXC_ = IWAV0013E Cannot create the MethodDescriptor for {0}. -Cannot_find_the_acc1_EXC_ = IWAV0014E Cannot find at least the write or read accessor for property {0}. -Cannot_create_Param1_EXC_ = IWAV0015E Cannot create the ParameterDescriptor for {0}. -Cannot_create_the_P1 = Cannot create the PropertyDescriptor for {0}. -{0}_no_read_method_EXC_ = IWAV0016E Class {0} doesn''t have the requested read accessor {1}. -{0}_no_write_method_EXC_ = IWAV0017E Class {0} doesn''t have the requested write accessor {1}. diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/beaninfo.properties b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/beaninfo.properties deleted file mode 100644 index d6eb1285d..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/beaninfo.properties +++ /dev/null @@ -1,32 +0,0 @@ -############################################################################### -# Copyright (c) 2003, 2005 IBM Corporation and others. -# All rights reserved. This program and the accompanying materials -# are made available under the terms of the Eclipse Public License v1.0 -# which accompanies this distribution, and is available at -# http://www.eclipse.org/legal/epl-v10.html -# -# Contributors: -# IBM Corporation - initial API and implementation -############################################################################### -# -# $Source: /cvsroot/webtools/jeetools.move/webtools.javaee.git/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/Attic/beaninfo.properties,v $ -# $Revision: 1.1 $ $Date: 2007/03/14 03:13:03 $ -# - - -# -# Properties for the VCE Beaninfo -# - -# -# IvjBeanInfo Strings -# -Cannot_get_the_meth1_EXC_ = IWAV0007E Cannot get the method {0}. -Cannot_create_the_E1_EXC_ = IWAV0008E Cannot create the EventSetDescriptor for {0}. -Cannot_create_Method_EXC_ = IWAV0009E Cannot create the MethodDescriptor for {0}. -Cannot_find_the_acc1_EXC_ = IWAV0010E Cannot find at least the write or read accessor for property {0}. -Cannot_create_Param1_EXC_ = IWAV0146E Cannot create the ParameterDescriptor for {0}. -Cannot_create_the_P1_EXC_ = IWAV0147E Cannot create the PropertyDescriptor for {0}. -{0}_no_read_method_EXC_ = IWAV0148E Class {0} doesn''t have the requested read accessor {1}. -{0}_no_write_method_EXC_ = IWAV0149E Class {0} doesn''t have the requested write accessor {1}. -UNCAUGHT_EXC_ = IWAV0123E --------- UNCAUGHT EXCEPTION --------- diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/BeanDescriptorEquality.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/BeanDescriptorEquality.java deleted file mode 100644 index 3c99de2db..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/BeanDescriptorEquality.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.beaninfo.vm; -/* - - - */ - -import java.beans.*; -/** - * Equality tester for BeanDescriptors - */ -public class BeanDescriptorEquality extends FeatureDescriptorEquality { - static void INIT() { - try { - MAP_EQUALITY.put(BeanDescriptor.class, (BeanDescriptorEquality.class).getConstructor(new Class[] {BeanDescriptor.class})); - } catch (NoSuchMethodException e) { - } - } - - /** - * Constructor for BeanDescriptorEquality. - */ - public BeanDescriptorEquality() { - super(); - } - - - public BeanDescriptorEquality(BeanDescriptor descr) { - super(descr); - } - - /** - * Calculate the hashcode for the current feature, add this - * to the hashcode received from super.calculateHashCode - * and return the new value. - * - * NOTE: for subclasses, it is MANDITORY that the first line be: - * int hashcode = super.calculateHashCode(); - * and the last line be: - * return hashcode*31 + (your calculated hashcode for just this subclass); - */ - protected int calculateHashCode() { - int hashcode = super.calculateHashCode(); - BeanDescriptor bd = (BeanDescriptor) fFeature; - int hc = bd.getBeanClass().hashCode(); - if (bd.getCustomizerClass() != null) - hc += bd.getCustomizerClass().hashCode(); - - return hashcode*31 + hc; - } - - public boolean equals(Object obj) { - if (identityTest(obj)) - return true; - if (!super.equals(obj)) - return false; - - BeanDescriptor ob = (BeanDescriptor) ((FeatureDescriptorEquality) obj).fFeature; - BeanDescriptor fb = (BeanDescriptor) fFeature; - - if (ob.getBeanClass() != fb.getBeanClass()) - return false; - if (ob.getCustomizerClass() != fb.getCustomizerClass()) - return false; - - return true; - } -} diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/EventSetDescriptorEquality.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/EventSetDescriptorEquality.java deleted file mode 100644 index b53aa8a72..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/EventSetDescriptorEquality.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.beaninfo.vm; -/* - - - */ - -import java.beans.*; -import java.util.*; -import java.lang.reflect.Method; -/** - * Equality tester for EventSetDescriptors - */ -public class EventSetDescriptorEquality extends FeatureDescriptorEquality { - - static void INIT() { - try { - MAP_EQUALITY.put(EventSetDescriptor.class, (EventSetDescriptorEquality.class).getConstructor(new Class[] {EventSetDescriptor.class})); - } catch (NoSuchMethodException e) { - } - } - - private ArrayList fListenerMethodDescriptors; // Array of MethodDescriptorEquality's. - - /** - * Constructor for EventSetDescriptorEquality. - */ - public EventSetDescriptorEquality() { - super(); - } - - - public EventSetDescriptorEquality(EventSetDescriptor descr) { - super(descr); - } - - /** - * A new feature is being set into this object, - * clear any cache members so that they can be reconstructed. - * - * NOTE: Subclasses - remember to call super.clearFeature(); - */ - protected void clearFeature() { - super.clearFeature(); - fListenerMethodDescriptors = null; - } - - protected ArrayList listenerMethodDescriptors() { - if (fListenerMethodDescriptors == null) { - MethodDescriptor[] mds = ((EventSetDescriptor) fFeature).getListenerMethodDescriptors(); - fListenerMethodDescriptors = new ArrayList(mds.length); - for (int i=0; i<mds.length; i++) - fListenerMethodDescriptors.add(new MethodDescriptorEquality(mds[i])); - } - return fListenerMethodDescriptors; - } - - /** - * Calculate the hashcode for the current feature, add this - * to the hashcode received from super.calculateHashCode - * and return the new value. - * - * NOTE: for subclasses, it is MANDITORY that the first line be: - * int hashcode = super.calculateHashCode(); - * and the last line be: - * return hashcode*31 + (your calculated hashcode for just this subclass); - */ - protected int calculateHashCode() { - int hashcode = super.calculateHashCode(); - EventSetDescriptor bd = (EventSetDescriptor) fFeature; - int hc = bd.getAddListenerMethod().hashCode(); - Method[] methods = bd.getListenerMethods(); - int mhc = 0; - for (int i=0; i<methods.length; i++) - mhc = mhc*31 + methods[i].hashCode(); - hc += mhc; - hc += listenerMethodDescriptors().hashCode(); - hc += bd.getListenerType().hashCode(); - hc += bd.getRemoveListenerMethod().hashCode(); - hc += (bd.isInDefaultEventSet() ? Boolean.TRUE : Boolean.FALSE).hashCode(); - hc += (bd.isUnicast() ? Boolean.TRUE : Boolean.FALSE).hashCode(); - - return hashcode*31 + hc; - } - - - public boolean equals(Object obj) { - if (identityTest(obj)) - return true; - - if (!super.equals(obj)) - return false; - - EventSetDescriptor oe = (EventSetDescriptor) ((FeatureDescriptorEquality) obj).fFeature; - EventSetDescriptor fe = (EventSetDescriptor) fFeature; - - EventSetDescriptorEquality oee = (EventSetDescriptorEquality) obj; - - if (!oe.getAddListenerMethod().equals(fe.getAddListenerMethod())) - return false; - if (!java.util.Arrays.equals(oe.getListenerMethods(), fe.getListenerMethods())) - return false; - if (oe.getListenerType() != fe.getListenerType()) - return false; - if (oe.getRemoveListenerMethod() != fe.getRemoveListenerMethod()) - return false; - if (oe.isInDefaultEventSet() != fe.isInDefaultEventSet()) - return false; - if (oe.isUnicast() != oe.isUnicast()) - return false; - - if (fListenerMethodDescriptors != null || oee.fListenerMethodDescriptors != null) { - // We are in a Map lookup situation, so one side has listener method equalities, so we will compare that way. - if (!oee.listenerMethodDescriptors().equals(listenerMethodDescriptors())) - return false; - } else { - // We are in the building the list phases, don't waste space building entire list. - MethodDescriptor[] ours = fe.getListenerMethodDescriptors(); - MethodDescriptor[] theirs = oe.getListenerMethodDescriptors(); - if (ours.length != theirs.length) - return false; - if (ours.length > 0) { - MethodDescriptorEquality workingOurs = new MethodDescriptorEquality(); - MethodDescriptorEquality workingThiers = new MethodDescriptorEquality(); - for (int i = 0; i < ours.length; i++) { - workingOurs.setFeature(ours[i]); - workingThiers.setFeature(theirs[i]); - if (!workingOurs.equals(workingThiers)) - return false; - } - } - } - - return true; - } -} diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/FeatureDescriptorEquality.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/FeatureDescriptorEquality.java deleted file mode 100644 index 9888393fd..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/FeatureDescriptorEquality.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.beaninfo.vm; -/* - - - */ - -import java.beans.*; -import java.util.*; -import java.lang.reflect.*; -/** - * This object is used to test for semantic equality (equals()) - * between feature objects. It is needed because Feature's don't - * provide a semantic equality, only an identity equality. Need - * semantic equality so that keys in map can be found equal - * semantically. - */ - -public class FeatureDescriptorEquality { - protected FeatureDescriptor fFeature; - - private HashMap fValues; // The key/values for this feature. We grab them out - // so that we don't have to keep re-getting them for equality - // compares. This is done the first time needed in the equals - // statement. - - private int fHashCode = 0; // Hashcode of this equality object. The hashcode for the feature is expensive - // so we will calculate it once (the assumption is that - // features once created aren't changed, which for our - // purposes here in beaninfo land is good). - - protected static HashMap MAP_EQUALITY = new HashMap(10); // Map from descriptor to equality type. - static { - try { - MAP_EQUALITY.put(FeatureDescriptor.class, (FeatureDescriptorEquality.class).getConstructor(new Class[] {FeatureDescriptor.class})); - } catch (NoSuchMethodException e) { - } - // Need to set up the others. - BeanDescriptorEquality.INIT(); - EventSetDescriptorEquality.INIT(); - IndexedPropertyDescriptorEquality.INIT(); - MethodDescriptorEquality.INIT(); - ParameterDescriptorEquality.INIT(); - } - - /** - * Create the appropriate descriptor equality for this object. - */ - public static FeatureDescriptorEquality createEquality(FeatureDescriptor descr) { - try { - return (FeatureDescriptorEquality) ((Constructor) MAP_EQUALITY.get(descr.getClass())).newInstance(new Object[] {descr}); - } catch (IllegalAccessException e) { - } catch (InstantiationException e) { - } catch (InvocationTargetException e) { - e.printStackTrace(); - } - return null; - } - - public FeatureDescriptorEquality() { - } - - /** - * NOTE: Every subclass needs to implement an override for the methods: - * calculateHashCode - * equals - * clearFeature - if it has any cache values - */ - - public FeatureDescriptorEquality(FeatureDescriptor feature) { - setFeature(feature); - } - - public final void setFeature(FeatureDescriptor feature) { - clearFeature(); - fFeature = feature; - } - - /** - * A new feature is being set into this object, - * clear any cache members so that they can be reconstructed. - * - * NOTE: Subclasses - remember to call super.clearFeature(); - */ - protected void clearFeature() { - fValues = null; - fHashCode = 0; - } - - public final int hashCode() { - if (fHashCode == 0) - fHashCode = calculateHashCode(); - return fHashCode; - } - - protected final HashMap values() { - if (fValues == null) { - fValues = new HashMap(5); - - Enumeration keys = fFeature.attributeNames(); - while (keys.hasMoreElements()) { - String key = (String) keys.nextElement(); - fValues.put(key, fFeature.getValue(key)); - } - } - return fValues; - } - - /** - * Calculate the hashcode for the current feature, add this - * to the hashcode received from super.calculateHashCode - * and return the new value. - * - * NOTE: for subclasses, it is MANDITORY that the first line be: - * int hashcode = super.calculateHashCode(); - * and the last line be: - * return hashcode*31 + (your calculated hashcode for just this subclass); - */ - protected int calculateHashCode() { - int hashcode = 0; - if (fFeature.getName() != null) - hashcode += fFeature.getName().hashCode(); - - if (fFeature.getDisplayName() != fFeature.getName()) - hashcode += fFeature.getDisplayName().hashCode(); - if (fFeature.getShortDescription() != fFeature.getDisplayName()) - hashcode += fFeature.getShortDescription().hashCode(); - - hashcode += (fFeature.isExpert() ? Boolean.TRUE : Boolean.FALSE).hashCode(); - hashcode += (fFeature.isHidden() ? Boolean.TRUE : Boolean.FALSE).hashCode(); - hashcode += (fFeature.isPreferred() ? Boolean.TRUE : Boolean.FALSE).hashCode(); - - hashcode += values().hashCode(); - return hashcode; - } - - /** - * equals: See if this is equal semantically. - * - * NOTE: Every subclass needs to implement this and - * the first few lines should be: - * if (identityTest()) - * return true; - * if (!super.equals(obj)) - * return false; - */ - - public boolean equals(Object obj) { - if (identityTest(obj)) - return true; - if (!(obj instanceof FeatureDescriptorEquality)) - return false; - - FeatureDescriptorEquality ofe = (FeatureDescriptorEquality) obj; - FeatureDescriptor of = ofe.fFeature; - - if (fFeature.getClass() != of.getClass()) - return false; - - if (!fFeature.getName().equals(of.getName())) - return false; - if (!fFeature.getDisplayName().equals(of.getDisplayName())) - return false; - if (!fFeature.getShortDescription().equals(of.getShortDescription())) - return false; - if (fFeature.isExpert() != of.isExpert() || - fFeature.isHidden() != of.isHidden() || - fFeature.isPreferred() != of.isPreferred()) - return false; - - if (!values().equals(ofe.values())) - return false; - return true; - } - - /* - * Identity test: Tests for quick identity of - * descriptors. If this returns true, then - * no other tests required. - */ - protected boolean identityTest(Object obj) { - if (!(obj instanceof FeatureDescriptorEquality)) - return false; - if (this == obj) - return true; - - if (((FeatureDescriptorEquality) obj).fFeature == fFeature) - return true; - - return false; - } -} diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/IndexedPropertyDescriptorEquality.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/IndexedPropertyDescriptorEquality.java deleted file mode 100644 index 42100e47d..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/IndexedPropertyDescriptorEquality.java +++ /dev/null @@ -1,91 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.beaninfo.vm; -/* - - - */ - -import java.beans.*; -/** - * IndexedPropertyDescriptor equality tester - */ -public class IndexedPropertyDescriptorEquality extends PropertyDescriptorEquality { - - static void INIT() { - try { - MAP_EQUALITY.put(IndexedPropertyDescriptor.class, (IndexedPropertyDescriptorEquality.class).getConstructor(new Class[] {PropertyDescriptor.class})); - MAP_EQUALITY.put(PropertyDescriptor.class, (IndexedPropertyDescriptorEquality.class).getConstructor(new Class[] {PropertyDescriptor.class})); - } catch (NoSuchMethodException e) { - } - } - - public IndexedPropertyDescriptorEquality() { - } - - public IndexedPropertyDescriptorEquality(PropertyDescriptor descr) { - super(descr); - } - /** - * Calculate the hashcode for the current feature, add this - * to the hashcode received from super.calculateHashCode - * and return the new value. - * - * NOTE: for subclasses, it is MANDITORY that the first line be: - * int hashcode = super.calculateHashCode(); - * and the last line be: - * return hashcode*31 + (your calculated hashcode for just this subclass); - */ - protected int calculateHashCode() { - int hashcode = super.calculateHashCode(); - if (fFeature instanceof IndexedPropertyDescriptor) { - IndexedPropertyDescriptor pd = (IndexedPropertyDescriptor) fFeature; - - int hc = pd.getIndexedPropertyType().hashCode(); - - if (pd.getIndexedReadMethod() != null) - hc += pd.getIndexedReadMethod().hashCode(); - if (pd.getIndexedWriteMethod() != null) - hc += pd.getIndexedWriteMethod().hashCode(); - return hashcode*31 + hc; - } else - return hashcode; - } - - public boolean equals(Object obj) { - if (!(obj instanceof FeatureDescriptorEquality)) - return false; - if (identityTest(obj)) - return true; - if (fFeature.getClass() != ((FeatureDescriptorEquality) obj).fFeature.getClass()) - return false; // If they aren't both PropertyDesciptors or IndexedPropertyDescriptors, then they don't match. - if (!super.equals(obj)) - return false; - - if (fFeature instanceof IndexedPropertyDescriptor) { - IndexedPropertyDescriptor op = (IndexedPropertyDescriptor) ((FeatureDescriptorEquality) obj).fFeature; - IndexedPropertyDescriptor fp = (IndexedPropertyDescriptor) fFeature; - - if (op.getIndexedPropertyType() != fp.getIndexedPropertyType()) - return false; - if (op.getIndexedReadMethod() != fp.getIndexedReadMethod()) - return false; - if (op.getIndexedWriteMethod() != fp.getIndexedWriteMethod()) - return false; - } - - return true; - } - - - - -} diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/MethodDescriptorEquality.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/MethodDescriptorEquality.java deleted file mode 100644 index a56159c1e..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/MethodDescriptorEquality.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.beaninfo.vm; -/* - - - */ - -import java.beans.*; -import java.util.*; -/** - * Equality tester for MethodDescriptors - */ -public class MethodDescriptorEquality extends FeatureDescriptorEquality { - - static void INIT() { - try { - MAP_EQUALITY.put(MethodDescriptor.class, (MethodDescriptorEquality.class).getConstructor(new Class[] {MethodDescriptor.class})); - } catch (NoSuchMethodException e) { - } - } - - private ArrayList fParameterDescriptors; // Array of ParameterDescriptorEquality's. - - public MethodDescriptorEquality() { - } - - public MethodDescriptorEquality(MethodDescriptor descr) { - super(descr); - } - - /** - * A new feature is being set into this object, - * clear any cache members so that they can be reconstructed. - * - * NOTE: Subclasses - remember to call super.clearFeature(); - */ - protected void clearFeature() { - super.clearFeature(); - fParameterDescriptors = null; - } - - protected ArrayList parameterDescriptors() { - if (fParameterDescriptors == null) { - ParameterDescriptor[] pds = ((MethodDescriptor) fFeature).getParameterDescriptors(); - if (pds != null) { - fParameterDescriptors = new ArrayList(pds.length); - for (int i=0; i<pds.length; i++) - fParameterDescriptors.add(new ParameterDescriptorEquality(pds[i])); - } - } - return fParameterDescriptors; - } - /** - * Calculate the hashcode for the current feature, add this - * to the hashcode received from super.calculateHashCode - * and return the new value. - * - * NOTE: for subclasses, it is MANDITORY that the first line be: - * int hashcode = super.calculateHashCode(); - * and the last line be: - * return hashcode*31 + (your calculated hashcode for just this subclass); - */ - protected int calculateHashCode() { - int hashcode = super.calculateHashCode(); - MethodDescriptor bd = (MethodDescriptor) fFeature; - int hc = bd.getMethod().hashCode(); - if (parameterDescriptors() != null) - hc += parameterDescriptors().hashCode(); - - return hashcode*31 + hc; - } - - public boolean equals(Object obj) { - if (identityTest(obj)) - return true; - - if (!super.equals(obj)) - return false; - - MethodDescriptorEquality oem = (MethodDescriptorEquality) obj; - MethodDescriptor om = (MethodDescriptor) oem.fFeature; - MethodDescriptor fm = (MethodDescriptor) fFeature; - - if (fm.getMethod() != om.getMethod()) - return false; - - if (fParameterDescriptors != null || oem.fParameterDescriptors != null) { - // We are in a Map lookup situation, so one side has listener method equalities, so we will compare that way. - if (parameterDescriptors() == null) - if (((MethodDescriptorEquality) obj).parameterDescriptors() != null) - return false; - else ; - else - if (!parameterDescriptors().equals(((MethodDescriptorEquality) obj).parameterDescriptors())) - return false; - } else { - // We are in the building the list phases, don't waste space building entire list. - ParameterDescriptor[] ours = fm.getParameterDescriptors(); - ParameterDescriptor[] theirs = om.getParameterDescriptors(); - if (ours == theirs) - return true; - else if (ours == null) - if (theirs != null) - return false; - else - ; - else if (theirs == null) - return false; - else if (ours.length != theirs.length) - return false; - else if (ours.length > 0) { - ParameterDescriptorEquality workingOurs = new ParameterDescriptorEquality(); - ParameterDescriptorEquality workingThiers = new ParameterDescriptorEquality(); - for (int i = 0; i < ours.length; i++) { - workingOurs.setFeature(ours[i]); - workingThiers.setFeature(theirs[i]); - if (!workingOurs.equals(workingThiers)) - return false; - } - } - } - - - return true; - } -} diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ModelingBeanInfo.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ModelingBeanInfo.java deleted file mode 100644 index 1344589c0..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ModelingBeanInfo.java +++ /dev/null @@ -1,863 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.beaninfo.vm; - -/* - - - */ - -import java.beans.*; -import java.io.IOException; -import java.io.ObjectOutputStream; -import java.lang.reflect.*; -import java.util.*; - -import org.eclipse.jem.beaninfo.common.IBaseBeanInfoConstants; -import org.eclipse.jem.beaninfo.vm.BaseBeanInfo; -import org.eclipse.jem.internal.beaninfo.common.*; -import org.eclipse.jem.internal.proxy.common.*; - -/** - * This class is the beaninfo class that is created when beaninfo modeling introspects a bean. Its purpose is to gather together and analyze the - * beaninfo. For example, it checks with the supertype beaninfo to see if all of the supertype's descriptors are included in this list. If they are, - * then it knows that it does a straight inheritance of the supertype's descriptors, and those descriptors can be removed from the list. This makes it - * easier on the model side so that there isn't a great proliferation of descriptors all describing the same properties. In that case they can be - * merged from the supertype model. If some are not found, then that means this beaninfo is trying to hide some of them, and in that case this is the - * definitive list and inheritance shouldn't be used on the model side. However, for those features which are essentially the inherited feature (i.e. - * the BeanInfo simply filtered out some inherited but not all), they will be returnable (by name). The IDE side will take these that are "inherited" - * and will return the actual structured feature from the inherited class. - * - * The test for seeing if the super feature is included in the beaninfo is first to see if the the feature is in the beaninfo by name, if it is then - * it is marked as included. Then a check is made on equality, if they are equal, then the feature is removed from the beaninfo list, but the merge - * flag is still left on, and removed inherited feature is added to the list of inherited features. If all inherited features are found, this list is - * cleared and flag is set which simply says merge all inherited. This allows merging to occur but it also allows overrides to occur. - * - * Note: Test for identity is different between JDK 1.5 and above and below. 1.5 and above, we can use actual equals() because the same descriptor is - * returned from inherited features. In 1.3, clones were always returned and equals() would answer false, so we need to create a special equality - * descriptor which turns the equals() into one that can test clones for semantic equality. See Java Bug ID#4996673 The problem was supposed to be - * fixed in 1.4 but it was not fixed. Originally a new clone was created each time a beaninfo was requested. That is no longer done in 1.4, but the - * processing to create the original beaninfo does a clone accidently under the covers. Looking at 1.5 it looks this was fixed, but it hasn't been - * tested here yet. - */ - -public abstract class ModelingBeanInfo implements ICallback { - - private static boolean PRE15; - static { - String version = System.getProperty("java.version", ""); //$NON-NLS-1$ //$NON-NLS-2$ - PRE15 = version.startsWith("1."); //$NON-NLS-1$ - if (PRE15) { - // Continue to check, get the revision. - int revision = 0; - if (version.length() > 2) { - int revEnd = version.indexOf('.', 2); - revision = version.length() > 2 ? Integer.parseInt(revEnd != -1 ? version.substring(2, revEnd) : version.substring(2)) : 0; - PRE15 = revision < 5; - } - } - } - - static class FeatureEqualitySet extends HashSet { - - /** - * Comment for <code>serialVersionUID</code> - * - * @since 1.1.0 - */ - private static final long serialVersionUID = -3744776740604328324L; - private FeatureDescriptorEquality workingKey; - - public FeatureEqualitySet(List features) { - super(features.size()); - // Get first feature to fiqure out type of working key. This will not be reentrant. - workingKey = FeatureDescriptorEquality.createEquality((FeatureDescriptor) features.get(0)); - this.addAll(features); - } - - /** - * @see java.util.Collection#add(Object) - */ - public boolean add(Object o) { - return super.add(FeatureDescriptorEquality.createEquality((FeatureDescriptor) o)); - } - - /** - * @see java.util.Collection#contains(Object) - */ - public boolean contains(Object o) { - workingKey.setFeature((FeatureDescriptor) o); - return super.contains(workingKey); - } - - } - - // The following fields indicate if the super info should be merged - // in on the model side. no merge means there were no inherited methods at all. So the - // beaninfo presented is definitive. If merge, then get...Descriptors will return just - // the ones for this level, and getSuper...Descriptors will return the inherited ones. - // Though in this case, if the returned super list is null, then that means use ALL of - // the inherited ones. - // The super list returns simply the names, don't need to have the full descriptors in that case. - protected boolean fMergeInheritedEvents = false, fMergeInheritedMethods = false, fMergeInheritedProperties = false; - - protected final BeanInfo fTargetBeanInfo; // The beaninfo being modeled. - - // Local descriptors - protected EventSetDescriptor[] fEventSets; - - protected MethodDescriptor[] fMethods; - - protected PropertyDescriptor[] fProperties; - - // Not inherited descriptor names, will be null if no merge or if merge all. This is list of names to NOT merge. It is usually shorter than the list to merge from super. - - // Methods are special. You can have duplicates, so name is not sufficient. - // So for methods, - // will use an array of Strings where: - // For each one the full signature - // will be in the list, e.g. "name:methodName(argtype,..." where argtype is the fullyqualified - // classname (using "." notation for inner classes), and using format "java.lang.String[]" for - // arrays. - // - // This is because even if there are no duplicates, it will take less time/space to simply create the entries - // then it would to create a set to see if there are duplicates and then create the final array. - protected String[] fNotInheritedEventSets; - - protected String[] fNotInheritedMethods; - - protected String[] fNotInheritedProperties; - - protected int doFlags; - - /** - * Method used to do introspection and create the appropriate ModelingBeanInfo - * - * This will always introspect. - */ - public static ModelingBeanInfo introspect(Class introspectClass, int doFlags) throws IntrospectionException { - return introspect(introspectClass, true, doFlags); - } - - /** - * Method used to do introspection and create the appropriate ModelingBeanInfo - * - * introspectIfNoBeanInfo: If this is true, then if no explicit beaninfo was found for this class, then introspection will be done anyway. The - * Introspector will use reflection for local methods/events/properties of this class and then add in the results of the superclass introspection. - * If this parameter is false, then if the explicit beaninfo is not found, then no introspection will be done and null will be returned. - */ - public static ModelingBeanInfo introspect(Class introspectClass, boolean introspectIfNoBeanInfo, int doFlags) throws IntrospectionException { - if (!Beans.isDesignTime()) - Beans.setDesignTime(true); // Since this a jem beaninfo specific vm, we should also be considered design time. - if (!introspectIfNoBeanInfo) { - // Need to check if the beaninfo is explicitly supplied. - // If not, then we return null. - // The checks will be the same that Introspector will use. - - boolean found = false; - // 1. Is there a BeanInfo class in the same package - if (!classExists(introspectClass.getName() + "BeanInfo", introspectClass)) { //$NON-NLS-1$ - // 2. Is this class a BeanInfo class for itself. - if (!(BeanInfo.class).isAssignableFrom(introspectClass)) { - // 3. Can this class be found in the Beaninfo searchpath. - String[] searchPath = Introspector.getBeanInfoSearchPath(); - int startClassname = introspectClass.getName().lastIndexOf(".") + 1; //$NON-NLS-1$ - String biName = "." + introspectClass.getName().substring(startClassname) + "BeanInfo"; //$NON-NLS-1$ //$NON-NLS-2$ - for (int i = 0; i < searchPath.length; i++) { - if (classExists(searchPath[i] + biName, introspectClass)) { - found = true; - break; - } - } - } else - found = true; - } else - found = true; - - if (!found) - return null; - } - - BeanInfo bInfo = Introspector.getBeanInfo(introspectClass); - Class superClass = introspectClass.getSuperclass(); - - if (superClass == null) - return PRE15 ? (ModelingBeanInfo) new ModelingBeanInfoPre15(bInfo, doFlags) : new ModelingBeanInfo15(bInfo, doFlags); - else - return PRE15 ? (ModelingBeanInfo) new ModelingBeanInfoPre15(bInfo, Introspector.getBeanInfo(superClass), doFlags) : new ModelingBeanInfo15(bInfo, - Introspector.getBeanInfo(superClass), doFlags); - } - - /** - * See if this class exists, first in the class loader of the sent class, then in the system loader, then the bootstrap loader, and finally the - * current thread context class loader. - */ - protected static boolean classExists(String className, Class fromClass) { - if (fromClass.getClassLoader() != null) - try { - fromClass.getClassLoader().loadClass(className); - return true; - } catch (ClassNotFoundException e) { - } - if (ClassLoader.getSystemClassLoader() != null) - try { - ClassLoader.getSystemClassLoader().loadClass(className); - return true; - } catch (ClassNotFoundException e) { - } - try { - Class.forName(className); - return true; - } catch (ClassNotFoundException e) { - } - - try { - // Use the classloader from the current Thread. - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - cl.loadClass(className); - return true; - } catch (ClassNotFoundException e) { - } - - return false; - - } - - /** - * Used only for Object since that is the only bean that doesn't have a superclass. Superclass beaninfo required for all other classes. If this is - * constructed then this means no merge and the list is definitive. - */ - protected ModelingBeanInfo(BeanInfo beanInfo, int doFlags) { - fTargetBeanInfo = beanInfo; - this.doFlags = doFlags; - } - - protected ModelingBeanInfo(BeanInfo beanInfo, BeanInfo superBeanInfo, int doFlags) { - this(beanInfo, doFlags); - - // Now go through the beaninfo to determine the merge state. - // The default is no merge. - - if ((doFlags & IBeanInfoIntrospectionConstants.DO_EVENTS) != 0) { - List full = addAll(beanInfo.getEventSetDescriptors()); - List inherited = addAll(superBeanInfo.getEventSetDescriptors()); - - fMergeInheritedEvents = stripList(full, inherited); - if (fMergeInheritedEvents) { - if (!full.isEmpty()) - fEventSets = (EventSetDescriptor[]) full.toArray(new EventSetDescriptor[full.size()]); - if (!inherited.isEmpty()) - createEventArray(inherited); // This is actually a list of those NOT inherited. - } - } - - if ((doFlags & IBeanInfoIntrospectionConstants.DO_METHODS) != 0) { - List full = addAll(beanInfo.getMethodDescriptors()); - List inherited = addAll(superBeanInfo.getMethodDescriptors()); - - fMergeInheritedMethods = stripList(full, inherited); - if (fMergeInheritedMethods) { - if (!full.isEmpty()) - fMethods = (MethodDescriptor[]) full.toArray(new MethodDescriptor[full.size()]); - if (!inherited.isEmpty()) - createMethodEntries(inherited); // This is actually a list of those NOT inherited. - } - } - - if ((doFlags & IBeanInfoIntrospectionConstants.DO_PROPERTIES) != 0) { - List full = addAll(beanInfo.getPropertyDescriptors()); - List inherited = addAll(superBeanInfo.getPropertyDescriptors()); - - fMergeInheritedProperties = stripList(full, inherited); - if (fMergeInheritedProperties) { - if (!full.isEmpty()) - fProperties = (PropertyDescriptor[]) full.toArray(new PropertyDescriptor[full.size()]); - if (!inherited.isEmpty()) - createPropertyArray(inherited); // This is actually a list of those NOT inherited. - } - } - } - - protected void createEventArray(List features) { - fNotInheritedEventSets = createDescriptorNames(features); - } - - protected void createMethodEntries(List features) { - int s = features.size(); - fNotInheritedMethods = new String[s]; - for (int i = 0; i < s; i++) { - fNotInheritedMethods[i] = longName((MethodDescriptor) features.get(i)); - } - } - - protected String longName(MethodDescriptor md) { - String n = md.getName(); - StringBuffer sb = new StringBuffer(n.length() + 20); - sb.append(n); - sb.append(':'); - Method m = md.getMethod(); - sb.append(m.getName()); - sb.append('('); - Class[] parms = m.getParameterTypes(); - for (int j = 0; j < parms.length; j++) { - if (j > 0) - sb.append(','); - if (!parms[j].isArray()) - sb.append(parms[j].getName().replace('$', '.')); - else { - Class finalType = parms[j].getComponentType(); - int insrt = sb.length(); - while (finalType.isArray()) { - sb.append("[]"); //$NON-NLS-1$ - finalType = finalType.getComponentType(); - } - sb.insert(insrt, finalType.getName().replace('$', '.')); - } - } - return sb.toString(); - } - - protected void createPropertyArray(List features) { - fNotInheritedProperties = createDescriptorNames(features); - } - - protected String[] createDescriptorNames(List features) { - String[] result = new String[features.size()]; - for (int i = 0; i < result.length; i++) { - result[i] = ((FeatureDescriptor) features.get(i)).getName(); - } - return result; - } - - protected List addAll(Object[] set) { - if (set != null) { - ArrayList l = new ArrayList(set.length); - for (int i = 0; i < set.length; i++) { - l.add(set[i]); - } - return l; - } else - return Collections.EMPTY_LIST; - } - - /** - * If this returns true, then all of the super class's events should be merged in. If it returns false, then the events returned are it, there are - * no others. - */ - public boolean isMergeInheritedEvents() { - return fMergeInheritedEvents; - } - - /** - * If this returns true, then all of the super class's methods should be merged in. If it returns false, then the methods returned are it, there - * are no others. - */ - public boolean isMergeInheritedMethods() { - return fMergeInheritedMethods; - } - - /** - * If this returns true, then all of the super class's properties should be merged in. If it returns false, then the properties returned are it, - * there are no others. - */ - public boolean isMergeInheritedProperties() { - return fMergeInheritedProperties; - } - - public BeanInfo[] getAdditionalBeanInfo() { - return fTargetBeanInfo.getAdditionalBeanInfo(); - } - - public BeanDescriptor getBeanDescriptor() { - return fTargetBeanInfo.getBeanDescriptor(); - } - - public EventSetDescriptor[] getEventSetDescriptors() { - return fMergeInheritedEvents ? fEventSets : fTargetBeanInfo.getEventSetDescriptors(); - } - - public java.awt.Image getIcon(int iconKind) { - return fTargetBeanInfo.getIcon(iconKind); - } - - public MethodDescriptor[] getMethodDescriptors() { - return fMergeInheritedMethods ? fMethods : fTargetBeanInfo.getMethodDescriptors(); - } - - public PropertyDescriptor[] getPropertyDescriptors() { - return fMergeInheritedProperties ? fProperties : fTargetBeanInfo.getPropertyDescriptors(); - } - - public String[] getNotInheritedEventSetDescriptors() { - return fNotInheritedEventSets; - } - - public String[] getNotInheritedMethodDescriptors() { - return fNotInheritedMethods; - } - - public String[] getNotInheritedPropertyDescriptors() { - return fNotInheritedProperties; - } - - protected String computeKey(FeatureDescriptor feature) { - return feature instanceof MethodDescriptor ? longName((MethodDescriptor) feature) : feature.getName(); - } - - /* - * Strip the list down using the Equality objects. - */ - protected boolean stripList(List fullList, List inheritedList) { - // The process is to create a boolean list mirroring the inheritedList. - // This boolean list indicates if the corresponding (by index) - // entry from the inheritedList is to be retained in the final computed - // list. - // - // A Hashmap is created where the key is the computedKey from the inheritedList - // and the value is the index into the inheritedList. This is so that we can quickly determine if the - // entry is matching. - // - // Then the fullList will be stepped through and see if there is - // an entry in the Hashmap for it. If there is an entry, then - // the entry is checked to see if it is semantically equal. - // If it is, then the boolean list entry is marked so that - // the inheritedList entry will be retained, the fullList entry removed and the counter - // of the number of entries in the inheritedList copy is incremented. - // If they aren't semantically equal, then we know that this is - // an override. In that case, the fullList entry is kept, the inheritedList - // entry is not retained, but we don't prevent merge later. - // - // If the fullList entry is not found in the HashMap, then we know it is not - // from the inheritedList, so it will be retained in the fullList. - // - // If we get all of the way through, then we know that what is left - // in fullList is just this level. - // - // When we return we know that - // a) fullList has only the features that are found at the local level - // b) inheritedList if not empty contains the ones from super that SHOULD NOT be inherited. - // If it is empty, then if this method returns true, then ALL should be inherited, - // or if this method returns false, then it doesn't matter because we aren't merging any. - // - // All of this is based upon the assumption that the list can - // get quite large (which it does for javax.swing) and that - // a simple n-squared order search would be too slow. - - if (fullList.isEmpty()) { - return false; // There are none in the full list, so there should be none, and don't merge. - } else if (inheritedList.isEmpty()) - return false; // There are no inheritedList features, so treat as no merge. - - // We have some features and some inheritedList features, so we need to go through the lists. - - // Create a working copy of the FeatureDescriptorEquality for fullList and stripList and just reuse them - FeatureDescriptorEquality workingStrip = FeatureDescriptorEquality.createEquality((FeatureDescriptor) inheritedList.get(0)); - FeatureDescriptorEquality workingFull = FeatureDescriptorEquality.createEquality((FeatureDescriptor) fullList.get(0)); - - int inheritedSize = inheritedList.size(); - boolean[] copy = new boolean[inheritedSize]; - - HashMap inheritedMap = new HashMap(inheritedSize); - for (int i = 0; i < inheritedSize; i++) { - FeatureDescriptor f = (FeatureDescriptor) inheritedList.get(i); - String key = computeKey(f); - Object value = inheritedMap.get(key); - if (value == null) - inheritedMap.put(key, new Integer(i)); - else { - // Shouldn't occur. - } - - } - - // When we are done with this processing, inheritedList will contain the super that should not be used, and full list will contain only the locals - // (those defined at this class level).; - int inheritedRetained = 0; - Iterator fullItr = fullList.iterator(); - // Continue while we've retained less than the full super amount. If we've retained all of the inheritedList, there is no - // need to continue processing the fullList because there can't possibly be any inheritedList entries left to find. - while (inheritedRetained < inheritedSize && fullItr.hasNext()) { - FeatureDescriptor f = (FeatureDescriptor) fullItr.next(); - boolean foundFull = false; - Object index = inheritedMap.get(computeKey(f)); - if (index != null) { - workingFull.setFeature(f); - int ndx = ((Integer) index).intValue(); - workingStrip.setFeature((FeatureDescriptor) inheritedList.get(ndx)); - if (workingFull.equals(workingStrip)) { - // They are semantically identical, so retain in the inheritedList. - copy[ndx] = true; - foundFull = true; - inheritedRetained++; - } - } - - if (foundFull) { - // We found the inheritedList entry semantically equal in the full list somewhere, so we need to remove the full entry. - fullItr.remove(); - } - } - - if (inheritedRetained == inheritedSize) { - inheritedList.clear(); // All were found in inheritedList, so just clear the inheritedList and return just what was left in the found. - // Those in full found in super had been removed from full during the processing. - return true; // We merge with all inherited. - } else if (inheritedRetained != 0) { - // Some were retained, take out of the list those that were retained. - // When done the list will contain those that should be dropped from the inherited list. - // We start from end because the actual number of bytes moved overall will be less than if we started from the front. - for (ListIterator itr = inheritedList.listIterator(inheritedList.size()); itr.hasPrevious();) { - int i = itr.previousIndex(); - itr.previous(); // To back up the itr so that remove can remove it. We actually don't care what the value is. - if (copy[i]) - itr.remove(); - } - return true; // We merge, and the list is not empty but it did have some removed, so we leave the list alone. Those are not inherited. - } else - return false; // All were removed (retained == 0). None were retained. So we just don't do a merge. The list will be ignored. - } - - // The modeling beaninfo is also used to send itself back in serialized mode as a callback. - - private IVMCallbackServer vmServer; - - private int callbackID; - - /* - * (non-Javadoc) - * - * @see org.eclipse.jem.internal.proxy.common.ICallback#initializeCallback(org.eclipse.jem.internal.proxy.common.IVMServer, int) - */ - public void initializeCallback(IVMCallbackServer vmServer, int callbackID) { - this.vmServer = vmServer; - this.callbackID = callbackID; - } - - public void send() throws IOException, CommandException { - if (doFlags != 0) { - ObjectOutputStream stream = new ObjectOutputStream(vmServer.requestStream(callbackID, 0)); - if ((doFlags & IBeanInfoIntrospectionConstants.DO_BEAN_DECOR) != 0) - sendBeanDecorator(stream); - if ((doFlags & IBeanInfoIntrospectionConstants.DO_PROPERTIES) != 0) - sendPropertyDecorators(stream); - if ((doFlags & IBeanInfoIntrospectionConstants.DO_METHODS) != 0) - sendMethodDecorators(stream); - if ((doFlags & IBeanInfoIntrospectionConstants.DO_EVENTS) != 0) - sendEventDecorators(stream); - stream.writeInt(IBeanInfoIntrospectionConstants.DONE); - stream.close(); - } - } - - /** - * Called by IDE to send the bean decorator information back through the callback. - * @throws CommandException - * @throws IOException - * - * @since 1.1.0 - */ - public void sendBeanDecorator(ObjectOutputStream stream) throws IOException, CommandException { - BeanRecord br = new BeanRecord(); - BeanDescriptor bd = getBeanDescriptor(); - - if (bd != null) { - br.customizerClassName = getClassName(bd.getCustomizerClass()); - br.mergeInheritedProperties = isMergeInheritedProperties(); - br.mergeInheritedOperations = isMergeInheritedMethods(); - br.mergeInheritedEvents = isMergeInheritedEvents(); - br.notInheritedPropertyNames = getNotInheritedPropertyDescriptors(); - br.notInheritedOperationNames = getNotInheritedMethodDescriptors(); - br.notInheritedEventNames = getNotInheritedEventSetDescriptors(); - fill(bd, br, BEAN_RECORD_TYPE); - } - stream.writeInt(IBeanInfoIntrospectionConstants.BEAN_DECORATOR_SENT); - stream.writeObject(br); - } - - /** - * Called by IDE to send the property decorators information back through the callback. - * - * @throws CommandException - * @throws IOException - * @since 1.1.0 - */ - public void sendPropertyDecorators(ObjectOutputStream stream) throws IOException, CommandException { - PropertyDescriptor[] properties = getPropertyDescriptors(); - if (properties != null && properties.length > 0) { - // Now start writing the records. - stream.writeInt(IBeanInfoIntrospectionConstants.PROPERTY_DECORATORS_SENT); - stream.writeInt(properties.length); - for (int i = 0; i < properties.length; i++) { - PropertyDescriptor pd = properties[i]; - // Much of the two types are common, so if indexed, fill in the index part and then pass on to property part. - PropertyRecord usepr = null; - int useType = 0; - if (pd.getClass() == IndexedPropertyDescriptor.class) { - IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd; - IndexedPropertyRecord ipr = new IndexedPropertyRecord(); - usepr = ipr; - useType = INDEXEDPROPERTY_RECORD_TYPE; - ipr.indexedReadMethod = getReflectedMethodRecord(ipd.getIndexedReadMethod()); - ipr.indexedWriteMethod = getReflectedMethodRecord(ipd.getIndexedWriteMethod()); - ipr.indexedPropertyTypeName = getClassName(ipd.getIndexedPropertyType()); - } else { - usepr = new PropertyRecord(); - useType = PROPERTY_RECORD_TYPE; - } - usepr.propertyEditorClassName = getClassName(pd.getPropertyEditorClass()); - usepr.propertyTypeName = getClassName(pd.getPropertyType()); - usepr.readMethod = getReflectedMethodRecord(pd.getReadMethod()); - usepr.writeMethod = getReflectedMethodRecord((pd.getWriteMethod())); - usepr.bound = pd.isBound(); - usepr.constrained = pd.isConstrained(); - usepr.designTime = null; - usepr.field = null; - fill(pd, usepr, useType); - stream.writeObject(usepr); - } - } - } - - /** - * Called by IDE to send the method decorators information back through the callback. - * - * @throws CommandException - * @throws IOException - * @since 1.1.0 - */ - public void sendMethodDecorators(ObjectOutputStream stream) throws IOException, CommandException { - MethodDescriptor[] methods = getMethodDescriptors(); - if (methods != null && methods.length > 0) { - // Now start writing the records. - stream.writeInt(IBeanInfoIntrospectionConstants.METHOD_DECORATORS_SENT); - stream.writeInt(methods.length); - for (int i = 0; i < methods.length; i++) { - MethodRecord mr = new MethodRecord(); - fill(mr, methods[i]); - stream.writeObject(mr); - } - } - } - - /** - * Fill in a MethodRecord from the MethodDescriptor. - * @param mr - * @param md - * - * @since 1.1.0 - */ - protected void fill(MethodRecord mr, MethodDescriptor md) { - mr.methodForDescriptor = getReflectedMethodRecord(md.getMethod()); - ParameterDescriptor[] parms = md.getParameterDescriptors(); - if (parms == null) - mr.parameters = null; - else { - mr.parameters = new ParameterRecord[parms.length]; - for (int j = 0; j < parms.length; j++) { - ParameterRecord pr = new ParameterRecord(); - fill(parms[j], pr, PARAMETER_RECORD_TYPE); - mr.parameters[j] = pr; - } - } - fill(md, mr, METHOD_RECORD_TYPE); - } - - /** - * Called by IDE to send the event set decorators information back through the callback. - * - * @throws CommandException - * @throws IOException - * @since 1.1.0 - */ - public void sendEventDecorators(ObjectOutputStream stream ) throws IOException, CommandException { - EventSetDescriptor[] events = getEventSetDescriptors(); - if (events != null && events.length > 0) { - // Now start writing the records. - stream.writeInt(IBeanInfoIntrospectionConstants.EVENT_DECORATORS_SENT); - stream.writeInt(events.length); - for (int i = 0; i < events.length; i++) { - EventSetDescriptor ed = events[i]; - EventSetRecord er = new EventSetRecord(); - er.addListenerMethod = getReflectedMethodRecord(ed.getAddListenerMethod()); - MethodDescriptor[] mds = ed.getListenerMethodDescriptors(); - if (mds == null) - er.listenerMethodDescriptors = null; - else { - er.listenerMethodDescriptors = new MethodRecord[mds.length]; - for (int j = 0; j < mds.length; j++) { - fill(er.listenerMethodDescriptors[j] = new MethodRecord(), mds[j]); - } - } - er.listenerTypeName = getClassName(ed.getListenerType()); - er.removeListenerMethod = getReflectedMethodRecord(ed.getRemoveListenerMethod()); - er.inDefaultEventSet = ed.isInDefaultEventSet(); - er.unicast = ed.isUnicast(); - er.eventAdapterClassName = null; - fill(ed, er, EVENTSET_RECORD_TYPE); - stream.writeObject(er); - } - } - } - - protected static final int BEAN_RECORD_TYPE = 0; - - protected static final int PROPERTY_RECORD_TYPE = 1; - - protected static final int INDEXEDPROPERTY_RECORD_TYPE = 2; - - protected static final int METHOD_RECORD_TYPE = 3; - - protected static final int PARAMETER_RECORD_TYPE = 4; - - protected static final int EVENTSET_RECORD_TYPE = 5; - - /** - * Fill in the special attr/values for the given record type. The default handles the standard ones. - * - * @param record - * @param descr - * @param attributeName - * @param recordType - * type of record ultimately being processed. - * @return <code>true</code> if this attribute is a special one and processed, <code>false</code> if not special and should be added to - * attributes list transferred to IDE. - * - * @see ModelingBeanInfo#PROPERTY_RECORD_TYPE - * @since 1.1.0 - */ - protected boolean fillFromAttributes(FeatureRecord record, FeatureDescriptor descr, String attributeName, int recordType) { - switch (recordType) { - case INDEXEDPROPERTY_RECORD_TYPE: - case PROPERTY_RECORD_TYPE: - if (BaseBeanInfo.DESIGNTIMEPROPERTY.equals(attributeName)) { - ((PropertyRecord) record).designTime = (Boolean) descr.getValue(attributeName); - return true; - } else if (BaseBeanInfo.FIELDPROPERTY.equals(attributeName)) { - Field f = (Field) descr.getValue(attributeName); - // We have a field, set the property type to this since we couldn't correctly create this otherwise. - PropertyRecord pr = (PropertyRecord) record; - pr.propertyTypeName = getClassName(f.getType()); - pr.field = getReflectedFieldRecord(f); - pr.readMethod = null; // Need to wipe out our dummy. - pr.writeMethod = null; // Or if it set, not valid for a field. - return true; - } - break; - case EVENTSET_RECORD_TYPE: - if (BaseBeanInfo.EVENTADAPTERCLASS.equals(attributeName)) { - ((EventSetRecord) record).eventAdapterClassName = (String) descr.getValue(attributeName); - return true; - } - break; - default: - break; // Didn't handle it. - } - return false; - } - - /** - * Fill in the feature portion of the Descriptor into the record. We can be reusing some records (so we don't keep allocating when not needed), so - * we will null out unset fields. - * - * @param descr - * @param record - * @param recordType - * type of record ultimately being processed. Used for fillFromAttributes. - * - * @see ModelingBeanInfo#PROPERTY_RECORD_TYPE - * @since 1.1.0 - */ - protected void fill(FeatureDescriptor descr, FeatureRecord record, int recordType) { - record.name = descr.getName(); - String dn = descr.getDisplayName(); - if (!record.name.equals(dn)) - record.displayName = dn; // display name returns name if display name not set. We don't want to send it if identical. (Note some Beaninfos are setting displayname the same text but not same string). - else - record.displayName = null; - String shd = descr.getShortDescription(); - if (!dn.equals(shd)) - record.shortDescription = shd; // short description returns displayname if short description not set. We don't want to send it if - // identical. - else - record.shortDescription = null; - record.expert = descr.isExpert(); - record.hidden = descr.isHidden(); - record.preferred = descr.isPreferred(); - record.category = null; // Clear out in case not set. - Enumeration attrs = descr.attributeNames(); - if (attrs.hasMoreElements()) { - // We don't have a way of knowing how many there are ahead of time, so we will build into lists and then turn into arrays at the end. - List names = new ArrayList(); - List values = new ArrayList(); - while (attrs.hasMoreElements()) { - String attrName = (String) attrs.nextElement(); - if (attrName.equals(IBaseBeanInfoConstants.CATEGORY)) - record.category = (String) descr.getValue(IBaseBeanInfoConstants.CATEGORY); - else if (attrName.equals(BaseBeanInfo.PREFERRED)) { - // A bug in Java 1.3, doing setPreferred was lost. So for those also stored it in attributes. So if set here, then use it. - record.preferred = ((Boolean) descr.getValue(BaseBeanInfo.PREFERRED)).booleanValue(); - } else if (!fillFromAttributes(record, descr, attrName, recordType)) { - // Just copy accross. FillfromAttributes didn't handle it. - FeatureAttributeValue fv = new FeatureAttributeValue(); - fv.setValue(descr.getValue(attrName)); - names.add(attrName); - values.add(fv); - } - } - if (!names.isEmpty()) { - record.attributeNames = (String[]) names.toArray(new String[names.size()]); - record.attributeValues = (FeatureAttributeValue[]) values.toArray(new FeatureAttributeValue[values.size()]); - } else { - record.attributeNames = null; - record.attributeValues = null; - } - } else { - record.attributeNames = null; - record.attributeValues = null; - } - - } - - /* - * Get the classname from the class. If classs is null, then this return null. - */ - private String getClassName(Class classs) { - return classs != null ? classs.getName() : null; - } - - private ReflectMethodRecord getReflectedMethodRecord(Method method) { - if (method != null) { - ReflectMethodRecord rmr = new ReflectMethodRecord(); - rmr.className = getClassName(method.getDeclaringClass()); - rmr.methodName = method.getName(); - Class[] parmTypes = method.getParameterTypes(); - if (parmTypes.length > 0) { - rmr.parameterTypeNames = new String[parmTypes.length]; - for (int i = 0; i < parmTypes.length; i++) { - rmr.parameterTypeNames[i] = getClassName(parmTypes[i]); - } - } - return rmr; - } else - return null; - } - - private ReflectFieldRecord getReflectedFieldRecord(Field field) { - if (field != null) { - ReflectFieldRecord rf = new ReflectFieldRecord(); - rf.className = getClassName(field.getDeclaringClass()); - rf.fieldName = field.getName(); - rf.readOnly = Modifier.isFinal(field.getModifiers()); - return rf; - } else - return null; - } -} diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ModelingBeanInfo15.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ModelingBeanInfo15.java deleted file mode 100644 index 04d2cb68f..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ModelingBeanInfo15.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.beaninfo.vm; -/* - - - */ - -import java.beans.BeanInfo; - -/** - * This was supposed to for 1.4 or above where it can use identity - * to test for inherited features, but it still is not correct - * in 1.4. See the header comments in ModelingBeanInfo. - * @see org.eclipse.jem.internal.beaninfo.vm.ModelingBeanInfo - */ -public class ModelingBeanInfo15 extends ModelingBeanInfo { - - /** - * Constructor for ModelingBeanInfo15. - * @param beanInfo - */ - public ModelingBeanInfo15(BeanInfo beanInfo, int doFlags) { - super(beanInfo, doFlags); - } - - /** - * Constructor for ModelingBeanInfo15. - * @param beanInfo - * @param superBeanInfo - */ - public ModelingBeanInfo15(BeanInfo beanInfo, BeanInfo superBeanInfo, int doFlags) { - super(beanInfo, superBeanInfo, doFlags); - } -} diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ModelingBeanInfoPre15.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ModelingBeanInfoPre15.java deleted file mode 100644 index bd2d85cbb..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ModelingBeanInfoPre15.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2003, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.beaninfo.vm; -/* - - - */ - -import java.beans.BeanInfo; - -/** - * This is the modeling BeanInfo for Pre-JDK 1.4. - */ -public class ModelingBeanInfoPre15 extends ModelingBeanInfo { - - public ModelingBeanInfoPre15(BeanInfo beanInfo, int doFlags) { - super(beanInfo, doFlags); - } - - public ModelingBeanInfoPre15(BeanInfo beanInfo, BeanInfo superBeanInfo, int doFlags) { - super(beanInfo, superBeanInfo, doFlags); - } -} diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ParameterDescriptorEquality.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ParameterDescriptorEquality.java deleted file mode 100644 index 8e09fcdf5..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/ParameterDescriptorEquality.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.beaninfo.vm; -/* - - - */ - -import java.beans.*; -/** - * ParameterDescriptor equality tester - */ -public class ParameterDescriptorEquality extends FeatureDescriptorEquality { - - static void INIT() { - try { - MAP_EQUALITY.put(ParameterDescriptor.class, (ParameterDescriptorEquality.class).getConstructor(new Class[] {ParameterDescriptor.class})); - } catch (NoSuchMethodException e) { - } - } - - public ParameterDescriptorEquality() { - } - - public ParameterDescriptorEquality(ParameterDescriptor descr) { - super(descr); - } - -} diff --git a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/PropertyDescriptorEquality.java b/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/PropertyDescriptorEquality.java deleted file mode 100644 index 75d5eee64..000000000 --- a/plugins/org.eclipse.jem.beaninfo.common/vm_beaninfovm/org/eclipse/jem/internal/beaninfo/vm/PropertyDescriptorEquality.java +++ /dev/null @@ -1,83 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2001, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jem.internal.beaninfo.vm; -/* - - - */ - -import java.beans.*; -/** - * PropertyDescriptor equality tester - */ -public abstract class PropertyDescriptorEquality extends FeatureDescriptorEquality { - - public PropertyDescriptorEquality() { - } - - public PropertyDescriptorEquality(PropertyDescriptor descr) { - super(descr); - } - /** - * Calculate the hashcode for the current feature, add this - * to the hashcode received from super.calculateHashCode - * and return the new value. - * - * NOTE: for subclasses, it is MANDITORY that the first line be: - * int hashcode = super.calculateHashCode(); - * and the last line be: - * return hashcode*31 + (your calculated hashcode for just this subclass); - */ - protected int calculateHashCode() { - int hashcode = super.calculateHashCode(); - PropertyDescriptor pd = (PropertyDescriptor) fFeature; - int hc = 0; - if (pd.getPropertyEditorClass() != null) - hc += pd.getPropertyEditorClass().hashCode(); - if (pd.getPropertyType() != null) - hc += pd.getPropertyType().hashCode(); - if (pd.getReadMethod() != null) - hc += pd.getReadMethod().hashCode(); - if (pd.getWriteMethod() != null) - hc += pd.getWriteMethod().hashCode(); - - hc += (pd.isBound() ? Boolean.TRUE : Boolean.FALSE).hashCode(); - hc += (pd.isConstrained() ? Boolean.TRUE : Boolean.FALSE).hashCode(); - - return hashcode*31 + hc; - } - - public boolean equals(Object obj) { - if (identityTest(obj)) - return true; - - if (!super.equals(obj)) - return false; - - PropertyDescriptor op = (PropertyDescriptor) ((FeatureDescriptorEquality) obj).fFeature; - PropertyDescriptor fp = (PropertyDescriptor) fFeature; - - if (op.getPropertyEditorClass() != fp.getPropertyEditorClass()) - return false; - if (op.getReadMethod() != fp.getReadMethod()) - return false; - if (op.getWriteMethod() != fp.getWriteMethod()) - return false; - if (op.isBound() != fp.isBound()) - return false; - if (op.isConstrained() != fp.isConstrained()) - return false; - - return true; - } - - -} |