serp.bytecode.BCClass.getType()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(13.4k)|赞(0)|评价(0)|浏览(91)

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

BCClass.getType介绍

[英]Return the Class object for this class, if it is loadable.
[中]如果该类可加载,则返回该类的类对象。

代码示例

代码示例来源:origin: net.sourceforge.serp/serp

/**
 * Write the class bytecode to the .class file in the proper directory of
 * the CLASSPATH. The file must exist already, so this method only works
 * on existing classes.
 */
public void write() throws IOException {
  String name = getName();
  int dotIndex = name.lastIndexOf('.') + 1;
  name = name.substring(dotIndex);
  Class type = getType();
  // attempt to get the class file for the class as a stream;
  // we need to use the url decoder in case the target directory
  // has spaces in it
  OutputStream out = new FileOutputStream(URLDecoder.decode
    (type.getResource(name + ".class").getFile()));
  try {
    write(out);
  } finally {
    out.close();
  }
}

代码示例来源:origin: org.apache.openjpa/openjpa-all

/**
 * Write the class bytecode to the .class file in the proper directory of
 * the CLASSPATH. The file must exist already, so this method only works
 * on existing classes.
 */
public void write() throws IOException {
  String name = getName();
  int dotIndex = name.lastIndexOf('.') + 1;
  name = name.substring(dotIndex);
  Class type = getType();
  // attempt to get the class file for the class as a stream;
  // we need to use the url decoder in case the target directory
  // has spaces in it
  OutputStream out = new FileOutputStream(URLDecoder.decode
    (type.getResource(name + ".class").getFile()));
  try {
    write(out);
  } finally {
    out.close();
  }
}

代码示例来源:origin: org.apache.openjpa/openjpa-kernel

@SuppressWarnings("deprecation")
public static void write(BCClass bc) throws IOException {
  if (bc.getMajorVersion() < Java7_MajorVersion) {
    bc.write();
  } else {
    String name = bc.getName();
    int dotIndex = name.lastIndexOf('.') + 1;
    name = name.substring(dotIndex);
    Class<?> type = bc.getType();
    OutputStream out = new FileOutputStream(
        URLDecoder.decode(type.getResource(name + ".class").getFile()));
    try {
      writeJava7(bc, out);
    } finally {
      out.flush();
      out.close();
    }
  }
}

代码示例来源:origin: org.apache.openejb.patch/openjpa

@SuppressWarnings("deprecation")
public static void write(BCClass bc) throws IOException {
  if (bc.getMajorVersion() < Java7_MajorVersion) {
    bc.write();
  } else {
    String name = bc.getName();
    int dotIndex = name.lastIndexOf('.') + 1;
    name = name.substring(dotIndex);
    Class<?> type = bc.getType();
    OutputStream out = new FileOutputStream(
        URLDecoder.decode(type.getResource(name + ".class").getFile()));
    try {
      writeJava7(bc, out);
    } finally {
      out.flush();
      out.close();
    }
  }
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-asm-shaded

@SuppressWarnings("deprecation")
public static void write(BCClass bc) throws IOException {
  if (bc.getMajorVersion() < Java7_MajorVersion) {
    bc.write();
  } else {
    String name = bc.getName();
    int dotIndex = name.lastIndexOf('.') + 1;
    name = name.substring(dotIndex);
    Class<?> type = bc.getType();
    OutputStream out = new FileOutputStream(
        URLDecoder.decode(type.getResource(name + ".class").getFile()));
    try {
      writeJava7(bc, out);
    } finally {
      out.flush();
      out.close();
    }
  }
}

代码示例来源:origin: org.apache.openjpa/openjpa-all

@SuppressWarnings("deprecation")
public static void write(BCClass bc) throws IOException {
  if (bc.getMajorVersion() < Java7_MajorVersion) {
    bc.write();
  } else {
    String name = bc.getName();
    int dotIndex = name.lastIndexOf('.') + 1;
    name = name.substring(dotIndex);
    Class<?> type = bc.getType();
    OutputStream out = new FileOutputStream(
        URLDecoder.decode(type.getResource(name + ".class").getFile()));
    try {
      writeJava7(bc, out);
    } finally {
      out.flush();
      out.close();
    }
  }
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-kernel

@SuppressWarnings("deprecation")
public static void write(BCClass bc) throws IOException {
  if (bc.getMajorVersion() < Java7_MajorVersion) {
    bc.write();
  } else {
    String name = bc.getName();
    int dotIndex = name.lastIndexOf('.') + 1;
    name = name.substring(dotIndex);
    Class<?> type = bc.getType();
    OutputStream out = new FileOutputStream(
        URLDecoder.decode(type.getResource(name + ".class").getFile()));
    try {
      writeJava7(bc, out);
    } finally {
      out.flush();
      out.close();
    }
  }
}

代码示例来源:origin: org.apache.openjpa/openjpa-kernel-5

private static void write(BCClass bc, PCEnhancer enhancer,
  Map<Class, byte[]> map, Class cls, List subs, List ints)
  throws IOException {
  if (bc == enhancer.getManagedTypeBytecode()) {
    // if it was already defined, don't put it in the map,
    // but do set the metadata accordingly.
    if (enhancer.isAlreadyRedefined())
      ints.add(bc.getType());
    else if (JavaVersions.VERSION >= 5)
      map.put(bc.getType(), bc.toByteArray());
  } else {
    if (!enhancer.isAlreadySubclassed()) {
      // this is the new subclass
      ClassLoader loader = GeneratedClasses.getMostDerivedLoader(
        cls, PersistenceCapable.class);
      subs.add(GeneratedClasses.loadBCClass(bc, loader));
    }
  }
}

代码示例来源:origin: org.apache.openjpa/com.springsource.org.apache.openjpa.java5

private static void write(BCClass bc, PCEnhancer enhancer,
  Map<Class, byte[]> map, Class cls, List subs, List ints)
  throws IOException {
  if (bc == enhancer.getManagedTypeBytecode()) {
    // if it was already defined, don't put it in the map,
    // but do set the metadata accordingly.
    if (enhancer.isAlreadyRedefined())
      ints.add(bc.getType());
    else if (JavaVersions.VERSION >= 5)
      map.put(bc.getType(), bc.toByteArray());
  } else {
    if (!enhancer.isAlreadySubclassed()) {
      // this is the new subclass
      ClassLoader loader = GeneratedClasses.getMostDerivedLoader(
        cls, PersistenceCapable.class);
      subs.add(GeneratedClasses.loadBCClass(bc, loader));
    }
  }
}

代码示例来源:origin: org.apache.openejb.patch/openjpa

private static void write(BCClass bc, PCEnhancer enhancer,
  Map<Class<?>, byte[]> map, Class<?> cls, List<Class<?>> subs, List<Class<?>> ints)
  throws IOException {
  if (bc == enhancer.getManagedTypeBytecode()) {
    // if it was already defined, don't put it in the map,
    // but do set the metadata accordingly.
    if (enhancer.isAlreadyRedefined())
      ints.add(bc.getType());
    else {
      map.put(bc.getType(), bc.toByteArray());
      debugBytecodes(bc);
    }
  } else {
    if (!enhancer.isAlreadySubclassed()) {
      debugBytecodes(bc);
      
      // this is the new subclass
      ClassLoader loader = GeneratedClasses.getMostDerivedLoader(
        cls, PersistenceCapable.class);
      subs.add(GeneratedClasses.loadBCClass(bc, loader));
    }
  }
}

代码示例来源:origin: org.apache.openjpa/openjpa-all

private static void write(BCClass bc, PCEnhancer enhancer,
  Map<Class<?>, byte[]> map, Class<?> cls, List<Class<?>> subs, List<Class<?>> ints)
  throws IOException {
  if (bc == enhancer.getManagedTypeBytecode()) {
    // if it was already defined, don't put it in the map,
    // but do set the metadata accordingly.
    if (enhancer.isAlreadyRedefined())
      ints.add(bc.getType());
    else {
      map.put(bc.getType(), bc.toByteArray());
      debugBytecodes(bc);
    }
  } else {
    if (!enhancer.isAlreadySubclassed()) {
      debugBytecodes(bc);
      
      // this is the new subclass
      ClassLoader loader = GeneratedClasses.getMostDerivedLoader(
        cls, PersistenceCapable.class);
      subs.add(GeneratedClasses.loadBCClass(bc, loader));
    }
  }
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-kernel

private static void write(BCClass bc, PCEnhancer enhancer,
  Map<Class<?>, byte[]> map, Class<?> cls, List<Class<?>> subs, List<Class<?>> ints)
  throws IOException {
  if (bc == enhancer.getManagedTypeBytecode()) {
    // if it was already defined, don't put it in the map,
    // but do set the metadata accordingly.
    if (enhancer.isAlreadyRedefined())
      ints.add(bc.getType());
    else {
      map.put(bc.getType(), bc.toByteArray());
      debugBytecodes(bc);
    }
  } else {
    if (!enhancer.isAlreadySubclassed()) {
      debugBytecodes(bc);
      
      // this is the new subclass
      ClassLoader loader = GeneratedClasses.getMostDerivedLoader(
        cls, PersistenceCapable.class);
      subs.add(GeneratedClasses.loadBCClass(bc, loader));
    }
  }
}

代码示例来源:origin: org.apache.openjpa/com.springsource.org.apache.openjpa

private static void write(BCClass bc, PCEnhancer enhancer,
  Map<Class, byte[]> map, Class cls, List subs, List ints)
  throws IOException {
  if (bc == enhancer.getManagedTypeBytecode()) {
    // if it was already defined, don't put it in the map,
    // but do set the metadata accordingly.
    if (enhancer.isAlreadyRedefined())
      ints.add(bc.getType());
    else if (JavaVersions.VERSION >= 5) {
      map.put(bc.getType(), bc.toByteArray());
      debugBytecodes(bc);
    }
  } else {
    if (!enhancer.isAlreadySubclassed()) {
      debugBytecodes(bc);
      
      // this is the new subclass
      ClassLoader loader = GeneratedClasses.getMostDerivedLoader(
        cls, PersistenceCapable.class);
      subs.add(GeneratedClasses.loadBCClass(bc, loader));
    }
  }
}

代码示例来源:origin: org.apache.openejb.patch/openjpa

/**
 * Adds a non-static getter that delegates to the super methods, and
 * performs any necessary field tracking.
 */
private void addSubclassGetMethod(FieldMetaData fmd) {
  String methName = "get" + StringUtils.capitalize(fmd.getName());
  if (_managedType.getMethods(methName, new Class[0]).length == 0)
    methName = "is" + StringUtils.capitalize(fmd.getName());
  BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(),
    null);
  setVisibilityToSuperMethod(getter);
  getter.makePublic();
  Code code = getter.getCode(true);
  // if we're not already tracking field access via reflection, then we
  // must make the getter hook in lazy loading before accessing the super
  // method.
  if (!getRedefine())
    addNotifyAccess(code, fmd);
  code.aload().setThis();
  code.invokespecial().setMethod(_managedType.getType(), methName,
    fmd.getDeclaredType(), null);
  code.xreturn().setType(fmd.getDeclaredType());
  code.calculateMaxLocals();
  code.calculateMaxStack();
}

代码示例来源:origin: org.apache.openejb.patch/openjpa-kernel

private void configureBCs() {
  if (!_bcsConfigured) {
    if (getRedefine()) {
      if (_managedType.getAttribute(REDEFINED_ATTRIBUTE) == null)
        _managedType.addAttribute(REDEFINED_ATTRIBUTE);
      else
        _isAlreadyRedefined = true;
    }
    if (getCreateSubclass()) {
      PCSubclassValidator val = new PCSubclassValidator(
        _meta, _managedType, _log, _fail);
      val.assertCanSubclass();
      _pc = _managedType.getProject().loadClass(
        toPCSubclassName(_managedType.getType()));
      if (_pc.getSuperclassBC() != _managedType) {
        _pc.setSuperclass(_managedType);
        _pc.setAbstract(_managedType.isAbstract());
        _pc.declareInterface(DynamicPersistenceCapable.class);
      } else {
        _isAlreadySubclassed = true;
      }
    }
    _bcsConfigured = true;
  }
}

代码示例来源:origin: org.apache.openejb.patch/openjpa

private void configureBCs() {
  if (!_bcsConfigured) {
    if (getRedefine()) {
      if (_managedType.getAttribute(REDEFINED_ATTRIBUTE) == null)
        _managedType.addAttribute(REDEFINED_ATTRIBUTE);
      else
        _isAlreadyRedefined = true;
    }
    if (getCreateSubclass()) {
      PCSubclassValidator val = new PCSubclassValidator(
        _meta, _managedType, _log, _fail);
      val.assertCanSubclass();
      _pc = _managedType.getProject().loadClass(
        toPCSubclassName(_managedType.getType()));
      if (_pc.getSuperclassBC() != _managedType) {
        _pc.setSuperclass(_managedType);
        _pc.setAbstract(_managedType.isAbstract());
        _pc.declareInterface(DynamicPersistenceCapable.class);
      } else {
        _isAlreadySubclassed = true;
      }
    }
    _bcsConfigured = true;
  }
}

代码示例来源:origin: net.sourceforge.serp/serp

/**
 * Import the given bytecode from another project. If a {@link BCClass}
 * with the same name already exists in this project, it will be returned.
 * Otherwise, a new {@link BCClass} will be created from the
 * information in the given class.
 */
public BCClass loadClass(BCClass bc) {
  String name = bc.getName();
  BCClass cached = checkCache(name);
  if (cached != null)
    return cached;
  BCClass ret = new BCClass(this);
  if (bc.isPrimitive())
    ret.setState(new PrimitiveState(bc.getType(), _names));
  else if (bc.isArray())
    ret.setState(new ArrayState(bc.getName(), bc.getComponentName()));
  else {
    ret.setState(new ObjectState(_names));
    ret.read(bc);
  }
  cache(name, ret);
  return ret;
}

代码示例来源:origin: org.apache.openjpa/openjpa-all

/**
 * Import the given bytecode from another project. If a {@link BCClass}
 * with the same name already exists in this project, it will be returned.
 * Otherwise, a new {@link BCClass} will be created from the
 * information in the given class.
 */
public BCClass loadClass(BCClass bc) {
  String name = bc.getName();
  BCClass cached = checkCache(name);
  if (cached != null)
    return cached;
  BCClass ret = new BCClass(this);
  if (bc.isPrimitive())
    ret.setState(new PrimitiveState(bc.getType(), _names));
  else if (bc.isArray())
    ret.setState(new ArrayState(bc.getName(), bc.getComponentName()));
  else {
    ret.setState(new ObjectState(_names));
    ret.read(bc);
  }
  cache(name, ret);
  return ret;
}

代码示例来源:origin: org.apache.openjpa/openjpa-all

/**
 * Adds a non-static getter that delegates to the super methods, and
 * performs any necessary field tracking.
 */
private void addSubclassGetMethod(FieldMetaData fmd) {
  String methName = "get" + StringUtil.capitalize(fmd.getName());
  if (_managedType.getMethods(methName, new Class[0]).length == 0)
    methName = "is" + StringUtil.capitalize(fmd.getName());
  BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(),
    null);
  setVisibilityToSuperMethod(getter);
  getter.makePublic();
  Code code = getter.getCode(true);
  // if we're not already tracking field access via reflection, then we
  // must make the getter hook in lazy loading before accessing the super
  // method.
  if (!getRedefine())
    addNotifyAccess(code, fmd);
  code.aload().setThis();
  code.invokespecial().setMethod(_managedType.getType(), methName,
    fmd.getDeclaredType(), null);
  code.xreturn().setType(fmd.getDeclaredType());
  code.calculateMaxLocals();
  code.calculateMaxStack();
}

代码示例来源:origin: org.apache.openjpa/openjpa-kernel

/**
 * Adds a non-static getter that delegates to the super methods, and
 * performs any necessary field tracking.
 */
private void addSubclassGetMethod(FieldMetaData fmd) {
  String methName = "get" + StringUtil.capitalize(fmd.getName());
  if (_managedType.getMethods(methName, new Class[0]).length == 0)
    methName = "is" + StringUtil.capitalize(fmd.getName());
  BCMethod getter = _pc.declareMethod(methName, fmd.getDeclaredType(),
    null);
  setVisibilityToSuperMethod(getter);
  getter.makePublic();
  Code code = getter.getCode(true);
  // if we're not already tracking field access via reflection, then we
  // must make the getter hook in lazy loading before accessing the super
  // method.
  if (!getRedefine())
    addNotifyAccess(code, fmd);
  code.aload().setThis();
  code.invokespecial().setMethod(_managedType.getType(), methName,
    fmd.getDeclaredType(), null);
  code.xreturn().setType(fmd.getDeclaredType());
  code.calculateMaxLocals();
  code.calculateMaxStack();
}

相关文章

微信公众号

最新文章

更多