Author: kristwaa Date: Fri Mar 13 09:01:22 2009 New Revision: 753176 URL: http://svn.apache.org/viewvc?rev=753176&view=rev Log: DERBY-4073: Creation/configuration of ClientXDataSource fails because of two setSsl methods. Removed the method setSsl(int). Added constants for the valid values for setSsl(String). Documented setSsl(String) and some other methods. Patch file: derby-4073-1a-add_docs_and_remove_setSsl_int.diff Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java Modified: db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java?rev=753176&r1=753175&r2=753176&view=diff ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/jdbc/ClientBaseDataSource.java Fri Mar 13 09:01:22 2009 @@ -173,25 +173,48 @@ //---------------------- client SSL ---------------- + /** The constant indicating that SSL encryption won't be used. */ public final static int SSL_OFF = 0; + private final static String SSL_OFF_STR = "off"; + /** The constant indicating that SSL encryption will be used. */ public final static int SSL_BASIC = 1; + private final static String SSL_BASIC_STR = "basic"; + /** + * The constant indicating that SSL encryption with peer authentication + * will be used. + */ public final static int SSL_PEER_AUTHENTICATION = 2; + private final static String SSL_PEER_AUTHENTICATION_STR = + "peerAuthentication"; + /** + * Parses the string and returns the corresponding constant for the SSL + * mode denoted. + *
+ * Valid values are off, basic and + * peerAuthentication. + * + * @param s string denoting the SSL mode + * @return A constant indicating the SSL mode denoted by the string. If the + * string is {@code null}, {@link #SSL_OFF} is returned. + * @throws SqlException if the string has an invalid value + */ public static final int getSSLModeFromString(String s) throws SqlException { if (s != null){ - if (s.equalsIgnoreCase("off")) { + if (s.equalsIgnoreCase(SSL_OFF_STR)) { return SSL_OFF; - } else if (s.equalsIgnoreCase("basic")) { + } else if (s.equalsIgnoreCase(SSL_BASIC_STR)) { return SSL_BASIC; - } else if (s.equalsIgnoreCase("peerAuthentication")) { + } else if (s.equalsIgnoreCase(SSL_PEER_AUTHENTICATION_STR)) { return SSL_PEER_AUTHENTICATION; } else { - throw new SqlException(null, - new ClientMessageId(SQLState.INVALID_ATTRIBUTE), - Attribute.SSL_ATTR, s, "off, basic, peerAuthentication"); + throw new SqlException(null, + new ClientMessageId(SQLState.INVALID_ATTRIBUTE), + Attribute.SSL_ATTR, s, SSL_OFF_STR + ", " + + SSL_BASIC_STR + ", " + SSL_PEER_AUTHENTICATION_STR); } } else { // Default @@ -199,6 +222,15 @@ } } + /** + * Returns the SSL mode specified by the property object. + * + * @param properties data source properties + * @return A constant indicating the SSL mode to use. Defaults to + * {@link #SSL_OFF} if the SSL attribute isn't specified. + * @throws SqlException if an invalid value for the SSL mode is specified + * in the property object + */ public static final int getClientSSLMode(Properties properties) throws SqlException { @@ -877,25 +909,36 @@ private int sslMode; + /** + * Specifices the SSL encryption mode to use. + *
+ * Valid values are off, basic and + * peerAuthentication. + * + * @param mode the SSL mode to use (off, basic or + * peerAuthentication) + * @throws SqlException if the specified mode is invalid + */ public void setSsl(String mode) throws SqlException { sslMode = getSSLModeFromString(mode); } - public void setSsl(int mode) { - sslMode = mode; - } - + /** + * Returns the SSL encryption mode specified for the data source. + * + * @return off, basic or peerAuthentication. + */ public String getSsl() { switch(sslMode) { case SSL_OFF: default: - return "off"; + return SSL_OFF_STR; case SSL_BASIC: - return "basic"; + return SSL_BASIC_STR; case SSL_PEER_AUTHENTICATION: - return "peerAuthentication"; + return SSL_PEER_AUTHENTICATION_STR; } } @@ -1106,7 +1149,7 @@ setRetrieveMessageText(getRetrieveMessageText(prop)); } if (prop.containsKey(Attribute.SSL_ATTR)) { - setSsl(getClientSSLMode(prop)); + sslMode = getClientSSLMode(prop); } } }