Search in sources :

Example 1 with StringModificationStrategy

use of org.onebusaway.gtfs_transformer.impl.StringModificationStrategy 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);
    }
}
Also used : TypedEntityMatch(org.onebusaway.gtfs_transformer.match.TypedEntityMatch) EntityTransformStrategy(org.onebusaway.gtfs_transformer.services.EntityTransformStrategy) GtfsEntityTransformStrategy(org.onebusaway.gtfs_transformer.services.GtfsEntityTransformStrategy) JSONObject(org.json.JSONObject) StringModificationStrategy(org.onebusaway.gtfs_transformer.impl.StringModificationStrategy) JSONObject(org.json.JSONObject) TransformSpecificationException(org.onebusaway.gtfs_transformer.TransformSpecificationException) Pair(org.onebusaway.collections.tuple.Pair)

Aggregations

JSONObject (org.json.JSONObject)1 Pair (org.onebusaway.collections.tuple.Pair)1 TransformSpecificationException (org.onebusaway.gtfs_transformer.TransformSpecificationException)1 StringModificationStrategy (org.onebusaway.gtfs_transformer.impl.StringModificationStrategy)1 TypedEntityMatch (org.onebusaway.gtfs_transformer.match.TypedEntityMatch)1 EntityTransformStrategy (org.onebusaway.gtfs_transformer.services.EntityTransformStrategy)1 GtfsEntityTransformStrategy (org.onebusaway.gtfs_transformer.services.GtfsEntityTransformStrategy)1