01: /*
02: * Copyright 2005 Hippo Webworks.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package nl.hippo.slide.replication;
17:
18: import java.io.ByteArrayInputStream;
19: import java.io.InputStream;
20: import java.util.Enumeration;
21: import java.util.Hashtable;
22: import java.util.List;
23: import java.util.Vector;
24:
25: import org.apache.avalon.framework.configuration.Configuration;
26: import org.apache.avalon.framework.configuration.ConfigurationException;
27: import org.apache.avalon.framework.logger.AbstractLogEnabled;
28: import org.apache.avalon.framework.logger.Logger;
29: import org.apache.slide.content.NodeProperty;
30: import org.apache.slide.content.NodeRevisionContent;
31: import org.apache.slide.content.NodeRevisionDescriptor;
32:
33: public class ReplicatorCollection extends AbstractLogEnabled {
34:
35: private List replicators = new Vector();
36:
37: public ReplicatorCollection() {
38: super ();
39: }
40:
41: public void enableLogging(Logger logger) {
42: super .enableLogging(logger);
43:
44: for (int i = 0; i < replicators.size(); i++) {
45: setupLogger(replicators.get(i));
46: }
47: }
48:
49: public void addReplicator(Replicator replicator) {
50: replicators.add(replicator);
51: }
52:
53: public void create(String uri, NodeRevisionDescriptor descriptor,
54: NodeRevisionContent content) {
55: boolean isCollection = NodeRevisionDescriptor.COLLECTION_TYPE
56: .equals(descriptor.getResourceType());
57: if (replicators.size() == 0) {
58: getLogger().debug("No replicators defined!");
59: }
60: for (int i = 0; i < replicators.size(); i++) {
61: Replicator r = (Replicator) replicators.get(i);
62: if (!r.canReplicate(uri)) {
63: continue;
64: }
65: if (isCollection) {
66: r.mkcol(uri, descriptor);
67: } else {
68: r.create(uri, descriptor, content);
69: }
70: }
71: }
72:
73: public void remove(String uri) {
74: if (replicators.size() == 0) {
75: getLogger().debug("No replicators defined!");
76: }
77: for (int i = 0; i < replicators.size(); i++) {
78: Replicator r = (Replicator) replicators.get(i);
79: if (!r.canReplicate(uri)) {
80: continue;
81: }
82: r.remove(uri);
83: }
84: }
85:
86: public static ReplicatorCollection getReplicatorCollection(
87: Configuration config, Logger logger)
88: throws ConfigurationException {
89: ReplicatorCollection coll = new ReplicatorCollection();
90: coll.enableLogging(logger);
91: Configuration[] replicators = config.getChildren("replicator");
92: for (int i = 0; i < replicators.length; i++) {
93: coll.addReplicator(Replicator.getReplicator(replicators[i],
94: logger));
95: }
96: return coll;
97: }
98: }
|