Search in sources :

Example 6 with Creator

use of org.directwebremoting.extend.Creator in project ma-core-public by infiniteautomation.

the class DwrXmlConfigurator method processParameters.

/**
 * Collections often have missing information. This helps fill the missing
 * data in.
 * @param javascript The name of the creator
 * @param parent The container of the include and exclude elements.
 * @throws ClassNotFoundException If the type attribute can't be converted into a Class
 */
private void processParameters(String javascript, Element parent) throws ClassNotFoundException {
    NodeList nodes = parent.getElementsByTagName(ELEMENT_PARAMETER);
    for (int i = 0; i < nodes.getLength(); i++) {
        Element include = (Element) nodes.item(i);
        String methodName = include.getAttribute(ATTRIBUTE_METHOD);
        // Try to find the method that we are annotating
        Creator creator = creatorManager.getCreator(javascript);
        Class dest = creator.getType();
        Method method = null;
        Method[] methods = dest.getMethods();
        for (int j = 0; j < methods.length; j++) {
            Method test = methods[j];
            if (test.getName().equals(methodName)) {
                if (method == null) {
                    method = test;
                } else {
                    log.warn("Setting extra type info to overloaded methods may fail with <parameter .../>");
                }
            }
        }
        if (method == null) {
            log.error("Unable to find method called: " + methodName + " on type: " + dest.getName() + " from creator: " + javascript);
            continue;
        }
        String number = include.getAttribute(ATTRIBUTE_NUMBER);
        int paramNo = Integer.parseInt(number);
        String types = include.getAttribute(ATTRIBUTE_TYPE);
        StringTokenizer st = new StringTokenizer(types, ",");
        int j = 0;
        while (st.hasMoreTokens()) {
            String type = st.nextToken();
            Class clazz = LocalUtil.classForName(type.trim());
            TypeHintContext thc = new TypeHintContext(converterManager, method, paramNo).createChildContext(j++);
            converterManager.setExtraTypeInfo(thc, clazz);
        }
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) TypeHintContext(org.directwebremoting.extend.TypeHintContext) NodeList(org.w3c.dom.NodeList) Element(org.w3c.dom.Element) Creator(org.directwebremoting.extend.Creator) Method(java.lang.reflect.Method)

Example 7 with Creator

use of org.directwebremoting.extend.Creator in project jaffa-framework by jaffa-projects.

the class FinderMetaDataHelper method getServiceClass.

/**
 * Looks up dwr.xml for the input serviceName and returns the corresponding class.
 * The servletContext is needed to get a handle on the DWR context.
 */
private static Class getServiceClass(String serviceName, ServletContext servletContext) {
    // Obtain the ServletContext for the 'dwr' servlet. Error out if not found
    String dwrPath = servletContext.getContextPath() + "/dwr";
    ServletContext dwrServletContext = servletContext.getContext(dwrPath);
    if (dwrServletContext == null) {
        String m = "Unable to obtain ServletContext for the '" + dwrPath + "' servlet. The ServiceClass cannot be determined for: " + serviceName;
        log.error(m);
        throw new IllegalArgumentException(m);
    }
    // Check the ServletContext for a List of Containers
    List<Container> containers = (List<Container>) dwrServletContext.getAttribute(ContainerUtil.ATTRIBUTE_CONTAINER_LIST);
    if (containers == null) {
        String m = "Unable to load the dwr.xml configuration from the '" + dwrPath + "' servlet. The ServiceClass cannot be determined for: " + serviceName;
        log.error(m);
        throw new IllegalArgumentException(m);
    }
    // Iterate through the Containers, looking for a 'Creator' for the input service
    Class serviceClass = null;
    for (Container container : containers) {
        CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
        Creator creator = creatorManager.getCreator(serviceName);
        if (creator != null) {
            serviceClass = creator.getType();
            if (log.isDebugEnabled())
                log.debug("The ServiceClass for '" + serviceName + "' is " + serviceClass);
            break;
        }
    }
    // Error out if the service class cannot be determined
    if (serviceClass == null) {
        String m = "ServiceClass not be found for '" + serviceName + "' in dwr.xml";
        log.error(m);
        throw new IllegalArgumentException(m);
    }
    return serviceClass;
}
Also used : Container(org.directwebremoting.Container) ServletContext(javax.servlet.ServletContext) ArrayList(java.util.ArrayList) List(java.util.List) Creator(org.directwebremoting.extend.Creator) CreatorManager(org.directwebremoting.extend.CreatorManager)

Example 8 with Creator

use of org.directwebremoting.extend.Creator in project ma-core-public by infiniteautomation.

the class ContainerUtil method debugConfig.

/**
 * Create a bunch of debug information about a container
 * @param container The container to print debug information about
 */
public static void debugConfig(Container container) {
    if (log.isDebugEnabled()) {
        // Container level debug
        log.debug("Container");
        log.debug("  Type: " + container.getClass().getName());
        Collection beanNames = container.getBeanNames();
        for (Iterator it = beanNames.iterator(); it.hasNext(); ) {
            String name = (String) it.next();
            Object object = container.getBean(name);
            if (object instanceof String) {
                log.debug("  Param: " + name + " = " + object + " (" + object.getClass().getName() + ")");
            } else {
                log.debug("  Bean: " + name + " = " + object + " (" + object.getClass().getName() + ")");
            }
        }
        // AccessControl debugging
        AccessControl accessControl = (AccessControl) container.getBean(AccessControl.class.getName());
        log.debug("AccessControl");
        log.debug("  Type: " + accessControl.getClass().getName());
        // AjaxFilterManager debugging
        AjaxFilterManager ajaxFilterManager = (AjaxFilterManager) container.getBean(AjaxFilterManager.class.getName());
        log.debug("AjaxFilterManager");
        log.debug("  Type: " + ajaxFilterManager.getClass().getName());
        // ConverterManager debugging
        ConverterManager converterManager = (ConverterManager) container.getBean(ConverterManager.class.getName());
        log.debug("ConverterManager");
        log.debug("  Type: " + converterManager.getClass().getName());
        // CreatorManager debugging
        CreatorManager creatorManager = (CreatorManager) container.getBean(CreatorManager.class.getName());
        log.debug("CreatorManager");
        log.debug("  Type: " + creatorManager.getClass().getName());
        Collection creatorNames = creatorManager.getCreatorNames();
        for (Iterator it = creatorNames.iterator(); it.hasNext(); ) {
            String creatorName = (String) it.next();
            Creator creator = creatorManager.getCreator(creatorName);
            log.debug("  Creator: " + creatorName + " = " + creator + " (" + creator.getClass().getName() + ")");
        }
    }
}
Also used : ConverterManager(org.directwebremoting.extend.ConverterManager) DefaultConverterManager(org.directwebremoting.dwrp.DefaultConverterManager) Iterator(java.util.Iterator) Collection(java.util.Collection) Creator(org.directwebremoting.extend.Creator) CreatorManager(org.directwebremoting.extend.CreatorManager) AccessControl(org.directwebremoting.extend.AccessControl) AjaxFilterManager(org.directwebremoting.extend.AjaxFilterManager)

Example 9 with Creator

use of org.directwebremoting.extend.Creator in project ma-core-public by infiniteautomation.

the class SignatureParser method findClass.

/**
 * Lookup a class acording to the import rules
 * @param type The name of the class to find
 * @return The found class, or null if it does not exist
 */
private Class findClass(String type) {
    String itype = type;
    // Handle inner classes
    if (itype.indexOf('.') != -1) {
        log.debug("Inner class detected: " + itype);
        itype = itype.replace('.', '$');
    }
    try {
        String full = (String) classImports.get(itype);
        if (full == null) {
            full = itype;
        }
        return LocalUtil.classForName(full);
    } catch (Exception ex) {
    // log.debug("Trying to find class in package imports");
    }
    for (Iterator it = packageImports.iterator(); it.hasNext(); ) {
        String pkg = (String) it.next();
        String lookup = pkg + '.' + itype;
        try {
            return LocalUtil.classForName(lookup);
        } catch (Exception ex) {
        // log.debug("Not found: " + lookup);
        }
    }
    // So we've failed to find a Java class name. We can also lookup by
    // Javascript name to help the situation where there is a dynamic proxy
    // in the way.
    Creator creator = creatorManager.getCreator(type);
    if (creator != null) {
        return creator.getType();
    }
    log.error("Failed to find class: '" + itype + "' from <signature> block.");
    log.info("- Looked in the following class imports:");
    for (Iterator it = classImports.entrySet().iterator(); it.hasNext(); ) {
        Map.Entry entry = (Map.Entry) it.next();
        log.info("  - " + entry.getKey() + " -> " + entry.getValue());
    }
    log.info("- Looked in the following package imports:");
    for (Iterator it = packageImports.iterator(); it.hasNext(); ) {
        log.info("  - " + it.next());
    }
    return null;
}
Also used : Iterator(java.util.Iterator) Creator(org.directwebremoting.extend.Creator) HashMap(java.util.HashMap) Map(java.util.Map)

Example 10 with Creator

use of org.directwebremoting.extend.Creator in project ma-core-public by infiniteautomation.

the class DefaultCreatorManager method addCreator.

/* (non-Javadoc)
     * @see org.directwebremoting.CreatorManager#addCreator(java.lang.String, org.directwebremoting.Creator)
     */
public void addCreator(String scriptName, Creator creator) throws IllegalArgumentException {
    // Check that we don't have this one already
    Creator other = (Creator) creators.get(scriptName);
    if (other != null) {
        throw new IllegalArgumentException(Messages.getString("DefaultCreatorManager.DuplicateName", scriptName, other.getType().getName(), creator));
    }
    // Check that it can at least tell us what type of thing we will be getting
    try {
        Class test = creator.getType();
        if (test == null) {
            log.error("Creator: '" + creator + "' for " + scriptName + ".js is returning null for type queries.");
        } else {
            log.debug("- adding creator: " + LocalUtil.getShortClassName(creator.getClass()) + " for " + scriptName);
            creators.put(scriptName, creator);
        }
    } catch (NoClassDefFoundError ex) {
        log.error("Missing class for creator '" + creator + "'. Cause: " + ex.getMessage());
    } catch (Exception ex) {
        log.error("Error loading class for creator '" + creator + "'.", ex);
    }
    // DefaultRemoter.execute(Call call)
    if (initApplicationScopeCreatorsAtStartup && creator.getScope().equals(Creator.APPLICATION)) {
        try {
            WebContext webcx = WebContextFactory.get();
            Object object = creator.getInstance();
            webcx.getServletContext().setAttribute(creator.getJavascript(), object);
            log.debug("Created new " + creator.getJavascript() + ", stored in application.");
        } catch (InstantiationException ex) {
            log.warn("Failed to create " + creator.getJavascript(), ex);
            log.debug("Maybe it will succeed when the application is in flight. If so you should probably set initApplicationScopeCreatorsAtStartup=false in web.xml");
        }
    }
}
Also used : WebContext(org.directwebremoting.WebContext) Creator(org.directwebremoting.extend.Creator)

Aggregations

Creator (org.directwebremoting.extend.Creator)14 Iterator (java.util.Iterator)8 Method (java.lang.reflect.Method)6 Map (java.util.Map)4 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 List (java.util.List)3 WebContext (org.directwebremoting.WebContext)3 CreatorManager (org.directwebremoting.extend.CreatorManager)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 AjaxFilter (org.directwebremoting.AjaxFilter)2 AccessControl (org.directwebremoting.extend.AccessControl)2 AjaxFilterManager (org.directwebremoting.extend.AjaxFilterManager)2 ConverterManager (org.directwebremoting.extend.ConverterManager)2 TypeHintContext (org.directwebremoting.extend.TypeHintContext)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1