01: /*
02: * Copyright (C) 2004, 2006 Joe Walnes.
03: * Copyright (C) 2006, 2007 XStream Committers.
04: * All rights reserved.
05: *
06: * The software in this package is published under the terms of the BSD
07: * style license a copy of which has been included with this distribution in
08: * the LICENSE.txt file.
09: *
10: * Created on 07. March 2004 by Joe Walnes
11: */
12: package com.thoughtworks.xstream.converters.reflection;
13:
14: import java.lang.reflect.Field;
15:
16: /**
17: * Provides core reflection services.
18: *
19: * @author Joe Walnes
20: */
21: public interface ReflectionProvider {
22:
23: /**
24: * Creates a new instance of the specified type. It is in the responsibility
25: * of the implementation how such an instance is created.
26: * @param type the type to instantiate
27: * @return a new instance of this type
28: */
29: Object newInstance(Class type);
30:
31: void visitSerializableFields(Object object, Visitor visitor);
32:
33: void writeField(Object object, String fieldName, Object value,
34: Class definedIn);
35:
36: Class getFieldType(Object object, String fieldName, Class definedIn);
37:
38: boolean fieldDefinedInClass(String fieldName, Class type);
39:
40: /**
41: * A visitor interface for serializable fields defined in a class.
42: *
43: */
44: interface Visitor {
45:
46: /**
47: * Callback for each visit
48: * @param name field name
49: * @param type field type
50: * @param definedIn where the field was defined
51: * @param value field value
52: */
53: void visit(String name, Class type, Class definedIn,
54: Object value);
55: }
56:
57: /**
58: * Returns a field defined in some class.
59: * @param definedIn class where the field was defined
60: * @param fieldName field name
61: * @return the field itself
62: */
63: Field getField(Class definedIn, String fieldName);
64:
65: }
|