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.ConfigProcessor;
18: import com.thoughtworks.xstream.builder.processor.TypeConfigProcessor;
19:
20: /**
21: * A type configuration.
22: *
23: * @author Guilherme Silveira
24: * @TODO gs: extract public interface, keep implementation hidden from the end user?
25: */
26: public class TypeConfig implements ConfigProcessor {
27: private final Class type;
28:
29: private final List childrenNodes;
30:
31: public TypeConfig(Class type) {
32: this .type = type;
33: this .childrenNodes = new ArrayList();
34: }
35:
36: public void process(XStream instance) {
37: for (int i = 0; i < childrenNodes.size(); i++) {
38: TypeConfigProcessor node = (TypeConfigProcessor) childrenNodes
39: .get(i);
40: node.process(instance, type);
41: }
42: }
43:
44: public void with(TypeConfigProcessor[] processors) {
45: for (int i = 0; i < processors.length; i++) {
46: TypeConfigProcessor processor = processors[i];
47: this .childrenNodes.add(processor);
48: }
49: }
50:
51: public void with(TypeConfigProcessor processor) {
52: this.childrenNodes.add(processor);
53: }
54:
55: }
|