Package org.directwebremoting.extend

Examples of org.directwebremoting.extend.ConverterManager


     */
    public void configure(Container container)
    {
        AccessControl accessControl = container.getBean(AccessControl.class);
        AjaxFilterManager ajaxFilterManager = container.getBean(AjaxFilterManager.class);
        ConverterManager converterManager = container.getBean(ConverterManager.class);
        CreatorManager creatorManager = container.getBean(CreatorManager.class);

        // Configure the global filters
        if (null != filters)
        {
            for (AjaxFilter filter : filters)
            {
                ajaxFilterManager.addAjaxFilter(filter);
            }
        }

        // Configure the creator types
        if (creatorTypes != null)
        {
            for (Entry<String, String> entry : creatorTypes.entrySet())
            {
                String typeName = entry.getKey();
                String className = entry.getValue();

                creatorManager.addCreatorType(typeName, className);
            }
        }

        // Configure the converter types
        if (converterTypes != null)
        {
            for (Entry<String, String> entry : converterTypes.entrySet())
            {
                String typeName = entry.getKey();
                String className = entry.getValue();

                converterManager.addConverterType(typeName, className);
            }
        }

        // Configure the creators
        if (creators != null)
        {
            try
            {
                for (Entry<String, CreatorConfig> entry : creators.entrySet())
                {
                    String scriptName = entry.getKey();
                    CreatorConfig creatorConfig = entry.getValue();

                    if (creatorConfig.getCreator() != null)
                    {
                        Creator creator = creatorConfig.getCreator();
                        creatorManager.addCreator(creator);
                    }
                    else
                    {
                        String creatorName = creatorConfig.getCreatorType();
                        Map<String, String> params = creatorConfig.getParams();
                        creatorManager.addCreator(creatorName, params);
                    }

                    for (String exclude : creatorConfig.getExcludes())
                    {
                        accessControl.addExcludeRule(scriptName, exclude);
                    }

                    for (String include : creatorConfig.getIncludes())
                    {
                        accessControl.addIncludeRule(scriptName, include);
                    }

                    Map<String, List<String>> auth = creatorConfig.getAuth();
                    for (Entry<String, List<String>> constraint : auth.entrySet())
                    {
                        for (String role : constraint.getValue())
                        {
                            accessControl.addRoleRestriction(scriptName, constraint.getKey(), role);
                        }
                    }

                    for (Object obj : creatorConfig.getFilters())
                    {
                        if (obj instanceof String)
                        {
                            String filterName = (String) obj;

                            AjaxFilter filter = LocalUtil.classNewInstance(filterName, filterName, AjaxFilter.class);
                            if (filter != null)
                            {
                                ajaxFilterManager.addAjaxFilter(filter, scriptName);
                            }
                        }
                        else if (obj instanceof AjaxFilter)
                        {
                            AjaxFilter filter = (AjaxFilter) obj;
                            ajaxFilterManager.addAjaxFilter(filter, scriptName);
                        }
                        else
                        {
                            throw new IllegalArgumentException("An invalid filter is added for script '" + scriptName + "'. It should either be the class name of the filter or an instantiated AjaxFilter, but was: '" + obj + "'.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw new IllegalArgumentException(ex);
            }
        }

        // Configure the converters
        if (converters != null)
        {
            try
            {
                for (Entry<String, ConverterConfig> entry : converters.entrySet())
                {
                    String match = entry.getKey();
                    ConverterConfig converterConfig = entry.getValue();

                    Map<String, String> params = converterConfig.getParams();
                    if (!converterConfig.getIncludes().isEmpty())
                    {
                        params.put("include", StringUtils.collectionToCommaDelimitedString(converterConfig.getIncludes()));
                    }

                    if (!converterConfig.getExcludes().isEmpty())
                    {
                        params.put("exclude", StringUtils.collectionToCommaDelimitedString(converterConfig.getExcludes()));
                    }

                    if (StringUtils.hasText(converterConfig.getJavascriptClassName()))
                    {
                        params.put("javascript", converterConfig.getJavascriptClassName());
                    }

                    if (converterConfig.isForce())
                    {
                        params.put("force", String.valueOf(converterConfig.isForce()));
                    }

                    String type = converterConfig.getType();
                    if(type.startsWith("preconfigured"))
                    {
                        converterManager.addConverter(match, (Converter) container.getBean(type.substring(14)));
                    }
                    else
                    {
                        converterManager.addConverter(match, type, params);
                    }
                }
            }
            catch (Exception ex)
            {
View Full Code Here


     * @param data The published data
     */
    public void publish(String topic, RealRawData data)
    {
        WebContext webContext = WebContextFactory.get();
        ConverterManager converterManager = webContext.getContainer().getBean(ConverterManager.class);
        Hub hub = HubFactory.get();

        MessageEvent event = new DefaultMessageEvent(hub, converterManager, data);
        hub.publish(topic, event);
    }
View Full Code Here

    {
        Class<? extends Converter> converter = convertAnn.converter();
        String converterClass = converter.getName();
        Map<String, String> params = getParamsMap(convertAnn.params());

        ConverterManager converterManager = container.getBean(ConverterManager.class);
        String converterName = converterClass.replace(".", "_");
        converterManager.addConverterType(converterName, converterClass);

        if (BeanConverter.class.isAssignableFrom(converter))
        {
            StringBuilder properties = new StringBuilder();
            Class<?> superClazz = clazz;
            while (superClazz != Object.class)
            {
                for (Field field : superClazz.getDeclaredFields())
                {
                    if (field.getAnnotation(RemoteProperty.class) != null)
                    {
                        properties.append(',').append(field.getName());
                    }
                }

                for (Method method : superClazz.getMethods())
                {
                    if (method.getAnnotation(RemoteProperty.class) != null)
                    {
                        String name = method.getName();
                        if (name.startsWith(METHOD_PREFIX_GET) || name.startsWith(METHOD_PREFIX_IS))
                        {
                            if (name.startsWith(METHOD_PREFIX_GET))
                            {
                                name = name.substring(3);
                            }
                            else
                            {
                                name = name.substring(2);
                            }
                            name = Introspector.decapitalize(name);
                            properties.append(',').append(name);
                        }
                    }
                }
                superClazz = superClazz.getSuperclass();
            }

            if (properties.length() > 0)
            {
                properties.deleteCharAt(0);
                params.put("include", properties.toString());
            }
        }

        converterManager.addConverter(clazz.getName(), converterName, params);
    }
View Full Code Here

    @SuppressWarnings("unchecked")
    public static <T> void executeCallback(String key, RealRawData data) throws ConversionException
    {
        WebContext webContext = WebContextFactory.get();
        ScriptSession session = webContext.getScriptSession();
        ConverterManager converterManager = webContext.getContainer().getBean(ConverterManager.class);

        Map<String, Class<T>> typeMap = (Map<String, Class<T>>) session.getAttribute(KEY_TYPE);
        Class<T> type = typeMap.remove(key);
        session.removeAttribute(KEY_TYPE);
        session.setAttribute(KEY_TYPE, typeMap);

        try
        {
            Method method = Callback.class.getMethod("dataReturned", type);

            Property property = new ParameterProperty(new MethodDeclaration(method), 0);
            InboundVariable iv = data.getInboundVariable();
            Object callbackData  = converterManager.convertInbound(type, iv, property);

            Map<String, Callback<T>> callbackMap = (Map<String, Callback<T>>) session.getAttribute(KEY_TYPE);
            Callback<T> callback = callbackMap.remove(key);
            session.removeAttribute(KEY_TYPE);
            session.setAttribute(KEY_CALLBACK, callbackMap);
View Full Code Here

    public int doEndTag() throws JspException
    {
        try
        {
            Container container = ServerContextFactory.get().getContainer();
            ConverterManager converterManager = container.getBean(ConverterManager.class);

            HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
            HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
            WebContextFactory.WebContextBuilder contextBuilder = container.getBean(WebContextFactory.WebContextBuilder.class);
            contextBuilder.engageThread(container, request, response);
View Full Code Here

                        {
                            bayeuxHandler.setRemoter(remoter);
                        }
                    }

                    ConverterManager c = container.getBean(ConverterManager.class);
                    if (c != null)
                    {
                        converterManager = c;
                        if (bayeuxHandler != null)
                        {
View Full Code Here

            AjaxFilterManager ajaxFilterManager = container.getBean(AjaxFilterManager.class);
            Loggers.STARTUP.debug("AjaxFilterManager");
            Loggers.STARTUP.debug("  Type: " + ajaxFilterManager.getClass().getName());

            // ConverterManager debugging
            ConverterManager converterManager = container.getBean(ConverterManager.class);
            Loggers.STARTUP.debug("ConverterManager");
            Loggers.STARTUP.debug("  Type: " + converterManager.getClass().getName());

            // CreatorManager debugging
            CreatorManager creatorManager = container.getBean(CreatorManager.class);
            Loggers.STARTUP.debug("CreatorManager");
            Loggers.STARTUP.debug("  Type: " + creatorManager.getClass().getName());
View Full Code Here

TOP

Related Classes of org.directwebremoting.extend.ConverterManager

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.