//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: private Object invokeInternal() throws Exception private Object InvokeInternal() { Object target = Target; String methodName = MethodName; if (target == null || methodName == null) { throw new NullPointerException((target == null ? "target" : "methodName") + " should not be null"); } Object[] arguments = Arguments; if (arguments == null) { arguments = EmptyArray; } // Class.forName() won't load classes outside // of core from a class inside core. Special // case this method. if (target == typeof(Class) && methodName.Equals("forName")) { return(ClassFinder.resolveClass((String)arguments[0], this.Loader)); } Class[] argClasses = new Class[arguments.Length]; for (int i = 0; i < arguments.Length; i++) { argClasses[i] = (arguments[i] == null) ? null : arguments[i].GetType(); } AccessibleObject m = null; if (target is Class) { /* * For class methods, simluate the effect of a meta class * by taking the union of the static methods of the * actual class, with the instance methods of "Class.class" * and the overloaded "newInstance" methods defined by the * constructors. * This way "System.class", for example, will perform both * the static method getProperties() and the instance method * getSuperclass() defined in "Class.class". */ if (methodName.Equals("new")) { methodName = "newInstance"; } // Provide a short form for array instantiation by faking an nary-constructor. if (methodName.Equals("newInstance") && ((Class)target).Array) { Object result = Array.newInstance(((Class)target).ComponentType, arguments.Length); for (int i = 0; i < arguments.Length; i++) { Array.set(result, i, arguments[i]); } return(result); } if (methodName.Equals("newInstance") && arguments.Length != 0) { // The Character class, as of 1.4, does not have a constructor // which takes a String. All of the other "wrapper" classes // for Java's primitive types have a String constructor so we // fake such a constructor here so that this special case can be // ignored elsewhere. if (target == typeof(Character) && arguments.Length == 1 && argClasses[0] == typeof(String)) { return(new Character(((String)arguments[0]).CharAt(0))); } try { m = ConstructorFinder.findConstructor((Class)target, argClasses); } catch (NoSuchMethodException) { m = null; } } if (m == null && target != typeof(Class)) { m = GetMethod((Class)target, methodName, argClasses); } if (m == null) { m = GetMethod(typeof(Class), methodName, argClasses); } } else { /* * This special casing of arrays is not necessary, but makes files * involving arrays much shorter and simplifies the archiving infrastrcure. * The Array.set() method introduces an unusual idea - that of a static method * changing the state of an instance. Normally statements with side * effects on objects are instance methods of the objects themselves * and we reinstate this rule (perhaps temporarily) by special-casing arrays. */ if (target.GetType().IsArray&& (methodName.Equals("set") || methodName.Equals("get"))) { int index = ((Integer)arguments[0]).IntValue(); if (methodName.Equals("get")) { return(Array.get(target, index)); } else { Array.set(target, index, arguments[1]); return(null); } } m = GetMethod(target.GetType(), methodName, argClasses); } if (m != null) { try { if (m is Method) { return(MethodUtil.invoke((Method)m, target, arguments)); } else { return(((Constructor)m).newInstance(arguments)); } } catch (IllegalAccessException iae) { throw new Exception("Statement cannot invoke: " + methodName + " on " + target.GetType(), iae); } catch (InvocationTargetException ite) { Throwable te = ite.TargetException; if (te is Exception) { throw (Exception)te; } else { throw ite; } } } throw new NoSuchMethodException(ToString()); }
/// <summary> /// Use the given ClassLoader rather than using the system class /// </summary> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @SuppressWarnings("rawtypes") protected Class resolveClass(java.io.ObjectStreamClass classDesc) throws java.io.IOException, ClassNotFoundException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: protected internal override Class ResolveClass(ObjectStreamClass classDesc) { String cname = classDesc.Name; return(ClassFinder.resolveClass(cname, this.Loader)); }