Package com.cedarsoft.spring.rcp.conversion

Source Code of com.cedarsoft.spring.rcp.conversion.Tagged2StringConverter

package com.cedarsoft.spring.rcp.conversion;

import com.cedarsoft.utils.tags.Tag;
import com.cedarsoft.utils.tags.TagSet;
import com.cedarsoft.utils.tags.Tagged;
import org.springframework.binding.convert.ConversionContext;
import org.springframework.binding.convert.support.ConversionServiceAwareConverter;

import java.util.Iterator;

/**
*
*/
public class Tagged2StringConverter extends ConversionServiceAwareConverter {
  @Override
  protected Object doConvert( Object source, Class targetClass, ConversionContext context ) throws Exception {
    assert targetClass.equals( String.class );

    StringBuilder builder = new StringBuilder();
    for ( Iterator<? extends Tag> it = ( ( Tagged ) source ).getTags().iterator(); it.hasNext(); ) {
      Tag tag = it.next();
      builder.append( tag );
      if ( it.hasNext() ) {
        builder.append( ", " );
      }
    }

    return builder.toString();
  }

  @Override
  public Class[] getSourceClasses() {
    return new Class[]{Tagged.class, TagSet.class};
  }

  @Override
  public Class[] getTargetClasses() {
    return new Class[]{String.class};
  }
}
TOP

Related Classes of com.cedarsoft.spring.rcp.conversion.Tagged2StringConverter

TOP
Copyright © 2018 www.massapi.com. 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.