diff --git a/spring-ldap-odm/build-original.xml b/spring-ldap-odm/build-original.xml deleted file mode 100644 index 5c8174ca..00000000 --- a/spring-ldap-odm/build-original.xml +++ /dev/null @@ -1,169 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java index 1139dd31..3f5319f6 100644 --- a/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java +++ b/spring-ldap-odm/src/itest/java/org/springframework/ldap/odm/dao/LdapDaoITest.java @@ -30,7 +30,7 @@ public class LdapDaoITest extends AbstractLdapTemplateIntegrationTest LOGGER.debug("********************INIT TEST CLASS**************************"); return new String[]{"beans.xml"}; } - + protected void onSetUp() throws Exception { super.onSetUp(); diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImpl.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImpl.java index 66e73315..f8793ddc 100644 --- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImpl.java +++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/mapping/ObjectDirectoryMapperImpl.java @@ -12,10 +12,10 @@ import org.springframework.beans.TypeMismatchException; import org.springframework.core.MethodParameter; import org.springframework.ldap.core.DirContextAdapter; import org.springframework.ldap.core.DistinguishedName; +import org.springframework.ldap.odm.typeconversion.ConversionType; import org.springframework.ldap.odm.typeconversion.LdapTypeConverter; +import org.springframework.ldap.odm.typeconversion.MultiValueType; import org.springframework.ldap.odm.typeconversion.ReferencedEntryEditorFactory; -import org.springframework.ldap.odm.typeconversion.ValidConversionType; -import org.springframework.ldap.odm.typeconversion.ValidContainerType; import org.springframework.ldap.odm.util.AttributeWrapper; import org.springframework.util.StringUtils; @@ -108,7 +108,7 @@ public class ObjectDirectoryMapperImpl implements ObjectDirectoryMapper { ctxAdapter.setAttributeValue(attributeName, beanPropertyValue); } - else if (ValidContainerType.isImplementedBy(beanPropertyValue.getClass())) + else if (MultiValueType.isAssignableTo(beanPropertyValue.getClass())) { ctxAdapter.setAttributeValues(attributeName, typeConverter.getAllAsText(beanPropertyValue)); @@ -211,7 +211,7 @@ public class ObjectDirectoryMapperImpl implements ObjectDirectoryMapper { for (Method getter : propertyGetters.values()) { - if (!ValidConversionType.isValidConversionType(getter.getReturnType())) + if (!ConversionType.isConversionType(getter.getReturnType())) { try { @@ -225,8 +225,8 @@ public class ObjectDirectoryMapperImpl implements ObjectDirectoryMapper + getter.getName() + "() has invalid return type. Return type must be a directory " + "mapped object, or one of the following: \n\n" - + ValidConversionType.listTypes() + "\n\n" - + ValidContainerType.listTypes(), e); + + ConversionType.listTypes() + "\n\n" + + MultiValueType.listTypes(), e); } } } diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ValidConversionType.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ConversionType.java similarity index 70% rename from spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ValidConversionType.java rename to spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ConversionType.java index 30ef32e6..16759f7d 100644 --- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ValidConversionType.java +++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ConversionType.java @@ -12,7 +12,7 @@ import java.util.Date; /** This list of types supported for mapping between ldap attributes and bean properties. */ -public enum ValidConversionType +public enum ConversionType { BYTE_ARRAY(byte[].class), BOOLEAN(Boolean.class), @@ -32,9 +32,9 @@ public enum ValidConversionType private final Class clazz; - ValidConversionType(Class validType) + ConversionType(Class type) { - this.clazz = validType; + this.clazz = type; } @@ -42,13 +42,13 @@ public enum ValidConversionType public static String listTypes() { StringBuilder sb = new StringBuilder(); - sb.append("VALID CONVERSION TYPES: "); - for (int i = 0; i < ValidConversionType.values().length; i++) + sb.append("CONVERSION TYPES: "); + for (int i = 0; i < values().length; i++) { - ValidConversionType validType = ValidConversionType.values()[i]; + ConversionType type = values()[i]; sb.append("\n"); - sb.append(validType.clazz.getSimpleName()); - if (i != ValidConversionType.values().length - 1) + sb.append(type.clazz.getSimpleName()); + if (i != values().length - 1) { sb.append(","); } @@ -57,11 +57,11 @@ public enum ValidConversionType } /** Returns true if the argument is a member of this enumeration. */ - public static boolean isValidConversionType(Class returnType) + public static boolean isConversionType(Class candidate) { - for (ValidConversionType type : ValidConversionType.values()) + for (ConversionType type : values()) { - if (returnType.equals(type.clazz)) + if (candidate.equals(type.clazz)) { return true; } diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/LdapTypeConverter.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/LdapTypeConverter.java index 78add002..7c84b1dc 100644 --- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/LdapTypeConverter.java +++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/LdapTypeConverter.java @@ -69,6 +69,7 @@ public class LdapTypeConverter extends SimpleTypeConverter } } + /** Convert a collection or Array of objects to their string representation */ public String[] getAllAsText(Object values) { if (values instanceof Collection) @@ -80,10 +81,7 @@ public class LdapTypeConverter extends SimpleTypeConverter return getAllAsText((Object[]) values); } } - - /** - * Convert Object array to String array - */ + private String[] getAllAsText(Object[] values) { String[] textValues = new String[values.length]; diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/LoadPolicy.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/LoadPolicy.java index f14b39cd..2475e2a7 100644 --- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/LoadPolicy.java +++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/LoadPolicy.java @@ -10,3 +10,9 @@ public enum LoadPolicy { THROW_REFERENTIAL_INTEGRITY_EXCEPTIONS, SUPPRESS_REFERENTIAL_INTEGRITY_EXCEPTIONS } +/* + * Copyright 2005 by Majitek. All Rights Reserved. + * + * This software is the proprietary information of Majitek. Use is subject to license terms. + */ + diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ValidContainerType.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/MultiValueType.java similarity index 76% rename from spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ValidContainerType.java rename to spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/MultiValueType.java index e7cd1f83..cef581e8 100644 --- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ValidContainerType.java +++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/MultiValueType.java @@ -10,7 +10,7 @@ import java.util.List; import java.util.Set; import java.util.Collection; -public enum ValidContainerType +public enum MultiValueType { ARRAY(Object[].class), COLLECTION(Collection.class), @@ -19,7 +19,7 @@ public enum ValidContainerType private final Class clazz; - ValidContainerType(Class clazz) + MultiValueType(Class clazz) { this.clazz = clazz; } @@ -30,10 +30,10 @@ public enum ValidContainerType public static String listTypes() { StringBuilder sb = new StringBuilder(); - sb.append("VALID MULTI-VALUE CONTAINER TYPES:"); + sb.append("MULTI-VALUE TYPES:"); for (int i = 0; i < values().length; i++) { - ValidContainerType validType = values()[i]; + MultiValueType validType = values()[i]; sb.append("\n"); sb.append(validType.clazz.getSimpleName()); if (i != values().length - 1) @@ -47,9 +47,9 @@ public enum ValidContainerType /** * Returns true if the argument is a member of this enumeration. */ - public static boolean isValidContainerType(Class returnType) + public static boolean isMultiValueType(Class returnType) { - for (ValidContainerType type : values()) + for (MultiValueType type : values()) { if (returnType.equals(type.clazz)) { @@ -59,9 +59,9 @@ public enum ValidContainerType return false; } - public static boolean isImplementedBy(Class returnType) + public static boolean isAssignableTo(Class returnType) { - for (ValidContainerType type : values()) + for (MultiValueType type : values()) { if (type.clazz.isAssignableFrom(returnType)) { diff --git a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ReferentialIntegrityException.java b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ReferentialIntegrityException.java index 4dc71314..e729db69 100644 --- a/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ReferentialIntegrityException.java +++ b/spring-ldap-odm/src/main/java/org/springframework/ldap/odm/typeconversion/ReferentialIntegrityException.java @@ -18,3 +18,10 @@ public class ReferentialIntegrityException extends RuntimeException super(message, cause); } } +/* + * Copyright 2005 by Majitek. All Rights Reserved. + * + * This software is the proprietary information of Majitek. Use is subject to license terms. + */ + + diff --git a/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/ConversionTypeTest.java b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/ConversionTypeTest.java new file mode 100644 index 00000000..58be046f --- /dev/null +++ b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/ConversionTypeTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2005 by Majitek. All Rights Reserved. + * + * This software is the proprietary information of Majitek. Use is subject to license terms. + */ + +package org.springframework.ldap.odm.typeconversion; + +import junit.framework.TestCase; +import junit.framework.Assert; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.springframework.ldap.core.DistinguishedName; +import javax.naming.ldap.LdapName; +import java.util.Date; +import java.util.List; + +public class ConversionTypeTest extends TestCase +{ + private static final Log LOGGER = LogFactory.getLog(ConversionTypeTest.class); + + public void testListTypes() + { + LOGGER.debug(ConversionType.listTypes()); + } + + public void testIsConversionType() + { + Assert.assertFalse(ConversionType.isConversionType(List.class)); + + Assert.assertTrue(ConversionType.isConversionType(byte[].class)); + Assert.assertTrue(ConversionType.isConversionType(Boolean.class)); + Assert.assertTrue(ConversionType.isConversionType(String.class)); + Assert.assertTrue(ConversionType.isConversionType(String[].class)); + Assert.assertTrue(ConversionType.isConversionType(Date.class)); + Assert.assertTrue(ConversionType.isConversionType(Date[].class)); + Assert.assertTrue(ConversionType.isConversionType(LdapName.class)); + Assert.assertTrue(ConversionType.isConversionType(LdapName[].class)); + Assert.assertTrue(ConversionType.isConversionType(DistinguishedName.class)); + Assert.assertTrue(ConversionType.isConversionType(DistinguishedName[].class)); + Assert.assertTrue(ConversionType.isConversionType(Integer.class)); + Assert.assertTrue(ConversionType.isConversionType(Integer[].class)); + Assert.assertTrue(ConversionType.isConversionType(Long.class)); + Assert.assertTrue(ConversionType.isConversionType(Long[].class)); + } + + +} diff --git a/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/LdapTypeConverterTest.java b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/LdapTypeConverterTest.java index 2826579a..9fde43ac 100644 --- a/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/LdapTypeConverterTest.java +++ b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/LdapTypeConverterTest.java @@ -12,6 +12,7 @@ import java.util.Arrays; import java.util.Date; import java.util.List; import java.util.Set; +import java.util.HashSet; import java.lang.reflect.Method; import javax.naming.InvalidNameException; @@ -40,7 +41,7 @@ public class LdapTypeConverterTest extends TestCase typeConverter = new LdapTypeConverter(); } - public void testConvertToByteArray() + public void testPassthroughOfByteArray() { byte[] objectToTranslate = "fred".getBytes(); @@ -57,7 +58,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToBoolean() + public void testConvertStringToBoolean() { String objectToTranslate = "true"; try @@ -73,7 +74,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertFromBoolean() + public void testConvertBooleanToString() { boolean objectToTranslate = false; try @@ -88,7 +89,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToString() + public void testPassthroughOfString() { String objectToTranslate = "onetwothree"; try @@ -103,7 +104,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToStringArray() + public void testPassthroughOfStringArray() { String object1 = "onetwothree"; String object2 = "fourfivesix"; @@ -122,7 +123,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToListOfStrings() + public void testConvertStringArrayToListOfStrings() { String object1 = "onetwothree"; String object2 = "fourfivesix"; @@ -142,7 +143,7 @@ public class LdapTypeConverterTest extends TestCase } - public void testConvertToSetOfStrings() + public void testConvertStringArrayToSetOfStrings() { String object1 = "onetwothree"; String object2 = "fourfivesix"; @@ -164,7 +165,7 @@ public class LdapTypeConverterTest extends TestCase - public void testConvertToDate() throws ParseException + public void testConvertStringToDate() throws ParseException { String object1 = "19700101100000.000+1000"; @@ -181,7 +182,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertFromDate() + public void testConvertDateToString() { Date source = new Date(1184283822285L); //Friday July 13, 2007 9:43:42 AM GMT+1000 LOGGER.debug(typeConverter.getAsText(source)); @@ -190,7 +191,7 @@ public class LdapTypeConverterTest extends TestCase .matches("20070713\\d\\d\\d\\d42.285\\+\\d\\d\\d\\d")); } - public void testConvertToDateArray() throws ParseException + public void testConvertStringArrayToDateArray() throws ParseException { String object1 = "20071105093655.0+1000"; String object2 = "19700101100000.0+1000"; @@ -210,7 +211,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testGeneralizedTimeToListOfDates() throws ParseException, NoSuchMethodException + public void testConvertGeneralizedTimeArrayToListOfDates() throws ParseException, NoSuchMethodException { String object1 = "20071105093655.0+1000"; String object2 = "19700101100000.0+1000"; @@ -234,7 +235,7 @@ public class LdapTypeConverterTest extends TestCase } - public void testConvertFromDateArray() + public void testConvertDateArrayToStringArray() { Date date1 = new Date(1184283822285L); //Friday July 13, 2007 9:43:42 AM + GMT+1000 Date date2 = new Date(0); //epoch + GMT + 1000 @@ -245,7 +246,21 @@ public class LdapTypeConverterTest extends TestCase Assert.assertTrue(converted[1].matches("19700101\\d\\d\\d\\d00.000\\+\\d\\d\\d\\d")); } - public void testConvertToLdapName() + public void testConvertDateCollectionToStringArray() + { + Date date1 = new Date(1184283822285L); //Friday July 13, 2007 9:43:42 AM + GMT+1000 + Date date2 = new Date(0); //epoch + GMT + 1000 + + Set dates = new HashSet(); + dates.add(date1); + dates.add(date2); + String[] converted = typeConverter.getAllAsText(dates); + Assert.assertTrue(converted[0].matches("20070713\\d\\d\\d\\d42.285\\+\\d\\d\\d\\d")); + Assert.assertTrue(converted[1].matches("19700101\\d\\d\\d\\d00.000\\+\\d\\d\\d\\d")); + } + + + public void testConvertStringToLdapName() { String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com"; try @@ -264,7 +279,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToLdapNameArray() + public void testConvertStringArrayToLdapNameArray() { String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com"; String object2 = "uid=fred, ou = people, dc = myretsu,dc=com"; @@ -286,7 +301,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToDistinguishedName() + public void testConvertStringToDistinguishedName() { String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com"; try @@ -301,7 +316,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToDistinguishedNameArray() + public void testConvertStringArrayToDistinguishedNameArray() { String object1 = "uid=amAdmin, ou = people, dc = myretsu,dc=com"; String object2 = "uid=fred, ou = people, dc = myretsu,dc=com"; @@ -319,7 +334,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToLong() + public void testConvertStringToLong() { String object1 = "9887342"; try @@ -334,7 +349,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToLongArray() + public void testConvertStringArrayToLongArray() { String object1 = "878787"; String object2 = "23948787"; @@ -353,7 +368,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToInteger() + public void testConvertStringToInteger() { String object1 = "9887342"; @@ -369,7 +384,7 @@ public class LdapTypeConverterTest extends TestCase } } - public void testConvertToIntegerArray() + public void testConvertStringArrayToIntegerArray() { String object1 = "878787"; String object2 = "23948787"; diff --git a/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/MultiValueTypeTest.java b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/MultiValueTypeTest.java new file mode 100644 index 00000000..9a145765 --- /dev/null +++ b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/MultiValueTypeTest.java @@ -0,0 +1,46 @@ +/* + * Copyright 2005 by Majitek. All Rights Reserved. + * + * This software is the proprietary information of Majitek. Use is subject to license terms. + */ + +package org.springframework.ldap.odm.typeconversion; + +import junit.framework.TestCase; +import junit.framework.Assert; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.HashSet; +import java.util.ArrayList; + +public class MultiValueTypeTest extends TestCase +{ + private static final Log LOGGER = LogFactory.getLog(MultiValueTypeTest.class); + + public void testListTypes() + { + LOGGER.debug(MultiValueType.listTypes()); + } + + public void testIsMultiValueType() + { + Assert.assertFalse(MultiValueType.isMultiValueType(String.class)); + Assert.assertTrue(MultiValueType.isMultiValueType(Object[].class)); + Assert.assertTrue(MultiValueType.isMultiValueType(Collection.class)); + Assert.assertTrue(MultiValueType.isMultiValueType(List.class)); + Assert.assertTrue(MultiValueType.isMultiValueType(Set.class)); + } + + public void testIsAssignableTo() + { + Assert.assertFalse(MultiValueType.isAssignableTo(String.class)); + Assert.assertTrue(MultiValueType.isAssignableTo(ArrayList.class)); + Assert.assertTrue(MultiValueType.isAssignableTo(HashSet.class)); + } + + +} diff --git a/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/ValidConversionTypeTest.java b/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/ValidConversionTypeTest.java deleted file mode 100644 index a5241bc5..00000000 --- a/spring-ldap-odm/src/test/java/org/springframework/ldap/odm/typeconversion/ValidConversionTypeTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2005 by Majitek. All Rights Reserved. - * - * This software is the proprietary information of Majitek. Use is subject to license terms. - */ - -package org.springframework.ldap.odm.typeconversion; - -import junit.framework.TestCase; -import junit.framework.Assert; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.ldap.core.DistinguishedName; -import javax.naming.ldap.LdapName; -import java.util.Date; -import java.util.List; - -public class ValidConversionTypeTest extends TestCase -{ - private static final Log LOGGER = LogFactory.getLog(ValidConversionTypeTest.class); - - public void testListTypes() - { - LOGGER.debug(ValidConversionType.listTypes()); - } - - public void testIsValidConversionType() - { - Assert.assertFalse(ValidConversionType.isValidConversionType(List.class)); - - Assert.assertTrue(ValidConversionType.isValidConversionType(byte[].class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(Boolean.class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(String.class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(String[].class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(Date.class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(Date[].class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(LdapName.class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(LdapName[].class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(DistinguishedName.class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(DistinguishedName[].class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(Integer.class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(Integer[].class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(Long.class)); - Assert.assertTrue(ValidConversionType.isValidConversionType(Long[].class)); - } - - -}