use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.
the class FederatedByCoordinateBoundsMethodInvocationHandlerImpl method invoke.
public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceAreaServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Object value = args[_argumentIndex];
if (_expression != null)
value = _expression.invoke(value);
CoordinateBounds bounds = (CoordinateBounds) value;
FederatedService service = collection.getServiceForBounds(bounds);
return method.invoke(service, args);
}
use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.
the class FederatedByEntityIdMethodInvocationHandlerImpl method invoke.
public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Object value = args[_argumentIndex];
if (_expression != null)
value = _expression.invoke(value);
String entityId = value.toString();
String agencyId = AgencyIdSupport.getAgencyIdFromEntityId(entityId);
FederatedService service = collection.getServiceForAgencyId(agencyId);
return method.invoke(service, args);
}
use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.
the class FederatedByEntityIdsMethodInvocationHandlerImpl method invoke.
@SuppressWarnings("unchecked")
public Object invoke(FederatedServiceCollection collection, Method method, Object[] args) throws ServiceException, IllegalArgumentException, IllegalAccessException, InvocationTargetException {
Iterable<String> entityIds = (Iterable<String>) args[_argumentIndex];
Set<String> agencyIds = new HashSet<String>();
for (String entityId : entityIds) agencyIds.add(AgencyIdSupport.getAgencyIdFromEntityId(entityId));
FederatedService service = collection.getServiceForAgencyIds(agencyIds);
return method.invoke(service, args);
}
use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.
the class FederatedServiceCollectionImpl method getServiceForAgencyIds.
@Override
public FederatedService getServiceForAgencyIds(Iterable<String> agencyIds) throws ServiceAreaServiceException {
Set<FederatedService> providers = new HashSet<FederatedService>();
for (String id : agencyIds) {
FederatedService provider = getServiceForAgencyId(id);
if (provider == null)
throw new NoSuchAgencyServiceException(id);
providers.add(provider);
}
return getProviderFromProviders(providers);
}
use of org.onebusaway.federations.FederatedService in project onebusaway-application-modules by camsys.
the class FederatedServiceLibrary method getFederatedServiceAgencyCoverage.
/**
* Given a list of {@link FederatedService} instances {@code
* federatedServiceInstances} that implement a target {@code
* federatedServiceInterface}, query each instance in turn to determine its
* set of agencies and geographic bounds, verifying that no two distinct
* federated service instances have overlapping agency ids or geographic
* bounds. We construct a map from each service instance to its set of agency
* ids along with their geographic regions.
*
* @param federatedServiceInstances
* @param federatedServiceInterface
* @return a map of service instances along with their agency ids and coverage
* areas
*/
public static Map<FederatedService, Map<String, List<CoordinateBounds>>> getFederatedServiceAgencyCoverage(List<? extends FederatedService> federatedServiceInstances, Class<? extends FederatedService> federatedServiceInterface) {
Map<FederatedService, Map<String, List<CoordinateBounds>>> byProvider = new HashMap<FederatedService, Map<String, List<CoordinateBounds>>>();
for (FederatedService service : federatedServiceInstances) {
if (!federatedServiceInterface.isAssignableFrom(service.getClass()))
throw new IllegalArgumentException("service provider " + service + " not instance of " + federatedServiceInterface.getName());
Map<String, List<CoordinateBounds>> agencyIdsWithCoverageArea = service.getAgencyIdsWithCoverageArea();
for (Map.Entry<String, List<CoordinateBounds>> entry : agencyIdsWithCoverageArea.entrySet()) {
String agencyId = entry.getKey();
List<CoordinateBounds> coverage = entry.getValue();
checkAgencyAndCoverageAgainstExisting(byProvider, agencyId, coverage, federatedServiceInterface, true);
}
byProvider.put(service, agencyIdsWithCoverageArea);
}
return byProvider;
}
Aggregations