diff options
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/request')
10 files changed, 447 insertions, 449 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java b/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java index e7bc05f64..016e368c6 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java +++ b/pki/base/common/src/com/netscape/cmscore/request/ARequestQueue.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -62,31 +61,25 @@ import com.netscape.certsrv.request.PolicyResult; import com.netscape.certsrv.request.RequestId; import com.netscape.certsrv.request.RequestStatus; - /** * The ARequestQueue class is an abstract class that implements - * most portions of the IRequestQueue interface. This includes + * most portions of the IRequestQueue interface. This includes * the state engine as defined for processing IRequest objects. * <p> * !Put state machine description here! * <p> - * This class defines several abstract protected functions that - * need to be defined by the concrete implementation. In - * particular, this class does not implement the operations - * for storing requests persistantly. + * This class defines several abstract protected functions that need to be defined by the concrete implementation. In particular, this class does not implement the operations for storing requests persistantly. * <p> - * This class also provides several accessor functions for setting - * fields in the IRequest object. These functions are provided - * as an aid to saving and restoring the state in the database. + * This class also provides several accessor functions for setting fields in the IRequest object. These functions are provided as an aid to saving and restoring the state in the database. * <p> - * This class also implements the locking operations specified by - * the IRequestQueue interface. + * This class also implements the locking operations specified by the IRequestQueue interface. * <p> + * * @author thayes * @version $Revision$ $Date$ */ public abstract class ARequestQueue - implements IRequestQueue { + implements IRequestQueue { /** * global request version for tracking request changes. @@ -96,37 +89,33 @@ public abstract class ARequestQueue /** * Create a new (unique) RequestId. (abstract) * <p> - * This method must be implemented by the specialized class to - * generate a new id from data in the persistant store. This id - * is used to create a new request object. + * This method must be implemented by the specialized class to generate a new id from data in the persistant store. This id is used to create a new request object. * <p> + * * @return - * a new RequestId object. + * a new RequestId object. * @exception EBaseException - * indicates that creation of the new id could not be completed. + * indicates that creation of the new id could not be completed. * @see RequestId */ protected abstract RequestId newRequestId() - throws EBaseException; + throws EBaseException; /** * Read a request from the persistant store. (abstract) * <p> - * This function is called to create the in-memory version of - * a request object. + * This function is called to create the in-memory version of a request object. * <p> - * The implementation of this object can use the createRequest - * member function to create a new instance of an IRequest, and - * use the setRequestStatus, setCreationTime and setModificationTime - * functions to set those values. + * The implementation of this object can use the createRequest member function to create a new instance of an IRequest, and use the setRequestStatus, setCreationTime and setModificationTime functions to set those values. * <p> + * * @param id - * the id of the request to read. + * the id of the request to read. * @return - * a new IRequest object. null is returned if the object cannot - * be located. + * a new IRequest object. null is returned if the object cannot + * be located. * @exception EBaseException - * TODO: this is not implemented yet + * TODO: this is not implemented yet * @see #createRequest * @see #setRequestStatus * @see #setModificationTime @@ -137,28 +126,27 @@ public abstract class ARequestQueue /** * Add the request to the store. (abstract) * <p> - * This function is called when a new request immediately after - * creating a new request. + * This function is called when a new request immediately after creating a new request. * <p> + * * @param request - * the request to add. + * the request to add. * @exception EBaseException - * TODO: this is not implemented yet + * TODO: this is not implemented yet */ protected abstract void addRequest(IRequest request) throws EBaseException; /** * Modify the request in the store. (abstract) * <p> - * Update the persistant copy of this request with the - * current values in the object. + * Update the persistant copy of this request with the current values in the object. * <p> - * Currently there are no hints for what has changed, so - * the entire request should be updated. + * Currently there are no hints for what has changed, so the entire request should be updated. * <p> + * * @param request * @exception EBaseException - * TODO: this is not implemented yet + * TODO: this is not implemented yet */ protected abstract void modifyRequest(IRequest request); @@ -166,27 +154,24 @@ public abstract class ARequestQueue * Get complete list of RequestId values found i this * queue. * <p> - * This method can form the basis for creating other types - * of search/list operations (although there are probably more - * efficient ways of doing this. ARequestQueue implements - * default versions of some of the searching by using this - * method as a basis. + * This method can form the basis for creating other types of search/list operations (although there are probably more efficient ways of doing this. ARequestQueue implements default versions of some of the searching by using this method as a basis. * <p> - * TODO: return IRequestList -or- just use listRequests as - * the basic engine. + * TODO: return IRequestList -or- just use listRequests as the basic engine. * <p> + * * @return - * an Enumeration that generates RequestId objects. + * an Enumeration that generates RequestId objects. */ abstract protected Enumeration getRawList(); /** * protected access for setting the current state of a request. * <p> + * * @param request - * The request to be modified. + * The request to be modified. * @param status - * The new value for the request status. + * The new value for the request status. */ protected final void setRequestStatus(IRequest request, RequestStatus status) { Request r = (Request) request; @@ -197,10 +182,11 @@ public abstract class ARequestQueue /** * protected access for setting the modification time of a request. * <p> + * * @param request - * The request to be modified. + * The request to be modified. * @param date - * The new value for the time. + * The new value for the time. */ protected final void setModificationTime(IRequest request, Date date) { Request r = (Request) request; @@ -211,10 +197,11 @@ public abstract class ARequestQueue /** * protected access for setting the creation time of a request. * <p> + * * @param request - * The request to be modified. + * The request to be modified. * @param date - * The new value for the time. + * The new value for the time. */ protected final void setCreationTime(IRequest request, Date date) { Request r = (Request) request; @@ -225,11 +212,12 @@ public abstract class ARequestQueue /** * protected access for creating a new Request object * <p> + * * @param id - * The identifier for the new request + * The identifier for the new request * @return - * A new request object. The caller should fill in other data - * values from the datastore. + * A new request object. The caller should fill in other data + * values from the datastore. */ protected final IRequest createRequest(RequestId id, String requestType) { Request r; @@ -250,12 +238,13 @@ public abstract class ARequestQueue } /** - * Implements IRequestQueue.newRequest + * Implements IRequestQueue.newRequest * <p> + * * @see IRequestQueue#newRequest */ public IRequest newRequest(String requestType) - throws EBaseException { + throws EBaseException { if (requestType == null) { throw new EBaseException(CMS.getUserMessage("CMS_BASE_INVALID_REQUEST_TYPE", "null")); } @@ -287,16 +276,18 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.cloneRequest * <p> + * * @see IRequestQueue#cloneRequest */ - public IRequest cloneRequest(IRequest r) - throws EBaseException { + public IRequest cloneRequest(IRequest r) + throws EBaseException { // 1. check for valid state. (Are any invalid ?) RequestStatus rs = r.getRequestStatus(); - if (rs == RequestStatus.BEGIN) throw new EBaseException("Invalid Status"); + if (rs == RequestStatus.BEGIN) + throw new EBaseException("Invalid Status"); - // 2. create new request + // 2. create new request String reqType = r.getRequestType(); IRequest clone = newRequest(reqType); @@ -316,10 +307,11 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.findRequest * <p> + * * @see IRequestQueue#findRequest */ public IRequest findRequest(RequestId id) - throws EBaseException { + throws EBaseException { IRequest r; // mTable.lock(id); @@ -327,12 +319,12 @@ public abstract class ARequestQueue r = readRequest(id); // if (r == null) mTable.unlock(id); - + return r; } private IRequestScheduler mRequestScheduler = null; - + public void setRequestScheduler(IRequestScheduler scheduler) { mRequestScheduler = scheduler; } @@ -344,10 +336,11 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.processRequest * <p> + * * @see IRequestQueue#processRequest */ public final void processRequest(IRequest r) - throws EBaseException { + throws EBaseException { // #610553 Thread Scheduler IRequestScheduler scheduler = getRequestScheduler(); @@ -360,7 +353,8 @@ public abstract class ARequestQueue // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.BEGIN) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.BEGIN) + throw new EBaseException("Invalid Status"); stateEngine(r); } finally { @@ -373,19 +367,21 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.markRequestPending * <p> + * * @see IRequestQueue#markRequestPending */ public final void markRequestPending(IRequest r) - throws EBaseException { + throws EBaseException { // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.BEGIN) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.BEGIN) + throw new EBaseException("Invalid Status"); - // 2. Change the request state. This method of making - // a request PENDING does NOT invoke the PENDING notifiers. - // To change this, just call stateEngine at the completion of this - // routine. + // 2. Change the request state. This method of making + // a request PENDING does NOT invoke the PENDING notifiers. + // To change this, just call stateEngine at the completion of this + // routine. setRequestStatus(r, RequestStatus.PENDING); updateRequest(r); @@ -395,10 +391,11 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.cloneAndMarkPending * <p> + * * @see IRequestQueue#cloneAndMarkPending */ - public IRequest cloneAndMarkPending(IRequest r) - throws EBaseException { + public IRequest cloneAndMarkPending(IRequest r) + throws EBaseException { IRequest clone = cloneRequest(r); markRequestPending(clone); @@ -408,14 +405,16 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.approveRequest * <p> + * * @see IRequestQueue#approveRequest */ public final void approveRequest(IRequest r) - throws EBaseException { + throws EBaseException { // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.PENDING) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.PENDING) + throw new EBaseException("Invalid Status"); AgentApprovals aas = AgentApprovals.fromStringVector( r.getExtDataInStringVector(AgentApprovals.class.getName())); @@ -426,7 +425,8 @@ public abstract class ARequestQueue // Record agent who did this String agentName = getUserIdentity(); - if (agentName == null) throw new EBaseException("Missing agent information"); + if (agentName == null) + throw new EBaseException("Missing agent information"); aas.addApproval(agentName); r.setExtData(AgentApprovals.class.getName(), aas.toStringVector()); @@ -436,7 +436,7 @@ public abstract class ARequestQueue if (pr == PolicyResult.ACCEPTED) { setRequestStatus(r, RequestStatus.APPROVED); } else if (pr == PolicyResult.DEFERRED || - pr == PolicyResult.REJECTED) { + pr == PolicyResult.REJECTED) { } // Always update. The policy code may have made changes to the @@ -449,16 +449,18 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.rejectRequest * <p> + * * @see IRequestQueue#rejectRequest */ public final void rejectRequest(IRequest r) - throws EBaseException { + throws EBaseException { // 1. Check for valid state RequestStatus rs = r.getRequestStatus(); - if (rs != RequestStatus.PENDING) throw new EBaseException("Invalid Status"); + if (rs != RequestStatus.PENDING) + throw new EBaseException("Invalid Status"); - // 2. Change state + // 2. Change state setRequestStatus(r, RequestStatus.REJECTED); updateRequest(r); @@ -469,10 +471,11 @@ public abstract class ARequestQueue /** * Implments IRequestQueue.cancelRequest * <p> + * * @see IRequestQueue#cancelRequest */ public final void cancelRequest(IRequest r) - throws EBaseException { + throws EBaseException { setRequestStatus(r, RequestStatus.CANCELED); updateRequest(r); @@ -488,7 +491,8 @@ public abstract class ARequestQueue setRequestStatus(r, RequestStatus.COMPLETE); updateRequest(r); - if (mNotify != null) mNotify.notify(r); + if (mNotify != null) + mNotify.notify(r); return; } @@ -496,10 +500,9 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.listRequests * <p> - * Should be overridden by the specialized class if - * a more efficient method is available for implementing - * this operation. + * Should be overridden by the specialized class if a more efficient method is available for implementing this operation. * <P> + * * @see IRequestQueue#listRequests */ public IRequestList listRequests() { @@ -509,10 +512,9 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.listRequestsByStatus * <p> - * Should be overridden by the specialized class if - * a more efficient method is available for implementing - * this operation. + * Should be overridden by the specialized class if a more efficient method is available for implementing this operation. * <P> + * * @see IRequestQueue#listRequestsByStatus */ public IRequestList listRequestsByStatus(RequestStatus s) { @@ -522,6 +524,7 @@ public abstract class ARequestQueue /** * Implements IRequestQueue.releaseRequest * <p> + * * @see IRequestQueue#releaseRequest */ public final void releaseRequest(IRequest request) { @@ -533,17 +536,18 @@ public abstract class ARequestQueue String name = getUserIdentity(); - if (name != null) r.setExtData(IRequest.UPDATED_BY, name); + if (name != null) + r.setExtData(IRequest.UPDATED_BY, name); - // TODO: use a state flag to determine whether to call - // addRequest or modifyRequest (see newRequest as well) + // TODO: use a state flag to determine whether to call + // addRequest or modifyRequest (see newRequest as well) modifyRequest(r); } // PRIVATE functions private final void stateEngine(IRequest r) - throws EBaseException { + throws EBaseException { boolean complete = false; while (!complete) { @@ -643,14 +647,14 @@ public abstract class ARequestQueue */ public void recover() { if (CMS.isRunningMode()) { - RecoverThread t = new RecoverThread(this); + RecoverThread t = new RecoverThread(this); - t.start(); + t.start(); } } /** - * recover from a crash. Resends all requests that are in + * recover from a crash. Resends all requests that are in * the APPROVED state. */ public void recoverWillBlock() { @@ -684,7 +688,7 @@ public abstract class ARequestQueue // Constructor protected ARequestQueue(IPolicy policy, IService service, INotify notify, - INotify pendingNotify) { + INotify pendingNotify) { mPolicy = policy; mService = service; mNotify = notify; @@ -704,7 +708,6 @@ public abstract class ARequestQueue protected ILogger mLogger; } - // // Table of RequestId values that are currently in use by some thread. // The fact that the request is in this table constitutes a lock @@ -735,13 +738,12 @@ public abstract class ARequestQueue } */ - // // Request - implementation of the IRequest interface. This // version is returned by ARequestQueue (and its derivatives) // class Request - implements IRequest { + implements IRequest { // IRequest.getRequestId public RequestId getRequestId() { return mRequestId; @@ -834,8 +836,8 @@ class Request while (e.hasMoreElements()) { String key = (String) e.nextElement(); if (!key.equals(IRequest.ISSUED_CERTS) && - !key.equals(IRequest.ERRORS) && - !key.equals(IRequest.REMOTE_REQID)) { + !key.equals(IRequest.ERRORS) && + !key.equals(IRequest.REMOTE_REQID)) { if (req.isSimpleExtDataValue(key)) { setExtData(key, req.getExtDataInString(key)); } else { @@ -847,15 +849,15 @@ class Request /** * This function used to check that the keys obeyed LDAP attribute name - * syntax rules. Keys are being encoded now, so it is changed to just + * syntax rules. Keys are being encoded now, so it is changed to just * filter out null and empty string keys. - * - * @param key The key to check - * @return false if invalid + * + * @param key The key to check + * @return false if invalid */ protected boolean isValidExtDataKey(String key) { return key != null && - (! key.equals("")); + (!key.equals("")); } protected boolean isValidExtDataHashtableValue(Hashtable<String, String> hash) { @@ -865,13 +867,12 @@ class Request Enumeration<String> keys = hash.keys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); - if (! ((key instanceof String) && - isValidExtDataKey((String)key)) ) { + if (!((key instanceof String) && isValidExtDataKey((String) key))) { return false; } Object value = hash.get(key); - if (! (value instanceof String)) { + if (!(value instanceof String)) { return false; } } @@ -880,7 +881,7 @@ class Request } public boolean setExtData(String key, String value) { - if (! isValidExtDataKey(key)) { + if (!isValidExtDataKey(key)) { return false; } if (value == null) { @@ -892,7 +893,7 @@ class Request } public boolean setExtData(String key, Hashtable value) { - if ( !(isValidExtDataKey(key) && isValidExtDataHashtableValue(value)) ) { + if (!(isValidExtDataKey(key) && isValidExtDataHashtableValue(value))) { return false; } @@ -909,10 +910,10 @@ class Request if (value == null) { return null; } - if (! (value instanceof String)) { + if (!(value instanceof String)) { return null; } - return (String)value; + return (String) value; } public Hashtable getExtDataInHashtable(String key) { @@ -920,10 +921,10 @@ class Request if (value == null) { return null; } - if (! (value instanceof Hashtable)) { + if (!(value instanceof Hashtable)) { return null; } - return new ExtDataHashtable((Hashtable)value); + return new ExtDataHashtable((Hashtable) value); } public Enumeration getExtDataKeys() { @@ -935,7 +936,7 @@ class Request } public boolean setExtData(String key, String subkey, String value) { - if (! (isValidExtDataKey(key) && isValidExtDataKey(subkey)) ) { + if (!(isValidExtDataKey(key) && isValidExtDataKey(subkey))) { return false; } if (isSimpleExtDataValue(key)) { @@ -945,7 +946,7 @@ class Request return false; } - Hashtable existingValue = (Hashtable)mExtData.get(key); + Hashtable existingValue = (Hashtable) mExtData.get(key); if (existingValue == null) { existingValue = new ExtDataHashtable(); mExtData.put(key, existingValue); @@ -959,7 +960,7 @@ class Request if (value == null) { return null; } - return (String)value.get(subkey); + return (String) value.get(subkey); } public boolean setExtData(String key, Integer value) { @@ -1223,7 +1224,7 @@ class Request return false; } try { - stringArray = (String[])stringVector.toArray(new String[0]); + stringArray = (String[]) stringVector.toArray(new String[0]); } catch (ArrayStoreException e) { return false; } @@ -1374,7 +1375,7 @@ class Request Set arrayKeys = hashValue.keySet(); Vector listValue = new Vector(arrayKeys.size()); for (Iterator iter = arrayKeys.iterator(); iter.hasNext();) { - String arrayKey = (String)iter.next(); + String arrayKey = (String) iter.next(); try { index = Integer.parseInt(arrayKey); } catch (NumberFormatException e) { @@ -1386,7 +1387,7 @@ class Request listValue.set(index, hashValue.get(arrayKey)); } - return (String[])listValue.toArray(new String[0]); + return (String[]) listValue.toArray(new String[0]); } public IAttrSet asIAttrSet() { @@ -1425,7 +1426,7 @@ class RequestIAttrSetWrapper implements IAttrSet { public void set(String name, Object obj) throws EBaseException { try { - mRequest.setExtData(name, (String)obj); + mRequest.setExtData(name, (String) obj); } catch (ClassCastException e) { throw new EBaseException(e.toString()); } @@ -1444,21 +1445,19 @@ class RequestIAttrSetWrapper implements IAttrSet { } } - /** * Example of a specialized request class. */ class EnrollmentRequest - extends Request - implements IEnrollmentRequest { + extends Request + implements IEnrollmentRequest { EnrollmentRequest(RequestId id) { super(id); } } - class RequestListByStatus - implements IRequestList { + implements IRequestList { public boolean hasMoreElements() { return (mNext != null); } @@ -1501,14 +1500,16 @@ class RequestListByStatus mNext = null; while (mNext == null) { - if (!mEnumeration.hasMoreElements()) break; - + if (!mEnumeration.hasMoreElements()) + break; + rId = (RequestId) mEnumeration.nextElement(); try { IRequest r = mQueue.findRequest(rId); - if (r.getRequestStatus() == mStatus) mNext = rId; + if (r.getRequestStatus() == mStatus) + mNext = rId; mQueue.releaseRequest(r); } catch (Exception e) { @@ -1518,13 +1519,12 @@ class RequestListByStatus protected RequestStatus mStatus; protected IRequestQueue mQueue; - protected Enumeration mEnumeration; + protected Enumeration mEnumeration; protected RequestId mNext; } - class RequestList - implements IRequestList { + implements IRequestList { public boolean hasMoreElements() { return mEnumeration.hasMoreElements(); } @@ -1549,10 +1549,9 @@ class RequestList mEnumeration = e; } - protected Enumeration mEnumeration; + protected Enumeration mEnumeration; } - class RecoverThread extends Thread { private ARequestQueue mQ = null; diff --git a/pki/base/common/src/com/netscape/cmscore/request/ARequestRecord.java b/pki/base/common/src/com/netscape/cmscore/request/ARequestRecord.java index f85beca0a..002ffd7b3 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/ARequestRecord.java +++ b/pki/base/common/src/com/netscape/cmscore/request/ARequestRecord.java @@ -17,22 +17,20 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import java.util.Date; import java.util.Hashtable; import com.netscape.certsrv.request.RequestId; import com.netscape.certsrv.request.RequestStatus; - /** * The low level (attributes only) version of the database - * record object. This exists so that RecordAttr methods can use - * this type definition, + * record object. This exists so that RecordAttr methods can use + * this type definition, * * RequestRecord refers both to this class and to RecordAttr objects. */ -class ARequestRecord { +class ARequestRecord { RequestId mRequestId; RequestStatus mRequestState; Date mCreateTime; diff --git a/pki/base/common/src/com/netscape/cmscore/request/CertRequestConstants.java b/pki/base/common/src/com/netscape/cmscore/request/CertRequestConstants.java index 7494b5e48..eab41fcd5 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/CertRequestConstants.java +++ b/pki/base/common/src/com/netscape/cmscore/request/CertRequestConstants.java @@ -17,9 +17,8 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - /** - * temporary location for cert request constants. + * temporary location for cert request constants. * XXX we really need to centralize all these but for now they are here * as needed. */ diff --git a/pki/base/common/src/com/netscape/cmscore/request/ExtDataHashtable.java b/pki/base/common/src/com/netscape/cmscore/request/ExtDataHashtable.java index 415908dc3..f21503a21 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/ExtDataHashtable.java +++ b/pki/base/common/src/com/netscape/cmscore/request/ExtDataHashtable.java @@ -6,7 +6,7 @@ import java.util.Map; import java.util.Set; /** - * Subclass of Hashtable returned by IRequest.getExtDataInHashtable. Its + * Subclass of Hashtable returned by IRequest.getExtDataInHashtable. Its * purpose is to hide the fact that LDAP doesn't preserve the case of keys. * It does this by lowercasing all keys used to access the Hashtable. */ @@ -38,7 +38,7 @@ public class ExtDataHashtable extends Hashtable { public boolean containsKey(Object o) { if (o instanceof String) { - String key = (String)o; + String key = (String) o; return super.containsKey(key.toLowerCase()); } return super.containsKey(o); @@ -46,7 +46,7 @@ public class ExtDataHashtable extends Hashtable { public Object get(Object o) { if (o instanceof String) { - String key = (String)o; + String key = (String) o; return super.get(key.toLowerCase()); } return super.get(o); @@ -54,7 +54,7 @@ public class ExtDataHashtable extends Hashtable { public Object put(Object oKey, Object val) { if (oKey instanceof String) { - String key = (String)oKey; + String key = (String) oKey; return super.put(key.toLowerCase(), val); } return super.put(oKey, val); @@ -62,8 +62,7 @@ public class ExtDataHashtable extends Hashtable { public void putAll(Map map) { Set keys = map.keySet(); - for (Iterator i = keys.iterator(); - i.hasNext();) { + for (Iterator i = keys.iterator(); i.hasNext();) { Object key = i.next(); put(key, map.get(key)); } @@ -71,7 +70,7 @@ public class ExtDataHashtable extends Hashtable { public Object remove(Object o) { if (o instanceof String) { - String key = (String)o; + String key = (String) o; return super.remove(key.toLowerCase()); } return super.remove(o); diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestAttr.java b/pki/base/common/src/com/netscape/cmscore/request/RequestAttr.java index 4583a1fac..25734c91e 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestAttr.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestAttr.java @@ -17,28 +17,26 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import com.netscape.certsrv.dbs.IDBAttrMapper; import com.netscape.certsrv.dbs.Modification; import com.netscape.certsrv.dbs.ModificationSet; import com.netscape.certsrv.request.IRequest; import com.netscape.certsrv.request.ldap.IRequestMod; - /** * The RequestAttr class defines the methods used * to transfer data between the various representations of - * a request. The three forms are: - * 1) LDAPAttributes (and Modifications) - * 2) Database record IDBAttrSet - * 3) IRequest (Request) object + * a request. The three forms are: + * 1) LDAPAttributes (and Modifications) + * 2) Database record IDBAttrSet + * 3) IRequest (Request) object */ abstract class RequestAttr { /** * */ - + abstract void set(ARequestRecord r, Object o); abstract Object get(ARequestRecord r); diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java index b748f23bb..b1b4fb04f 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestQueue.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import java.math.BigInteger; import java.util.Date; import java.util.Enumeration; @@ -43,13 +42,12 @@ import com.netscape.certsrv.request.ldap.IRequestMod; import com.netscape.cmscore.dbs.DBSubsystem; import com.netscape.cmscore.util.Debug; - public class RequestQueue - extends ARequestQueue - implements IRequestMod { + extends ARequestQueue + implements IRequestMod { // ARequestQueue.newRequestId protected RequestId newRequestId() - throws EBaseException { + throws EBaseException { // get the next request Id BigInteger next = mRepository.getNextSerialNumber(); @@ -63,7 +61,7 @@ public class RequestQueue // String name = Schema.LDAP_ATTR_REQUEST_ID + "=" + String name = "cn" + "=" + - id + "," + mBaseDN; + id + "," + mBaseDN; Object obj = null; IDBSSession dbs = null; @@ -71,19 +69,21 @@ public class RequestQueue try { dbs = mDB.createSession(); obj = dbs.read(name); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } // TODO Errors!!! - if (obj == null || !(obj instanceof RequestRecord)) return null; + if (obj == null || !(obj instanceof RequestRecord)) + return null; record = (RequestRecord) obj; @@ -107,20 +107,21 @@ public class RequestQueue // compute the name of the object // String name = Schema.LDAP_ATTR_REQUEST_ID + "=" + String name = "cn" + "=" + - record.mRequestId + "," + mBaseDN; + record.mRequestId + "," + mBaseDN; IDBSSession dbs = null; try { dbs = mDB.createSession(); dbs.add(name, record); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); throw e; } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } @@ -170,19 +171,20 @@ public class RequestQueue // String name = Schema.LDAP_ATTR_REQUEST_ID + "=" + String name = "cn" + "=" + - r.getRequestId() + "," + mBaseDN; + r.getRequestId() + "," + mBaseDN; IDBSSession dbs = null; try { dbs = mDB.createSession(); dbs.modify(name, mods); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } @@ -218,34 +220,30 @@ public class RequestQueue /** * Resets serial number. */ - public void resetSerialNumber(BigInteger serial) throws EBaseException - { + public void resetSerialNumber(BigInteger serial) throws EBaseException { mRepository.resetSerialNumber(serial); } - + /** * Removes all objects with this repository. */ - public void removeAllObjects() throws EBaseException - { + public void removeAllObjects() throws EBaseException { mRepository.removeAllObjects(); } - public BigInteger getLastRequestIdInRange(BigInteger reqId_low_bound, BigInteger reqId_upper_bound) - { + public BigInteger getLastRequestIdInRange(BigInteger reqId_low_bound, BigInteger reqId_upper_bound) { CMS.debug("RequestQueue: getLastRequestId: low " + reqId_low_bound + " high " + reqId_upper_bound); - if(reqId_low_bound == null || reqId_upper_bound == null || reqId_low_bound.compareTo(reqId_upper_bound) >= 0) - { + if (reqId_low_bound == null || reqId_upper_bound == null || reqId_low_bound.compareTo(reqId_upper_bound) >= 0) { CMS.debug("RequestQueue: getLastRequestId: bad upper and lower bound range."); return null; } - String filter = "(" + "requeststate" + "=*" + ")"; + String filter = "(" + "requeststate" + "=*" + ")"; RequestId fromId = new RequestId(reqId_upper_bound.toString(10)); CMS.debug("RequestQueue: getLastRequestId: filter " + filter + " fromId " + fromId); - ListEnumeration recList = (ListEnumeration) getPagedRequestsByFilter(fromId,filter,5 * -1,"requestId"); + ListEnumeration recList = (ListEnumeration) getPagedRequestsByFilter(fromId, filter, 5 * -1, "requestId"); int size = recList.getSize(); @@ -272,33 +270,29 @@ public class RequestQueue String reqId = null; - for(int i = 0; i < 5; i++) - { - curRec = recList.getElementAt(i); - - if(curRec != null) { + for (int i = 0; i < 5; i++) { + curRec = recList.getElementAt(i); - curId = curRec.getRequestId(); + if (curRec != null) { - reqId = curId.toString(); + curId = curRec.getRequestId(); - CMS.debug("RequestQueue: curReqId: " + reqId); + reqId = curId.toString(); - BigInteger curIdInt = new BigInteger(reqId); + CMS.debug("RequestQueue: curReqId: " + reqId); + BigInteger curIdInt = new BigInteger(reqId); - if( ((curIdInt.compareTo(reqId_low_bound) == 0) || (curIdInt.compareTo(reqId_low_bound) == 1) ) && - ((curIdInt.compareTo(reqId_upper_bound) == 0) || (curIdInt.compareTo(reqId_upper_bound) == -1) )) - { - CMS.debug("RequestQueue: getLastRequestId : returning value " + curIdInt); - return curIdInt; - } + if (((curIdInt.compareTo(reqId_low_bound) == 0) || (curIdInt.compareTo(reqId_low_bound) == 1)) && + ((curIdInt.compareTo(reqId_upper_bound) == 0) || (curIdInt.compareTo(reqId_upper_bound) == -1))) { + CMS.debug("RequestQueue: getLastRequestId : returning value " + curIdInt); + return curIdInt; + } - } + } } - BigInteger ret = new BigInteger(reqId_low_bound.toString(10)); ret = ret.add(new BigInteger("-1")); @@ -311,12 +305,14 @@ public class RequestQueue /** * Implements IRequestQueue.findRequestBySourceId * <p> + * * @see com.netscape.certsrv.request.IRequestQueue#findRequestBySourceId */ public RequestId findRequestBySourceId(String id) { IRequestList irl = findRequestsBySourceId(id); - if (irl == null) return null; + if (irl == null) + return null; return irl.nextRequestId(); } @@ -324,6 +320,7 @@ public class RequestQueue /** * Implements IRequestQueue.findRequestsBySourceId * <p> + * * @see com.netscape.certsrv.request.IRequestQueue#findRequestsBySourceId */ public IRequestList findRequestsBySourceId(String id) { @@ -343,13 +340,15 @@ public class RequestQueue Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null || !results.hasMoreElements()) return null; + if (results == null || !results.hasMoreElements()) + return null; return new SearchEnumeration(this, results); @@ -363,18 +362,20 @@ public class RequestQueue try { dbs = mDB.createSession(); results = dbs.search(mBaseDN, "(requestId=*)"); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -389,18 +390,20 @@ public class RequestQueue try { dbs = mDB.createSession(); results = dbs.search(mBaseDN, f); - } catch (EBaseException e) { - Debug.trace("Error: " + e); + } catch (EBaseException e) { + Debug.trace("Error: " + e); Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -411,7 +414,7 @@ public class RequestQueue IDBSearchResults results = null; IDBSSession dbs = null; String attrs[] = { IRequestRecord.ATTR_REQUEST_ID }; - + try { dbs = mDB.createSession(); results = dbs.search(mBaseDN, f, maxSize); @@ -420,14 +423,16 @@ public class RequestQueue Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - - if (results == null) return null; - + + if (results == null) + return null; + return new SearchEnumeration(this, results); } @@ -446,13 +451,15 @@ public class RequestQueue Debug.printStackTrace(e); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -473,18 +480,20 @@ public class RequestQueue dbs = mDB.createSession(); results = dbs.search(mBaseDN, f1); - } catch (EBaseException e) { + } catch (EBaseException e) { //System.err.println("Error: "+e); //e.printStackTrace(); } finally { // Close session - ignoring errors (UTIL) - if (dbs != null) try { + if (dbs != null) + try { dbs.close(); } catch (EBaseException e) { } } - if (results == null) return null; + if (results == null) + return null; return new SearchEnumeration(this, results); } @@ -500,19 +509,19 @@ public class RequestQueue * Implements IRequestQueue.getPagedRequestsByFilter */ public IRequestVirtualList - getPagedRequestsByFilter(String filter, int pageSize, String sortKey) { + getPagedRequestsByFilter(String filter, int pageSize, String sortKey) { return getPagedRequestsByFilter(null, filter, pageSize, sortKey); } public IRequestVirtualList - getPagedRequestsByFilter(RequestId from, String filter, int pageSize, - String sortKey) { - return getPagedRequestsByFilter(from, false, filter, pageSize, sortKey); + getPagedRequestsByFilter(RequestId from, String filter, int pageSize, + String sortKey) { + return getPagedRequestsByFilter(from, false, filter, pageSize, sortKey); } public IRequestVirtualList - getPagedRequestsByFilter(RequestId from, boolean jumpToEnd, String filter, int pageSize, - String sortKey) { + getPagedRequestsByFilter(RequestId from, boolean jumpToEnd, String filter, int pageSize, + String sortKey) { IDBVirtualList results = null; IDBSSession dbs = null; @@ -525,24 +534,24 @@ public class RequestQueue try { if (from == null) { - results = dbs.createVirtualList(mBaseDN, filter, (String[]) null, + results = dbs.createVirtualList(mBaseDN, filter, (String[]) null, sortKey, pageSize); } else { int len = from.toString().length(); String internalRequestId = null; if (jumpToEnd) { - internalRequestId ="99"; - } else { - if (len > 9) { - internalRequestId = Integer.toString(len) + from.toString(); + internalRequestId = "99"; } else { - internalRequestId = "0" + Integer.toString(len) + - from.toString(); + if (len > 9) { + internalRequestId = Integer.toString(len) + from.toString(); + } else { + internalRequestId = "0" + Integer.toString(len) + + from.toString(); + } } - } - results = dbs.createVirtualList(mBaseDN, filter, (String[]) null, + results = dbs.createVirtualList(mBaseDN, filter, (String[]) null, internalRequestId, sortKey, pageSize); } } catch (EBaseException e) { @@ -565,14 +574,14 @@ public class RequestQueue } public RequestQueue(String name, int increment, IPolicy p, IService s, INotify n, - INotify pendingNotify) - throws EBaseException { + INotify pendingNotify) + throws EBaseException { super(p, s, n, pendingNotify); mDB = DBSubsystem.getInstance(); mBaseDN = "ou=" + name + ",ou=requests," + mDB.getBaseDN(); - mRepository = new RequestRepository(name, increment, mDB,this); + mRepository = new RequestRepository(name, increment, mDB, this); } @@ -592,7 +601,7 @@ public class RequestQueue /* * return request repository - */ + */ public IRepository getRequestRepository() { return (IRepository) mRepository; } @@ -610,15 +619,15 @@ public class RequestQueue protected RequestRepository mRepository; } - class SearchEnumeration - implements IRequestList { + implements IRequestList { public RequestId nextRequestId() { Object obj; obj = mResults.nextElement(); - if (obj == null || !(obj instanceof RequestRecord)) return null; + if (obj == null || !(obj instanceof RequestRecord)) + return null; RequestRecord r = (RequestRecord) obj; @@ -647,7 +656,8 @@ class SearchEnumeration obj = mResults.nextElement(); - if (obj == null || !(obj instanceof RequestRecord)) return null; + if (obj == null || !(obj instanceof RequestRecord)) + return null; RequestRecord r = (RequestRecord) obj; @@ -655,7 +665,7 @@ class SearchEnumeration } public IRequest nextRequestObject() { - RequestRecord record = (RequestRecord)nextRequest(); + RequestRecord record = (RequestRecord) nextRequest(); if (record != null) return mQueue.makeRequest(record); return null; @@ -665,13 +675,13 @@ class SearchEnumeration protected RequestQueue mQueue; } - class ListEnumeration - implements IRequestVirtualList { + implements IRequestVirtualList { public IRequest getElementAt(int i) { RequestRecord record = (RequestRecord) mList.getElementAt(i); - if (record == null) return null; + if (record == null) + return null; return mQueue.makeRequest(record); } @@ -693,6 +703,7 @@ class ListEnumeration return mList.getSizeAfterJumpTo(); } + ListEnumeration(RequestQueue queue, IDBVirtualList list) { mQueue = queue; mList = list; diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestRecord.java b/pki/base/common/src/com/netscape/cmscore/request/RequestRecord.java index 321e32ec2..a3637758f 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestRecord.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestRecord.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -53,15 +52,14 @@ import com.netscape.cmscore.dbs.DateMapper; import com.netscape.cmscore.dbs.StringMapper; import com.netscape.cmscore.util.Debug; - // // A request record is the stored version of a request. // It has a set of attributes that are mapped into LDAP // attributes for actual directory operations. // public class RequestRecord - extends ARequestRecord - implements IRequestRecord, IDBObj { + extends ARequestRecord + implements IRequestRecord, IDBObj { /** * */ @@ -96,7 +94,8 @@ public class RequestRecord else { RequestAttr ra = (RequestAttr) mAttrTable.get(name); - if (ra != null) return ra.get(this); + if (ra != null) + return ra.get(this); } return null; @@ -104,7 +103,7 @@ public class RequestRecord // IDBObj.set @SuppressWarnings("unchecked") - public void set(String name, Object o) { + public void set(String name, Object o) { if (name.equals(IRequestRecord.ATTR_REQUEST_ID)) mRequestId = (RequestId) o; else if (name.equals(IRequestRecord.ATTR_REQUEST_STATE)) @@ -120,17 +119,18 @@ public class RequestRecord else if (name.equals(IRequestRecord.ATTR_REQUEST_OWNER)) mOwner = (String) o; else if (name.equals(IRequestRecord.ATTR_EXT_DATA)) - mExtData = (Hashtable)o; + mExtData = (Hashtable) o; else { RequestAttr ra = (RequestAttr) mAttrTable.get(name); - if (ra != null) ra.set(this, o); + if (ra != null) + ra.set(this, o); } } // IDBObj.delete public void delete(String name) - throws EBaseException { + throws EBaseException { throw new EBaseException("Invalid call to delete"); } @@ -177,19 +177,19 @@ public class RequestRecord static void mod(ModificationSet mods, IRequest r) throws EBaseException { // mods.add(IRequestRecord.ATTR_REQUEST_STATE, - Modification.MOD_REPLACE, r.getRequestStatus()); + Modification.MOD_REPLACE, r.getRequestStatus()); mods.add(IRequestRecord.ATTR_SOURCE_ID, - Modification.MOD_REPLACE, r.getSourceId()); + Modification.MOD_REPLACE, r.getSourceId()); mods.add(IRequestRecord.ATTR_REQUEST_OWNER, - Modification.MOD_REPLACE, r.getRequestOwner()); + Modification.MOD_REPLACE, r.getRequestOwner()); mods.add(IRequestRecord.ATTR_MODIFY_TIME, - Modification.MOD_REPLACE, r.getModificationTime()); + Modification.MOD_REPLACE, r.getModificationTime()); mods.add(IRequestRecord.ATTR_EXT_DATA, - Modification.MOD_REPLACE, loadExtDataFromRequest(r)); + Modification.MOD_REPLACE, loadExtDataFromRequest(r)); for (int i = 0; i < mRequestA.length; i++) { mRequestA[i].mod(mods, r); @@ -197,7 +197,7 @@ public class RequestRecord } static void register(IDBSubsystem db) - throws EDBException { + throws EDBException { IDBRegistry reg = db.getRegistry(); reg.registerObjectClass(RequestRecord.class.getName(), mOC); @@ -205,13 +205,13 @@ public class RequestRecord reg.registerAttribute(IRequestRecord.ATTR_REQUEST_ID, new RequestIdMapper()); reg.registerAttribute(IRequestRecord.ATTR_REQUEST_STATE, new RequestStateMapper()); reg.registerAttribute(IRequestRecord.ATTR_CREATE_TIME, - new DateMapper(Schema.LDAP_ATTR_CREATE_TIME)); + new DateMapper(Schema.LDAP_ATTR_CREATE_TIME)); reg.registerAttribute(IRequestRecord.ATTR_MODIFY_TIME, - new DateMapper(Schema.LDAP_ATTR_MODIFY_TIME)); + new DateMapper(Schema.LDAP_ATTR_MODIFY_TIME)); reg.registerAttribute(IRequestRecord.ATTR_SOURCE_ID, - new StringMapper(Schema.LDAP_ATTR_SOURCE_ID)); + new StringMapper(Schema.LDAP_ATTR_SOURCE_ID)); reg.registerAttribute(IRequestRecord.ATTR_REQUEST_OWNER, - new StringMapper(Schema.LDAP_ATTR_REQUEST_OWNER)); + new StringMapper(Schema.LDAP_ATTR_REQUEST_OWNER)); ExtAttrDynMapper extAttrMapper = new ExtAttrDynMapper(); reg.registerAttribute(IRequestRecord.ATTR_EXT_DATA, extAttrMapper); reg.registerDynamicMapper(extAttrMapper); @@ -248,9 +248,9 @@ public class RequestRecord String key = (String) e.nextElement(); Object value = mExtData.get(key); if (value instanceof String) { - r.setExtData(key, (String)value); + r.setExtData(key, (String) value); } else if (value instanceof Hashtable) { - r.setExtData(key, (Hashtable)value); + r.setExtData(key, (Hashtable) value); } else { throw new EDBException("Illegal data value in RequestRecord: " + r.toString()); @@ -273,30 +273,30 @@ public class RequestRecord */ static RequestAttr mRequestA[] = { - new RequestAttr(IRequest.ATTR_REQUEST_TYPE, + new RequestAttr(IRequest.ATTR_REQUEST_TYPE, new StringMapper(Schema.LDAP_ATTR_REQUEST_TYPE)) { - void set(ARequestRecord r, Object o) { - r.mRequestType = (String) o; - } - - Object get(ARequestRecord r) { - return r.mRequestType; - } - - void read(IRequestMod a, IRequest r, ARequestRecord rr) { - r.setRequestType(rr.mRequestType); - } - - void add(IRequest r, ARequestRecord rr) { - rr.mRequestType = r.getRequestType(); - } - - void mod(ModificationSet mods, IRequest r) { - addmod(mods, r.getRequestType()); - } - } + void set(ARequestRecord r, Object o) { + r.mRequestType = (String) o; + } + + Object get(ARequestRecord r) { + return r.mRequestType; + } + + void read(IRequestMod a, IRequest r, ARequestRecord rr) { + r.setRequestType(rr.mRequestType); + } + + void add(IRequest r, ARequestRecord rr) { + rr.mRequestType = r.getRequestType(); + } + + void mod(ModificationSet mods, IRequest r) { + addmod(mods, r.getRequestType()); + } + } - }; + }; static { mAttrs.add(IRequestRecord.ATTR_REQUEST_ID); mAttrs.add(IRequestRecord.ATTR_REQUEST_STATE); @@ -316,7 +316,6 @@ public class RequestRecord } - // // A mapper between an request state object and // its LDAP attribute representation @@ -326,7 +325,7 @@ public class RequestRecord // @version $Revision$ $Date$ // class RequestStateMapper - implements IDBAttrMapper { + implements IDBAttrMapper { // IDBAttrMapper methods // @@ -337,7 +336,7 @@ class RequestStateMapper // public void mapObjectToLDAPAttributeSet(IDBObj parent, - String name, Object obj, LDAPAttributeSet attrs) { + String name, Object obj, LDAPAttributeSet attrs) { RequestStatus rs = (RequestStatus) obj; attrs.add(new LDAPAttribute(Schema.LDAP_ATTR_REQUEST_STATE, @@ -345,11 +344,12 @@ class RequestStateMapper } public void mapLDAPAttributeSetToObject(LDAPAttributeSet attrs, - String name, IDBObj parent) - throws EBaseException { + String name, IDBObj parent) + throws EBaseException { LDAPAttribute attr = attrs.getAttribute(Schema.LDAP_ATTR_REQUEST_STATE); - if (attr == null) throw new EBaseException("schema violation"); + if (attr == null) + throw new EBaseException("schema violation"); String value = (String) attr.getStringValues().nextElement(); @@ -367,7 +367,6 @@ class RequestStateMapper } } - // // A mapper between an request id object and // its LDAP attribute representation @@ -377,7 +376,7 @@ class RequestStateMapper // @version $Revision$ $Date$ // class RequestIdMapper - implements IDBAttrMapper { + implements IDBAttrMapper { // IDBAttrMapper methods // @@ -388,7 +387,7 @@ class RequestIdMapper // public void mapObjectToLDAPAttributeSet(IDBObj parent, - String name, Object obj, LDAPAttributeSet attrs) { + String name, Object obj, LDAPAttributeSet attrs) { RequestId rid = (RequestId) obj; String v = BigIntegerMapper.BigIntegerToDB(new BigInteger(rid.toString())); @@ -397,11 +396,12 @@ class RequestIdMapper } public void mapLDAPAttributeSetToObject(LDAPAttributeSet attrs, - String name, IDBObj parent) - throws EBaseException { + String name, IDBObj parent) + throws EBaseException { LDAPAttribute attr = attrs.getAttribute(Schema.LDAP_ATTR_REQUEST_ID); - if (attr == null) throw new EBaseException("schema violation"); + if (attr == null) + throw new EBaseException("schema violation"); String value = (String) attr.getStringValues().nextElement(); @@ -427,19 +427,18 @@ class RequestIdMapper } } - /** * A mapper between an request attr set and its LDAP attribute representation. - * - * The attr attribute is no longer used. This class is kept for historical + * + * The attr attribute is no longer used. This class is kept for historical * and migration purposes. - * + * * @author thayes * @version $Revision$ $Date$ * @deprecated */ class RequestAttrsMapper - implements IDBAttrMapper { + implements IDBAttrMapper { // IDBAttrMapper methods // @@ -450,8 +449,8 @@ class RequestAttrsMapper // public void mapObjectToLDAPAttributeSet(IDBObj parent, - String name, Object obj, LDAPAttributeSet attrs) { - Hashtable ht = (Hashtable) obj; + String name, Object obj, LDAPAttributeSet attrs) { + Hashtable ht = (Hashtable) obj; Enumeration e = ht.keys(); try { @@ -473,13 +472,13 @@ class RequestAttrsMapper } catch (NotSerializableException x) { if (Debug.ON) { System.err.println("Error: attribute '" + key + "' (" + - x.getMessage() + ") is not serializable"); + x.getMessage() + ") is not serializable"); x.printStackTrace(); } } catch (Exception x) { if (Debug.ON) { System.err.println("Error: attribute '" + key + - "' - error during serialization: " + x); + "' - error during serialization: " + x); x.printStackTrace(); } } @@ -490,9 +489,9 @@ class RequestAttrsMapper attrs.add(new LDAPAttribute(Schema.LDAP_ATTR_REQUEST_ATTRS, bos.toByteArray())); - } catch (Exception x) { + } catch (Exception x) { Debug.trace("Output Mapping Error in requeset ID " + - ((RequestRecord) parent).getRequestId().toString() + " : " + x); + ((RequestRecord) parent).getRequestId().toString() + " : " + x); //if (Debug.ON) { Debug.printStackTrace(x); //} @@ -500,7 +499,7 @@ class RequestAttrsMapper } private byte[] encode(Object value) - throws NotSerializableException, IOException { + throws NotSerializableException, IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream os = new ObjectOutputStream(bos); @@ -511,7 +510,7 @@ class RequestAttrsMapper } private Object decode(byte[] data) - throws ObjectStreamException, IOException, ClassNotFoundException { + throws ObjectStreamException, IOException, ClassNotFoundException { ByteArrayInputStream bis = new ByteArrayInputStream(data); ObjectInputStream is = new ObjectInputStream(bis); @@ -519,7 +518,7 @@ class RequestAttrsMapper } private Hashtable decodeHashtable(byte[] data) - throws ObjectStreamException, IOException, ClassNotFoundException { + throws ObjectStreamException, IOException, ClassNotFoundException { Hashtable ht = new Hashtable(); ByteArrayInputStream bis = new ByteArrayInputStream(data); ObjectInputStream is = new ObjectInputStream(bis); @@ -530,22 +529,23 @@ class RequestAttrsMapper while (true) { key = (String) is.readObject(); - + // end of table is marked with null - if (key == null) break; + if (key == null) + break; byte[] bytes = (byte[]) is.readObject(); ht.put(key, decode(bytes)); } } catch (ObjectStreamException e) { - Debug.trace("Key " + key); // would be nice to know object type. + Debug.trace("Key " + key); // would be nice to know object type. throw e; } catch (IOException e) { - Debug.trace("Key " + key); // would be nice to know object type. + Debug.trace("Key " + key); // would be nice to know object type. throw e; } catch (ClassNotFoundException e) { - Debug.trace("Key " + key); // would be nice to know object type. + Debug.trace("Key " + key); // would be nice to know object type. throw e; } @@ -555,11 +555,12 @@ class RequestAttrsMapper /** * Implements IDBAttrMapper.mapLDAPAttributeSetToObject * <p> + * * @see IDBAttrMapper#mapLDAPAttributeSetToObject */ public void mapLDAPAttributeSetToObject(LDAPAttributeSet attrs, - String name, IDBObj parent) - throws EBaseException { + String name, IDBObj parent) + throws EBaseException { Hashtable ht = null; // @@ -581,7 +582,7 @@ class RequestAttrsMapper } } catch (Exception x) { Debug.trace("Mapping error in request Id " + - ((RequestRecord) parent).getRequestId().toString() + " : " + x); + ((RequestRecord) parent).getRequestId().toString() + " : " + x); Debug.trace("Attr " + attr.getName()); //if (Debug.ON) { Debug.printStackTrace(x); @@ -605,25 +606,25 @@ class RequestAttrsMapper /** * Maps dynamic data for the extData- prefix to and from the extData Hashtable * in RequestRecord. - * - * The data in RequestRecord is stored in a Hashtable. It comes in two forms: + * + * The data in RequestRecord is stored in a Hashtable. It comes in two forms: * 1. String key1 => String value1 - * String key2 => String value2 - * This is stored in LDAP as: - * extData-key1 => value1 - * extData-key2 => value2 - * + * String key2 => String value2 + * This is stored in LDAP as: + * extData-key1 => value1 + * extData-key2 => value2 + * * 2. String key => Hashtable value - * where value stores: - * String key2 => String value2 - * String key3 => String value3 - * This is stored in LDAP as: - * extData-key;key2 => value2 - * extData-key;key3 => value3 - * + * where value stores: + * String key2 => String value2 + * String key3 => String value3 + * This is stored in LDAP as: + * extData-key;key2 => value2 + * extData-key;key3 => value3 + * * These can be mixed, but each top-level key can only be associated with * a String value or a Hashtable value. - * + * */ class ExtAttrDynMapper implements IDBDynAttrMapper { @@ -636,17 +637,16 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { return mAttrs.elements(); } - /** * Decodes extdata encoded keys. * -- followed by a 4 digit hexadecimal string is decoded to the character * representing the hex string. - * - * The routine is written to be highly efficient. It only allocates + * + * The routine is written to be highly efficient. It only allocates * the StringBuffer if needed and copies the pieces in large chunks. - * - * @param key The key to decode - * @return The decoded key. + * + * @param key The key to decode + * @return The decoded key. */ public String decodeKey(String key) { StringBuffer output = null; @@ -656,8 +656,8 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { int index = 0; while (index < input.length) { if (input[index] == '-') { - if ( ((index + 1) < input.length) && - (input[index + 1] == '-')) { + if (((index + 1) < input.length) && + (input[index + 1] == '-')) { if (output == null) { output = new StringBuffer(input.length); } @@ -665,10 +665,10 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { index += 2; if ((index + 3) < input.length) { output.append( - Character.toChars( - Integer.parseInt(new String(input, index, 4), + Character.toChars( + Integer.parseInt(new String(input, index, 4), 16)) - ); + ); } index += 4; startCopyIndex = index; @@ -690,26 +690,26 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { /** * Encoded extdata keys for storage in LDAP. - * - * The rules for encoding are trickier than decoding. We want to allow + * + * The rules for encoding are trickier than decoding. We want to allow * '-' by itself to be stored in the database (for the common case of keys - * like 'Foo-Bar'. Therefore we are using '--' as the encoding character. + * like 'Foo-Bar'. Therefore we are using '--' as the encoding character. * The rules are: * 1) All characters [^-a-zA-Z0-9] are encoded as --XXXX where XXXX is the - * hex representation of the digit. + * hex representation of the digit. * 2) [a-zA-Z0-9] are always passed through unencoded * 3) [-] is passed through as long as it is preceded and followed - * by [a-zA-Z0-9] (or if it's at the beginning/end of the string) + * by [a-zA-Z0-9] (or if it's at the beginning/end of the string) * 4) If [-] is preceded or followed by [^a-zA-Z0-9] then - * the - as well as all following [^a-zA-Z0-9] characters are encoded - * as --XXXX. - * + * the - as well as all following [^a-zA-Z0-9] characters are encoded + * as --XXXX. + * * This routine tries to be as efficient as possible with StringBuffer and - * large copies. However, the encoding unfortunately requires several + * large copies. However, the encoding unfortunately requires several * objects to be allocated. - * + * * @param key The key to encode - * @return The encoded key + * @return The encoded key */ public String encodeKey(String key) { StringBuffer output = null; @@ -718,10 +718,10 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { int index = 0; while (index < input.length) { - if (! isAlphaNum(input[index])) { + if (!isAlphaNum(input[index])) { if ((input[index] == '-') && - ((index + 1) < input.length) && - (isAlphaNum(input[index + 1]))) { + ((index + 1) < input.length) && + (isAlphaNum(input[index + 1]))) { index += 2; } else if ((input[index] == '-') && ((index + 1) == input.length)) { @@ -731,8 +731,8 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { output = new StringBuffer(input.length + 5); } output.append(input, startCopyIndex, index - startCopyIndex); - while ( (index < input.length) && - (! isAlphaNum(input[index])) ) { + while ((index < input.length) && + (!isAlphaNum(input[index]))) { output.append("--"); String hexString = Integer.toHexString(input[index]); int padding = 4 - hexString.length(); @@ -782,25 +782,25 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { String key = (String) e.nextElement(); Object value = ht.get(key); if (value instanceof String) { - String stringValue = (String)value; + String stringValue = (String) value; attrs.add(new LDAPAttribute( extAttrPrefix + encodeKey(key), stringValue)); } else if (value instanceof Hashtable) { - Hashtable innerHash = (Hashtable)value; + Hashtable innerHash = (Hashtable) value; Enumeration innerHashEnum = innerHash.keys(); - while (innerHashEnum.hasMoreElements()){ - String innerKey = (String)innerHashEnum.nextElement(); - String innerValue = (String)innerHash.get(innerKey); + while (innerHashEnum.hasMoreElements()) { + String innerKey = (String) innerHashEnum.nextElement(); + String innerValue = (String) innerHash.get(innerKey); attrs.add(new LDAPAttribute( - extAttrPrefix + encodeKey(key) + ";" + encodeKey(innerKey), - innerValue)); + extAttrPrefix + encodeKey(key) + ";" + encodeKey(innerKey), + innerValue)); } } } } catch (Exception x) { Debug.trace("Output Mapping Error in requeset ID " + - ((IRequestRecord) parent).getRequestId().toString() + " : " + x); + ((IRequestRecord) parent).getRequestId().toString() + " : " + x); //if (Debug.ON) { Debug.printStackTrace(x); //} @@ -815,7 +815,7 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { Enumeration attrEnum = attrs.getAttributes(); while (attrEnum.hasMoreElements()) { - LDAPAttribute attr = (LDAPAttribute)attrEnum.nextElement(); + LDAPAttribute attr = (LDAPAttribute) attrEnum.nextElement(); String baseName = attr.getBaseName(); if (baseName.toLowerCase().startsWith(extAttrPrefix)) { String keyName = decodeKey( @@ -824,7 +824,7 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { String[] values = attr.getStringValueArray(); if (values.length != 1) { String message = "Output Mapping Error in request ID " + - ((IRequestRecord) parent).getRequestId().toString() + " : " + + ((IRequestRecord) parent).getRequestId().toString() + " : " + "more than one value returned for " + keyName; Debug.trace(message); @@ -833,22 +833,22 @@ class ExtAttrDynMapper implements IDBDynAttrMapper { if ((subTypes != null) && (subTypes.length > 0)) { if (subTypes.length != 1) { String message = "Output Mapping Error in request ID " + - ((IRequestRecord) parent).getRequestId().toString() + " : " + + ((IRequestRecord) parent).getRequestId().toString() + " : " + "more than one subType returned for " + keyName; Debug.trace(message); throw new EBaseException(message); } Object value = ht.get(keyName); - if ((value != null) && (! (value instanceof Hashtable))) { + if ((value != null) && (!(value instanceof Hashtable))) { String message = "Output Mapping Error in request ID " + - ((IRequestRecord) parent).getRequestId().toString() + " : " + + ((IRequestRecord) parent).getRequestId().toString() + " : " + "combined no-subtype and subtype data for key " + keyName; Debug.trace(message); throw new EBaseException(message); } - valueHashtable = (Hashtable)value; + valueHashtable = (Hashtable) value; if (valueHashtable == null) { valueHashtable = new Hashtable(); ht.put(keyName, valueHashtable); diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java b/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java index 1dafc2a7a..92c162ca8 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestRepository.java @@ -32,30 +32,32 @@ import com.netscape.certsrv.request.IRequestQueue; import com.netscape.cmscore.dbs.Repository; import com.netscape.cmscore.dbs.RepositoryRecord; - /** * TODO: what does this class provide beyond the Repository * base class?? * <p> + * * @author thayes * @version $Revision$ $Date$ */ class RequestRepository - extends Repository { + extends Repository { + + IDBSubsystem mDB = null; + IRequestQueue mRequestQueue = null; - IDBSubsystem mDB = null; - IRequestQueue mRequestQueue = null; /** * Create a request repository that uses the LDAP database * <p> + * * @param name - * the name of the repository. This String is used to - * construct the DN for the repository's LDAP entry. + * the name of the repository. This String is used to + * construct the DN for the repository's LDAP entry. * @param db - * the LDAP database system. + * the LDAP database system. */ public RequestRepository(String name, int increment, IDBSubsystem db) - throws EDBException { + throws EDBException { super(db, increment, "ou=" + name + ",ou=requests," + db.getBaseDN()); CMS.debug("RequestRepository: constructor 1"); @@ -67,8 +69,8 @@ class RequestRepository mDB = db; } - public RequestRepository(String name, int increment, IDBSubsystem db,IRequestQueue requestQueue) - throws EDBException { + public RequestRepository(String name, int increment, IDBSubsystem db, IRequestQueue requestQueue) + throws EDBException { super(db, increment, "ou=" + name + ",ou=requests," + db.getBaseDN()); CMS.debug("RequestRepository: constructor2."); @@ -82,12 +84,13 @@ class RequestRepository } /** - * get the LDAP base DN for this repository. This + * get the LDAP base DN for this repository. This * value can be used by the request queue to create the * name for the request records themselves. * <p> + * * @return - * the LDAP base DN. + * the LDAP base DN. */ public String getBaseDN() { return mBaseDN; @@ -96,34 +99,31 @@ class RequestRepository /** * Resets serial number. */ - public void resetSerialNumber(BigInteger serial) throws EBaseException - { + public void resetSerialNumber(BigInteger serial) throws EBaseException { setTheSerialNumber(serial); } - + /** * Removes all objects with this repository. */ - public void removeAllObjects() throws EBaseException - { + public void removeAllObjects() throws EBaseException { IDBSSession s = mDB.createSession(); try { - Enumeration e = s.search(getBaseDN(), + Enumeration e = s.search(getBaseDN(), "(" + RequestRecord.ATTR_REQUEST_ID + "=*)"); while (e.hasMoreElements()) { - RequestRecord r = (RequestRecord)e.nextElement(); - String name = "cn" + "=" + - r.getRequestId().toString() + "," + getBaseDN(); - s.delete(name); - } + RequestRecord r = (RequestRecord) e.nextElement(); + String name = "cn" + "=" + + r.getRequestId().toString() + "," + getBaseDN(); + s.delete(name); + } } finally { if (s != null) s.close(); } } - public BigInteger getLastSerialNumberInRange(BigInteger min, BigInteger max) - { + public BigInteger getLastSerialNumberInRange(BigInteger min, BigInteger max) { CMS.debug("RequestRepository: in getLastSerialNumberInRange: min " + min + " max " + max); @@ -131,26 +131,26 @@ class RequestRepository BigInteger ret = null; - if(mRequestQueue == null) { + if (mRequestQueue == null) { CMS.debug("RequestRepository: mRequestQueue is null."); - } else { - - CMS.debug("RequestRepository: about to call mRequestQueue.getLastRequestIdInRange"); - ret = mRequestQueue.getLastRequestIdInRange(min,max); + } else { + + CMS.debug("RequestRepository: about to call mRequestQueue.getLastRequestIdInRange"); + ret = mRequestQueue.getLastRequestIdInRange(min, max); } return ret; } + /** * the LDAP base DN for this repository */ protected String mBaseDN; - public String getPublishingStatus() { RepositoryRecord record = null; Object obj = null; @@ -160,8 +160,8 @@ class RequestRepository try { dbs = mDB.createSession(); obj = dbs.read(mBaseDN); - } catch (Exception e) { - CMS.debug("RequestRepository: getPublishingStatus: Error: " + e); + } catch (Exception e) { + CMS.debug("RequestRepository: getPublishingStatus: Error: " + e); CMS.debugStackTrace(); } finally { // Close session - ignoring errors (UTIL) @@ -169,7 +169,7 @@ class RequestRepository try { dbs.close(); } catch (Exception ex) { - CMS.debug("RequestRepository: getPublishingStatus: Error: " + ex); + CMS.debug("RequestRepository: getPublishingStatus: Error: " + ex); } } } @@ -181,7 +181,7 @@ class RequestRepository CMS.debug("RequestRepository: obj is NOT instanceof RepositoryRecord"); } CMS.debug("RequestRepository: getPublishingStatus mBaseDN: " + mBaseDN + - " status: " + ((status != null)?status:"null")); + " status: " + ((status != null) ? status : "null")); return status; } @@ -193,14 +193,14 @@ class RequestRepository ModificationSet mods = new ModificationSet(); if (status != null && status.length() > 0) { - mods.add(IRepositoryRecord.ATTR_PUB_STATUS, - Modification.MOD_REPLACE, status); + mods.add(IRepositoryRecord.ATTR_PUB_STATUS, + Modification.MOD_REPLACE, status); try { dbs = mDB.createSession(); dbs.modify(mBaseDN, mods); - } catch (Exception e) { - CMS.debug("RequestRepository: setPublishingStatus: Error: " + e); + } catch (Exception e) { + CMS.debug("RequestRepository: setPublishingStatus: Error: " + e); CMS.debugStackTrace(); } finally { // Close session - ignoring errors (UTIL) @@ -208,7 +208,7 @@ class RequestRepository try { dbs.close(); } catch (Exception ex) { - CMS.debug("RequestRepository: setPublishingStatus: Error: " + ex); + CMS.debug("RequestRepository: setPublishingStatus: Error: " + ex); } } } diff --git a/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java b/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java index 90df99248..ee625594f 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java +++ b/pki/base/common/src/com/netscape/cmscore/request/RequestSubsystem.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - import com.netscape.certsrv.apps.CMS; import com.netscape.certsrv.base.EBaseException; import com.netscape.certsrv.base.IConfigStore; @@ -32,24 +31,19 @@ import com.netscape.certsrv.request.IRequestSubsystem; import com.netscape.certsrv.request.IService; import com.netscape.cmscore.dbs.DBSubsystem; - /** * RequestSubsystem * <p> - * This class is reponsible for managing storage of request objects - * in the local database. + * This class is reponsible for managing storage of request objects in the local database. * <p> - * TODO: review this - * It provides: - * + registration of LDAP/JAVA mapping classes with the DBSubsystem - * + creation of RequestQueue storage in the database - * + retrieval of existing RequestQueue objects from the database + * TODO: review this It provides: + registration of LDAP/JAVA mapping classes with the DBSubsystem + creation of RequestQueue storage in the database + retrieval of existing RequestQueue objects from the database * <p> + * * @author thayes * @version $Revision$, $Date$ */ public class RequestSubsystem - implements IRequestSubsystem, ISubsystem { + implements IRequestSubsystem, ISubsystem { public final static String ID = IRequestSubsystem.SUB_ID; @@ -71,7 +65,7 @@ public class RequestSubsystem // in the database is supplied by the caller. // public void createRequestQueue(String name) - throws EBaseException { + throws EBaseException { /* String dbName = makeQueueName(name); @@ -84,15 +78,15 @@ public class RequestSubsystem } public IRequestQueue - getRequestQueue(String name, int increment, IPolicy p, IService s, INotify n) - throws EBaseException { + getRequestQueue(String name, int increment, IPolicy p, IService s, INotify n) + throws EBaseException { return getRequestQueue(name, increment, p, s, n, null); } public IRequestQueue - getRequestQueue(String name, int increment, IPolicy p, IService s, INotify n, - INotify pendingNotifier) - throws EBaseException { + getRequestQueue(String name, int increment, IPolicy p, IService s, INotify n, + INotify pendingNotifier) + throws EBaseException { RequestQueue rq = new RequestQueue(name, increment, p, s, n, pendingNotifier); // can't do this here because the service depends on getting rq @@ -110,6 +104,7 @@ public class RequestSubsystem /** * Implements ISubsystem.getId * <p> + * * @see ISubsystem#getId */ public String getId() { @@ -118,7 +113,7 @@ public class RequestSubsystem // ISubsystem.setId public void setId(String id) - throws EBaseException { + throws EBaseException { mId = id; } @@ -127,18 +122,19 @@ public class RequestSubsystem mParent = parent; mConfig = config; } - + /** * Implements ISubsystem.startup * <p> + * * @see ISubsystem#startup */ public void startup() - throws EBaseException { + throws EBaseException { mLogger = CMS.getLogger(); mLogger.log(ILogger.EV_SYSTEM, ILogger.S_REQQUEUE, ILogger.LL_INFO, - "Request subsystem started"); + "Request subsystem started"); } public void shutdown() { @@ -146,7 +142,7 @@ public class RequestSubsystem if (mLogger != null) { mLogger.log(ILogger.EV_SYSTEM, ILogger.S_REQQUEUE, ILogger.LL_INFO, - "Request subsystem stopped"); + "Request subsystem stopped"); } } @@ -166,7 +162,7 @@ public class RequestSubsystem // system. // protected IDBSSession createDBSSession() - throws EBaseException { + throws EBaseException { return getDBSubsystem().createSession(); } @@ -186,6 +182,5 @@ public class RequestSubsystem private String mId = IRequestSubsystem.SUB_ID; private IRequestQueue mRequestQueue; - protected ILogger mLogger; + protected ILogger mLogger; } - diff --git a/pki/base/common/src/com/netscape/cmscore/request/Schema.java b/pki/base/common/src/com/netscape/cmscore/request/Schema.java index 182e3470e..89a7b74b9 100644 --- a/pki/base/common/src/com/netscape/cmscore/request/Schema.java +++ b/pki/base/common/src/com/netscape/cmscore/request/Schema.java @@ -17,7 +17,6 @@ // --- END COPYRIGHT BLOCK --- package com.netscape.cmscore.request; - // // The Schema class contains constant string values for // LDAP attribute and object class names used in this package |