├── .gitignore ├── .project ├── .travis.yml ├── AUTHORS ├── README.md ├── core ├── dependency-reduced-pom.xml ├── pom.xml └── src │ ├── main │ ├── assembly │ │ └── bin.xml │ ├── java │ │ └── ma │ │ │ └── glasnost │ │ │ └── orika │ │ │ ├── BoundMapperFacade.java │ │ │ ├── Converter.java │ │ │ ├── ConverterException.java │ │ │ ├── CustomConverter.java │ │ │ ├── CustomMapper.java │ │ │ ├── DefaultFieldMapper.java │ │ │ ├── MapEntry.java │ │ │ ├── MappedTypePair.java │ │ │ ├── Mapper.java │ │ │ ├── MapperBase.java │ │ │ ├── MapperFacade.java │ │ │ ├── MapperFactory.java │ │ │ ├── MappingContext.java │ │ │ ├── MappingContextFactory.java │ │ │ ├── MappingException.java │ │ │ ├── MappingHint.java │ │ │ ├── ObjectFactory.java │ │ │ ├── OrikaSystemProperties.java │ │ │ ├── Properties.java │ │ │ ├── constructor │ │ │ ├── converter │ │ │ ├── BidirectionConverter.java │ │ │ ├── BidirectionalConverter.java │ │ │ ├── Converter.java │ │ │ ├── ConverterFactory.java │ │ │ ├── CustomConverterBase.java │ │ │ ├── DefaultConverterFactory.java │ │ │ ├── TypeConverter.java │ │ │ └── builtin │ │ │ │ ├── BuiltinConverters.java │ │ │ │ ├── CloneableConverter.java │ │ │ │ ├── ConstructorConverter.java │ │ │ │ ├── CopyByReferenceConverter.java │ │ │ │ ├── DateAndTimeConverters.java │ │ │ │ ├── DateToStringConverter.java │ │ │ │ ├── EnumConverter.java │ │ │ │ ├── FromStringConverter.java │ │ │ │ ├── NumericConverters.java │ │ │ │ ├── PassThroughConverter.java │ │ │ │ ├── StringToCharacterConverter.java │ │ │ │ ├── StringToEnumConverter.java │ │ │ │ ├── ToStringConverter.java │ │ │ │ └── WrapperToPrimitiveConverter.java │ │ │ ├── impl │ │ │ ├── Comparators.java │ │ │ ├── ConfigurableMapper.java │ │ │ ├── DefaultBoundMapperFacade.java │ │ │ ├── DefaultCodeGenerationStrategy.java │ │ │ ├── DefaultConstructorObjectFactory.java │ │ │ ├── DefaultMapperFactory.java │ │ │ ├── ExceptionUtility.java │ │ │ ├── GeneratedMapperBase.java │ │ │ ├── GeneratedObjectBase.java │ │ │ ├── GeneratedObjectFactory.java │ │ │ ├── MapperFacadeImpl.java │ │ │ ├── NonCyclicBoundMapperFacade.java │ │ │ ├── ReversedMapper.java │ │ │ ├── Specifications.java │ │ │ ├── UtilityResolver.java │ │ │ ├── generator │ │ │ │ ├── AggregateSpecification.java │ │ │ │ ├── CodeGenerationStrategy.java │ │ │ │ ├── CompilerStrategy.java │ │ │ │ ├── EclipseJdtCompilerStrategy.java │ │ │ │ ├── JavassistCompilerStrategy.java │ │ │ │ ├── MapEntryRef.java │ │ │ │ ├── MapperGenerator.java │ │ │ │ ├── MultiOccurrenceVariableRef.java │ │ │ │ ├── Node.java │ │ │ │ ├── ObjectFactoryGenerator.java │ │ │ │ ├── SourceCodeContext.java │ │ │ │ ├── Specification.java │ │ │ │ ├── UsedConvertersContext.java │ │ │ │ ├── UsedMapperFacadesContext.java │ │ │ │ ├── UsedTypesContext.java │ │ │ │ ├── VariableRef.java │ │ │ │ └── specification │ │ │ │ │ ├── AbstractSpecification.java │ │ │ │ │ ├── AnyTypeToString.java │ │ │ │ │ ├── ApplyRegisteredMapper.java │ │ │ │ │ ├── ArrayOrCollectionToArray.java │ │ │ │ │ ├── ArrayOrCollectionToCollection.java │ │ │ │ │ ├── ArrayOrCollectionToMap.java │ │ │ │ │ ├── Convert.java │ │ │ │ │ ├── CopyByReference.java │ │ │ │ │ ├── EnumToEnum.java │ │ │ │ │ ├── MapToArray.java │ │ │ │ │ ├── MapToCollection.java │ │ │ │ │ ├── MapToMap.java │ │ │ │ │ ├── MultiOccurrenceElementToObject.java │ │ │ │ │ ├── MultiOccurrenceToMultiOccurrence.java │ │ │ │ │ ├── ObjectToMultiOccurrenceElement.java │ │ │ │ │ ├── ObjectToObject.java │ │ │ │ │ ├── PrimitiveAndObject.java │ │ │ │ │ ├── StringToEnum.java │ │ │ │ │ ├── StringToStringConvertible.java │ │ │ │ │ └── UnmappableEnum.java │ │ │ ├── mapping │ │ │ │ └── strategy │ │ │ │ │ ├── CopyByReferenceStrategy.java │ │ │ │ │ ├── InstantiateAndUseCustomMapperStrategy.java │ │ │ │ │ ├── InstantiateByDefaultAndUseCustomMapperStrategy.java │ │ │ │ │ ├── MapExistingAndUseCustomMapperStrategy.java │ │ │ │ │ ├── MappingStrategy.java │ │ │ │ │ ├── MappingStrategyKey.java │ │ │ │ │ ├── MappingStrategyRecorder.java │ │ │ │ │ ├── UseConverterStrategy.java │ │ │ │ │ └── UseCustomMapperStrategy.java │ │ │ └── util │ │ │ │ ├── ClassUtil.java │ │ │ │ └── StringUtil.java │ │ │ ├── inheritance │ │ │ ├── DefaultSuperTypeResolverStrategy.java │ │ │ ├── SuperTypeResolver.java │ │ │ └── SuperTypeResolverStrategy.java │ │ │ ├── metadata │ │ │ ├── ArrayElementProperty.java │ │ │ ├── ClassMap.java │ │ │ ├── ClassMapBuilder.java │ │ │ ├── ClassMapBuilderFactory.java │ │ │ ├── ClassMapBuilderForArrays.java │ │ │ ├── ClassMapBuilderForLists.java │ │ │ ├── ClassMapBuilderForMaps.java │ │ │ ├── ConverterKey.java │ │ │ ├── FieldMap.java │ │ │ ├── FieldMapBuilder.java │ │ │ ├── ListElementProperty.java │ │ │ ├── MapKeyProperty.java │ │ │ ├── MapperKey.java │ │ │ ├── MappingDirection.java │ │ │ ├── NestedElementProperty.java │ │ │ ├── NestedProperty.java │ │ │ ├── Property.java │ │ │ ├── ScoringClassMapBuilder.java │ │ │ ├── Type.java │ │ │ ├── TypeBuilder.java │ │ │ ├── TypeFactory.java │ │ │ ├── TypeKey.java │ │ │ └── TypeUtil.java │ │ │ ├── property │ │ │ ├── IntrospectorPropertyResolver.java │ │ │ ├── PropertyResolver.java │ │ │ ├── PropertyResolverStrategy.java │ │ │ └── RegexPropertyResolver.java │ │ │ ├── unenhance │ │ │ ├── BaseUnenhancer.java │ │ │ ├── HibernateUnenhanceStrategy.java │ │ │ └── UnenhanceStrategy.java │ │ │ └── util │ │ │ ├── Cache.java │ │ │ ├── CacheLRULinkedHashMap.java │ │ │ ├── SortedCollection.java │ │ │ └── SortedSet.java │ └── resources │ │ └── META-INF │ │ ├── javassist.LICENSE.txt │ │ └── paranamer.LICENSE.txt │ └── test │ └── java-hidden │ └── types │ ├── AuthorHidden.java │ ├── BookHidden.java │ ├── LibraryHidden.java │ └── Runner.java ├── eclipse-tools ├── .settings │ ├── org.eclipse.core.resources.prefs │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs ├── pom.xml └── src │ └── main │ ├── java │ └── ma │ │ └── glasnost │ │ └── orika │ │ └── impl │ │ └── generator │ │ ├── ByteCodeClassLoader.java │ │ ├── EclipseJdtCompiler.java │ │ ├── FilePathUtility.java │ │ └── eclipsejdt │ │ ├── CompilationUnit.java │ │ ├── CompilerRequestor.java │ │ └── NameEnvironment.java │ └── resources │ └── formatter-prefs │ └── preferences.xml ├── misc └── orika-formatter.xml ├── pom.xml └── tests ├── pom.xml └── src └── main ├── java-hidden ├── dtotypes │ ├── AuthorHiddenDto.java │ ├── BookHiddenDto.java │ ├── LibraryHiddenDto.java │ └── Runner.java └── types │ ├── AuthorHidden.java │ ├── BookHidden.java │ ├── LibraryHidden.java │ └── Runner.java ├── java └── ma │ └── glasnost │ └── orika │ ├── examples │ ├── Example1TestCase.java │ └── Example2TestCase.java │ └── test │ ├── ConcurrentRule.java │ ├── DynamicSuite.java │ ├── HibernateUtil.java │ ├── MappingUtil.java │ ├── MavenProjectUtil.java │ ├── TestCase.java │ ├── array │ ├── ArrayTestCase.java │ └── ArrayTestCaseClasses.java │ ├── boundmapperfacade │ ├── ArrayTestCase.java │ ├── BidirectionalMappingTestCase.java │ ├── CollectionTestCase.java │ ├── ConstructorMappingTestCase.java │ ├── GenericCollectionsTestCase.java │ ├── InheritanceTestCase.java │ ├── InverseMappingTestCase.java │ ├── MapGenerationTestCase.java │ ├── NestedInheritanceTestCase.java │ ├── ObjectCollectionTestCase.java │ ├── PolicyElementsTestCase.java │ ├── ReuseMappersTestCase.java │ ├── SuperTypeForGeneratedTestCase.java │ ├── SuperTypeMappingTestCase.java │ ├── UsedMappersTestCase.java │ └── UserProvidedInheritanceTestCase.java │ ├── collection │ ├── CollectionTestCase.java │ ├── ExplicitCollectionTestCase.java │ └── ObjectCollectionTestCase.java │ ├── common │ └── types │ │ ├── TestCaseClasses.java │ │ └── Validations.java │ ├── community │ ├── AutomaticStringConversionTestCase.java │ ├── CustomMergerTest.java │ ├── Issue14TestCase.java │ ├── Issue17TestCase.java │ ├── Issue18TestCase.java │ ├── Issue19TestCase.java │ ├── Issue20TestCase.java │ ├── Issue21TestCase.java │ ├── Issue24TestCase.java │ ├── Issue25TestCase.java │ ├── Issue26TestCase.java │ ├── Issue28TestCase.java │ ├── Issue30TestCase.java │ ├── Issue34TestCase.java │ ├── Issue38TestCase.java │ ├── Issue41TestCase.java │ ├── Issue45TestCase.java │ ├── Issue46TestCase.java │ ├── Issue49TestCase.java │ ├── Issue50TestCase.java │ ├── Issue52aTestCase.java │ ├── Issue52bTestCase.java │ ├── Issue53TestCase.java │ ├── Issue61TestCase.java │ ├── Issue64TestCase.java │ ├── Issue65TestCase.java │ ├── Issue67TestCase.java │ ├── Issue68TestCase.java │ ├── Issue69TestCase.java │ ├── Issue71TestCase.java │ ├── IssueArrayToListTestCase.java │ ├── JaxbElementTestCase.java │ ├── MixConversionMappingTestCase.java │ ├── NestedListToArrayTestCase.java │ ├── collection │ │ ├── AbstractMapperTest.java │ │ ├── AbstractOrder.java │ │ ├── IPosition.java │ │ ├── MapperTest.java │ │ ├── Order.java │ │ ├── OrderData.java │ │ ├── Position.java │ │ └── PositionData.java │ ├── issue20 │ │ ├── BaseDto.java │ │ ├── BaseEntity.java │ │ ├── User.java │ │ ├── UserDto.java │ │ ├── UserGroupDto.java │ │ ├── UserInfo.java │ │ └── UsrGroup.java │ ├── issue21 │ │ ├── Authority.java │ │ ├── AuthorityDto.java │ │ ├── BaseDto.java │ │ ├── BaseEntity.java │ │ ├── User.java │ │ ├── UserDto.java │ │ ├── UserGroup.java │ │ ├── UserGroupDto.java │ │ └── UserInfo.java │ ├── issue25 │ │ ├── AddressMergingMapper.java │ │ ├── BaseManufacturingFacilityTest.java │ │ ├── CustomOrikaMapper.java │ │ ├── modelA │ │ │ ├── Address.java │ │ │ └── ManufacturingFacility.java │ │ └── modelB │ │ │ ├── AddressDTO.java │ │ │ ├── ManufacturingFacilityDTO.java │ │ │ └── ManufacturingFacilityDTS.java │ ├── issue26 │ │ ├── AbstractEntity.java │ │ ├── AbstractOrderID.java │ │ ├── Order.java │ │ ├── OrderData.java │ │ ├── OrderID.java │ │ └── OrderIDConverter.java │ ├── issue28 │ │ ├── AbstractOrder.java │ │ ├── Order.java │ │ ├── OrderData.java │ │ ├── Position.java │ │ └── PositionContainer.java │ ├── issue41 │ │ ├── MyEnum.java │ │ ├── MyEnumConverter.java │ │ ├── MySourceObject.java │ │ ├── MyTargetObject.java │ │ └── MyTargetSubObject.java │ └── issue42 │ │ └── InheritanceTestcase.java │ ├── constructor │ ├── converter │ ├── CloneableConverterNoSetAccessibleTestCase.java │ ├── CloneableConverterTestCase.java │ ├── ConstructorConverterTestCase.java │ ├── ConverterInheritanceTestCase.java │ ├── ConverterResolutionTestCase.java │ ├── ConverterTestCase.java │ ├── ConverterWithNestedPropertyTestCase.java │ ├── DateAndTimeConvertersTestCase.java │ ├── FieldLevelConverterClasses.java │ ├── FieldLevelConverterTestCase.java │ ├── FromStringConverterTestCase.java │ ├── LongToStringConverter.java │ ├── NumericConvertersTestCase.java │ ├── PassThroughConverterTestCase.java │ ├── PrimitiveConversionTestCase.java │ ├── StringConversionTestCase.java │ └── ToStringConverterTestCase.java │ ├── crossfeatures │ ├── PolicyElementsTestCase.java │ └── PolicyElementsTestCaseClasses.java │ ├── customconverter │ └── CustomConverterTestCase.java │ ├── custommapper │ └── CustomMappingTestCase.java │ ├── enums │ ├── EnumsTestCase.java │ └── EnumsTestCaseClasses.java │ ├── extensibility │ ├── ClassMapBuilderExtensibilityTestCase.java │ ├── DefaultMapperFactoryExtensibilityTestCase.java │ ├── PooledInstancesTestCase.java │ └── PropertyResolverExtensibilityTestCase.java │ ├── fieldmap │ ├── NestedExpressionTestCase.java │ ├── NestedPropertyTestCase.java │ └── OverrideFieldNameTestCase.java │ ├── generator │ ├── BeanToArrayGenerationTestCase.java │ ├── BeanToListGenerationTestCase.java │ ├── BeanToMapGenerationTestCase.java │ ├── ExpanderTestCase.java │ ├── MapNullsTestCase.java │ ├── MultiOccurrenceToMultiOccurrenceTestCase.java │ ├── TestCompilerStrategyWritingFiles.java │ └── eclipsejdt │ │ └── TestAlternateCompilerStrategy.java │ ├── generics │ ├── GenericCollectionsTestCase.java │ └── GenericsTestCase.java │ ├── hint │ ├── DefaultMappingHintTestCase.java │ └── DefaultMappingHintTestCaseClasses.java │ ├── inheritance │ ├── InheritanceTestCase.java │ ├── InitializeUsedMappersTestCase.java │ ├── NestedInheritanceTestCase.java │ ├── ReuseMappersTestCase.java │ ├── UsedMappersTestCase.java │ └── UserProvidedInheritanceTestCase.java │ ├── map │ ├── CoreMappingFunctionsTestCase.java │ └── MapGenerationTestCase.java │ ├── metadata │ ├── ScoringClassMapBuilderTest.java │ ├── TypeFactoryTestCase.java │ └── VariableRefTestCase.java │ ├── object │ ├── BidirectionalMappingTestCase.java │ ├── InverseMappingTestCase.java │ └── ObjectTestCase.java │ ├── perf │ ├── ClassLoaderLeakageTestCase.java │ ├── LaunchTestsForProfiler.java │ ├── MultiLayeredClassloaderTestCase.java │ └── MultiThreadedTestCase.java │ ├── primitives │ ├── BigDecimalPrimitiveTestCase.java │ ├── BooleanTestCase.java │ └── PrimitivesTestCase.java │ ├── property │ ├── IntrospectorResolverTestCase.java │ ├── PropertyResolverTestCase.java │ ├── PublicFieldMappingTestCase.java │ ├── RegexPropertyResolverTestCase.java │ └── TestCaseClasses.java │ ├── unenhance │ ├── Author.java │ ├── AuthorDTO.java │ ├── Book.java │ ├── BookDTO.java │ ├── HibernateProxyTestCase.java │ ├── SuperTypeForGeneratedTestCase.java │ ├── SuperTypeMappingTestCase.java │ ├── SuperTypeTestCaseClasses.java │ └── XMLGregorianCalendarToDateConverter.java │ └── util │ ├── ConfigurableMapperTestCase.java │ ├── PropertiesTestCase.java │ └── SortedCollectionTestCase.java └── resources ├── HibernateProxyTestCase-context.xml ├── Issue20TestCase-context.xml ├── Issue21TestCase-context.xml └── logback-test.xml /.gitignore: -------------------------------------------------------------------------------- 1 | # / 2 | /.settings/.* 3 | /target 4 | /.idea 5 | /orika-parent.iml 6 | 7 | # /core/ 8 | /core/.* 9 | /core/target 10 | /core/orika-core.iml 11 | 12 | # /eclipse-tools/ 13 | /eclipse-tools/.project 14 | /eclipse-tools/.classpath 15 | /eclipse-tools/.settings/.* 16 | /eclipse-tools/target 17 | 18 | # /core/ 19 | /tests/.* 20 | /tests/target 21 | /tests/orika-tests.iml 22 | 23 | /benchmarks/target 24 | /benchmarks/.settings/.* 25 | /benchmarks/.project 26 | /benchmarks/.classpath 27 | /benchmarks/bin 28 | 29 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | orika-parent 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: 3 | - oraclejdk7 4 | branches: 5 | only: 6 | - master 7 | 8 | notifications: 9 | recipients: 10 | - elaatifi@gmail.com 11 | - matt.deboer@gmail.com 12 | email: 13 | on_success: always 14 | on_failure: always 15 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Orika - simpler, better and faster Java bean mapping 2 | Copyright (C) 2011 Sidi Mohamed El Aatifi 3 | ---------------------------------------------------------------------- 4 | 5 | Authors 6 | 7 | Sidi Mohamed El Aatifi 8 | Cyril Combe 9 | Amine Moukhliss 10 | Matt DeBoer 11 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | We've recently moved to a Github Organization repo https://github.com/orika-mapper/orika 2 | ========================================================================================= 3 | 4 | 5 | Orika ! [![Build Status](https://secure.travis-ci.org/elaatifi/orika.png)](http://travis-ci.org/elaatifi/orika) 6 | ------------------------------------------------------------------------------------------ 7 | 8 | 9 | Orika is a Java Bean mapping framework that recursively copies (among other capabilities) data from one object to another. It can be very useful when developing multi-layered applications. 10 | -------------------------------------------------------------------------------- /core/src/main/assembly/bin.xml: -------------------------------------------------------------------------------- 1 | 4 | bin 5 | 6 | zip 7 | 8 | 9 | 10 | ${project.basedir} 11 | / 12 | 13 | README* 14 | LICENSE* 15 | NOTICE* 16 | 17 | 18 | 19 | ${project.build.directory} 20 | / 21 | 22 | *.jar 23 | 24 | 25 | 26 | ${project.build.directory}/site 27 | docs 28 | 29 | 30 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/ConverterException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika; 20 | 21 | /** 22 | * An exception that usually occurs during a conversion (run time). 23 | * 24 | * @author S.M. El Aatifi 25 | */ 26 | public class ConverterException extends RuntimeException { 27 | 28 | private static final long serialVersionUID = 8568713038592686945L; 29 | } 30 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/DefaultFieldMapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika; 20 | 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | /** 24 | * Provides a generic mapping suggestion mechanism to provide 25 | * help with guessing default mappings of fields when a straight 26 | * equivalent name match is not found 27 | * 28 | * @author matt.deboer@gmail.com 29 | */ 30 | public interface DefaultFieldMapper { 31 | 32 | /** 33 | * @param sourceExpression 34 | * @return a suggested optional mapping name for the given property, 35 | * or null if no suggestion for the given property 36 | */ 37 | public String suggestMappedField(String fromProperty, Type fromPropertyType); 38 | 39 | } 40 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/MappedTypePair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika; 19 | 20 | import ma.glasnost.orika.metadata.Type; 21 | 22 | /** 23 | * MappedTypePair represents any pair of mapped types, which are distinguished 24 | * from each other as 'A type' and 'B type' 25 | * 26 | * @author matt.deboer@gmail.com 27 | * 28 | */ 29 | public interface MappedTypePair { 30 | /** 31 | * @return the 'A' type for this mapped pair 32 | */ 33 | Type getAType(); 34 | 35 | /** 36 | * @return the 'B' type for this mapped pair 37 | */ 38 | Type getBType(); 39 | } 40 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/Mapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika; 20 | 21 | 22 | /** 23 | * Defines a contract between internal parts of Orika such as 24 | * MapperFacade, MapperGenerator, 25 | * MapperFactory and generated mappers. 26 | * 27 | * @author S.M. El Aatifi 28 | * 29 | * @see MapperFacade 30 | */ 31 | public interface Mapper extends MappedTypePair { 32 | 33 | /** 34 | * Maps the properties of an instance of type A to the properties 35 | * of an instance of type B. 36 | * 37 | * @param a the object from which to read the properties 38 | * @param b the object onto which the properties should be mapped 39 | * @param context 40 | */ 41 | void mapAtoB(A a, B b, MappingContext context); 42 | 43 | /** 44 | * Maps the properties of an instance of type B to the properties 45 | * of an instance of type A. 46 | * 47 | * @param b the object from which to read the properties 48 | * @param a the object onto which the properties should be mapped 49 | * @param context 50 | */ 51 | void mapBtoA(B b, A a, MappingContext context); 52 | 53 | /** 54 | * Store an instance of the current MapperFacade which may be used 55 | * in mapping of nested types. 56 | * 57 | * @param mapper 58 | */ 59 | void setMapperFacade(MapperFacade mapper); 60 | 61 | /** 62 | * Store the set of custom mappers used by this mapper. 63 | * @param mapper 64 | */ 65 | void setUsedMappers(Mapper[] mapper); 66 | 67 | } 68 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/MappingContextFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika; 19 | 20 | import java.util.Map; 21 | 22 | /** 23 | * @author matt.deboer@gmail.com 24 | * 25 | */ 26 | public interface MappingContextFactory { 27 | 28 | /** 29 | * Gets an available instance of MappingContext 30 | * 31 | * @return an instance of MappingContext 32 | */ 33 | public MappingContext getContext(); 34 | 35 | /** 36 | * Allows for implementations that reuse objects to clean-up/clear any resources 37 | * associated with the particular context instance once it is no longer needed. 38 | * 39 | * @param context the context to be recycled 40 | */ 41 | public void release(MappingContext context); 42 | 43 | 44 | /** 45 | * @return a reference to the global properties map for this mapping context factory; any properties 46 | * set here are available from any individual MappingContext created by this factory. 47 | */ 48 | public Map getGlobalProperties(); 49 | } 50 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/MappingHint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika; 20 | 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | 24 | /** 25 | * Provides a generic mapping suggestion mechanism to provide 26 | * help with guessing default mappings of fields when a straight 27 | * equivalent name match is not found 28 | * 29 | * @deprecated use ma.glasnost.orika.FieldSuggester instead 30 | * @author matt.deboer@gmail.com 31 | */ 32 | @Deprecated 33 | public interface MappingHint { 34 | 35 | /** 36 | * @param sourceExpression 37 | * @return a suggested optional mapping name for the given property, 38 | * or null if no suggestion for the given property 39 | */ 40 | public String suggestMappedField(String fromProperty, Class fromPropertyType); 41 | 42 | 43 | /** 44 | * DefaultFieldMappingConverter provided back-compatibility support for 45 | * MappingHint 46 | * 47 | * @author matt.deboer@gmail.com 48 | */ 49 | public static class DefaultFieldMappingConverter implements DefaultFieldMapper { 50 | 51 | private MappingHint delegate; 52 | public DefaultFieldMappingConverter(MappingHint delegate) { 53 | this.delegate = delegate; 54 | } 55 | 56 | public String suggestMappedField(String fromProperty, 57 | Type fromPropertyType) { 58 | return this.delegate.suggestMappedField(fromProperty, fromPropertyType.getRawType()); 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/ObjectFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika; 20 | 21 | public interface ObjectFactory { 22 | 23 | D create(Object source, MappingContext mappingContext); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/Properties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika; 19 | 20 | /** 21 | * @author matt.deboer@gmail.com 22 | * 23 | */ 24 | public enum Properties { 25 | SHOULD_MAP_NULLS, 26 | LOG_DETAILS, 27 | MAPPER_FACTORY, 28 | CODE_GENERATION_STRATEGY, 29 | PROPERTY_RESOLVER_STRATEGY, 30 | COMPILER_STRATEGY 31 | ; 32 | } 33 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/converter/BidirectionConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.converter; 19 | 20 | 21 | /** 22 | * 23 | * 24 | * @author 25 | * 26 | * @param 27 | * @param 28 | * 29 | * @deprecated use {@link ma.glasnost.orika.converter.BidirectionalConverter} instead 30 | */ 31 | @Deprecated 32 | public abstract class BidirectionConverter extends TypeConverter implements Converter { 33 | 34 | public abstract D convertTo(S source, Class destinationClass); 35 | 36 | public abstract S convertFrom(D source, Class destinationClass); 37 | 38 | @SuppressWarnings("unchecked") 39 | public Object convert(Object source, Class destinationClass) { 40 | if (destinationClass.equals(this.destinationClass)) { 41 | return convertTo((S) source, (Class) destinationClass); 42 | } else { 43 | return convertFrom((D) source, (Class) destinationClass); 44 | } 45 | } 46 | 47 | @SuppressWarnings("unchecked") 48 | @Override 49 | public boolean canConvert(Class sourceClass, Class destinationClass) { 50 | return super.canConvert(sourceClass, destinationClass) || super.canConvert((Class) destinationClass, sourceClass); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/converter/TypeConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.converter; 19 | 20 | import java.lang.reflect.ParameterizedType; 21 | import java.lang.reflect.Type; 22 | 23 | /** 24 | * 25 | * @param 26 | * @param 27 | * 28 | * @deprecated use {@link ma.glasnost.orika.CustomConverter} instead 29 | */ 30 | @Deprecated 31 | public abstract class TypeConverter extends CustomConverterBase { 32 | 33 | protected final Class sourceClass; 34 | protected final Class destinationClass; 35 | 36 | @SuppressWarnings("unchecked") 37 | public TypeConverter() { 38 | Type genericSuperclass = getClass().getGenericSuperclass(); 39 | if (genericSuperclass != null && genericSuperclass instanceof ParameterizedType) { 40 | sourceClass = (Class) ((ParameterizedType) genericSuperclass).getActualTypeArguments()[0]; 41 | destinationClass = (Class) ((ParameterizedType) genericSuperclass).getActualTypeArguments()[1]; 42 | } else { 43 | throw new IllegalStateException("When you subclass the TypeConverter S and D type-parameters are required."); 44 | } 45 | } 46 | 47 | public boolean canConvert(Class sourceClass, Class destinationClass) { 48 | return this.sourceClass.equals(sourceClass) && this.destinationClass.equals(destinationClass); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/converter/builtin/CopyByReferenceConverter.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.converter.builtin; 2 | 3 | import ma.glasnost.orika.CustomConverter; 4 | import ma.glasnost.orika.impl.util.ClassUtil; 5 | import ma.glasnost.orika.metadata.Type; 6 | 7 | /** 8 | * CopyByReferenceConverter handles conversion of Orika's built-in immutable 9 | * types, as well as anything-to-Object, and primitive to Wrapper conversions
10 | * 11 | * @author matt.deboer@gmail.com 12 | * 13 | */ 14 | public class CopyByReferenceConverter extends CustomConverter { 15 | 16 | /* 17 | * (non-Javadoc) 18 | * 19 | * @see 20 | * ma.glasnost.orika.Converter#canConvert(ma.glasnost.orika.metadata.Type, 21 | * ma.glasnost.orika.metadata.Type) 22 | */ 23 | public boolean canConvert(Type sourceType, Type destinationType) { 24 | 25 | return /*destinationType.isAssignableFrom(sourceType) 26 | || */(ClassUtil.isImmutable(sourceType) && (sourceType.equals(destinationType) || sourceType.isWrapperFor(destinationType) || destinationType.isWrapperFor(sourceType))); 27 | } 28 | 29 | public Object convert(Object source, Type destinationType) { 30 | return source; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/converter/builtin/EnumConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.converter.builtin; 19 | 20 | import ma.glasnost.orika.CustomConverter; 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | 24 | /** 25 | * EnumConverter is used to convert from one enum to another, based on 26 | * exact name match 27 | */ 28 | public class EnumConverter extends CustomConverter { 29 | 30 | public boolean canConvert(Type sourceType, Type destinationType) { 31 | return sourceType.isEnum() && destinationType.isEnum(); 32 | } 33 | 34 | /* (non-Javadoc) 35 | * @see ma.glasnost.orika.Converter#convert(java.lang.Object, ma.glasnost.orika.metadata.Type) 36 | */ 37 | public Object convert(Object source, Type destinationType) { 38 | @SuppressWarnings({ "unchecked", "rawtypes" }) 39 | Enum result = (Enum) Enum.valueOf((Class)destinationType.getRawType(), ((Enum)source).name()); 40 | return result; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/converter/builtin/PassThroughConverter.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.converter.builtin; 2 | 3 | import java.util.HashSet; 4 | import java.util.Set; 5 | 6 | import ma.glasnost.orika.CustomConverter; 7 | import ma.glasnost.orika.metadata.Type; 8 | import ma.glasnost.orika.metadata.TypeFactory; 9 | 10 | /** 11 | * PassThroughConverter allows configuration of a number of specific types which 12 | * should be passed through (as-is) without creating a mapped copy.

13 | * 14 | * This allows you to declare your own set of types which should be treated by 15 | * Orika as if they were in the set of immutable types. 16 | * 17 | * @author matt.deboer@gmail.com 18 | * 19 | */ 20 | public class PassThroughConverter extends CustomConverter { 21 | 22 | private final Set> passThroughTypes = new HashSet>(); 23 | 24 | /** 25 | * Constructs a new PassThroughConverter configured to treat the provided 26 | * list of types as immutable. 27 | * 28 | * @param types one or more types that should be treated as immutable 29 | */ 30 | public PassThroughConverter(java.lang.reflect.Type...types) { 31 | for (java.lang.reflect.Type type: types) { 32 | passThroughTypes.add(TypeFactory.valueOf(type)); 33 | } 34 | } 35 | 36 | private boolean shouldPassThrough(Type type) { 37 | for (Type registeredType: passThroughTypes) { 38 | if (registeredType.isAssignableFrom(type)) { 39 | return true; 40 | } 41 | } 42 | return false; 43 | } 44 | 45 | /* (non-Javadoc) 46 | * @see ma.glasnost.orika.Converter#canConvert(ma.glasnost.orika.metadata.Type, ma.glasnost.orika.metadata.Type) 47 | */ 48 | public boolean canConvert(Type sourceType, Type destinationType) { 49 | return shouldPassThrough(sourceType) && sourceType.equals(destinationType); 50 | } 51 | 52 | public Object convert(Object source, Type destinationType) { 53 | return source; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/converter/builtin/StringToCharacterConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.converter.builtin; 19 | 20 | import ma.glasnost.orika.converter.BidirectionalConverter; 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | /** 24 | * 25 | * 26 | */ 27 | public class StringToCharacterConverter extends BidirectionalConverter { 28 | 29 | /* (non-Javadoc) 30 | * @see ma.glasnost.orika.converter.BidirectionalConverter#convertTo(java.lang.Object, ma.glasnost.orika.metadata.Type) 31 | */ 32 | @Override 33 | public Character convertTo(String source, Type destinationType) { 34 | return source.charAt(0); 35 | } 36 | 37 | /* (non-Javadoc) 38 | * @see ma.glasnost.orika.converter.BidirectionalConverter#convertFrom(java.lang.Object, ma.glasnost.orika.metadata.Type) 39 | */ 40 | @Override 41 | public String convertFrom(Character source, Type destinationType) { 42 | return "" + source; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/converter/builtin/StringToEnumConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.converter.builtin; 19 | 20 | import ma.glasnost.orika.converter.Converter; 21 | import ma.glasnost.orika.converter.CustomConverterBase; 22 | 23 | 24 | /** 25 | * 26 | * @deprecated use {@link FromStringConverter} instead 27 | */ 28 | @SuppressWarnings({ "rawtypes", "unused" }) 29 | @Deprecated 30 | public class StringToEnumConverter extends CustomConverterBase { 31 | 32 | @SuppressWarnings("unchecked") 33 | public Enum convert(String source, Class destinationClass) { 34 | return Enum.valueOf(destinationClass, source); 35 | } 36 | 37 | public boolean canConvert(Class sourceClass, Class destinationClass) { 38 | return String.class.equals(sourceClass) && destinationClass != null && destinationClass.isEnum(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/converter/builtin/ToStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.converter.builtin; 19 | 20 | import ma.glasnost.orika.CustomConverter; 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | 24 | /** 25 | * Converts any object to string 26 | * 27 | * @author matt.deboer@gmail.com 28 | */ 29 | public class ToStringConverter extends CustomConverter { 30 | 31 | public boolean canConvert(Type sourceType, Type destinationType) { 32 | return destinationType.isString(); 33 | } 34 | 35 | public Object convert(Object source, Type destinationType) { 36 | return "" + source; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/DefaultConstructorObjectFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.impl; 19 | 20 | import ma.glasnost.orika.MappingContext; 21 | import ma.glasnost.orika.ObjectFactory; 22 | 23 | /** 24 | * DefaultConstructorObjectFactory is used for types which should be instantiated 25 | * using their default constructor. 26 | * 27 | * @author matt.deboer@gmail.com 28 | * 29 | */ 30 | public class DefaultConstructorObjectFactory implements ObjectFactory { 31 | 32 | private final Class type; 33 | 34 | public DefaultConstructorObjectFactory(Class type) { 35 | this.type = type; 36 | } 37 | 38 | /* (non-Javadoc) 39 | * @see ma.glasnost.orika.ObjectFactory#create(java.lang.Object, ma.glasnost.orika.MappingContext) 40 | */ 41 | public T create(Object source, MappingContext mappingContext) { 42 | try { 43 | return type.newInstance(); 44 | } catch (InstantiationException e) { 45 | throw new IllegalStateException(e); 46 | } catch (IllegalAccessException e) { 47 | throw new IllegalStateException(e); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/ExceptionUtility.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.impl; 19 | 20 | import java.util.Arrays; 21 | import java.util.List; 22 | 23 | /** 24 | * @author matt.deboer@gmail.com 25 | * 26 | */ 27 | public class ExceptionUtility { 28 | 29 | public static List corePackages = Arrays.asList( 30 | "java.","javax.","sun.", "sunw.", "com.sun.", "com.ibm.", 31 | "javassist.", "com.thoughtworks.paranamer."); 32 | 33 | /** 34 | * Tests whether the passed throwable was originated by orika mapper code. 35 | * 36 | * @param t 37 | * @return 38 | */ 39 | public static boolean originatedByOrika(Throwable t) { 40 | for (StackTraceElement ste: t.getStackTrace()) { 41 | if (isJreClass(ste.getClassName())) { 42 | continue; 43 | } else if (isOrikaClass(ste.getClassName())) { 44 | return true; 45 | } else { 46 | return false; 47 | } 48 | } 49 | return false; 50 | } 51 | 52 | private static boolean isOrikaClass(String className) { 53 | return className.startsWith("ma.glasnost.orika.") && !className.startsWith("ma.glasnost.orika.test."); 54 | } 55 | 56 | private static boolean isJreClass(String className) { 57 | for (String pkg: corePackages) { 58 | if (className.startsWith(pkg)) { 59 | return true; 60 | } 61 | } 62 | return false; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/GeneratedObjectFactory.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl; 2 | 3 | import ma.glasnost.orika.ObjectFactory; 4 | 5 | public abstract class GeneratedObjectFactory extends GeneratedObjectBase implements ObjectFactory { 6 | 7 | } 8 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/NonCyclicBoundMapperFacade.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.impl; 19 | 20 | import ma.glasnost.orika.MapperFactory; 21 | import ma.glasnost.orika.MappingContext; 22 | import ma.glasnost.orika.MappingContext.NonCyclicMappingContext; 23 | import ma.glasnost.orika.MappingContextFactory; 24 | 25 | /** 26 | * @author matt.deboer@gmail.com 27 | * 28 | */ 29 | public class NonCyclicBoundMapperFacade extends DefaultBoundMapperFacade { 30 | 31 | private final MappingContext nonCyclicContext; 32 | 33 | NonCyclicBoundMapperFacade(MapperFactory mapperFactory, MappingContextFactory contextFactory, java.lang.reflect.Type sourceType, 34 | java.lang.reflect.Type destinationType) { 35 | super(mapperFactory, contextFactory, sourceType, destinationType); 36 | this.nonCyclicContext = new NonCyclicMappingContext(); 37 | } 38 | 39 | public B map(A source) { 40 | return super.map(source, nonCyclicContext); 41 | } 42 | 43 | public A mapReverse(B source) { 44 | return super.mapReverse(source, nonCyclicContext); 45 | } 46 | 47 | public B map(A source, B destination) { 48 | return super.map(source, destination, nonCyclicContext); 49 | } 50 | 51 | public A mapReverse(B destination, A source) { 52 | return super.mapReverse(destination, source, nonCyclicContext); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/AggregateSpecification.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator; 2 | 3 | import java.util.List; 4 | 5 | import ma.glasnost.orika.MapperFactory; 6 | import ma.glasnost.orika.metadata.FieldMap; 7 | 8 | /** 9 | * AggregateSpecification encapsulates the logic to generate code for mappings 10 | * which are applied to collections of FieldMaps together 11 | * 12 | * @author mattdeboer 13 | * 14 | */ 15 | public interface AggregateSpecification { 16 | 17 | void setMapperFactory(MapperFactory mapperFactory); 18 | 19 | /** 20 | * Tests whether this Specification applies to the specified MappedTypePair 21 | * @param fieldMap 22 | * 23 | * @param typePair 24 | * @return true if this specification applies to the given MappedTypePair 25 | */ 26 | boolean appliesTo(FieldMap fieldMap); 27 | 28 | 29 | /** 30 | * @param fieldMappings 31 | * @param code 32 | * @return 33 | */ 34 | String generateMappingCode(List fieldMappings, SourceCodeContext code); 35 | } 36 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/MapEntryRef.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator; 2 | 3 | import ma.glasnost.orika.metadata.Property; 4 | import ma.glasnost.orika.metadata.Type; 5 | 6 | public class MapEntryRef extends VariableRef { 7 | 8 | public enum EntryPart { 9 | KEY {{ 10 | this.prototype = new Property.Builder() 11 | .name("key") 12 | .expression("key") 13 | .getter("getKey()") 14 | .setter("setKey(%s)") 15 | .build(); 16 | 17 | }}, 18 | VALUE {{ 19 | this.prototype = new Property.Builder() 20 | .name("value") 21 | .expression("value") 22 | .getter("getValue()") 23 | .setter("setValue(%s)") 24 | .build(); 25 | }}; 26 | 27 | protected Property prototype; 28 | 29 | Property newProperty(Type type) { 30 | return prototype.copy(type); 31 | } 32 | } 33 | 34 | public MapEntryRef(Type type, String name, EntryPart entryPart) { 35 | super(entryPart.newProperty(type), name); 36 | } 37 | 38 | protected String getter() { 39 | return VariableRef.getGetter(property(), name); 40 | } 41 | 42 | protected String setter() { 43 | return VariableRef.getSetter(property(), name); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/Specification.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator; 2 | 3 | import ma.glasnost.orika.MapperFactory; 4 | import ma.glasnost.orika.metadata.FieldMap; 5 | 6 | /** 7 | * Specification encapsulates the logic to generate code for mapping 8 | * and comparing a pair of types 9 | * 10 | * @author mattdeboer 11 | * 12 | */ 13 | public interface Specification { 14 | 15 | void setMapperFactory(MapperFactory mapperFactory); 16 | 17 | /** 18 | * Tests whether this Specification applies to the specified MappedTypePair 19 | * @param fieldMap 20 | * 21 | * @param typePair 22 | * @return true if this specification applies to the given MappedTypePair 23 | */ 24 | boolean appliesTo(FieldMap fieldMap); 25 | 26 | 27 | /** 28 | * Generates code for a boolean equality test between the two variable types, 29 | * where are potentially unrelated. 30 | * 31 | * @param source 32 | * @param destination 33 | * @param inverseProperty 34 | * @param code 35 | * @return the code snippet which represents a true|false statement describing 36 | * whether the two types should be considered 'equal' 37 | */ 38 | String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code); 39 | 40 | 41 | /** 42 | * Generates code to map the provided field map 43 | * 44 | * @param fieldMap the fieldMap for which source code should be generated 45 | * @param source a convenience wrapper around the source field which can be used facilitate code generation 46 | * @param destination a convenience wrapper around the destination field which can be used facilitate code generation 47 | * @param inverseProperty 48 | * @param code 49 | * @return the code snippet which represents mapping from the source to destination 50 | * property 51 | */ 52 | String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code); 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/UsedConvertersContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.impl.generator; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | import java.util.Map.Entry; 23 | 24 | import ma.glasnost.orika.Converter; 25 | 26 | /** 27 | * 28 | * @author matt.deboer@gmail.com 29 | * 30 | */ 31 | public class UsedConvertersContext { 32 | 33 | private Map,Integer> usedConverters = new HashMap,Integer>(); 34 | private int usedTypeIndex = 0; 35 | 36 | @SuppressWarnings("unchecked") 37 | public int getIndex(Converter converter) { 38 | if (converter==null) { 39 | throw new NullPointerException("type must not be null"); 40 | } 41 | Integer index = usedConverters.get(converter); 42 | if (index == null) { 43 | index = Integer.valueOf(usedTypeIndex++); 44 | usedConverters.put((Converter)converter, index); 45 | } 46 | return index; 47 | } 48 | 49 | public Converter[] toArray() { 50 | @SuppressWarnings("unchecked") 51 | Converter[] converters = new Converter[usedConverters.size()]; 52 | for (Entry, Integer> entry: usedConverters.entrySet()) { 53 | converters[entry.getValue()] = entry.getKey(); 54 | } 55 | return converters; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/UsedTypesContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.impl.generator; 19 | 20 | import java.util.HashMap; 21 | import java.util.Map; 22 | import java.util.Map.Entry; 23 | 24 | import ma.glasnost.orika.metadata.Type; 25 | 26 | /** 27 | * 28 | * @author matt.deboer@gmail.com 29 | * 30 | */ 31 | public class UsedTypesContext { 32 | 33 | private Map,Integer> usedTypes = new HashMap,Integer>(); 34 | private int usedTypeIndex = 0; 35 | 36 | @SuppressWarnings("unchecked") 37 | public int getIndex(Type type) { 38 | if (type==null) { 39 | throw new NullPointerException("type must not be null"); 40 | } 41 | Integer index = usedTypes.get(type); 42 | if (index == null) { 43 | index = Integer.valueOf(usedTypeIndex++); 44 | usedTypes.put((Type)type, index); 45 | } 46 | return index; 47 | } 48 | 49 | public Type[] toArray() { 50 | @SuppressWarnings("unchecked") 51 | Type[] types = new Type[usedTypes.size()]; 52 | for (Entry, Integer> entry: usedTypes.entrySet()) { 53 | types[entry.getValue()] = entry.getKey(); 54 | } 55 | return types; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/AbstractSpecification.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import ma.glasnost.orika.MapperFactory; 4 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 5 | import ma.glasnost.orika.impl.generator.Specification; 6 | import ma.glasnost.orika.impl.generator.VariableRef; 7 | import ma.glasnost.orika.metadata.FieldMap; 8 | 9 | public abstract class AbstractSpecification implements Specification { 10 | 11 | protected MapperFactory mapperFactory; 12 | 13 | public void setMapperFactory(MapperFactory mapperFactory) { 14 | this.mapperFactory = mapperFactory; 15 | } 16 | 17 | /** 18 | * Tests whether this fieldMap should map nulls; 19 | * 20 | * @param fieldMap 21 | * @param context 22 | * @return 23 | */ 24 | protected boolean shouldMapNulls(FieldMap fieldMap, SourceCodeContext context) { 25 | Boolean mapNull = fieldMap.isDestinationMappedOnNull(); 26 | if (mapNull == null) { 27 | mapNull = context.shouldMapNulls(); 28 | } 29 | return mapNull; 30 | } 31 | 32 | public abstract boolean appliesTo(FieldMap fieldMap); 33 | 34 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 35 | return source + ".equals(" + destination + ")"; 36 | } 37 | 38 | public abstract String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code); 39 | 40 | 41 | 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/AnyTypeToString.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.statement; 4 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 5 | import ma.glasnost.orika.impl.generator.VariableRef; 6 | import ma.glasnost.orika.metadata.FieldMap; 7 | 8 | public class AnyTypeToString extends AbstractSpecification { 9 | 10 | public boolean appliesTo(FieldMap fieldMap) { 11 | return String.class.equals(fieldMap.getDestination().getType().getRawType()); 12 | } 13 | 14 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 15 | return "(\"\" + " + source + ").equals(" + destination +")"; 16 | } 17 | 18 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 19 | if (source.isPrimitive()) { 20 | return statement(destination.assign("\"\"+ %s", source)); 21 | } else { 22 | if (shouldMapNulls(fieldMap, code)) { 23 | return statement("if (" + source.notNull() + ") {" + destination.assign("%s.toString()", source) + "} else {" + destination.assign("null") + "}"); 24 | } else { 25 | return statement(source.ifNotNull() + destination.assign("%s.toString()", source)); 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/ApplyRegisteredMapper.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import ma.glasnost.orika.metadata.FieldMap; 4 | 5 | public class ApplyRegisteredMapper extends ObjectToObject { 6 | 7 | public boolean appliesTo(FieldMap fieldMap) { 8 | return mapperFactory.existsRegisteredMapper(fieldMap.getAType(), fieldMap.getBType(), false); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/ArrayOrCollectionToArray.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import static java.lang.String.format; 4 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 5 | import ma.glasnost.orika.impl.generator.VariableRef; 6 | import ma.glasnost.orika.metadata.FieldMap; 7 | 8 | public class ArrayOrCollectionToArray extends AbstractSpecification { 9 | 10 | public boolean appliesTo(FieldMap fieldMap) { 11 | return fieldMap.getDestination().isArray() && (fieldMap.getSource().isArray() || fieldMap.getSource().isCollection()); 12 | } 13 | 14 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 15 | return ""; 16 | } 17 | 18 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 19 | 20 | final VariableRef arrayVar = destination.elementRef(destination.name()); 21 | String newArray = format("%s[] %s = new %s[%s]", destination.elementTypeName(), destination.name(), destination.elementTypeName(), source.size()); 22 | 23 | String mapArray; 24 | if (destination.elementType().isPrimitive()) { 25 | mapArray = format("mapArray(%s, asList(%s), %s.class, mappingContext)", arrayVar, source, arrayVar.typeName()); 26 | } else { 27 | mapArray = format("mapperFacade.mapAsArray(%s, asList(%s), %s, %s, mappingContext)", destination.name(), source, code.usedType(source.elementType()), 28 | code.usedType(destination.elementType())); 29 | } 30 | String mapNull = shouldMapNulls(fieldMap, code) ? format(" else { %s; }", destination.assignIfPossible("null")) : ""; 31 | return format(" %s { %s; %s; %s; } %s", source.ifNotNull(), newArray, mapArray, destination.assign(arrayVar), mapNull); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/CopyByReference.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.append; 4 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.statement; 5 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 6 | import ma.glasnost.orika.impl.generator.VariableRef; 7 | import ma.glasnost.orika.impl.util.ClassUtil; 8 | import ma.glasnost.orika.metadata.FieldMap; 9 | 10 | public class CopyByReference extends AbstractSpecification { 11 | 12 | public boolean appliesTo(FieldMap fieldMap) { 13 | return ClassUtil.isImmutable(fieldMap.getSource().getType()) 14 | && fieldMap.getDestination().isAssignableFrom(fieldMap.getSource()); 15 | } 16 | 17 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 18 | if (source.type().isPrimitive() || source.type().isPrimitiveWrapper()) { 19 | return source + " == " + destination; 20 | } else { 21 | return source + ".equals(" + destination + ")"; 22 | } 23 | 24 | } 25 | 26 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 27 | StringBuilder out = new StringBuilder(); 28 | if (!source.isPrimitive()) { 29 | out.append(source.ifNotNull() + "{"); 30 | } 31 | out.append(statement(destination.assign(source))); 32 | if (!source.isPrimitive()) { 33 | out.append("\n }"); 34 | if (shouldMapNulls(fieldMap, code) && !destination.isPrimitive()) { 35 | append(out, 36 | " else {", 37 | destination.assignIfPossible("null"), 38 | "\n }"); 39 | } 40 | } 41 | return out.toString(); 42 | } 43 | 44 | } 45 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/EnumToEnum.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import static java.lang.String.format; 4 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.statement; 5 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 6 | import ma.glasnost.orika.impl.generator.VariableRef; 7 | import ma.glasnost.orika.metadata.FieldMap; 8 | 9 | public class EnumToEnum extends AbstractSpecification { 10 | 11 | public boolean appliesTo(FieldMap fieldMap) { 12 | return fieldMap.getBType().isEnum() && fieldMap.getAType().isEnum(); 13 | } 14 | 15 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 16 | return "(Enum.valueOf(%s.class, %s.name()) == " + destination + ")"; 17 | } 18 | 19 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 20 | String assignEnum = destination.assign("Enum.valueOf(%s.class, %s.name())", destination.typeName(), source); 21 | String mapNull = shouldMapNulls(fieldMap, code) ? format(" else {\n %s;\n}", destination.assignIfPossible("null")): ""; 22 | return statement("%s { %s; } %s", source.ifNotNull(), assignEnum, mapNull); 23 | } 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/MapToArray.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.entrySetRef; 4 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 5 | import ma.glasnost.orika.impl.generator.VariableRef; 6 | import ma.glasnost.orika.metadata.FieldMap; 7 | 8 | public class MapToArray extends ArrayOrCollectionToArray { 9 | 10 | public boolean appliesTo(FieldMap fieldMap) { 11 | return fieldMap.getSource().isMap() && fieldMap.getDestination().isArray(); 12 | } 13 | 14 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 15 | return source + " == " + destination; 16 | } 17 | 18 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 19 | 20 | return super.generateMappingCode(fieldMap, entrySetRef(source), destination, code); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/MapToCollection.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.entrySetRef; 4 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 5 | import ma.glasnost.orika.impl.generator.VariableRef; 6 | import ma.glasnost.orika.metadata.FieldMap; 7 | 8 | public class MapToCollection extends ArrayOrCollectionToCollection { 9 | 10 | public boolean appliesTo(FieldMap fieldMap) { 11 | return fieldMap.getSource().isMap() && fieldMap.getDestination().isCollection(); 12 | } 13 | 14 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 15 | return source + " == " + destination; 16 | } 17 | 18 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 19 | 20 | return super.generateMappingCode(fieldMap, entrySetRef(source), destination, code); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/MultiOccurrenceElementToObject.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | 4 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.statement; 5 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 6 | import ma.glasnost.orika.impl.generator.VariableRef; 7 | import ma.glasnost.orika.impl.util.ClassUtil; 8 | import ma.glasnost.orika.metadata.FieldMap; 9 | 10 | public class MultiOccurrenceElementToObject extends AbstractSpecification { 11 | 12 | public boolean appliesTo(FieldMap fieldMap) { 13 | return (fieldMap.getSource().isMapKey() || fieldMap.getSource().isArrayElement() || fieldMap.getSource().isListElement()) 14 | && (ClassUtil.isImmutable(fieldMap.getDestination().getType()) || (!fieldMap.getDestination().isCollection() 15 | && !fieldMap.getDestination().isArray() && !fieldMap.getDestination().isMap() && !fieldMap.getDestination() 16 | .isEnum())); 17 | } 18 | 19 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 20 | return source + " == " + destination; 21 | } 22 | 23 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 24 | return statement(destination.assign(destination.cast(source))); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/ObjectToMultiOccurrenceElement.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.append; 4 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.statement; 5 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 6 | import ma.glasnost.orika.impl.generator.VariableRef; 7 | import ma.glasnost.orika.impl.util.ClassUtil; 8 | import ma.glasnost.orika.metadata.FieldMap; 9 | 10 | public class ObjectToMultiOccurrenceElement extends AbstractSpecification { 11 | 12 | public boolean appliesTo(FieldMap fieldMap) { 13 | return (fieldMap.getDestination().isMapKey() || fieldMap.getDestination().isArrayElement() || fieldMap.getDestination().isListElement()) 14 | && (ClassUtil.isImmutable(fieldMap.getSource().getType()) || (!fieldMap.getSource().isCollection() 15 | && !fieldMap.getSource().isArray() && !fieldMap.getSource().isMap() && !fieldMap.getSource() 16 | .isEnum())); 17 | } 18 | 19 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 20 | return source + " == " + destination; 21 | } 22 | 23 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 24 | 25 | StringBuilder out = new StringBuilder(); 26 | if (!source.isPrimitive()) { 27 | out.append(source.ifNotNull() + "{"); 28 | } 29 | out.append(statement(destination.assign(source))); 30 | if (!source.isPrimitive()) { 31 | out.append("}"); 32 | if (shouldMapNulls(fieldMap, code) && !destination.isPrimitive()) { 33 | append(out, 34 | " else {\n", 35 | destination.assignIfPossible("null"), 36 | "}\n"); 37 | } 38 | } 39 | return out.toString(); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/PrimitiveAndObject.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import ma.glasnost.orika.MappingException; 4 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 5 | import ma.glasnost.orika.impl.generator.VariableRef; 6 | import ma.glasnost.orika.metadata.FieldMap; 7 | 8 | /** 9 | * @author mattdeboer 10 | * 11 | */ 12 | public class PrimitiveAndObject extends AbstractSpecification { 13 | 14 | public boolean appliesTo(FieldMap fieldMap) { 15 | return fieldMap.getSource().getType().isPrimitive() || fieldMap.getDestination().getType().isPrimitive(); 16 | } 17 | 18 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 19 | return source + " == " + destination; 20 | } 21 | 22 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 23 | throw new MappingException("Encountered mapping of primitive to object (or vise-versa); sourceType="+ 24 | source.type() + ", destinationType=" + destination.type()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/StringToEnum.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import static java.lang.String.format; 4 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.statement; 5 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 6 | import ma.glasnost.orika.impl.generator.VariableRef; 7 | import ma.glasnost.orika.metadata.FieldMap; 8 | 9 | public class StringToEnum extends AbstractSpecification { 10 | 11 | public boolean appliesTo(FieldMap fieldMap) { 12 | return fieldMap.getBType().isEnum() && fieldMap.getAType().isString(); 13 | } 14 | 15 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 16 | return "(Enum.valueOf(%s.class, \"\"+%s) == " + destination +")"; 17 | } 18 | 19 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 20 | String assignEnum = destination.assign("Enum.valueOf(%s.class, \"\"+%s)", destination.typeName(), source); 21 | String mapNull = shouldMapNulls(fieldMap, code) ? format(" else {\n %s;\n}", destination.assignIfPossible("null")): ""; 22 | return statement("%s { %s; } %s", source.ifNotNull(), assignEnum, mapNull); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/StringToStringConvertible.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import static java.lang.String.format; 4 | import static ma.glasnost.orika.impl.generator.SourceCodeContext.statement; 5 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 6 | import ma.glasnost.orika.impl.generator.VariableRef; 7 | import ma.glasnost.orika.metadata.FieldMap; 8 | 9 | public class StringToStringConvertible extends AbstractSpecification { 10 | 11 | public boolean appliesTo(FieldMap fieldMap) { 12 | return String.class.equals(fieldMap.getSource().getType().getRawType()) 13 | && (fieldMap.getDestination().getType().isPrimitive() || fieldMap.getDestination().getType().isPrimitiveWrapper()); 14 | } 15 | 16 | public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 17 | return "(" + source.notNull() + " && " + source + ".equals(\"\" + " + destination +"))"; 18 | } 19 | 20 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 21 | String value = source.toString(); 22 | if (String.class.equals(source.rawType()) && (Character.class.equals(destination.rawType()) || char.class.equals(destination.rawType()))) { 23 | value = value + ".charAt(0)"; 24 | } 25 | if (destination.isPrimitive()) { 26 | return statement(destination.assign("%s.valueOf(%s)", destination.wrapperTypeName(), value)); 27 | } else { 28 | String mapNull = shouldMapNulls(fieldMap, code) ? format(" else { %s; }", destination.assignIfPossible("null")): ""; 29 | return statement(format("%s {\n %s; } %s", source.ifNotNull(), destination.assign("%s.valueOf(%s)", destination.typeName(), value), mapNull)); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/generator/specification/UnmappableEnum.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.impl.generator.specification; 2 | 3 | import ma.glasnost.orika.MappingException; 4 | import ma.glasnost.orika.impl.generator.SourceCodeContext; 5 | import ma.glasnost.orika.impl.generator.VariableRef; 6 | import ma.glasnost.orika.metadata.FieldMap; 7 | 8 | /** 9 | * UnmappableEnum is a place-holder specification to catch types which 10 | * cannot be mapped (and which shouldn't fall through to some other specification) 11 | * 12 | * @author mattdeboer 13 | * 14 | */ 15 | public class UnmappableEnum extends AbstractSpecification { 16 | 17 | public boolean appliesTo(FieldMap fieldMap) { 18 | return fieldMap.getBType().isEnum() && !fieldMap.getAType().isEnum() && !fieldMap.getAType().isString(); 19 | } 20 | 21 | public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) { 22 | throw new MappingException("Encountered mapping of enum to object (or vise-versa); sourceType="+ 23 | source.type() + ", destinationType=" + destination.type()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/mapping/strategy/CopyByReferenceStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.impl.mapping.strategy; 20 | 21 | import ma.glasnost.orika.MappingContext; 22 | import ma.glasnost.orika.metadata.Type; 23 | 24 | public class CopyByReferenceStrategy implements MappingStrategy { 25 | 26 | private static class Singleton { 27 | private static CopyByReferenceStrategy INSTANCE = new CopyByReferenceStrategy(); 28 | } 29 | 30 | public static CopyByReferenceStrategy getInstance() { 31 | return Singleton.INSTANCE; 32 | } 33 | 34 | private CopyByReferenceStrategy() { 35 | 36 | } 37 | 38 | public Object map(Object sourceObject, Object destinationObject, MappingContext context) { 39 | return sourceObject; 40 | } 41 | 42 | /* (non-Javadoc) 43 | * @see ma.glasnost.orika.impl.mapping.strategy.MappingStrategy#getSoureType() 44 | */ 45 | public Type getSoureType() { 46 | return null; 47 | } 48 | 49 | /* (non-Javadoc) 50 | * @see ma.glasnost.orika.impl.mapping.strategy.MappingStrategy#getDestinationType() 51 | */ 52 | public Type getDestinationType() { 53 | return null; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/mapping/strategy/InstantiateAndUseCustomMapperStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.impl.mapping.strategy; 20 | 21 | import ma.glasnost.orika.MappingContext; 22 | import ma.glasnost.orika.ObjectFactory; 23 | import ma.glasnost.orika.metadata.Type; 24 | import ma.glasnost.orika.unenhance.UnenhanceStrategy; 25 | 26 | public class InstantiateAndUseCustomMapperStrategy extends UseCustomMapperStrategy { 27 | 28 | protected final ObjectFactory objectFactory; 29 | 30 | public InstantiateAndUseCustomMapperStrategy(Type sourceType, Type destinationType, DirectionalCustomMapperReference customMapper, ObjectFactory objectFactory, UnenhanceStrategy unenhancer) { 31 | super(sourceType, destinationType, customMapper, unenhancer); 32 | this.objectFactory = objectFactory; 33 | } 34 | 35 | protected Object getInstance(Object sourceObject, Object destinationObject, MappingContext context) { 36 | return objectFactory.create(sourceObject, context); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/mapping/strategy/InstantiateByDefaultAndUseCustomMapperStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.impl.mapping.strategy; 20 | 21 | import ma.glasnost.orika.MappingContext; 22 | import ma.glasnost.orika.metadata.Type; 23 | import ma.glasnost.orika.unenhance.UnenhanceStrategy; 24 | 25 | public class InstantiateByDefaultAndUseCustomMapperStrategy extends UseCustomMapperStrategy { 26 | 27 | public InstantiateByDefaultAndUseCustomMapperStrategy(Type sourceType, Type destinationType, DirectionalCustomMapperReference customMapper, UnenhanceStrategy unenhancer) { 28 | super(sourceType, destinationType, customMapper, unenhancer); 29 | } 30 | 31 | protected Object getInstance(Object sourceObject, Object destinationObject, MappingContext context) { 32 | try { 33 | return destinationType.getRawType().newInstance(); 34 | } catch (InstantiationException e) { 35 | throw new RuntimeException(e); 36 | } catch (IllegalAccessException e) { 37 | throw new RuntimeException(e); 38 | } 39 | } 40 | 41 | public String toString() { 42 | StringBuilder description = new StringBuilder(); 43 | description.append(getClass().getSimpleName() + "("); 44 | description.append(this.customMapper); 45 | description.append(")"); 46 | return description.toString(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/mapping/strategy/MapExistingAndUseCustomMapperStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.impl.mapping.strategy; 20 | 21 | import ma.glasnost.orika.MappingContext; 22 | import ma.glasnost.orika.metadata.Type; 23 | import ma.glasnost.orika.unenhance.UnenhanceStrategy; 24 | 25 | public class MapExistingAndUseCustomMapperStrategy extends UseCustomMapperStrategy { 26 | 27 | public MapExistingAndUseCustomMapperStrategy(Type sourceType, Type destinationType, DirectionalCustomMapperReference customMapper, UnenhanceStrategy unenhancer) { 28 | super(sourceType, destinationType, customMapper, unenhancer); 29 | } 30 | 31 | protected Object getInstance(Object sourceObject, Object destinationObject, MappingContext context) { 32 | return destinationObject; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/mapping/strategy/MappingStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.impl.mapping.strategy; 20 | 21 | import ma.glasnost.orika.MappingContext; 22 | import ma.glasnost.orika.metadata.Type; 23 | 24 | /** 25 | * MappingStrategy defines the contract for a pre-resolved classification of mapping 26 | * which may be cached for quick lookup based on raw inputs. 27 | * 28 | * @author matt.deboer@gmail.com 29 | * 30 | */ 31 | public interface MappingStrategy { 32 | 33 | /** 34 | * Perform the mapping 35 | * 36 | * @param sourceObject the source object to map 37 | * @param destinationObject the pre-instantiated destination object onto which properties 38 | * should be copied; may be null 39 | * @param context the current mapping context 40 | * @return the mapping result 41 | */ 42 | public Object map(Object sourceObject, Object destinationObject, MappingContext context); 43 | 44 | public Type getSoureType(); 45 | 46 | public Type getDestinationType(); 47 | 48 | } 49 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/impl/util/StringUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.impl.util; 19 | 20 | /** 21 | * @author matt.deboer@gmail.com 22 | * 23 | */ 24 | public abstract class StringUtil { 25 | 26 | public static String capitalize(String string) { 27 | if ("".equals(string)) { 28 | return ""; 29 | } else if (string.length() == 1) { 30 | return string.substring(0,1).toUpperCase(); 31 | } else { 32 | return string.substring(0,1).toUpperCase() + string.substring(1); 33 | } 34 | } 35 | 36 | 37 | } 38 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/inheritance/DefaultSuperTypeResolverStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.inheritance; 20 | 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | public abstract class DefaultSuperTypeResolverStrategy implements SuperTypeResolverStrategy { 24 | 25 | public abstract boolean isAcceptable(Type type); 26 | 27 | public boolean accept(Type type) { 28 | return isAcceptable(type); 29 | } 30 | 31 | public boolean shouldLookupSuperType(Type type) { 32 | return !isAcceptable(type); 33 | } 34 | 35 | public boolean shouldPreferClassOverInterface() { 36 | return true; 37 | } 38 | }; 39 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/inheritance/SuperTypeResolverStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.inheritance; 20 | 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | /** 24 | * This strategy is used by the super-type resolver to 25 | * determine when and how to lookup a super-type, and and 26 | * also provides decision as to whether the super-type is 27 | * accepted. 28 | * 29 | * @author matt.deboer@gmail.com 30 | */ 31 | public interface SuperTypeResolverStrategy { 32 | 33 | /** 34 | * @param type 35 | * @return true if the proposed super-type is acceptable 36 | */ 37 | public boolean accept(Type type); 38 | 39 | /** 40 | * 41 | * @param type 42 | * @return true if a super-type should be looked up for the proposed type; 43 | * false signifies that the class should be returned as-is. 44 | */ 45 | public boolean shouldLookupSuperType(Type type); 46 | 47 | /** 48 | * @return true if a super class(es) should be looked-up first before 49 | * trying interfaces 50 | */ 51 | public boolean shouldPreferClassOverInterface(); 52 | } 53 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/metadata/ArrayElementProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.metadata; 19 | 20 | /** 21 | * ListElementProperty is a special Property instance used to represent a value 22 | * which associated with a particular index in a list. 23 | * 24 | * @author matt.deboer@gmail.com 25 | * 26 | */ 27 | public class ArrayElementProperty extends Property { 28 | 29 | public ArrayElementProperty(int index, Type propertyType, Property container) { 30 | super("["+index + "]","["+index + "]","["+index + "]","["+index + "] = %s",propertyType,null, container); 31 | } 32 | 33 | public boolean isArrayElement() { 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/metadata/ListElementProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.metadata; 19 | 20 | /** 21 | * ListElementProperty is a special Property instance used to represent a value 22 | * which associated with a particular index in a list. 23 | * 24 | * @author matt.deboer@gmail.com 25 | * 26 | */ 27 | public class ListElementProperty extends Property { 28 | 29 | public ListElementProperty(int index, Type propertyType, Property owner) { 30 | super(""+index,""+index,"get(" + index + ")","add(" + index + ", %s)",propertyType,null, owner); 31 | } 32 | 33 | public boolean isListElement() { 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/metadata/MapKeyProperty.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.metadata; 19 | 20 | /** 21 | * MapKeyProperty is a special Property instance used to represent a value 22 | * which associated with a key within a Map. 23 | * 24 | * @author matt.deboer@gmail.com 25 | * 26 | */ 27 | public class MapKeyProperty extends Property { 28 | 29 | public MapKeyProperty(String key, Type type, Property owner) { 30 | super(key,key,"get(\"" + key + "\")","put(\"" + key + "\",%s)",type,null, owner); 31 | } 32 | 33 | public boolean isMapKey() { 34 | return true; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/metadata/MappingDirection.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.metadata; 2 | 3 | public enum MappingDirection { 4 | 5 | BIDIRECTIONAL { 6 | @Override 7 | MappingDirection flip() { 8 | return BIDIRECTIONAL; 9 | } 10 | }, 11 | 12 | A_TO_B { 13 | @Override 14 | MappingDirection flip() { 15 | return B_TO_A; 16 | } 17 | }, 18 | 19 | B_TO_A { 20 | @Override 21 | MappingDirection flip() { 22 | return A_TO_B; 23 | } 24 | }; 25 | 26 | abstract MappingDirection flip(); 27 | 28 | } 29 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/unenhance/UnenhanceStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.unenhance; 20 | 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | /** 24 | * Defines a strategy to unenhance an object specifically a proxy one like those 25 | * of Hibernate.
26 | * Unenhanement can be used in cases where a class needs to be "unwrapped" from 27 | * a proxy, or when a super-type or interface should be used for an object 28 | * instead of the object's own class. 29 | * 30 | * 31 | * @author S.M. El Aatifi 32 | * 33 | */ 34 | public interface UnenhanceStrategy { 35 | 36 | /** 37 | * Should return the unenhanced type to be used when determining attribute 38 | * mapping information for the type. 39 | * 40 | * @param 41 | * @param type 42 | * @return 43 | */ 44 | public Type unenhanceType(T object, Type type); 45 | 46 | public T unenhanceObject(T object, Type type); 47 | } 48 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/util/Cache.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.util; 2 | 3 | public interface Cache { 4 | 5 | void cache(K key, V value); 6 | 7 | V get(Object key); 8 | 9 | boolean containsKey(Object key); 10 | } 11 | -------------------------------------------------------------------------------- /core/src/main/java/ma/glasnost/orika/util/CacheLRULinkedHashMap.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.util; 2 | 3 | import java.util.LinkedHashMap; 4 | import java.util.Map; 5 | 6 | public class CacheLRULinkedHashMap extends LinkedHashMap implements Cache { 7 | private static final long serialVersionUID = 6402613994118746566L; 8 | private final int maxSize; 9 | 10 | public CacheLRULinkedHashMap(int initialCapacity) { 11 | super(initialCapacity, .75F, true); 12 | 13 | maxSize = initialCapacity; 14 | } 15 | 16 | @Override 17 | protected boolean removeEldestEntry(Map.Entry eldest) { 18 | return size() > maxSize; 19 | } 20 | 21 | public void cache(K key, V value) { 22 | put(key, value); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /core/src/test/java-hidden/types/AuthorHidden.java: -------------------------------------------------------------------------------- 1 | package types; 2 | 3 | import ma.glasnost.orika.test.unenhance.SuperTypeTestCaseClasses.Author; 4 | 5 | public class AuthorHidden implements Author { 6 | 7 | private String name; 8 | 9 | public String getName() { 10 | return name; 11 | } 12 | 13 | public void setName(String name) { 14 | this.name = name; 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /core/src/test/java-hidden/types/BookHidden.java: -------------------------------------------------------------------------------- 1 | package types; 2 | 3 | import ma.glasnost.orika.test.unenhance.SuperTypeTestCaseClasses.Author; 4 | import ma.glasnost.orika.test.unenhance.SuperTypeTestCaseClasses.Book; 5 | 6 | public class BookHidden implements Book { 7 | 8 | private String title; 9 | private Author author; 10 | 11 | 12 | public String getTitle() { 13 | return title; 14 | } 15 | 16 | public void setTitle(String title) { 17 | this.title = title; 18 | } 19 | 20 | public Author getAuthor() { 21 | return author; 22 | } 23 | 24 | public void setAuthor(Author author) { 25 | this.author = author; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /core/src/test/java-hidden/types/LibraryHidden.java: -------------------------------------------------------------------------------- 1 | package types; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import ma.glasnost.orika.test.unenhance.SuperTypeTestCaseClasses.Book; 7 | import ma.glasnost.orika.test.unenhance.SuperTypeTestCaseClasses.Library; 8 | 9 | public class LibraryHidden implements Library { 10 | 11 | private String title; 12 | 13 | private List books; 14 | 15 | public String getTitle() { 16 | return title; 17 | } 18 | 19 | public void setTitle(String title) { 20 | this.title = title; 21 | } 22 | 23 | public List getBooks() { 24 | if (books==null) { 25 | books = new ArrayList(); 26 | } 27 | return books; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /core/src/test/java-hidden/types/Runner.java: -------------------------------------------------------------------------------- 1 | package types; 2 | 3 | 4 | import ma.glasnost.orika.MapperFactory; 5 | import ma.glasnost.orika.metadata.ClassMapBuilder; 6 | import ma.glasnost.orika.test.MappingUtil; 7 | import ma.glasnost.orika.test.common.types.TestCaseClasses.BookDTO; 8 | 9 | import org.junit.Test; 10 | 11 | public class Runner { 12 | 13 | public static void run(MapperFactory mapperFactory) { 14 | 15 | 16 | mapperFactory.registerClassMap( 17 | ClassMapBuilder.map(BookHidden.class, BookDTO.class).byDefault().toClassMap()); 18 | 19 | AuthorHidden author = new AuthorHidden(); 20 | author.setName("Chuck Testa"); 21 | 22 | BookHidden book = new BookHidden(); 23 | book.setAuthor(author); 24 | 25 | mapperFactory.getMapperFacade().map(book, BookDTO.class); 26 | 27 | } 28 | 29 | 30 | @Test 31 | public void test() { 32 | run(MappingUtil.getMapperFactory()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /eclipse-tools/.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | #Sat Sep 29 13:38:05 PDT 2012 2 | eclipse.preferences.version=1 3 | encoding//src/main/java=UTF-8 4 | encoding//src/main/resources=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /eclipse-tools/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | #Sat Sep 29 13:38:06 PDT 2012 2 | eclipse.preferences.version=1 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.compliance=1.5 5 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 6 | org.eclipse.jdt.core.compiler.source=1.5 7 | -------------------------------------------------------------------------------- /eclipse-tools/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | #Sat Sep 29 13:38:00 PDT 2012 2 | activeProfiles= 3 | eclipse.preferences.version=1 4 | resolveWorkspaceProjects=true 5 | version=1 6 | -------------------------------------------------------------------------------- /eclipse-tools/src/main/java/ma/glasnost/orika/impl/generator/ByteCodeClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.impl.generator; 20 | 21 | import java.util.Map; 22 | import java.util.concurrent.ConcurrentHashMap; 23 | 24 | /** 25 | * A simple class-loader that can load classes from bytes that have been 26 | * pre-cached for the given class name. 27 | * 28 | * @author matt.deboer@gmail.com 29 | * 30 | */ 31 | public class ByteCodeClassLoader extends ClassLoader { 32 | 33 | private Map classData; 34 | 35 | public ByteCodeClassLoader(ClassLoader parent) { 36 | super(parent); 37 | classData = new ConcurrentHashMap(); 38 | } 39 | 40 | /** 41 | * Cache the bytes for a given class by name; will be used upon a subsequent 42 | * load request. 43 | * 44 | * @param name 45 | * @param data 46 | */ 47 | void putClassData(String name, byte[] data) { 48 | classData.put(name, data); 49 | } 50 | 51 | byte[] getBytes(String name) { 52 | byte[] data = classData.get(name); 53 | return data != null ? data.clone() : null; 54 | } 55 | 56 | protected Class findClass(String name) throws ClassNotFoundException { 57 | byte[] b = classData.get(name); 58 | if (b == null) { 59 | throw new ClassNotFoundException(name); 60 | } 61 | return defineClass(name, b, 0, b.length); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /eclipse-tools/src/main/java/ma/glasnost/orika/impl/generator/eclipsejdt/CompilationUnit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.impl.generator.eclipsejdt; 20 | 21 | import java.util.StringTokenizer; 22 | 23 | import org.eclipse.jdt.internal.compiler.env.ICompilationUnit; 24 | 25 | public class CompilationUnit implements ICompilationUnit { 26 | 27 | private String packageName; 28 | private String source; 29 | private String mainTypeName; 30 | 31 | /** 32 | * @param source the source text from which the class will be compiled 33 | * @param packageName the name of the package 34 | * @param simpleClassName this is the name of the class without the package, but including 35 | * the parent type if the class is a nested class. 36 | */ 37 | public CompilationUnit(String source, String packageName, String simpleClassName) { 38 | this.packageName = packageName; 39 | if (simpleClassName.contains(".")) { 40 | mainTypeName = simpleClassName.split("[.]")[0]; 41 | } else { 42 | mainTypeName = simpleClassName; 43 | } 44 | this.source = source; 45 | } 46 | 47 | public char[] getFileName() { 48 | return (mainTypeName + ".java").toCharArray(); 49 | } 50 | 51 | public char[] getContents() { 52 | return source.toCharArray(); 53 | } 54 | 55 | public char[] getMainTypeName() { 56 | return mainTypeName.toCharArray(); 57 | } 58 | 59 | public char[][] getPackageName() { 60 | StringTokenizer izer = new StringTokenizer(packageName, "."); 61 | char[][] result = new char[izer.countTokens()][]; 62 | for (int i = 0; i < result.length; i++) { 63 | String tok = izer.nextToken(); 64 | result[i] = tok.toCharArray(); 65 | } 66 | return result; 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /tests/src/main/java-hidden/dtotypes/AuthorHiddenDto.java: -------------------------------------------------------------------------------- 1 | package dtotypes; 2 | 3 | public class AuthorHiddenDto { 4 | 5 | private String name; 6 | 7 | public String getName() { 8 | return name; 9 | } 10 | 11 | public void setName(String name) { 12 | this.name = name; 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /tests/src/main/java-hidden/dtotypes/BookHiddenDto.java: -------------------------------------------------------------------------------- 1 | package dtotypes; 2 | 3 | public class BookHiddenDto { 4 | 5 | private String title; 6 | private AuthorHiddenDto author; 7 | 8 | 9 | public String getTitle() { 10 | return title; 11 | } 12 | 13 | public void setTitle(String title) { 14 | this.title = title; 15 | } 16 | 17 | public AuthorHiddenDto getAuthor() { 18 | return author; 19 | } 20 | 21 | public void setAuthor(AuthorHiddenDto author) { 22 | this.author = author; 23 | } 24 | 25 | } -------------------------------------------------------------------------------- /tests/src/main/java-hidden/dtotypes/LibraryHiddenDto.java: -------------------------------------------------------------------------------- 1 | package dtotypes; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | 7 | public class LibraryHiddenDto { 8 | 9 | private String title; 10 | 11 | private List books; 12 | 13 | public String getTitle() { 14 | return title; 15 | } 16 | 17 | public void setTitle(String title) { 18 | this.title = title; 19 | } 20 | 21 | public List getBooks() { 22 | if (books==null) { 23 | books = new ArrayList(); 24 | } 25 | return books; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /tests/src/main/java-hidden/dtotypes/Runner.java: -------------------------------------------------------------------------------- 1 | package dtotypes; 2 | 3 | 4 | import types.BookHidden; 5 | import types.AuthorHidden; 6 | 7 | import ma.glasnost.orika.MapperFactory; 8 | import ma.glasnost.orika.test.MappingUtil; 9 | 10 | import org.junit.Test; 11 | 12 | public class Runner { 13 | 14 | public static void run(MapperFactory mapperFactory) { 15 | 16 | mapperFactory.classMap(BookHidden.class, BookHiddenDto.class).byDefault().register(); 17 | 18 | AuthorHidden author = new AuthorHidden(); 19 | author.setName("Chuck Testa"); 20 | 21 | BookHidden book = new BookHidden(); 22 | book.setAuthor(author); 23 | 24 | mapperFactory.getMapperFacade().map(book, BookHiddenDto.class); 25 | 26 | } 27 | 28 | 29 | @Test 30 | public void test() { 31 | run(MappingUtil.getMapperFactory()); 32 | } 33 | 34 | } 35 | -------------------------------------------------------------------------------- /tests/src/main/java-hidden/types/AuthorHidden.java: -------------------------------------------------------------------------------- 1 | package types; 2 | 3 | import ma.glasnost.orika.test.unenhance.SuperTypeTestCaseClasses.Author; 4 | 5 | public class AuthorHidden implements Author { 6 | 7 | private String name; 8 | 9 | public String getName() { 10 | return name; 11 | } 12 | 13 | public void setName(String name) { 14 | this.name = name; 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /tests/src/main/java-hidden/types/BookHidden.java: -------------------------------------------------------------------------------- 1 | package types; 2 | 3 | import ma.glasnost.orika.test.unenhance.SuperTypeTestCaseClasses.Author; 4 | import ma.glasnost.orika.test.unenhance.SuperTypeTestCaseClasses.Book; 5 | 6 | public class BookHidden implements Book { 7 | 8 | private String title; 9 | private Author author; 10 | 11 | 12 | public String getTitle() { 13 | return title; 14 | } 15 | 16 | public void setTitle(String title) { 17 | this.title = title; 18 | } 19 | 20 | public Author getAuthor() { 21 | return author; 22 | } 23 | 24 | public void setAuthor(Author author) { 25 | this.author = author; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /tests/src/main/java-hidden/types/LibraryHidden.java: -------------------------------------------------------------------------------- 1 | package types; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import ma.glasnost.orika.test.unenhance.SuperTypeTestCaseClasses.Book; 7 | import ma.glasnost.orika.test.unenhance.SuperTypeTestCaseClasses.Library; 8 | 9 | public class LibraryHidden implements Library { 10 | 11 | private String title; 12 | 13 | private List books; 14 | 15 | public String getTitle() { 16 | return title; 17 | } 18 | 19 | public void setTitle(String title) { 20 | this.title = title; 21 | } 22 | 23 | public List getBooks() { 24 | if (books==null) { 25 | books = new ArrayList(); 26 | } 27 | return books; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /tests/src/main/java-hidden/types/Runner.java: -------------------------------------------------------------------------------- 1 | package types; 2 | 3 | 4 | import ma.glasnost.orika.MapperFactory; 5 | import ma.glasnost.orika.metadata.ClassMapBuilder; 6 | import ma.glasnost.orika.test.MappingUtil; 7 | import ma.glasnost.orika.test.common.types.TestCaseClasses.BookDTO; 8 | 9 | import org.junit.Test; 10 | 11 | public class Runner { 12 | 13 | public static void run(MapperFactory mapperFactory) { 14 | 15 | 16 | mapperFactory.registerClassMap( 17 | ClassMapBuilder.map(BookHidden.class, BookDTO.class).byDefault().toClassMap()); 18 | 19 | AuthorHidden author = new AuthorHidden(); 20 | author.setName("Chuck Testa"); 21 | 22 | BookHidden book = new BookHidden(); 23 | book.setAuthor(author); 24 | 25 | mapperFactory.getMapperFacade().map(book, BookDTO.class); 26 | 27 | } 28 | 29 | 30 | @Test 31 | public void test() { 32 | run(MappingUtil.getMapperFactory()); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/HibernateUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.test; 20 | 21 | import org.hibernate.SessionFactory; 22 | import org.hibernate.cfg.Configuration; 23 | 24 | public final class HibernateUtil { 25 | 26 | private HibernateUtil() { 27 | 28 | } 29 | 30 | public static final SessionFactory sessionFactory; 31 | 32 | static { 33 | try { 34 | sessionFactory = new Configuration().configure().buildSessionFactory(); 35 | } catch (Throwable ex) { 36 | System.err.println("Initial SessionFactory creation failed." + ex); 37 | throw new ExceptionInInitializerError(ex); 38 | } 39 | } 40 | 41 | public static SessionFactory getSessionFactory() { 42 | return sessionFactory; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/MavenProjectUtil.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test; 2 | 3 | import java.io.File; 4 | import java.io.UnsupportedEncodingException; 5 | import java.net.URLDecoder; 6 | 7 | /** 8 | * MavenProjectUtil provides lookup of the current project's root folder, 9 | * assuming the default compile directory somewhere beneath the 'target' folder; 10 | * uses lookup of the current class' class-file as a resource and walks up 11 | * to the target folder 12 | * 13 | * @author matt.deboer@gmail.com 14 | * 15 | */ 16 | public class MavenProjectUtil { 17 | public static File findProjectRoot() { 18 | File classFile; 19 | try { 20 | classFile = new File(URLDecoder.decode( 21 | MavenProjectUtil.class.getClassLoader().getResource(MavenProjectUtil.class.getName().replace(".","/") + ".class").getFile(),"UTF-8")); 22 | } catch (UnsupportedEncodingException e) { 23 | throw new RuntimeException("Failed to get Maven project root",e); 24 | } 25 | File classFolder = classFile; 26 | for (int i=0, len=MavenProjectUtil.class.getName().split("\\.").length; i < len; ++i) 27 | classFolder = classFolder.getParentFile(); 28 | 29 | while(classFolder != null && !(classFolder.isDirectory() && "target".equals(classFolder.getName()))) 30 | classFolder = classFolder.getParentFile(); 31 | 32 | return classFolder != null ? classFolder.getParentFile() : null; 33 | 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/TestCase.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test; 2 | 3 | import junit.framework.Assert; 4 | import ma.glasnost.orika.MapperFacade; 5 | 6 | import org.junit.Ignore; 7 | import org.junit.Test; 8 | 9 | public class TestCase { 10 | 11 | public static class S { 12 | public Name name; 13 | public String description; 14 | } 15 | 16 | public static class D { 17 | public Name name; 18 | public String description; 19 | } 20 | 21 | public static class Name { 22 | public String first; 23 | public String last; 24 | } 25 | 26 | 27 | @Test 28 | @Ignore 29 | public void test() { 30 | 31 | MapperFacade mapper = MappingUtil.getMapperFactory().getMapperFacade(); 32 | 33 | S source = new S(); 34 | D dest = new D(); 35 | Name n = new Name(); 36 | n.first = "John"; 37 | n.last = "Doe"; 38 | dest.name = n; 39 | dest.description = "Typical"; 40 | 41 | mapper.map(source, dest); 42 | 43 | Assert.assertNotNull(dest.name); 44 | Assert.assertNotNull(dest.name.first); 45 | Assert.assertNotNull(dest.description); 46 | 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/array/ArrayTestCaseClasses.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.array; 2 | 3 | import java.util.List; 4 | 5 | public class ArrayTestCaseClasses { 6 | 7 | public static class A { 8 | private byte[] buffer; 9 | 10 | public byte[] getBuffer() { 11 | return buffer; 12 | } 13 | 14 | public void setBuffer(byte[] buffer) { 15 | this.buffer = buffer; 16 | } 17 | } 18 | 19 | public static class B { 20 | private byte[] buffer; 21 | 22 | public byte[] getBuffer() { 23 | return buffer; 24 | } 25 | 26 | public void setBuffer(byte[] buffer) { 27 | this.buffer = buffer; 28 | } 29 | } 30 | 31 | public static class C { 32 | private Byte[] buffer; 33 | 34 | public Byte[] getBuffer() { 35 | return buffer; 36 | } 37 | 38 | public void setBuffer(Byte[] buffer) { 39 | this.buffer = buffer; 40 | } 41 | } 42 | 43 | public static class D { 44 | private List buffer; 45 | 46 | public List getBuffer() { 47 | return buffer; 48 | } 49 | 50 | public void setBuffer(List buffer) { 51 | this.buffer = buffer; 52 | } 53 | 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/collection/ExplicitCollectionTestCase.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.collection; 2 | 3 | import java.util.Collection; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import ma.glasnost.orika.test.MappingUtil; 8 | 9 | import org.junit.Assert; 10 | import org.junit.Test; 11 | 12 | /** 13 | * Test a class that User: kenton Date: 12/7/12 Time: 10:50 AM 14 | */ 15 | public class ExplicitCollectionTestCase { 16 | 17 | @Test 18 | public void testStringToStringWithSpecifiedGenericType() { 19 | ExplicitSet set = new ExplicitSet(); 20 | set.add("1"); 21 | set.add("2"); 22 | A source = new A(); 23 | source.setStrings(set); 24 | 25 | B destination = MappingUtil.getMapperFactory().getMapperFacade().map(source, B.class); 26 | 27 | Assert.assertNotNull(destination.getStrings()); 28 | Assert.assertEquals(set.size(), destination.getStrings().size()); 29 | } 30 | 31 | public static class A { 32 | private ExplicitSet strings; 33 | 34 | public ExplicitSet getStrings() { 35 | return strings; 36 | } 37 | 38 | public void setStrings(ExplicitSet strings) { 39 | this.strings = strings; 40 | } 41 | } 42 | 43 | public static class B { 44 | private Set strings; 45 | 46 | public Set getStrings() { 47 | return strings; 48 | } 49 | 50 | public void setStrings(Set strings) { 51 | this.strings = strings; 52 | } 53 | } 54 | 55 | public static class ExplicitSet extends HashSet { 56 | 57 | private static final long serialVersionUID = 1L; 58 | 59 | public ExplicitSet(int i) { 60 | super(i); 61 | } 62 | 63 | public ExplicitSet(int i, float v) { 64 | super(i, v); 65 | } 66 | 67 | public ExplicitSet(Collection strings) { 68 | super(strings); 69 | } 70 | 71 | public ExplicitSet() { 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/Issue18TestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | 23 | import junit.framework.Assert; 24 | 25 | import ma.glasnost.orika.MapperFactory; 26 | import ma.glasnost.orika.impl.DefaultMapperFactory; 27 | import ma.glasnost.orika.metadata.ClassMapBuilder; 28 | 29 | import org.junit.Test; 30 | 31 | public class Issue18TestCase { 32 | 33 | 34 | @SuppressWarnings("deprecation") 35 | @Test 36 | public void testMappingEmptyArray() { 37 | 38 | MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); 39 | mapperFactory.registerClassMap(ClassMapBuilder.map(Object.class,Object.class).byDefault().toClassMap()); 40 | List listA = new ArrayList(); 41 | List listB = mapperFactory.getMapperFacade().mapAsList(listA, Object.class); 42 | 43 | Assert.assertNotNull(listB); 44 | Assert.assertTrue(listB.isEmpty()); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/Issue19TestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community; 19 | 20 | import junit.framework.Assert; 21 | import ma.glasnost.orika.MapperFactory; 22 | import ma.glasnost.orika.impl.DefaultMapperFactory; 23 | 24 | import org.junit.Test; 25 | 26 | public class Issue19TestCase { 27 | 28 | @Test 29 | public void test() { 30 | MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); 31 | 32 | A a = new A(); 33 | a.setAttribute("attribute"); 34 | 35 | B b = new B(); 36 | mapperFactory.getMapperFacade().map(a, b); 37 | Assert.assertEquals(a.getAttribute(),b.getAttribute()); 38 | 39 | B b1 = new B(); 40 | mapperFactory.getMapperFacade().map(a, b1); 41 | Assert.assertEquals(a.getAttribute(),b1.getAttribute()); 42 | } 43 | 44 | static public class A { 45 | private String attribute; 46 | 47 | public String getAttribute() { 48 | return attribute; 49 | } 50 | 51 | public void setAttribute(String attribute) { 52 | this.attribute = attribute; 53 | } 54 | } 55 | 56 | static public class B { 57 | private String attribute; 58 | 59 | public String getAttribute() { 60 | return attribute; 61 | } 62 | 63 | public void setAttribute(String attribute) { 64 | this.attribute = attribute; 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/Issue24TestCase.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community; 2 | 3 | import ma.glasnost.orika.MapperFactory; 4 | import ma.glasnost.orika.MappingContext; 5 | import ma.glasnost.orika.metadata.ClassMapBuilder; 6 | import ma.glasnost.orika.metadata.Type; 7 | import ma.glasnost.orika.metadata.TypeFactory; 8 | import ma.glasnost.orika.test.MappingUtil; 9 | import org.junit.Assert; 10 | import org.junit.Test; 11 | 12 | /** 13 | * Issue 24: 14 | * lookupConcreteDestinationType should return the most specific type, 15 | * not the first that is assignable 16 | * 17 | * @author mattdeboer 18 | * 19 | */ 20 | public class Issue24TestCase { 21 | 22 | @Test 23 | public void testLookupDestinationGetsMostSpecific() { 24 | MapperFactory factory = MappingUtil.getMapperFactory(); 25 | 26 | factory.registerClassMap(ClassMapBuilder.map(A.class, BSub.class).byDefault().toClassMap()); 27 | factory.registerClassMap(ClassMapBuilder.map(A.class, B.class).byDefault().toClassMap()); 28 | factory.registerClassMap(ClassMapBuilder.map(A.class, BSuper.class).byDefault().toClassMap()); 29 | factory.getMapperFacade(); 30 | 31 | Type bsuper = factory.lookupConcreteDestinationType(TypeFactory.valueOf(A.class), TypeFactory.valueOf(BSuper.class), null); 32 | Assert.assertEquals(BSuper.class, bsuper.getRawType()); 33 | Type b = factory.lookupConcreteDestinationType(TypeFactory.valueOf(A.class), TypeFactory.valueOf(B.class), null); 34 | Assert.assertEquals(B.class, b.getRawType()); 35 | Type bsub = factory.lookupConcreteDestinationType(TypeFactory.valueOf(A.class), TypeFactory.valueOf(BSub.class), null); 36 | Assert.assertEquals(BSub.class, bsub.getRawType()); 37 | } 38 | 39 | public class A { 40 | 41 | } 42 | 43 | public class BSuper extends B { 44 | 45 | } 46 | 47 | public class B extends BSub { 48 | 49 | } 50 | 51 | public class BSub { 52 | 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/Issue26TestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community; 19 | 20 | import junit.framework.Assert; 21 | import ma.glasnost.orika.MapperFacade; 22 | import ma.glasnost.orika.MapperFactory; 23 | import ma.glasnost.orika.impl.DefaultMapperFactory; 24 | import ma.glasnost.orika.test.MappingUtil; 25 | import ma.glasnost.orika.test.community.issue26.Order; 26 | import ma.glasnost.orika.test.community.issue26.OrderData; 27 | import ma.glasnost.orika.test.community.issue26.OrderID; 28 | import ma.glasnost.orika.test.community.issue26.OrderIDConverter; 29 | 30 | import org.junit.Test; 31 | 32 | public class Issue26TestCase { 33 | 34 | @Test 35 | public void testMapping() { 36 | MapperFactory mapperFactory = MappingUtil.getMapperFactory(); 37 | 38 | mapperFactory.registerClassMap( 39 | mapperFactory.classMap(Order.class, OrderData.class) 40 | .field("entityID", "orderId").byDefault().toClassMap()); 41 | 42 | mapperFactory.getConverterFactory().registerConverter(new OrderIDConverter()); 43 | MapperFacade facade = mapperFactory.getMapperFacade(); 44 | 45 | OrderData data = new OrderData(1234l); 46 | Order order = facade.map(data, Order.class); 47 | Assert.assertEquals(new OrderID(1234l), order.getEntityID()); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/Issue38TestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community; 19 | 20 | import org.junit.Assert; 21 | import org.junit.Test; 22 | 23 | import ma.glasnost.orika.MapperFacade; 24 | import ma.glasnost.orika.MapperFactory; 25 | import ma.glasnost.orika.metadata.ClassMapBuilder; 26 | import ma.glasnost.orika.test.MappingUtil; 27 | 28 | public class Issue38TestCase { 29 | 30 | @Test 31 | public void testAvoidEmptyObjectCreation() { 32 | MapperFactory factory = MappingUtil.getMapperFactory(); 33 | 34 | factory.registerClassMap(ClassMapBuilder.map(A.class, B.class).field("b.i1", "i1").field("b.i2", "i2").toClassMap()); 35 | 36 | MapperFacade mapperFacade = factory.getMapperFacade(); 37 | 38 | 39 | B b = new B(); 40 | b.i1 = null; 41 | b.i2 = null; 42 | 43 | 44 | A result = mapperFacade.map(b, A.class); 45 | 46 | Assert.assertNull(result.b); 47 | 48 | b.i1 = 2; 49 | b.i2 = null; 50 | } 51 | 52 | @Test 53 | public void testCreateDestinationIfNotNull() { 54 | MapperFactory factory = MappingUtil.getMapperFactory(); 55 | 56 | factory.registerClassMap(ClassMapBuilder.map(A.class, B.class).field("b.i1", "i1").field("b.i2", "i2").toClassMap()); 57 | 58 | MapperFacade mapperFacade = factory.getMapperFacade(); 59 | 60 | 61 | B b = new B(); 62 | b.i1 = 2; 63 | b.i2 = 3; 64 | 65 | 66 | A result = mapperFacade.map(b, A.class); 67 | 68 | Assert.assertNotNull(result.b); 69 | Assert.assertEquals(b.i1, result.b.i1); 70 | Assert.assertEquals(b.i2, result.b.i2); 71 | 72 | } 73 | 74 | public static class A { 75 | public B b; 76 | } 77 | 78 | public static class B { 79 | public Integer i1; 80 | public Integer i2; 81 | } 82 | 83 | 84 | 85 | } 86 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/Issue49TestCase.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community; 2 | 3 | import ma.glasnost.orika.MapperFacade; 4 | import ma.glasnost.orika.MapperFactory; 5 | import ma.glasnost.orika.impl.DefaultMapperFactory; 6 | 7 | import org.junit.Assert; 8 | import org.junit.Test; 9 | 10 | /** 11 | * Verify that we use Enum.name istead of Enum.toString 12 | * 13 | * @author Dmitriy Khomyakov 14 | */ 15 | public class Issue49TestCase { 16 | 17 | @Test 18 | public void testMapOfEnum() { 19 | DefaultMapperFactory.Builder builder = new DefaultMapperFactory.Builder(); 20 | MapperFactory factory = builder.build(); 21 | MapperFacade mapperFacade = factory.getMapperFacade(); 22 | Entity entity = new Entity(); 23 | entity.setState(State.B); 24 | final Dto dto = mapperFacade.map(entity, Dto.class); 25 | Assert.assertEquals(dto.getState(), entity.getState()); 26 | } 27 | 28 | public static enum State { 29 | A { 30 | @Override 31 | public String toString() { 32 | return "first"; 33 | } 34 | }, 35 | B { 36 | @Override 37 | public String toString() { 38 | return "second"; 39 | } 40 | } 41 | } 42 | 43 | public static class Entity { 44 | private State state; 45 | 46 | public State getState() { 47 | return state; 48 | } 49 | 50 | public void setState(State state) { 51 | this.state = state; 52 | } 53 | } 54 | 55 | public static class Dto { 56 | private State state; 57 | 58 | public State getState() { 59 | return state; 60 | } 61 | 62 | public void setState(State state) { 63 | this.state = state; 64 | } 65 | } 66 | 67 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/Issue67TestCase.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community; 2 | 3 | import org.junit.Test; 4 | 5 | import ma.glasnost.orika.MapperFacade; 6 | import ma.glasnost.orika.MapperFactory; 7 | import ma.glasnost.orika.impl.DefaultMapperFactory; 8 | 9 | public class Issue67TestCase { 10 | 11 | @Test 12 | public void simpleCase() { 13 | MapperFactory factory = new DefaultMapperFactory.Builder().build(); 14 | factory.registerClassMap(factory.classMap(Bean.class, Bean.class) 15 | .byDefault().toClassMap()); 16 | MapperFacade mapper = factory.getMapperFacade(); 17 | Bean bean = new Bean(); 18 | bean.setSize(20); 19 | bean.setName("Kidney"); 20 | mapper.map(bean, Bean.class); 21 | 22 | /* If map pass no need to check */ 23 | } 24 | 25 | public static class Bean { 26 | 27 | private String name; 28 | private int size; 29 | 30 | /* 31 | * public int getSize() { return size; } 32 | */ 33 | public void setSize(int size) { 34 | this.size = size; 35 | } 36 | 37 | public String getName() { 38 | return name; 39 | } 40 | 41 | public void setName(String value) { 42 | this.name = value; 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/collection/AbstractMapperTest.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community.collection; 2 | 3 | import ma.glasnost.orika.MapperFactory; 4 | import ma.glasnost.orika.impl.DefaultMapperFactory; 5 | 6 | public abstract class AbstractMapperTest { 7 | protected MapperFactory createMapperFactory() { 8 | // MapperFactory mapperFactory = new 9 | // DefaultMapperFactory.Builder().compilerStrategy(new 10 | // EclipseJdtCompilerStrategy()).build(); 11 | MapperFactory mapperFactory = new DefaultMapperFactory.Builder().build(); 12 | return mapperFactory; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/collection/AbstractOrder.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community.collection; 2 | 3 | import java.util.Collection; 4 | 5 | public class AbstractOrder

{ 6 | private Collection

positions; 7 | 8 | // sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to 9 | // java.lang.Class 10 | public Collection

getPositions() { 11 | return positions; 12 | } 13 | 14 | // sun.reflect.generics.reflectiveObjects.WildcardTypeImpl cannot be cast to 15 | // java.lang.Class 16 | public Collection getPositionen2() { 17 | return positions; 18 | } 19 | 20 | public void setPositions(Collection

positions) { 21 | this.positions = positions; 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/collection/IPosition.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community.collection; 2 | 3 | public interface IPosition { 4 | 5 | } 6 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/collection/MapperTest.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community.collection; 2 | 3 | import ma.glasnost.orika.MapperFacade; 4 | import ma.glasnost.orika.MapperFactory; 5 | 6 | import org.junit.Assert; 7 | import org.junit.Before; 8 | import org.junit.Test; 9 | 10 | public class MapperTest extends AbstractMapperTest { 11 | private MapperFacade facade; 12 | 13 | @Before 14 | public void setUp() { 15 | MapperFactory mapperFactory = createMapperFactory(); 16 | mapperFactory.registerClassMap(mapperFactory.classMap(Order.class, OrderData.class).byDefault().toClassMap()); 17 | mapperFactory.registerClassMap(mapperFactory.classMap(Position.class, PositionData.class).byDefault().toClassMap()); 18 | facade = mapperFactory.getMapperFacade(); 19 | } 20 | 21 | @Test 22 | public void test() { 23 | OrderData data = new OrderData(); 24 | data.setName("asd"); 25 | PositionData positionData = new PositionData(); 26 | positionData.setNumber("1234"); 27 | data.add(positionData); 28 | positionData = new PositionData(); 29 | positionData.setNumber("2345"); 30 | data.add(positionData); 31 | Order order = facade.map(data, Order.class); 32 | Assert.assertEquals("asd", order.getName()); 33 | Assert.assertEquals(2, order.getPositions().size()); 34 | Assert.assertEquals("1234", order.getPositions().iterator().next().getNumber()); 35 | // map it back 36 | OrderData data2 = facade.map(order, OrderData.class); 37 | Assert.assertEquals("asd", data2.getName()); 38 | Assert.assertEquals(2, data2.getPositions().size()); 39 | Assert.assertEquals("1234", data2.getPositions().iterator().next().getNumber()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/collection/Order.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community.collection; 2 | 3 | public class Order extends AbstractOrder { 4 | private String name; 5 | 6 | public String getName() { 7 | return name; 8 | } 9 | 10 | public void setName(String name) { 11 | this.name = name; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/collection/OrderData.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community.collection; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class OrderData { 7 | private String name; 8 | private List positions; 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | 18 | public List getPositions() { 19 | return positions; 20 | } 21 | 22 | public void setPositions(List positions) { 23 | this.positions = positions; 24 | } 25 | 26 | public void add(PositionData data) { 27 | if (positions == null) { 28 | positions = new ArrayList(); 29 | } 30 | positions.add(data); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/collection/Position.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community.collection; 2 | 3 | public class Position implements IPosition { 4 | private String number; 5 | 6 | public String getNumber() { 7 | return number; 8 | } 9 | 10 | public void setNumber(String number) { 11 | this.number = number; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/collection/PositionData.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.community.collection; 2 | 3 | public class PositionData { 4 | private String number; 5 | 6 | public String getNumber() { 7 | return number; 8 | } 9 | 10 | public void setNumber(String number) { 11 | this.number = number; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue20/BaseDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue20; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * @author Dmitriy Khomyakov 24 | * @author matt.deboer@gmail.com 25 | */ 26 | public abstract class BaseDto implements Serializable { 27 | /** 28 | * 29 | */ 30 | private static final long serialVersionUID = 1L; 31 | 32 | private Long id; 33 | 34 | private Long version; 35 | 36 | public Long getId() { 37 | return id; 38 | } 39 | 40 | public void setId(Long id) { 41 | this.id = id; 42 | } 43 | 44 | public Long getVersion() { 45 | return version; 46 | } 47 | 48 | public void setVersion(Long version) { 49 | this.version = version; 50 | } 51 | 52 | public boolean isNew() { 53 | return id == null; 54 | } 55 | 56 | @Override 57 | public boolean equals(Object o) { 58 | if (this == o) 59 | return true; 60 | 61 | if (o == null || (getClass() != o.getClass())) 62 | return false; 63 | 64 | BaseDto that = (BaseDto) o; 65 | 66 | if (isNew()) { 67 | return this == that; 68 | } else { 69 | return id.equals(that.id); 70 | } 71 | 72 | } 73 | 74 | @Override 75 | public int hashCode() { 76 | return id != null ? id.hashCode() : 0; 77 | } 78 | 79 | @Override 80 | public String toString() { 81 | return "BaseDto{" + "id=" + id + ", version=" + version + '}'; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue20/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue20; 19 | 20 | 21 | 22 | import javax.persistence.Column; 23 | import javax.persistence.Entity; 24 | import javax.persistence.FetchType; 25 | import javax.persistence.JoinColumn; 26 | import javax.persistence.ManyToOne; 27 | 28 | /** 29 | * @author Dmitriy Khomyakov 30 | * @author matt.deboer@gmail.com 31 | */ 32 | @Entity 33 | public class User extends BaseEntity { 34 | private UsrGroup group; 35 | private String name; 36 | private String password; 37 | 38 | public User(String name) { 39 | this(name, name); 40 | } 41 | 42 | public User(String name, String password) { 43 | this.name = name; 44 | this.password = password; 45 | } 46 | 47 | public User() { 48 | } 49 | 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | 55 | @ManyToOne(fetch = FetchType.LAZY) 56 | @JoinColumn 57 | public UsrGroup getGroup() { 58 | return group; 59 | } 60 | 61 | public void setGroup(UsrGroup group) { 62 | this.group = group; 63 | } 64 | 65 | @Column(unique = true) 66 | public String getName() { 67 | return name; 68 | } 69 | 70 | 71 | 72 | public String getPassword() { 73 | return password; 74 | } 75 | 76 | public void setPassword(String password) { 77 | this.password = password; 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | return "User{" + 83 | "name='" + name + '\'' + 84 | "} " + super.toString(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue20/UserDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue20; 19 | 20 | /** 21 | * @author Dmitriy Khomyakov 22 | * @author matt.deboer@gmail.com 23 | */ 24 | public class UserDto extends BaseDto { 25 | 26 | /** 27 | * 28 | */ 29 | private static final long serialVersionUID = 1L; 30 | private String name; 31 | // private String password; 32 | private UserGroupDto group; 33 | 34 | public UserDto() { 35 | } 36 | 37 | public UserDto(String name, UserGroupDto group) { 38 | this.name = name; 39 | this.group = group; 40 | } 41 | 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | public void setName(String name) { 47 | this.name = name; 48 | } 49 | 50 | public UserGroupDto getGroup() { 51 | return group; 52 | } 53 | 54 | public void setGroup(UserGroupDto group) { 55 | this.group = group; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | return "UserDto{" + "name='" + name + '\'' + 61 | // ", password='" + password + '\'' + 62 | "} " + super.toString(); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue20/UserGroupDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue20; 19 | 20 | import java.util.Set; 21 | 22 | /** 23 | * @author Dmitriy Khomyakov 24 | * @author matt.deboer@gmail.com 25 | */ 26 | public class UserGroupDto extends BaseDto { 27 | /** 28 | * 29 | */ 30 | private static final long serialVersionUID = 1L; 31 | private String name; 32 | private Set users; 33 | 34 | public String getName() { 35 | return name; 36 | } 37 | 38 | public void setName(String name) { 39 | this.name = name; 40 | } 41 | 42 | public Set getUsers() { 43 | return users; 44 | } 45 | 46 | public void setUsers(Set users) { 47 | this.users = users; 48 | } 49 | 50 | public void addUser(UserDto user) { 51 | getUsers().add(user); 52 | user.setGroup(this); 53 | } 54 | 55 | @Override 56 | public String toString() { 57 | return "UserGroupDto{" + "name='" + name + '\'' + ", users=" + users 58 | + "} " + super.toString(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue20/UserInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue20; 19 | 20 | /** 21 | * @author Dmitriy Khomyakov 22 | * @author matt.deboer@gmail.com 23 | */ 24 | public class UserInfo extends BaseDto { 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 1L; 29 | private String name; 30 | 31 | public void setName(String name) { 32 | this.name = name; 33 | } 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "UserInfo{" + "name='" + name + '\'' + "} " + super.toString(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue20/UsrGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue20; 19 | 20 | import java.util.HashSet; 21 | import java.util.Set; 22 | 23 | import javax.persistence.Entity; 24 | import javax.persistence.JoinColumn; 25 | import javax.persistence.OneToMany; 26 | 27 | /** 28 | * @author Dmitriy Khomyakov 29 | * @author matt.deboer@gmail.com 30 | */ 31 | @Entity 32 | public class UsrGroup extends BaseEntity { 33 | private String name; 34 | private String caption; 35 | private Set users; 36 | 37 | public UsrGroup() { 38 | } 39 | 40 | 41 | public UsrGroup(String name) { 42 | this.name = name; 43 | users = new HashSet(); 44 | } 45 | 46 | public String getName() { 47 | return name; 48 | } 49 | 50 | public void setName(String name) { 51 | this.name = name; 52 | } 53 | 54 | public String getCaption() { 55 | return caption; 56 | } 57 | 58 | public void setCaption(String caption) { 59 | this.caption = caption; 60 | } 61 | 62 | @OneToMany 63 | @JoinColumn 64 | public Set getUsers() { 65 | return users; 66 | } 67 | 68 | public void setUsers(Set users) { 69 | this.users = users; 70 | } 71 | 72 | public void addUser(User user){ 73 | getUsers().add(user); 74 | user.setGroup(this); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return "UserGroup{" + 80 | "name='" + name + '\'' + 81 | ", caption='" + caption + '\'' + 82 | "} " + super.toString(); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue21/AuthorityDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue21; 19 | 20 | import java.util.Set; 21 | 22 | /** 23 | * 24 | * @author Dmitriy Khomyakov 25 | * @author matt.deboer@gmail.com 26 | */ 27 | public class AuthorityDto extends BaseDto { 28 | private String caption; 29 | 30 | private String name; 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | private Set children; 41 | 42 | 43 | public String getCaption() { 44 | return caption; 45 | } 46 | 47 | public void setCaption(String caption) { 48 | this.caption = caption; 49 | } 50 | 51 | public Set getChildren() { 52 | return children; 53 | } 54 | 55 | public void setChildren(Set children) { 56 | this.children = children; 57 | } 58 | 59 | 60 | 61 | @Override 62 | public String toString() { 63 | return "AuthorityDto{" + 64 | "caption='" + caption + '\'' + 65 | "} " + super.toString(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue21/BaseDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue21; 19 | 20 | import java.io.Serializable; 21 | 22 | /** 23 | * 24 | * @author Dmitriy Khomyakov 25 | * @author matt.deboer@gmail.com 26 | */ 27 | public abstract class BaseDto implements Serializable { 28 | /** 29 | * 30 | */ 31 | private static final long serialVersionUID = 1L; 32 | 33 | private Long id; 34 | 35 | private Long version; 36 | 37 | public Long getId() { 38 | return id; 39 | } 40 | 41 | public void setId(Long id) { 42 | this.id = id; 43 | } 44 | 45 | public Long getVersion() { 46 | return version; 47 | } 48 | 49 | public void setVersion(Long version) { 50 | this.version = version; 51 | } 52 | 53 | public boolean isNew() { 54 | return id == null; 55 | } 56 | 57 | @Override 58 | public boolean equals(Object o) { 59 | if (this == o) 60 | return true; 61 | 62 | if (o == null || (getClass() != o.getClass())) 63 | return false; 64 | 65 | BaseDto that = (BaseDto) o; 66 | 67 | if (isNew()) { 68 | return this == that; 69 | } else { 70 | return id.equals(that.id); 71 | } 72 | 73 | } 74 | 75 | @Override 76 | public int hashCode() { 77 | return id != null ? id.hashCode() : 0; 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | return "BaseDto{" + "id=" + id + ", version=" + version + '}'; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue21/UserDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue21; 19 | 20 | import java.util.Set; 21 | 22 | /** 23 | * 24 | * @author Dmitriy Khomyakov 25 | * @author matt.deboer@gmail.com 26 | */ 27 | public class UserDto extends BaseDto { 28 | 29 | private String name; 30 | // private String password; 31 | private UserGroupDto group; 32 | 33 | private Set authorities; 34 | 35 | public UserDto() { 36 | } 37 | 38 | public UserDto(String name, UserGroupDto group) { 39 | this.name = name; 40 | this.group = group; 41 | } 42 | 43 | public Set getAuthorities() { 44 | return authorities; 45 | } 46 | 47 | public void setAuthorities(Set authorities) { 48 | this.authorities = authorities; 49 | } 50 | 51 | public String getName() { 52 | return name; 53 | } 54 | 55 | public void setName(String name) { 56 | this.name = name; 57 | } 58 | 59 | public UserGroupDto getGroup() { 60 | return group; 61 | } 62 | 63 | public void setGroup(UserGroupDto group) { 64 | this.group = group; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return "UserDto{" + "name='" + name + '\'' + 70 | // ", password='" + password + '\'' + 71 | "} " + super.toString(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue21/UserGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue21; 19 | 20 | import ma.glasnost.orika.test.community.issue21.BaseEntity; 21 | 22 | import javax.persistence.Entity; 23 | import javax.persistence.JoinColumn; 24 | import javax.persistence.OneToMany; 25 | import java.util.HashSet; 26 | import java.util.Set; 27 | 28 | /** 29 | * 30 | * @author Dmitriy Khomyakov 31 | * @author matt.deboer@gmail.com 32 | */ 33 | @Entity 34 | public class UserGroup extends BaseEntity { 35 | private String name; 36 | private String caption; 37 | private Set users; 38 | 39 | public UserGroup() { 40 | } 41 | 42 | public UserGroup(String name) { 43 | this.name = name; 44 | users = new HashSet(); 45 | } 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | public void setName(String name) { 52 | this.name = name; 53 | } 54 | 55 | public String getCaption() { 56 | return caption; 57 | } 58 | 59 | public void setCaption(String caption) { 60 | this.caption = caption; 61 | } 62 | 63 | @OneToMany 64 | @JoinColumn 65 | public Set getUsers() { 66 | return users; 67 | } 68 | 69 | public void setUsers(Set users) { 70 | this.users = users; 71 | } 72 | 73 | public void removeUser(User user) { 74 | getUsers().remove(user); 75 | user.setGroup(null); 76 | } 77 | 78 | public void addUser(User user) { 79 | getUsers().add(user); 80 | user.setGroup(this); 81 | } 82 | 83 | @Override 84 | public String toString() { 85 | return "UserGroup{" + "name='" + name + '\'' + ", caption='" + caption 86 | + '\'' + "} " + super.toString(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue21/UserGroupDto.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue21; 19 | 20 | import java.util.Set; 21 | 22 | /** 23 | * 24 | * @author Dmitriy Khomyakov 25 | * @author matt.deboer@gmail.com 26 | */ 27 | public class UserGroupDto extends BaseDto { 28 | private String name; 29 | private Set users; 30 | 31 | public String getName() { 32 | return name; 33 | } 34 | 35 | public void setName(String name) { 36 | this.name = name; 37 | } 38 | 39 | public Set getUsers() { 40 | return users; 41 | } 42 | 43 | public void setUsers(Set users) { 44 | this.users = users; 45 | } 46 | 47 | public void addUser(UserDto user) { 48 | getUsers().add(user); 49 | user.setGroup(this); 50 | } 51 | 52 | public void removeUser(UserDto user) { 53 | getUsers().remove(user); 54 | user.setGroup(this); 55 | } 56 | 57 | @Override 58 | public String toString() { 59 | return "UserGroupDto{" + "name='" + name + '\'' + ", users=" + users 60 | + "} " + super.toString(); 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue21/UserInfo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue21; 19 | 20 | /** 21 | * 22 | * @author Dmitriy Khomyakov 23 | * @author matt.deboer@gmail.com 24 | */ 25 | public class UserInfo extends BaseDto { 26 | private String name; 27 | 28 | public void setName(String name) { 29 | this.name = name; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | @Override 37 | public String toString() { 38 | return "UserInfo{" + 39 | "name='" + name + '\'' + 40 | "} " + super.toString(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue25/modelB/AddressDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue25.modelB; 19 | 20 | import java.io.Serializable; 21 | 22 | public class AddressDTO implements Serializable { 23 | 24 | /** 25 | * 26 | */ 27 | private static final long serialVersionUID = -8573731692897972845L; 28 | 29 | private Long idNumber; 30 | private String street = null; 31 | private Long postalcode = null; 32 | private String comment = null; 33 | private Character land = null; 34 | public Long getIdNumber() { 35 | return idNumber; 36 | } 37 | public void setIdNumber(Long idNumber) { 38 | this.idNumber = idNumber; 39 | } 40 | public String getStreet() { 41 | return street; 42 | } 43 | public void setStreet(String street) { 44 | this.street = street; 45 | } 46 | public Long getPostalcode() { 47 | return postalcode; 48 | } 49 | public void setPostalcode(Long postalcode) { 50 | this.postalcode = postalcode; 51 | } 52 | public String getComment() { 53 | return comment; 54 | } 55 | public void setComment(String comment) { 56 | this.comment = comment; 57 | } 58 | public Character getLand() { 59 | return land; 60 | } 61 | public void setLand(Character land) { 62 | this.land = land; 63 | } 64 | 65 | 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue25/modelB/ManufacturingFacilityDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue25.modelB; 19 | 20 | import java.io.Serializable; 21 | 22 | 23 | public class ManufacturingFacilityDTO implements Serializable { 24 | 25 | /** 26 | * 27 | */ 28 | private static final long serialVersionUID = 4949602104392727453L; 29 | 30 | private String description; 31 | private Long idNumber; 32 | 33 | public ManufacturingFacilityDTO(){ 34 | 35 | } 36 | 37 | public String getDescription() { 38 | return description; 39 | } 40 | 41 | public void setDescription(String description) { 42 | this.description = description; 43 | } 44 | 45 | public Long getIdNumber() { 46 | return idNumber; 47 | } 48 | 49 | public void setIdNumber(Long idNumber) { 50 | this.idNumber = idNumber; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue25/modelB/ManufacturingFacilityDTS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue25.modelB; 19 | 20 | import java.io.Serializable; 21 | import java.util.ArrayList; 22 | import java.util.List; 23 | 24 | public class ManufacturingFacilityDTS implements Serializable { 25 | 26 | /** 27 | * 28 | */ 29 | private static final long serialVersionUID = -1917745131193055771L; 30 | 31 | private ManufacturingFacilityDTO manufacturingfacility; 32 | private List addressL; 33 | 34 | public ManufacturingFacilityDTO getManufacturingfacility() { 35 | return (manufacturingfacility==null)? manufacturingfacility = new ManufacturingFacilityDTO():this.manufacturingfacility; 36 | } 37 | public void setManufacturingfacility(ManufacturingFacilityDTO manufacturingfacility) { 38 | this.manufacturingfacility = manufacturingfacility; 39 | } 40 | public List getAddressL() { 41 | return (addressL == null ? addressL = new ArrayList() : addressL); 42 | } 43 | public void setAddressL(List addressL) { 44 | this.addressL = addressL; 45 | } 46 | 47 | public String getDescription() { 48 | return getManufacturingfacility().getDescription(); 49 | } 50 | 51 | public void setDescription(String description) { 52 | getManufacturingfacility().setDescription(description); 53 | } 54 | 55 | public Long getIdNumber() { 56 | return getManufacturingfacility().getIdNumber(); 57 | } 58 | 59 | public void setIdNumber(Long idNumber) { 60 | getManufacturingfacility().setIdNumber(idNumber); 61 | } 62 | } 63 | 64 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue26/AbstractEntity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue26; 19 | 20 | public abstract class AbstractEntity { 21 | private ID entityID; 22 | 23 | public AbstractEntity() { /* Required by Orika mapping */ 24 | this(null); 25 | } 26 | 27 | public AbstractEntity(ID entityID) { 28 | this.entityID = entityID; 29 | } 30 | 31 | public ID getEntityID() { 32 | return entityID; 33 | } 34 | 35 | public void setEntityID(ID entityID) { 36 | this.entityID = entityID; 37 | } 38 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue26/AbstractOrderID.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue26; 19 | 20 | public abstract class AbstractOrderID { 21 | private static final long serialVersionUID = 2L; 22 | 23 | private Long bestellungID; 24 | 25 | public Long getID() { 26 | return bestellungID; 27 | } 28 | 29 | public AbstractOrderID() { /* Required by Orika mapping */ 30 | this(null); 31 | } 32 | 33 | public AbstractOrderID(Long bestellungID) { 34 | this.bestellungID = bestellungID; 35 | } 36 | 37 | public AbstractOrderID(long bestellungID) { 38 | this.bestellungID = bestellungID; 39 | } 40 | 41 | public Long getBestellungID() { 42 | return bestellungID; 43 | } 44 | 45 | public void setBestellungID(Long bestellungID) { 46 | this.bestellungID = bestellungID; 47 | } 48 | 49 | @Override 50 | public int hashCode() { 51 | final int prime = 31; 52 | int result = 1; 53 | result = prime * result 54 | + ((bestellungID == null) ? 0 : bestellungID.hashCode()); 55 | return result; 56 | } 57 | 58 | @Override 59 | public boolean equals(Object obj) { 60 | if (this == obj) 61 | return true; 62 | if (obj == null) 63 | return false; 64 | if (getClass() != obj.getClass()) 65 | return false; 66 | AbstractOrderID other = (AbstractOrderID) obj; 67 | if (bestellungID == null) { 68 | if (other.bestellungID != null) 69 | return false; 70 | } else if (!bestellungID.equals(other.bestellungID)) 71 | return false; 72 | return true; 73 | } 74 | 75 | 76 | } 77 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue26/Order.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue26; 19 | 20 | public final class Order extends AbstractEntity { 21 | private static final long serialVersionUID = 1L; 22 | 23 | public Order() { 24 | this(null); 25 | } 26 | 27 | public Order(OrderID id) { 28 | super(id); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue26/OrderData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue26; 19 | 20 | import java.io.Serializable; 21 | 22 | public class OrderData implements Serializable { 23 | private static final long serialVersionUID = 1L; 24 | private Long orderId; 25 | 26 | public OrderData() { 27 | } 28 | 29 | public OrderData(Long Id) { 30 | this.orderId = Id; 31 | } 32 | 33 | public Long getOrderId() { 34 | return orderId; 35 | } 36 | 37 | public void setOrderId(Long Id) { 38 | this.orderId = Id; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue26/OrderID.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue26; 19 | 20 | public class OrderID extends AbstractOrderID { 21 | 22 | private static final long serialVersionUID = 1L; 23 | 24 | public OrderID() { /* Required by Orika mapping */ 25 | this(null); 26 | } 27 | 28 | public OrderID(Long orderID) { 29 | super(orderID); 30 | } 31 | 32 | public OrderID(long orderID) { 33 | super(orderID); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue26/OrderIDConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue26; 19 | 20 | import ma.glasnost.orika.CustomConverter; 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | public class OrderIDConverter extends CustomConverter { 24 | 25 | /* (non-Javadoc) 26 | * @see ma.glasnost.orika.Converter#convert(java.lang.Object, ma.glasnost.orika.metadata.Type) 27 | */ 28 | public OrderID convert(Long source, Type destinationType) { 29 | return new OrderID(source); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue28/AbstractOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue28; 19 | 20 | public abstract class AbstractOrder> extends PositionContainer { 21 | private static final long serialVersionUID = 3L; 22 | 23 | private Long number; 24 | 25 | public AbstractOrder() { 26 | this(null); 27 | } 28 | 29 | public AbstractOrder(Long number) { 30 | this.number = number; 31 | } 32 | 33 | public Long getId() { 34 | return number; 35 | } 36 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue28/Order.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue28; 19 | 20 | public class Order extends AbstractOrder { 21 | private static final long serialVersionUID = 1L; 22 | private int customerNumber; 23 | 24 | public Order() { 25 | this(null); 26 | } 27 | 28 | public Order(Long id) { 29 | super(id); 30 | } 31 | 32 | public int getCustomerNumber() { 33 | return customerNumber; 34 | } 35 | 36 | public void setCustomerNumber(int customerNumber) { 37 | this.customerNumber = customerNumber; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue28/OrderData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue28; 19 | 20 | import java.io.Serializable; 21 | 22 | public class OrderData implements Serializable { 23 | private static final long serialVersionUID = 1L; 24 | private Long number; 25 | 26 | public OrderData() { 27 | } 28 | 29 | public OrderData(Long number) { 30 | this.number = number; 31 | } 32 | 33 | public Long getNumber() { 34 | return number; 35 | } 36 | 37 | public void setNumber(Long number) { 38 | this.number = number; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue28/Position.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue28; 19 | 20 | public class Position { 21 | private T order; 22 | 23 | public T getOrder() { 24 | return order; 25 | } 26 | 27 | public void setOrder(T order) { 28 | this.order = order; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue28/PositionContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue28; 19 | 20 | import java.util.Collection; 21 | 22 | public abstract class PositionContainer { 23 | private Collection> positions; 24 | 25 | public Collection> getPositions() { 26 | return positions; 27 | } 28 | 29 | public void setPositions(Collection> positions) { 30 | this.positions = positions; 31 | } 32 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue41/MyEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue41; 19 | 20 | public enum MyEnum { 21 | one, two 22 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue41/MyEnumConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue41; 19 | 20 | import ma.glasnost.orika.CustomConverter; 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | public class MyEnumConverter extends CustomConverter { 24 | 25 | public MyEnum convert(String source, Type destinationType) { 26 | if ("un".equals(source)) { 27 | return MyEnum.one; 28 | } 29 | 30 | if ("deux".equals(source)) { 31 | return MyEnum.two; 32 | } 33 | return null; 34 | } 35 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue41/MySourceObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue41; 19 | 20 | public class MySourceObject { 21 | private String e; 22 | 23 | public String getE() { 24 | return e; 25 | } 26 | 27 | public void setE(String e) { 28 | this.e = e; 29 | } 30 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue41/MyTargetObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue41; 19 | 20 | 21 | public class MyTargetObject { 22 | private MyTargetSubObject sub; 23 | private MyEnum directE; 24 | 25 | public MyEnum getDirectE() { 26 | return directE; 27 | } 28 | 29 | public void setDirectE(MyEnum directE) { 30 | this.directE = directE; 31 | } 32 | 33 | public MyTargetSubObject getSub() { 34 | return sub; 35 | } 36 | 37 | public void setSub(MyTargetSubObject sub) { 38 | this.sub = sub; 39 | } 40 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/community/issue41/MyTargetSubObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.community.issue41; 19 | 20 | public class MyTargetSubObject { 21 | private MyEnum e; 22 | 23 | private String s; 24 | 25 | public String getS() { 26 | return s; 27 | } 28 | 29 | public void setS(String s) { 30 | this.s = s; 31 | } 32 | 33 | public MyEnum getE() { 34 | return e; 35 | } 36 | 37 | public void setE(MyEnum e) { 38 | this.e = e; 39 | } 40 | } -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/converter/ConverterTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.test.converter; 20 | 21 | import junit.framework.Assert; 22 | import ma.glasnost.orika.MapperFactory; 23 | import ma.glasnost.orika.metadata.ClassMapBuilder; 24 | import ma.glasnost.orika.test.MappingUtil; 25 | 26 | import org.junit.Test; 27 | 28 | public class ConverterTestCase { 29 | 30 | @Test 31 | public void testConvertLongString() { 32 | MapperFactory factory = MappingUtil.getMapperFactory(); 33 | 34 | factory.getConverterFactory().registerConverter(new LongToStringConverter()); 35 | 36 | factory.registerClassMap(ClassMapBuilder.map(A.class, B.class).field("id", "string").toClassMap()); 37 | 38 | factory.build(); 39 | 40 | A source = new A(); 41 | source.setId(42L); 42 | 43 | B destination = factory.getMapperFacade().map(source, B.class); 44 | 45 | Assert.assertEquals("42", destination.getString()); 46 | 47 | } 48 | 49 | public static class A { 50 | private Long id; 51 | 52 | public Long getId() { 53 | return id; 54 | } 55 | 56 | public void setId(Long id) { 57 | this.id = id; 58 | } 59 | 60 | } 61 | 62 | public static class B { 63 | private String string; 64 | 65 | public String getString() { 66 | return string; 67 | } 68 | 69 | public void setString(String string) { 70 | this.string = string; 71 | } 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/converter/FieldLevelConverterClasses.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.converter; 2 | 3 | import java.util.Date; 4 | 5 | public class FieldLevelConverterClasses { 6 | 7 | public static class A { 8 | private String date; 9 | 10 | public String getDate() { 11 | return date; 12 | } 13 | 14 | public void setDate(String date) { 15 | this.date = date; 16 | } 17 | } 18 | 19 | // Date format dd/MM/yyyy 20 | public static class B { 21 | private Date date; 22 | 23 | public Date getDate() { 24 | return date; 25 | } 26 | 27 | public void setDate(Date date) { 28 | this.date = date; 29 | } 30 | } 31 | 32 | // Date format dd-MM-yyyy 33 | public static class C { 34 | private Date date; 35 | 36 | public Date getDate() { 37 | return date; 38 | } 39 | 40 | public void setDate(Date date) { 41 | this.date = date; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/converter/FieldLevelConverterTestCase.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.converter; 2 | 3 | import java.text.SimpleDateFormat; 4 | import java.util.Date; 5 | 6 | import junit.framework.Assert; 7 | import ma.glasnost.orika.MapperFacade; 8 | import ma.glasnost.orika.MapperFactory; 9 | import ma.glasnost.orika.converter.ConverterFactory; 10 | import ma.glasnost.orika.converter.builtin.DateToStringConverter; 11 | import ma.glasnost.orika.metadata.ClassMapBuilder; 12 | import ma.glasnost.orika.test.MappingUtil; 13 | import ma.glasnost.orika.test.converter.FieldLevelConverterClasses.A; 14 | import ma.glasnost.orika.test.converter.FieldLevelConverterClasses.B; 15 | import ma.glasnost.orika.test.converter.FieldLevelConverterClasses.C; 16 | 17 | import org.junit.Test; 18 | 19 | public class FieldLevelConverterTestCase { 20 | 21 | @Test 22 | public void testDateToString() { 23 | MapperFactory factory = MappingUtil.getMapperFactory(); 24 | 25 | ConverterFactory converterFactory = factory.getConverterFactory(); 26 | converterFactory.registerConverter("dateConverter1", new DateToStringConverter("dd/MM/yyyy")); 27 | converterFactory.registerConverter("dateConverter2", new DateToStringConverter("dd-MM-yyyy")); 28 | 29 | factory.registerClassMap(ClassMapBuilder.map(A.class, B.class).fieldMap("date").converter("dateConverter1").add().toClassMap()); 30 | factory.registerClassMap(ClassMapBuilder.map(A.class, C.class).fieldMap("date").converter("dateConverter2").add().toClassMap()); 31 | 32 | factory.build(); 33 | 34 | MapperFacade mapperFacade = factory.getMapperFacade(); 35 | 36 | C c = new C(); 37 | c.setDate(new Date()); 38 | 39 | A a = mapperFacade.map(c, A.class); 40 | 41 | Assert.assertEquals(new SimpleDateFormat("dd-MM-yyyy").format(c.getDate()), a.getDate()); 42 | 43 | B b = new B(); 44 | b.setDate(new Date()); 45 | 46 | a = mapperFacade.map(b, A.class); 47 | 48 | Assert.assertEquals(new SimpleDateFormat("dd/MM/yyyy").format(b.getDate()), a.getDate()); 49 | 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/converter/LongToStringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.converter; 19 | 20 | import ma.glasnost.orika.converter.CustomConverterBase; 21 | import ma.glasnost.orika.metadata.Type; 22 | 23 | @SuppressWarnings("deprecation") 24 | public class LongToStringConverter extends CustomConverterBase { 25 | 26 | public boolean canConvert(Class sourceClass, Class destinationClass) { 27 | return Long.class.equals(sourceClass) && String.class.equals(destinationClass); 28 | } 29 | 30 | public String convert(Long source, Class destinationClass) { 31 | if (source != null) { 32 | return source.toString(); 33 | } 34 | return null; 35 | } 36 | 37 | /* (non-Javadoc) 38 | * @see ma.glasnost.orika.Converter#convert(java.lang.Object, ma.glasnost.orika.metadata.Type) 39 | */ 40 | public String convert(Long source, Type destinationType) { 41 | // TODO Auto-generated method stub 42 | return null; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/converter/PrimitiveConversionTestCase.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.converter; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import org.junit.Assert; 6 | import org.junit.Test; 7 | 8 | import ma.glasnost.orika.MapperFactory; 9 | import ma.glasnost.orika.converter.CustomConverterBase; 10 | import ma.glasnost.orika.metadata.ClassMapBuilder; 11 | import ma.glasnost.orika.metadata.Type; 12 | import ma.glasnost.orika.test.MappingUtil; 13 | 14 | public class PrimitiveConversionTestCase { 15 | 16 | @Test 17 | public void testPrimitiveToWrapper() { 18 | MapperFactory factory = MappingUtil.getMapperFactory(); 19 | factory.getConverterFactory().registerConverter(new CustomConverterBase() { 20 | 21 | public BigDecimal convert(Double source, 22 | Class destinationType) { 23 | return BigDecimal.valueOf(source); 24 | } 25 | }); 26 | 27 | factory.getConverterFactory().registerConverter(new CustomConverterBase() { 28 | 29 | public Double convert(BigDecimal source, 30 | Class destinationType) { 31 | return source.doubleValue(); 32 | } 33 | }); 34 | 35 | factory.registerClassMap(ClassMapBuilder.map(A.class, B.class).byDefault().toClassMap()); 36 | 37 | 38 | A source = new A(); 39 | source.setValue(BigDecimal.TEN); 40 | 41 | B target = factory.getMapperFacade().map(source, B.class); 42 | 43 | Assert.assertTrue(target.getValue() == 10.0); 44 | } 45 | 46 | public static class A { 47 | private BigDecimal value; 48 | 49 | public BigDecimal getValue() { 50 | return value; 51 | } 52 | 53 | public void setValue(BigDecimal value) { 54 | this.value = value; 55 | } 56 | 57 | } 58 | 59 | public static class B { 60 | private double value; 61 | 62 | public double getValue() { 63 | return value; 64 | } 65 | 66 | public void setValue(double value) { 67 | this.value = value; 68 | } 69 | 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/converter/StringConversionTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.test.converter; 20 | 21 | import org.junit.Assert; 22 | import org.junit.Ignore; 23 | import org.junit.Test; 24 | 25 | public class StringConversionTestCase { 26 | 27 | @Test 28 | @Ignore 29 | public void testIntToString() { 30 | Assert.fail(); 31 | } 32 | 33 | @Test 34 | @Ignore 35 | public void testBooleanToString() { 36 | Assert.fail(); 37 | } 38 | 39 | @Test 40 | @Ignore 41 | public void testStringToInt() { 42 | Assert.fail(); 43 | } 44 | 45 | @Test 46 | @Ignore 47 | public void testStringToBoolean() { 48 | Assert.fail(); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/converter/ToStringConverterTestCase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.converter; 19 | 20 | import java.util.Date; 21 | 22 | import junit.framework.Assert; 23 | import ma.glasnost.orika.MapperFacade; 24 | import ma.glasnost.orika.MapperFactory; 25 | import ma.glasnost.orika.MappingException; 26 | import ma.glasnost.orika.converter.builtin.ToStringConverter; 27 | import ma.glasnost.orika.impl.DefaultMapperFactory; 28 | import ma.glasnost.orika.test.MappingUtil; 29 | 30 | import org.junit.Test; 31 | 32 | 33 | public class ToStringConverterTestCase { 34 | 35 | @Test(expected=MappingException.class) 36 | public void testToString_withoutConverter() { 37 | MapperFactory factory = new DefaultMapperFactory.Builder().useBuiltinConverters(false).build(); 38 | MapperFacade mapper = factory.getMapperFacade(); 39 | 40 | Date now = new Date(); 41 | String string = mapper.map(now, String.class); 42 | Assert.assertFalse(now.toString().equals(string)); 43 | } 44 | 45 | @Test 46 | public void testToString() { 47 | MapperFactory factory = MappingUtil.getMapperFactory(); 48 | factory.getConverterFactory().registerConverter(new ToStringConverter()); 49 | MapperFacade mapper = factory.getMapperFacade(); 50 | 51 | Date now = new Date(); 52 | String string = mapper.map(now, String.class); 53 | Assert.assertEquals(now.toString(), string); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/generator/eclipsejdt/TestAlternateCompilerStrategy.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.test.generator.eclipsejdt; 20 | 21 | import ma.glasnost.orika.OrikaSystemProperties; 22 | import ma.glasnost.orika.impl.generator.EclipseJdtCompilerStrategy; 23 | import ma.glasnost.orika.test.DynamicSuite; 24 | import ma.glasnost.orika.test.DynamicSuite.Scenario; 25 | import ma.glasnost.orika.test.DynamicSuite.TestCasePattern; 26 | 27 | import org.junit.AfterClass; 28 | import org.junit.BeforeClass; 29 | import org.junit.runner.RunWith; 30 | 31 | /** 32 | * This provides the equivalent of a test suite which will run 33 | * all the defined test cases (matching ".*TestCase.class") using 34 | * EclipseJdtCompilerStrategy as the compiler strategy instead of 35 | * JavassistCompilerStrategy which is the default. 36 | * 37 | * @author matt.deboer@gmail.com 38 | * 39 | */ 40 | @RunWith(DynamicSuite.class) 41 | @TestCasePattern(".*TestCase") 42 | @Scenario(name="eclipseJdt") 43 | public class TestAlternateCompilerStrategy { 44 | 45 | @BeforeClass 46 | public static void eclipseJdt() { 47 | System.setProperty(OrikaSystemProperties.COMPILER_STRATEGY, 48 | EclipseJdtCompilerStrategy.class.getCanonicalName()); 49 | } 50 | 51 | @AfterClass 52 | public static void tearDown() { 53 | System.clearProperty(OrikaSystemProperties.COMPILER_STRATEGY); 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/metadata/VariableRefTestCase.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.metadata; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import junit.framework.Assert; 7 | 8 | import ma.glasnost.orika.impl.UtilityResolver; 9 | import ma.glasnost.orika.metadata.Property; 10 | import ma.glasnost.orika.property.IntrospectorPropertyResolver; 11 | 12 | import org.junit.Test; 13 | 14 | public class VariableRefTestCase { 15 | 16 | 17 | public static class Year { 18 | public int yearNumber; 19 | public List months = new ArrayList(); 20 | } 21 | 22 | public static class Month { 23 | public int monthNumber; 24 | public List days = new ArrayList(); 25 | } 26 | 27 | public static class Day { 28 | public int dayNumber; 29 | public String dayOfWeek; 30 | } 31 | 32 | public static class FlatData { 33 | public int dayNumber; 34 | public String dayOfWeek; 35 | public int yearNumber; 36 | public int monthNumber; 37 | } 38 | 39 | 40 | @Test 41 | public void testGetter() { 42 | 43 | Property prop = UtilityResolver.getDefaultPropertyResolverStrategy().getProperty(Year.class, "months{days{dayOfWeek}}"); 44 | Assert.assertNotNull(prop); 45 | Assert.assertNotNull(prop.getContainer()); 46 | Assert.assertNotNull(prop.getContainer().getContainer()); 47 | 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/perf/LaunchTestsForProfiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.test.perf; 20 | 21 | import java.io.File; 22 | import java.io.IOException; 23 | 24 | import ma.glasnost.orika.test.DynamicSuite; 25 | 26 | import org.junit.runner.JUnitCore; 27 | 28 | /** 29 | * LaunchTestsForProfiler provides a launcher for using the VisualVm (or another) 30 | * profiler over all of the unit tests.
31 | * It provides a break at the beginning pausing for input which allows 32 | * attaching/configuring the profiler, as well as a similar pause at the 33 | * end to allow for capturing/saving results.

34 | * 35 | * 36 | * @author matt.deboer@gmail.com 37 | * 38 | */ 39 | public class LaunchTestsForProfiler { 40 | 41 | public static void main(String[] args) throws IOException { 42 | 43 | File classFolder = new File(LaunchTestsForProfiler.class.getResource("/").getFile()); 44 | Class[] testClasses = DynamicSuite.findTestCases(classFolder, ".*TestCase").toArray(new Class[0]); 45 | 46 | 47 | System.out.println("Press enter when ready to start..."); 48 | System.in.read(); 49 | 50 | /* 51 | * Manually fire the set of test classes; this avoids having this test included when all 52 | * test cases are run within an IDE, since this is a special case used only for profiling 53 | */ 54 | JUnitCore.runClasses(testClasses); 55 | 56 | System.out.println("Press enter when ready to quit..."); 57 | System.in.read(); 58 | System.in.read(); 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/primitives/BigDecimalPrimitiveTestCase.java: -------------------------------------------------------------------------------- 1 | package ma.glasnost.orika.test.primitives; 2 | 3 | import java.math.BigDecimal; 4 | 5 | import ma.glasnost.orika.CustomConverter; 6 | import ma.glasnost.orika.MapperFactory; 7 | import ma.glasnost.orika.metadata.Type; 8 | import ma.glasnost.orika.test.MappingUtil; 9 | 10 | import org.junit.Assert; 11 | import org.junit.Test; 12 | 13 | public class BigDecimalPrimitiveTestCase { 14 | { 15 | 16 | } 17 | 18 | @Test 19 | public void shouldMapBigDecimalToPrimtiveDouble() { 20 | 21 | MapperFactory factory = MappingUtil.getMapperFactory(); 22 | factory.getConverterFactory().registerConverter(new CustomConverter() { 23 | 24 | public Double convert(BigDecimal source, Type destinationType) { 25 | return new Double(source.doubleValue()); 26 | } 27 | 28 | }); 29 | 30 | A source = new A(); 31 | source.setValue(BigDecimal.TEN); 32 | B dest = factory.getMapperFacade().map(source, B.class); 33 | 34 | Assert.assertEquals(new Double(10), (Double) dest.getValue()); 35 | 36 | } 37 | 38 | public static class A { 39 | private BigDecimal value; 40 | 41 | public BigDecimal getValue() { 42 | return value; 43 | } 44 | 45 | public void setValue(BigDecimal value) { 46 | this.value = value; 47 | } 48 | 49 | } 50 | 51 | public static class B { 52 | private double value; 53 | 54 | public double getValue() { 55 | return value; 56 | } 57 | 58 | public void setValue(double value) { 59 | this.value = value; 60 | } 61 | 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/unenhance/Author.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.test.unenhance; 20 | 21 | import java.util.HashSet; 22 | import java.util.Set; 23 | 24 | import javax.persistence.Column; 25 | import javax.persistence.Entity; 26 | import javax.persistence.GeneratedValue; 27 | import javax.persistence.GenerationType; 28 | import javax.persistence.Id; 29 | import javax.persistence.OneToMany; 30 | 31 | @Entity 32 | public class Author { 33 | 34 | @Id 35 | @GeneratedValue(strategy = GenerationType.AUTO) 36 | private Long id; 37 | 38 | @Column 39 | private String name; 40 | 41 | @OneToMany 42 | private Set books; 43 | 44 | public Author() { 45 | this.books = new HashSet(); 46 | } 47 | 48 | public Set getBooks() { 49 | return books; 50 | } 51 | 52 | public void setBooks(Set books) { 53 | this.books = books; 54 | } 55 | 56 | public String getName() { 57 | return name; 58 | } 59 | 60 | public void setName(String name) { 61 | this.name = name; 62 | } 63 | 64 | public Long getId() { 65 | return id; 66 | } 67 | 68 | public void setId(Long id) { 69 | this.id = id; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/unenhance/AuthorDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.test.unenhance; 20 | 21 | public class AuthorDTO { 22 | private Long id; 23 | private String name; 24 | 25 | public Long getId() { 26 | return id; 27 | } 28 | 29 | public void setId(Long id) { 30 | this.id = id; 31 | } 32 | 33 | public String getName() { 34 | return name; 35 | } 36 | 37 | public void setName(String name) { 38 | this.name = name; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/unenhance/Book.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.test.unenhance; 20 | 21 | import javax.persistence.Column; 22 | import javax.persistence.Entity; 23 | import javax.persistence.FetchType; 24 | import javax.persistence.GeneratedValue; 25 | import javax.persistence.GenerationType; 26 | import javax.persistence.Id; 27 | import javax.persistence.ManyToOne; 28 | 29 | @Entity 30 | public class Book { 31 | 32 | @Id 33 | @GeneratedValue(strategy = GenerationType.AUTO) 34 | private Long id; 35 | 36 | @Column 37 | private String title; 38 | 39 | @ManyToOne(fetch = FetchType.LAZY) 40 | private Author author; 41 | 42 | public String getTitle() { 43 | return title; 44 | } 45 | 46 | public void setTitle(String title) { 47 | this.title = title; 48 | } 49 | 50 | public Author getAuthor() { 51 | return author; 52 | } 53 | 54 | public void setAuthor(Author author) { 55 | this.author = author; 56 | } 57 | 58 | public Long getId() { 59 | return id; 60 | } 61 | 62 | public void setId(Long id) { 63 | this.id = id; 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/unenhance/BookDTO.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package ma.glasnost.orika.test.unenhance; 20 | 21 | 22 | 23 | public class BookDTO { 24 | 25 | private Long id; 26 | private String title; 27 | private AuthorDTO author; 28 | 29 | public String getTitle() { 30 | return title; 31 | } 32 | 33 | public void setTitle(String title) { 34 | this.title = title; 35 | } 36 | 37 | public AuthorDTO getAuthor() { 38 | return author; 39 | } 40 | 41 | public void setAuthor(AuthorDTO author) { 42 | this.author = author; 43 | } 44 | 45 | public Long getId() { 46 | return id; 47 | } 48 | 49 | public void setId(Long id) { 50 | this.id = id; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /tests/src/main/java/ma/glasnost/orika/test/unenhance/XMLGregorianCalendarToDateConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Orika - simpler, better and faster Java bean mapping 3 | * 4 | * Copyright (C) 2011 Orika authors 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package ma.glasnost.orika.test.unenhance; 19 | 20 | import java.util.Date; 21 | 22 | import javax.xml.datatype.XMLGregorianCalendar; 23 | 24 | import ma.glasnost.orika.converter.CustomConverterBase; 25 | 26 | @SuppressWarnings("deprecation") 27 | public class XMLGregorianCalendarToDateConverter extends CustomConverterBase { 28 | 29 | public Date convert(XMLGregorianCalendar source, Class destinationClass) { 30 | Date target = null; 31 | if (source != null) { 32 | target = source.toGregorianCalendar().getTime(); 33 | } 34 | return target; 35 | } 36 | 37 | public boolean canConvert(Class sourceClass, Class destinationClass) { 38 | return XMLGregorianCalendar.class.isAssignableFrom(sourceClass) && Date.class.equals(destinationClass); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /tests/src/main/resources/HibernateProxyTestCase-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | ma.glasnost.orika.test.unenhance.Author 18 | ma.glasnost.orika.test.unenhance.Book 19 | 20 | 21 | 22 | 23 | hibernate.dialect=org.hibernate.dialect.H2Dialect 24 | hibernate.hbm2ddl.auto = create-drop 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /tests/src/main/resources/Issue20TestCase-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | ma.glasnost.orika.test.community.issue20.User 18 | ma.glasnost.orika.test.community.issue20.UsrGroup 19 | 20 | 21 | 22 | 23 | hibernate.dialect=org.hibernate.dialect.H2Dialect 24 | hibernate.hbm2ddl.auto = create-drop 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /tests/src/main/resources/Issue21TestCase-context.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | ma.glasnost.orika.test.community.issue21.User 18 | ma.glasnost.orika.test.community.issue21.UserGroup 19 | ma.glasnost.orika.test.community.issue21.Authority 20 | 21 | 22 | 23 | 24 | hibernate.dialect=org.hibernate.dialect.H2Dialect 25 | hibernate.hbm2ddl.auto = create-drop 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /tests/src/main/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 6 | 7 | 8 | 9 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | --------------------------------------------------------------------------------