FederatedServiceMethodInvocationHandlerFactory { public FederatedServiceMethodInvocationHandler getHandlerForMethod( Method method) { FederatedByAgencyIdMethod byAgency = method.getAnnotation(FederatedByAgencyIdMethod.class); if (byAgency != null) return new FederatedByAgencyIdMethodInvocationHandlerImpl(method, byAgency.argument(), byAgency.propertyExpression()); FederatedByAnyEntityIdMethod byAnyEntityId = method.getAnnotation(FederatedByAnyEntityIdMethod.class); if (byAnyEntityId != null) return new FederatedByAnyEntityIdMethodInvocationHandlerImpl(method, byAnyEntityId.argument(), byAnyEntityId.properties(), byAnyEntityId.agencyIdProperties()); FederatedByEntityIdMethod ann0 = method.getAnnotation(FederatedByEntityIdMethod.class); if (ann0 != null) return new FederatedByEntityIdMethodInvocationHandlerImpl(method, ann0.argument(), ann0.propertyExpression()); FederatedByEntityIdsMethod ann1 = method.getAnnotation(FederatedByEntityIdsMethod.class); if (ann1 != null) return new FederatedByEntityIdsMethodInvocationHandlerImpl( ann1.argument()); FederatedByBoundsMethod ann2 = method.getAnnotation(FederatedByBoundsMethod.class); if (ann2 != null) return new FederatedByBoundsMethodInvocationHandlerImpl( ann2.lat1Argument(), ann2.lon1Argument(), ann2.lat2Argument(), ann2.lon2Argument()); FederatedByLocationMethod ann3 = method.getAnnotation(FederatedByLocationMethod.class); if (ann3 != null) return new FederatedByLocationMethodInvocationHandlerImpl( ann3.latArgument(), ann3.lonArgument()); FederatedByAggregateMethod ann4 = method.getAnnotation(FederatedByAggregateMethod.class); if (ann4 != null) { EMethodAggregationType aggregationType = getAggregationTypeForMethod(method); return new FederatedByAggregateMethodInvocationHandlerImpl( aggregationType); } FederatedByCoordinateBoundsMethod ann5 = method.getAnnotation(FederatedByCoordinateBoundsMethod.class); if (ann5 != null) return new FederatedByCoordinateBoundsMethodInvocationHandlerImpl(method, ann5.argument(), ann5.propertyExpression()); FederatedByCoordinatePointsMethod ann6 = method.getAnnotation(FederatedByCoordinatePointsMethod.class); if (ann6 != null) { int[] argumentIndices = ann6.arguments(); String[] expressions = ann6.propertyExpressions(); if (expressions.length == 0) expressions = new String[argumentIndices.length]; return new FederatedByCoordinatePointsMethodInvocationHandlerImpl(method, argumentIndices, expressions); } FederatedByCustomMethod ann7 = method.getAnnotation(FederatedByCustomMethod.class); if (ann7 != null) { Class<? extends FederatedServiceMethodInvocationHandler> handlerClass = ann7.handler(); try { return handlerClass.newInstance(); } catch (Exception ex) { throw new ServiceException( "error creating FederatedServiceMethodInvocationHandler of type " + handlerClass, ex); } } throw new IllegalArgumentException( "No FederatedService method annotation for method: " + method); }  FederatedServiceMethodInvocationHandler getHandlerForMethod(
      Method method);  }
@Test public void testGetValuesAsList() throws SecurityException, NoSuchMethodException { Method method = SimpleFederatedService.class.getDeclaredMethod("getValuesAsList"); FederatedServiceMethodInvocationHandler handler = _factory.getHandlerForMethod(method); FederatedByAggregateMethodInvocationHandlerImpl impl = (FederatedByAggregateMethodInvocationHandlerImpl) handler; assertEquals(EMethodAggregationType.LIST, impl.getAggregationType()); }
@Test public void testGetValuesAsMap() throws SecurityException, NoSuchMethodException { Method method = SimpleFederatedService.class.getDeclaredMethod("getValuesAsMap"); FederatedServiceMethodInvocationHandler handler = _factory.getHandlerForMethod(method); FederatedByAggregateMethodInvocationHandlerImpl impl = (FederatedByAggregateMethodInvocationHandlerImpl) handler; assertEquals(EMethodAggregationType.MAP, impl.getAggregationType()); }
@Test public void testGetValueForId() throws SecurityException, NoSuchMethodException { Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForId", String.class); FederatedServiceMethodInvocationHandler handler = _factory.getHandlerForMethod(method); FederatedByEntityIdMethodInvocationHandlerImpl impl = (FederatedByEntityIdMethodInvocationHandlerImpl) handler; assertEquals(0, impl.getArgumentIndex()); }
@Test public void testGetValueForValueAndId() throws SecurityException, NoSuchMethodException { Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForValueAndId", String.class, String.class); FederatedServiceMethodInvocationHandler handler = _factory.getHandlerForMethod(method); FederatedByEntityIdMethodInvocationHandlerImpl impl = (FederatedByEntityIdMethodInvocationHandlerImpl) handler; assertEquals(1, impl.getArgumentIndex()); }
@Test public void testGetValueForIds() throws SecurityException, NoSuchMethodException { Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForIds", Set.class); FederatedServiceMethodInvocationHandler handler = _factory.getHandlerForMethod(method); FederatedByEntityIdsMethodInvocationHandlerImpl impl = (FederatedByEntityIdsMethodInvocationHandlerImpl) handler; assertEquals(0, impl.getArgumentIndex()); }
@Test public void testGetValueForValueAndIds() throws SecurityException, NoSuchMethodException { Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForValueAndIds", String.class, Set.class); FederatedServiceMethodInvocationHandler handler = _factory.getHandlerForMethod(method); FederatedByEntityIdsMethodInvocationHandlerImpl impl = (FederatedByEntityIdsMethodInvocationHandlerImpl) handler; assertEquals(1, impl.getArgumentIndex()); }
@Test public void testGetValueForBounds() throws SecurityException, NoSuchMethodException { Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForBounds", Double.TYPE, Double.TYPE, Double.TYPE, Double.TYPE); FederatedServiceMethodInvocationHandler handler = _factory.getHandlerForMethod(method); FederatedByBoundsMethodInvocationHandlerImpl impl = (FederatedByBoundsMethodInvocationHandlerImpl) handler; assertEquals(0, impl.getLat1ArgumentIndex()); assertEquals(1, impl.getLon1ArgumentIndex()); assertEquals(2, impl.getLat2ArgumentIndex()); assertEquals(3, impl.getLon2ArgumentIndex()); }
@Test public void testGetValueForCoordinateBounds() throws SecurityException, NoSuchMethodException { Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForCoordinateBounds", CoordinateBounds.class); FederatedServiceMethodInvocationHandler handler = _factory.getHandlerForMethod(method); FederatedByCoordinateBoundsMethodInvocationHandlerImpl impl = (FederatedByCoordinateBoundsMethodInvocationHandlerImpl) handler; assertEquals(0, impl.getArgumentIndex()); }
@Test public void testGetValueForCoordinateBoundsTestBean() throws SecurityException, NoSuchMethodException { Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForCoordinateBoundsTestBean", CoordinateBoundsTestBean.class); FederatedServiceMethodInvocationHandler handler = _factory.getHandlerForMethod(method); FederatedByCoordinateBoundsMethodInvocationHandlerImpl impl = (FederatedByCoordinateBoundsMethodInvocationHandlerImpl) handler; assertEquals(0, impl.getArgumentIndex()); assertEquals("bounds", impl.getExpression().getPath()); }
@Test public void testGetValueForLocation() throws SecurityException, NoSuchMethodException { Method method = SimpleFederatedService.class.getDeclaredMethod( "getValueForLocation", Double.TYPE, Double.TYPE); FederatedServiceMethodInvocationHandler handler = _factory.getHandlerForMethod(method); FederatedByLocationMethodInvocationHandlerImpl impl = (FederatedByLocationMethodInvocationHandlerImpl) handler; assertEquals(0, impl.getLatArgumentIndex()); assertEquals(1, impl.getLonArgumentIndex()); }