summaryrefslogtreecommitdiff
path: root/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java
diff options
context:
space:
mode:
authorAndrew Branson <andrew.branson@cern.ch>2014-06-02 11:31:08 +0200
committerAndrew Branson <andrew.branson@cern.ch>2014-06-02 11:31:08 +0200
commitb96dd998d6c442be19c342399839896d00d4b6f5 (patch)
tree51a0a07647e1d439d0adefdb57e6818a15d179ec /src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java
parent42adf60503b73c5106b30ba57fdeba13b3091169 (diff)
Initial commit
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java')
-rw-r--r--src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java138
1 files changed, 0 insertions, 138 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 51b9ded..0000000
--- a/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java
+++ /dev/null
@@ -1,138 +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(ItemPath 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(ItemPath 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();
- String thisName = thisProp.substring(0, thisProp.indexOf(':'));
- if (thisName.startsWith("!") && thisName.length()>1) thisName = thisName.substring(1);
- propbag.add(thisName);
- }
-
- 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 The Property object
- * @throws ObjectNotFoundException
- */
- public Property getProperty(ItemPath thisEntity, String name) throws ObjectNotFoundException {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- return getProperty(entityEntry, name);
- }
-
- /**
- * @param thisEntity - EntityPath of the subject entity
- * @param name - the property name to delete
- * @throws ObjectNotFoundException
- * @throws ObjectCannotBeUpdated
- */
- public void deleteProperty(ItemPath thisEntity, String name) throws ObjectNotFoundException, ObjectCannotBeUpdated {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- Property prop = getProperty(entityEntry, name);
- Logger.msg(6, "LDAPLookupUtils.deleteProperty("+name+") - Deleting property");
- LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", getPropertyAttrValue(prop));
- }
-
- private static String getPropertyAttrValue(Property prop) {
- return (prop.isMutable()?"":"!")+prop.getName()+":"+prop.getValue();
- }
-
- /**
- * @param thisEntity - EntityPath of the subject entity
- * @param prop - the property to store
- * @throws ObjectNotFoundException
- * @throws ObjectCannotBeUpdated
- */
- public void setProperty(ItemPath thisEntity, Property prop) throws ObjectNotFoundException, ObjectCannotBeUpdated {
- LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- try {
- Property oldProp = getProperty(entityEntry, prop.getName());
- Logger.msg(6, "LDAPLookupUtils.setProperty("+prop.getName()+") - Removing old value '"+oldProp.getValue()+"'");
- LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", getPropertyAttrValue(oldProp));
- } 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", getPropertyAttrValue(prop));
- }
-
- public static Property getProperty(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+":";
- String roPropPrefix = "!"+propPrefix;
- String val = null, name = null; boolean mutable = false;
- for (Enumeration<?> e = props.getStringValues(); name==null && e.hasMoreElements();) {
- String attrVal = (String)e.nextElement();
- if (attrVal.toLowerCase().startsWith(propPrefix.toLowerCase())) {
- name = attrVal.substring(0, propPrefix.length()-1);
- val = attrVal.substring(propPrefix.length());
- mutable = true; break;
- }
-
- if (attrVal.toLowerCase().startsWith(roPropPrefix.toLowerCase())) {
- name = attrVal.substring(1, roPropPrefix.length()-1);
- val = attrVal.substring(roPropPrefix.length());
- mutable = false; break;
- }
- }
- if (name == null)
- throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
- Logger.msg(6, "Loaded "+(mutable?"":"Non-")+"Mutable Property: "+name+"="+val);
- return new Property(name, val, mutable);
- }
-
-}