Search in sources :

Example 1 with NoDefaultAgencyIdException

use of org.onebusaway.gtfs.serialization.NoDefaultAgencyIdException in project onebusaway-gtfs-modules by OneBusAway.

the class DeferredValueSupport method resolveAgencyAndId.

/**
 * 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 = null;
    try {
        agencyId = context.getDefaultAgencyId();
    } catch (NoDefaultAgencyIdException ndaie) {
        agencyId = null;
    }
    AgencyAndId existingId = (AgencyAndId) bean.getPropertyValue(propertyName);
    if (existingId != null) {
        agencyId = existingId.getAgencyId();
    }
    return new AgencyAndId(agencyId, newId);
}
Also used : NoDefaultAgencyIdException(org.onebusaway.gtfs.serialization.NoDefaultAgencyIdException) AgencyAndId(org.onebusaway.gtfs.model.AgencyAndId) GtfsReaderContext(org.onebusaway.gtfs.serialization.GtfsReaderContext)

Aggregations

AgencyAndId (org.onebusaway.gtfs.model.AgencyAndId)1 GtfsReaderContext (org.onebusaway.gtfs.serialization.GtfsReaderContext)1 NoDefaultAgencyIdException (org.onebusaway.gtfs.serialization.NoDefaultAgencyIdException)1