* @throws ConnectionIOException
* if an error occurs when converting values
*/
private static ConnectionParameter readConnection( Element element ) throws ConnectionIOException
{
ConnectionParameter connection = new ConnectionParameter();
// ID
Attribute idAttribute = element.attribute( ID_TAG );
if ( idAttribute != null )
{
connection.setId( idAttribute.getValue() );
}
// Name
Attribute nameAttribute = element.attribute( NAME_TAG );
if ( nameAttribute != null )
{
connection.setName( nameAttribute.getValue() );
}
// Host
Attribute hostAttribute = element.attribute( HOST_TAG );
if ( hostAttribute != null )
{
connection.setHost( hostAttribute.getValue() );
}
// Port
Attribute portAttribute = element.attribute( PORT_TAG );
if ( portAttribute != null )
{
try
{
connection.setPort( Integer.parseInt( portAttribute.getValue() ) );
}
catch ( NumberFormatException e )
{
throw new ConnectionIOException( "Unable to parse 'Port' of connection '" + connection.getName()
+ "' as int value. Port value :" + portAttribute.getValue() );
}
}
// Encryption Method
Attribute encryptionMethodAttribute = element.attribute( ENCRYPTION_METHOD_TAG );
if ( encryptionMethodAttribute != null )
{
try
{
connection.setEncryptionMethod( EncryptionMethod.valueOf( encryptionMethodAttribute.getValue() ) );
}
catch ( IllegalArgumentException e )
{
throw new ConnectionIOException( "Unable to parse 'Encryption Method' of connection '"
+ connection.getName() + "' as int value. Encryption Method value :"
+ encryptionMethodAttribute.getValue() );
}
}
// Auth Method
Attribute authMethodAttribute = element.attribute( AUTH_METHOD_TAG );
if ( authMethodAttribute != null )
{
try
{
connection.setAuthMethod( AuthenticationMethod.valueOf( authMethodAttribute.getValue() ) );
}
catch ( IllegalArgumentException e )
{
throw new ConnectionIOException( "Unable to parse 'Authentication Method' of connection '"
+ connection.getName() + "' as int value. Authentication Method value :"
+ authMethodAttribute.getValue() );
}
}
// Bind Principal
Attribute bindPrincipalAttribute = element.attribute( BIND_PRINCIPAL_TAG );
if ( bindPrincipalAttribute != null )
{
connection.setBindPrincipal( bindPrincipalAttribute.getValue() );
}
// Bind Password
Attribute bindPasswordAttribute = element.attribute( BIND_PASSWORD_TAG );
if ( bindPasswordAttribute != null )
{
connection.setBindPassword( bindPasswordAttribute.getValue() );
}
// Extended Properties
Element extendedPropertiesElement = element.element( EXTENDED_PROPERTIES_TAG );
if ( extendedPropertiesElement != null )
{
for ( Iterator<?> i = extendedPropertiesElement.elementIterator( EXTENDED_PROPERTY_TAG ); i.hasNext(); )
{
Element extendedPropertyElement = ( Element ) i.next();
Attribute keyAttribute = extendedPropertyElement.attribute( KEY_TAG );
Attribute valueAttribute = extendedPropertyElement.attribute( VALUE_TAG );
if ( keyAttribute != null && valueAttribute != null )
{
connection.setExtendedProperty( keyAttribute.getValue(), valueAttribute.getValue() );
}
}
}
return connection;