summaryrefslogtreecommitdiffstats
path: root/awt/java/beans
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2008-10-21 07:00:00 -0700
commit7c1b96a165f970a09ed239bb4fb3f1b0d8f2a407 (patch)
treedf5a6539447324de36e95b057d6b9f0361b7a250 /awt/java/beans
downloadframeworks_native-7c1b96a165f970a09ed239bb4fb3f1b0d8f2a407.zip
frameworks_native-7c1b96a165f970a09ed239bb4fb3f1b0d8f2a407.tar.gz
frameworks_native-7c1b96a165f970a09ed239bb4fb3f1b0d8f2a407.tar.bz2
Initial Contribution
Diffstat (limited to 'awt/java/beans')
-rw-r--r--awt/java/beans/FeatureDescriptor.java234
-rw-r--r--awt/java/beans/IndexedPropertyChangeEvent.java66
-rw-r--r--awt/java/beans/IndexedPropertyDescriptor.java227
-rw-r--r--awt/java/beans/IntrospectionException.java27
-rw-r--r--awt/java/beans/PropertyChangeEvent.java62
-rw-r--r--awt/java/beans/PropertyChangeListener.java25
-rw-r--r--awt/java/beans/PropertyChangeListenerProxy.java41
-rw-r--r--awt/java/beans/PropertyChangeSupport.java351
-rw-r--r--awt/java/beans/PropertyDescriptor.java300
-rw-r--r--awt/java/beans/PropertyEditor.java49
-rw-r--r--awt/java/beans/PropertyEditorManager.java114
-rw-r--r--awt/java/beans/PropertyEditorSupport.java129
-rw-r--r--awt/java/beans/PropertyVetoException.java54
13 files changed, 1679 insertions, 0 deletions
diff --git a/awt/java/beans/FeatureDescriptor.java b/awt/java/beans/FeatureDescriptor.java
new file mode 100644
index 0000000..2945c65
--- /dev/null
+++ b/awt/java/beans/FeatureDescriptor.java
@@ -0,0 +1,234 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package java.beans;
+
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.Map;
+
+/**
+ * Common base class for Descriptors.
+ */
+public class FeatureDescriptor {
+
+ private Map<String, Object> values;
+
+ boolean preferred, hidden, expert;
+
+ String shortDescription;
+
+ String name;
+
+ String displayName;
+
+ /**
+ * <p>
+ * Constructs an instance.
+ * </p>
+ */
+ public FeatureDescriptor() {
+ this.values = new HashMap<String, Object>();
+ }
+
+ /**
+ * <p>
+ * Sets the value for the named attribute.
+ * </p>
+ *
+ * @param attributeName
+ * The name of the attribute to set a value with.
+ * @param value
+ * The value to set.
+ */
+ public void setValue(String attributeName, Object value) {
+ if (attributeName == null || value == null) {
+ throw new NullPointerException();
+ }
+ values.put(attributeName, value);
+ }
+
+ /**
+ * <p>
+ * Gets the value associated with the named attribute.
+ * </p>
+ *
+ * @param attributeName
+ * The name of the attribute to get a value for.
+ * @return The attribute's value.
+ */
+ public Object getValue(String attributeName) {
+ Object result = null;
+ if (attributeName != null) {
+ result = values.get(attributeName);
+ }
+ return result;
+ }
+
+ /**
+ * <p>
+ * Enumerates the attribute names.
+ * </p>
+ *
+ * @return An instance of {@link Enumeration}.
+ */
+ public Enumeration<String> attributeNames() {
+ // Create a new list, so that the references are copied
+ return Collections.enumeration(new LinkedList<String>(values.keySet()));
+ }
+
+ /**
+ * <p>
+ * Sets the short description.
+ * </p>
+ *
+ * @param text
+ * The description to set.
+ */
+ public void setShortDescription(String text) {
+ this.shortDescription = text;
+ }
+
+ /**
+ * <p>
+ * Sets the name.
+ * </p>
+ *
+ * @param name
+ * The name to set.
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * <p>
+ * Sets the display name.
+ * </p>
+ *
+ * @param displayName
+ * The display name to set.
+ */
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ /**
+ * <p>
+ * Gets the short description or {@link #getDisplayName()} if not set.
+ * </p>
+ *
+ * @return The description.
+ */
+ public String getShortDescription() {
+ return shortDescription == null ? getDisplayName() : shortDescription;
+ }
+
+ /**
+ * <p>
+ * Gets the name.
+ * </p>
+ *
+ * @return The name.
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * <p>
+ * Gets the display name or {@link #getName()} if not set.
+ * </p>
+ *
+ * @return The display name.
+ */
+ public String getDisplayName() {
+ return displayName == null ? getName() : displayName;
+ }
+
+ /**
+ * <p>
+ * Sets the preferred indicator.
+ * </p>
+ *
+ * @param preferred
+ * <code>true</code> if preferred, <code>false</code>
+ * otherwise.
+ */
+ public void setPreferred(boolean preferred) {
+ this.preferred = preferred;
+ }
+
+ /**
+ * <p>
+ * Sets the hidden indicator.
+ * </p>
+ *
+ * @param hidden
+ * <code>true</code> if hidden, <code>false</code> otherwise.
+ */
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+
+ /**
+ * <p>
+ * Sets the expert indicator.
+ * </p>
+ *
+ * @param expert
+ * <code>true</code> if expert, <code>false</code> otherwise.
+ */
+ public void setExpert(boolean expert) {
+ this.expert = expert;
+ }
+
+ /**
+ * <p>
+ * Indicates if this feature is preferred.
+ * </p>
+ *
+ * @return <code>true</code> if preferred, <code>false</code> otherwise.
+ */
+ public boolean isPreferred() {
+ return preferred;
+ }
+
+ /**
+ * <p>
+ * Indicates if this feature is hidden.
+ * </p>
+ *
+ * @return <code>true</code> if hidden, <code>false</code> otherwise.
+ */
+ public boolean isHidden() {
+ return hidden;
+ }
+
+ /**
+ * <p>
+ * Indicates if this feature is an expert feature.
+ * </p>
+ *
+ * @return <code>true</code> if hidden, <code>false</code> otherwise.
+ */
+ public boolean isExpert() {
+ return expert;
+ }
+}
diff --git a/awt/java/beans/IndexedPropertyChangeEvent.java b/awt/java/beans/IndexedPropertyChangeEvent.java
new file mode 100644
index 0000000..c9084c6
--- /dev/null
+++ b/awt/java/beans/IndexedPropertyChangeEvent.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package java.beans;
+
+/**
+ * A type of {@link PropertyChangeEvent} that indicates that an indexed property
+ * has changed.
+ *
+ * @since 1.5
+ */
+public class IndexedPropertyChangeEvent extends PropertyChangeEvent {
+
+ private static final long serialVersionUID = -320227448495806870L;
+
+ private final int index;
+
+ /**
+ * Creates a new property changed event with an indication of the property
+ * index.
+ *
+ * @param source
+ * the changed bean.
+ * @param propertyName
+ * the changed property, or <code>null</code> to indicate an
+ * unspecified set of the properties have changed.
+ * @param oldValue
+ * the previous value of the property, or <code>null</code> if
+ * the <code>propertyName</code> is <code>null</code> or the
+ * previous value is unknown.
+ * @param newValue
+ * the new value of the property, or <code>null</code> if the
+ * <code>propertyName</code> is <code>null</code> or the new
+ * value is unknown..
+ * @param index
+ * the index of the property.
+ */
+ public IndexedPropertyChangeEvent(Object source, String propertyName,
+ Object oldValue, Object newValue, int index) {
+ super(source, propertyName, oldValue, newValue);
+ this.index = index;
+ }
+
+ /**
+ * Answer the index of the property that was changed in this event.
+ *
+ * @return The property element index.
+ */
+ public int getIndex() {
+ return index;
+ }
+}
diff --git a/awt/java/beans/IndexedPropertyDescriptor.java b/awt/java/beans/IndexedPropertyDescriptor.java
new file mode 100644
index 0000000..25667d9
--- /dev/null
+++ b/awt/java/beans/IndexedPropertyDescriptor.java
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import org.apache.harmony.beans.internal.nls.Messages;
+
+public class IndexedPropertyDescriptor extends PropertyDescriptor {
+ private Method indexedGetter;
+
+ private Method indexedSetter;
+
+ public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass,
+ String getterName, String setterName, String indexedGetterName,
+ String indexedSetterName) throws IntrospectionException {
+ super(propertyName, beanClass, getterName, setterName);
+
+ // RI behaves like this
+ if (indexedGetterName == null && indexedSetterName == null &&
+ (getterName != null || setterName != null)) {
+ throw new IntrospectionException(Messages.getString("beans.50"));
+ }
+ setIndexedReadMethod(beanClass, indexedGetterName);
+ setIndexedWriteMethod(beanClass, indexedSetterName);
+ }
+
+ public IndexedPropertyDescriptor(String propertyName, Method getter, Method setter,
+ Method indexedGetter, Method indexedSetter) throws IntrospectionException {
+ super(propertyName, getter, setter);
+
+ // we need this in order to be compatible with RI
+ if (indexedGetter == null && indexedSetter == null &&
+ (getter != null || setter != null)) {
+ throw new IntrospectionException(Messages.getString("beans.50"));
+ }
+ setIndexedReadMethod(indexedGetter);
+ setIndexedWriteMethod(indexedSetter);
+ }
+
+ public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass)
+ throws IntrospectionException {
+ super(propertyName, beanClass, null, null);
+ String getterName;
+ String setterName;
+ String indexedGetterName;
+ String indexedSetterName;
+
+ // array getter
+ getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
+ if (hasMethod(beanClass, getterName)) {
+ setReadMethod(beanClass, getterName);
+ }
+ // array setter
+ setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
+ if (hasMethod(beanClass, setterName)) {
+ setWriteMethod(beanClass, setterName);
+ }
+ // indexed getter
+ indexedGetterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
+ if (hasMethod(beanClass, indexedGetterName)) {
+ setIndexedReadMethod(beanClass, indexedGetterName);
+ }
+ // indexed setter
+ indexedSetterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
+ if (hasMethod(beanClass, indexedSetterName)) {
+ setIndexedWriteMethod(beanClass, indexedSetterName);
+ }
+ // RI seems to behave a bit differently
+ if (indexedGetter == null && indexedSetter == null &&
+ getReadMethod() == null && getWriteMethod() == null) {
+ throw new IntrospectionException(
+ Messages.getString("beans.01", propertyName)); //$NON-NLS-1$
+ }
+ if (indexedGetter == null && indexedSetter == null) {
+ // not an indexed property indeed
+ throw new IntrospectionException(Messages.getString("beans.50"));
+ }
+ }
+
+ public void setIndexedReadMethod(Method indexedGetter) throws IntrospectionException {
+ if (indexedGetter != null) {
+ int modifiers = indexedGetter.getModifiers();
+ Class<?>[] parameterTypes;
+ Class<?> returnType;
+ Class<?> indexedPropertyType;
+
+ if (!Modifier.isPublic(modifiers)) {
+ throw new IntrospectionException(Messages.getString("beans.21")); //$NON-NLS-1$
+ }
+ parameterTypes = indexedGetter.getParameterTypes();
+ if (parameterTypes.length != 1) {
+ throw new IntrospectionException(Messages.getString("beans.22")); //$NON-NLS-1$
+ }
+ if (!parameterTypes[0].equals(int.class)) {
+ throw new IntrospectionException(Messages.getString("beans.23")); //$NON-NLS-1$
+ }
+ returnType = indexedGetter.getReturnType();
+ indexedPropertyType = getIndexedPropertyType();
+ if ((indexedPropertyType != null) && !returnType.equals(indexedPropertyType)) {
+ throw new IntrospectionException(Messages.getString("beans.24")); //$NON-NLS-1$
+ }
+ }
+ this.indexedGetter = indexedGetter;
+ }
+
+ public void setIndexedWriteMethod(Method indexedSetter) throws IntrospectionException {
+ if (indexedSetter != null) {
+ int modifiers = indexedSetter.getModifiers();
+ Class<?>[] parameterTypes;
+ Class<?> firstParameterType;
+ Class<?> secondParameterType;
+ Class<?> propType;
+
+ if (!Modifier.isPublic(modifiers)) {
+ throw new IntrospectionException(Messages.getString("beans.25")); //$NON-NLS-1$
+ }
+ parameterTypes = indexedSetter.getParameterTypes();
+ if (parameterTypes.length != 2) {
+ throw new IntrospectionException(Messages.getString("beans.26")); //$NON-NLS-1$
+ }
+ firstParameterType = parameterTypes[0];
+ if (!firstParameterType.equals(int.class)) {
+ throw new IntrospectionException(Messages.getString("beans.27")); //$NON-NLS-1$
+ }
+ secondParameterType = parameterTypes[1];
+ propType = getIndexedPropertyType();
+ if (propType != null && !secondParameterType.equals(propType)) {
+ throw new IntrospectionException(Messages.getString("beans.28")); //$NON-NLS-1$
+ }
+ }
+ this.indexedSetter = indexedSetter;
+ }
+
+ public Method getIndexedWriteMethod() {
+ return indexedSetter;
+ }
+
+ public Method getIndexedReadMethod() {
+ return indexedGetter;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ boolean result = super.equals(obj);
+
+ if (result) {
+ IndexedPropertyDescriptor pd = (IndexedPropertyDescriptor) obj;
+
+ if (indexedGetter != null) {
+ result = indexedGetter.equals(pd.getIndexedReadMethod());
+ } else if (result && indexedGetter == null) {
+ result = pd.getIndexedReadMethod() == null;
+ }
+
+ if (result) {
+ if (indexedSetter != null) {
+ result = indexedSetter.equals(pd.getIndexedWriteMethod());
+ } else if (indexedSetter == null) {
+ result = pd.getIndexedWriteMethod() == null;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ public Class<?> getIndexedPropertyType() {
+ Class<?> result = null;
+
+ if (indexedGetter != null) {
+ result = indexedGetter.getReturnType();
+ } else if (indexedSetter != null) {
+ Class<?>[] parameterTypes = indexedSetter.getParameterTypes();
+
+ result = parameterTypes[1];
+ }
+ return result;
+ }
+
+ private void setIndexedReadMethod(Class<?> beanClass, String indexedGetterName) {
+ Method[] getters = findMethods(beanClass, indexedGetterName);
+ boolean result = false;
+
+ for (Method element : getters) {
+ try {
+ setIndexedReadMethod(element);
+ result = true;
+ } catch (IntrospectionException ie) {}
+
+ if (result) {
+ break;
+ }
+ }
+ }
+
+ private void setIndexedWriteMethod(Class<?> beanClass, String indexedSetterName) {
+ Method[] setters = findMethods(beanClass, indexedSetterName);
+ boolean result = false;
+
+ for (Method element : setters) {
+ try {
+ setIndexedWriteMethod(element);
+ result = true;
+ } catch (IntrospectionException ie) {}
+
+ if (result) {
+ break;
+ }
+ }
+ }
+}
diff --git a/awt/java/beans/IntrospectionException.java b/awt/java/beans/IntrospectionException.java
new file mode 100644
index 0000000..c895afe
--- /dev/null
+++ b/awt/java/beans/IntrospectionException.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+public class IntrospectionException extends Exception {
+
+ static final long serialVersionUID = -3728150539969542619L;
+
+ public IntrospectionException(String message) {
+ super(message);
+ }
+}
diff --git a/awt/java/beans/PropertyChangeEvent.java b/awt/java/beans/PropertyChangeEvent.java
new file mode 100644
index 0000000..97c703a
--- /dev/null
+++ b/awt/java/beans/PropertyChangeEvent.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+import java.util.EventObject;
+
+public class PropertyChangeEvent extends EventObject {
+
+ private static final long serialVersionUID = 7042693688939648123L;
+
+ String propertyName;
+
+ Object oldValue;
+
+ Object newValue;
+
+ Object propagationId;
+
+ public PropertyChangeEvent(Object source, String propertyName,
+ Object oldValue, Object newValue) {
+ super(source);
+
+ this.propertyName = propertyName;
+ this.oldValue = oldValue;
+ this.newValue = newValue;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public void setPropagationId(Object propagationId) {
+ this.propagationId = propagationId;
+ }
+
+ public Object getPropagationId() {
+ return propagationId;
+ }
+
+ public Object getOldValue() {
+ return oldValue;
+ }
+
+ public Object getNewValue() {
+ return newValue;
+ }
+}
diff --git a/awt/java/beans/PropertyChangeListener.java b/awt/java/beans/PropertyChangeListener.java
new file mode 100644
index 0000000..94422c0
--- /dev/null
+++ b/awt/java/beans/PropertyChangeListener.java
@@ -0,0 +1,25 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+import java.util.EventListener;
+
+public interface PropertyChangeListener extends EventListener {
+
+ public void propertyChange(PropertyChangeEvent event);
+}
diff --git a/awt/java/beans/PropertyChangeListenerProxy.java b/awt/java/beans/PropertyChangeListenerProxy.java
new file mode 100644
index 0000000..f4f3aec
--- /dev/null
+++ b/awt/java/beans/PropertyChangeListenerProxy.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+import java.util.EventListenerProxy;
+
+public class PropertyChangeListenerProxy extends EventListenerProxy implements
+ PropertyChangeListener {
+
+ String propertyName;
+
+ public PropertyChangeListenerProxy(String propertyName,
+ PropertyChangeListener listener) {
+ super(listener);
+ this.propertyName = propertyName;
+ }
+
+ public String getPropertyName() {
+ return propertyName;
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ PropertyChangeListener listener = (PropertyChangeListener) getListener();
+ listener.propertyChange(event);
+ }
+}
diff --git a/awt/java/beans/PropertyChangeSupport.java b/awt/java/beans/PropertyChangeSupport.java
new file mode 100644
index 0000000..d56e63a
--- /dev/null
+++ b/awt/java/beans/PropertyChangeSupport.java
@@ -0,0 +1,351 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+public class PropertyChangeSupport implements Serializable {
+
+ private static final long serialVersionUID = 6401253773779951803l;
+
+ private transient Object sourceBean;
+
+ private transient List<PropertyChangeListener> allPropertiesChangeListeners =
+ new ArrayList<PropertyChangeListener>();
+
+ private transient Map<String, List<PropertyChangeListener>>
+ selectedPropertiesChangeListeners =
+ new HashMap<String, List<PropertyChangeListener>>();
+
+ // fields for serialization compatibility
+ private Hashtable<String, List<PropertyChangeListener>> children;
+
+ private Object source;
+
+ private int propertyChangeSupportSerializedDataVersion = 1;
+
+ public PropertyChangeSupport(Object sourceBean) {
+ if (sourceBean == null) {
+ throw new NullPointerException();
+ }
+ this.sourceBean = sourceBean;
+ }
+
+ public void firePropertyChange(String propertyName, Object oldValue,
+ Object newValue) {
+ PropertyChangeEvent event = createPropertyChangeEvent(propertyName,
+ oldValue, newValue);
+ doFirePropertyChange(event);
+ }
+
+ public void fireIndexedPropertyChange(String propertyName, int index,
+ Object oldValue, Object newValue) {
+
+ // nulls and equals check done in doFire...
+ doFirePropertyChange(new IndexedPropertyChangeEvent(sourceBean,
+ propertyName, oldValue, newValue, index));
+ }
+
+ public synchronized void removePropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ if ((propertyName != null) && (listener != null)) {
+ List<PropertyChangeListener> listeners =
+ selectedPropertiesChangeListeners.get(propertyName);
+
+ if (listeners != null) {
+ listeners.remove(listener);
+ }
+ }
+ }
+
+ public synchronized void addPropertyChangeListener(String propertyName,
+ PropertyChangeListener listener) {
+ if ((listener != null) && (propertyName != null)) {
+ List<PropertyChangeListener> listeners =
+ selectedPropertiesChangeListeners.get(propertyName);
+
+ if (listeners == null) {
+ listeners = new ArrayList<PropertyChangeListener>();
+ selectedPropertiesChangeListeners.put(propertyName, listeners);
+ }
+
+ // RI compatibility
+ if (listener instanceof PropertyChangeListenerProxy) {
+ PropertyChangeListenerProxy proxy =
+ (PropertyChangeListenerProxy) listener;
+
+ listeners.add(new PropertyChangeListenerProxy(
+ proxy.getPropertyName(),
+ (PropertyChangeListener) proxy.getListener()));
+ } else {
+ listeners.add(listener);
+ }
+ }
+ }
+
+ public synchronized PropertyChangeListener[] getPropertyChangeListeners(
+ String propertyName) {
+ List<PropertyChangeListener> listeners = null;
+
+ if (propertyName != null) {
+ listeners = selectedPropertiesChangeListeners.get(propertyName);
+ }
+
+ return (listeners == null) ? new PropertyChangeListener[] {}
+ : listeners.toArray(
+ new PropertyChangeListener[listeners.size()]);
+ }
+
+ public void firePropertyChange(String propertyName, boolean oldValue,
+ boolean newValue) {
+ PropertyChangeEvent event = createPropertyChangeEvent(propertyName,
+ oldValue, newValue);
+ doFirePropertyChange(event);
+ }
+
+ public void fireIndexedPropertyChange(String propertyName, int index,
+ boolean oldValue, boolean newValue) {
+
+ if (oldValue != newValue) {
+ fireIndexedPropertyChange(propertyName, index, Boolean
+ .valueOf(oldValue), Boolean.valueOf(newValue));
+ }
+ }
+
+ public void firePropertyChange(String propertyName, int oldValue,
+ int newValue) {
+ PropertyChangeEvent event = createPropertyChangeEvent(propertyName,
+ oldValue, newValue);
+ doFirePropertyChange(event);
+ }
+
+ public void fireIndexedPropertyChange(String propertyName, int index,
+ int oldValue, int newValue) {
+
+ if (oldValue != newValue) {
+ fireIndexedPropertyChange(propertyName, index,
+ new Integer(oldValue), new Integer(newValue));
+ }
+ }
+
+ public synchronized boolean hasListeners(String propertyName) {
+ boolean result = allPropertiesChangeListeners.size() > 0;
+ if (!result && (propertyName != null)) {
+ List<PropertyChangeListener> listeners =
+ selectedPropertiesChangeListeners.get(propertyName);
+ if (listeners != null) {
+ result = listeners.size() > 0;
+ }
+ }
+ return result;
+ }
+
+ public synchronized void removePropertyChangeListener(
+ PropertyChangeListener listener) {
+ if (listener != null) {
+ if (listener instanceof PropertyChangeListenerProxy) {
+ String name = ((PropertyChangeListenerProxy) listener)
+ .getPropertyName();
+ PropertyChangeListener lst = (PropertyChangeListener)
+ ((PropertyChangeListenerProxy) listener).getListener();
+
+ removePropertyChangeListener(name, lst);
+ } else {
+ allPropertiesChangeListeners.remove(listener);
+ }
+ }
+ }
+
+ public synchronized void addPropertyChangeListener(
+ PropertyChangeListener listener) {
+ if (listener != null) {
+ if (listener instanceof PropertyChangeListenerProxy) {
+ String name = ((PropertyChangeListenerProxy) listener)
+ .getPropertyName();
+ PropertyChangeListener lst = (PropertyChangeListener)
+ ((PropertyChangeListenerProxy) listener).getListener();
+ addPropertyChangeListener(name, lst);
+ } else {
+ allPropertiesChangeListeners.add(listener);
+ }
+ }
+ }
+
+ public synchronized PropertyChangeListener[] getPropertyChangeListeners() {
+ ArrayList<PropertyChangeListener> result =
+ new ArrayList<PropertyChangeListener>(
+ allPropertiesChangeListeners);
+
+ for (String propertyName : selectedPropertiesChangeListeners.keySet()) {
+ List<PropertyChangeListener> selectedListeners =
+ selectedPropertiesChangeListeners.get(propertyName);
+
+ if (selectedListeners != null) {
+
+ for (PropertyChangeListener listener : selectedListeners) {
+ result.add(new PropertyChangeListenerProxy(propertyName,
+ listener));
+ }
+ }
+ }
+
+ return result.toArray(new PropertyChangeListener[result.size()]);
+ }
+
+ private void writeObject(ObjectOutputStream oos) throws IOException {
+ List<PropertyChangeListener> allSerializedPropertiesChangeListeners =
+ new ArrayList<PropertyChangeListener>();
+
+ for (PropertyChangeListener pcl : allPropertiesChangeListeners) {
+ if (pcl instanceof Serializable) {
+ allSerializedPropertiesChangeListeners.add(pcl);
+ }
+ }
+
+ Map<String, List<PropertyChangeListener>>
+ selectedSerializedPropertiesChangeListeners =
+ new HashMap<String, List<PropertyChangeListener>>();
+
+ for (String propertyName : selectedPropertiesChangeListeners.keySet()) {
+ List<PropertyChangeListener> keyValues =
+ selectedPropertiesChangeListeners.get(propertyName);
+
+ if (keyValues != null) {
+ List<PropertyChangeListener> serializedPropertiesChangeListeners
+ = new ArrayList<PropertyChangeListener>();
+
+ for (PropertyChangeListener pcl : keyValues) {
+ if (pcl instanceof Serializable) {
+ serializedPropertiesChangeListeners.add(pcl);
+ }
+ }
+
+ if (!serializedPropertiesChangeListeners.isEmpty()) {
+ selectedSerializedPropertiesChangeListeners.put(
+ propertyName, serializedPropertiesChangeListeners);
+ }
+ }
+ }
+
+ children = new Hashtable<String, List<PropertyChangeListener>>(
+ selectedSerializedPropertiesChangeListeners);
+ children.put("", allSerializedPropertiesChangeListeners); //$NON-NLS-1$
+ oos.writeObject(children);
+
+ Object source = null;
+ if (sourceBean instanceof Serializable) {
+ source = sourceBean;
+ }
+ oos.writeObject(source);
+
+ oos.writeInt(propertyChangeSupportSerializedDataVersion);
+ }
+
+ @SuppressWarnings("unchecked")
+ private void readObject(ObjectInputStream ois) throws IOException,
+ ClassNotFoundException {
+ children = (Hashtable<String, List<PropertyChangeListener>>) ois
+ .readObject();
+
+ selectedPropertiesChangeListeners = new HashMap<String, List<PropertyChangeListener>>(
+ children);
+ allPropertiesChangeListeners = selectedPropertiesChangeListeners
+ .remove(""); //$NON-NLS-1$
+ if (allPropertiesChangeListeners == null) {
+ allPropertiesChangeListeners = new ArrayList<PropertyChangeListener>();
+ }
+
+ sourceBean = ois.readObject();
+ propertyChangeSupportSerializedDataVersion = ois.readInt();
+ }
+
+ public void firePropertyChange(PropertyChangeEvent event) {
+ doFirePropertyChange(event);
+ }
+
+ private PropertyChangeEvent createPropertyChangeEvent(String propertyName,
+ Object oldValue, Object newValue) {
+ return new PropertyChangeEvent(sourceBean, propertyName, oldValue,
+ newValue);
+ }
+
+ private PropertyChangeEvent createPropertyChangeEvent(String propertyName,
+ boolean oldValue, boolean newValue) {
+ return new PropertyChangeEvent(sourceBean, propertyName, oldValue,
+ newValue);
+ }
+
+ private PropertyChangeEvent createPropertyChangeEvent(String propertyName,
+ int oldValue, int newValue) {
+ return new PropertyChangeEvent(sourceBean, propertyName, oldValue,
+ newValue);
+ }
+
+ private void doFirePropertyChange(PropertyChangeEvent event) {
+ String propertyName = event.getPropertyName();
+ Object oldValue = event.getOldValue();
+ Object newValue = event.getNewValue();
+
+ if ((newValue != null) && (oldValue != null)
+ && newValue.equals(oldValue)) {
+ return;
+ }
+
+ /*
+ * Copy the listeners collections so they can be modified while we fire
+ * events.
+ */
+
+ // Listeners to all property change events
+ PropertyChangeListener[] listensToAll;
+ // Listens to a given property change
+ PropertyChangeListener[] listensToOne = null;
+ synchronized (this) {
+ listensToAll = allPropertiesChangeListeners
+ .toArray(new PropertyChangeListener[allPropertiesChangeListeners
+ .size()]);
+
+ List<PropertyChangeListener> listeners = selectedPropertiesChangeListeners
+ .get(propertyName);
+ if (listeners != null) {
+ listensToOne = listeners
+ .toArray(new PropertyChangeListener[listeners.size()]);
+ }
+ }
+
+ // Fire the listeners
+ for (PropertyChangeListener listener : listensToAll) {
+ listener.propertyChange(event);
+ }
+ if (listensToOne != null) {
+ for (PropertyChangeListener listener : listensToOne) {
+ listener.propertyChange(event);
+ }
+ }
+ }
+
+}
diff --git a/awt/java/beans/PropertyDescriptor.java b/awt/java/beans/PropertyDescriptor.java
new file mode 100644
index 0000000..9389152
--- /dev/null
+++ b/awt/java/beans/PropertyDescriptor.java
@@ -0,0 +1,300 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.util.Vector;
+import org.apache.harmony.beans.internal.nls.Messages;
+
+public class PropertyDescriptor extends FeatureDescriptor {
+ private Method getter;
+
+ private Method setter;
+
+ private Class<?> propertyEditorClass;
+
+ private boolean constrained;
+
+ private boolean bound;
+
+ public PropertyDescriptor(String propertyName, Class<?> beanClass, String getterName,
+ String setterName) throws IntrospectionException {
+ super();
+ if (beanClass == null) {
+ throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
+ }
+ if (propertyName == null || propertyName.length() == 0) {
+ throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
+ }
+ this.setName(propertyName);
+ this.setDisplayName(propertyName);
+ if (setterName != null) {
+ if (hasMethod(beanClass, setterName)) {
+ setWriteMethod(beanClass, setterName);
+ } else {
+ throw new IntrospectionException(Messages.getString("beans.20")); //$NON-NLS-1$
+ }
+ }
+ if (getterName != null) {
+ if (hasMethod(beanClass, getterName)) {
+ setReadMethod(beanClass, getterName);
+ } else {
+ throw new IntrospectionException(Messages.getString("beans.1F")); //$NON-NLS-1$
+ }
+ }
+ }
+
+ public PropertyDescriptor(String propertyName, Method getter, Method setter)
+ throws IntrospectionException {
+ super();
+ if (propertyName == null || propertyName.length() == 0) {
+ throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
+ }
+ this.setName(propertyName);
+ this.setDisplayName(propertyName);
+ setWriteMethod(setter);
+ setReadMethod(getter);
+ }
+
+ public PropertyDescriptor(String propertyName, Class<?> beanClass)
+ throws IntrospectionException {
+ String getterName;
+ String setterName;
+ if (beanClass == null) {
+ throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
+ }
+ if (propertyName == null || propertyName.length() == 0) {
+ throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
+ }
+ this.setName(propertyName);
+ this.setDisplayName(propertyName);
+ getterName = createDefaultMethodName(propertyName, "is"); //$NON-NLS-1$
+ if (hasMethod(beanClass, getterName)) {
+ setReadMethod(beanClass, getterName);
+ } else {
+ getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
+ if (hasMethod(beanClass, getterName)) {
+ setReadMethod(beanClass, getterName);
+ }
+ }
+ setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
+ if (hasMethod(beanClass, setterName)) {
+ setWriteMethod(beanClass, setterName);
+ }
+ if (getter == null && setter == null) {
+ throw new IntrospectionException(Messages.getString("beans.01", propertyName)); //$NON-NLS-1$
+ }
+ }
+
+ public void setWriteMethod(Method setter) throws IntrospectionException {
+ if (setter != null) {
+ int modifiers = setter.getModifiers();
+ if (!Modifier.isPublic(modifiers)) {
+ throw new IntrospectionException(Messages.getString("beans.05")); //$NON-NLS-1$
+ }
+ Class<?>[] parameterTypes = setter.getParameterTypes();
+ if (parameterTypes.length != 1) {
+ throw new IntrospectionException(Messages.getString("beans.06")); //$NON-NLS-1$
+ }
+ Class<?> parameterType = parameterTypes[0];
+ Class<?> propertyType = getPropertyType();
+ if (propertyType != null && !propertyType.equals(parameterType)) {
+ throw new IntrospectionException(Messages.getString("beans.07")); //$NON-NLS-1$
+ }
+ }
+ this.setter = setter;
+ }
+
+ public void setReadMethod(Method getter) throws IntrospectionException {
+ if (getter != null) {
+ int modifiers = getter.getModifiers();
+ if (!Modifier.isPublic(modifiers)) {
+ throw new IntrospectionException(Messages.getString("beans.0A")); //$NON-NLS-1$
+ }
+ Class<?>[] parameterTypes = getter.getParameterTypes();
+ if (parameterTypes.length != 0) {
+ throw new IntrospectionException(Messages.getString("beans.08")); //$NON-NLS-1$
+ }
+ Class<?> returnType = getter.getReturnType();
+ if (returnType.equals(Void.TYPE)) {
+ throw new IntrospectionException(Messages.getString("beans.33")); //$NON-NLS-1$
+ }
+ Class<?> propertyType = getPropertyType();
+ if ((propertyType != null) && !returnType.equals(propertyType)) {
+ throw new IntrospectionException(Messages.getString("beans.09")); //$NON-NLS-1$
+ }
+ }
+ this.getter = getter;
+ }
+
+ public Method getWriteMethod() {
+ return setter;
+ }
+
+ public Method getReadMethod() {
+ return getter;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ boolean result = (object != null && object instanceof PropertyDescriptor);
+ if (result) {
+ PropertyDescriptor pd = (PropertyDescriptor) object;
+ boolean gettersAreEqual = (this.getter == null) && (pd.getReadMethod() == null)
+ || (this.getter != null) && (this.getter.equals(pd.getReadMethod()));
+ boolean settersAreEqual = (this.setter == null) && (pd.getWriteMethod() == null)
+ || (this.setter != null) && (this.setter.equals(pd.getWriteMethod()));
+ boolean propertyTypesAreEqual = this.getPropertyType() == pd.getPropertyType();
+ boolean propertyEditorClassesAreEqual = this.getPropertyEditorClass() == pd
+ .getPropertyEditorClass();
+ boolean boundPropertyAreEqual = this.isBound() == pd.isBound();
+ boolean constrainedPropertyAreEqual = this.isConstrained() == pd.isConstrained();
+ result = gettersAreEqual && settersAreEqual && propertyTypesAreEqual
+ && propertyEditorClassesAreEqual && boundPropertyAreEqual
+ && constrainedPropertyAreEqual;
+ }
+ return result;
+ }
+
+ public void setPropertyEditorClass(Class<?> propertyEditorClass) {
+ this.propertyEditorClass = propertyEditorClass;
+ }
+
+ public Class<?> getPropertyType() {
+ Class<?> result = null;
+ if (getter != null) {
+ result = getter.getReturnType();
+ } else if (setter != null) {
+ Class<?>[] parameterTypes = setter.getParameterTypes();
+ result = parameterTypes[0];
+ }
+ return result;
+ }
+
+ public Class<?> getPropertyEditorClass() {
+ return propertyEditorClass;
+ }
+
+ public void setConstrained(boolean constrained) {
+ this.constrained = constrained;
+ }
+
+ public void setBound(boolean bound) {
+ this.bound = bound;
+ }
+
+ public boolean isConstrained() {
+ return constrained;
+ }
+
+ public boolean isBound() {
+ return bound;
+ }
+
+ boolean hasMethod(Class<?> beanClass, String methodName) {
+ Method[] methods = findMethods(beanClass, methodName);
+ return (methods.length > 0);
+ }
+
+ String createDefaultMethodName(String propertyName, String prefix) {
+ String result = null;
+ if (propertyName != null) {
+ String bos = propertyName.substring(0, 1).toUpperCase();
+ String eos = propertyName.substring(1, propertyName.length());
+ result = prefix + bos + eos;
+ }
+ return result;
+ }
+
+ Method[] findMethods(Class<?> aClass, String methodName) {
+ Method[] allMethods = aClass.getMethods();
+ Vector<Method> matchedMethods = new Vector<Method>();
+ Method[] result;
+ for (Method method : allMethods) {
+ if (method.getName().equals(methodName)) {
+ matchedMethods.add(method);
+ }
+ }
+ result = new Method[matchedMethods.size()];
+ for (int j = 0; j < matchedMethods.size(); ++j) {
+ result[j] = matchedMethods.elementAt(j);
+ }
+ return result;
+ }
+
+ void setReadMethod(Class<?> beanClass, String getterName) {
+ boolean result = false;
+ Method[] getters = findMethods(beanClass, getterName);
+ for (Method element : getters) {
+ try {
+ setReadMethod(element);
+ result = true;
+ } catch (IntrospectionException ie) {
+ }
+ if (result) {
+ break;
+ }
+ }
+ }
+
+ void setWriteMethod(Class<?> beanClass, String setterName) throws IntrospectionException {
+ boolean result = false;
+ Method[] setters = findMethods(beanClass, setterName);
+ for (Method element : setters) {
+ try {
+ setWriteMethod(element);
+ result = true;
+ } catch (IntrospectionException ie) {
+ }
+ if (result) {
+ break;
+ }
+ }
+ }
+
+ public PropertyEditor createPropertyEditor(Object bean) {
+ PropertyEditor editor;
+ if (propertyEditorClass == null) {
+ return null;
+ }
+ if (!PropertyEditor.class.isAssignableFrom(propertyEditorClass)) {
+ // beans.48=Property editor is not assignable from the
+ // PropertyEditor interface
+ throw new ClassCastException(Messages.getString("beans.48")); //$NON-NLS-1$
+ }
+ try {
+ Constructor<?> constr;
+ try {
+ // try to look for the constructor with single Object argument
+ constr = propertyEditorClass.getConstructor(Object.class);
+ editor = (PropertyEditor) constr.newInstance(bean);
+ } catch (NoSuchMethodException e) {
+ // try no-argument constructor
+ constr = propertyEditorClass.getConstructor();
+ editor = (PropertyEditor) constr.newInstance();
+ }
+ } catch (Exception e) {
+ // beans.47=Unable to instantiate property editor
+ RuntimeException re = new RuntimeException(Messages.getString("beans.47"), e); //$NON-NLS-1$
+ throw re;
+ }
+ return editor;
+ }
+}
diff --git a/awt/java/beans/PropertyEditor.java b/awt/java/beans/PropertyEditor.java
new file mode 100644
index 0000000..65bedea
--- /dev/null
+++ b/awt/java/beans/PropertyEditor.java
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+
+public interface PropertyEditor {
+
+ public void paintValue(Graphics gfx, Rectangle box);
+
+ public void setAsText(String text) throws IllegalArgumentException;
+
+ public String[] getTags();
+
+ public String getJavaInitializationString();
+
+ public String getAsText();
+
+ public void setValue(Object value);
+
+ public Object getValue();
+
+ public void removePropertyChangeListener(PropertyChangeListener listener);
+
+ public void addPropertyChangeListener(PropertyChangeListener listener);
+
+ public Component getCustomEditor();
+
+ public boolean supportsCustomEditor();
+
+ public boolean isPaintable();
+}
diff --git a/awt/java/beans/PropertyEditorManager.java b/awt/java/beans/PropertyEditorManager.java
new file mode 100644
index 0000000..ed55829
--- /dev/null
+++ b/awt/java/beans/PropertyEditorManager.java
@@ -0,0 +1,114 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class PropertyEditorManager {
+
+ private static String[] path = { "org.apache.harmony.beans.editors" }; //$NON-NLS-1$
+
+ private static final Map<Class<?>, Class<?>> registeredEditors = new HashMap<Class<?>, Class<?>>();
+
+ public PropertyEditorManager() {
+ }
+
+ public static void registerEditor(Class<?> targetType, Class<?> editorClass) {
+ if (targetType == null) {
+ throw new NullPointerException();
+ }
+
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPropertiesAccess();
+ }
+ if (editorClass != null) {
+ registeredEditors.put(targetType, editorClass);
+ } else {
+ registeredEditors.remove(targetType);
+ }
+ }
+
+ public static synchronized PropertyEditor findEditor(Class<?> targetType) {
+ if (targetType == null) {
+ throw new NullPointerException();
+ }
+
+ Class<?> editorClass = null;
+ PropertyEditor editor = null;
+
+ editorClass = registeredEditors.get(targetType);
+
+ if (editorClass == null) {
+ String editorClassName = targetType.getName() + "Editor"; //$NON-NLS-1$
+ ClassLoader loader = targetType.getClassLoader();
+
+ if (loader == null) {
+ loader = Thread.currentThread().getContextClassLoader();
+ }
+
+ try {
+ editorClass = Class.forName(editorClassName, true, loader);
+ } catch (ClassNotFoundException cnfe) {
+ String shortEditorClassName = editorClassName
+ .substring(editorClassName.lastIndexOf(".") + 1); //$NON-NLS-1$
+
+ if (targetType.isPrimitive()) {
+ shortEditorClassName = shortEditorClassName.substring(0, 1)
+ .toUpperCase()
+ + shortEditorClassName.substring(1);
+ }
+
+ for (String element : path) {
+ editorClassName = element + "." + shortEditorClassName; //$NON-NLS-1$
+
+ try {
+ editorClass = Class.forName(editorClassName, true,
+ loader);
+ break;
+ } catch (Exception e) {
+ }
+ }
+ } catch (Exception e) {
+ }
+ }
+
+ if (editorClass != null) {
+ try {
+ editor = (PropertyEditor) editorClass.newInstance();
+ } catch (Exception e) {
+ }
+ }
+
+ return editor;
+ }
+
+ public static synchronized void setEditorSearchPath(String[] apath) {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null) {
+ sm.checkPropertiesAccess();
+ }
+
+ path = apath;
+ }
+
+ public static synchronized String[] getEditorSearchPath() {
+ return path;
+ }
+}
diff --git a/awt/java/beans/PropertyEditorSupport.java b/awt/java/beans/PropertyEditorSupport.java
new file mode 100644
index 0000000..c3929a1
--- /dev/null
+++ b/awt/java/beans/PropertyEditorSupport.java
@@ -0,0 +1,129 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package java.beans;
+
+import java.awt.Component;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.harmony.beans.internal.nls.Messages;
+
+public class PropertyEditorSupport implements PropertyEditor {
+
+ Object source = null;
+
+ List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
+
+ Object oldValue = null;
+
+ Object newValue = null;
+
+ public PropertyEditorSupport(Object source) {
+ if (source == null) {
+ throw new NullPointerException(Messages.getString("beans.0C")); //$NON-NLS-1$
+ }
+ this.source = source;
+ }
+
+ public PropertyEditorSupport() {
+ source = this;
+ }
+
+ public void paintValue(Graphics gfx, Rectangle box) {
+ }
+
+ public void setAsText(String text) throws IllegalArgumentException {
+ if (newValue instanceof String) {
+ setValue(text);
+ } else {
+ throw new IllegalArgumentException(text);
+ }
+ }
+
+ public String[] getTags() {
+ return null;
+ }
+
+ public String getJavaInitializationString() {
+ return "???"; //$NON-NLS-1$
+ }
+
+ public String getAsText() {
+ return newValue == null ? "null" : newValue.toString(); //$NON-NLS-1$
+ }
+
+ public void setValue(Object value) {
+ this.oldValue = this.newValue;
+ this.newValue = value;
+ firePropertyChange();
+ }
+
+ public Object getValue() {
+ return newValue;
+ }
+
+ public void setSource(Object source) {
+ if (source == null) {
+ throw new NullPointerException(Messages.getString("beans.0C")); //$NON-NLS-1$
+ }
+ this.source = source;
+ }
+
+ public Object getSource() {
+ return source;
+ }
+
+ public synchronized void removePropertyChangeListener(
+ PropertyChangeListener listener) {
+ if (listeners != null) {
+ listeners.remove(listener);
+ }
+ }
+
+ public synchronized void addPropertyChangeListener(
+ PropertyChangeListener listener) {
+ listeners.add(listener);
+ }
+
+ public Component getCustomEditor() {
+ return null;
+ }
+
+ public boolean supportsCustomEditor() {
+ return false;
+ }
+
+ public boolean isPaintable() {
+ return false;
+ }
+
+ public void firePropertyChange() {
+ if (listeners.size() > 0) {
+ PropertyChangeEvent event = new PropertyChangeEvent(source, null,
+ oldValue, newValue);
+ Iterator<PropertyChangeListener> iterator = listeners.iterator();
+
+ while (iterator.hasNext()) {
+ PropertyChangeListener listener = iterator.next();
+ listener.propertyChange(event);
+ }
+ }
+ }
+}
diff --git a/awt/java/beans/PropertyVetoException.java b/awt/java/beans/PropertyVetoException.java
new file mode 100644
index 0000000..c7f092a
--- /dev/null
+++ b/awt/java/beans/PropertyVetoException.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package java.beans;
+
+/**
+ * Indicates that a proposed property change is unacceptable.
+ */
+public class PropertyVetoException extends Exception {
+
+ private static final long serialVersionUID = 129596057694162164L;
+
+ private final PropertyChangeEvent evt;
+
+ /**
+ * <p>
+ * Constructs an instance with a message and the change event.
+ * </p>
+ *
+ * @param message
+ * A description of the veto.
+ * @param event
+ * The event that was vetoed.
+ */
+ public PropertyVetoException(String message, PropertyChangeEvent event) {
+ super(message);
+ this.evt = event;
+ }
+
+ /**
+ * <p>
+ * Gets the property change event.
+ * </p>
+ *
+ * @return An instance of {@link PropertyChangeEvent}
+ */
+ public PropertyChangeEvent getPropertyChangeEvent() {
+ return evt;
+ }
+}