You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by jo...@apache.org on 2013/02/27 13:22:37 UTC
svn commit: r1450756 - in /commons/proper/vfs/trunk/core/src:
main/java/org/apache/commons/vfs2/ main/java/org/apache/commons/vfs2/util/
test/java/org/apache/commons/vfs2/
Author: joehni
Date: Wed Feb 27 12:22:37 2013
New Revision: 1450756
URL: http://svn.apache.org/r1450756
Log:
Revert VFS-266, not the proper time for a refactoring.
Modified:
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/UserAuthenticationData.java
commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/util/UserAuthenticatorUtils.java
commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/UserAuthenticationDataTestCase.java
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties?rev=1450756&r1=1450755&r2=1450756&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/Resources.properties Wed Feb 27 12:22:37 2013
@@ -297,4 +297,3 @@ vfs.selectors/filefilter.missing.error=C
# Utils
vfs.util/find-abstract-file-object.error=Object "{0}" did not extend from AbstractFileObject.
vfs.util/missing-capability.error=The Filesystem do not provide the required capability "{0}"
-vfs.util/incompatible-auth-value.error=The provided preferred value of type "{1}" for the user authentication data type"{0}" is incompatible.
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/UserAuthenticationData.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/UserAuthenticationData.java?rev=1450756&r1=1450755&r2=1450756&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/UserAuthenticationData.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/UserAuthenticationData.java Wed Feb 27 12:22:37 2013
@@ -16,10 +16,9 @@
*/
package org.apache.commons.vfs2;
-import java.lang.reflect.Array;
-import java.util.Arrays;
-import java.util.HashMap;
+import java.util.Iterator;
import java.util.Map;
+import java.util.TreeMap;
/**
* Contains various authentication data.
@@ -33,43 +32,15 @@ public class UserAuthenticationData
{
/** The type name */
private final String type;
- private final Class<?> clazz;
/**
* Creates a new Type.
*
- * @param type the type name
- * @deprecated As of 2.1 use {@link #Type(String, Class)}
+ * @param type the type
*/
- @Deprecated
public Type(final String type)
{
- this(type, char[].class);
- }
-
- /**
- * Creates a new Type.
- *
- * @param type the type name
- * @param clazz the class type
- * @since 2.1
- */
- public Type(final String type, final Class<?> clazz)
- {
this.type = type;
- this.clazz = clazz;
- }
-
- /**
- * Test the provided class type for compatibility.
- *
- * @param clz the class type to check
- * @return {@code true} if class type is assignable
- * @since 2.1
- */
- public final boolean isAssignable(final Class<?> clz)
- {
- return clazz.isAssignableFrom(clz);
}
@Override
@@ -84,12 +55,9 @@ public class UserAuthenticationData
return false;
}
- final Type other = (Type) o;
- if (type != null ? !type.equals(other.type) : other.type != null)
- {
- return false;
- }
- if (clazz != null ? (other.clazz == null || !clazz.getName().equals(other.clazz.getName())) : other.clazz != null)
+ final Type type1 = (Type) o;
+
+ if (type != null ? !type.equals(type1.type) : type1.type != null)
{
return false;
}
@@ -110,11 +78,7 @@ public class UserAuthenticationData
@Override
public int hashCode()
{
- final int prime = 7;
- int result = 1;
- result = prime * result + ((clazz == null) ? 0 : clazz.getName().hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
- return result;
+ return type != null ? type.hashCode() : 0;
}
/**
@@ -129,16 +93,16 @@ public class UserAuthenticationData
}
/** The user name. */
- public static final Type USERNAME = new Type("username", char[].class);
+ public static final Type USERNAME = new Type("username");
/** The password. */
- public static final Type PASSWORD = new Type("password", char[].class);
+ public static final Type PASSWORD = new Type("password");
/** The user's domain. */
- public static final Type DOMAIN = new Type("domain", char[].class);
+ public static final Type DOMAIN = new Type("domain");
/** The authentication data. */
- private final Map<Type, Object> authenticationData = new HashMap<Type, Object>();
+ private final Map<Type, char[]> authenticationData = new TreeMap<Type, char[]>();
/**
* Creates a new uninitialized instance.
@@ -152,65 +116,20 @@ public class UserAuthenticationData
* Sets a data to this collection.
* @param type The Type to add
* @param data The data associated with the Type
- * @deprecated As of 2.1 use {@link #setAuthData(Type, Object)}
*/
- @Deprecated
public void setData(final Type type, final char[] data)
{
- setAuthData(type, data);
+ authenticationData.put(type, data);
}
/**
* Gets a data from the collection.
* @param type The Type to retrieve.
* @return a character array containing the data associated with the type.
- * @deprecated As of 2.1 use {@link #getAuthData(Type)}
*/
- @Deprecated
public char[] getData(final Type type)
{
- return getAuthData(type);
- }
-
- /**
- * Sets a data to this collection.
- * @param type The Type to add
- * @param data The data associated with the Type
- * @return {@code true} if the provided data is compatible with the Type
- * @since 2.1
- */
- public <T> boolean setAuthData(final Type type, final T data)
- {
- if (data == null || type.isAssignable(data.getClass()))
- {
- authenticationData.put(type, data);
- return true;
- }
- return false;
- }
-
- /**
- * Gets a data from the collection.
- * @param type The Type to retrieve.
- * @return the data associated with the Type.
- * @since 2.1
- */
- public <T> T getAuthData(final Type type)
- {
- final T result;
- Object data = authenticationData.get(type);
- if (data != null && type.isAssignable(data.getClass()))
- {
- @SuppressWarnings("unchecked")
- T checked = (T) data;
- result = checked;
- }
- else
- {
- result = null;
- }
-
- return result;
+ return authenticationData.get(type);
}
/**
@@ -218,63 +137,21 @@ public class UserAuthenticationData
*/
public void cleanup()
{
- for(Object data : authenticationData.values())
+ // step 1: nullify character buffers
+ final Iterator<char[]> iterAuthenticationData = authenticationData.values().iterator();
+ while (iterAuthenticationData.hasNext())
{
- if (data == null)
+ final char[] data = iterAuthenticationData.next();
+ if (data == null || data.length < 0)
{
continue;
}
-
- // step 1: nullify arrays
- if (data.getClass().isArray())
+
+ for (int i = 0; i < data.length; i++)
{
- int length = Array.getLength(data);
- if (length == 0)
- {
- continue;
- }
- if (data.getClass().getComponentType().isPrimitive())
- {
- if (data.getClass() == char[].class)
- {
- Arrays.fill((char[])data, '\0');
- }
- else if (data.getClass() == byte[].class)
- {
- Arrays.fill((byte[])data, (byte)0);
- }
- else if (data.getClass() == short[].class)
- {
- Arrays.fill((short[])data, (short)0);
- }
- else if (data.getClass() == int[].class)
- {
- Arrays.fill((int[])data, 0);
- }
- else if (data.getClass() == long[].class)
- {
- Arrays.fill((long[])data, 0L);
- }
- else if (data.getClass() == float[].class)
- {
- Arrays.fill((float[])data, 0.0f);
- }
- else if (data.getClass() == double[].class)
- {
- Arrays.fill((double[])data, 0.0);
- }
- else if (data.getClass() == boolean[].class)
- {
- Arrays.fill((boolean[])data, false);
- }
- }
- else
- {
- Arrays.fill((Object[])data, null);
- }
+ data[i] = 0;
}
}
-
// step 2: allow data itself to gc
authenticationData.clear();
}
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/util/UserAuthenticatorUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/util/UserAuthenticatorUtils.java?rev=1450756&r1=1450755&r2=1450756&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/util/UserAuthenticatorUtils.java (original)
+++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/util/UserAuthenticatorUtils.java Wed Feb 27 12:22:37 2013
@@ -16,7 +16,6 @@
*/
package org.apache.commons.vfs2.util;
-import org.apache.commons.vfs2.FileSystemException;
import org.apache.commons.vfs2.FileSystemOptions;
import org.apache.commons.vfs2.UserAuthenticationData;
import org.apache.commons.vfs2.UserAuthenticator;
@@ -39,45 +38,12 @@ public final class UserAuthenticatorUtil
* @param type The type of the element to retrieve.
* @param overriddenValue The default value.
* @return The data of the given type as a character array or null if the data is not available.
- * @deprecated As of 2.1 use {@link #getAuthData(UserAuthenticationData, org.apache.commons.vfs2.UserAuthenticationData.Type, Object)} instead
*/
- @Deprecated
public static char[] getData(final UserAuthenticationData data, final UserAuthenticationData.Type type,
final char[] overriddenValue)
{
- try
- {
- return getAuthData(data, type, overriddenValue);
- }
- catch (final FileSystemException e)
- {
- return null;
- }
- }
-
- /**
- * Gets data of given type from the UserAuthenticationData or null if there is no data or data of this type
- * available.
- *
- * @param data The UserAuthenticationData.
- * @param type The type of the element to retrieve.
- * @param overriddenValue The default value.
- * @return The data of the given type as a character array or null if the data is not available.
- * @throws FileSystemException if the overridden value is not compatible to the user authentication data type
- * @since 2.1
- */
- public static <T, U extends T> T getAuthData(
- final UserAuthenticationData data, final UserAuthenticationData.Type type, final U overriddenValue)
- throws FileSystemException
- {
if (overriddenValue != null)
{
- if (!type.isAssignable(overriddenValue.getClass()))
- {
- throw new FileSystemException(
- "vfs.util/incompatible-auth-value.error", type.toString(), overriddenValue.getClass().getName());
- }
-
return overriddenValue;
}
@@ -86,7 +52,7 @@ public final class UserAuthenticatorUtil
return null;
}
- return data.getAuthData(type);
+ return data.getData(type);
}
/**
Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/UserAuthenticationDataTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/UserAuthenticationDataTestCase.java?rev=1450756&r1=1450755&r2=1450756&view=diff
==============================================================================
--- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/UserAuthenticationDataTestCase.java (original)
+++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/UserAuthenticationDataTestCase.java Wed Feb 27 12:22:37 2013
@@ -23,7 +23,7 @@ import org.junit.Test;
public class UserAuthenticationDataTestCase
{
@Test
- public void testCharacterBasedDataWithLegacyMethods()
+ public void testCharacterBasedData()
{
UserAuthenticationData data = new UserAuthenticationData();
char[] array = "PMC".toCharArray();
@@ -43,49 +43,12 @@ public class UserAuthenticationDataTestC
}
@Test
- public void testCharacterBasedData()
- {
- UserAuthenticationData data = new UserAuthenticationData();
- char[] array = "PMC".toCharArray();
- data.setAuthData(UserAuthenticationData.USERNAME, array);
- data.setAuthData(UserAuthenticationData.DOMAIN, "Apache".toCharArray());
- assertSame(array, data.getAuthData(UserAuthenticationData.USERNAME));
- assertArrayEquals("Apache".toCharArray(), data.<char[]>getAuthData(UserAuthenticationData.DOMAIN));
- data.setAuthData(UserAuthenticationData.DOMAIN, "Apache Commons".toCharArray());
- assertArrayEquals("Apache Commons".toCharArray(), data.<char[]>getAuthData(UserAuthenticationData.DOMAIN));
- assertNull(data.getAuthData(UserAuthenticationData.PASSWORD));
-
- data.cleanup();
- assertNull(data.getAuthData(UserAuthenticationData.USERNAME));
- assertNull(data.getAuthData(UserAuthenticationData.DOMAIN));
- char[] nulls = {0,0,0};
- assertArrayEquals(nulls, array);
- }
-
- @Test
- public void testCustomTypeWithArray()
- {
- UserAuthenticationData.Type type = new UserAuthenticationData.Type("JUNIT", UserAuthenticationDataTestCase[].class);
- UserAuthenticationData data = new UserAuthenticationData();
- UserAuthenticationDataTestCase[] array = { this };
- data.setAuthData(type, array);
- assertSame(array, data.getAuthData(type));
-
- data.cleanup();
- UserAuthenticationDataTestCase[] nulls = { null };
- assertArrayEquals(nulls, array);
- }
-
- @Test
- public void testCustomTypeWithHierarchy()
+ public void testCustomType()
{
- UserAuthenticationData.Type type = new UserAuthenticationData.Type("JUNIT", CharSequence.class);
+ UserAuthenticationData.Type type = new UserAuthenticationData.Type("JUNIT");
UserAuthenticationData data = new UserAuthenticationData();
- assertTrue(data.setAuthData(type, "test"));
- assertEquals("test", data.getAuthData(type));
- assertFalse(data.setAuthData(type, Integer.valueOf(42)));
- assertEquals("test", data.getAuthData(type));
- assertTrue(data.setAuthData(type, null));
- assertNull(data.getAuthData(type));
+ char[] array = "test".toCharArray();
+ data.setData(type, array);
+ assertSame(array, data.getData(type));
}
}