List of usage examples for java.lang.reflect Method getAnnotationsByType
@Override public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass)
From source file:com.flipkart.flux.client.intercept.WorkflowInterceptor.java
@Override public Object invoke(MethodInvocation invocation) throws Throwable { try {//from w w w .j av a 2 s .c o m final Method method = invocation.getMethod(); final Workflow[] workFlowAnnotations = method.getAnnotationsByType(Workflow.class); checkForBadSignatures(invocation); final String correlationId = checkForCorrelationId(invocation.getArguments()); localContext.registerNew(new MethodId(method).toString(), workFlowAnnotations[0].version(), workFlowAnnotations[0].description(), correlationId); registerEventsForArguments(invocation.getArguments()); invocation.proceed(); connector.submitNewWorkflow(localContext.getStateMachineDef()); return null; // TODO, return a proxy object } finally { this.localContext.reset(); } }
From source file:com.narvis.dataaccess.weather.OpenWeatherMapPortal.java
/** * Call the method wich provide the answer for the given method * * @param command/*from w w w.j a va 2 s . c o m*/ * @return the return value of the called method */ private String CallMethodByCommand(String command) { if (command == null) { return null; } Method[] methods = this.getClass().getMethods(); //Heizenberg is behind you... for (Method meth : methods) { Command[] comAnnotations = meth.getAnnotationsByType(Command.class); for (Command comAnnot : comAnnotations) { if (comAnnot.CommandName().equals(command)) { try { //Method found we call it return (String) meth.invoke(this); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { //The user came to the wrong methodhood, we quit return null; } } } } return null; }
From source file:com.flipkart.flux.deploymentunit.DeploymentUnit.java
/** * Given a class loader, retrieves workflow classes names from config file, and returns methods * which are annotated with {@link com.flipkart.flux.client.model.Task} annotation in those classes. *///from www.ja v a 2 s. c o m private void populateTaskMethods() { List<String> classNames = (List<String>) configuration.getProperty(WORKFLOW_CLASSES); try { //loading this class separately in this class loader as the following isAnnotationPresent check returns false, if //we use default class loader's Task, as both class loaders don't have any relation between them. Class taskAnnotationClass = deploymentUnitClassLoader.loadClass(Task.class.getCanonicalName()); for (String name : classNames) { Class clazz = deploymentUnitClassLoader.loadClass(name); for (Method method : clazz.getMethods()) { if (method.isAnnotationPresent(taskAnnotationClass)) { Annotation taskAnnotation = method.getAnnotationsByType(taskAnnotationClass)[0]; long version = 0; for (Method annotationMethod : taskAnnotationClass.getDeclaredMethods()) { if (annotationMethod.getName().equals("version")) { version = (Long) annotationMethod.invoke(taskAnnotation); } } MethodId methodId = new MethodId(method); String taskIdentifier = methodId.toString() + _VERSION + version; taskMethods.put(taskIdentifier, method); } } } } catch (Exception e) { throw new FluxError(FluxError.ErrorType.runtime, "Error while getting task methods for deploymentUnit: " + name + "/" + version, e); } }
From source file:org.apache.tinkerpop.gremlin.AbstractGremlinTest.java
@Before public void setup() throws Exception { final Method testMethod = this.getClass().getMethod(cleanMethodName(name.getMethodName())); final LoadGraphWith[] loadGraphWiths = testMethod.getAnnotationsByType(LoadGraphWith.class); final LoadGraphWith loadGraphWith = loadGraphWiths.length == 0 ? null : loadGraphWiths[0]; final LoadGraphWith.GraphData loadGraphWithData = null == loadGraphWith ? null : loadGraphWith.value(); graphProvider = GraphManager.getGraphProvider(); config = graphProvider.standardGraphConfiguration(this.getClass(), name.getMethodName(), loadGraphWithData); // this should clear state from a previously unfinished test. since the graph does not yet exist, // persisted graphs will likely just have their directories removed graphProvider.clear(config);//from w w w. j av a 2 s . c o m graph = graphProvider.openTestGraph(config); g = graphProvider.traversal(graph); // get feature requirements on the test method and add them to the list of ones to check final FeatureRequirement[] featureRequirement = testMethod.getAnnotationsByType(FeatureRequirement.class); final List<FeatureRequirement> frs = new ArrayList<>(Arrays.asList(featureRequirement)); // if the graph is loading data then it will come with it's own requirements if (loadGraphWiths.length > 0) frs.addAll(loadGraphWiths[0].value().featuresRequired()); // if the graph has a set of feature requirements bundled together then add those final FeatureRequirementSet[] featureRequirementSets = testMethod .getAnnotationsByType(FeatureRequirementSet.class); if (featureRequirementSets.length > 0) frs.addAll(Arrays.stream(featureRequirementSets).flatMap(f -> f.value().featuresRequired().stream()) .collect(Collectors.toList())); // process the unique set of feature requirements final Set<FeatureRequirement> featureRequirementSet = new HashSet<>(frs); for (FeatureRequirement fr : featureRequirementSet) { try { //System.out.println(String.format("Assume that %s meets Feature Requirement - %s - with %s", fr.featureClass().getSimpleName(), fr.feature(), fr.supported())); assumeThat(String.format( "%s does not support all of the features required by this test so it will be ignored: %s.%s=%s", graph.getClass().getSimpleName(), fr.featureClass().getSimpleName(), fr.feature(), fr.supported()), graph.features().supports(fr.featureClass(), fr.feature()), is(fr.supported())); } catch (NoSuchMethodException nsme) { throw new NoSuchMethodException(String.format("[supports%s] is not a valid feature on %s", fr.feature(), fr.featureClass())); } } beforeLoadGraphWith(graph); // load a graph with sample data if the annotation is present on the test graphProvider.loadGraphData(graph, loadGraphWith, this.getClass(), name.getMethodName()); afterLoadGraphWith(graph); }