Package com.codiform.moo

Examples of com.codiform.moo.TranslationException


        while ( sourceItems.hasNext() ) {
          Object item = itemSource.getValue( sourceItems.next() );
          targetCollection.add( item );
        }
      } else {
        throw new TranslationException( "Cannot translate collection to target of type: " + target.getClass().getName() );
      }
    } else {
      throw new TranslationException( "Cannot translate collection from type: " + value.getClass().getName() );
    }
  }
View Full Code Here


          Object item = itemSource.getValue( sourceItems.next() );
          Object translated = cache.getTranslation( item, property.getItemClass() );
          targetCollection.add( translated );
        }
      } else {
        throw new TranslationException( "Cannot translate collection to target of type: " + target.getClass().getName() );
      }
    } else {
      throw new TranslationException( "Cannot translate from collection of type: " + target.getClass().getName() );
    }
  }
View Full Code Here

  @Override
  public <T> T getTranslationTargetInstance( Object source, Class<T> targetType ) {
    Class<? extends T> type = getDefaultTypeForTarget( targetType );
    if ( type == null ) {
      throw new TranslationException( "Cannot determine default collection type for type: " + targetType );
    } else {
      return construct( type );
    }
  }
View Full Code Here

  private <T> T getObjectTranslation( Object source, Class<? extends TranslationTargetFactory> factoryType, Class<T> destinationClass ) {
    ObjectTranslator<T> translator = getTranslator( destinationClass );
    TranslationTargetFactory factory = getTranslationTargetFactory( factoryType );
    T translated = factory.getTranslationTargetInstance( source, destinationClass );
    if ( translated == null )
      throw new TranslationException( "Translation target factory (" + factory + ") returned null instance; cannot translate." );
    translationCache.putTranslation( source, translated );
    translator.update( source, translated, this, variables );
    return translated;
  }
View Full Code Here

      try {
        TranslationTargetFactory instance = factoryType.newInstance();
        translationTargetFactoryCache.put( factoryType, instance );
        return instance;
      } catch ( InstantiationException cause ) {
        throw new TranslationException( "Could not create translation target factory: " + factoryType, cause );
      } catch ( IllegalAccessException cause ) {
        throw new TranslationException( "Could not create translation target factory: " + factoryType, cause );
      }
    }
  }
View Full Code Here

      Object target = createTargetMap( value, property, translationSource );
      if ( target instanceof Map ) {
        translateMap( (Map<Object, Object>)value, (Map<Object, Object>)target, property, translationSource );
        return target;
      } else {
        throw new TranslationException( "Cannot translate map to target of type: " + target.getClass().getName() );
      }
    } else {
      throw new TranslationException( "Cannot translate map from type: " + value.getClass().getName() );
    }
  }
View Full Code Here

      if ( target instanceof Map ) {
        Map<Object, Object> targetMap = (Map<Object, Object>)target;
        targetMap.putAll( (Map<Object, Object>)value );
        return targetMap;
      } else {
        throw new TranslationException( "Cannot translate Map to target of type: " + target.getClass().getName() );
      }
    } else {
      throw new TranslationException( "Cannot translate collection from type: " + value.getClass().getName() );
    }
  }
View Full Code Here

  @Override
  public <T> T getTranslationTargetInstance( Object source, Class<T> targetType ) {
    Class<? extends T> type = getDefaultTypeForTarget( targetType );
    if ( type == null ) {
      throw new TranslationException( "Cannot determine default collection type for type: " + targetType );
    } else {
      return construct( type );
    }
  }
View Full Code Here

      if ( source instanceof String )
        return (String)source;
      else
        return source.toString();
    } catch ( Exception exception ) {
      throw new TranslationException( "Could not translate object " + source + " to String.", exception );
    }
  }
View Full Code Here

   */
  public T create() {
    try {
      return destinationClass.newInstance();
    } catch (InstantiationException exception) {
      throw new TranslationException(String.format(
          "Error while instantiating %s", destinationClass),
          exception);
    } catch (IllegalAccessException exception) {
      throw new TranslationException(String.format(
          "Not allowed to instantiate %s", destinationClass),
          exception);
    }
  }
View Full Code Here

TOP

Related Classes of com.codiform.moo.TranslationException

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.