blob: f26369454dd44c919b29504830fc31686f61084e [file] [log] [blame]
package org.eclipse.osbp.dsl.tests.carstore.dtos.mapper;
import org.eclipse.osbp.dsl.dto.lib.IMapper;
import org.eclipse.osbp.dsl.dto.lib.IMapperAccess;
import org.eclipse.osbp.dsl.dto.lib.MappingContext;
import org.eclipse.osbp.dsl.tests.carstore.dtos.AddressDto;
import org.eclipse.osbp.dsl.tests.carstore.entities.Address;
/**
* This class maps the dto {@link AddressDto} to and from the entity {@link Address}.
*
*/
@SuppressWarnings("all")
public class AddressDtoMapper<DTO extends AddressDto, ENTITY extends Address> implements IMapper<DTO, ENTITY> {
private IMapperAccess mapperAccess;
/**
* Returns the mapper instance that may map between the given dto and entity. Or <code>null</code> if no mapper is available.
*
* @param dtoClass - the class of the dto that should be mapped
* @param entityClass - the class of the entity that should be mapped
* @return the mapper instance or <code>null</code>
*/
protected <D, E> IMapper<D, E> getToDtoMapper(final Class<D> dtoClass, final Class<E> entityClass) {
return mapperAccess.getToDtoMapper(dtoClass, entityClass);
}
/**
* Returns the mapper instance that may map between the given dto and entity. Or <code>null</code> if no mapper is available.
*
* @param dtoClass - the class of the dto that should be mapped
* @param entityClass - the class of the entity that should be mapped
* @return the mapper instance or <code>null</code>
*/
protected <D, E> IMapper<D, E> getToEntityMapper(final Class<D> dtoClass, final Class<E> entityClass) {
return mapperAccess.getToEntityMapper(dtoClass, entityClass);
}
/**
* Called by OSGi-DS. Binds the mapper access service.
*
* @param service - The mapper access service
*
*/
protected void bindMapperAccess(final IMapperAccess mapperAccess) {
this.mapperAccess = mapperAccess;
}
/**
* Called by OSGi-DS. Binds the mapper access service.
*
* @param service - The mapper access service
*
*/
protected void unbindMapperAccess(final IMapperAccess mapperAccess) {
this.mapperAccess = null;
}
/**
* Creates a new instance of the entity
*/
public Address createEntity() {
return new Address();
}
/**
* Creates a new instance of the dto
*/
public AddressDto createDto() {
return new AddressDto();
}
/**
* Maps the entity {@link Address} to the dto {@link AddressDto}.
*
* @param dto - The target dto
* @param entity - The source entity
* @param context - The context to get information about depth,...
*
*/
public void mapToDTO(final AddressDto dto, final Address entity, final MappingContext context) {
if(context == null){
throw new IllegalArgumentException("Please pass a context!");
}
dto.setStreetname(toDto_streetname(entity, context));
dto.setPostalcode(toDto_postalcode(entity, context));
}
/**
* Maps the dto {@link AddressDto} to the entity {@link Address}.
*
* @param dto - The source dto
* @param entity - The target entity
* @param context - The context to get information about depth,...
*
*/
public void mapToEntity(final AddressDto dto, final Address entity, final MappingContext context) {
if(context == null){
throw new IllegalArgumentException("Please pass a context!");
}
entity.setStreetname(toEntity_streetname(dto, entity, context));
entity.setPostalcode(toEntity_postalcode(dto, entity, context));
}
/**
* Maps the property streetname from the given entity to dto property.
*
* @param in - The source entity
* @param context - The context to get information about depth,...
* @return the mapped value
*
*/
protected String toDto_streetname(final Address in, final MappingContext context) {
return in.getStreetname();
}
/**
* Maps the property streetname from the given entity to dto property.
*
* @param in - The source entity
* @param parentEntity - The parentEntity
* @param context - The context to get information about depth,...
* @return the mapped value
*
*/
protected String toEntity_streetname(final AddressDto in, final Address parentEntity, final MappingContext context) {
return in.getStreetname();
}
/**
* Maps the property postalcode from the given entity to dto property.
*
* @param in - The source entity
* @param context - The context to get information about depth,...
* @return the mapped value
*
*/
protected String toDto_postalcode(final Address in, final MappingContext context) {
return in.getPostalcode();
}
/**
* Maps the property postalcode from the given entity to dto property.
*
* @param in - The source entity
* @param parentEntity - The parentEntity
* @param context - The context to get information about depth,...
* @return the mapped value
*
*/
protected String toEntity_postalcode(final AddressDto in, final Address parentEntity, final MappingContext context) {
return in.getPostalcode();
}
public String createDtoHash(final Object in) {
throw new UnsupportedOperationException("No id attribute available");
}
public String createEntityHash(final Object in) {
throw new UnsupportedOperationException("No id attribute available");
}
}