Package ma.glasnost.orika

Examples of ma.glasnost.orika.MappingException


   
    public <S, D> void map(S sourceObject, D destinationObject, MappingContext context) {
       
        try {
            if (destinationObject == null) {
                throw new MappingException("[destinationObject] can not be null.");
            }
           
            if (sourceObject == null) {
                throw new MappingException("[sourceObject] can not be null.");
            }
           
            if (context.getMappedObject(sourceObject, destinationObject.getClass()) == null) {
                MappingStrategy strategy = resolveMappingStrategy(sourceObject, null, destinationObject.getClass(), true, context);
                strategy.map(sourceObject, destinationObject, context);
            }

        } catch (MappingException e) {
            /* don't wrap our own exceptions */
            throw e;
        } catch (RuntimeException e) {
            if (!ExceptionUtility.originatedByOrika(e)) {
                throw e;
            }
            throw new MappingException("Error encountered while mapping for the following inputs: " + "\nrawSource=" + sourceObject
                    + "\nsourceClass=" + (sourceObject != null ? sourceObject.getClass() : null)
                    + "\nrawDestination=" + destinationObject + "\ndestinationClass="
                    + (destinationObject != null ? destinationObject.getClass() : null), e);
        }
    }
View Full Code Here


    @SuppressWarnings("unchecked")
    public <S, D> D map(S sourceObject, Class<D> destinationClass, MappingContext context) {
       
        try {
            if (destinationClass == null) {
                throw new MappingException("Can not map to a null class.");
            }
            if (sourceObject == null) {
                return null;
            }
           
            D result = (D) context.getMappedObject(sourceObject, destinationClass);
            if (result == null) {
                MappingStrategy strategy = resolveMappingStrategy(sourceObject, null, destinationClass, false, context);
                result = (D) strategy.map(sourceObject, null, context);
            }
            return result;
           
        } catch (MappingException e) {
            /* don't wrap our own exceptions */
            throw e;
        } catch (RuntimeException e) {
            if (!ExceptionUtility.originatedByOrika(e)) {
                throw e;
            }
            throw new MappingException("Error encountered while mapping for the following inputs: " + "\nrawSource=" + sourceObject
                    + "\nsourceClass=" + (sourceObject != null ? sourceObject.getClass() : null)
                    + "\ndestinationClass=" + destinationClass, e);
        }
    }
View Full Code Here

            context.registerMapperGeneration(classMap);
           
            return instance;
           
        } catch (final Exception e) {
            throw new MappingException(e);
        }
    }
View Full Code Here

                try {
                    mappedFields.add(currentFieldMap);
                    String sourceCode = generateFieldMapCode(code, fieldMap, classMap, destination, logDetails);
                    out.append(sourceCode);
                } catch (final Exception e) {
                    MappingException me = new MappingException(e);
                    me.setSourceProperty(fieldMap.getSource());
                    me.setDestinationProperty(fieldMap.getDestination());
                    me.setSourceType(source.type());
                    me.setDestinationType(destination.type());
                    throw me;
                }
            } else if (logDetails !=null) {
              logDetails.append("ignored for this mapping direction");
            }
View Full Code Here

            }
           
            return objectFactory;
           
        } catch (final Exception e) {
            throw new MappingException("exception while creating object factory for " + type.getName(), e);
        }
    }
View Full Code Here

        if (sourceClasses != null && !sourceClasses.isEmpty()) {
            for (Type<? extends Object> sourceType : sourceClasses) {
                out.append(addSourceClassConstructor(code, type, sourceType, mappingContext, logDetails));
            }
        } else {
            throw new MappingException("Cannot generate ObjectFactory for " + type);
        }
       
        // TODO: can this condition be reached?
        // if object factory generation failed, we should not create the factory
        // which is unable to construct an instance of anything.
View Full Code Here

                    throw new RuntimeException("Unexpected error while trying to resolve property " + referenceType.getCanonicalName() + ", ["
                            + pd.getName() + "]", e);
                }
            }
        } catch (IntrospectionException e) {
            throw new MappingException(e);
        }
    }
View Full Code Here

                     * that something went wrong. However, there is a
                     * possibility that a custom ObjectFactory was registered
                     * for the immutable type, which would be valid.
                     */
                    if (ClassUtil.isImmutable(mapperKey.getBType()) && !objectFactoryRegistry.containsKey(mapperKey.getBType())) {
                        throw new MappingException("No converter registered for conversion from " + mapperKey.getAType() + " to "
                                + mapperKey.getBType() + ", nor any ObjectFactory which can generate " + mapperKey.getBType() + " from "
                                + mapperKey.getAType());
                    }
                   
                    if (LOGGER.isDebugEnabled()) {
View Full Code Here

            Set<ClassMap<Object, Object>> usedClassMapSet = new HashSet<ClassMap<Object, Object>>();
           
            for (final MapperKey parentMapperKey : classMap.getUsedMappers()) {
                ClassMap<Object, Object> usedClassMap = classMapsDictionary.get(parentMapperKey);
                if (usedClassMap == null) {
                    throw new MappingException("Cannot find class mapping using mapper : " + classMap.getMapperClassName());
                }
                usedClassMapSet.add(usedClassMap);
            }
            usedMapperMetadataRegistry.put(key, usedClassMapSet);
        }
View Full Code Here

    }
   
    private void collectUsedMappers(ClassMap<?, ?> classMap, List<Mapper<Object, Object>> parentMappers, MapperKey parentMapperKey) {
        Mapper<Object, Object> parentMapper = lookupMapper(parentMapperKey);
        if (parentMapper == null) {
            throw new MappingException("Cannot find used mappers for : " + classMap.getMapperClassName());
        }
        parentMappers.add(parentMapper);
       
        Set<ClassMap<Object, Object>> usedClassMapSet = usedMapperMetadataRegistry.get(parentMapperKey);
        if (usedClassMapSet != null) {
View Full Code Here

TOP

Related Classes of ma.glasnost.orika.MappingException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.