⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 corehandler.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*------------------------------------------------------------------------------Name:      CoreHandler.javaProject:   xmlBlaster.orgCopyright: xmlBlaster.org, see xmlBlaster-LICENSE fileComment:   Implementation for administrative property access------------------------------------------------------------------------------*/package org.xmlBlaster.engine.admin.intern;import java.util.logging.Logger;import java.util.logging.Level;import org.xmlBlaster.util.plugin.I_Plugin;import org.xmlBlaster.util.MsgUnit;import org.xmlBlaster.util.SessionName;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.context.ContextNode;import org.xmlBlaster.util.def.ErrorCode;import org.xmlBlaster.engine.ServerScope;import org.xmlBlaster.engine.TopicHandler;import org.xmlBlaster.engine.qos.AddressServer;import org.xmlBlaster.engine.admin.I_CommandHandler;import org.xmlBlaster.engine.admin.CommandManager;import org.xmlBlaster.engine.admin.CommandWrapper;import org.xmlBlaster.engine.admin.I_AdminNode;import org.xmlBlaster.engine.admin.I_AdminTopic;import org.xmlBlaster.engine.admin.I_AdminSubscription;import org.xmlBlaster.engine.admin.I_AdminSubject;import org.xmlBlaster.engine.admin.I_AdminSession;import org.xmlBlaster.engine.SubscriptionInfo;import java.lang.reflect.*;import java.beans.IntrospectionException;import java.beans.PropertyDescriptor;/** * Implementation of administrative access to xmlBlaster internal java objects.  * @author xmlBlaster@marcelruff.info  * @since 0.79f */final public class CoreHandler implements I_CommandHandler, I_Plugin {   private String ME = "CoreHandler";   private ServerScope glob = null;   private static Logger log = Logger.getLogger(CoreHandler.class.getName());   private CommandManager commandManager = null;   private String listSeparator = "\n";   /**    * This is called after creation of the plugin.     * @param glob The Global handle of this xmlBlaster server instance.    * @param commandManager My big brother taking care of me    */   public void initialize(ServerScope glob, CommandManager commandManager) {      this.glob = glob;      this.commandManager = commandManager;      this.ME = "CoreHandler" + this.glob.getLogPrefixDashed();      this.listSeparator = this.glob.getProperty().get("xmlBlaster/admin/listSeparator", this.listSeparator);      this.commandManager.register("DEFAULT", this);      this.commandManager.register(ContextNode.SUBJECT_MARKER_TAG, this); // "client"      this.commandManager.register(ContextNode.SUBSCRIPTION_MARKER_TAG, this); // "subscription"      // "topic" was handled by MsgHandler.java, changed 2006-02-028, marcel      this.commandManager.register(ContextNode.TOPIC_MARKER_TAG, this); // "topic"      log.fine("Core administration plugin is initialized");   }   /**    * This method is called by the PluginManager (enforced by I_Plugin).     * @see org.xmlBlaster.util.plugin.I_Plugin#init(org.xmlBlaster.util.Global,org.xmlBlaster.util.plugin.PluginInfo)    */   public void init(org.xmlBlaster.util.Global glob, org.xmlBlaster.util.plugin.PluginInfo pluginInfo) {   }   /**    * Return plugin type for Plugin loader    * @return "CoreHandler"    */   public String getType() {      return "CoreHandler";   }   /**    * Return plugin version for Plugin loader    * @return "1.0"    */   public String getVersion() {      return "1.0";   }   /**    * Get a human readable name of this filter implementation    * @return "CoreHandler"    */   public String getName() {      return "CoreHandler";   }   private MsgUnit[] doGetInvoke(CommandWrapper cmd, String property, Object impl, Class clazz)       throws XmlBlasterException {            Method method = null;      try {         Class[] argClasses = new Class[0];         method = clazz.getMethod(property, argClasses);         //This seems to need both set() AND get():         //PropertyDescriptor desc = new PropertyDescriptor(property, clazz); // if property=value it looks for setValue() or getValue()         //method = desc.getReadMethod();      }      catch (Exception e) { // try operations like 'addProperty' without set/get prefix         Method[] m = clazz.getMethods();         for (int i=0; m!=null&&i<m.length;i++) {            if (m[i].getName().equals(property)) {               method = m[i];               break;            }         }         if (method == null) {            for (int i=0; m!=null&&i<m.length;i++) {               String mm = m[i].getName();               if (mm.startsWith("get")) {                  mm = mm.substring(3);                  String first = ""+mm.charAt(0);                  mm = first.toLowerCase() + mm.substring(1);               }                                 if (mm.equals(property)) {                  method = m[i];                  break;               }            }         }         if (method == null) {            log.warning("Invoke for property '" + property + "' on class=" + clazz + " on object=" + impl.getClass() + " failed: No such method found");            throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Invoke for property '" + property + "' on class=" + clazz + " on object=" + impl.getClass() + " failed: No such method found");         }      }      Object[] argValues = convertMethodArguments(method.getParameterTypes(), cmd.getArgs());      try {         Object tmp = method.invoke (impl, argValues);         log.fine("Successful invoked set method '" + property + "'");                  //Object tmp = getInvoke(property, impl, clazz, cmd.getQueryKeyData(), cmd.getQueryQosData());         String ret = "";         if (tmp instanceof String[]) {            String[] tmpArr = (String[])tmp;            for (int i=0; i<tmpArr.length; i++) {               ret += tmpArr[i];               if (i < tmpArr.length-1)                  ret += this.listSeparator; // "\n";            }         }         else {            ret = ""+ tmp;         }         if (log.isLoggable(Level.FINE)) log.fine("Retrieved " + cmd.getCommand());         if (log.isLoggable(Level.FINEST)) log.finest("Retrieved " + cmd.getCommand() + "=" + ret);            MsgUnit[] msgs = null;         if (tmp instanceof MsgUnit[]) msgs = (MsgUnit[])tmp;         else {            msgs = new MsgUnit[1];            // msgs[0] = new MsgUnit(cmd.getQueryKeyData().toXml(), ret.getBytes(), "text/plain");            msgs[0] = new MsgUnit("<key oid='__cmd:"+cmd.getCommand()+"'/>", ret.getBytes(), "<qos/>");         }         return msgs;              } catch (Exception e) {         if (e.getCause() != null && e.getCause() instanceof XmlBlasterException) {            log.warning("Invoke for property '" + property + "' on class=" + clazz + " on object=" + impl.getClass() + " failed:" + ((XmlBlasterException)e.getCause()).getMessage());            throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Invoke for property '" + property + "' on class=" + clazz + " on object=" + impl.getClass() + " failed", e.getCause());         }         String str = e.toString();         if (e.getCause() != null) str = e.getCause().toString();         log.warning("Invoke for property '" + property + "' on class=" + clazz + " on object=" + impl.getClass() + " failed: No such method found:" + str);         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Invoke for property '" + property + "' on class=" + clazz + " on object=" + impl.getClass() + " failed: No such method found", e);      }   }   /**    * @see org.xmlBlaster.engine.admin.I_CommandHandler#get(String,CommandWrapper)    */   public MsgUnit[] get(AddressServer addressServer, String sessionId, CommandWrapper cmd) throws XmlBlasterException {      if (cmd == null)         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Please pass a command which is not null");      String registerKey = cmd.getThirdLevel();      if (registerKey == null || registerKey.length() < 2)         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Please pass a command which has a valid property added, '" + cmd.getCommand() + "' is invalid, aborted request.");      if (registerKey.startsWith("?")) {         // for example "/node/heron/?freeMem"         return doGetInvoke(cmd, registerKey.substring(1), glob.getRequestBroker(), I_AdminNode.class);       }      if (registerKey.equals(ContextNode.SUBJECT_MARKER_TAG) || registerKey.equals("DEFAULT")) {  // "client"         String loginName = cmd.getUserNameLevel();         if (loginName == null || loginName.length() < 1 || loginName.startsWith("?"))            throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Please pass a command which has a valid client name in '" + cmd.getCommand() + "' with '" + loginName + "' is invalid");         I_AdminSubject subjectInfo = glob.getAuthenticate().getSubjectInfoByName(new SessionName(glob, loginName));         if (subjectInfo == null)            throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Please pass a command which has a valid client name in '" + cmd.getCommand() + "' client '" + loginName + "' is unknown");         String pubSessionId = cmd.getSessionIdLevel();         if (pubSessionId == null || pubSessionId.length() < 1)            throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Please pass a command which has a valid public session ID in '" + cmd.getCommand() + "'.");         if (pubSessionId.startsWith("?")) {            // for example "/node/heron/joe/?uptime"

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -