Exemplo n.º 1
0
  /** Performs tasks to resolve the lazy instantiation. */
  private synchronized void init() {
    if (!initialized) {
      // Mimic the behavior of XStream's JVM class
      String vendor = System.getProperty("java.vm.vendor");
      float version = 1.3f;
      try {
        version = Float.parseFloat(System.getProperty("java.version").substring(0, 3));
      } catch (NumberFormatException nfe) {
        // Keep the default
      }
      Class unsafe = null;
      try {
        unsafe = Class.forName("sun.misc.Unsafe", false, getClass().getClassLoader());
      } catch (ClassNotFoundException cnfe) {
        // Keep the default
      }
      ReflectionProvider reflectionProvider = null;
      if ((vendor.contains("Sun")
              || vendor.contains("Oracle")
              || vendor.contains("Apple")
              || vendor.contains("Hewlett-Packard")
              || vendor.contains("IBM")
              || vendor.contains("Blackdown"))
          && version >= 1.4f
          && unsafe != null) {
        try {
          reflectionProvider =
              (ReflectionProvider)
                  Class.forName(
                          "com.thoughtworks.xstream.converters.reflection.Sun14ReflectionProvider",
                          false,
                          getClass().getClassLoader())
                      .newInstance();
        } catch (InstantiationException ie) {
          reflectionProvider = new PureJavaReflectionProvider();
        } catch (IllegalAccessException iae) {
          reflectionProvider = new PureJavaReflectionProvider();
        } catch (ClassNotFoundException cnfe) {
          reflectionProvider = new PureJavaReflectionProvider();
        }
      } else {
        reflectionProvider = new PureJavaReflectionProvider();
      }
      HierarchicalStreamDriver driver = new DomDriver();

      xs = new XStream(reflectionProvider, driver);
      xs.setMarshallingStrategy(new LockssReferenceByXPathMarshallingStrategy(lockssContext));
      xs.registerConverter(new LockssDateConverter());
      initialized = true;
    }
  }
Exemplo n.º 2
0
    private Method cacheMethod(
        Object obj, String methodName, Class[] methodParameters, HashMap methodCache) {
      Class objClass = obj.getClass();
      Method objMethod = null;

      // Look up inheritance hierarchy
      while (objClass != Object.class) {
        try {
          objMethod = objClass.getDeclaredMethod(methodName, methodParameters);
          objClass = Object.class; // executed only if call succeeds
        } catch (NoSuchMethodException nsmE) {
          objClass = objClass.getSuperclass();
        }
      }

      // Cache result
      if (objMethod == null) {
        methodCache.put(obj.getClass(), NONE);
      } else {
        objMethod.setAccessible(true); // monstrous, monstrous
        methodCache.put(obj.getClass(), objMethod);
      }
      return objMethod;
    }
Exemplo n.º 3
0
 public boolean canConvert(Class type) {
   return type.equals(Date.class);
 }