1 package org.modeshape.graph.connector.path;
2
3 import java.util.Set;
4 import java.util.UUID;
5 import java.util.concurrent.ConcurrentHashMap;
6 import java.util.concurrent.ConcurrentMap;
7 import net.jcip.annotations.ThreadSafe;
8 import org.modeshape.common.util.CheckArg;
9 import org.modeshape.graph.ExecutionContext;
10 import org.modeshape.graph.connector.RepositoryContext;
11 import org.modeshape.graph.observe.Observer;
12
13 @ThreadSafe
14 public abstract class PathRepository {
15
16 protected final UUID rootNodeUuid;
17 private final String sourceName;
18 private final String defaultWorkspaceName;
19
20 protected final ConcurrentMap<String, PathWorkspace> workspaces = new ConcurrentHashMap<String, PathWorkspace>();
21
22
23
24
25
26
27
28 protected PathRepository( PathRepositorySource source ) {
29 CheckArg.isNotNull(source, "source");
30 CheckArg.isNotEmpty(source.getName(), "source.name");
31 CheckArg.isNotNull(source.getRootNodeUuid(), "source.rootNodeUUID");
32 this.rootNodeUuid = source.getRootNodeUuid();
33 this.sourceName = source.getName();
34 this.defaultWorkspaceName = source.getDefaultWorkspaceName() != null ? source.getDefaultWorkspaceName() : "";
35 }
36
37
38
39
40
41
42
43
44
45
46
47
48 public final UUID getRootNodeUuid() {
49 return rootNodeUuid;
50 }
51
52
53
54
55
56
57
58 public String getSourceName() {
59 return sourceName;
60 }
61
62 protected String getDefaultWorkspaceName() {
63 return defaultWorkspaceName;
64 }
65
66
67
68
69
70
71 public Set<String> getWorkspaceNames() {
72 return workspaces.keySet();
73 }
74
75
76
77
78
79
80
81 public PathWorkspace getWorkspace( String name ) {
82 if (name == null) name = defaultWorkspaceName;
83 return workspaces.get(name);
84 }
85
86
87
88
89
90
91
92
93 protected abstract void initialize();
94
95 public boolean isWritable() {
96 return false;
97 }
98
99
100 PathRequestProcessor createRequestProcessor( ExecutionContext context,
101 PathRepositorySource source ) {
102 RepositoryContext repositoryContext = source.getRepositoryContext();
103 Observer observer = repositoryContext != null ? repositoryContext.getObserver() : null;
104 boolean updatesAllowed = source.areUpdatesAllowed();
105
106
107
108
109 PathRepositoryTransaction txn = new PathRepositoryTransaction() {
110
111 public void commit() {
112 }
113
114 public void rollback() {
115 }
116
117 };
118
119 return new PathRequestProcessor(context, this, observer, updatesAllowed, txn);
120 }
121 }