KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > outerj > daisy > frontend > components > docbasket > DocumentBasketEntry


1 /*
2  * Copyright 2004 Outerthought bvba and Schaubroeck nv
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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 org.outerj.daisy.frontend.components.docbasket;
17
18 import org.apache.excalibur.xml.sax.XMLizable;
19 import org.apache.cocoon.xml.AttributesImpl;
20 import org.apache.commons.lang.builder.HashCodeBuilder;
21 import org.xml.sax.ContentHandler JavaDoc;
22 import org.xml.sax.SAXException JavaDoc;
23
24 /**
25  * An entry in a document basket.
26  *
27  * <p>The specific document variant version identified by document basket entry
28  * is immutable, other properties (document name) can be modified.
29  *
30  * <p>Two entries are equal if they are about the same document variant version.
31  */

32 public class DocumentBasketEntry implements XMLizable {
33     private final long documentId;
34     private final String JavaDoc branch;
35     private final String JavaDoc language;
36     private final long versionId;
37     private String JavaDoc documentName;
38     private int hashCode;
39
40     public DocumentBasketEntry(long documentId, String JavaDoc branch, String JavaDoc language, long versionId, String JavaDoc documentName) {
41         this.documentId = documentId;
42         this.branch = branch;
43         this.language = language;
44         this.versionId = versionId;
45         this.documentName = documentName;
46         initHashCode();
47     }
48
49     private void initHashCode() {
50         HashCodeBuilder builder = new HashCodeBuilder();
51         builder.append(this.documentId);
52         builder.append(branch);
53         builder.append(language);
54         builder.append(versionId);
55         this.hashCode = builder.toHashCode();
56     }
57
58     public long getDocumentId() {
59         return documentId;
60     }
61
62     public String JavaDoc getBranch() {
63         return branch;
64     }
65
66     public String JavaDoc getLanguage() {
67         return language;
68     }
69
70     public long getVersionId() {
71         return versionId;
72     }
73
74     public String JavaDoc getDocumentName() {
75         return documentName;
76     }
77
78     public void setDocumentName(String JavaDoc documentName) {
79         this.documentName = documentName;
80     }
81
82     public void toSAX(ContentHandler JavaDoc contentHandler) throws SAXException JavaDoc {
83         AttributesImpl attrs = new AttributesImpl();
84         attrs.addCDATAAttribute("id", String.valueOf(documentId));
85         attrs.addCDATAAttribute("branch", branch);
86         attrs.addCDATAAttribute("language", language);
87         attrs.addCDATAAttribute("versionId", versionId == -1 ? "" : String.valueOf(versionId));
88         attrs.addCDATAAttribute("name", documentName);
89         contentHandler.startElement("", "entry", "entry", attrs);
90         contentHandler.endElement("", "entry", "entry");
91     }
92
93     public boolean equals(Object JavaDoc obj) {
94         DocumentBasketEntry other = (DocumentBasketEntry)obj;
95         return other.documentId == this.documentId
96                 && other.branch.equals(this.branch)
97                 && other.language.equals(this.language)
98                 && other.versionId == this.versionId;
99     }
100
101     public int hashCode() {
102         return hashCode;
103     }
104 }
105
Popular Tags