KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > approval > Approval


1 /*************************************************************************
2  * *
3  * EJBCA: The OpenSource Certificate Authority *
4  * *
5  * This software is free software; you can redistribute it and/or *
6  * modify it under the terms of the GNU Lesser General Public *
7  * License as published by the Free Software Foundation; either *
8  * version 2.1 of the License, or any later version. *
9  * *
10  * See terms of license at gnu.org. *
11  * *
12  *************************************************************************/

13 package org.ejbca.core.model.approval;
14
15 import java.io.Externalizable JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.io.ObjectInput JavaDoc;
18 import java.io.ObjectOutput JavaDoc;
19 import java.math.BigInteger JavaDoc;
20 import java.security.cert.X509Certificate JavaDoc;
21 import java.util.Date JavaDoc;
22
23
24 import org.ejbca.util.CertTools;
25
26
27
28 /**
29  * Class representing one approval of a request data.
30  * Includes information like:
31  * Approval admin certificate
32  * isApproved (rejected otherwise)
33  * ApprovalDate
34  * Comment
35  *
36  *
37  * Approvals is sorted by dates.
38  *
39  * @author Philip Vendil
40  * @version $Id: Approval.java,v 1.2 2006/07/30 18:19:02 herrvendil Exp $
41  */

42
43 public class Approval implements Comparable JavaDoc, Externalizable JavaDoc {
44     
45     private static final long serialVersionUID = -1L;
46     
47     private static final int LATEST_VERSION = 1;
48
49     private String JavaDoc adminCertIssuerDN = null;
50     private String JavaDoc adminCertSerialNumber = null;
51     private boolean approved = false;
52     private Date JavaDoc approvalDate = null;
53     private String JavaDoc comment = null;
54     private String JavaDoc approvalSignature = null;
55     private String JavaDoc username = null;
56     
57     
58     /**
59      * @param approved
60      * @param apDate
61      * @param comment
62      */

63     public Approval(String JavaDoc comment) {
64         super();
65         this.approvalDate = new Date JavaDoc();
66         this.comment = comment;
67     }
68     
69     /**
70      * Constuctor used in externaliziation only
71      */

72     public Approval(){}
73
74     /**
75      * @return Returns the adminCertIssuerDN.
76      */

77     public String JavaDoc getAdminCertIssuerDN() {
78         return adminCertIssuerDN;
79     }
80     
81     
82     /**
83      * @return Returns the adminCertSerialNumber.
84      */

85     public BigInteger JavaDoc getAdminCertSerialNumber() {
86         return new BigInteger JavaDoc(adminCertSerialNumber,16);
87     }
88     
89     
90     /**
91      * @return Returns the approvalDate.
92      */

93     public Date JavaDoc getApprovalDate() {
94         return approvalDate;
95     }
96     
97     
98     /**
99      * @return Returns the approved.
100      */

101     public boolean isApproved() {
102         return approved;
103     }
104     
105     
106     /**
107      * @return Returns the comment.
108      */

109     public String JavaDoc getComment() {
110         return comment;
111     }
112     
113     /**
114      * @return Returns the username of the approving administrator
115      */

116     public String JavaDoc getUsername() {
117         return username;
118     }
119
120     /**
121      * The cert and username of the approving administrator. Should only be set
122      * by the ApprovalSessionBean
123      *
124      *
125      */

126     public void setApprovalCertificateAndUsername(boolean approved, X509Certificate JavaDoc approvalAdminCert, String JavaDoc username) {
127         this.approved = approved;
128         this.adminCertSerialNumber = approvalAdminCert.getSerialNumber().toString(16);
129         this.adminCertIssuerDN = CertTools.getIssuerDN(approvalAdminCert);
130         this.username = username;
131     }
132
133     /**
134      * Sort by approval date
135      */

136     public int compareTo(Object JavaDoc arg0) {
137         return approvalDate.compareTo(((Approval) arg0).approvalDate);
138     }
139
140     public void writeExternal(ObjectOutput JavaDoc out) throws IOException JavaDoc {
141         out.writeInt(LATEST_VERSION);
142         out.writeObject(this.adminCertIssuerDN);
143         out.writeObject(this.adminCertSerialNumber);
144         out.writeBoolean(this.approved);
145         out.writeObject(this.approvalDate);
146         out.writeObject(this.comment);
147         out.writeObject(this.approvalSignature);
148         out.writeObject(this.username);
149     }
150
151     public void readExternal(ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
152         
153         int version = in.readInt();
154         if(version == 1){
155             this.adminCertIssuerDN = (String JavaDoc) in.readObject();
156             this.adminCertSerialNumber = (String JavaDoc) in.readObject();
157             this.approved = in.readBoolean();
158             this.approvalDate = (Date JavaDoc) in.readObject();
159             this.comment = (String JavaDoc) in.readObject();
160             this.approvalSignature = (String JavaDoc) in.readObject();
161             this.username = (String JavaDoc) in.readObject();
162         }
163         
164     }
165
166
167
168
169 }
170
Popular Tags