dwrxmlconfigurator.java
来自「反向的AJAX。最大的特性是我们成为反向的Ajax。DWR1.x允许你用java」· Java 代码 · 共 652 行 · 第 1/2 页
JAVA
652 行
*/ private static Map createSettingMap(Element parent) { Map params = new HashMap(); // Go through the attributes in the allower element, adding to the param map NamedNodeMap attrs = parent.getAttributes(); for (int i = 0; i < attrs.getLength(); i++) { Node node = attrs.item(i); String name = node.getNodeName(); String value = node.getNodeValue(); params.put(name, value); } // Go through the param elements in the allower element, adding to the param map NodeList locNodes = parent.getElementsByTagName(ELEMENT_PARAM); for (int i = 0; i < locNodes.getLength(); i++) { // Since this comes from getElementsByTagName we can assume that // all the nodes are elements. Element element = (Element) locNodes.item(i); // But getElementsByTagName(ELEMENT_PARAM) includes param nodes that // are nested down inside filters, so we need to check that the // parent node is 'parent'. $&*?! DOM! if (element.getParentNode() != parent) { continue; } String name = element.getAttribute(ATTRIBUTE_NAME); if (name != null) { String value = element.getAttribute(ATTRIBUTE_VALUE); if (value == null || value.length() == 0) { StringBuffer buffer = new StringBuffer(); NodeList textNodes = element.getChildNodes(); for (int j = 0; j < textNodes.getLength(); j++) { buffer.append(textNodes.item(j).getNodeValue()); } value = buffer.toString(); } params.put(name, value); } } return params; } /** * Process the include and exclude elements, passing them on to the creator * manager. * @param javascript The name of the creator * @param parent The container of the include and exclude elements. */ private void processPermissions(String javascript, Element parent) { NodeList incNodes = parent.getElementsByTagName(ELEMENT_INCLUDE); for (int i = 0; i < incNodes.getLength(); i++) { Element include = (Element) incNodes.item(i); String method = include.getAttribute(ATTRIBUTE_METHOD); accessControl.addIncludeRule(javascript, method); } NodeList excNodes = parent.getElementsByTagName(ELEMENT_EXCLUDE); for (int i = 0; i < excNodes.getLength(); i++) { Element include = (Element) excNodes.item(i); String method = include.getAttribute(ATTRIBUTE_METHOD); accessControl.addExcludeRule(javascript, method); } } /** * J2EE role based method level security added here. * @param javascript The name of the creator * @param parent The container of the include and exclude elements. */ private void processAuth(String javascript, Element parent) { NodeList nodes = parent.getElementsByTagName(ELEMENT_AUTH); for (int i = 0; i < nodes.getLength(); i++) { Element include = (Element) nodes.item(i); String method = include.getAttribute(ATTRIBUTE_METHOD); String role = include.getAttribute(ATTRIBUTE_ROLE); accessControl.addRoleRestriction(javascript, method, role); } } /** * J2EE role based method level security added here. * @param javascript The name of the creator * @param parent The container of the include and exclude elements. */ private void processAjaxFilters(String javascript, Element parent) { NodeList nodes = parent.getElementsByTagName(ELEMENT_FILTER); for (int i = 0; i < nodes.getLength(); i++) { Element include = (Element) nodes.item(i); String type = include.getAttribute(ATTRIBUTE_CLASS); AjaxFilter filter = (AjaxFilter) LocalUtil.classNewInstance(javascript, type, AjaxFilter.class); if (filter != null) { LocalUtil.setParams(filter, createSettingMap(include), ignore); ajaxFilterManager.addAjaxFilter(filter, javascript); } } } /** * Parse and extra type info from method signatures * @param element The element to read */ private void loadSignature(Element element) { StringBuffer sigtext = new StringBuffer(); // This coagulates text nodes, not sure if we need to do this? element.normalize(); NodeList nodes = element.getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { Node node = nodes.item(i); short type = node.getNodeType(); if (type != Node.TEXT_NODE && type != Node.CDATA_SECTION_NODE) { log.warn("Ignoring illegal node type: " + type); continue; } sigtext.append(node.getNodeValue()); } SignatureParser sigp = new SignatureParser(converterManager, creatorManager); sigp.parse(sigtext.toString()); } /** * 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); } } } /* (non-Javadoc) * @see java.lang.Object#toString() */ public String toString() { if (servletResourceName != null) { return "DwrXmlConfigurator[ServletResource:" + servletResourceName + "]"; } else { return "DwrXmlConfigurator[ClassResource:" + classResourceName + "]"; } } /** * The parsed document */ private Document document; /** * The properties that we don't warn about if they don't exist. */ private static List ignore = Arrays.asList(new String[] { "class", }); /** * The log stream */ public static final Logger log = Logger.getLogger(DwrXmlConfigurator.class); /** * What AjaxFilters apply to which Ajax calls? */ private AjaxFilterManager ajaxFilterManager = null; /** * The converter manager that decides how parameters are converted */ private ConverterManager converterManager = null; /** * The DefaultCreatorManager to which we delegate creation of new objects. */ private CreatorManager creatorManager = null; /** * The security manager */ private AccessControl accessControl = null; /** * For debug purposes, the classResourceName that we were configured with. * Either this or {@link #servletResourceName} will be null */ private String classResourceName; /** * For debug purposes, the servletResourceName that we were configured with * Either this or {@link #classResourceName} will be null */ private String servletResourceName; /* * The element names */ private static final String ELEMENT_INIT = "init"; private static final String ELEMENT_ALLOW = "allow"; private static final String ELEMENT_CREATE = "create"; private static final String ELEMENT_CONVERT = "convert"; private static final String ELEMENT_PARAM = "param"; private static final String ELEMENT_INCLUDE = "include"; private static final String ELEMENT_EXCLUDE = "exclude"; private static final String ELEMENT_PARAMETER = "parameter"; private static final String ELEMENT_AUTH = "auth"; private static final String ELEMENT_SIGNATURES = "signatures"; private static final String ELEMENT_FILTER = "filter"; /* * The attribute names */ private static final String ATTRIBUTE_ID = "id"; private static final String ATTRIBUTE_CLASS = "class"; private static final String ATTRIBUTE_CONVERTER = "converter"; private static final String ATTRIBUTE_MATCH = "match"; private static final String ATTRIBUTE_JAVASCRIPT = "javascript"; private static final String ATTRIBUTE_CREATOR = "creator"; private static final String ATTRIBUTE_NAME = "name"; private static final String ATTRIBUTE_VALUE = "value"; private static final String ATTRIBUTE_METHOD = "method"; private static final String ATTRIBUTE_ROLE = "role"; private static final String ATTRIBUTE_NUMBER = "number"; private static final String ATTRIBUTE_TYPE = "type";}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?