Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrkulp2006-02-06 17:14:43 +0000
committerrkulp2006-02-06 17:14:43 +0000
commit7361694990bdac786cbeca5c42db53f27bbb535a (patch)
tree938c51e4b446569832bf46749a78e967cc50e0d6 /plugins/org.eclipse.jem.beaninfo
parent12885a933a64838295acbc31f563782b1f21d4de (diff)
downloadwebtools.javaee-7361694990bdac786cbeca5c42db53f27bbb535a.tar.gz
webtools.javaee-7361694990bdac786cbeca5c42db53f27bbb535a.tar.xz
webtools.javaee-7361694990bdac786cbeca5c42db53f27bbb535a.zip
Release the code for the generic "factory" stuff.
Diffstat (limited to 'plugins/org.eclipse.jem.beaninfo')
-rw-r--r--plugins/org.eclipse.jem.beaninfo/.project13
-rw-r--r--plugins/org.eclipse.jem.beaninfo/META-INF/MANIFEST.MF2
-rw-r--r--plugins/org.eclipse.jem.beaninfo/beaninfoCommon/org/eclipse/jem/beaninfo/common/IBaseBeanInfoConstants.java75
-rw-r--r--plugins/org.eclipse.jem.beaninfo/beaninfoCommon/org/eclipse/jem/internal/beaninfo/common/FeatureAttributeValue.java43
-rw-r--r--plugins/org.eclipse.jem.beaninfo/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/BaseBeanInfo.java181
5 files changed, 206 insertions, 108 deletions
diff --git a/plugins/org.eclipse.jem.beaninfo/.project b/plugins/org.eclipse.jem.beaninfo/.project
index 79380706a..c03103858 100644
--- a/plugins/org.eclipse.jem.beaninfo/.project
+++ b/plugins/org.eclipse.jem.beaninfo/.project
@@ -3,19 +3,6 @@
<name>org.eclipse.jem.beaninfo</name>
<comment></comment>
<projects>
- <project>com.ibm.etools.emf.event</project>
- <project>org.apache.xerces</project>
- <project>org.eclipse.compare</project>
- <project>org.eclipse.core.resources</project>
- <project>org.eclipse.core.runtime.compatibility</project>
- <project>org.eclipse.emf.ecore</project>
- <project>org.eclipse.emf.ecore.xmi</project>
- <project>org.eclipse.jdt.core</project>
- <project>org.eclipse.jdt.launching</project>
- <project>org.eclipse.jem</project>
- <project>org.eclipse.jem.proxy</project>
- <project>org.eclipse.jem.workbench</project>
- <project>org.eclipse.osgi</project>
</projects>
<buildSpec>
<buildCommand>
diff --git a/plugins/org.eclipse.jem.beaninfo/META-INF/MANIFEST.MF b/plugins/org.eclipse.jem.beaninfo/META-INF/MANIFEST.MF
index d7bee6a8f..b9d8c285a 100644
--- a/plugins/org.eclipse.jem.beaninfo/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.jem.beaninfo/META-INF/MANIFEST.MF
@@ -27,4 +27,4 @@ Require-Bundle: org.eclipse.jem.proxy,
org.eclipse.debug.core,
org.eclipse.jem.util,
org.eclipse.emf.ecore.change
-Eclipse-AutoStart: true
+Eclipse-LazyStart: true
diff --git a/plugins/org.eclipse.jem.beaninfo/beaninfoCommon/org/eclipse/jem/beaninfo/common/IBaseBeanInfoConstants.java b/plugins/org.eclipse.jem.beaninfo/beaninfoCommon/org/eclipse/jem/beaninfo/common/IBaseBeanInfoConstants.java
index 2af047eb7..14ac20727 100644
--- a/plugins/org.eclipse.jem.beaninfo/beaninfoCommon/org/eclipse/jem/beaninfo/common/IBaseBeanInfoConstants.java
+++ b/plugins/org.eclipse.jem.beaninfo/beaninfoCommon/org/eclipse/jem/beaninfo/common/IBaseBeanInfoConstants.java
@@ -10,7 +10,7 @@
*******************************************************************************/
/*
* $RCSfile: IBaseBeanInfoConstants.java,v $
- * $Revision: 1.1 $ $Date: 2005/10/18 15:32:19 $
+ * $Revision: 1.2 $ $Date: 2006/02/06 17:14:43 $
*/
package org.eclipse.jem.beaninfo.common;
@@ -29,10 +29,75 @@ package org.eclipse.jem.beaninfo.common;
public interface IBaseBeanInfoConstants {
/**
- * Indicator used to describe a factory instantiation pattern. Not API as will change to become more extensible
- * via .override mechanism in future
- *
- * @since 1.1
+ * Indicator used to describe a factory instantiation pattern.
+ * <p>
+ * This will be on the attributes of the BeanDescriptor for the factory class. It will be complete, in that if this
+ * factory is inherited from another factory, it must copy in the superclass's factory attribute. They won't be
+ * automatically merged.
+ * <p>
+ * The format is an Object[][]. The first dimension at index zero is for toolkit wide information and then indexes one and beyond are one for each creation method name. The second dimension is for one entry
+ * of classwide data and the rest are the data for
+ * each creation method.
+ * <p>
+ * The first entry at Object[0] will be <code>{initString, isShared, onFreeform}</code> where:
+ * <dl>
+ * <dt>initString
+ * <dd>The init string that should be used to create an instance of the toolkit if it needs one, or <code>null</code> if it doesn't
+ * need one (i.e. all static) or if the default constructor should be used.
+ * This is used when a component is dropped from the palette that is for a toolkit component.
+ * <dt>isShared
+ * <dd><code>false</code> if each call to the creation method should have a new instance of the toolkit. This means that the toolkit manages only
+ * one instance. This is more like a controller than a toolkit in this case. <code>true</code> if it should
+ * try to reuse the toolkit of the parent if it has one, or any other found toolkit of the same type, (i.e. a subtype will be acceptable).
+ * This is used when a component is dropped from the palette that is for a toolkit component.
+ * <dt>onFreeform
+ * <dd><code>true</code> if the toolkit is created that it should appear on the freeform surface to be selectable. This would be of use
+ * if the toolkit had properties that need to be set. If the toolkit had no properties then it doesn't need to be selectable and should
+ * not be on the freeform. Use <code>false</code> in that case.
+ * </dl>
+ * <p>
+ * The second and other entries of the array are of the format:
+ * <code>{methodName, returnedClassname, isStatic, Object[], ...}</code> where:
+ * <dl>
+ * <dt>methodName
+ * <dd>The name of the creation method this entry is for (String).
+ * <dt>returnedClassname
+ * <dd>The name of the class that is created and returned from the method (String).
+ * <dt>isStatic
+ * <dd><code>Boolean.TRUE</code> if the method is a static method, <code>Boolean.FALSE</code> if not.
+ * This is used when a component is dropped from the palette that is for a toolkit component.
+ * <dt>Object[]
+ * <dd>Zero or more arrays. The array contains the name of the properties for each method signature that each
+ * respective argument is for, or <code>null</code> if that arg is not a property. There can be more than one array if there
+ * is more than one factory method of the same name, and returns the same type, but what is different is only the number of arguments.
+ * If there is a
+ * factory method that has no properties as arguments or has no arguments, don't include an array for it. For example if there was only one factory method and it had no
+ * arguments then there would not be any arrays.
+ * Currently cannot handle where more than one method has the same number of arguments but different types for the arguments.
+ * </dl>
+ * <p>
+ * A example is:
+ * <pre><code>
+ * new Object[][] {
+ * {"new a.b.c.Toolkit(\"ABC\")", Boolean.TRUE, Boolean.FALSE},
+ * {"createButton", "a.b.c.Button", Boolean.FALSE, new Object[] {"parent", "text"}, new Object[] {"parent"}}
+ * }
+ * </code>
+ * </pre>
+ * <p>
+ * This example says that this class is toolkit (factory). To construct an instead use <code>"new a.b.c.Toolkit(\"ABC\")"</code> and it is shared
+ * with other objects created from this factory instance. Also, the factory method is "createButton", returns an "a.b.c.Button", and it is
+ * not a static call (i.e. use a toolkit instance to create it). It has two forms of factory methods. One is two arguments where the first
+ * arg is the parent property and the second arg is the text property. The other form has only one argument, the parent property.
+ * <p>
+ * The way this is used in a palette entry to drop a new object that a toolkit can create is to have an expression of the form
+ * <code>{toolkit:classname}.factorymethod(args)</code>. So for the above example it would be <code>{toolkit:a.b.c.Toolkit}.createButton(parent)</code>.
+ * The classname <b>must</b> be fully-qualified and if an inner class it must use the "$" instead of "." for the name, i.e. a.b.c.Toolkit.InnerFactory
+ * would be a.b.c.Toolkit$InnerFactory.
+ * <p>
+ * <b>NOTE:</b> This is an EXPERIMENTAL API and can change in the future until committed.
+ *
+ * @since 1.2.0
*/
public static final String FACTORY_CREATION = "FACTORY_CREATION";//$NON-NLS-1$
diff --git a/plugins/org.eclipse.jem.beaninfo/beaninfoCommon/org/eclipse/jem/internal/beaninfo/common/FeatureAttributeValue.java b/plugins/org.eclipse.jem.beaninfo/beaninfoCommon/org/eclipse/jem/internal/beaninfo/common/FeatureAttributeValue.java
index 9d040b72c..e4bc536c4 100644
--- a/plugins/org.eclipse.jem.beaninfo/beaninfoCommon/org/eclipse/jem/internal/beaninfo/common/FeatureAttributeValue.java
+++ b/plugins/org.eclipse.jem.beaninfo/beaninfoCommon/org/eclipse/jem/internal/beaninfo/common/FeatureAttributeValue.java
@@ -10,7 +10,7 @@
*******************************************************************************/
/*
* $RCSfile: FeatureAttributeValue.java,v $
- * $Revision: 1.9 $ $Date: 2005/12/14 21:21:02 $
+ * $Revision: 1.10 $ $Date: 2006/02/06 17:14:43 $
*/
package org.eclipse.jem.internal.beaninfo.common;
@@ -47,6 +47,7 @@ public class FeatureAttributeValue implements Serializable {
private transient Object value;
private transient Object internalValue;
+ private boolean implicitValue;
private static final long serialVersionUID = 1105717634844L;
/**
@@ -60,6 +61,10 @@ public class FeatureAttributeValue implements Serializable {
public FeatureAttributeValue(String initString) {
// Use the init string to create the value. This is our
// own short-hand for this.
+ if (initString.startsWith(IMPLICIT)) {
+ setImplicitValue(true);
+ initString = initString.substring(IMPLICIT.length());
+ }
value = parseString(initString);
}
@@ -72,7 +77,7 @@ public class FeatureAttributeValue implements Serializable {
public FeatureAttributeValue() {
}
-
+
/**
* @return Returns the value.
*
@@ -125,7 +130,11 @@ public class FeatureAttributeValue implements Serializable {
public String toString() {
if (value == null)
return super.toString();
- return makeString(value);
+ StringBuffer out = new StringBuffer(100);
+ if (isImplicitValue())
+ out.append(IMPLICIT);
+ makeString(value, out);
+ return out.toString();
}
@@ -166,10 +175,11 @@ public class FeatureAttributeValue implements Serializable {
makeString(value, out);
return out.toString();
}
-
+
private static final Pattern QUOTE = Pattern.compile("\""); // Pattern for searching for double-quote. Make it static so don't waste time compiling each time. //$NON-NLS-1$
private static final String NULL = "null"; // Output string for null //$NON-NLS-1$
private static final String INVALID = "INV"; // Invalid object flag. //$NON-NLS-1$
+ private static final String IMPLICIT = "implicit,"; // Implicit flag. //$NON-NLS-1$
/*
* Used for recursive building of the string.
@@ -746,5 +756,30 @@ public class FeatureAttributeValue implements Serializable {
} else
return val; // It is the value itself.
}
+
+
+ /**
+ * Is this FeatureAttributeValue an implicit value, i.e. one that came from
+ * BeanInfo Introspection and not from an override file.
+ *
+ * @return Returns the implicitValue.
+ *
+ * @since 1.2.0
+ */
+ public boolean isImplicitValue() {
+ return implicitValue;
+ }
+
+
+ /**
+ * Set the implicit value flag.
+ * @param implicitValue The implicitValue to set.
+ *
+ * @see #isImplicitValue()
+ * @since 1.2.0
+ */
+ public void setImplicitValue(boolean implicitValue) {
+ this.implicitValue = implicitValue;
+ }
}
diff --git a/plugins/org.eclipse.jem.beaninfo/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/BaseBeanInfo.java b/plugins/org.eclipse.jem.beaninfo/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/BaseBeanInfo.java
index 4cfc8de21..e5392dd8c 100644
--- a/plugins/org.eclipse.jem.beaninfo/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/BaseBeanInfo.java
+++ b/plugins/org.eclipse.jem.beaninfo/vm_beaninfovm/org/eclipse/jem/beaninfo/vm/BaseBeanInfo.java
@@ -12,7 +12,7 @@ package org.eclipse.jem.beaninfo.vm;
/*
* $RCSfile: BaseBeanInfo.java,v $
- * $Revision: 1.11 $ $Date: 2005/10/18 15:32:19 $
+ * $Revision: 1.12 $ $Date: 2006/02/06 17:14:43 $
*/
import java.awt.Image;
@@ -195,7 +195,7 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
* @param cls
* bean for which the bean descriptor is being created.
* @param args
- * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc.
+ * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc. or null if no args
* @return new bean descriptor
*
* @since 1.1.0
@@ -203,22 +203,25 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
public static BeanDescriptor createBeanDescriptor(Class cls, Object[] args) {
Class customizerClass = 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;
+ 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);
- for (int i = 0; i < args.length; i += 2) {
- String key = (String) args[i];
- Object value = args[i + 1];
- setFeatureDescriptorValue(bd, key, value);
- }
-
+ 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;
}
@@ -230,7 +233,7 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
* @param name
* Name of event set
* @param args
- * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc.
+ * 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
@@ -272,16 +275,17 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
new Object[] { name}));
}
;
- // 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);
- }
-
+ 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;
}
@@ -293,7 +297,7 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
* @param name
* name of the method.
* @param args
- * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc.
+ * 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
@@ -323,12 +327,14 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
new Object[] { name}));
}
;
- // 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);
- }
+ 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;
}
@@ -383,7 +389,7 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
* @param name
* name of parameter
* @param args
- * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc.
+ * arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc. or null if no args
* @return new parameter descriptor
*
* @since 1.1.0
@@ -399,13 +405,14 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
;
// set the name
pd.setName(name);
- // 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);
- }
-
+ 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;
}
@@ -425,7 +432,7 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
* no getter or setter.
* @param name
* @param field
- * @param args
+ * @param args arg pairs, [0] keyword, [1] value, [2] keyword, [3] value, etc. or null if no args
* @return
*
* @since 1.1.0
@@ -494,7 +501,7 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
* @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.
+ * 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;
@@ -566,60 +573,64 @@ public abstract class BaseBeanInfo extends SimpleBeanInfo implements IBaseBeanIn
}
private static void applyPropertyArguments(PropertyDescriptor pd, Object[] args, Class cls) {
- 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);
+ 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}));
}
- } 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);
}
- } else {
- // arbitrary value
- setFeatureDescriptorValue(pd, key, value);
}
}
}
}
private static void applyFieldArguments(PropertyDescriptor pd, Object[] args) {
- 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);
+ 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);
+ }
}
}
- }
+ }
}
/**

Back to the top