* @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() //$NON-NLS-1$
+ "' as int value. Port value :" + portAttribute.getValue() ); //$NON-NLS-1$
}
}
// 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 '" //$NON-NLS-1$
+ connection.getName() + "' as int value. Encryption Method value :" //$NON-NLS-1$
+ 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 '" //$NON-NLS-1$
+ connection.getName() + "' as int value. Authentication Method value :" //$NON-NLS-1$
+ 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() );
}
// SASL Realm
Attribute saslRealmAttribute = element.attribute( SASL_REALM_TAG );
if ( saslRealmAttribute != null )
{
connection.setSaslRealm( saslRealmAttribute.getValue() );
}
// SASL Quality of Protection
Attribute saslQopAttribute = element.attribute( SASL_QOP_TAG );
if ( saslQopAttribute != null )
{
connection.setSaslQop( SaslQop.valueOf( saslQopAttribute.getValue() ) );
}
// SASL Security Strength
Attribute saslSecStrengthAttribute = element.attribute( SASL_SEC_STRENGTH_TAG );
if ( saslSecStrengthAttribute != null )
{
connection.setSaslSecurityStrength( SaslSecurityStrength.valueOf( saslSecStrengthAttribute.getValue() ) );
}
// SASL Mutual Authentication
Attribute saslMutualAuthAttribute = element.attribute( SASL_MUTUAL_AUTH_TAG );
if ( saslMutualAuthAttribute != null )
{
connection.setSaslMutualAuthentication( Boolean.parseBoolean( saslMutualAuthAttribute.getValue() ) );
}
// KRB5 Credentials Conf
Attribute krb5CredentialsConf = element.attribute( KRB5_CREDENTIALS_CONF_TAG );
if ( krb5CredentialsConf != null )
{
connection.setKrb5CredentialConfiguration( Krb5CredentialConfiguration.valueOf( krb5CredentialsConf
.getValue() ) );
}
// KRB5 Configuration
Attribute krb5Config = element.attribute( KRB5_CONFIG_TAG );
if ( krb5Config != null )
{
connection.setKrb5Configuration( Krb5Configuration.valueOf( krb5Config.getValue() ) );
}
// KRB5 Configuration File
Attribute krb5ConfigFile = element.attribute( KRB5_CONFIG_FILE_TAG );
if ( krb5ConfigFile != null )
{
connection.setKrb5ConfigurationFile( krb5ConfigFile.getValue() );
}
// KRB5 REALM
Attribute krb5Realm = element.attribute( KRB5_REALM_TAG );
if ( krb5Realm != null )
{
connection.setKrb5Realm( krb5Realm.getValue() );
}
// KRB5 KDC Host
Attribute krb5KdcHost = element.attribute( KRB5_KDC_HOST_TAG );
if ( krb5KdcHost != null )
{
connection.setKrb5KdcHost( krb5KdcHost.getValue() );
}
// KRB5 KDC Port
Attribute krb5KdcPort = element.attribute( KRB5_KDC_PORT_TAG );
if ( krb5KdcPort != null )
{
connection.setKrb5KdcPort( Integer.valueOf( krb5KdcPort.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;