1 package org.treetank.access.conf;
2
3 import java.security.Key;
4
5 import org.treetank.access.conf.ResourceConfiguration.IResourceConfigurationFactory;
6 import org.treetank.access.conf.SessionConfiguration.ISessionConfigurationFactory;
7 import org.treetank.api.IMetaEntryFactory;
8 import org.treetank.api.IDataFactory;
9 import org.treetank.io.IBackend;
10 import org.treetank.io.IBackend.IBackendFactory;
11 import org.treetank.io.berkeley.BerkeleyStorage;
12 import org.treetank.io.bytepipe.ByteHandlerPipeline;
13 import org.treetank.io.bytepipe.Encryptor;
14 import org.treetank.io.bytepipe.IByteHandler;
15 import org.treetank.io.bytepipe.IByteHandler.IByteHandlerPipeline;
16 import org.treetank.io.jclouds.JCloudsStorage;
17 import org.treetank.revisioning.IRevisioning;
18 import org.treetank.revisioning.SlidingSnapshot;
19
20 import com.google.inject.AbstractModule;
21 import com.google.inject.assistedinject.FactoryModuleBuilder;
22
23
24
25
26
27
28
29 public class ModuleSetter {
30
31
32 private Class<? extends IDataFactory> mDataFacClass;
33
34 private Class<? extends IMetaEntryFactory> mMetaFacClass;
35
36 private Class<? extends IRevisioning> mRevisioningClass = SlidingSnapshot.class;
37
38 private Class<? extends IBackend> mBackend = JCloudsStorage.class;
39
40 private Key mKey = StandardSettings.KEY;
41
42 private IByteHandlerPipeline mByteHandler = new ByteHandlerPipeline(new Encryptor(mKey));
43
44
45
46
47
48
49
50
51 public ModuleSetter setDataFacClass(final Class<? extends IDataFactory> pDataFac) {
52 this.mDataFacClass = pDataFac;
53 return this;
54 }
55
56
57
58
59
60
61
62
63 public ModuleSetter setMetaFacClass(final Class<? extends IMetaEntryFactory> pMetaFac) {
64 this.mMetaFacClass = pMetaFac;
65 return this;
66 }
67
68
69
70
71
72
73
74
75 public ModuleSetter setRevisioningClass(final Class<? extends IRevisioning> pRevision) {
76 this.mRevisioningClass = pRevision;
77 return this;
78 }
79
80
81
82
83
84
85
86
87 public ModuleSetter setBackendClass(final Class<? extends IBackend> pBackend) {
88 this.mBackend = pBackend;
89 return this;
90 }
91
92
93
94
95
96
97
98
99 public ModuleSetter setIByteHandlerInstance(final IByteHandlerPipeline pByteHandler) {
100 this.mByteHandler = pByteHandler;
101 return this;
102 }
103
104
105
106
107
108
109
110
111 public ModuleSetter setKeyInstance(final Key pKey) {
112 this.mKey = pKey;
113 return this;
114 }
115
116
117
118
119
120
121 public AbstractModule createModule() {
122 return new AbstractModule() {
123 @Override
124 protected void configure() {
125 bind(IDataFactory.class).to(mDataFacClass);
126 bind(IMetaEntryFactory.class).to(mMetaFacClass);
127 bind(IRevisioning.class).to(mRevisioningClass);
128 bind(IByteHandlerPipeline.class).toInstance(mByteHandler);
129 install(new FactoryModuleBuilder().implement(IBackend.class, mBackend).build(
130 IBackendFactory.class));
131 install(new FactoryModuleBuilder().build(IResourceConfigurationFactory.class));
132 bind(Key.class).toInstance(mKey);
133 install(new FactoryModuleBuilder().build(ISessionConfigurationFactory.class));
134 }
135 };
136 }
137
138 }