hostcontroller.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 699 行 · 第 1/2 页
JAVA
699 行
} if (_regexp != null) { // server/0523 Matcher matcher = _regexp.matcher(name); if (matcher.matches()) { Path rootDirectory = calculateRoot(matcher); if (getRootDirectory().equals(rootDirectory)) return true; } } return false; } private Path calculateRoot(Matcher matcher) { // XXX: duplicates HostRegexp Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(getParentClassLoader()); if (_rootDirectoryPattern == null) { // server/129p return Vfs.lookup(); } int length = matcher.end() - matcher.start(); ArrayList<String> vars = new ArrayList<String>(); HashMap<String,Object> varMap = new HashMap<String,Object>(); for (int j = 0; j <= matcher.groupCount(); j++) { vars.add(matcher.group(j)); varMap.put("host" + j, matcher.group(j)); } varMap.put("regexp", vars); varMap.put("host", new TestVar(matcher.group(0), vars)); Path path = PathBuilder.lookupPath(_rootDirectoryPattern, varMap); return path; } catch (Exception e) { log.log(Level.FINE, e.toString(), e); // XXX: not quite right return Vfs.lookup(_rootDirectoryPattern); } finally { thread.setContextClassLoader(oldLoader); } } /** * Merges two entries. */ protected HostController merge(HostController newController) { if (getConfig() != null && getConfig().getRegexp() != null) return newController; else if (newController.getConfig() != null && newController.getConfig().getRegexp() != null) return this; else { Thread thread = Thread.currentThread(); ClassLoader oldLoader = thread.getContextClassLoader(); try { thread.setContextClassLoader(getParentClassLoader()); HostController mergedController = new HostController(newController.getHostName(), getRootDirectory(), _container); mergedController.mergeController(this); mergedController.mergeController(newController); if (! isNameMatch(newController.getHostName()) && ! newController.isNameMatch(getHostName())) { ConfigException e; e = new ConfigException(L.l("Illegal merge of {0} and {1}. Both hosts have the same root-directory '{2}'.", getHostName(), newController.getHostName(), getRootDirectory())); log.warning(e.getMessage()); log.log(Level.FINEST, e.toString(), e); mergedController.setConfigException(e); } return mergedController; } catch (Throwable e) { log.log(Level.FINE, e.toString(), e); return null; } finally { thread.setContextClassLoader(oldLoader); } } } /** * Merges with the old controller. */ protected void mergeController(DeployController oldControllerV) { super.mergeController(oldControllerV); HostController oldController = (HostController) oldControllerV; _entryHostAliases.addAll(oldController._entryHostAliases); if (! oldController.getHostName().equals("")) _entryHostAliases.add(oldController.getHostName()); _entryHostAliasRegexps.addAll(oldController._entryHostAliasRegexps); _hostAliases.addAll(oldController._hostAliases); _hostAliasRegexps.addAll(oldController._hostAliasRegexps); if (_regexp == null) { _regexp = oldController._regexp; _rootDirectoryPattern = oldController._rootDirectoryPattern; } } /** * Creates a new instance of the host object. */ protected Host instantiateDeployInstance() { return new Host(_container, this, _hostName); } /** * Creates the host. */ protected void configureInstance(Host host) throws Throwable { _hostAliases.clear(); _hostAliases.addAll(_entryHostAliases); WebBeansContainer webBeans = WebBeansContainer.create(); //webBeans.addSingleton(_hostVar, "host", Standard.class); for (Map.Entry<String,Object> entry : getVariableMap().entrySet()) { Object value = entry.getValue(); if (value != null) webBeans.addSingleton(value, entry.getKey(), Standard.class); } // getVariableMap().put("host-root", getRootDirectory()); if (_container != null) { for (EarConfig config : _container.getEarDefaultList()) host.addEarDefault(config); for (WebAppConfig config : _container.getWebAppDefaultList()) host.addWebAppDefault(config); } super.configureInstance(host); } protected void extendJMXContext(Map<String,String> context) { context.put("Host", getMBeanId()); } /** * Returns the appropriate log for debugging. */ protected Logger getLog() { return log; } /** * Returns equality. */ public boolean equals(Object o) { if (! (o instanceof HostController)) return false; HostController entry = (HostController) o; return _hostName.equals(entry._hostName); } /** * Returns a printable view. */ public String toString() { return "HostController[" + getName() + "]"; } /** * EL variables for the host. */ public class Var { public String getName() { return HostController.this.getName(); } public String getHostName() { return HostController.this.getHostName(); } public String getUrl() { Host host = getDeployInstance(); if (host != null) return host.getURL(); else if (_hostName.equals("")) return ""; else if (_hostName.startsWith("http:") || _hostName.startsWith("https:")) return _hostName; else return "http://" + _hostName; } public ArrayList getRegexp() { return (ArrayList) getVariableMap().get("regexp"); } public Path getRoot() { Host host = getDeployInstance(); if (host != null) return host.getRootDirectory(); else return HostController.this.getRootDirectory(); } /** * @deprecated */ public Path getRootDir() { return getRoot(); } /** * @deprecated */ public Path getRootDirectory() { return getRoot(); } public Path getDocumentDirectory() { Host host = getDeployInstance(); if (host != null) return host.getDocumentDirectory(); else return null; } public Path getDocDir() { return getDocumentDirectory(); } public Path getWarDirectory() { Host host = getDeployInstance(); if (host != null) return host.getWarDir(); else return null; } public Path getWarDir() { return getWarDirectory(); } public Path getWarExpandDirectory() { Host host = getDeployInstance(); if (host != null) return host.getWarExpandDir(); else return null; } public Path getWarExpandDir() { return getWarExpandDirectory(); } public String toString() { return "Host[" + getId() + "]"; } } /** * EL variables for the host, when testing for regexp identity . */ public class TestVar { private String _name; private ArrayList<String> _regexp; TestVar(String name, ArrayList<String> regexp) { _name = name; _regexp = regexp; } public String getName() { return _name; } public String getHostName() { return _name; } public ArrayList<String> getRegexp() { // server/13t0 return _regexp; } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?