summaryrefslogtreecommitdiffstats
path: root/pki/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java
diff options
context:
space:
mode:
Diffstat (limited to 'pki/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java')
-rw-r--r--pki/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java109
1 files changed, 53 insertions, 56 deletions
diff --git a/pki/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java b/pki/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java
index 65b1039d4..20e40a8e3 100644
--- a/pki/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java
+++ b/pki/base/common/src/com/netscape/cmscore/dbs/DBRegistry.java
@@ -17,7 +17,6 @@
// --- END COPYRIGHT BLOCK ---
package com.netscape.cmscore.dbs;
-
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
@@ -37,22 +36,21 @@ import com.netscape.certsrv.dbs.IDBObj;
import com.netscape.certsrv.dbs.IDBRegistry;
import com.netscape.certsrv.dbs.IFilterConverter;
import com.netscape.certsrv.logging.ILogger;
-
/**
* A class represents a registry where all the
- * schema (object classes and attribute) information
+ * schema (object classes and attribute) information
* is stored.
- *
+ *
* Attribute mappers can be registered with this
* registry.
- *
+ *
* Given the schema information stored, this registry
* has knowledge to convert a Java object into a
* LDAPAttributeSet or vice versa.
- *
+ *
* @author thomask
- * @version $Revision$, $Date$
+ * @version $Revision$, $Date$
*/
public class DBRegistry implements IDBRegistry, ISubsystem {
@@ -87,17 +85,17 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
}
/**
- * Initializes the internal registery. Connects to the
- * data source, and create a pool of connection of which
+ * Initializes the internal registery. Connects to the
+ * data source, and create a pool of connection of which
* applications can use. Optionally, check the integrity
* of the database.
*/
- public void init(ISubsystem owner, IConfigStore config)
- throws EBaseException {
+ public void init(ISubsystem owner, IConfigStore config)
+ throws EBaseException {
mConfig = config;
mConverter = new LdapFilterConverter(mAttrufNames);
}
-
+
/**
* Retrieves configuration store.
*/
@@ -128,14 +126,14 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
* Registers object class.
*/
public void registerObjectClass(String className, String ldapNames[])
- throws EDBException {
+ throws EDBException {
try {
Class<?> c = Class.forName(className);
mOCclassNames.put(className, ldapNames);
mOCldapNames.put(sortAndConcate(
- ldapNames).toLowerCase(),
- new NameAndObject(className, c));
+ ldapNames).toLowerCase(),
+ new NameAndObject(className, c));
} catch (ClassNotFoundException e) {
/*LogDoc
@@ -145,7 +143,7 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
* @message DBRegistry: <exception thrown>
*/
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB,
- ILogger.LL_FAILURE, CMS.getLogMessage("OPERATION_ERROR", e.toString()));
+ ILogger.LL_FAILURE, CMS.getLogMessage("OPERATION_ERROR", e.toString()));
throw new EDBException(
CMS.getUserMessage("CMS_DBS_INVALID_CLASS_NAME", className));
}
@@ -161,8 +159,8 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
/**
* Registers attribute mapper.
*/
- public void registerAttribute(String ufName, IDBAttrMapper mapper)
- throws EDBException {
+ public void registerAttribute(String ufName, IDBAttrMapper mapper)
+ throws EDBException {
// should not allows 'objectclass' as attribute; it has
// special meaning
mAttrufNames.put(ufName.toLowerCase(), mapper);
@@ -183,6 +181,7 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
* Creates LDAP-based search filters with help of
* registered mappers.
* Parses filter from filter string specified in RFC1558.
+ *
* <pre>
* <filter> ::= '(' <filtercomp> ')'
* <filtercomp> ::= <and> | <or> | <not> | <item>
@@ -209,37 +208,37 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
return getFilter(filter, mConverter);
}
- public String getFilter(String filter, IFilterConverter c)
- throws EBaseException {
+ public String getFilter(String filter, IFilterConverter c)
+ throws EBaseException {
String f = filter;
f = f.trim();
if (f.startsWith("(") && f.endsWith(")")) {
- return "(" + getFilterComp(f.substring(1,
+ return "(" + getFilterComp(f.substring(1,
f.length() - 1), c) + ")";
} else {
return getFilterComp(filter, c);
}
}
- private String getFilterComp(String f, IFilterConverter c)
- throws EBaseException {
+ private String getFilterComp(String f, IFilterConverter c)
+ throws EBaseException {
f = f.trim();
- if (f.startsWith("&")) { // AND operation
- return "&" + getFilterList(f.substring(1,
+ if (f.startsWith("&")) { // AND operation
+ return "&" + getFilterList(f.substring(1,
f.length()), c);
} else if (f.startsWith("|")) { // OR operation
- return "|" + getFilterList(f.substring(1,
+ return "|" + getFilterList(f.substring(1,
f.length()), c);
} else if (f.startsWith("!")) { // NOT operation
return "!" + getFilter(f.substring(1, f.length()), c);
- } else { // item
+ } else { // item
return getFilterItem(f, c);
}
}
-
- private String getFilterList(String f, IFilterConverter c)
- throws EBaseException {
+
+ private String getFilterList(String f, IFilterConverter c)
+ throws EBaseException {
f = f.trim();
int level = 0;
int start = 0;
@@ -274,8 +273,8 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
/**
* So, here we need to separate item into name, op, value.
*/
- private String getFilterItem(String f, IFilterConverter c)
- throws EBaseException {
+ private String getFilterItem(String f, IFilterConverter c)
+ throws EBaseException {
f = f.trim();
int idx = f.indexOf('=');
@@ -318,7 +317,7 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
if (value.indexOf('*') == -1) {
if (type.equals("objectclass")) {
String ldapNames[] = (String[])
- mOCclassNames.get(value);
+ mOCclassNames.get(value);
if (ldapNames == null)
throw new EDBException(
@@ -326,8 +325,8 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
String filter = "";
for (int g = 0; g < ldapNames.length; g++) {
- filter += "(objectclass=" +
- ldapNames[g] + ")";
+ filter += "(objectclass=" +
+ ldapNames[g] + ")";
}
return "&" + filter;
} else {
@@ -341,14 +340,14 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
/**
* Maps object into LDAP attribute set.
*/
- public void mapObject(IDBObj parent, String name, Object obj,
- LDAPAttributeSet attrs) throws EBaseException {
+ public void mapObject(IDBObj parent, String name, Object obj,
+ LDAPAttributeSet attrs) throws EBaseException {
IDBAttrMapper mapper = (IDBAttrMapper) mAttrufNames.get(
name.toLowerCase());
if (mapper == null) {
return; // no mapper found, just skip this attribute
- }
+ }
mapper.mapObjectToLDAPAttributeSet(parent, name, obj, attrs);
}
@@ -358,10 +357,10 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
* This method is used for searches, to map the database attributes
* to LDAP attributes.
*/
- public String[] getLDAPAttributes(String attrs[])
- throws EBaseException {
+ public String[] getLDAPAttributes(String attrs[])
+ throws EBaseException {
IDBAttrMapper mapper;
-
+
if (attrs == null)
return null;
Vector<String> v = new Vector<String>();
@@ -391,10 +390,9 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
} else {
IDBDynAttrMapper matchingDynAttrMapper = null;
// check if a dynamic mapper can handle the attribute
- for (Iterator<IDBDynAttrMapper> dynMapperIter = mDynAttrMappers.iterator();
- dynMapperIter.hasNext();) {
+ for (Iterator<IDBDynAttrMapper> dynMapperIter = mDynAttrMappers.iterator(); dynMapperIter.hasNext();) {
IDBDynAttrMapper dynAttrMapper =
- (IDBDynAttrMapper)dynMapperIter.next();
+ (IDBDynAttrMapper) dynMapperIter.next();
if (dynAttrMapper.supportsLDAPAttributeName(attrs[i])) {
matchingDynAttrMapper = dynAttrMapper;
break;
@@ -410,7 +408,7 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
* @message DBRegistry: <attr> is not registered
*/
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB,
- ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_DBS_ATTR_NOT_REGISTER", attrs[i]));
+ ILogger.LL_FAILURE, CMS.getLogMessage("CMSCORE_DBS_ATTR_NOT_REGISTER", attrs[i]));
throw new EDBException(CMS.getLogMessage("CMSCORE_DBS_ATTR_NOT_REGISTER", attrs[i]));
}
}
@@ -427,8 +425,8 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
/**
* Creates attribute set from object.
*/
- public LDAPAttributeSet createLDAPAttributeSet(IDBObj obj)
- throws EBaseException {
+ public LDAPAttributeSet createLDAPAttributeSet(IDBObj obj)
+ throws EBaseException {
Enumeration<String> e = obj.getSerializableAttrNames();
LDAPAttributeSet attrs = new LDAPAttributeSet();
@@ -453,7 +451,7 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
* Creates object from attribute set.
*/
public IDBObj createObject(LDAPAttributeSet attrs)
- throws EBaseException {
+ throws EBaseException {
// map object class attribute to object
LDAPAttribute attr = attrs.getAttribute("objectclass");
@@ -463,7 +461,7 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
// sort the object class values
@SuppressWarnings("unchecked")
- Enumeration<String> vals = attr.getStringValues();
+ Enumeration<String> vals = attr.getStringValues();
Vector<String> v = new Vector<String>();
while (vals.hasMoreElements()) {
@@ -488,15 +486,15 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
while (ee.hasMoreElements()) {
String oname = (String) ee.nextElement();
IDBAttrMapper mapper = (IDBAttrMapper)
- mAttrufNames.get(
- oname.toLowerCase());
+ mAttrufNames.get(
+ oname.toLowerCase());
if (mapper == null) {
throw new EDBException(
CMS.getUserMessage("CMS_DBS_NO_MAPPER_FOUND", oname));
}
- mapper.mapLDAPAttributeSetToObject(attrs,
- oname, obj);
+ mapper.mapLDAPAttributeSetToObject(attrs,
+ oname, obj);
}
return obj;
} catch (Exception e) {
@@ -508,7 +506,7 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
* @message DBRegistry: <attr> is not registered
*/
mLogger.log(ILogger.EV_SYSTEM, ILogger.S_DB,
- ILogger.LL_FAILURE, CMS.getLogMessage("OPERATION_ERROR", e.toString()));
+ ILogger.LL_FAILURE, CMS.getLogMessage("OPERATION_ERROR", e.toString()));
throw new EDBException(CMS.getUserMessage("CMS_DBS_INVALID_ATTRS"));
}
}
@@ -543,7 +541,6 @@ public class DBRegistry implements IDBRegistry, ISubsystem {
}
}
-
/**
* Just a convenient container class.
*/
@@ -556,7 +553,7 @@ class NameAndObject {
mN = name;
mO = o;
}
-
+
public String getName() {
return mN;
}