Package com.codiform.moo.property.source

Examples of com.codiform.moo.property.source.SourceProperty


  private void copyToTargetCollection( Object value, Object target, CollectionProperty property ) {
    if ( value instanceof Collection ) {
      if ( target instanceof Collection ) {
        Collection<Object> targetCollection = (Collection<Object>)target;
        Iterator<?> sourceItems = ( (Collection<?>)value ).iterator();
        SourceProperty itemSource = getItemSource( property.getItemSource() );
        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() );
      }
View Full Code Here


  private void translateToTargetCollection( Object value, Object target, CollectionProperty property, TranslationSource cache ) {
    if ( value instanceof Collection ) {
      if ( target instanceof Collection ) {
        Collection<Object> targetCollection = (Collection<Object>)target;
        Iterator<?> sourceItems = ( (Collection<?>)value ).iterator();
        SourceProperty itemSource = getItemSource( property.getItemSource() );
        while ( sourceItems.hasNext() ) {
          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() );
View Full Code Here

      throw new TranslationException( "Cannot translate map from type: " + value.getClass().getName() );
    }
  }

  private void translateMap( Map<Object, Object> source, Map<Object, Object> target, MapProperty property, TranslationSource translationSource ) {
    SourceProperty keySourceProperty = getSourceProperty( property.getKeySource() );
    SourceProperty valueSourceProperty = getSourceProperty( property.getValueSource() );
    for ( Map.Entry<Object, Object> entry : source.entrySet() ) {
      Object key, value;

      key = keySourceProperty.getValue( entry.getKey() );
      if ( key == null && !property.allowNullKeys() )
        continue;

      key = getKeyOrTranslation( key, property, translationSource );
      if ( key == null && !property.allowNullKeys() )
        continue;

      value = valueSourceProperty.getValue( entry.getValue() );
      value = getValueOrTranslation( value, property, translationSource );
      target.put( key, value );
    }
  }
View Full Code Here

    }
  }

  private void updateMapByKey( Map<Object, Object> sourceMap, Map<Object, Object> destinationMap, TranslationSource translationSource,
      MapProperty property ) {
    SourceProperty keySourceProperty = getSourceProperty( property.getKeySource() );
    SourceProperty valueSourceProperty = getSourceProperty( property.getValueSource() );

    for ( Map.Entry<Object, Object> entry : sourceMap.entrySet() ) {
      Object key = entry.getKey();
      key = keySourceProperty.getValue( key );
      if ( key == null && !property.allowNullKeys() )
        continue;

      key = getKeyOrTranslation( key, property, translationSource );
      if ( key == null && !property.allowNullKeys() )
        continue;

      Object sourceValue = entry.getValue();
      sourceValue = valueSourceProperty.getValue( sourceValue );
      sourceValue = getValueOrTranslation( sourceValue, property, translationSource );

      Object destinationValue = destinationMap.get( key );
      if ( destinationValue != null && sourceValue != null ) {
        translationSource.update( sourceValue, destinationValue );
View Full Code Here

  private Object transformCollection( Object value, CollectionProperty property, TranslationSource translationSource ) {
    return translatorFactory.getCollectionTranslator().translate( value, property, translationSource );
  }

  private Object getValue( Object source, Property property, Map<String, Object> variables ) {
    SourceProperty sourceProperty = sourcePropertyFactory.getSourceProperty( property.getSourcePropertyExpression() );
    if ( variables == null || variables.isEmpty() ) {
      return sourceProperty.getValue( source );
    } else {
      return sourceProperty.getValue( source, variables );
    }
  }
View Full Code Here

TOP

Related Classes of com.codiform.moo.property.source.SourceProperty

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.