Logo Search packages:      
Sourcecode: libjson-java version File versions

static Class [] net::sf::json::JSONArray::getCollectionType ( PropertyDescriptor  pd,
boolean  useGetter 
) throws JSONException [inline, static]

Get the collection type from a getter or setter, or null if no type was found.
Contributed by [Matt Small @ WaveMaker].

Definition at line 206 of file JSONArray.java.

                              {

      Type type;
      if( useGetter ){
         Method m = pd.getReadMethod();
         type = m.getGenericReturnType();
      }else{
         Method m = pd.getWriteMethod();
         Type[] gpts = m.getGenericParameterTypes();

         if( 1 != gpts.length ){
            throw new JSONException( "method " + m + " is not a standard setter" );
         }
         type = gpts[0];
      }

      if( !(type instanceof ParameterizedType) ){
         return null;
         // throw new JSONException("type not instanceof ParameterizedType:
         // "+type.getClass());
      }

      ParameterizedType pType = (ParameterizedType) type;
      Type[] actualTypes = pType.getActualTypeArguments();

      Class[] ret = new Class[actualTypes.length];
      for( int i = 0; i < ret.length; i++ ){
         ret[i] = (Class) actualTypes[i];
      }

      return ret;
   }


Generated by  Doxygen 1.6.0   Back to index