Package net.sf.joafip

Source Code of net.sf.joafip.MainEnhanceCode

package net.sf.joafip;

import java.io.IOException;

import net.sf.joafip.java.util.PTreeMap;
import net.sf.joafip.reflect.HelperReflect;
import net.sf.joafip.reflect.ReflectException;
import net.sf.joafip.reflect.ReflectInvalidClassException;
import net.sf.joafip.service.ClassLoaderProvider;
import net.sf.joafip.store.entity.classinfo.ClassInfo;
import net.sf.joafip.store.entity.objectio.ObjectAndPersistInfo;
import net.sf.joafip.store.service.bytecode.ClassEnhancer;
import net.sf.joafip.store.service.bytecode.EnhanceException;
import net.sf.joafip.store.service.classinfo.ClassInfoException;
import net.sf.joafip.store.service.classinfo.ClassInfoFactory;
import net.sf.joafip.store.service.objectio.ObjectIOClassNotFoundException;
import net.sf.joafip.store.service.objectio.ObjectIODataCorruptedException;
import net.sf.joafip.store.service.objectio.ObjectIODataRecordNotFoundException;
import net.sf.joafip.store.service.objectio.ObjectIOException;
import net.sf.joafip.store.service.objectio.ObjectIOInvalidClassException;
import net.sf.joafip.store.service.objectio.ObjectIONotSerializableException;
import net.sf.joafip.store.service.objectio.manager.IObjectIOManagerForProxyObjectIO;
import net.sf.joafip.store.service.proxy.IProxyCallBack;
import net.sf.joafip.store.service.proxy.IProxyCallBackToImplement;

public final class MainEnhanceCode implements IProxyCallBackToImplement {

  private final ClassEnhancer classEnhancer;

  private final ClassInfoFactory classInfoFactory = new ClassInfoFactory(1);

  private HelperReflect helperReflect = HelperReflect.getInstance();

  public static void main(String[] args) {
    MainEnhanceCode main;
    try {
      main = new MainEnhanceCode();
      main.test();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

  private MainEnhanceCode() throws IOException, EnhanceException {
    super();
    classEnhancer = new ClassEnhancer(new ClassLoaderProvider(),
        new ClassInfoFactory(1));
  }

  private void test() throws EnhanceException, InstantiationException,
      IllegalAccessException, ReflectException,
      ReflectInvalidClassException, ClassInfoException {
    final Class<?> clazz = PTreeMap.class;
    final ClassInfo objectClassInfo = classInfoFactory.getClassInfo(clazz);
    Class<?> enhancedClass = classEnhancer.enhanceClass(objectClassInfo, 0);

    /*
     * create instance
     */
    // Object object = enhancedClass.newInstance();
    Object object = helperReflect.newInstanceNoConstruction(enhancedClass);
    System.out.println(System.identityHashCode(object));

    /*
     * test cast to IProxyCallBack
     */
    IProxyCallBack proxyCallBack = (IProxyCallBack) object;
    proxyCallBack.setProxyCallBack$JOAFIP$(this);
    System.out.println(proxyCallBack.isLoaded$JOAFIP$());

  }

  @Override
  public void forceLoad$JOAFIP$() throws ObjectIOException,
      ObjectIODataRecordNotFoundException, ObjectIOInvalidClassException,
      ObjectIOClassNotFoundException, ObjectIODataCorruptedException,
      ObjectIONotSerializableException {
  }

  @Override
  public void unload$JOAFIP$() {
  }

  @Override
  public long getMyFileAccessSessionIdentifier$JOAFIP$() {
    return 0;
  }

  @Override
  public ClassInfo getProxiedClass$JOAFIP$() {
    return null;
  }

  @Override
  public void intercept$JOAFIP$() {
  }

  @Override
  public void methodEnd$JOAFIP$() {
  }

  @Override
  public boolean isLoaded$JOAFIP$() {
    return false;
  }

  @Override
  public void setLoaded$JOAFIP$(boolean loaded) throws ObjectIOException {
  }

  @Override
  public ClassInfoFactory getClassInfoFactory$JOAFIP$() {
    return null;
  }

  @Override
  public void setInstance$JOAFIP$(ObjectAndPersistInfo objectAndPersistInfo) {
  }

  @Override
  public IObjectIOManagerForProxyObjectIO getObjectIOManager$JOAFIP$() {
    return null;
  }

  @Override
  public void setLoading$JOAFIP$(boolean loading) {
  }
}
TOP

Related Classes of net.sf.joafip.MainEnhanceCode

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.