示例#1
0
  /**
   * Returns true if the given class has an associated CollectionHandler.
   *
   * @param javaClass the class to search collection handlers for
   * @return true if the given class has an associated CollectionHandler, otherwise false.
   */
  public static boolean hasHandler(Class javaClass) {

    if (_info == null) loadInfo();

    // -- Adjust javaClass for arrays, needed for arrays of
    // -- primitives, except for byte[] which shouldn't
    // -- use a collection handler
    if (javaClass.isArray()) {
      if (javaClass.getComponentType() != Byte.TYPE) javaClass = Object[].class;
    }

    for (int i = 0; i < _info.length; ++i)
      if (_info[i].javaClass.isAssignableFrom(javaClass)) return true;

    return false;
  } // -- hasHandler
示例#2
0
  /**
   * Returns the collection's Java class from the collection name. The collection name may be a
   * short name (e.g. <tt>vector</tt>) or the collection Java class name (e.g.
   * <tt>java.util.Vector</tt>). If the collection is not supported, an exception is thrown.
   *
   * @param name The collection name
   * @return The collection Java class
   * @throws MappingException The named collection is not supported
   */
  public static Class getCollectionType(String name) throws MappingException {
    if (_info == null) loadInfo();
    for (int i = 0; i < _info.length; ++i)
      if (_info[i].shortName.equalsIgnoreCase(name) || _info[i].javaClass.getName().equals(name))
        return _info[i].javaClass;
    // throw new MappingException( "mapping.noCollectionHandler", name );

    // -- Fix for JDK 1.1 compatibility
    // old code: return Collection.class;
    if (!_loadedCollectionClass) {
      _loadedCollectionClass = true;
      try {
        _collectionClass = Class.forName("java.util.Collection");
      } catch (ClassNotFoundException cnfe) {
        // Do nothing we are just here for JDK 1.1
        // compatibility
      }
    }
    return _collectionClass;
  }
示例#3
0
  /**
   * Returns the collection's handler based on the Java class.
   *
   * @param javaClass The collection's Java class
   * @return The collection handler
   * @throws MappingException The collection class is not supported
   */
  public static CollectionHandler getHandler(Class javaClass) throws MappingException {
    if (_info == null) loadInfo();

    // -- Adjust javaClass for arrays, needed for arrays of
    // -- primitives, except for byte[] which shouldn't
    // -- use a collection handler
    if (javaClass.isArray()) {
      if (javaClass.getComponentType() != Byte.TYPE) javaClass = Object[].class;
    }

    // -- First check direct class equality, to provide a better match
    // -- (for example in JDK 1.2 a Vector is also a Collection)
    for (int i = 0; i < _info.length; ++i)
      if (_info[i].javaClass.equals(javaClass)) return _info[i].handler;

    // -- handle Possible inheritence
    for (int i = 0; i < _info.length; ++i)
      if (_info[i].javaClass.isAssignableFrom(javaClass)) return _info[i].handler;

    throw new MappingException("mapping.noCollectionHandler", javaClass.getName());
  }
示例#4
0
 /**
  * Returns true if the collection requires get/set methods. <tt>java.util</tt> collections only
  * require a get method, but an array collection required both get and set methods.
  *
  * @parfam javaClass The collection's java class
  * @return True if collection requires get/set methods, false if collection requires only get
  *     method
  * @throws MappingException The collection class is not supported
  */
 public static boolean isGetSetCollection(Class javaClass) throws MappingException {
   if (_info == null) loadInfo();
   for (int i = 0; i < _info.length; ++i)
     if (_info[i].javaClass.equals(javaClass)) return _info[i].getSetCollection;
   throw new MappingException("mapping.noCollectionHandler", javaClass.getName());
 }