if(ocd != null){
if(conf != null && currentAttributes.size() > 0){
AttributeDefinition[] attrDefs = ocd.getAttributeDefinitions(ObjectClassDefinition.ALL);
Hashtable ADs = new Hashtable(); //id is key
for(int i = 0; i < attrDefs.length; i++){
AttributeDefinition ad = attrDefs[i];
ADs.put(ad.getID(), ad);
}
Dictionary props = conf.getProperties();
Enumeration attrsAssigns = currentAttributes.elements();
while(attrsAssigns.hasMoreElements()){
AE ae = (AE) attrsAssigns.nextElement();
AttributeDefinition ad = (AttributeDefinition) ADs.get(ae.adref);
if(ad != null){
Object value = null;
int card = ad.getCardinality();
switch(ad.getType()){
case AttributeDefinition.STRING:
if(card < 0){
value = new Vector(-1 * card);
Enumeration values = ae.values.elements();
while(values.hasMoreElements()){
((Vector)value).add(values.nextElement());
}
}
else if(card > 0){
value = new String[card];
Enumeration values = ae.values.elements();
for(int i = 0; values.hasMoreElements(); i++){
((String[])value)[i] = (String) values.nextElement();
}
}
else{
value = ae.values.elementAt(0);
}
break;
case AttributeDefinition.BOOLEAN:
if(card < 0){
value = new Vector(-1 * card);
Enumeration values = ae.values.elements();
while(values.hasMoreElements()){
((Vector)value).add(Boolean.valueOf((String)values.nextElement()));
}
}
else if(card > 0){
value = new Boolean[card];
Enumeration values = ae.values.elements();
for(int i = 0; values.hasMoreElements(); i++){
((Boolean[])value)[i] = Boolean.valueOf((String) values.nextElement());
}
}
else{
value = Boolean.valueOf((String) ae.values.elementAt(0));
}
break;
case AttributeDefinition.BYTE:
if(card < 0){
value = new Vector(-1 * card);
Enumeration values = ae.values.elements();
while(values.hasMoreElements()){
((Vector)value).add(Byte.valueOf((String)values.nextElement()));
}
}
else if(card > 0){
value = new Byte[card];
Enumeration values = ae.values.elements();
for(int i = 0; values.hasMoreElements(); i++){
((Byte[])value)[i] = Byte.valueOf((String) values.nextElement());
}
}
else{
value = Byte.valueOf((String) ae.values.elementAt(0));
}
break;
case AttributeDefinition.DOUBLE:
if(card < 0){
value = new Vector(-1 * card);
Enumeration values = ae.values.elements();
while(values.hasMoreElements()){
((Vector)value).add(Double.valueOf((String)values.nextElement()));
}
}
else if(card > 0){
value = new Double[card];
Enumeration values = ae.values.elements();
for(int i = 0; values.hasMoreElements(); i++){
((Double[])value)[i] = Double.valueOf((String) values.nextElement());
}
}
else{
value = Double.valueOf((String) ae.values.elementAt(0));
}
break;
case AttributeDefinition.FLOAT:
if(card < 0){
value = new Vector(-1 * card);
Enumeration values = ae.values.elements();
while(values.hasMoreElements()){
((Vector)value).add(Float.valueOf((String)values.nextElement()));
}
}
else if(card > 0){
value = new Float[card];
Enumeration values = ae.values.elements();
for(int i = 0; values.hasMoreElements(); i++){
((Float[])value)[i] = Float.valueOf((String) values.nextElement());
}
}
else{
value = Float.valueOf((String) ae.values.elementAt(0));
}
break;
case AttributeDefinition.INTEGER:
if(card < 0){
value = new Vector(-1 * card);
Enumeration values = ae.values.elements();
while(values.hasMoreElements()){
((Vector)value).add(Integer.valueOf((String)values.nextElement()));
}
}
else if(card > 0){
value = new Integer[card];
Enumeration values = ae.values.elements();
for(int i = 0; values.hasMoreElements(); i++){
((Integer[])value)[i] = Integer.valueOf((String) values.nextElement());
}
}
else{
value = Integer.valueOf((String) ae.values.elementAt(0));
}
break;
case AttributeDefinition.LONG:
if(card < 0){
value = new Vector(-1 * card);
Enumeration values = ae.values.elements();
while(values.hasMoreElements()){
((Vector)value).add(Long.valueOf((String)values.nextElement()));
}
}
else if(card > 0){
value = new Long[card];
Enumeration values = ae.values.elements();
for(int i = 0; values.hasMoreElements(); i++){
((Long[])value)[i] = Long.valueOf((String) values.nextElement());
}
}
else{
value = Long.valueOf((String) ae.values.elementAt(0));
}
break;
case AttributeDefinition.SHORT:
if(card < 0){
value = new Vector(-1 * card);
Enumeration values = ae.values.elements();
while(values.hasMoreElements()){
((Vector)value).add(Short.valueOf((String)values.nextElement()));
}
}
else if(card > 0){
value = new Integer[card];
Enumeration values = ae.values.elements();
for(int i = 0; values.hasMoreElements(); i++){
((Short[])value)[i] = Short.valueOf((String) values.nextElement());
}
}
else{
value = Short.valueOf((String) ae.values.elementAt(0));
}
break;
case AttributeDefinition.CHARACTER:
if(card < 0){
value = new Vector(-1 * card);
Enumeration values = ae.values.elements();
while(values.hasMoreElements()){
((Vector)value).add(new Character(((String)values.nextElement()).charAt(0)));
}
}
else if(card > 0){
value = new Character[card];
Enumeration values = ae.values.elements();
for(int i = 0; values.hasMoreElements(); i++){
((Character[])value)[i] = new Character(((String)values.nextElement()).charAt(0));
}
}
else{
value = new Character(((String) ae.values.elementAt(0)).charAt(0));
}
break;
}
/*TODO code along these lines would be less repetitive
Class clazz = null;
switch(ad.getType()){
case AttributeDefinition.STRING:
clazz = null;
break;
case AttributeDefinition.BOOLEAN:
clazz = Boolean.class;
break;
case AttributeDefinition.BYTE:
clazz = Byte.class;
break;
case AttributeDefinition.DOUBLE:
clazz = Double.class;
break;
case AttributeDefinition.FLOAT:
clazz = Float.class;
break;
case AttributeDefinition.INTEGER:
clazz = Integer.class;
break;
case AttributeDefinition.LONG:
clazz = Long.class;
break;
case AttributeDefinition.SHORT:
clazz = Short.class;
break;
case AttributeDefinition.CHARACTER:
clazz = Character.class;
break;
}
Method method = null;
try{
method = clazz.getMethod("valueOf", new Class[]{String.class});
}
catch(NoSuchMethodException e){
}
Boolean val = null;
try{
val = (Boolean) method.invoke(null, new Object[]{"true"});
}
catch(IllegalAccessException e){
}
catch(InvocationTargetException e){
}
*/
if(value != null){
props.put(ad.getName(), value);
}
}
} //while