use of org.onebusaway.gtfs_transformer.TransformSpecificationException in project onebusaway-gtfs-modules by OneBusAway.
the class TransformFactory method handleSubsectionOperation.
private void handleSubsectionOperation(String line, JSONObject json) throws JSONException, TransformSpecificationException {
SubsectionTripTransformStrategy strategy = getStrategy(SubsectionTripTransformStrategy.class);
SubsectionOperation operation = new SubsectionTripTransformStrategy.SubsectionOperation();
setObjectPropertiesFromJsonUsingCsvFields(operation, json, line);
if (operation.getFromStopId() == null && operation.getToStopId() == null) {
throw new TransformSpecificationException("must specify at least fromStopId or toStopId in subsection op", line);
}
strategy.addOperation(operation);
}
use of org.onebusaway.gtfs_transformer.TransformSpecificationException in project onebusaway-gtfs-modules by OneBusAway.
the class TransformFactory method handleTransformOperation.
private void handleTransformOperation(String line, JSONObject json) throws JSONException, TransformSpecificationException {
if (!json.has(ARG_CLASS)) {
throw new TransformSpecificationMissingArgumentException(line, ARG_CLASS);
}
String value = json.getString(ARG_CLASS);
Object factoryObj = null;
try {
Class<?> clazz = Class.forName(value);
factoryObj = clazz.newInstance();
} catch (Exception ex) {
throw new TransformSpecificationException("error instantiating class: " + value, ex, line);
}
handleTransformOperation(line, json, factoryObj);
}
use of org.onebusaway.gtfs_transformer.TransformSpecificationException in project onebusaway-gtfs-modules by OneBusAway.
the class TransformFactory method handleTrimOperation.
private void handleTrimOperation(String line, JSONObject json) throws JSONException, TransformSpecificationException {
TypedEntityMatch match = getMatch(line, json);
if (match.getType() != Trip.class) {
throw new TransformSpecificationException("the trim_trip op only supports matching against trips", line);
}
TrimTripTransformStrategy strategy = getStrategy(TrimTripTransformStrategy.class);
TrimOperation operation = new TrimTripTransformStrategy.TrimOperation();
operation.setMatch(match);
if (json.has("to_stop_id")) {
operation.setToStopId(json.getString("to_stop_id"));
}
if (json.has("from_stop_id")) {
operation.setFromStopId(json.getString("from_stop_id"));
}
if (operation.getToStopId() == null && operation.getFromStopId() == null) {
throw new TransformSpecificationMissingArgumentException(line, new String[] { "to_stop_id", "from_stop_id" });
}
strategy.addOperation(operation);
}
use of org.onebusaway.gtfs_transformer.TransformSpecificationException in project onebusaway-gtfs-modules by OneBusAway.
the class TransformFactory method handleTransformOperation.
private void handleTransformOperation(String line, JSONObject json, Object factoryObj) throws JSONException, TransformSpecificationException {
setObjectPropertiesFromJsonUsingCsvFields(factoryObj, json, line);
boolean added = false;
if (factoryObj instanceof GtfsTransformStrategy) {
_transformer.addTransform((GtfsTransformStrategy) factoryObj);
added = true;
}
if (factoryObj instanceof GtfsEntityTransformStrategy) {
_transformer.addEntityTransform((GtfsEntityTransformStrategy) factoryObj);
added = true;
}
if (factoryObj instanceof GtfsTransformStrategyFactory) {
GtfsTransformStrategyFactory factory = (GtfsTransformStrategyFactory) factoryObj;
factory.createTransforms(_transformer);
added = true;
}
if (!added) {
throw new TransformSpecificationException("factory object is not an instance of GtfsTransformStrategy, GtfsEntityTransformStrategy, or GtfsTransformStrategyFactory: " + factoryObj.getClass().getName(), line);
}
}
use of org.onebusaway.gtfs_transformer.TransformSpecificationException in project onebusaway-gtfs-modules by OneBusAway.
the class TransformFactory method handleUpdateOperation.
private void handleUpdateOperation(String line, JSONObject json) throws JSONException, TransformSpecificationException {
EntitiesTransformStrategy strategy = getStrategy(EntitiesTransformStrategy.class);
TypedEntityMatch match = getMatch(line, json);
if (json.has("factory")) {
String factoryType = json.getString("factory");
try {
Class<?> clazz = Class.forName(factoryType);
Object factoryObj = clazz.newInstance();
if (!(factoryObj instanceof EntityTransformStrategy)) {
throw new TransformSpecificationException("factory object is not an instance of EntityTransformStrategy: " + clazz.getName(), line);
}
strategy.addModification(match, (EntityTransformStrategy) factoryObj);
} catch (Throwable ex) {
throw new TransformSpecificationException("error creating factory ModificationStrategy instance", ex, line);
}
return;
}
if (json.has(ARG_UPDATE)) {
JSONObject update = json.getJSONObject(ARG_UPDATE);
EntityTransformStrategy mod = getUpdateEntityTransformStrategy(line, match, update);
strategy.addModification(match, mod);
}
if (json.has("strings")) {
JSONObject strings = json.getJSONObject("strings");
Map<String, Pair<String>> replacements = getEntityPropertiesAndStringReplacementsFromJsonObject(match.getType(), strings);
StringModificationStrategy mod = new StringModificationStrategy(replacements);
strategy.addModification(match, mod);
}
}
Aggregations