01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.cms.repository;
19:
20: import java.util.Vector;
21:
22: import org.apache.avalon.framework.container.ContainerUtil;
23: import org.apache.avalon.framework.logger.AbstractLogEnabled;
24: import org.apache.avalon.framework.logger.Logger;
25: import org.apache.avalon.framework.service.ServiceManager;
26: import org.apache.lenya.cms.rc.CheckInEntry;
27: import org.apache.lenya.cms.rc.RCML;
28:
29: /**
30: * Revision history implementation.
31: */
32: public class SourceNodeHistory extends AbstractLogEnabled implements
33: History {
34:
35: private SourceNode node;
36: private ServiceManager manager;
37:
38: /**
39: * Ctor.
40: * @param node The node which the history belongs to.
41: * @param manager The service manager.
42: * @param logger The logger.
43: */
44: public SourceNodeHistory(SourceNode node, ServiceManager manager,
45: Logger logger) {
46: this .node = node;
47: this .manager = manager;
48: ContainerUtil.enableLogging(this , logger);
49: }
50:
51: public Revision getLatestRevision() {
52: try {
53: int[] numbers = getRevisionNumbers();
54: if (numbers.length > 0) {
55: return getRevision(numbers[0]);
56: } else {
57: throw new RepositoryException(
58: "There is no revision for node [" + this .node
59: + "] yet.");
60: }
61: } catch (Exception e) {
62: throw new RuntimeException(e);
63: }
64: }
65:
66: public Revision getRevision(int number) throws RepositoryException {
67: return new SourceNodeRevision(this .node, number, this .manager,
68: getLogger());
69: }
70:
71: public int[] getRevisionNumbers() {
72: RCML rcml = this .node.getRcml();
73: try {
74: Vector entries = rcml.getBackupEntries();
75: int[] numbers = new int[entries.size()];
76: for (int i = 0; i < entries.size(); i++) {
77: CheckInEntry entry = (CheckInEntry) entries.get(i);
78: numbers[i] = entry.getVersion();
79: }
80: return numbers;
81: } catch (Exception e) {
82: throw new RuntimeException(e);
83: }
84: }
85:
86: }
|