org.onebusaway.gtfs.csv.schema.EntitySchemaFactoryHelper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of onebusaway-gtfs Show documentation
Show all versions of onebusaway-gtfs Show documentation
A Java library for reading and writing General Transit Feed Spec feeds
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