org.apache.cayenne.util.Util.getJavaClass()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(178)

本文整理了Java中org.apache.cayenne.util.Util.getJavaClass()方法的一些代码示例,展示了Util.getJavaClass()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.getJavaClass()方法的具体详情如下:
包路径:org.apache.cayenne.util.Util
类名称:Util
方法名:getJavaClass

Util.getJavaClass介绍

[英]Creates a Java class, handling regular class names as well as single-dimensional arrays and primitive types.
[中]创建一个Java类,处理常规类名、一维数组和基本类型。

代码示例

代码示例来源:origin: org.apache.cayenne/cayenne-nodeps

public EnumSerializerProxy() {
  try {
    // sniff JDK 1.5
    Class.forName("java.lang.StringBuilder");
    Class factoryClass = Util.getJavaClass(FACTORY_CLASS);
    this.enumSerializer = (AbstractSerializerFactory) factoryClass.newInstance();
  }
  catch (Throwable th) {
    // ignore.. jdk 1.4
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-nodeps

static ConverterFactory createFactory() {
  try {
    // sniff JDK 1.5
    Class.forName("java.lang.StringBuilder");
    Class factoryClass = Util.getJavaClass(FACTORY_CLASS_JDK15);
    return (ConverterFactory) factoryClass.newInstance();
  }
  catch (Throwable th) {
    // .. jdk 1.4
    return new ConverterFactory();
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-server

SubclassTypeFactory(ExtendedType type) {
  this.type = type;
  try {
    javaClass = Util.getJavaClass(type.getClassName());
    // some classes that should not be handled here..
    if (javaClass.isArray()
        || javaClass.equals(Object.class)
        || javaClass.isPrimitive()) {
      javaClass = null;
    }
  } catch (ClassNotFoundException e) {
    // ignore.
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-nodeps

/**
 * Creates new ExtendedTypeMap, populating it with default JDBC-compatible types. If
 * JDK version is at least 1.5, also loads support for enumerated types.
 */
public ExtendedTypeMap() {
  // see if we can support enums
  try {
    Class enumTypeClass = Util
        .getJavaClass("org.apache.cayenne.access.types.EnumType");
    this.enumTypeConstructor = enumTypeClass.getConstructor(new Class[] {
      Class.class
    });
  }
  catch (Throwable th) {
    // no enums support... either Java 1.4 or Cayenne 1.5 extensions are absent
  }
  this.initDefaultTypes();
}

代码示例来源:origin: org.apache.cayenne/cayenne-server

/**
 * @deprecated since 4.0 as class loading should not happen here.
 */
@Deprecated
public PasswordEncoding getPasswordEncoder() {
  try {
    return (PasswordEncoding) Util.getJavaClass(getPasswordEncoderClass()).newInstance();
  } catch (InstantiationException | IllegalAccessException | ClassNotFoundException | DIRuntimeException e) {
    ; // Swallow it -- no need to throw/etc.
  }
  logger.error("Failed to obtain specified Password Encoder '" + getPasswordEncoderClass() + "'");
  return null;
}

代码示例来源:origin: org.apache.cayenne/cayenne-server

/**
 * Returns default java.sql.Types type by the Java type name.
 * 
 * @param className
 *            Fully qualified Java Class name.
 * @return The SQL type or NOT_DEFINED if no type found.
 */
public static int getSqlTypeByJava(String className) {
  if (className == null) {
    return NOT_DEFINED;
  }
  Integer type = JAVA_SQL_ENUM.get(className);
  if (type != null) {
    return type;
  }
  // try to load a Java class - some nonstandard mappings may work
  Class<?> aClass;
  try {
    aClass = Util.getJavaClass(className);
  } catch (Throwable th) {
    return NOT_DEFINED;
  }
  return getSqlTypeByJava(aClass);
}

代码示例来源:origin: org.apache.cayenne/cayenne-server

/**
 * Returns Java class of the embeddable.
 * 
 * @deprecated since 4.0 this method based on statically defined class
 *             loading algorithm is not going to work in environments like
 *             OSGi. {@link AdhocObjectFactory} should be used as it can
 *             provide the environment-specific class loading policy.
 */
@Deprecated
public Class<?> getJavaClass() {
  String name = getClassName();
  try {
    return Util.getJavaClass(name);
  } catch (ClassNotFoundException e) {
    throw new CayenneRuntimeException("Failed to load class " + name + ": " + e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-web

module = (Module) Util.getJavaClass(moduleName).newInstance();
} catch (Exception e) {
  String message = String.format("Error instantiating custom DI module '%s' by filter '%s': %s",

代码示例来源:origin: org.apache.cayenne/cayenne-server

/**
 * Loads JDBC driver using current thread class loader.
 * 
 * @since 3.0
 * @deprecated since 4.0 as class loading should not happen here.
 */
@Deprecated
private static Driver loadDriver(String driverClassName) {
  Class<?> driverClass;
  try {
    driverClass = Util.getJavaClass(driverClassName);
  } catch (Exception ex) {
    throw new CayenneRuntimeException("Can not load JDBC driver named '%s': %s", driverClassName, ex.getMessage());
  }
  try {
    return (Driver) driverClass.newInstance();
  } catch (Exception ex) {
    throw new CayenneRuntimeException("Error instantiating driver '%s': %s", driverClassName, ex.getMessage());
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-server

module = (Module) Util.getJavaClass(moduleName).newInstance();

代码示例来源:origin: org.apache.cayenne/cayenne-server

/**
 * Returns Java class of persistent objects described by this entity. For
 * generic entities with no class specified explicitly, default DataMap
 * superclass is used, and if it is not set - CayenneDataObject is used.
 * Casts any thrown exceptions into CayenneRuntimeException.
 * 
 * @since 1.2
 * @deprecated since 4.0 this method based on statically defined class
 *             loading algorithm is not going to work in environments like
 *             OSGi. {@link AdhocObjectFactory} should be used as it can
 *             provide the environment-specific class loading policy. 
 */
@Deprecated
public Class<?> getJavaClass() {
  String name = getJavaClassName();
  try {
    return Util.getJavaClass(name);
  } catch (ClassNotFoundException e) {
    throw new CayenneRuntimeException("Failed to doLoad class " + name + ": " + e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-server

private Collection<Class<?>> getAnnotatedEntities(Class<? extends Annotation> annotationType) {
  Collection<Class<?>> entities = entitiesByAnnotation.get(annotationType.getName());
  if (entities == null) {
    // ensure no dupes
    entities = new HashSet<>();
    for (ObjEntity entity : entityResolver.getObjEntities()) {
      Class<?> entityType;
      try {
        entityType = Util.getJavaClass(entity.getClassName());
      } catch (ClassNotFoundException e) {
        throw new CayenneRuntimeException("Class not found: " + entity.getClassName(), e);
      }
      // ensure that we don't register the same callback for multiple
      // classes in the same hierarchy, so find the topmost type using
      // a given annotation and register it once
      // TODO: This ignores "excludeSuperclassListeners" setting,
      // which is not possible with annotations anyways
      while (entityType != null && entityType.isAnnotationPresent(annotationType)) {
        Class<?> superType = entityType.getSuperclass();
        if (superType == null || !superType.isAnnotationPresent(annotationType)) {
          entities.add(entityType);
          break;
        }
        entityType = superType;
      }
    }
    entitiesByAnnotation.put(annotationType.getName(), entities);
  }
  return entities;
}

代码示例来源:origin: org.apache.cayenne/cayenne-nodeps

typeClass = Util.getJavaClass(javaClassName);

代码示例来源:origin: org.apache.cayenne/cayenne-server

enumClass = Util.getJavaClass(className);

代码示例来源:origin: org.apache.cayenne/cayenne-server

/**
 * Returns Java class of an object property described by this attribute.
 * Wraps any thrown exceptions into CayenneRuntimeException.
 */
public Class<?> getJavaClass() {
  if (this.getType() == null) {
    return null;
  }
  try {
    return Util.getJavaClass(getType());
  } catch (ClassNotFoundException e) {
    throw new CayenneRuntimeException("Failed to load class for name '" + this.getType() + "': "
        + e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-server

typeClass = Util.getJavaClass(className);
} catch (Throwable th) {

代码示例来源:origin: org.apache.cayenne/cayenne-server

/**
 * Returns Java class of an object property described by this attribute. Wraps any
 * thrown exceptions into CayenneRuntimeException.
 */
@Override
public Class<?> getJavaClass() {
  if (this.getType() == null) {
    return null;
  }
  try {
    return Util.getJavaClass(getType());
  }
  catch (ClassNotFoundException e) {
    throw new CayenneRuntimeException("Failed to load class for name '"
        + this.getType()
        + "': "
        + e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-nodeps

/**
 * Returns Java class of an object property described by this attribute. Wraps any
 * thrown exceptions into CayenneRuntimeException.
 */
public Class getJavaClass() {
  if (this.getType() == null) {
    return null;
  }
  try {
    // tolerate null class loader
    return Util.getJavaClass(getType());
  }
  catch (ClassNotFoundException e) {
    throw new CayenneRuntimeException("Failed to load class for name '"
        + this.getType()
        + "': "
        + e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-nodeps

/**
 * Returns Java class of persistent objects described by this entity. For generic
 * entities with no class specified explicitly, default DataMap superclass is used,
 * and if it is not set - CayenneDataObject is used. Casts any thrown exceptions into
 * CayenneRuntimeException.
 * 
 * @since 1.2
 */
public Class getJavaClass() {
  String name = getClassName();
  if (name == null && getDataMap() != null) {
    name = getDataMap().getDefaultSuperclass();
  }
  if (name == null) {
    name = CAYENNE_DATA_OBJECT_CLASS;
  }
  try {
    return Util.getJavaClass(name);
  }
  catch (ClassNotFoundException e) {
    throw new CayenneRuntimeException("Failed to load class "
        + name
        + ": "
        + e.getMessage(), e);
  }
}

代码示例来源:origin: org.apache.cayenne/cayenne-lifecycle

public EntityIdCoder(ObjEntity entity) {
  this.entityName = entity.getName();
  this.converters = new TreeMap<String, Converter>();
  for (ObjAttribute attribute : entity.getAttributes()) {
    if (attribute.isPrimaryKey()) {
      converters.put(attribute.getDbAttributeName(),
          create(attribute.getJavaClass()));
    }
  }
  for (DbAttribute attribute : entity.getDbEntity().getPrimaryKeys()) {
    if (!converters.containsKey(attribute.getName())) {
      String type = TypesMapping
          .getJavaBySqlType(attribute.getType());
      try {
        converters.put(attribute.getName(),
            create(Util.getJavaClass(type)));
      } catch (ClassNotFoundException e) {
        throw new CayenneRuntimeException(
            "Can't instantiate class " + type, e);
      }
    }
  }
  if (converters.isEmpty()) {
    throw new IllegalArgumentException("Entity has no PK definied: "
        + entity.getName());
  }
  this.idSize = (int) Math.ceil(converters.size() / 0.75d);
}

相关文章