KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > model > ca > publisher > CustomPublisherContainer


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  
14 package org.ejbca.core.model.ca.publisher;
15
16 import java.io.ByteArrayInputStream JavaDoc;
17 import java.io.IOException JavaDoc;
18 import java.security.cert.Certificate JavaDoc;
19 import java.util.HashMap JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Properties JavaDoc;
22
23 import javax.ejb.EJBException JavaDoc;
24
25 import org.ejbca.core.model.log.Admin;
26 import org.ejbca.core.model.ra.ExtendedInformation;
27
28
29
30 /**
31  * CustomPublisherContainer is a class handling a custom publisher. It is used
32  * to store and retrieve custom publisher configuration to database.
33  *
34  *
35  * @version $Id: CustomPublisherContainer.java,v 1.3 2006/07/21 15:28:25 anatom Exp $
36  */

37 public class CustomPublisherContainer extends BasePublisher{
38     private ICustomPublisher custompublisher = null;
39     
40     public static final float LATEST_VERSION = 1;
41     
42     public static final int TYPE_CUSTOMPUBLISHERCONTAINER = 1;
43     
44     // Default Values
45

46     protected static final String JavaDoc CLASSPATH = "classpath";
47     protected static final String JavaDoc PROPERTYDATA = "propertydata";
48         
49     
50     
51     public CustomPublisherContainer(){
52         super();
53         data.put(TYPE, new Integer JavaDoc(TYPE_CUSTOMPUBLISHERCONTAINER));
54         setClassPath("");
55         setPropertyData("");
56     }
57     
58     // Public Methods
59
/**
60      * Returns the class path of custom publisher used.
61      */

62     public String JavaDoc getClassPath(){
63         return (String JavaDoc) data.get(CLASSPATH);
64     }
65
66     /**
67      * Sets the class path of custom publisher used.
68      */

69     public void setClassPath(String JavaDoc classpath){
70       data.put(CLASSPATH, classpath);
71     }
72
73     /**
74      * Returns the propertydata used to configure this custom publisher.
75      */

76     public String JavaDoc getPropertyData(){
77         return (String JavaDoc) data.get(PROPERTYDATA);
78     }
79
80     /**
81      * Sets the propertydata used to configure this custom publisher.
82      */

83     public void setPropertyData(String JavaDoc propertydata){
84         data.put(PROPERTYDATA, propertydata);
85     }
86     
87     public Properties JavaDoc getProperties() throws IOException JavaDoc{
88         Properties JavaDoc prop = new Properties JavaDoc();
89         prop.load(new ByteArrayInputStream JavaDoc(getPropertyData().getBytes()));
90         return prop;
91     }
92   
93     
94     /**
95      * @see org.ejbca.core.model.ca.publisher.BasePublisher
96      */

97     public boolean storeCertificate(Admin admin, Certificate JavaDoc incert, String JavaDoc username, String JavaDoc password, String JavaDoc cafp, int status, int type, long revocationDate, int revocationReason, ExtendedInformation extendedinformation) throws PublisherException{
98         return this.getCustomPublisher().storeCertificate(admin,incert,username,password, cafp,status,type, revocationDate, revocationReason, extendedinformation);
99     }
100     
101     /**
102      * @see org.ejbca.core.model.ca.publisher.BasePublisher
103      */

104     public boolean storeCRL(Admin admin, byte[] incrl, String JavaDoc cafp, int number) throws PublisherException{
105         return this.getCustomPublisher().storeCRL(admin,incrl,cafp,number);
106     }
107     
108     /**
109      * @see org.ejbca.core.model.ca.publisher.BasePublisher
110      */

111     public void revokeCertificate(Admin admin, Certificate JavaDoc cert, int reason) throws PublisherException{
112         this.getCustomPublisher().revokeCertificate(admin,cert,reason);
113     }
114     
115     /**
116      * @see org.ejbca.core.model.ca.publisher.BasePublisher
117      */

118     public void testConnection(Admin admin) throws PublisherConnectionException{
119         this.getCustomPublisher().testConnection(admin);
120     }
121     
122     // Private methods
123
private ICustomPublisher getCustomPublisher() {
124         if(custompublisher == null){
125             try{
126                 Class JavaDoc implClass = Class.forName( getClassPath() );
127                 Object JavaDoc obj = implClass.newInstance();
128                 this.custompublisher = (ICustomPublisher) obj;
129                 this.custompublisher.init(getProperties());
130             }catch(ClassNotFoundException JavaDoc e){
131                 throw new EJBException JavaDoc(e);
132             }
133             catch(IllegalAccessException JavaDoc iae){
134                 throw new EJBException JavaDoc(iae);
135             }
136             catch(IOException JavaDoc ioe){
137                 throw new EJBException JavaDoc(ioe);
138             }
139             catch(InstantiationException JavaDoc ie){
140                 throw new EJBException JavaDoc(ie);
141             }
142         }
143         
144         return custompublisher;
145     }
146         
147     /**
148      * @see org.ejbca.core.model.ca.publisher.BasePublisher#clone()
149      */

150     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
151         CustomPublisherContainer clone = new CustomPublisherContainer();
152         HashMap JavaDoc clonedata = (HashMap JavaDoc) clone.saveData();
153
154         Iterator JavaDoc i = (data.keySet()).iterator();
155         while(i.hasNext()){
156             Object JavaDoc key = i.next();
157             clonedata.put(key, data.get(key));
158         }
159
160         clone.loadData(clonedata);
161         return clone;
162         }
163
164     /* *
165      * @see org.ejbca.core.model.ca.publisher.BasePublisher#getLatestVersion()
166      */

167     public float getLatestVersion() {
168         return LATEST_VERSION;
169     }
170
171     /**
172      * Resets the current custom publisher
173      * @see org.ejbca.core.model.UpgradeableDataHashMap#saveData()
174      */

175     public Object JavaDoc saveData() {
176         this.custompublisher = null;
177         return super.saveData();
178     }
179     
180
181 }
182
Popular Tags