View Javadoc

1   /*
2    * To change this template, choose Tools | Templates
3    * and open the template in the editor.
4    */
5   package org.jcr_blog.jcrmapping.converter.basic;
6   
7   import com.google.common.collect.Lists;
8   import java.util.List;
9   import javax.enterprise.context.ApplicationScoped;
10  import javax.jcr.RepositoryException;
11  import javax.jcr.Value;
12  import org.jcr_blog.jcrmapping.NodeConverterException;
13  import org.jcr_blog.jcrmapping.converter.CollectionConverter;
14  
15  /**
16   *
17   * @author sprehn
18   */
19  @ApplicationScoped
20  public class ListConverter implements CollectionConverter {
21      
22      @Override
23      public boolean isApplicableValuesToObjects(final Class<?> clazz) {
24          return clazz.isAssignableFrom(List.class);
25      }
26  
27      @Override
28      public Object toObjects(final Value[] values,  CreateObjectCallback callback) throws NodeConverterException, RepositoryException {
29          final List<Object> result = Lists.newArrayListWithExpectedSize(values.length);
30          for (final Value v : values) {
31              result.add(callback.toObject(v));
32          }
33          return result;
34      }
35  }