use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class COSManager method assignDirectCOSDef.
/**
* Assigns a direct (Classic) COS definition to a persistent object.
*
* @param pObject
* The target persistent object.
* @param cosDef
* The direct (Classic) COS definition.
* @param cosTemplate
* A COS template belonging to the definition.
* @param sMgr
* A SchemaManager instance.
*
* @throws UMSException
* if an exception occurs
*/
private void assignDirectCOSDef(PersistentObject pObject, DirectCOSDefinition cosDef, COSTemplate cosTemplate, SchemaManager sMgr) throws UMSException {
//
if (cosDef.getGuid() == null) {
String msg = i18n.getString(IUMSConstants.COS_DEFINITION_NOT_PERSISTENT);
throw new UMSException(msg);
}
// Make sure target entry is in same tree as COS Def parent.
//
DN targetDN = DN.valueOf(pObject.getGuid().getDn());
DN cosParentDN = DN.valueOf(cosDef.getParentGuid().getDn());
if (!(targetDN.isInScopeOf(cosParentDN, SearchScope.SUBORDINATES))) {
String msg = i18n.getString(IUMSConstants.COS_TARGET_OBJECT_DIFFERENT_TREE);
throw new UMSException(msg);
}
//
if (cosDef.getCOSSpecifier().equalsIgnoreCase("nsrole"))
return;
ArrayList aList;
AttrSet attrSet = new AttrSet();
// Get cosSpecifier object class - should only be one.
// Update the target entry with cosSpecifier object class.
// Only add it if it doesn't already exist.
//
aList = (ArrayList) sMgr.getObjectClasses(cosDef.getCOSSpecifier());
String cosSpecObjectClass = (String) aList.get(0);
if (!objectClassExists(cosSpecObjectClass, pObject)) {
attrSet.add(new Attr("objectclass", cosSpecObjectClass));
}
// Get the cos attributes from the definition (ex. mailquota).
// For each of the attributes, get the objectclass. These
// will be used to attach to the target entry. This is only
// done if the cos attribute qualifier is not "operational"
// (you don't need to add cos attribute object classes for
// "operational" cos attribute qualifier.
//
String[] cosAttributes = cosDef.getCOSAttributes();
String qualifier = null;
Arrays.asList(ICOSDefinition.qualifiers);
Attr attr = cosTemplate.getAttribute("objectclass");
String[] cosTempObjClasses = attr.getStringValues();
for (int i = 0; i < cosAttributes.length; i++) {
StringTokenizer st = new StringTokenizer(cosAttributes[i]);
st.nextToken();
qualifier = st.nextToken();
if ((!qualifier.equals(ICOSDefinition.qualifiers[ICOSDefinition.OPERATIONAL]))) {
for (int j = 0; j < cosTempObjClasses.length; j++) {
if (!cosTempObjClasses[j].equalsIgnoreCase("top") && !cosTempObjClasses[j].equalsIgnoreCase("costemplate") && !objectClassExists(cosTempObjClasses[j], pObject)) {
if (!attrSet.contains("objectclass", cosTempObjClasses[j])) {
attrSet.add(new Attr("objectclass", cosTempObjClasses[j]));
}
}
}
}
}
//
if (pObject.getAttribute(cosDef.getCOSSpecifier()) == null)
attrSet.add(new Attr(cosDef.getCOSSpecifier(), cosTemplate.getName()));
if (attrSet.size() > 0) {
pObject.modify(toModifications(ModificationType.ADD, attrSet));
pObject.save();
}
}
use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class COSTemplate method getName.
/**
* Returns the name of this COS template.
*
* @return The name of this COS template.
* @supported.api
*/
public String getName() {
String attributeValue = null;
Attr attribute = getAttribute(getNamingAttribute());
if (attribute != null) {
attributeValue = attribute.getValue();
}
return attributeValue;
}
use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class DirectCOSDefinition method getCOSSpecifier.
/**
* Returns the COS specifier.
*
* @return the COS specifier
*
* @see DirectCOSDefinition#setCOSSpecifier(String cosSpecifier)
* @supported.api
*/
public String getCOSSpecifier() {
String attributeValue = null;
Attr attribute = getAttribute(COSSPECIFIER);
if (attribute != null) {
attributeValue = attribute.getValue();
}
return attributeValue;
}
use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class DirectCOSDefinition method addCOSTemplate.
/**
* Adds a COS Template to this COS definition. This COS definition must be
* persistent before adding the template.
*
* @param cosTemplate
* The COS Template to be added.
*
* @throws UMSException
* The exception thrown from the data layer.
* @supported.api
*/
public void addCOSTemplate(COSTemplate cosTemplate) throws UMSException {
if (getGuid() == null) {
String msg = i18n.getString(IUMSConstants.DEFINITION_NOT_PERSISTENT);
throw new UMSException(msg);
}
if (getAttribute(ICOSDefinition.COSTEMPLATEDN) == null) {
this.modify(new Attr(ICOSDefinition.COSTEMPLATEDN, getGuid().getDn()), ModificationType.ADD);
this.save();
}
this.addChild(cosTemplate);
}
use of com.iplanet.services.ldap.Attr in project OpenAM by OpenRock.
the class TemplateManager method decodeAttr.
/**
* Decode single attribute with multiple values into an AttrSet. For
* example:
*
* <pre>
* Attribute:
* required: objectclass=top
* required: objectclass=groupofuniquenames
* required: cn
* required: sn
*
* Attribute Set:
* objectclass: top
* objectclass: groupofuniquenames
* cn:
* sn:
* </pre>
*
* @param attr
* Attribute to be decoded from
* @param delimiter
* Delimiter used in the encoding
* @return Decoded attribute set
*/
private AttrSet decodeAttr(Attr attr, String delimiter) {
if (attr == null)
return null;
String[] values = attr.getStringValues();
AttrSet attrSet = new AttrSet();
for (int i = 0, size = attr.size(); i < size; i++) {
String value = values[i];
String attrName = null;
String attrValue = null;
int index = value.indexOf('=');
if (index < 0) {
attrName = value;
} else {
attrName = value.substring(0, index);
attrValue = value.substring(index + 1, value.length());
}
if (attrValue != null && attrValue.length() != 0) {
attrSet.add(new Attr(attrName, attrValue));
} else {
attrSet.add(new Attr(attrName));
}
}
return attrSet;
}
Aggregations