{
searchParameter.setSearchBase( new LdapDN( searchBaseAttribute.getValue() ) );
}
catch ( InvalidNameException e )
{
throw new ConnectionIOException( "Unable to parse 'Search Base' of search '"
+ searchParameter.getName() + "' :" + searchBaseAttribute.getValue() );
}
}
// Filter
Attribute filterAttribute = searchParameterElement.attribute( FILTER_TAG );
if ( filterAttribute != null )
{
searchParameter.setFilter( filterAttribute.getValue() );
}
// Returning Attributes
Element returningAttributesElement = searchParameterElement.element( RETURNING_ATTRIBUTES_TAG );
if ( returningAttributesElement != null )
{
List<String> returningAttributes = new ArrayList<String>();
for ( Iterator<?> i = returningAttributesElement.elementIterator( RETURNING_ATTRIBUTE_TAG ); i.hasNext(); )
{
Element returningAttributeElement = ( Element ) i.next();
Attribute valueAttribute = returningAttributeElement.attribute( VALUE_TAG );
if ( valueAttribute != null )
{
returningAttributes.add( valueAttribute.getValue() );
}
}
searchParameter.setReturningAttributes( returningAttributes
.toArray( new String[returningAttributes.size()] ) );
}
// Scope
Attribute scopeAttribute = searchParameterElement.attribute( SCOPE_TAG );
if ( scopeAttribute != null )
{
try
{
searchParameter.setScope( SearchScope.valueOf( scopeAttribute.getValue() ) );
}
catch ( IllegalArgumentException e )
{
throw new ConnectionIOException( "Unable to parse 'Scope' of search '" + searchParameter.getName()
+ "' as int value. Scope value :" + scopeAttribute.getValue() );
}
}
// Time limit
Attribute timeLimitAttribute = searchParameterElement.attribute( TIME_LIMIT_TAG );
if ( timeLimitAttribute != null )
{
try
{
searchParameter.setTimeLimit( Integer.parseInt( timeLimitAttribute.getValue() ) );
}
catch ( NumberFormatException e )
{
throw new ConnectionIOException( "Unable to parse 'Time limit' of search '" + searchParameter.getName()
+ "' as int value. Time limit value :" + timeLimitAttribute.getValue() );
}
}
// Count limit
Attribute countLimitAttribute = searchParameterElement.attribute( COUNT_LIMIT_TAG );
if ( countLimitAttribute != null )
{
try
{
searchParameter.setCountLimit( Integer.parseInt( countLimitAttribute.getValue() ) );
}
catch ( NumberFormatException e )
{
throw new ConnectionIOException( "Unable to parse 'Count limit' of search '"
+ searchParameter.getName() + "' as int value. Count limit value :"
+ countLimitAttribute.getValue() );
}
}
// Alias dereferencing method
Attribute aliasesDereferencingMethodAttribute = searchParameterElement
.attribute( ALIASES_DEREFERENCING_METHOD_TAG );
if ( aliasesDereferencingMethodAttribute != null )
{
try
{
searchParameter.setAliasesDereferencingMethod( Connection.AliasDereferencingMethod
.valueOf( aliasesDereferencingMethodAttribute.getValue() ) );
}
catch ( IllegalArgumentException e )
{
throw new ConnectionIOException( "Unable to parse 'Aliases Dereferencing Method' of search '"
+ searchParameter.getName() + "' as int value. Aliases Dereferencing Method value :"
+ aliasesDereferencingMethodAttribute.getValue() );
}
}
// Referrals handling method
Attribute referralsHandlingMethodAttribute = searchParameterElement.attribute( REFERRALS_HANDLING_METHOD_TAG );
if ( referralsHandlingMethodAttribute != null )
{
try
{
searchParameter.setReferralsHandlingMethod( Connection.ReferralHandlingMethod
.valueOf( referralsHandlingMethodAttribute.getValue() ) );
}
catch ( IllegalArgumentException e )
{
throw new ConnectionIOException( "Unable to parse 'Referrals Handling Method' of search '"
+ searchParameter.getName() + "' as int value. Referrals Handling Method value :"
+ referralsHandlingMethodAttribute.getValue() );
}
}
// Controls
Element controlsElement = searchParameterElement.element( CONTROLS_TAG );
if ( controlsElement != null )
{
for ( Iterator<?> i = controlsElement.elementIterator( CONTROL_TAG ); i.hasNext(); )
{
Element controlElement = ( Element ) i.next();
Attribute valueAttribute = controlElement.attribute( VALUE_TAG );
if ( valueAttribute != null )
{
byte[] bytes = Base64.decode( valueAttribute.getValue().toCharArray() );
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
try
{
bais = new ByteArrayInputStream( bytes );
ois = new ObjectInputStream( bais );
StudioControl control = ( StudioControl ) ois.readObject();
searchParameter.getControls().add( control );
ois.close();
}
catch ( Exception e )
{
throw new ConnectionIOException( "Unable to parse 'Control' of search '"
+ searchParameter.getName() + "'. Control value :" + valueAttribute.getValue() );
}
}
}
}