📄 commandwrapper.java
字号:
/*------------------------------------------------------------------------------Name: CommandWrapper.javaProject: xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE fileComment: Contains the parsed command------------------------------------------------------------------------------*/package org.xmlBlaster.engine.admin;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.util.StringPairTokenizer;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.context.ContextNode;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.engine.ServerScope;import java.util.StringTokenizer;/** * Holds the command partially preparsed, this is an immutable object. * <p /> * Examples what we need to parse: * <pre> * /node/heron/?freeMem * /node/heron/sysprop/?java.vm.version * /node/heron/client/joe/ses17/?queue/callback/maxEntries * </pre> * <p /> * See the <a href="http://www.xmlBlaster.org/xmlBlaster/doc/requirements/admin.commands.html">command requirement</a> * for a detailed description. * @author xmlBlaster@marcelruff.info * @see org.xmlBlaster.test.classtest.CommandWrapperTest * @since 0.79f */public final class CommandWrapper{ private final String ME; private final ServerScope glob; private static Logger log = Logger.getLogger(CommandWrapper.class.getName()); //private final static String PROP_SEPARATOR = "&"; //private final static String XMLBLASTER_PREFIX = "xmlBlaster."; /** The original command (modified to be absolute) */ private final String cmd; private final String myStrippedClusterNodeId; /** The first level -> "node" */ String root = null; /** The second level -> "heron" */ String clusterNodeId = null; /** The third level -> "?freeMem" or "sysprop" or "client" or "topic" */ String third = null; /** The fourth level -> "client/joe" */ String fourth = null; /** The fifth level -> "client/joe/17" or "client/joe/session/17" or "client/joe/?maxSessions" */ String fifth = null; /** The sixth level -> "client/joe/ses17/?queue/callback/maxEntries" */ String sixth = null; /** The rest of the command -> "?java.vm.version"*/ String tail = null; /** "sysprop/?call[auth]=true" this is "call[auth]" */ String key = null; /** "sysprop/?call[auth]=true" this is "true" * for "sysprop/?setSomtthing=true&17" it is "true", "17" */ String[] args = null; /** "true&17" */ private String argsString; /** the qos properties */ //QueryQosData qosData; /** the key (the admin command itself: it could also be seen as the destination of the admin command) */ //QueryKeyData keyData; /** the properties on the right end */ //Map props = new HashMap(); /** * this constructor is currently used for the get * @param glob * @param command the oid must be adjusted inside if the qosData is null. * @throws XmlBlasterException */ public CommandWrapper(ServerScope glob, String command) throws XmlBlasterException { this.glob = glob; this.ME = "CommandWrapper-" + this.glob.getId(); this.myStrippedClusterNodeId = getStrippedClusterNodeId(); if (command == null) throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Your command is null, aborted request"); command = CommandWrapper.stripCommand(glob, command); // string "__cmd:" away if (!command.startsWith("/")) this.cmd = "/node/" + myStrippedClusterNodeId + "/" + command; else this.cmd = command; parse(); } private void parse() throws XmlBlasterException { String prefix = cmd; int questionIndex = cmd.indexOf("?"); int equalsIndex = cmd.indexOf("="); if (questionIndex >= 0 && equalsIndex >= 0 && questionIndex < equalsIndex) { parseKeyValue(); prefix = cmd.substring(0,equalsIndex); if (log.isLoggable(Level.FINE)) log.fine("prefix=" + prefix + " key=" + key + " value=" + args); } StringTokenizer st = new StringTokenizer(prefix, "/"); int ii=1; while (st.hasMoreTokens()) { String token = st.nextToken(); if (log.isLoggable(Level.FINE)) log.fine("Parsing '" + prefix + "' ii=" + ii + " token=" + token); if (ii==1) root = token; else if (ii == 2) clusterNodeId = token; else if (ii == 3) third = token; else if (ii == 4) fourth = token; else if (ii == 5) { if (ContextNode.SESSION_MARKER_TAG.equals(token)) // "session" continue; fifth = token; } else if (ii == 6) sixth = token; else { break; } ii++; } if (root == null || clusterNodeId == null || third == null) { throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".parse", "Your command is invalid, missing levels: '" + cmd + "'"); } if (!"node".equals(root)) { throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".parse", "Your root node is invalid, only <node> is supported, sorry '" + cmd + "' rejected"); } if (!glob.getId().equals(clusterNodeId) && !myStrippedClusterNodeId.equals(clusterNodeId)) { throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".parse", "Query of foreign cluster node '" + clusterNodeId + "' is not implemented, sorry '" + cmd + "' rejected"); } int offset = root.length() + clusterNodeId.length() + third.length() + 4; if (cmd.length() > offset) tail = cmd.substring(offset); } /** * Returns the cluster node id with removed "/" chars (if any where there). * @return "http:myserver:3412" instead of "http://myserver:3412", names like "heron.mycomp.com" are untouched */ public final String getStrippedClusterNodeId() { return org.xmlBlaster.util.ReplaceVariable.replaceAll(glob.getId(), "/", ""); } /** * /node/heron/client/joe/ses17/?callback/queue/maxEntries * @return "node" */ public final String getRoot() { return root; } /** * /node/heron/client/joe/ses17/?queue/callback/maxEntries * @return e.g. "heron" */ public final String getClusterNodeId() { return clusterNodeId; } /** * /node/heron/client/joe/ses17/?queue/callback/maxEntries * @return The third level of a command like "client", "sysprop", "topic", "?uptime" */ public final String getThirdLevel() { return third; } /** * <pre> * /node/heron/client/joe/ses17/?queue/callback/maxEntries * /node/heron/topic/?hello * </pre> * @return "joe" or "?hello" in the above example */ public final String getUserNameLevel() { return fourth; } /** * /node/heron/client/joe/ses17/?queue/callback/maxEntries * @return "ses17" in the above example */ public final String getSessionIdLevel() { return getFifthLevel(); } /** * /node/heron/client/joe/ses17/?queue/callback/maxEntries * @return "ses17" in the above example */ public final String getFifthLevel() { return fifth; } /** * /node/heron/client/joe/ses17/?callback/queue/maxEntries * @return "?queue/callback/maxEntries" in the above example */ public final String getSessionAttrLevel() { return sixth; } /** * @return The fourth level and deeper, e.g. "?java.vm.version", "joe/?sessionList" or null */ public final String getTail() { return tail; } /** * @return If set() is invoked the value behind the "="
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -