KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejbca > core > ejb > authorization > AccessRulesPK


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
15 package org.ejbca.core.ejb.authorization;
16
17 import org.ejbca.core.model.authorization.AccessRule;
18
19 /**
20  * The current pk in AdminEntityData and AccessRulesData is a mix of integer pk and
21  * constraints and actually works fine.
22  * It's used like a primitive int primary key in the db, but embeds logic for
23  * enforcing constraints, which would otherwise have to be programatically added to the beans.
24  * If needed it can easily be replaced with an int pk and programatic logic to handle
25  * constraints. From the database view the pk is just an int.
26  *
27  * @version $Id: AccessRulesPK.java,v 1.1 2006/01/17 20:30:04 anatom Exp $
28  */

29
30 public final class AccessRulesPK implements java.io.Serializable JavaDoc {
31
32     public int primKey;
33
34
35     public AccessRulesPK(java.lang.String JavaDoc admingroupname, int caid, AccessRule accessrule) {
36         this.primKey =
37         ((admingroupname==null?0:admingroupname.hashCode())
38         ^
39         (caid)
40         ^
41         (accessrule.getAccessRule()==null?0:accessrule.getAccessRule().hashCode()));
42     }
43
44     public AccessRulesPK() {
45     }
46
47     public int getPrimKey()
48     {
49         return primKey;
50     }
51
52     public void setpK(int primKey)
53     {
54         this.primKey = primKey;
55     }
56
57     /**
58      * @see java.lang.Object#equals(java.lang.Object)
59      */

60     public boolean equals(java.lang.Object JavaDoc otherOb) {
61         if (!(otherOb instanceof org.ejbca.core.ejb.authorization.AccessRulesPK)) {
62             return false;
63         }
64         org.ejbca.core.ejb.authorization.AccessRulesPK other = (org.ejbca.core.ejb.authorization.AccessRulesPK) otherOb;
65         return (this.primKey==other.primKey);
66     }
67
68     /**
69      * @see java.lang.Object#hashCode()
70      */

71     public int hashCode() {
72         return this.primKey;
73     }
74
75     /** @return String representation of this pk in the form of [.field1.field2.field3]. */
76     public String JavaDoc toString()
77     {
78         StringBuffer JavaDoc toStringValue = new StringBuffer JavaDoc("[.");
79         toStringValue.append(this.primKey).append('.');
80         toStringValue.append(']');
81         return toStringValue.toString();
82     }
83 }
84
Popular Tags