|
From: Petr B. <pe...@it...> - 2007-02-04 10:32:01
|
Hi,
I would like to post spring-ldap team my extension of DirContextAdapter.=
=
When item in the ldap is not set, method context.getStringAttribute thro=
w =
exception NullPointerException. In practise application is it obstructio=
n.
When getStringAttribute throw exception, method get default value. You c=
an =
get other the string values such as double,boolean, long, int.
This is source code of extension.
---
package net.itsynapse2.utils.data;
import org.springframework.ldap.support.DirContextAdapter;
public class DirContextAdapterImpl extends DirContextAdapter {
public String getStringAttribute(String attrName, String defaultVal=
ue) =
{
String result =3D defaultValue;
try {
result =3D getStringAttribute(attrName);
} catch(java.lang.NullPointerException npe) {}
return result;
}
public boolean getBooleanAttribute(String attrName, boolean =
defaultValue) {
boolean result =3D defaultValue;
try {
result =3D Boolean.parseBoolean(getStringAttribute(attrName=
));
} catch(java.lang.NullPointerException npe) {}
return result;
}
public long getIntegerAttribute(String attrName, int defaultValue) =
{
int result =3D defaultValue;
try {
result =3D Integer.parseInt(getStringAttribute(attrName));
} catch(java.lang.NullPointerException npe) {}
return result;
}
public long getLongAttribute(String attrName, long defaultValue) {
long result =3D defaultValue;
try {
result =3D Long.parseLong(getStringAttribute(attrName));
} catch(java.lang.NullPointerException npe) {}
return result;
}
public double getDoubleAttribute(String attrName, double defaultVal=
ue) =
{
double result =3D defaultValue;
try {
result =3D Double.parseDouble(getStringAttribute(attrName))=
;
} catch(java.lang.NullPointerException npe) {}
return result;
}
}
-- =
Petr Burdik
|
|
From: Ulrik S. <ulr...@ja...> - 2007-02-04 11:46:33
|
Thanks, Petr. We will take this under consideration. We have a splendid forum for these kinds of questions: http://forum.springframework.org/forumdisplay.php?f=40 Please post a thread there, and we can continue the discussion. -- Ulrik Sandberg Spring LDAP > Hi, > I would like to post spring-ldap team my extension of > DirContextAdapter. > When item in the ldap is not set, method context.getStringAttribute > throw > exception NullPointerException. In practise application is it > obstruction. > > When getStringAttribute throw exception, method get default value. > You can > get other the string values such as double,boolean, long, int. > > This is source code of extension. > > --- > > package net.itsynapse2.utils.data; > > import org.springframework.ldap.support.DirContextAdapter; > > public class DirContextAdapterImpl extends DirContextAdapter { > public String getStringAttribute(String attrName, String > defaultValue) > { > String result = defaultValue; > > try { > result = getStringAttribute(attrName); > } catch(java.lang.NullPointerException npe) {} > > return result; > } > public boolean getBooleanAttribute(String attrName, boolean > defaultValue) { > boolean result = defaultValue; > > try { > result = Boolean.parseBoolean(getStringAttribute > (attrName)); > } catch(java.lang.NullPointerException npe) {} > > return result; > } > public long getIntegerAttribute(String attrName, int > defaultValue) { > int result = defaultValue; > > try { > result = Integer.parseInt(getStringAttribute(attrName)); > } catch(java.lang.NullPointerException npe) {} > > return result; > > } > public long getLongAttribute(String attrName, long > defaultValue) { > long result = defaultValue; > > try { > result = Long.parseLong(getStringAttribute(attrName)); > } catch(java.lang.NullPointerException npe) {} > > return result; > > } > public double getDoubleAttribute(String attrName, double > defaultValue) > { > double result = defaultValue; > > try { > result = Double.parseDouble(getStringAttribute > (attrName)); > } catch(java.lang.NullPointerException npe) {} > > return result; > } > > } > > -- > Petr Burdik > > ---------------------------------------------------------------------- > --- > Using Tomcat but need to do more? Need to support web services, > security? > Get stuff done quickly with pre-integrated technology to make your > job easier. > Download IBM WebSphere Application Server v.1.0.1 based on Apache > Geronimo > http://sel.as-us.falkag.net/sel? > cmd=lnk&kid=120709&bid=263057&dat=121642 > _______________________________________________ > Springframework-developer mailing list > Spr...@li... > https://lists.sourceforge.net/lists/listinfo/springframework-developer > |