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

📄 corehandler.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
         else if (classes[i] == Long.TYPE || classes[i] == Long.class) {            try {               ret[i] = Long.valueOf(args[i]);              }            catch (Throwable ex) {               throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".convertMethodArguments", "wrong type of argument nr. '" + (i+1) + "' should be of type '" + classes[i].getName() + "' but its value is '" + args[i] + "'");            }         }                  else if (classes[i] == Float.TYPE || classes[i] == Float.class) {            try {               ret[i] = Float.valueOf(args[i]);              }            catch (Throwable ex) {               throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".convertMethodArguments", "wrong type of argument nr. '" + (i+1) + "' should be of type '" + classes[i].getName() + "' but its value is '" + args[i] + "'");            }         }                  else if (classes[i] == Double.TYPE || classes[i] == Double.class) {            try {               ret[i] = Double.valueOf(args[i]);              }            catch (Throwable ex) {               throw new XmlBlasterException(this.glob, ErrorCode.USER_ILLEGALARGUMENT, ME + ".convertMethodArguments", "wrong type of argument nr. '" + (i+1) + "' should be of type '" + classes[i].getName() + "' but its value is '" + args[i] + "'");            }         }      }      return ret;         }   /**    * @param property e.g. "uptime", the method "setUptime()" will be called    * @param aClass e.g. I_AdminSubject.class    * @param argValues = new Object[1]; argValues[0] = "Hi"    */   private Object setInvoke(String property, Object impl, Class aClass, String[] argValuesAsStrings) throws XmlBlasterException {      try {         Method method = null;         try {            PropertyDescriptor desc = new PropertyDescriptor(property, aClass); // if property=value it looks for setValue() or getValue()            method = desc.getWriteMethod();         }         catch (IntrospectionException e) { // try operations like 'addProperty' without set/get prefix         }         if (method == null) {            Method[] m = aClass.getMethods();            for (int i=0; m!=null&&i<m.length;i++)               if (m[i].getName().equals(property))                  method = m[i];            if (method == null) {               log.warning("Invoke for property '" + property + "' on class=" + aClass + " on object=" + impl.getClass() + " failed: No such method found");               throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Invoke for property '" + property + "' on class=" + aClass + " on object=" + impl.getClass() + " failed: No such method found");            }         }         // for property '?exit=-1' the setExit is not found as no getExit exist, so try again         if (argValuesAsStrings.length > 0 && "exit".equals(property)) {            method = aClass.getMethod("setExit", new Class[] { java.lang.String.class }); // call requestBroker.setExit(String)         }                  Object[] argValues = convertMethodArguments(method.getParameterTypes(), argValuesAsStrings);         Object obj = method.invoke (impl, argValues);         log.info("Successful invoked set method '" + property + "'");         if (obj != null) {            log.fine("Ignoring returned value of set method '" + property + "'");            if (obj instanceof String[]) {               String[] tmpArr = (String[])obj;               String ret = "";               for (int i=0; i<tmpArr.length; i++) {                  ret += tmpArr[i];                  if (i < tmpArr.length-1)                     ret += this.listSeparator; // "\n";               }               obj = ret;            }         }         return obj;      }      catch (Exception e) {         if (e instanceof XmlBlasterException) throw (XmlBlasterException)e;         if (log != null && aClass != null && argValuesAsStrings != null && argValuesAsStrings.length > 0 &&             argValuesAsStrings[0] != null) {            log.severe("Invoke for property '" + property + "' with " + argValuesAsStrings.length + " arguments of type " +               argValuesAsStrings[0].getClass().toString() +               " on interface " + aClass.toString() + " failed: " + e.toString());         }         else {            log.severe("Invoke for property '" + property + "' on interface " + ((aClass!=null)?aClass.toString():"") + " failed: " + e.toString());         }         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, ME, "Invoke for property '" + property + "' on class=" + aClass + " on object=" + impl.getClass() + " failed: " + e.toString());      }   }   /*   private Object setInvoke(String property, Object impl, Class aClass, String value) throws XmlBlasterException {      String[] argValuesAsStrings = new String[1];      argValuesAsStrings[0] = value;      return setInvoke(property, impl, aClass, argValuesAsStrings);   }   */   public String help() {      return "Administration of properties from system, xmlBlaster.properties and command line";   }   public String help(String cmd) {      return help();   }   public void shutdown() {      if (log.isLoggable(Level.FINE)) log.fine("Shutdown ignored, nothing to do");   }} // end of class CoreHandler/** * Code borrowed from XmlRpc lib from Apache (thanks). * This class uses Java Reflection to call methods * We use this because the above code with bean PropertyDescriptor * forced us to have to every getXXX() a setXXX() as well, * but some properties are read only! *//*class Invoker{   private Global glob;   private Object invokeTarget;   private Class targetClass;   boolean debug = true;    // @param targetClass is passed explicitly, as target.getClass() would allow    //        to access methods in the implementing class (e.g. RequestBroker) instead    //        of only I_AdminClass   public Invoker(Global glob, Object target, Class targetClass) {      this.glob = glob;      this.invokeTarget = target;      this.targetClass = targetClass;   }   // main method, sucht methode in object, wenn gefunden dann aufrufen.   public Object execute(String methodName, QueryQosData qosData, QueryKeyData XXkeyData)       throws XmlBlasterException {      Class[] argClasses = new Class[0];      Method method = null;      boolean hasArgs = false;      try {         method = targetClass.getMethod(methodName, argClasses);      }      catch (NoSuchMethodException nsm_e) {         hasArgs = true;         try {            argClasses = new Class[] { keyData.getClass(), qosData.getClass() };            method = targetClass.getMethod(methodName, argClasses);         }         catch (NoSuchMethodException nsm_e1) {            throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, "CoreHandler",                      "Please check your command, aborted request.", nsm_e);         }      }      catch (SecurityException s_e) {         throw new XmlBlasterException(glob, ErrorCode.USER_SECURITY_AUTHENTICATION_ACCESSDENIED, "CoreHandler",                   "Aborted request.", s_e);      }      Object[] argValues = null;      if (hasArgs) {         argValues = new Object[] { keyData, qosData };      }      else argValues = new Object[0];      try {         // our policy is to make all public methods callable except the ones defined in java.lang.Object         if (method.getDeclaringClass () == Class.forName ("java.lang.Object"))            throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, "CoreHandler",                      "Invoker can't call methods defined in java.lang.Object");      }      catch (java.lang.ClassNotFoundException e) {         throw new XmlBlasterException(glob, ErrorCode.INTERNAL_UNKNOWN, "CoreHandler",                     "Invoker can't call methods defined in java.lang.Object", e);      }      // invoke      Object returnValue = null;      try  {         returnValue = method.invoke (invokeTarget, argValues);      }      catch (IllegalAccessException iacc_e) {         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, "CoreHandler",                   "Aborted request.", iacc_e);      }      catch (IllegalArgumentException iarg_e) {         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, "CoreHandler",                   "Aborted request.", iarg_e);      }      catch (InvocationTargetException it_e) {         if (debug)            it_e.getTargetException ().printStackTrace ();         Throwable t = it_e.getTargetException();         throw new XmlBlasterException(glob, ErrorCode.USER_ILLEGALARGUMENT, "CoreHandler",                   "Aborted request.", t);      }      return returnValue;   }} // class Invoker*/

⌨️ 快捷键说明

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