01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.config;
05:
06: import com.tc.config.schema.builder.ConfigBuilderFactory;
07: import com.tc.config.schema.builder.DSOApplicationConfigBuilder;
08: import com.tc.config.schema.builder.InstrumentedClassConfigBuilder;
09: import com.tc.config.schema.builder.LockConfigBuilder;
10: import com.tc.config.schema.builder.RootConfigBuilder;
11:
12: import java.util.LinkedList;
13: import java.util.List;
14:
15: /**
16: * This class is an adapter between the ConfigVisitor class and the config builder stuff. It allows config to be
17: * accreted during the visitation process and then baked into a config builder. I'm not extremely satisfied with the
18: * naming and package structure of this thing, but it'll do. If you don't like it, feel free to move it.
19: *
20: * @author orion
21: */
22: public class DSOApplicationConfigImpl implements DSOApplicationConfig {
23:
24: private final ConfigBuilderFactory factory;
25: private final List roots = new LinkedList();
26: private final List instrumentedClasses = new LinkedList();
27: private final List locks = new LinkedList();
28:
29: public DSOApplicationConfigImpl(ConfigBuilderFactory factory) {
30: this .factory = factory;
31: }
32:
33: public void writeTo(DSOApplicationConfigBuilder builder) {
34: if (!roots.isEmpty()) {
35: builder.setRoots((RootConfigBuilder[]) roots
36: .toArray(new RootConfigBuilder[roots.size()]));
37: }
38: builder
39: .setInstrumentedClasses((InstrumentedClassConfigBuilder[]) instrumentedClasses
40: .toArray(new InstrumentedClassConfigBuilder[instrumentedClasses
41: .size()]));
42: builder.setLocks((LockConfigBuilder[]) locks
43: .toArray(new LockConfigBuilder[locks.size()]));
44: }
45:
46: public void addRoot(String rootName, String rootFieldName) {
47: RootConfigBuilder root = factory.newRootConfigBuilder();
48: root.setRootName(rootName);
49: root.setFieldName(rootFieldName);
50: roots.add(root);
51: }
52:
53: public void addIncludePattern(String classPattern) {
54: addIncludePattern(classPattern, false);
55: }
56:
57: public void addIncludePattern(String classPattern,
58: boolean honorTransient) {
59: InstrumentedClassConfigBuilder instrumentedClass = factory
60: .newInstrumentedClassConfigBuilder();
61: instrumentedClass.setClassExpression(classPattern);
62: instrumentedClass.setHonorTransient(honorTransient);
63: addInstrumentedClass(instrumentedClass);
64: }
65:
66: private void addInstrumentedClass(
67: InstrumentedClassConfigBuilder instrumentedClass) {
68: instrumentedClasses.add(instrumentedClass);
69: }
70:
71: public void addWriteAutolock(String methodPattern) {
72: LockConfigBuilder lock = factory
73: .newWriteAutoLockConfigBuilder();
74: lock.setMethodExpression(methodPattern);
75: locks.add(lock);
76: }
77:
78: public void addReadAutolock(String methodPattern) {
79: LockConfigBuilder lock = factory.newReadAutoLockConfigBuilder();
80: lock.setMethodExpression(methodPattern);
81: locks.add(lock);
82: }
83:
84: }
|