KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > config > DSOApplicationConfigImpl


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.config;
5
6 import com.tc.config.schema.builder.ConfigBuilderFactory;
7 import com.tc.config.schema.builder.DSOApplicationConfigBuilder;
8 import com.tc.config.schema.builder.InstrumentedClassConfigBuilder;
9 import com.tc.config.schema.builder.LockConfigBuilder;
10 import com.tc.config.schema.builder.RootConfigBuilder;
11
12 import java.util.LinkedList JavaDoc;
13 import java.util.List JavaDoc;
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 JavaDoc roots = new LinkedList JavaDoc();
26   private final List JavaDoc instrumentedClasses = new LinkedList JavaDoc();
27   private final List JavaDoc locks = new LinkedList JavaDoc();
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.toArray(new RootConfigBuilder[roots.size()]));
36     }
37     builder.setInstrumentedClasses((InstrumentedClassConfigBuilder[]) instrumentedClasses
38         .toArray(new InstrumentedClassConfigBuilder[instrumentedClasses.size()]));
39     builder.setLocks((LockConfigBuilder[]) locks.toArray(new LockConfigBuilder[locks.size()]));
40   }
41
42   public void addRoot(String JavaDoc rootName, String JavaDoc rootFieldName) {
43     RootConfigBuilder root = factory.newRootConfigBuilder();
44     root.setRootName(rootName);
45     root.setFieldName(rootFieldName);
46     roots.add(root);
47   }
48
49   public void addIncludePattern(String JavaDoc classPattern) {
50     addIncludePattern(classPattern, false);
51   }
52
53   public void addIncludePattern(String JavaDoc classPattern, boolean honorTransient) {
54     InstrumentedClassConfigBuilder instrumentedClass = factory.newInstrumentedClassConfigBuilder();
55     instrumentedClass.setClassExpression(classPattern);
56     instrumentedClass.setHonorTransient(honorTransient);
57     addInstrumentedClass(instrumentedClass);
58   }
59
60   private void addInstrumentedClass(InstrumentedClassConfigBuilder instrumentedClass) {
61     instrumentedClasses.add(instrumentedClass);
62   }
63
64   public void addWriteAutolock(String JavaDoc methodPattern) {
65     LockConfigBuilder lock = factory.newWriteAutoLockConfigBuilder();
66     lock.setMethodExpression(methodPattern);
67     locks.add(lock);
68   }
69   
70   public void addReadAutolock(String JavaDoc methodPattern) {
71     LockConfigBuilder lock = factory.newReadAutoLockConfigBuilder();
72     lock.setMethodExpression(methodPattern);
73     locks.add(lock);
74   }
75
76 }
77
Popular Tags