/**
  * Creates an array of parameters to pass to the given mutator method.
  * If the given object is not the right type to pass to the method
  * directly, it will be converted using {@link #convertType(Class,Object)}.
  *
  * @param method  the mutator method
  * @param value  the value to pass to the mutator method
  * @return an array containing one object that is either the given value
  *   or a transformed value
  * @throws IllegalAccessException if {@link #convertType(Class,Object)}
  *   raises it
  * @throws IllegalArgumentException if any other exception is raised
  *   by {@link #convertType(Class,Object)}
  */
 protected Object[] createWriteMethodArguments(java.lang.reflect.Method method, Object value)
 {//throws IllegalAccessException, ClassCastException {
     try
     {
         if (value != null)
         {
             java.lang.Class[] types = method.getParameterTypes();
             if (types != null && types.Length > 0)
             {
                 java.lang.Class paramType = types[0];
                 if (!paramType.isAssignableFrom(value.getClass()))
                 {
                     value = convertType(paramType, value);
                 }
             }
         }
         Object[] answer = { value };
         return(answer);
     }
     catch (java.lang.reflect.InvocationTargetException e)
     {
         logInfo(e);
         throw new java.lang.IllegalArgumentException(e.getMessage());
     }
     catch (java.lang.InstantiationException e)
     {
         logInfo(e);
         throw new java.lang.IllegalArgumentException(e.getMessage());
     }
 }
        /**
         * Sets the bean property with the given name to the given value.
         *
         * @param name  the name of the property to set
         * @param value  the value to set that property to
         * @return  the previous value of that property
         * @throws IllegalArgumentException  if the given name is null;
         *   if the given name is not a {@link String}; if the bean doesn't
         *   define a property with that name; or if the bean property with
         *   that name is read-only
         */
        public override Object put(Object name, Object value)
        {//throws IllegalArgumentException, ClassCastException {
            if (bean != null)
            {
                Object oldValue = get(name);
                java.lang.reflect.Method method = getWriteMethod(name);
                if (method == null)
                {
                    throw new java.lang.IllegalArgumentException("The bean of type: " + bean.getClass().getName() + " has no property called: " + name);
                }
                try
                {
                    Object[] arguments = createWriteMethodArguments(method, value);
                    method.invoke(bean, arguments);

                    Object newValue = get(name);
                    firePropertyChange(name, oldValue, newValue);
                }
                catch (java.lang.reflect.InvocationTargetException e)
                {
                    logInfo(e);
                    throw new java.lang.IllegalArgumentException(e.getMessage());
                }
                catch (java.lang.IllegalAccessException e)
                {
                    logInfo(e);
                    throw new java.lang.IllegalArgumentException(e.getMessage());
                }
                return(oldValue);
            }
            return(null);
        }
 /**
  * Constructs an instance for the given type element and the type found.
  *
  * @param element
  *            the annotation type element.
  * @param foundType
  *            the invalid type that was found. This is actually the textual
  *            type description found in the binary class representation,
  *            so it may not be human-readable.
  */
 public AnnotationTypeMismatchException(java.lang.reflect.Method element, String foundType)
     : base("The annotation element, "+element+", doesn't match the type "+foundType+".")
 {
     //$NON-NLS-1$
     this.elementJ = element;
     this.foundTypeJ = foundType;
 }
 /**
  * Transforms the input to result by invoking a method on the input.
  *
  * @param input  the input object to transform
  * @return the transformed result, null if null input
  */
 public Object transform(Object input)
 {
     if (input == null)
     {
         return(null);
     }
     try
     {
         // C#
         // Type c = input.GetType();
         // MethodInfo mi = c.GetMethod(iMethodName, iParamTypes);
         // if (null == mi) throw new FunctorException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.GetType() + "' does not exist");
         // return mi.Invoke(input, iArgs);
         // JavApi
         java.lang.Class          cls    = input.getClass();
         java.lang.reflect.Method method = cls.getMethod(iMethodName, iParamTypes);
         return(method.invoke(input, iArgs));
     }
     catch (java.lang.NoSuchMethodException) {
         throw new FunctorException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.getClass() + "' does not exist");
     } catch (java.lang.IllegalAccessException) {
         throw new FunctorException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.GetType() + "' cannot be accessed");
     }
     catch (Exception exc) {
         // HACK - How to add System.Exception in constructor...
         throw new FunctorException("InvokerTransformer: The method '" + iMethodName + "' on '" + input.GetType() + "' threw an exception " + exc.GetType());//, ex);
     }
 }
Example #5
0
 public void setReadMethod(java.lang.reflect.Method getter)
 {//throws IntrospectionException {
     if (getter != null)
     {
         int modifiers = getter.getModifiers();
         if (!java.lang.reflect.Modifier.isPublic(modifiers))
         {
             throw new IntrospectionException("Modifier for getter method should be public.");//Messages.getString("beans.0A")); //$NON-NLS-1$
         }
         java.lang.Class[] parameterTypes = getter.getParameterTypes();
         if (parameterTypes.Length != 0)
         {
             throw new IntrospectionException("Number of parameters in getter method is not equal to 0.");//Messages.getString("beans.08")); //$NON-NLS-1$
         }
         java.lang.Class returnType = getter.getReturnType();
         if (returnType.equals(java.lang.Void.TYPE))
         {
             throw new IntrospectionException("{0} does not return <void>");//Messages.getString("beans.33")); //$NON-NLS-1$
         }
         java.lang.Class propertyType = getPropertyType();
         if ((propertyType != null) && !returnType.equals(propertyType))
         {
             throw new IntrospectionException("Parameter type in getter method does not corresponds to predefined.");//Messages.getString("beans.09")); //$NON-NLS-1$
         }
     }
     this.getter = getter;
 }
 /**
  * Returns the value of the bean's property with the given name.
  * <p>
  * The given name must be a {@link String} and must not be
  * null; otherwise, this method returns <code>null</code>.
  * If the bean defines a property with the given name, the value of
  * that property is returned.  Otherwise, <code>null</code> is
  * returned.
  * <p>
  * Write-only properties will not be matched as the test operates against
  * property read methods.
  *
  * @param name  the name of the property whose value to return
  * @return  the value of the property with that name
  */
 public override Object get(Object name)
 {
     if (bean != null)
     {
         java.lang.reflect.Method method = getReadMethod(name);
         if (method != null)
         {
             try
             {
                 return(method.invoke(bean, NULL_ARGUMENTS));
             }
             catch (java.lang.IllegalAccessException e)
             {
                 logWarn(e);
             }
             catch (java.lang.IllegalArgumentException e)
             {
                 logWarn(e);
             }
             catch (java.lang.reflect.InvocationTargetException e)
             {
                 logWarn(e);
             }
             catch (java.lang.NullPointerException e)
             {
                 logWarn(e);
             }
         }
     }
     return(null);
 }
Example #7
0
 /**
  * Factory method that performs validation.
  * <p>
  * Creates a Factory that will return a clone of the same prototype object
  * each time the factory is used. The prototype will be cloned using one of these
  * techniques (in order):
  * <ul>
  * <li>public clone method
  * <li>public copy constructor
  * <li>serialization clone
  * <ul>
  *
  * @param prototype  the object to clone each time in the factory
  * @return the <code>prototype</code> factory
  * @throws IllegalArgumentException if the prototype is null
  * @throws IllegalArgumentException if the prototype cannot be cloned
  */
 public static Factory getInstance(Object prototype)
 {
     if (prototype == null)
     {
         return(ConstantFactory.NULL_INSTANCE);
     }
     try
     {
         java.lang.reflect.Method method = prototype.getClass().getMethod("clone", (java.lang.Class[])null);
         return(new PrototypeCloneFactory(prototype, method));
     }
     catch (java.lang.NoSuchMethodException)
     {
         try
         {
             prototype.getClass().getConstructor(new java.lang.Class[] { prototype.getClass() });
             return(new InstantiateFactory(
                        prototype.getClass(),
                        new java.lang.Class[] { prototype.getClass() },
                        new Object[] { prototype }));
         }
         catch (java.lang.NoSuchMethodException)
         {
             if (prototype is java.io.Serializable)
             {
                 return(new PrototypeSerializationFactory((java.io.Serializable)prototype));
             }
         }
     }
     throw new java.lang.IllegalArgumentException("The prototype must be cloneable via a public clone method");
 }
Example #8
0
 /// <summary>
 /// Get all declared Method of this type.
 /// </summary>
 /// <returns>method array</returns>
 public java.lang.reflect.Method[] getDeclaredMethods()
 {
     MethodInfo [] mi = this.delegateInstance.GetMethods();
     java.lang.reflect.Method[] result = new java.lang.reflect.Method[mi.Length];
     for (int i = 0; i < mi.Length; i++)
     {
         result[i] = new java.lang.reflect.Method(mi[i]);
     }
     return(result);
 }
Example #9
0
 /// <summary>
 /// Get all declared Method of this type.
 /// </summary>
 /// <returns>method array</returns>
 public java.lang.reflect.Method[] getDeclaredMethods()
 {
     MethodInfo [] mi = this.delegateInstance.GetMethods();
     java.lang.reflect.Method[] result = new java.lang.reflect.Method[mi.Length];
     for (int i = 0; i < mi.Length; i++)
     {
         result[i] = new java.lang.reflect.Method(mi[i]);
     }
     return result;
 }
Example #10
0
 /**
  * Find the Clone method for the class specified.
  */
 private void findCloneMethod()
 {
     try
     {
         iCloneMethod = iPrototype.getClass().getMethod("clone", (java.lang.Class[])null);
     }
     catch (java.lang.NoSuchMethodException ex)
     {
         throw new java.lang.IllegalArgumentException("PrototypeCloneFactory: The clone method must exist and be public ");
     }
 }
Example #11
0
 void setReadMethod(java.lang.Class beanClass, String getterName)
 {//throws IntrospectionException {
     try
     {
         java.lang.reflect.Method readMethod = beanClass.getMethod(getterName, new java.lang.Class[] { });
         setReadMethod(readMethod);
     }
     catch (java.lang.Exception e)
     {
         throw new IntrospectionException(e.getLocalizedMessage());
     }
     catch (System.Exception e)
     {
         throw new IntrospectionException(e.getMessage());
     }
 }
Example #12
0
 void setWriteMethod(java.lang.Class beanClass, String setterName)
 {//throws IntrospectionException {
     java.lang.reflect.Method writeMethod = null;
     try
     {
         if (getter != null)
         {
             writeMethod = beanClass.getMethod(setterName,
                                               new java.lang.Class[] { getter.getReturnType() });
         }
         else
         {
             java.lang.Class            clazz   = beanClass;
             java.lang.reflect.Method[] methods = null;
             while (clazz != null && writeMethod == null)
             {
                 methods = clazz.getDeclaredMethods();
                 foreach (java.lang.reflect.Method method in methods)
                 {
                     if (setterName.equals(method.getName()))
                     {
                         if (method.getParameterTypes().Length == 1)
                         {
                             writeMethod = method;
                             break;
                         }
                     }
                 }
                 clazz = clazz.getSuperclass();
             }
         }
     }
     catch (java.lang.Exception e)
     {
         throw new IntrospectionException(e.getLocalizedMessage());
     }
     catch (System.Exception e)
     {
         throw new IntrospectionException(e.Message);
     }
     if (writeMethod == null)
     {
         throw new IntrospectionException("Method not found: " + setterName); //$NON-NLS-1$
     }
     setWriteMethod(writeMethod);
 }
        private void initialise()
        {
            if (getBean() == null)
            {
                return;
            }

            java.lang.Class beanClass = getBean().getClass();
            try
            {
                //BeanInfo beanInfo = Introspector.getBeanInfo( bean, null );
                java.beans.BeanInfo             beanInfo            = java.beans.Introspector.getBeanInfo(beanClass);
                java.beans.PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
                if (propertyDescriptors != null)
                {
                    for (int i = 0; i < propertyDescriptors.Length; i++)
                    {
                        java.beans.PropertyDescriptor propertyDescriptor = propertyDescriptors[i];
                        if (propertyDescriptor != null)
                        {
                            String name = propertyDescriptor.getName();
                            java.lang.reflect.Method readMethod  = propertyDescriptor.getReadMethod();
                            java.lang.reflect.Method writeMethod = propertyDescriptor.getWriteMethod();
                            java.lang.Class          aType       = propertyDescriptor.getPropertyType();

                            if (readMethod != null)
                            {
                                readMethods.put(name, readMethod);
                            }
                            if (writeMethod != null)
                            {
                                writeMethods.put(name, writeMethod);
                            }
                            types.put(name, aType);
                        }
                    }
                }
            }
            catch (java.beans.IntrospectionException e)
            {
                logWarn(e);
            }
        }
Example #14
0
 public void setWriteMethod(java.lang.reflect.Method setter)
 {//throws IntrospectionException {
     if (setter != null)
     {
         int modifiers = setter.getModifiers();
         if (!java.lang.reflect.Modifier.isPublic(modifiers))
         {
             throw new IntrospectionException("Modifier for setter method should be public.");//Messages.getString("beans.05")); //$NON-NLS-1$
         }
         java.lang.Class[] parameterTypes = setter.getParameterTypes();
         if (parameterTypes.Length != 1)
         {
             throw new IntrospectionException("Number of parameters in setter method is not equal to 1.");//Messages.getString("beans.06")); //$NON-NLS-1$
         }
         java.lang.Class parameterType = parameterTypes[0];
         java.lang.Class propertyType  = getPropertyType();
         if (propertyType != null && !propertyType.equals(parameterType))
         {
             throw new IntrospectionException("Parameter type in setter method does not corresponds to predefined.");//Messages.getString("beans.07")); //$NON-NLS-1$
         }
     }
     this.setter = setter;
 }
 /**
  * Constructor to store prototype.
  */
 internal PrototypeCloneFactory(Object prototype, java.lang.reflect.Method method)
     : base()
 {
     iPrototype = prototype;
     iCloneMethod = method;
 }
Example #16
0
 /**
  * Constructor to store prototype.
  */
 internal PrototypeCloneFactory(Object prototype, java.lang.reflect.Method method)
     : base()
 {
     iPrototype   = prototype;
     iCloneMethod = method;
 }
 public AnnotationTypeMismatchException(java.lang.reflect.Method element, String foundType) : base()
 {
     this.type   = foundType;
     this.method = element;
 }
 public void setWriteMethod(java.lang.reflect.Method setter)
 {
     //throws IntrospectionException {
     if (setter != null)
     {
         int modifiers = setter.getModifiers();
         if (!java.lang.reflect.Modifier.isPublic(modifiers))
         {
             throw new IntrospectionException("Modifier for setter method should be public.");//Messages.getString("beans.05")); //$NON-NLS-1$
         }
         java.lang.Class[] parameterTypes = setter.getParameterTypes();
         if (parameterTypes.Length != 1)
         {
             throw new IntrospectionException("Number of parameters in setter method is not equal to 1.");//Messages.getString("beans.06")); //$NON-NLS-1$
         }
         java.lang.Class parameterType = parameterTypes[0];
         java.lang.Class propertyType = getPropertyType();
         if (propertyType != null && !propertyType.equals(parameterType))
         {
             throw new IntrospectionException("Parameter type in setter method does not corresponds to predefined.");//Messages.getString("beans.07")); //$NON-NLS-1$
         }
     }
     this.setter = setter;
 }
 public void setReadMethod(java.lang.reflect.Method getter)
 {
     //throws IntrospectionException {
     if (getter != null)
     {
         int modifiers = getter.getModifiers();
         if (!java.lang.reflect.Modifier.isPublic(modifiers))
         {
             throw new IntrospectionException("Modifier for getter method should be public.");//Messages.getString("beans.0A")); //$NON-NLS-1$
         }
         java.lang.Class[] parameterTypes = getter.getParameterTypes();
         if (parameterTypes.Length != 0)
         {
             throw new IntrospectionException("Number of parameters in getter method is not equal to 0.");//Messages.getString("beans.08")); //$NON-NLS-1$
         }
         java.lang.Class returnType = getter.getReturnType();
         if (returnType.equals(java.lang.Void.TYPE))
         {
             throw new IntrospectionException("{0} does not return <void>");//Messages.getString("beans.33")); //$NON-NLS-1$
         }
         java.lang.Class propertyType = getPropertyType();
         if ((propertyType != null) && !returnType.equals(propertyType))
         {
             throw new IntrospectionException("Parameter type in getter method does not corresponds to predefined.");//Messages.getString("beans.09")); //$NON-NLS-1$
         }
     }
     this.getter = getter;
 }
            /**
             * Find the Clone method for the class specified.
             */
            private void findCloneMethod()
            {
                try
                {
                    iCloneMethod = iPrototype.getClass().getMethod("clone", (java.lang.Class[])null);

                }
                catch (java.lang.NoSuchMethodException ex)
                {
                    throw new java.lang.IllegalArgumentException("PrototypeCloneFactory: The clone method must exist and be public ");
                }
            }
 /*
  * Constructs an instance for the given type element and the type found.
  *
  * @param element
  *            the annotation type element.
  * @param foundType
  *            the invalid type that was found. This is actually the textual
  *            type description found in the binary class representation,
  *            so it may not be human-readable.
  */
 public AnnotationTypeMismatchException(java.lang.reflect.Method element, String foundType) :
     base("The annotation element, " + element + ", doesn't match the type " + foundType + ".")
 {         //$NON-NLS-1$
     this.elementJ   = element;
     this.foundTypeJ = foundType;
 }
 /**
  * Returns true if the bean defines a property with the given name.
  * <p>
  * The given name must be a <code>String</code>; if not, this method
  * returns false. This method will also return false if the bean
  * does not define a property with that name.
  * <p>
  * Write-only properties will not be matched as the test operates against
  * property read methods.
  *
  * @param name  the name of the property to check
  * @return false if the given name is null or is not a <code>String</code>;
  *   false if the bean does not define a property with that name; or
  *   true if the bean does define a property with that name
  */
 public override bool containsKey(Object name)
 {
     java.lang.reflect.Method method = getReadMethod(name);
     return(method != null);
 }