⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexedpropertydescriptor.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                                             + "the same class.");          }      }    if (getIndex != null        && (getIndex.getParameterTypes().length != 1         || !(getIndex.getParameterTypes()[0]).equals(java.lang.Integer.TYPE)))      {        throw new IntrospectionException("get index method has wrong "                                         + "parameters");      }    if (setIndex != null       && (setIndex.getParameterTypes().length != 2         || !(setIndex.getParameterTypes()[0]).equals(java.lang.Integer.TYPE)))      {        throw new IntrospectionException("set index method has wrong "                                         + "parameters");      }    if (getIndex != null && setIndex != null)      {        if(!getIndex.getReturnType().equals(setIndex.getParameterTypes()[1]))          {            throw new IntrospectionException("set index methods do not share "                                             + "the same type");          }        if(!getIndex.getDeclaringClass().isAssignableFrom           (setIndex.getDeclaringClass())           && !setIndex.getDeclaringClass().isAssignableFrom           (getIndex.getDeclaringClass()))          {            throw new IntrospectionException("get and set index methods are "                                             + "not in the same class.");          }      }    if (getIndex != null && getMethod != null        && !getIndex.getDeclaringClass().isAssignableFrom        (getMethod.getDeclaringClass())        && !getMethod.getDeclaringClass().isAssignableFrom        (getIndex.getDeclaringClass()))      {        throw new IntrospectionException("methods are not in the same class.");      }    if (getIndex != null && getMethod != null        && !Array.newInstance(getIndex.getReturnType(),0)        .getClass().equals(getMethod.getReturnType()))      {        throw new IntrospectionException("array methods do not match index "                                         + "methods.");      }    this.getMethod = getMethod;    this.setMethod = setMethod;    this.getIndex = getIndex;    this.setIndex = setIndex;    this.indexedPropertyType = getIndex != null ? getIndex.getReturnType()                                             : setIndex.getParameterTypes()[1];    this.propertyType = getMethod != null ? getMethod.getReturnType()      : (setMethod != null ? setMethod.getParameterTypes()[0]         : Array.newInstance(this.indexedPropertyType,0).getClass());  }  public Class getIndexedPropertyType()  {    return indexedPropertyType;  }  public Method getIndexedReadMethod()  {    return getIndex;  }  /**   * Sets the method that is used to read an indexed property.   *   * @param m the method to set   */  public void setIndexedReadMethod(Method m) throws IntrospectionException  {    getIndex = m;  }  public Method getIndexedWriteMethod()  {    return setIndex;  }  /**   * Sets the method that is used to write an indexed property.   *   * @param m the method to set   */  public void setIndexedWriteMethod(Method m) throws IntrospectionException  {    setIndex = m;  }  private void findMethods(Class beanClass, String getMethodName,                           String setMethodName, String getIndexName,                           String setIndexName)    throws IntrospectionException  {    try      {        if(getIndexName != null)          {            try              {                Class[] getArgs = new Class[1];                getArgs[0] = java.lang.Integer.TYPE;                getIndex = beanClass.getMethod(getIndexName,getArgs);                indexedPropertyType = getIndex.getReturnType();              }            catch(NoSuchMethodException E)              {              }          }        if(getIndex != null)          {            if(setIndexName != null)              {                try                  {                    Class[] setArgs = new Class[2];                    setArgs[0] = java.lang.Integer.TYPE;                    setArgs[1] = indexedPropertyType;                    setIndex = beanClass.getMethod(setIndexName,setArgs);                    if(!setIndex.getReturnType().equals(java.lang.Void.TYPE))                      {                        throw new IntrospectionException(setIndexName                                                + " has non-void return type");                      }                  }                catch(NoSuchMethodException E)                  {                  }              }          }        else if(setIndexName != null)          {            Method[] m = beanClass.getMethods();            for(int i=0;i<m.length;i++)              {                Method current = m[i];                if(current.getName().equals(setIndexName)                   && current.getParameterTypes().length == 2                   && (current.getParameterTypes()[0])                   .equals(java.lang.Integer.TYPE)                   && current.getReturnType().equals(java.lang.Void.TYPE))                  {                    if(setIndex != null)                      {                        throw new IntrospectionException("Multiple, different "                                     + "set methods found that fit the bill!");                      }                    else                      {                        setIndex = current;                        indexedPropertyType = current.getParameterTypes()[1];                      }                  }              }            if(setIndex == null)              {                throw new IntrospectionException("Cannot find get or set "                                                 + "methods.");              }          }        else          {           throw new IntrospectionException("Cannot find get or set methods.");          }        Class arrayType = Array.newInstance(indexedPropertyType,0).getClass();        Class[] setArgs = new Class[1];        setArgs[0] = arrayType;        try          {            setMethod = beanClass.getMethod(setMethodName,setArgs);            if (!setMethod.getReturnType().equals(java.lang.Void.TYPE))              {                setMethod = null;              }          }        catch(NoSuchMethodException E)          {          }        Class[] getArgs = new Class[0];        try          {            getMethod = beanClass.getMethod(getMethodName,getArgs);            if (!getMethod.getReturnType().equals(arrayType))              {                getMethod = null;              }          }        catch(NoSuchMethodException E)          {          }      }    catch(SecurityException E)      {        throw new IntrospectionException("SecurityException while trying to "                                         + "find methods.");      }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -