All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.onebusaway.gtfs.csv.schema.EntitySchemaFactoryHelper Maven / Gradle / Ivy

There is a newer version: 1.3.4
Show newest version
package org.onebusaway.gtfs.csv.schema;

import org.onebusaway.gtfs.csv.schema.beans.CsvEntityMappingBean;
import org.onebusaway.gtfs.csv.schema.beans.CsvFieldMappingBean;

import java.lang.reflect.Field;

public class EntitySchemaFactoryHelper {

  private DefaultEntitySchemaFactory _factory;

  public EntitySchemaFactoryHelper(DefaultEntitySchemaFactory factory) {
    _factory = factory;
  }

  public CsvEntityMappingBean addEntity(Class entityClass) {
    CsvEntityMappingBean bean = new CsvEntityMappingBean(entityClass);
    _factory.addBean(bean);
    return bean;
  }

  public CsvEntityMappingBean addEntity(Class entityClass, String filename) {
    CsvEntityMappingBean bean = addEntity(entityClass);
    bean.setFilename(filename);
    return bean;
  }

  public CsvEntityMappingBean addEntity(Class entityClass, String filename, String prefix) {
    CsvEntityMappingBean bean = addEntity(entityClass, filename);
    bean.setPrefix(prefix);
    return bean;
  }

  public CsvFieldMappingBean addField(CsvEntityMappingBean entityBean, String fieldName) {
    Class entityClass = entityBean.getType();
    try {
      Field field = entityClass.getDeclaredField(fieldName);
      CsvFieldMappingBean fieldBean = new CsvFieldMappingBean(field);
      entityBean.addField(fieldBean);
      return fieldBean;
    } catch (Exception e) {
      throw new IllegalStateException(e);
    }
  }
  
  public CsvFieldMappingBean[] addFields(CsvEntityMappingBean entityBean, String... fieldNames){
    CsvFieldMappingBean[] fields = new CsvFieldMappingBean[fieldNames.length];
    for( int i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy