Package ma.glasnost.orika

Examples of ma.glasnost.orika.MappingException


        final Class<?> dc = destination.getOwner().rawType();
       
        final Class<?> destinationElementClass = d.elementType().getRawType();
       
        if (destinationElementClass == null) {
            throw new MappingException("cannot determine runtime type of destination collection " + dc.getName() + "." + d.name());
        }
       
        // Start check if source property ! = null
        out.append(s.ifNotNull() + " {\n");
       
View Full Code Here


    public String generateEqualityTestCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) {
        return source + " == " + destination;
    }

    public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) {
        throw new MappingException("Encountered mapping of primitive to object (or vise-versa); sourceType="+
                source.type() + ", destinationType=" + destination.type());
    }
View Full Code Here

    public boolean appliesTo(FieldMap fieldMap) {
        return fieldMap.getBType().isEnum() && !fieldMap.getAType().isEnum() && !fieldMap.getAType().isString();
    }

    public String generateMappingCode(FieldMap fieldMap, VariableRef source, VariableRef destination, SourceCodeContext code) {
        throw new MappingException("Encountered mapping of enum to object (or vise-versa); sourceType="+
                source.type() + ", destinationType=" + destination.type());
    }
View Full Code Here

     * @param defaults
     */
    protected ClassMapBuilder(Type<A> aType, Type<B> bType, MapperFactory mapperFactory, PropertyResolverStrategy propertyResolver, DefaultFieldMapper... defaults) {
     
      if (aType == null) {
          throw new MappingException("[aType] is required");
      }
     
      if (bType == null) {
          throw new MappingException("[bType] is required");
      }
     
      this.mapperFactory = mapperFactory;
      this.propertyResolver = propertyResolver;
      this.defaults = defaults;
View Full Code Here

        /*
         * Add more information to the message to help with debugging
         */
        String msg = getClass().getSimpleName() + ".map(" + aType + ", " + bType + ")" +
            ".field('" + fieldNameA + "', '" + fieldNameB + "'): Error: " + e.getLocalizedMessage();
        throw new MappingException(msg, e);
      }
    }
View Full Code Here

     * @return this ClassMapBuilder
     */
    public <X, Y> ClassMapBuilder<A, B> use(Type<?> aParentType, Type<?> bParentType) {
       
        if (!aParentType.isAssignableFrom(aType)) {
            throw new MappingException(aType.getSimpleName() + " is not a subclass of " + aParentType.getSimpleName());
        }
       
        if (!bParentType.isAssignableFrom(bType)) {
            throw new MappingException(bType.getSimpleName() + " is not a subclass of " + bParentType.getSimpleName());
        }
       
        usedMappers.add(new MapperKey(aParentType, bParentType));
       
        return this;
View Full Code Here

       
        StringBuilder out = new StringBuilder();
        for (final VariableRef ref : propertyRef.getPath()) {
           
            if (!ClassUtil.isConcrete(ref.type()) && !ref.type().isMultiOccurrence()) {
                throw new MappingException("Abstract types are unsupported for nested properties. \n" + ref.name());
            }
            append(out,
                    format("if(%s) { \n", ref.isNull()),
                    ref.assign(newObject(source, ref.type())),
                    "}");
View Full Code Here

                    strategyRecorder.setInstantiate(true);
                    resolvedDestinationType = mapperFactory.lookupConcreteDestinationType(resolvedSourceType, destinationType,
                            context);
                    if (resolvedDestinationType == null) {
                        if (!ClassUtil.isConcrete(destinationType)) {
                            MappingException e = new MappingException("No concrete class mapping defined for source class "
                                    + resolvedSourceType.getName());
                            e.setDestinationType(destinationType);
                            e.setSourceType(resolvedSourceType);
                            throw e;
                        } else {
                            resolvedDestinationType = destinationType;
                        }
                    }
View Full Code Here

    @SuppressWarnings("unchecked")
    public <S, D> D map(final S sourceObject, final Type<S> sourceType, final Type<D> destinationType, final MappingContext context) {
       
        try {
            if (destinationType == null) {
                throw new MappingException("Can not map to a null class.");
            }
            if (sourceObject == null) {
                return null;
            }
           
            D existingResult = (D) context.getMappedObject(sourceObject, destinationType);
            if (existingResult == null) {
                MappingStrategy strategy = resolveMappingStrategy(sourceObject, sourceType, destinationType, false, context);
                existingResult = (D) strategy.map(sourceObject, null, context);
            }
            return existingResult;
           
        } 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) + "\nsourceType=" + sourceType
                    + "\ndestinationType=" + destinationType, e);
        }
    }
View Full Code Here

   
    public <S, D> void map(S sourceObject, D destinationObject, Type<S> sourceType, Type<D> destinationType, MappingContext context) {
       
        try {
            if (destinationObject == null) {
                throw new MappingException("[destinationObject] can not be null.");
            }
           
            if (destinationType == null) {
                throw new MappingException("[destinationType] can not be null.");
            }
           
            if (sourceObject == null) {
                throw new MappingException("[sourceObject] can not be null.");
            }
           
            if (context.getMappedObject(sourceObject, destinationType) == null) {
                MappingStrategy strategy = resolveMappingStrategy(sourceObject, sourceType, destinationType, 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) + "\nsourceType=" + sourceType
                    + "\nrawDestination=" + destinationObject + "\ndestinationClass="
                    + (destinationObject != null ? destinationObject.getClass() : null) + "\ndestinationType=" + destinationType, e);
        }
       
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.