Search in sources :

Example 1 with SignatureParser

use of org.directwebremoting.impl.SignatureParser in project ma-core-public by infiniteautomation.

the class SpringConfigurator method configure.

/* (non-Javadoc)
     * @see org.directwebremoting.Configurator#configure(org.directwebremoting.Container)
     */
public void configure(Container container) {
    AccessControl accessControl = (AccessControl) container.getBean(AccessControl.class.getName());
    AjaxFilterManager ajaxFilterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
    ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
    CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
    // Configure the creator types
    if (creatorTypes != null) {
        for (Iterator it = creatorTypes.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            String typeName = (String) entry.getKey();
            String className = (String) entry.getValue();
            creatorManager.addCreatorType(typeName, className);
        }
    }
    // Configure the converter types
    if (converterTypes != null) {
        for (Iterator it = converterTypes.entrySet().iterator(); it.hasNext(); ) {
            Map.Entry entry = (Map.Entry) it.next();
            String typeName = (String) entry.getKey();
            String className = (String) entry.getValue();
            converterManager.addConverterType(typeName, className);
        }
    }
    // Configure the creators
    if (creators != null) {
        try {
            for (Iterator it = creators.entrySet().iterator(); it.hasNext(); ) {
                Map.Entry entry = (Map.Entry) it.next();
                String scriptName = (String) entry.getKey();
                CreatorConfig creatorConfig = (CreatorConfig) entry.getValue();
                if (creatorConfig.getCreator() != null) {
                    Creator creator = creatorConfig.getCreator();
                    creatorManager.addCreator(scriptName, creator);
                } else {
                    String creatorName = creatorConfig.getCreatorType();
                    Map params = creatorConfig.getParams();
                    creatorManager.addCreator(scriptName, creatorName, params);
                }
                List excludes = creatorConfig.getExcludes();
                for (Iterator eit = excludes.iterator(); eit.hasNext(); ) {
                    String exclude = (String) eit.next();
                    accessControl.addExcludeRule(scriptName, exclude);
                }
                List includes = creatorConfig.getIncludes();
                for (Iterator iit = includes.iterator(); iit.hasNext(); ) {
                    String include = (String) iit.next();
                    accessControl.addIncludeRule(scriptName, include);
                }
                Properties auth = creatorConfig.getAuth();
                for (Iterator ait = auth.entrySet().iterator(); ait.hasNext(); ) {
                    Map.Entry aentry = (Map.Entry) ait.next();
                    String methodName = (String) aentry.getKey();
                    String role = (String) aentry.getValue();
                    accessControl.addRoleRestriction(scriptName, methodName, role);
                }
                List filters = creatorConfig.getFilters();
                for (Iterator fit = filters.iterator(); fit.hasNext(); ) {
                    Object obj = fit.next();
                    if (obj instanceof String) {
                        String filterName = (String) obj;
                        AjaxFilter filter = (AjaxFilter) 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(Messages.getString("SpringConfigurator.InvalidFilter", scriptName, obj));
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
            throw new IllegalArgumentException(ex.toString());
        }
    }
    // Configure the converters
    if (converters != null) {
        try {
            for (Iterator it = converters.entrySet().iterator(); it.hasNext(); ) {
                Map.Entry entry = (Map.Entry) it.next();
                String match = (String) entry.getKey();
                ConverterConfig converterConfig = (ConverterConfig) entry.getValue();
                Map params = converterConfig.getParams();
                if (converterConfig.getIncludes().size() > 0) {
                    params.put("include", StringUtils.collectionToCommaDelimitedString(converterConfig.getIncludes()));
                }
                if (converterConfig.getExcludes().size() > 0) {
                    params.put("exclude", StringUtils.collectionToCommaDelimitedString(converterConfig.getExcludes()));
                }
                // params.put("force", Boolean.valueOf(converterConfig.isForce()));
                if (StringUtils.hasText(converterConfig.getJavascriptClassName())) {
                    params.put("javascript", converterConfig.getJavascriptClassName());
                }
                converterManager.addConverter(match, converterConfig.getType(), params);
            }
        } catch (Exception ex) {
            throw new IllegalArgumentException(Messages.getString("SpringConfigurator.ConfigureConverterError"));
        }
    }
    // Configure the signatures
    if (StringUtils.hasText(signatures)) {
        SignatureParser sigp = new SignatureParser(converterManager, creatorManager);
        sigp.parse(signatures);
    }
}
Also used : Creator(org.directwebremoting.extend.Creator) Properties(java.util.Properties) AccessControl(org.directwebremoting.extend.AccessControl) AjaxFilterManager(org.directwebremoting.extend.AjaxFilterManager) ConverterManager(org.directwebremoting.extend.ConverterManager) Iterator(java.util.Iterator) List(java.util.List) CreatorManager(org.directwebremoting.extend.CreatorManager) Map(java.util.Map) SignatureParser(org.directwebremoting.impl.SignatureParser) AjaxFilter(org.directwebremoting.AjaxFilter)

Example 2 with SignatureParser

use of org.directwebremoting.impl.SignatureParser in project ma-core-public by infiniteautomation.

the class FluentConfigurator method flush.

/**
 * Takes and configuration that is in progress and calls methods on the
 * various objects to enable that configuration.
 */
private void flush() {
    switch(state) {
        case STATE_INIT_CONVERT:
            // do nothing;
            break;
        case STATE_INIT_CREATE:
            // do nothing;
            break;
        case STATE_ALLOW_CONVERT:
            try {
                if (params == null) {
                    converterManager.addConverter(match, converter, EMPTY_MAP);
                } else {
                    converterManager.addConverter(match, converter, params);
                }
            } catch (Exception e) {
                log.warn("Failed to add converter of type='" + converter + "', match=" + match + ": ", e);
            }
            params = null;
            match = null;
            converter = null;
            break;
        case STATE_ALLOW_CREATE:
            try {
                if (params == null) {
                    creatorManager.addCreator(scriptName, typeName, EMPTY_MAP);
                } else {
                    creatorManager.addCreator(scriptName, typeName, params);
                }
                if (filters != null) {
                    for (Iterator it = filters.iterator(); it.hasNext(); ) {
                        String className = (String) it.next();
                        AjaxFilter filter = (AjaxFilter) LocalUtil.classNewInstance(scriptName, className, AjaxFilter.class);
                        if (filter != null) {
                            LocalUtil.setParams(filter, Collections.EMPTY_MAP, Collections.EMPTY_LIST);
                            ajaxFilterManager.addAjaxFilter(filter, scriptName);
                        }
                    }
                }
            } catch (Exception e) {
                log.warn("Failed to add creator of type='" + typeName + "', scriptName=" + scriptName + ": ", e);
            }
            params = null;
            scriptName = null;
            typeName = null;
            filters = null;
            break;
        case STATE_ALLOW_FILTER:
            try {
                Class impl = LocalUtil.classForName(filterClassName);
                AjaxFilter object = (AjaxFilter) impl.newInstance();
                if (params != null) {
                    LocalUtil.setParams(object, params, Collections.EMPTY_LIST);
                }
                ajaxFilterManager.addAjaxFilter(object);
            } catch (ClassCastException ex) {
                log.error(filterClassName + " does not implement " + AjaxFilter.class.getName(), ex);
            } catch (NoClassDefFoundError ex) {
                log.info("Missing class for filter (class='" + filterClassName + "'). Cause: " + ex.getMessage());
            } catch (Exception ex) {
                log.error("Failed to add filter: class=" + filterClassName, ex);
            }
            params = null;
            filterClassName = null;
            break;
        case STATE_SIGNATURE:
            if (signature != null && signature.length() > 0) {
                SignatureParser sigp = new SignatureParser(converterManager, creatorManager);
                sigp.parse(signature.toString());
            }
            break;
        default:
            break;
    }
}
Also used : Iterator(java.util.Iterator) SignatureParser(org.directwebremoting.impl.SignatureParser) AjaxFilter(org.directwebremoting.AjaxFilter)

Aggregations

Iterator (java.util.Iterator)2 AjaxFilter (org.directwebremoting.AjaxFilter)2 SignatureParser (org.directwebremoting.impl.SignatureParser)2 List (java.util.List)1 Map (java.util.Map)1 Properties (java.util.Properties)1 AccessControl (org.directwebremoting.extend.AccessControl)1 AjaxFilterManager (org.directwebremoting.extend.AjaxFilterManager)1 ConverterManager (org.directwebremoting.extend.ConverterManager)1 Creator (org.directwebremoting.extend.Creator)1 CreatorManager (org.directwebremoting.extend.CreatorManager)1