01: /*
02: * Copyright (C) 2007 XStream Committers.
03: * All rights reserved.
04: *
05: * The software in this package is published under the terms of the BSD
06: * style license a copy of which has been included with this distribution in
07: * the LICENSE.txt file.
08: *
09: * Created on 13. July 2007 by Guilherme Silveira
10: */
11: package com.thoughtworks.xstream.builder;
12:
13: import java.util.ArrayList;
14: import java.util.List;
15:
16: import com.thoughtworks.xstream.XStream;
17: import com.thoughtworks.xstream.builder.processor.FieldConfigProcessor;
18: import com.thoughtworks.xstream.builder.processor.TypeConfigProcessor;
19:
20: /**
21: * A field configuration.
22: *
23: * @author Guilherme Silveira
24: * @TODO gs: extract public interface, keep implementation hidden from the end user?
25: */
26: public class FieldConfig implements TypeConfigProcessor {
27:
28: private final String fieldName;
29: private final List processors;
30:
31: public FieldConfig(String fieldName) {
32: this .fieldName = fieldName;
33: this .processors = new ArrayList();
34: }
35:
36: public void process(XStream instance, Class type) {
37: for (int i = 0; i < processors.size(); i++) {
38: FieldConfigProcessor node = (FieldConfigProcessor) processors
39: .get(i);
40: node.process(instance, type, fieldName);
41: }
42: }
43:
44: public FieldConfig with(FieldConfigProcessor[] processors) {
45: for (int i = 0; i < processors.length; i++) {
46: FieldConfigProcessor processor = processors[i];
47: this .processors.add(processor);
48: }
49: return this ;
50: }
51:
52: public FieldConfig with(FieldConfigProcessor processor) {
53: this.processors.add(processor);
54: return this;
55: }
56:
57: }
|