diff options
Diffstat (limited to 'src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java')
| -rw-r--r-- | src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java b/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java index 57ed17d..fcf1ef8 100644 --- a/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java +++ b/src/main/java/com/c2kernel/lookup/LDAPPropertyManager.java @@ -51,7 +51,9 @@ public class LDAPPropertyManager { 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 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()];
@@ -61,12 +63,12 @@ public class LDAPPropertyManager { /**
* @param thisEntity - EntityPath of the subject entity
* @param propName - the name of the property to retrieve
- * @return String the property value
+ * @return The Property object
* @throws ObjectNotFoundException
*/
- public String getPropertyValue(EntityPath thisEntity, String name) throws ObjectNotFoundException {
+ public Property getProperty(EntityPath thisEntity, String name) throws ObjectNotFoundException {
LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- return getPropertyAttr(entityEntry, name);
+ return getProperty(entityEntry, name);
}
/**
@@ -77,9 +79,13 @@ public class LDAPPropertyManager { */
public void deleteProperty(EntityPath thisEntity, String name) throws ObjectNotFoundException, ObjectCannotBeUpdated {
LDAPEntry entityEntry = LDAPLookupUtils.getEntry(ldap.getConnection(), thisEntity.getFullDN());
- String propVal = getPropertyAttr(entityEntry, name);
+ Property prop = getProperty(entityEntry, name);
Logger.msg(6, "LDAPLookupUtils.deleteProperty("+name+") - Deleting property");
- LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", name+":"+propVal);
+ LDAPLookupUtils.removeAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", getPropertyAttrValue(prop));
+ }
+
+ private static String getPropertyAttrValue(Property prop) {
+ return (prop.isMutable()?"":"!")+prop.getName()+":"+prop.getValue();
}
/**
@@ -91,28 +97,42 @@ public class LDAPPropertyManager { 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);
+ 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", prop.getName()+":"+prop.getValue());
+ LDAPLookupUtils.addAttributeValue(ldap.getConnection(), entityEntry, "cristalprop", getPropertyAttrValue(prop));
}
- private static String getPropertyAttr(LDAPEntry myEntry, String propName) throws ObjectNotFoundException {
+ 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+":";
- for (Enumeration<?> e = props.getStringValues(); e.hasMoreElements();) {
- String val = (String)e.nextElement();
- if (val.toLowerCase().startsWith(propPrefix.toLowerCase()))
- return val.substring(propPrefix.length());
+ 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;
+ }
}
- throw new ObjectNotFoundException("Property "+propName+" does not exist", "");
+ 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);
}
}
|
