KickJava   Java API By Example, From Geeks To Geeks.

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


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.ByteArrayInputStream JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.io.ObjectInputStream JavaDoc;
18 import java.util.ArrayList JavaDoc;
19 import java.util.Collection JavaDoc;
20
21 import javax.ejb.EJBException JavaDoc;
22
23 import org.apache.log4j.Logger;
24 import org.ejbca.util.Base64;
25
26
27
28
29 /**
30  * Class containing utils for extracting data from the approvaldata table.
31  * is used by the Entity and Session bean only.
32  *
33  *
34  * @author Philip Vendil
35  * @version $Id: ApprovalDataUtil.java,v 1.3 2006/08/09 07:29:48 herrvendil Exp $
36  */

37
38 public class ApprovalDataUtil {
39     
40     private static final Logger log = Logger.getLogger(ApprovalDataUtil.class);
41
42
43     public static Collection JavaDoc getApprovals(String JavaDoc stringdata) {
44         ArrayList JavaDoc retval = new ArrayList JavaDoc();
45         try{
46             ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(Base64.decode(stringdata.getBytes())));
47             
48             int size = ois.readInt();
49             for(int i=0;i<size;i++){
50                 Approval next = (Approval) ois.readObject();
51                 retval.add(next);
52             }
53             
54         } catch (IOException JavaDoc e) {
55             log.error("Error building approvals.",e);
56             throw new EJBException JavaDoc(e);
57         } catch (ClassNotFoundException JavaDoc e) {
58             log.error("Error building approvals.",e);
59             throw new EJBException JavaDoc(e);
60         }
61         
62         return retval;
63     }
64     
65     public static ApprovalRequest getApprovalRequest(String JavaDoc stringdata) {
66         ApprovalRequest retval = null;
67         try {
68             
69             ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(Base64.decode(stringdata.getBytes())));
70             retval= (ApprovalRequest) ois.readObject();
71         } catch (IOException JavaDoc e) {
72             log.error("Error building approval request.",e);
73             throw new EJBException JavaDoc(e);
74         } catch (ClassNotFoundException JavaDoc e) {
75             log.error("Error building approval request.",e);
76             throw new EJBException JavaDoc(e);
77         }
78         
79         return retval;
80     }
81
82
83 }
84
Popular Tags