001: /*************************************************************************
002: * *
003: * EJBCA: The OpenSource Certificate Authority *
004: * *
005: * This software is free software; you can redistribute it and/or *
006: * modify it under the terms of the GNU Lesser General Public *
007: * License as published by the Free Software Foundation; either *
008: * version 2.1 of the License, or any later version. *
009: * *
010: * See terms of license at gnu.org. *
011: * *
012: *************************************************************************/package org.ejbca.core.model.hardtoken.types;
013:
014: import java.io.Serializable;
015:
016: import org.ejbca.core.model.UpgradeableDataHashMap;
017:
018: /**
019: * HardToken is a base class that all HardToken classes is supposed to inherit. It function is to
020: * define the data the token is supposed contain.
021: *
022: * @author TomSelleck
023: * @version $Id: HardToken.java,v 1.2 2007/04/13 06:15:20 herrvendil Exp $
024: */
025: public abstract class HardToken extends UpgradeableDataHashMap
026: implements Serializable, Cloneable {
027: // Default Values
028: public static final float LATEST_VERSION = 0;
029: public static final String TOKENTYPE = "TOKENTYPE";
030:
031: public static final String LABEL_REGULARCARD = "LABEL_REGULARCARD";
032: public static final String LABEL_TEMPORARYCARD = "LABEL_TEMPORARYCARD";
033: public static final String LABEL_PROJECTCARD = "LABEL_PROJECTCARD";
034:
035: public static final String TOKENPROFILE = "TOKENPROFILE";
036: public static final String LABEL = "LABEL";
037:
038: protected boolean includePUK = true;
039:
040: // Public Constants.
041:
042: /* Constants used to define how the stored data should be represented in the web-gui.*/
043: public static final int INTEGER = 0;
044: public static final int LONG = 1;
045: public static final int STRING = 2;
046: public static final int BOOLEAN = 3;
047: public static final int DATE = 4;
048: public static final int EMPTYROW = 5;
049: public static final String EMPTYROW_FIELD = "EMTPYROW";
050:
051: public HardToken(boolean includePUK) {
052: this .includePUK = includePUK;
053: }
054:
055: // Public Methods
056: public Object getField(String field) {
057: return data.get(field);
058: }
059:
060: public abstract String[] getFields(boolean includePUK);
061:
062: public abstract int[] getDataTypes(boolean includePUK);
063:
064: public abstract String[] getFieldTexts(boolean includePUK);
065:
066: public int getNumberOfFields() {
067: return getFields(includePUK).length;
068: }
069:
070: public String getFieldText(int index) {
071: return getFieldTexts(includePUK)[index];
072: }
073:
074: public String getFieldPointer(int index) {
075: return getFields(includePUK)[index];
076: }
077:
078: public int getFieldDataType(int index) {
079: return getDataTypes(includePUK)[index];
080: }
081:
082: public void setField(String field, Object value) {
083: data.put(field, value);
084: }
085:
086: public int getTokenProfileId() {
087: if (data.get(HardToken.TOKENPROFILE) == null)
088: return 0;
089:
090: return ((Integer) data.get(HardToken.TOKENPROFILE)).intValue();
091: }
092:
093: public void setTokenProfileId(int hardtokenprofileid) {
094: data.put(HardToken.TOKENPROFILE,
095: new Integer(hardtokenprofileid));
096: }
097:
098: /**
099: *
100: * @return one of the LABEL_ constants or null of no label is set.
101: */
102: public String getLabel() {
103: return (String) data.get(HardToken.LABEL);
104: }
105:
106: /**
107: *
108: * @param hardTokenLabel should be one of the LABEL_ constants
109: */
110: public void setLabel(String hardTokenLabel) {
111: data.put(HardToken.LABEL, hardTokenLabel);
112: }
113:
114: /**
115: * Implemtation of UpgradableDataHashMap function getLatestVersion
116: *
117: */
118: public float getLatestVersion() {
119: return LATEST_VERSION;
120: }
121:
122: /**
123: * Implemtation of UpgradableDataHashMap function upgrade.
124: */
125: public void upgrade() {
126: }
127:
128: }
|