public static Method getWriteMethod()

in src/main/java/org/apache/commons/ognl/OgnlRuntime.java [1885:1957]


    public static Method getWriteMethod( Class<?> target, String name, int numParms )
    {
        try
        {
            name = name.replace( "\"", "" );

            BeanInfo info = Introspector.getBeanInfo( target );
            MethodDescriptor[] methods = info.getMethodDescriptors();

            for ( MethodDescriptor method : methods )
            {
                if ( !isMethodCallable( method.getMethod() ) )
                {
                    continue;
                }

                if ( ( method.getName().equalsIgnoreCase( name ) || method.getName().toLowerCase().equals(
                    name.toLowerCase() ) || method.getName().toLowerCase().equals( "set" + name.toLowerCase() ) )
                    && !method.getName().startsWith( "get" ) )
                {

                    if ( numParms > 0 && method.getMethod().getParameterTypes().length == numParms )
                    {
                        return method.getMethod();
                    }
                    if ( numParms < 0 )
                    {
                        return method.getMethod();
                    }
                }
            }

            // try again on pure class

            Method[] cmethods = target.getClass().getMethods();
            for ( Method cmethod : cmethods )
            {
                if ( !isMethodCallable( cmethod ) )
                {
                    continue;
                }

                if ( ( cmethod.getName().equalsIgnoreCase( name ) || cmethod.getName().toLowerCase().equals(
                    name.toLowerCase() ) || cmethod.getName().toLowerCase().equals( "set" + name.toLowerCase() ) )
                    && !cmethod.getName().startsWith( "get" ) )
                {

                    if ( numParms > 0 && cmethod.getParameterTypes().length == numParms )
                    {
                        return cmethod;
                    }
                    if ( numParms < 0 )
                    {
                        return cmethod;
                    }
                }
            }

            // try one last time adding a set to beginning

            if ( !name.startsWith( "set" ) )
            {
                return OgnlRuntime.getReadMethod( target, "set" + name, numParms );
            }

        }
        catch ( Throwable t )
        {
            throw OgnlOps.castToRuntime( t );
        }

        return null;
    }