1 package com.thoughtworks.xstream.objecttree.reflection;
2
3 import com.thoughtworks.xstream.objecttree.ObjectAccessException;
4 import sun.reflect.ReflectionFactory;
5
6 import java.lang.reflect.Constructor;
7 import java.lang.reflect.InvocationTargetException;
8
9 public class SunReflectionObjectFactory implements ObjectFactory {
10
11 private ReflectionFactory reflectionFactory = ReflectionFactory.getReflectionFactory();
12
13 public Object create(Class type) {
14 try {
15 Constructor javaLangObjectConstructor = Object.class.getDeclaredConstructor(new Class[0]);
16 Constructor customConstructor = reflectionFactory.newConstructorForSerialization(type, javaLangObjectConstructor);
17 Object newValue = customConstructor.newInstance(new Object[0]);
18 return newValue;
19 } catch (NoSuchMethodException e) {
20 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
21 } catch (SecurityException e) {
22 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
23 } catch (InstantiationException e) {
24 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
25 } catch (IllegalAccessException e) {
26 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
27 } catch (IllegalArgumentException e) {
28 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
29 } catch (InvocationTargetException e) {
30 throw new ObjectAccessException("Cannot construct " + type.getName(), e);
31 }
32 }
33
34 }
This page was automatically generated by Maven