You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2006/03/20 17:31:33 UTC
svn commit: r387239 [3/21] - in
/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math: ./
Harmony/ doc/ doc/images/ make/ src/ src/common/ src/common/javasrc/
src/common/javasrc/java/ src/common/javasrc/java/applet/
src/common/javasrc/jav...
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/EventHandler.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/EventHandler.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/EventHandler.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/EventHandler.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,392 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.7.6.3 $
+ */
+package java.beans;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.lang.reflect.Proxy;
+import java.util.StringTokenizer;
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.7.6.3 $
+ */
+
+public class EventHandler implements InvocationHandler {
+
+ private Object target;
+ private String action;
+ private String eventPropertyName;
+ private String listenerMethodName;
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public EventHandler(Object target, String action, String eventPropertyName,
+ String listenerMethodName) {
+ this.target = target;
+ this.action = action;
+ this.eventPropertyName = eventPropertyName;
+ this.listenerMethodName = listenerMethodName;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Object invoke(Object proxy, Method method, Object[] arguments) {
+ // workaround if arguments are null - treat them as array with
+ // single null element
+ if(arguments == null) {
+ arguments = new Object[] { null };
+ }
+
+ Class proxyClass = proxy.getClass();
+ // if a proxy
+ if(Proxy.isProxyClass(proxyClass)) {
+ InvocationHandler handler = Proxy.getInvocationHandler(proxy);
+ // if a valid object
+ if((handler instanceof EventHandler) && isValidInvocation(method,
+ arguments)) {
+ try {
+ Object[] args = getArgs(arguments); // extract value from event property name
+ Method m = getMethod(proxy, method, arguments, args); // extract method to be invoked on target
+ return m.invoke(target, args);
+ } catch (Throwable t) {
+ System.out.println(t.getClass() + ": " + t.getMessage());
+ return null;
+ }
+ } else {
+ // if not a valid call
+ return null;
+ }
+ } else {
+ // if not a valid object
+ return null;
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public String getListenerMethodName() {
+ return listenerMethodName;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public String getEventPropertyName() {
+ return eventPropertyName;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public String getAction() {
+ return action;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Object getTarget() {
+ return target;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public static Object create(
+ Class listenerInterface,
+ Object target,
+ String action,
+ String eventPropertyName,
+ String listenerMethodName) {
+ return Proxy.newProxyInstance(null, new Class[] { listenerInterface },
+ new EventHandler(target, action, eventPropertyName,
+ listenerMethodName));
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public static Object create(
+ Class listenerInterface,
+ Object target,
+ String action,
+ String eventPropertyName) {
+ return Proxy.newProxyInstance(null, new Class[] { listenerInterface },
+ new EventHandler(target, action, eventPropertyName, null));
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public static Object create(
+ Class listenerInterface,
+ Object target,
+ String action) {
+ return Proxy.newProxyInstance(null, new Class[] { listenerInterface },
+ new EventHandler(target, action, null, null));
+ }
+
+ private boolean isValidInvocation(Method method, Object[] arguments) {
+ boolean result = false;
+
+ if(listenerMethodName == null) { // all listener methods are valid
+ result = true;
+ } else if (listenerMethodName.equals(method.getName())) { // method's name matches
+ // no arguments in call are valid
+ if((eventPropertyName == null) && ((arguments == null)
+ || (arguments.length == 0))) {
+ result = true;
+ // one-argument call is value
+ } else if ((eventPropertyName != null) && (arguments != null)
+ && (arguments.length == 1)){
+ result = true;
+ } else {
+ result = false;
+ }
+ } else {
+ result = false;
+ }
+
+ return result;
+ }
+
+ private Object[] getArgs(Object[] arguments) throws Exception {
+ if(eventPropertyName == null) {
+ return new Object[] {};
+ } else if ((arguments == null) || (arguments.length == 0)
+ || (arguments[0] == null)) {
+ return arguments;
+ } else {
+ Object arg = arguments[0];
+ StringTokenizer st = new StringTokenizer(eventPropertyName, ".");
+
+ while(st.hasMoreTokens()) {
+ String propertyName = st.nextToken();
+ PropertyDescriptor pd = findPropertyDescriptor(arg.getClass(),
+ propertyName);
+
+ if(pd != null) {
+ Method getter = pd.getReadMethod();
+
+ if(getter != null) {
+ arg = getter.invoke(arg, new Object[] {});
+ } else {
+ throw new IntrospectionException(
+ "no getter for property " + propertyName
+ + " found");
+ }
+ } else {
+ Method method = findStaticGetter(arg.getClass(),
+ propertyName);
+
+ if(method != null) {
+ arg = method.invoke(null, new Object[] {});
+ } else {
+ throw new IntrospectionException(
+ "cannot access property " + propertyName
+ + " getter");
+ }
+ }
+ }
+ return new Object[] { arg };
+ }
+ }
+
+ private Method getMethod(
+ Object proxy,
+ Method method,
+ Object[] arguments,
+ Object[] args) throws Exception {
+ Method result = null;
+
+ // filtering - examine if the 'method' could be applied to proxy
+
+ boolean found = false;
+
+ // can be invoke with any listener method
+ if(listenerMethodName == null) {
+ Class[] proxyInterfaces = proxy.getClass().getInterfaces();
+
+ for(int i = 0; i < proxyInterfaces.length; ++i) {
+ Method[] interfaceMethods = proxyInterfaces[i].getMethods();
+
+ for(int k = 0; k < interfaceMethods.length; ++k) {
+ Method listenerMethod = interfaceMethods[k];
+
+ if(equalNames(listenerMethod, method)
+ && canInvokeWithArguments(listenerMethod,
+ arguments)) {
+ found = true;
+ break;
+ }
+ }
+
+ if(found) {
+ break;
+ }
+
+ }
+
+ // can be invoked with a specified listener method
+ } else if(method.getName().equals(listenerMethodName)){
+ found = true;
+ }
+
+ if(found == false) {
+ return null;
+ }
+
+ // 'Method' can be applied to proxy - filtering succeeded
+ try {
+ result = findMethod(target.getClass(), args);
+ if(result == null) {
+ PropertyDescriptor pd = findPropertyDescriptor(
+ target.getClass(), action);
+ if(pd != null) {
+ result = pd.getWriteMethod();
+
+ if(result == null) {
+ throw new NoSuchMethodException(
+ "no setter for property " + action + " found");
+ }
+ } else {
+ throw new Exception(
+ "Exception while finding property descriptor");
+ }
+ } else {
+ return result;
+ }
+ } catch (IntrospectionException ie) {
+ throw new Exception("Exception while finding property descriptor");
+ }
+
+ return result;
+ }
+
+ private PropertyDescriptor findPropertyDescriptor(
+ Class theClass, String propertyName) throws IntrospectionException
+ {
+ PropertyDescriptor result = null;
+ BeanInfo beanInfo = Introspector.getBeanInfo(theClass);
+ PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
+ for(int i = 0; i < pds.length; ++i) {
+ if(pds[i].getName().equals(propertyName)) {
+ result = pds[i];
+ break;
+ }
+ }
+ return result;
+ }
+
+ private Method findStaticGetter(
+ Class theClass, String propertyName) throws IntrospectionException
+ {
+ Method result = null;
+
+ Method[] methods = theClass.getMethods();
+ for(int i = 0; i < methods.length; ++i) {
+ int modifiers = methods[i].getModifiers();
+
+ if(Modifier.isStatic(modifiers) && Modifier.isPublic(modifiers)) {
+ String methodName = methods[i].getName();
+ String postfix = null;
+
+ if(methodName.startsWith("get")) {
+ postfix = methodName.substring(3);
+ } else if(methodName.startsWith("is")) {
+ postfix = methodName.substring(2);
+ } else {
+ continue;
+ }
+
+ if(
+ (methods[i].getParameterTypes().length != 0) ||
+ (methods[i].getReturnType() == void.class)
+ ) {
+ continue;
+ }
+
+ postfix = Introspector.decapitalize(postfix);
+ if(postfix.equals(propertyName)) {
+ result = methods[i];
+ break;
+ }
+ }
+ }
+
+ return result;
+ }
+
+ private Method findMethod(Class type, Object[] args) {
+ Method[] methods = type.getMethods();
+
+ for(int i = 0; i < methods.length; ++i) {
+ if(action.equals(methods[i].getName()) && canInvokeWithArguments(
+ methods[i], args)) {
+ return methods[i];
+ }
+ }
+
+ return null;
+ }
+
+ private static boolean isPrimitiveWrapper(Class wrapper, Class base) {
+ return (base == boolean.class) && (wrapper == Boolean.class) ||
+ (base == byte.class) && (wrapper == Byte.class) ||
+ (base == char.class) && (wrapper == Character.class) ||
+ (base == short.class) && (wrapper == Short.class) ||
+ (base == int.class) && (wrapper == Integer.class) ||
+ (base == long.class) && (wrapper == Long.class) ||
+ (base == float.class) && (wrapper == Float.class) ||
+ (base == double.class) && (wrapper == Double.class);
+ }
+
+ private static boolean canInvokeWithArguments(Method m, Object[] arguments) {
+ Class[] parameterTypes = m.getParameterTypes();
+
+ if(parameterTypes.length == arguments.length) {
+ for(int i = 0; i < arguments.length; ++i) {
+ Class argumentType = (arguments[i] == null) ? null
+ : arguments[i].getClass();
+ if((argumentType == null) || isPrimitiveWrapper(argumentType,
+ parameterTypes[i])) {
+ // ... nothing to do - just not to break the cycle
+ } else if(!argumentType.isAssignableFrom(parameterTypes[i])) {
+ return false;
+ }
+ }
+ } else {
+ return false;
+ }
+
+ return true;
+
+ }
+
+ private static boolean equalNames(Method m1, Method m2) {
+ return m1.getName().equals(m2.getName());
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/EventSetDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/EventSetDescriptor.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/EventSetDescriptor.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/EventSetDescriptor.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,470 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.9.6.3 $
+ */
+package java.beans;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.TooManyListenersException;
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.9.6.3 $
+ */
+
+public class EventSetDescriptor extends FeatureDescriptor {
+
+ private String eventSetName = null;
+
+ private Class listenerType = null;
+ private ArrayList listenerMethodDescriptors = new ArrayList();
+
+ private Method getListenerMethod = null;
+ private Method addListenerMethod = null;
+ private Method removeListenerMethod = null;
+
+ private boolean unicast = false;
+ private boolean inDefaultEventSet = true;
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public EventSetDescriptor(Class sourceClass, String eventSetName,
+ Class listenerType, String listenerMethodName
+ ) throws IntrospectionException {
+
+ super();
+
+ setName(eventSetName);
+ setDisplayName(eventSetName);
+ this.eventSetName = eventSetName;
+ this.listenerType = listenerType;
+
+ this.listenerMethodDescriptors.add(
+ new MethodDescriptor(findMethodByName(listenerType,
+ listenerMethodName)));
+
+ this.addListenerMethod = findMethodByPrefix(sourceClass, "add", "",
+ listenerType);
+ this.removeListenerMethod = findMethodByPrefix(sourceClass, "remove",
+ "", listenerType);
+
+ if(addListenerMethod == null && removeListenerMethod == null) {
+ throw new IntrospectionException(
+ "Add and remove methods are not available");
+ }
+
+ this.getListenerMethod = findMethodByPrefix(sourceClass, "get", "s",
+ listenerType);
+
+ this.unicast = isUnicastByDefault(addListenerMethod);
+
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public EventSetDescriptor(Class sourceClass, String eventSetName,
+ Class listenerType, String[] listenerMethodNames,
+ String addListenerMethodName, String removeListenerMethodName
+ ) throws IntrospectionException {
+ super();
+
+ setName(eventSetName);
+ setDisplayName(eventSetName);
+ this.eventSetName = eventSetName;
+ this.listenerType = listenerType;
+
+ if(listenerMethodNames != null) {
+ for(int i = 0; i < listenerMethodNames.length; ++i) {
+ try {
+ listenerMethodDescriptors.add(new MethodDescriptor(
+ findMethodByName(listenerType, listenerMethodNames[i])));
+ } catch (IntrospectionException ie) {
+ listenerMethodDescriptors.clear();
+ throw ie;
+ }
+ }
+ }
+
+ this.addListenerMethod = findMethodByName(listenerType,
+ addListenerMethodName);
+ this.removeListenerMethod = findMethodByName(listenerType,
+ removeListenerMethodName);
+ this.getListenerMethod = null;
+
+ this.unicast = isUnicastByDefault(addListenerMethod);
+
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public EventSetDescriptor(
+ Class sourceClass,
+ String eventSetName,
+ Class listenerType,
+ String[] listenerMethodNames,
+ String addListenerMethodName,
+ String removeListenerMethodName,
+ String getListenerMethodName) throws IntrospectionException {
+ super();
+
+ setName(eventSetName);
+ setDisplayName(eventSetName);
+ this.eventSetName = eventSetName;
+ this.listenerType = listenerType;
+
+ if(listenerMethodNames != null) {
+ for(int i = 0; i < listenerMethodNames.length; ++i) {
+ try {
+ listenerMethodDescriptors.add(
+ new MethodDescriptor(findMethodByName(listenerType,
+ listenerMethodNames[i])));
+ } catch (IntrospectionException ie) {
+ listenerMethodDescriptors.clear();
+ throw ie;
+ }
+ }
+ }
+
+ this.addListenerMethod = findMethodByName(listenerType,
+ addListenerMethodName);
+ this.removeListenerMethod = findMethodByName(listenerType,
+ removeListenerMethodName);
+ this.getListenerMethod = findMethodByName(listenerType,
+ getListenerMethodName);
+
+ this.unicast = isUnicastByDefault(addListenerMethod);
+
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public EventSetDescriptor(
+ String eventSetName,
+ Class listenerType,
+ Method[] listenerMethods,
+ Method addListenerMethod,
+ Method removeListenerMethod) throws IntrospectionException {
+ super();
+
+ setName(eventSetName);
+ setDisplayName(eventSetName);
+ this.eventSetName = eventSetName;
+ this.listenerType = listenerType;
+
+ if(listenerMethods != null) {
+ for(int i = 0; i < listenerMethods.length; ++i) {
+ if(checkMethod(listenerType, listenerMethods[i])) {
+ this.listenerMethodDescriptors.add(new MethodDescriptor(
+ listenerMethods[i]));
+ }
+ }
+ }
+
+ this.addListenerMethod = checkRegistrationMethod(listenerType,
+ addListenerMethod);
+ this.removeListenerMethod = checkRegistrationMethod(listenerType,
+ removeListenerMethod);
+ this.getListenerMethod = null;
+
+ this.unicast = isUnicastByDefault(addListenerMethod);
+
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public EventSetDescriptor(String eventSetName, Class listenerType,
+ Method[] listenerMethods, Method addListenerMethod,
+ Method removeListenerMethod, Method getListenerMethod
+ ) throws IntrospectionException {
+
+ super();
+
+ setName(eventSetName);
+ setDisplayName(eventSetName);
+ this.eventSetName = eventSetName;
+ this.listenerType = listenerType;
+
+ if(listenerMethods != null) {
+ for(int i = 0; i < listenerMethods.length; ++i) {
+ if(checkMethod(listenerType, listenerMethods[i])) {
+ this.listenerMethodDescriptors.add(new MethodDescriptor(
+ listenerMethods[i]));
+ }
+ }
+ }
+
+ this.addListenerMethod = checkRegistrationMethod(listenerType,
+ addListenerMethod);
+ this.removeListenerMethod = checkRegistrationMethod(listenerType,
+ removeListenerMethod);
+ this.getListenerMethod = checkGetListenerMethod(listenerType,
+ getListenerMethod);
+
+ this.unicast = isUnicastByDefault(addListenerMethod);
+
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public EventSetDescriptor(String eventSetName, Class listenerType,
+ MethodDescriptor[] listenerMethodDescriptors,
+ Method addListenerMethod, Method removeListenerMethod
+ ) throws IntrospectionException {
+ super();
+
+ setName(eventSetName);
+ setDisplayName(eventSetName);
+ this.eventSetName = eventSetName;
+ this.listenerType = listenerType;
+
+ for (int i = 0; i < listenerMethodDescriptors.length; ++i) {
+ Method listenerMethod = listenerMethodDescriptors[i].getMethod();
+ if(checkMethod(listenerType, listenerMethod)) {
+ this.listenerMethodDescriptors.add(
+ listenerMethodDescriptors[i]);
+ }
+ }
+
+ this.addListenerMethod = checkRegistrationMethod(listenerType,
+ addListenerMethod);
+ this.removeListenerMethod = checkRegistrationMethod(listenerType,
+ removeListenerMethod);
+ this.getListenerMethod = null;
+
+ this.unicast = isUnicastByDefault(addListenerMethod);
+
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Method[] getListenerMethods() {
+ Method[] result = new Method[listenerMethodDescriptors.size()];
+ Iterator i = listenerMethodDescriptors.iterator();
+ int idx = 0;
+ while(i.hasNext()) {
+ MethodDescriptor md = (MethodDescriptor) i.next();
+ result[idx] = md.getMethod();
+ idx++;
+ }
+ return result;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public MethodDescriptor[] getListenerMethodDescriptors() {
+ MethodDescriptor[] result =
+ new MethodDescriptor[listenerMethodDescriptors.size()];
+ Iterator i = listenerMethodDescriptors.iterator();
+ int idx = 0;
+ while(i.hasNext()) {
+ result[idx] = (MethodDescriptor) i.next();
+ idx++;
+ }
+ return result;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Method getRemoveListenerMethod() {
+ return removeListenerMethod;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Method getGetListenerMethod() {
+ return getListenerMethod;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Method getAddListenerMethod() {
+ return addListenerMethod;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Class getListenerType() {
+ return listenerType;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setUnicast(boolean unicast) {
+ this.unicast = unicast;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setInDefaultEventSet(boolean inDefaultEventSet) {
+ this.inDefaultEventSet = inDefaultEventSet;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public boolean isUnicast() {
+ return unicast;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public boolean isInDefaultEventSet() {
+ return inDefaultEventSet;
+ }
+
+ private Class getEventType(Class listenerType)
+ throws ClassNotFoundException {
+ String listenerTypeName = listenerType.getName();
+ int idx = listenerTypeName.lastIndexOf("Listener");
+ String eventTypeName = listenerTypeName.substring(0, idx) + "Event";
+ return Class.forName(eventTypeName, true,
+ listenerType.getClassLoader());
+ }
+
+ private boolean checkMethod(Class listenerType, Method listenerMethod)
+ throws IntrospectionException {
+ if(listenerMethod != null
+ && !listenerMethod.getDeclaringClass().isAssignableFrom(
+ listenerType)) {
+ throw new IntrospectionException("No method \""
+ + listenerMethod.getName() + "\" for "
+ + listenerType.getName() + " found.");
+ } else {
+ return true;
+ }
+ }
+
+ private Method findMethodByName(Class listenerType,
+ String listenerMethodName) throws IntrospectionException {
+ try {
+ return listenerType.getMethod(listenerMethodName,
+ new Class[] { getEventType(listenerType) });
+ } catch (NoSuchMethodException nsme) {
+ throw new IntrospectionException("No method \""
+ + listenerMethodName + "\" for " + listenerType.getName()
+ + " found.");
+ } catch (ClassNotFoundException cnfe) {
+ throw new IntrospectionException(
+ "Cannot acquire event type from " + listenerType.getName()
+ + " listener.");
+ }
+ }
+
+ private Method findMethodByPrefix(
+ Class sourceClass,
+ String prefix,
+ String postfix,
+ Class listenerType) {
+ String fullName = listenerType.getName(); // com.drl.beans.SmthListener
+ int idx = fullName.lastIndexOf(".");
+ String methodName = prefix + fullName.substring(idx + 1) + postfix; // prefix(e.g., add) + SmthListener
+ try {
+ if(prefix.equals("get")) {
+ return sourceClass.getMethod(methodName, new Class[] {});
+ } else {
+ return sourceClass.getMethod(methodName,
+ new Class[] { listenerType });
+ }
+ } catch (NoSuchMethodException nsme) {
+ return null;
+ }
+
+ }
+
+ private static boolean isUnicastByDefault(Method addMethod) {
+ if(addMethod != null) {
+ Class[] exceptionTypes = addMethod.getExceptionTypes();
+ for(int i = 0; i < exceptionTypes.length; ++i) {
+ if(exceptionTypes[i].equals(TooManyListenersException.class)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private static Method checkRegistrationMethod(
+ Class listenerType,
+ Method registrationMethod) throws IntrospectionException {
+ if(registrationMethod == null) {
+ return null;
+ } else {
+ Class returnType = registrationMethod.getReturnType();
+
+ if(returnType != void.class) {
+ throw new IntrospectionException(registrationMethod.getName()
+ + " does not return <void>");
+ }
+
+ Class[] parameterTypes = registrationMethod.getParameterTypes();
+ if(parameterTypes == null || parameterTypes.length != 1) {
+ throw new IntrospectionException(registrationMethod.getName()
+ + " should have a single input parameter");
+ } else if(parameterTypes[0] != listenerType){
+ throw new IntrospectionException(
+ "Single parameter does not match to "
+ + listenerType.getName() + " class");
+ } else {
+ return registrationMethod;
+ }
+ }
+ }
+
+ private static Method checkGetListenerMethod(
+ Class listenerType,
+ Method getListenerMethod) throws IntrospectionException {
+ if(getListenerMethod == null) {
+ return null;
+ } else {
+ Class[] parameterTypes = getListenerMethod.getParameterTypes();
+
+ if(parameterTypes.length != 0) {
+ throw new IntrospectionException(
+ "No input params are allowed for getListenerMethod");
+ }
+
+ Class returnType = getListenerMethod.getReturnType();
+ if(returnType.isArray()
+ && returnType.getComponentType() == listenerType) {
+ return getListenerMethod;
+ } else {
+ throw new IntrospectionException(
+ "Return type of getListenerMethod is not an array "
+ + "of listeners");
+ }
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/ExceptionListener.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/ExceptionListener.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/ExceptionListener.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/ExceptionListener.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.2.6.3 $
+ */
+package java.beans;
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.2.6.3 $
+ */
+
+public interface ExceptionListener {
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void exceptionThrown(Exception e);
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/Expression.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/Expression.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/Expression.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/Expression.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,86 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.7.6.3 $
+ */
+package java.beans;
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.7.6.3 $
+ */
+
+public class Expression extends Statement {
+
+ boolean valueIsDefined = false;
+ Object value;
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Expression(
+ Object value,
+ Object target,
+ String methodName,
+ Object[] arguments) {
+ super(target, methodName, arguments);
+ this.value = value;
+ this.valueIsDefined = true;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Expression(Object target, String methodName, Object[] arguments) {
+ super(target, methodName, arguments);
+ this.value = null;
+ this.valueIsDefined = false;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public String toString() {
+ try {
+ Object resultValue = getValue();
+ String result = (resultValue == null) ? "<null>"
+ : convertClassName(resultValue.getClass());
+ return result + "=" + super.toString();
+ } catch(Exception e) {
+ return new String("Error in expression: " + e.getClass());
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setValue(Object value) {
+ this.value = value;
+ this.valueIsDefined = true;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Object getValue() throws Exception {
+ if((value == null) && !valueIsDefined) {
+ value = invokeMethod();
+ }
+ return value;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/FeatureDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/FeatureDescriptor.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/FeatureDescriptor.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/FeatureDescriptor.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,170 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.4.6.3 $
+ */
+package java.beans;
+
+import java.util.HashMap;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.StringTokenizer;
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.4.6.3 $
+ */
+
+public class FeatureDescriptor {
+
+ private HashMap values = new HashMap();
+ boolean preferred, hidden, expert;
+ String shortDescription = null;
+ String name = null;
+ String displayName = null;
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public FeatureDescriptor() {
+ this.preferred = false;
+ this.hidden = false;
+ this.expert = false;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setValue(String attributeName, Object value) {
+ if ((attributeName != null) && (value != null)) {
+ values.put(attributeName, value);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Object getValue(String attributeName) {
+ Object result = null;
+ if (attributeName != null) {
+ result = values.get(attributeName);
+ }
+ return result;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Enumeration attributeNames() {
+ String attributeNamesStr = "";
+ Iterator i = values.keySet().iterator();
+ while(i.hasNext()) {
+ String attributeName = (String) i.next();
+ if(attributeNamesStr.equals("")) {
+ attributeNamesStr += attributeName;
+ } else {
+ attributeNamesStr += ' ' + attributeName;
+ }
+ }
+ return new StringTokenizer(attributeNamesStr);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setShortDescription(String text) {
+ this.shortDescription = text;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setDisplayName(String displayName) {
+ this.displayName = displayName;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public String getShortDescription() {
+ return shortDescription;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public String getDisplayName() {
+ return displayName;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setPreferred(boolean preferred) {
+ this.preferred = preferred;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setHidden(boolean hidden) {
+ this.hidden = hidden;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setExpert(boolean expert) {
+ this.expert = expert;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public boolean isPreferred() {
+ return preferred;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public boolean isHidden() {
+ return hidden;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public boolean isExpert() {
+ return expert;
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/IndexedPropertyDescriptor.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/IndexedPropertyDescriptor.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/IndexedPropertyDescriptor.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/IndexedPropertyDescriptor.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,226 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.5.6.3 $
+ */
+package java.beans;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.5.6.3 $
+ */
+
+public class IndexedPropertyDescriptor extends PropertyDescriptor {
+
+ private Method indexedGetter = null;
+ private Method indexedSetter = null;
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public IndexedPropertyDescriptor(
+ String propertyName,
+ Class beanClass,
+ String getterName,
+ String setterName,
+ String indexedGetterName,
+ String indexedSetterName) throws IntrospectionException {
+ super(propertyName, beanClass, getterName, setterName);
+ setIndexedReadMethod(beanClass, indexedGetterName);
+ setIndexedWriteMethod(beanClass, indexedSetterName);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public IndexedPropertyDescriptor(
+ String propertyName,
+ Method getter,
+ Method setter,
+ Method indexedGetter,
+ Method indexedSetter) throws IntrospectionException {
+ super(propertyName, getter, setter);
+ setIndexedReadMethod(indexedGetter);
+ setIndexedWriteMethod(indexedGetter);
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public IndexedPropertyDescriptor(String propertyName, Class beanClass)
+ throws IntrospectionException {
+ super(propertyName, beanClass);
+
+ String indexedGetterName = createDefaultMethodName(propertyName, "get");
+ if(hasMethod(beanClass, indexedGetterName)) {
+ setIndexedReadMethod(beanClass, indexedGetterName);
+ }
+
+ String indexedSetterName = createDefaultMethodName(propertyName, "set");
+ if(hasMethod(beanClass, indexedSetterName)) {
+ setIndexedWriteMethod(beanClass, indexedSetterName);
+ }
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setIndexedReadMethod(Method indexedGetter)
+ throws IntrospectionException {
+ if (indexedGetter != null) {
+ int modifiers = indexedGetter.getModifiers();
+ if (!Modifier.isPublic(modifiers)) {
+ throw new IntrospectionException(
+ "Modifier for indexed getter method should be public.");
+ }
+
+ Class[] parameterTypes = indexedGetter.getParameterTypes();
+ if (parameterTypes.length != 1) {
+ throw new IntrospectionException(
+ "Number of parameters in getter method is not "
+ + "equal to 1.");
+ }
+
+ if (!parameterTypes[0].equals(int.class)) {
+ throw new IntrospectionException(
+ "Parameter in indexed getter method is not of "
+ + "integer type.");
+ }
+
+ Class returnType = indexedGetter.getReturnType();
+ Class indexedPropertyType = getIndexedPropertyType();
+ if((indexedPropertyType != null) && !returnType.equals(
+ indexedPropertyType)) {
+ throw new IntrospectionException(
+ "Parameter type in indexed getter method does not "
+ + "correspond to predefined.");
+ }
+ }
+
+ this.indexedGetter = indexedGetter;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public void setIndexedWriteMethod(Method indexedSetter)
+ throws IntrospectionException {
+ if (indexedSetter != null) {
+ int modifiers = indexedSetter.getModifiers();
+ if (!Modifier.isPublic(modifiers)) {
+ throw new IntrospectionException(
+ "Modifier for indexed setter method should be public.");
+ }
+
+ Class[] parameterTypes = indexedSetter.getParameterTypes();
+ if (parameterTypes.length != 2) {
+ throw new IntrospectionException(
+ "Number of parameters in indexed setter method is not "
+ + "equal to 2.");
+ }
+
+ Class firstParameterType = parameterTypes[0];
+ if (!firstParameterType.equals(int.class)) {
+ throw new IntrospectionException(
+ "First parameter type in indexed setter method "
+ + "should be int.");
+ }
+
+ Class secondParameterType = parameterTypes[1];
+ if (!secondParameterType.equals(getIndexedPropertyType())) {
+ throw new IntrospectionException(
+ "Second parameter type in indexed setter method "
+ + "does not corresponds to predefined.");
+ }
+ }
+
+ this.indexedSetter = indexedSetter;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Method getIndexedWriteMethod() {
+ return indexedSetter;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public Method getIndexedReadMethod() {
+ return indexedGetter;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public boolean equals(Object obj) {
+ boolean result = super.equals(obj);
+ if(result) {
+ IndexedPropertyDescriptor pd = (IndexedPropertyDescriptor) obj;
+ result =
+ (this.indexedGetter.equals(pd.getIndexedReadMethod())) &&
+ (this.indexedSetter.equals(pd.getIndexedWriteMethod()));
+ return result;
+ }
+ return result;
+ }
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ 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 (int i = 0; i < getters.length; ++i) {
+ try {
+ setIndexedReadMethod(getters[i]);
+ result = true;
+ } catch (IntrospectionException ie) {}
+ if (result) break;
+ }
+ }
+
+ private void setIndexedWriteMethod(Class beanClass,
+ String indexedSetterName) {
+ Method[] setters = findMethods(beanClass, indexedSetterName);
+ boolean result = false;
+ for (int i = 0; i < setters.length; ++i) {
+ try {
+ setIndexedWriteMethod(setters[i]);
+ result = true;
+ } catch (IntrospectionException ie) {}
+ if (result) break;
+ }
+ }
+}
Added: incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/IntrospectionException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/IntrospectionException.java?rev=387239&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/IntrospectionException.java (added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/regex-beans-math/src/common/javasrc/java/beans/IntrospectionException.java Mon Mar 20 08:31:09 2006
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
+ *
+ * Licensed 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.
+ */
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.2.6.3 $
+ */
+package java.beans;
+
+/**
+ * @author Maxim V. Berkultsev
+ * @version $Revision: 1.2.6.3 $
+ */
+
+public class IntrospectionException extends Exception {
+
+ String message;
+
+ /**
+ * @com.intel.drl.spec_ref
+ */
+ public IntrospectionException(String message) {
+ this.message = message;
+ }
+}