public JaxrsResourceMethod(MetaMethod method, JaxrsHeaders headers, String rootResourcePath) { Path subResourcePath = method.getAnnotation(Path.class); String fullPath = rootResourcePath; if (fullPath.startsWith("/")) { fullPath = fullPath.substring(1); } if (fullPath.endsWith("/")) { fullPath = fullPath.substring(0, fullPath.length() - 1); } if (subResourcePath != null) { if (!subResourcePath.value().startsWith("/")) { fullPath += "/"; } fullPath += subResourcePath.value(); } this.method = method; this.path = fullPath; this.httpMethod = JaxrsGwtRequestMethodMapper.fromMethod(method); this.parameters = JaxrsResourceMethodParameters.fromMethod(method); this.methodHeaders = JaxrsHeaders.fromMethod(method); this.resourceClassHeaders = headers; }
/** * Generates HTTP headers based on the JAX-RS annotations on the provided method. * * @param clazz the JAX-RS resource class * @return headers */ public static JaxrsHeaders fromMethod(MetaMethod method) { JaxrsHeaders headers = new JaxrsHeaders(); Produces p = method.getAnnotation(Produces.class); if (p != null) { headers.setAcceptHeader(p.value()); } Consumes c = method.getAnnotation(Consumes.class); if (c != null) { headers.setContentTypeHeader(c.value()); } return headers; }
final List<Class<?>> interceptors = new ArrayList<>(); InterceptedCall interceptedCall = method.getAnnotation(InterceptedCall.class); if (interceptedCall == null) { interceptedCall = type.getAnnotation(InterceptedCall.class);
final List<Class<?>> interceptors = new ArrayList<>(); InterceptedCall interceptedCall = method.getAnnotation(InterceptedCall.class); if (interceptedCall == null) { interceptedCall = type.getAnnotation(InterceptedCall.class);
private Collection<Statement> registerDeclarativeHandlers(final MetaClass bindable) { final List<MetaMethod> handlerMethods = bindable.getMethodsAnnotatedWith(org.jboss.errai.ui.shared.api.annotations.PropertyChangeHandler.class); if ( handlerMethods.isEmpty() ) return Collections.emptyList(); final List<Statement> retVal = new ArrayList<>(); for (final MetaMethod method : handlerMethods) { if (method.getParameters().length == 1 && method.getParameters()[0].getType().getFullyQualifiedName().equals(PropertyChangeEvent.class.getName())) { final String property = method.getAnnotation(org.jboss.errai.ui.shared.api.annotations.PropertyChangeHandler.class).value(); if (!property.isEmpty()) validateProperty(bindable, property); final Object handler = createHandlerForMethod(method); final ContextualStatementBuilder subStmt = (property.isEmpty() ? loadVariable("agent").invoke("addPropertyChangeHandler", handler): loadVariable("agent").invoke("addPropertyChangeHandler", property, handler)); retVal.add(subStmt); } else { throw new RuntimeException( String.format("The @ChangeHandler method [%s] must have exactly one argument of type %s.", method.getName(), PropertyChangeEvent.class.getSimpleName())); } } return retVal; }
private Collection<Statement> registerDeclarativeHandlers(final MetaClass bindable) { final List<MetaMethod> handlerMethods = bindable.getMethodsAnnotatedWith(org.jboss.errai.ui.shared.api.annotations.PropertyChangeHandler.class); if ( handlerMethods.isEmpty() ) return Collections.emptyList(); final List<Statement> retVal = new ArrayList<>(); for (final MetaMethod method : handlerMethods) { if (method.getParameters().length == 1 && method.getParameters()[0].getType().getFullyQualifiedName().equals(PropertyChangeEvent.class.getName())) { final String property = method.getAnnotation(org.jboss.errai.ui.shared.api.annotations.PropertyChangeHandler.class).value(); if (!property.isEmpty()) validateProperty(bindable, property); final Object handler = createHandlerForMethod(method); final ContextualStatementBuilder subStmt = (property.isEmpty() ? loadVariable("agent").invoke("addPropertyChangeHandler", handler): loadVariable("agent").invoke("addPropertyChangeHandler", property, handler)); retVal.add(subStmt); } else { throw new RuntimeException( String.format("The @ChangeHandler method [%s] must have exactly one argument of type %s.", method.getName(), PropertyChangeEvent.class.getSimpleName())); } } return retVal; }
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { MetaMethod metaMethod = decorable.getAsMethod(); PermissionCheck securedResource = metaMethod.getAnnotation(PermissionCheck.class); String permission = securedResource.value(); String onGranted = securedResource.onGranted(); String onDenied = securedResource.onDenied(); String declaringClass = metaMethod.getDeclaringClassName(); // The method must return void if (!metaMethod.getReturnType().getName().equals("void")) { throw new RuntimeException("The @PermissionCheck annotated method \"" + declaringClass + "#" + metaMethod.getName() + "\" must return void"); } // Permission check if (permission == null || permission.trim().length() == 0) { Statement stmt = createPermissionCheck(permission, onGranted, onDenied); controller.addInvokeBefore(metaMethod, stmt); } }
@Override public void generateDecorator(final Decorable decorable, final FactoryController controller) { MetaMethod metaMethod = decorable.getAsMethod(); PermissionCheck securedResource = metaMethod.getAnnotation(PermissionCheck.class); String permission = securedResource.value(); String onGranted = securedResource.onGranted(); String onDenied = securedResource.onDenied(); String declaringClass = metaMethod.getDeclaringClassName(); // The method must return void if (!metaMethod.getReturnType().getName().equals("void")) { throw new RuntimeException("The @PermissionCheck annotated method \"" + declaringClass + "#" + metaMethod.getName() + "\" must return void"); } // Permission check if (permission == null || permission.trim().length() == 0) { Statement stmt = createPermissionCheck(permission, onGranted, onDenied); controller.addInvokeBefore(metaMethod, stmt); } }
@SuppressWarnings("unchecked") private SetMultimap<MetaClass, Annotation> getValidationConfig(Collection<MetaClass> validationAnnotations, GeneratorContext context) { final SetMultimap<MetaClass, Annotation> beans = HashMultimap.create(); for (final MetaClass annotation : validationAnnotations) { for (final MetaField field : ClassScanner.getFieldsAnnotatedWith((Class<? extends Annotation>) annotation.asClass(), null, context)) { beans.put(field.getDeclaringClass(), field.getAnnotation((Class<? extends Annotation>) annotation.asClass())); } for (final MetaMethod method : ClassScanner.getMethodsAnnotatedWith((Class<? extends Annotation>) annotation.asClass(), null, context)) { beans.put(method.getDeclaringClass(), method.getAnnotation((Class<? extends Annotation>) annotation.asClass())); } for (final MetaClass type : ClassScanner.getTypesAnnotatedWith((Class<? extends Annotation>) annotation.asClass(), null, context)) { beans.put(type, type.getAnnotation((Class<? extends Annotation>) annotation.asClass())); } } return beans; }
private void generateEventHandlerMethodClasses(final Decorable decorable, final FactoryController controller, final List<Statement> initStmts, final String dataFieldElementsVarName, final Statement fieldsMap) { final Statement instance = Refs.get("instance"); final Map<String, MetaClass> dataFieldTypes = DataFieldCodeDecorator.aggregateDataFieldTypeMap(decorable, decorable.getDecorableDeclaringType()); dataFieldTypes.put("this", decorable.getDecorableDeclaringType()); final MetaClass declaringClass = decorable.getDecorableDeclaringType(); /* Ensure that no @DataFields are handled more than once when used in combination with @SyncNative */ final Set<String> processedNativeHandlers = new HashSet<>(); final Set<String> processedEventHandlers = new HashSet<>(); for (final MetaMethod method : declaringClass.getMethodsAnnotatedWith(EventHandler.class)) { final String[] targetDataFieldNames = method.getAnnotation(EventHandler.class).value(); validateNonEmptyEventHandlerTargets(declaringClass, method, targetDataFieldNames); final MetaClass eventType = assertEventType(declaringClass, method); if (eventType.isAssignableTo(Event.class)) { processGwtDomEvent(controller, initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass, processedNativeHandlers, processedEventHandlers, method, targetDataFieldNames, eventType); } else if (eventType.isAssignableTo(com.google.web.bindery.event.shared.Event.class)) { processGwtWidgetEvent(controller, initStmts, fieldsMap, dataFieldTypes, declaringClass, processedNativeHandlers, processedEventHandlers, method, targetDataFieldNames, eventType); } else { processJsInteropDomEvent(initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass, method, targetDataFieldNames, eventType, controller); } } }
private void generateEventHandlerMethodClasses(final Decorable decorable, final FactoryController controller, final List<Statement> initStmts, final String dataFieldElementsVarName, final Statement fieldsMap) { final Statement instance = Refs.get("instance"); final Map<String, MetaClass> dataFieldTypes = DataFieldCodeDecorator.aggregateDataFieldTypeMap(decorable, decorable.getDecorableDeclaringType()); dataFieldTypes.put("this", decorable.getDecorableDeclaringType()); final MetaClass declaringClass = decorable.getDecorableDeclaringType(); /* Ensure that no @DataFields are handled more than once when used in combination with @SyncNative */ final Set<String> processedNativeHandlers = new HashSet<>(); final Set<String> processedEventHandlers = new HashSet<>(); for (final MetaMethod method : declaringClass.getMethodsAnnotatedWith(EventHandler.class)) { final String[] targetDataFieldNames = method.getAnnotation(EventHandler.class).value(); validateNonEmptyEventHandlerTargets(declaringClass, method, targetDataFieldNames); final MetaClass eventType = assertEventType(declaringClass, method); if (eventType.isAssignableTo(Event.class)) { processGwtDomEvent(controller, initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass, processedNativeHandlers, processedEventHandlers, method, targetDataFieldNames, eventType); } else if (eventType.isAssignableTo(com.google.web.bindery.event.shared.Event.class)) { processGwtWidgetEvent(controller, initStmts, fieldsMap, dataFieldTypes, declaringClass, processedNativeHandlers, processedEventHandlers, method, targetDataFieldNames, eventType); } else { processJsInteropDomEvent(initStmts, dataFieldElementsVarName, fieldsMap, instance, dataFieldTypes, declaringClass, method, targetDataFieldNames, eventType, controller); } } }
final FactoryController controller) { MetaMethod metaMethod = decorable.getAsMethod(); ResourceCheck securedResource = metaMethod.getAnnotation(ResourceCheck.class); String resourceType = securedResource.type(); String resourceAction = securedResource.action();
final FactoryController controller) { MetaMethod metaMethod = decorable.getAsMethod(); ResourceCheck securedResource = metaMethod.getAnnotation(ResourceCheck.class); String resourceType = securedResource.type(); String resourceAction = securedResource.action();
final String key = method.getAnnotation(Key.class).value();
Event.FOCUSEVENTS | Event.GESTUREEVENTS | Event.KEYEVENTS | Event.MOUSEEVENTS | Event.TOUCHEVENTS; if (method.isAnnotationPresent(SinkNative.class)) { eventsToSink = method.getAnnotation(SinkNative.class).value();
final String key = method.getAnnotation(Key.class).value();
Event.FOCUSEVENTS | Event.GESTUREEVENTS | Event.KEYEVENTS | Event.MOUSEEVENTS | Event.TOUCHEVENTS; if (method.isAnnotationPresent(SinkNative.class)) { eventsToSink = method.getAnnotation(SinkNative.class).value();