private void addController(Module module, MappingNode moduleNode, LinkedEngine moduleEngine, ControllerRef controller) { // Engine engine = new ControllerEngine(module, controller); Set<String> mappingPaths = new HashSet<String>(Arrays.asList(controller.getMappingPaths())); for (String mappingPath : mappingPaths) { List<Mapping> mappings = MappingFactory.parse(mappingPath); // MappingNode target = moduleNode; for (Mapping mapping : mappings) { if (mapping.getDefinition().length() == 0) { continue; } MappingNode temp = target.getChild(mapping.getDefinition()); if (temp == null) { temp = new MappingNode(mapping); target.linkAsChild(temp); } target = temp; } LinkedEngine controllerEngine = new LinkedEngine(moduleEngine, engine, target); target.getMiddleEngines().addEngine(ReqMethod.ALL, controllerEngine); // // actions MethodRef[] actions = controller.getActions(); for (MethodRef action : actions) { addAction(module, controller, action, target, controllerEngine); } } }
/** * 检查整个树的状况,尽可能报告可能存在的问题 * * @param tree * @param parent * @param prefix */ private void check(MappingNode tree, MappingNode parent, String prefix) { MappingNode child = parent.getLeftMostChild(); MappingNode sibling = null; while (child != null) { if (sibling != null) { if (child.compareTo(sibling) == 0) { logger.error("mapping conflicts: '" + child.getMapping().getDefinition() + "' conflicts with '" + sibling.getMapping().getDefinition() + "' in '" + prefix + "'; here is the mapping tree, " + "you can find the conflict in it:\n" + PrinteHelper.list(tree)); throw new IllegalArgumentException("mapping conflicts: '" + child.getMapping().getDefinition() + "' conflicts with '" + sibling.getMapping().getDefinition() + "' in '" + prefix + "'"); } } check(tree, child, prefix + child.getMapping().getDefinition()); sibling = child; child = child.getSibling(); } } }
/** * */ public void destroy() { this.leafEngines.destroy(); MappingNode c = leftMostChild; while (c != null) { c.destroy(); c = c.sibling; } this.middleEngines.destroy(); }
sb.append("<node path=\"").append(prefix + node.getMappingPath()).append("\">"); EngineGroup leaf = node.getLeafEngines(); if (leaf.size() > 0) { for (ReqMethod method : leaf.getAllowedMethods()) { MappingNode child = node.getLeftMostChild(); while (child != null) { printNode(child, prefix + node.getMappingPath(), sb); child = child.getSibling();
private void addAction(Module module, ControllerRef controller, MethodRef action, MappingNode controllerNode, LinkedEngine controllerEngine) { Map<String, Set<ReqMethod>> mappingPaths = action.getMappings(); if (mappingPaths.size() == 0) { return; } Engine actionEngine = new ActionEngine(module, controller.getControllerClass(),// controller.getControllerObject(), action.getMethod()); for (String mappingPath : mappingPaths.keySet()) { List<Mapping> mappings = MappingFactory.parse(mappingPath); MappingNode target = controllerNode; for (Mapping mapping : mappings) { if (mapping.getDefinition().length() == 0) { continue; } MappingNode temp = target.getChild(mapping.getDefinition()); if (temp == null) { temp = new MappingNode(mapping); target.linkAsChild(temp); } target = temp; } // for (ReqMethod method : mappingPaths.get(mappingPath)) { LinkedEngine linkedActionEngine = new LinkedEngine(// controllerEngine, actionEngine, target); target.getLeafEngines().addEngine(method, linkedActionEngine); } } }
testMethod, testUri, curpath.getCtxpath(), curpath.getDispatcher()); ArrayList<MatchResult> matchResults = tree.match(testPath); if (matchResults == null) { final EngineGroup leafEngineGroup = lastMatched.getMappingNode().getLeafEngines(); final LinkedEngine leafEngine = select(leafEngineGroup.getEngines(testMethod), inv .getRequest());
@Override public int hashCode() { return getMapping().hashCode(); }
private MappingNode prepareMappingTree(List<Module> modules) { Mapping rootMapping = new ConstantMapping(""); MappingNode mappingTree = new MappingNode(rootMapping); LinkedEngine rootEngine = new LinkedEngine(null, new RootEngine(instructionExecutor), mappingTree); mappingTree.getMiddleEngines().addEngine(ReqMethod.ALL, rootEngine); TreeBuilder treeBuilder = new TreeBuilder(); treeBuilder.create(mappingTree, modules); return mappingTree; }
last = curNode.getMapping().match(remaining); if (last != null && /*只对常量匹配的作判断*/last.getParameterName() == null) { curNode.ammountOfRegexChildren = countRegexChildren(curNode);
@Override public String toString() { return getMappingPath(); }
@Override public boolean equals(Object obj) { if (!(obj instanceof MappingNode)) { return false; } MappingNode target = (MappingNode) obj; return this.compareTo(target) == 0; }
tab += gap; String path = tab + prefix + node.getMappingPath(); if (path.length() == 0) { path = "ROOT"; EngineGroup leaf = node.getLeafEngines(); if (leaf.size() > 0) { for (ReqMethod method : leaf.getAllowedMethods()) { MappingNode child = node.getLeftMostChild(); while (child != null) { println(child, prefix + node.getMappingPath(), deep + 1, sb); child = child.getSibling();
private void addAction(Module module, ControllerRef controller, MethodRef action, MappingNode controllerNode, LinkedEngine controllerEngine) { Map<String, Set<ReqMethod>> mappingPaths = action.getMappings(); if (mappingPaths.size() == 0) { return; } Engine actionEngine = new ActionEngine(module, controller.getControllerClass(),// controller.getControllerObject(), action.getMethod()); for (String mappingPath : mappingPaths.keySet()) { List<Mapping> mappings = MappingFactory.parse(mappingPath); MappingNode target = controllerNode; for (Mapping mapping : mappings) { if (mapping.getDefinition().length() == 0) { continue; } MappingNode temp = target.getChild(mapping.getDefinition()); if (temp == null) { temp = new MappingNode(mapping); target.linkAsChild(temp); } target = temp; } // for (ReqMethod method : mappingPaths.get(mappingPath)) { LinkedEngine linkedActionEngine = new LinkedEngine(// controllerEngine, actionEngine, target); target.getLeafEngines().addEngine(method, linkedActionEngine); } } }
private boolean innerStart() throws Throwable { final boolean debugEnabled = logger.isDebugEnabled(); final List<MatchResult> matchResults = mappingTree.match(this.path); if (matchResults == null) { final EngineGroup leafEngineGroup = lastMatched.getMappingNode().getLeafEngines(); if (leafEngineGroup.size() == 0) {
@Override public int compareTo(MappingNode target) { return this.getMapping().compareTo(target.getMapping()); }
private MappingNode prepareMappingTree(List<Module> modules) { Mapping rootMapping = new ConstantMapping(""); MappingNode mappingTree = new MappingNode(rootMapping); LinkedEngine rootEngine = new LinkedEngine(null, new RootEngine(instructionExecutor), mappingTree); mappingTree.getMiddleEngines().addEngine(ReqMethod.ALL, rootEngine); TreeBuilder treeBuilder = new TreeBuilder(); treeBuilder.create(mappingTree, modules); return mappingTree; }
last = curNode.getMapping().match(remaining); if (last != null && /*只对常量匹配的作判断*/last.getParameterName() == null) { curNode.ammountOfRegexChildren = countRegexChildren(curNode);
@Override public String getResourceId() { StringBuilder sb = new StringBuilder(255); sb.append(getRequest().getContextPath()); for (MatchResult matchResult : rose.getMatchResults()) { sb.append(matchResult.getMappingNode().getMappingPath()); } return sb.toString(); }
@Override public boolean equals(Object obj) { if (!(obj instanceof MappingNode)) { return false; } MappingNode target = (MappingNode) obj; return this.compareTo(target) == 0; }
private void addModule(final MappingNode rootNode, Module module) { List<Mapping> terms = MappingFactory.parse(module.getMappingPath()); LinkedEngine rootEngine = rootNode.getMiddleEngines().getEngines(ReqMethod.GET)[0]; MappingNode parent = rootNode; for (Mapping mapping : terms) { if (mapping.getDefinition().length() == 0) { continue; } MappingNode temp = parent.getChild(mapping.getDefinition()); if (temp == null) { temp = new MappingNode(mapping); parent.linkAsChild(temp); } parent = temp; } LinkedEngine moduleEngine = new LinkedEngine(rootEngine, new ModuleEngine(module), parent); parent.getMiddleEngines().addEngine(ReqMethod.ALL, moduleEngine); // controllers List<ControllerRef> controllers = module.getControllers(); for (ControllerRef controller : controllers) { addController(module, parent, moduleEngine, controller); } }