public static <T extends GenericMutableDao> void readGtfs(
      T entityStore, File resourcePath, String defaultAgencyId) throws IOException {

    GtfsReader reader = new GtfsReader();
    reader.setDefaultAgencyId(defaultAgencyId);

    reader.setInputLocation(resourcePath);

    reader.setEntityStore(entityStore);

    reader.run();
  }
 /**
  * Returns a {@link AgencyAndId} with the specified new id value and the appropriate agency id
  * prefix. By default, we use the GTFS reader's default agency id. However, if the specified
  * bean+property has an existing {@link AgencyAndId} value, we use the agency-id specified there.
  */
 public AgencyAndId resolveAgencyAndId(BeanWrapper bean, String propertyName, String newId) {
   GtfsReaderContext context = _reader.getGtfsReaderContext();
   String agencyId = context.getDefaultAgencyId();
   AgencyAndId existingId = (AgencyAndId) bean.getPropertyValue(propertyName);
   if (existingId != null) {
     agencyId = existingId.getAgencyId();
   }
   return new AgencyAndId(agencyId, newId);
 }
 /**
  * Returns a {@link Converter} that can convert values to the target value type. If the target
  * entity type + property has a custom converter defined in the GTFS entity schema, we will use
  * that as instead.
  *
  * @param targetEntityType the target entity type whose property will be updated.
  * @param targetPropertyName the target property name for the property that will be updated on the
  *     target entity.
  * @param targetValueType the target value type we wish to convert to
  */
 public Converter resolveConverter(
     Class<?> targetEntityType, String targetPropertyName, Class<?> targetValueType) {
   SingleFieldMapping mapping =
       _schemaCache.getFieldMappingForCsvFieldName(targetEntityType, targetPropertyName);
   if (mapping == null) {
     mapping =
         _schemaCache.getFieldMappingForObjectFieldName(targetEntityType, targetPropertyName);
   }
   if (mapping != null) {
     if (mapping instanceof ConverterFactory) {
       ConverterFactory factory = (ConverterFactory) mapping;
       return factory.create(_reader.getContext());
     }
     if (mapping instanceof Converter) {
       return (Converter) mapping;
     }
   }
   return ConvertUtils.lookup(targetValueType);
 }
  @Override
  public void run() {

    if (_readers.isEmpty()) return;

    try {

      StoreImpl store = new StoreImpl(_store);

      for (GtfsReader reader : _readers) {
        reader.setEntityStore(store);
        reader.addEntityHandler(new EntityCounter());
      }

      store.open();

      List<Agency> agencies = new ArrayList<Agency>();
      List<Class<?>> entityClasses = _readers.get(0).getEntityClasses();

      for (Class<?> entityClass : entityClasses) {
        _log.info("reading entities: " + entityClass.getName());

        for (GtfsReader reader : _readers) {

          // Pre-load the agencies, since one agency can be mentioned across
          // multiple feeds
          if (entityClass.equals(Agency.class)) reader.setAgencies(agencies);

          reader.readEntities(entityClass);

          if (entityClass.equals(Agency.class))
            agencies = new ArrayList<Agency>(reader.getAgencies());

          store.flush();
        }
      }

      store.close();

    } catch (IOException ex) {
      ex.printStackTrace();
    }
  }
 public void addGtfsReaderFromInputLocation(File inputLocation) throws IOException {
   GtfsReader reader = new GtfsReader();
   reader.setInputLocation(inputLocation);
   addGtfsReader(reader);
 }