Package org.jibeframework.core

Examples of org.jibeframework.core.Context


   * @param actualArguments
   * @return
   */
  @SuppressWarnings("unchecked")
  public Object[] resolveArguments(Method method, Object[] actualArguments) {
    Context context = Context.getCurrentContext();
    Map<String, Object> data = (Map<String, Object>) context.getParams().get("data");
    Class<?>[] parameterTypes = method.getParameterTypes();
    MethodParameter[] parameters = new MethodParameter[parameterTypes.length];
    for (int i = 0; i < parameterTypes.length; i++) {
      parameters[i] = new MethodParameter(method, i);
      parameters[i].initParameterNameDiscovery(parameterNameDiscoverer);
    }
    Object[] args = new Object[parameters.length];
    for (int i = 0; i < parameters.length; i++) {
      String name = parameters[i].getParameterName();
      if (data != null && data.containsKey(name)) {
        Object val = data.get(name);
        if (conversionService.canConvert(val.getClass(), parameters[i].getParameterType())) {
          args[i] = conversionService.convert(val, parameters[i].getParameterType());
        } else {
          args[i] = val;
        }
      }
      if (args[i] == null) {
        for (Annotation paramAnn : parameters[i].getParameterAnnotations()) {
          if (data != null && RequestParam.class.isInstance(paramAnn)) {
            RequestParam requestParam = (RequestParam) paramAnn;
            String paramName = requestParam.value();
            boolean required = requestParam.required();
            String defaultValue = requestParam.defaultValue();

            Object val = data.get(paramName);
            if (val == null) {
              if (defaultValue != null) {
                val = defaultValue;
              } else if (required) {
                throw new JibeRuntimeException(paramName
                    + " parameter has to be present in the request");
              }
            }
            if (conversionService.canConvert(val.getClass(), parameters[i].getParameterType())) {
              args[i] = conversionService.convert(val, parameters[i].getParameterType());
            } else {
              args[i] = val;
            }
            break;
          } else if (ConversationAttribute.class.isInstance(paramAnn)) {
            ConversationAttribute convAttrAnn = (ConversationAttribute) paramAnn;
            if (StringUtils.isEmpty(convAttrAnn.value())) {
              for (Object attr : context.getConversation().getAttributes().values()) {
                if (attr != null && parameters[i].getParameterType().isAssignableFrom(attr.getClass())) {
                  args[i] = attr;
                }
              }
            } else {
              args[i] = context.getConversation().getAttribute(convAttrAnn.value());
            }
          }
        }
      }
      Class<?> parameterType = parameters[i].getParameterType();
View Full Code Here


      GroovyObject goo = (GroovyObject) scriptClass.newInstance();
      UIComponent ann = AnnotationUtils.findAnnotation(scriptClass, UIComponent.class);
      if (ann != null) {
        UIComponentMixin.applyMixin(ann.value(), goo, applicationContext);
      }
      Context context = Context.getCurrentContext();
      for (Map.Entry<Field, Object> f : injectionCache.entrySet()) {
        ReflectionUtils.makeAccessible(f.getKey());
        Object dependency = null;
        if (f.getValue() instanceof String) {
          String beanId = (String) f.getValue();
          if (context.containsViewBean(beanId)) {
            dependency = context.getViewBean(beanId);
          } else {
            dependency = applicationContext.getBean(beanId);
          }
        } else {
          dependency = applicationContext.getBean((Class) f.getValue());
View Full Code Here

      servicesStatic = staticModels.get(CoreServices.class.getName());
    } catch (TemplateModelException e) {
      throw new JibeRuntimeException("Services class can not be inserted into template model", e);
    }
    model.put("CoreServices", servicesStatic);
    Context currentContext = Context.getCurrentContext();
    if (currentContext != null) {
      model.put("CurrentContext", currentContext);
    }
    Template t = null;
    try {
View Full Code Here

  @BeforeClass
  public static void setUp() {
    request.getSession().setAttribute("locale", Locale.ENGLISH);
    request.setParameter("_conversationID", "ttt");
    context = new Context();
    context.setServletRequest(request);
    context.setHttpSession(request.getSession());
    context.getParams().put("_conversationID", "ttt");
    RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request));
  }
View Full Code Here

  private Map<Locale, Map<String, String>> clientMessagesCache = new HashMap<Locale, Map<String, String>>();
  private Object lock = new Object();
  private List<MessagesProvider> proxies = new ArrayList<MessagesProvider>();

  public Locale getLocale() {
    Context currentContext = Context.getCurrentContext();
    if (currentContext != null) {
      return currentContext.getLocale();
    }
    return null;
  }
View Full Code Here

  public MethodHolder resolveHolder(String methodId, Object... args) {
    List<MethodHolder> candidates = new ArrayList<MethodHolder>();
    String beanName = StringUtils.substringBeforeLast(methodId, ".");
    String methodName = StringUtils.substringAfterLast(methodId, ".");
    Class<?> userClass = null;
    Context context = Context.getCurrentContext();
    Object bean = null;
    if (context.containsViewBean(beanName)) {
      bean = context.getViewBean(beanName);
      userClass = ((GroovyObject) bean).getMetaClass().getTheClass();
    } else {
      bean = applicationContext.getBean(beanName);
      userClass = ClassUtils.getUserClass(bean.getClass());
    }
View Full Code Here

    this.value = StringUtils.substringAfter((String) value, "icon::");

  }

  protected Object getValue() {
    Context context = Context.getCurrentContext();
    return context.getServletRequest().getContextPath() + "/images/" + value;
  }
View Full Code Here

  @SuppressWarnings("unchecked")
  @Override
  protected Object getValue() {
    Object config = null;
    Context context = Context.getCurrentContext();
    if (context.containsViewBean(extendedId)) {
      GroovyObject bean = (GroovyObject) context.getViewBean(extendedId);
      config = bean.invokeMethod("getComponentDefinition", null);
    } else {
      config = configService.getConfig(extendedId);
    }
    if (Map.class.isAssignableFrom(config.getClass())) {
View Full Code Here

  public boolean applies(MapWrapper wrapper) {
    return wrapper.getConfig().containsKey("jmodel");
  }

  public MapWrapper process(MapWrapper wrapper) {
    Context currentContext = Context.getCurrentContext();
    currentContext.startModelBuilding((String) wrapper.getModelScope());
    if (wrapper.getConfig().containsKey(JVALIDATION)) {
      Map<String, Object> entry = new HashMap<String, Object>();
      entry.put(JVALIDATION, wrapper.getConfig().remove(JVALIDATION));
      currentContext.addModelEntry(FORM_VALIDATION, entry);
    }
    return wrapper;
  }
View Full Code Here

TOP

Related Classes of org.jibeframework.core.Context

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.