diff options
| author | Andrew Branson <andrew.branson@cern.ch> | 2013-02-22 14:04:33 +0100 |
|---|---|---|
| committer | Andrew Branson <andrew.branson@cern.ch> | 2013-03-18 14:03:54 +0100 |
| commit | 6e35118970c7af70eb0ac938859d794f7348d367 (patch) | |
| tree | c85299f5a174a04c9df2847c1f469ff427dd6f64 /src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java | |
| parent | d6cfc7505be13b3b09adf423206cf75d9f806c12 (diff) | |
Extracted LDAP specifics into subpackage
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java')
| -rw-r--r-- | src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java | 118 |
1 files changed, 0 insertions, 118 deletions
diff --git a/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java b/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java deleted file mode 100644 index 57ed17d..0000000 --- a/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java +++ /dev/null @@ -1,118 +0,0 @@ -package com.c2kernel.lookup;
-
-import java.util.ArrayList;
-import java.util.Enumeration;
-
-import com.c2kernel.common.ObjectCannotBeUpdated;
-import com.c2kernel.common.ObjectNotFoundException;
-import com.c2kernel.property.Property;
-import com.c2kernel.utils.Logger;
-import com.novell.ldap.LDAPAttribute;
-import com.novell.ldap.LDAPEntry;
-
-/**************************************************************************
- *
- * $Revision: 1.3 $
- * $Date: 2006/03/03 13:52:21 $
- *
- * Copyright (C) 2003 CERN - European Organization for Nuclear Research
- * All rights reserved.
- **************************************************************************/
-
-public class LDAPPropertyManager {
- /**
- *
- */
- protected LDAPLookup ldap;
-
- public LDAPPropertyManager(LDAPLookup ldap) {
- super();
- this.ldap = ldap;
- }
-
- /**
- * @param thisEntity - EntityPath of the subject entity
- * @return
- * @throws ObjectNotFoundException
- */
- public boolean hasProperties(EntityPath thisEntity) throws ObjectNotFoundException {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- return entityEntry.getAttribute("cristalprop") != null;
- }
-
- /**
- * @param thisEntity - EntityPath of the subject entity
- * @return array of Property
- * @throws ObjectNotFoundException
- */
- public String[] getPropertyNames(EntityPath thisEntity) throws ObjectNotFoundException {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- ArrayList<String> propbag = new ArrayList<String>();
- LDAPAttribute props = entityEntry.getAttribute("cristalprop");
- for (Enumeration<?> e = props.getStringValues(); e.hasMoreElements();) {
- String thisProp = (String)e.nextElement();
- propbag.add(thisProp.substring(0, thisProp.indexOf(':')));
- }
-
- String[] retArr = new String[props.size()];
- return propbag.toArray(retArr);
- }
-
- /**
- * @param thisEntity - EntityPath of the subject entity
- * @param propName - the name of the property to retrieve
- * @return String the property value
- * @throws ObjectNotFoundException
- */
- public String getPropertyValue(EntityPath thisEntity, String name) throws ObjectNotFoundException {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- return getPropertyAttr(entityEntry, name);
- }
-
- /**
- * @param thisEntity - EntityPath of the subject entity
- * @param name - the property name to delete
- * @throws ObjectNotFoundException
- * @throws ObjectCannotBeUpdated
- */
- public void deleteProperty(EntityPath thisEntity, String name) throws ObjectNotFoundException, ObjectCannotBeUpdated {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- String propVal = getPropertyAttr(entityEntry, name);
- Logger.msg(6, "LDAPLookupUtils.deleteProperty("+name+") - Deleting property");
- LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", name+":"+propVal);
- }
-
- /**
- * @param thisEntity - EntityPath of the subject entity
- * @param prop - the property to store
- * @throws ObjectNotFoundException
- * @throws ObjectCannotBeUpdated
- */
- public void setProperty(EntityPath thisEntity, Property prop) throws ObjectNotFoundException, ObjectCannotBeUpdated {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- try {
- String propVal = getPropertyAttr(entityEntry, prop.getName());
- Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - Removing old value '"+propVal+"'");
- LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", prop.getName()+":"+propVal);
- } catch (ObjectNotFoundException ex) {
- Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - creating new property.");
- }
- Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - setting to '"+prop.getValue()+"'");
- LDAPLookupUtils.addAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", prop.getName()+":"+prop.getValue());
- }
-
- private static String getPropertyAttr(LDAPEntry myEntry, String propName) throws ObjectNotFoundException {
- // delete existing props
- LDAPAttribute props = myEntry.getAttribute("cristalprop");
- if (props == null)
- throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
- String propPrefix = propName+":";
- for (Enumeration<?> e = props.getStringValues(); e.hasMoreElements();) {
- String val = (String)e.nextElement();
- if (val.toLowerCase().startsWith(propPrefix.toLowerCase()))
- return val.substring(propPrefix.length());
- }
- throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
- }
-
-}
|
