50 |
import java.security.ProtectionDomain; |
import java.security.ProtectionDomain; |
51 |
import java.util.ArrayList; |
import java.util.ArrayList; |
52 |
import java.util.Arrays; |
import java.util.Arrays; |
53 |
|
import java.util.HashMap; |
54 |
|
import java.util.HashSet; |
55 |
import gnu.java.lang.ClassHelper; |
import gnu.java.lang.ClassHelper; |
56 |
|
|
57 |
/* |
/* |
477 |
*/ |
*/ |
478 |
public Object[] getSigners() |
public Object[] getSigners() |
479 |
{ |
{ |
480 |
return (Object[]) signers.clone (); |
return signers == null ? null : (Object[]) signers.clone (); |
481 |
} |
} |
482 |
|
|
483 |
/** |
/** |
566 |
* Like <code>getFields()</code> but without the security checks. |
* Like <code>getFields()</code> but without the security checks. |
567 |
*/ |
*/ |
568 |
private Field[] internalGetFields() { |
private Field[] internalGetFields() { |
569 |
ArrayList list = new ArrayList(); |
HashSet set = new HashSet(); |
570 |
list.addAll(Arrays.asList(getDeclaredFields(true))); |
set.addAll(Arrays.asList(getDeclaredFields(true))); |
571 |
if (isInterface()) { |
Class[] interfaces = getInterfaces(); |
572 |
Class[] interfaces = getInterfaces(); |
for (int i = 0; i < interfaces.length; i++) |
573 |
for (int i = 0; i < interfaces.length; i++) |
set.addAll(Arrays.asList(interfaces[i].internalGetFields())); |
574 |
list.addAll(Arrays.asList(interfaces[i].internalGetFields())); |
Class superClass = getSuperclass(); |
575 |
} else { |
if (superClass != null) |
576 |
Class superClass = getSuperclass(); |
set.addAll(Arrays.asList(superClass.internalGetFields())); |
577 |
if (superClass != null) |
return (Field[])set.toArray(new Field[set.size()]); |
|
list.addAll(Arrays.asList(superClass.internalGetFields())); |
|
|
} |
|
|
return (Field[])list.toArray(new Field[list.size()]); |
|
578 |
} |
} |
579 |
|
|
580 |
/** |
/** |
581 |
* Get all the public methods declared in this class or inherited from |
* Get all the public methods declared in this class or inherited from |
582 |
* superclasses. This returns an array of length 0 if there are no methods, |
* superclasses. This returns an array of length 0 if there are no methods, |
583 |
* including for primitive types. This does include the implicit methods of |
* including for primitive types. This does not include the implicit |
584 |
* arrays and interfaces which mirror methods of Object, nor does it |
* methods of interfaces which mirror methods of Object, nor does it |
585 |
* include constructors or the class initialization methods. The Virtual |
* include constructors or the class initialization methods. The Virtual |
586 |
* Machine allows multiple methods with the same signature but differing |
* Machine allows multiple methods with the same signature but differing |
587 |
* return types; all such methods are in the returned array. A security |
* return types; all such methods are in the returned array. A security |
595 |
*/ |
*/ |
596 |
public Method[] getMethods() { |
public Method[] getMethods() { |
597 |
memberAccessCheck(Member.PUBLIC); |
memberAccessCheck(Member.PUBLIC); |
598 |
|
// NOTE the API docs claim that no methods are returned for arrays, |
599 |
|
// but Sun's implementation *does* return the public methods of Object |
600 |
|
// (as would be expected), so we follow their implementation instead |
601 |
|
// of their documentation. |
602 |
return internalGetMethods(); |
return internalGetMethods(); |
603 |
} |
} |
604 |
|
|
607 |
*/ |
*/ |
608 |
private Method[] internalGetMethods() |
private Method[] internalGetMethods() |
609 |
{ |
{ |
610 |
java.util.HashMap map = new java.util.HashMap(); |
HashMap map = new HashMap(); |
611 |
Method[] methods; |
Method[] methods; |
612 |
Class[] interfaces = getInterfaces(); |
Class[] interfaces = getInterfaces(); |
613 |
for(int i = 0; i < interfaces.length; i++) |
for(int i = 0; i < interfaces.length; i++) |
715 |
*/ |
*/ |
716 |
public Field getField(String name) throws NoSuchFieldException { |
public Field getField(String name) throws NoSuchFieldException { |
717 |
memberAccessCheck(Member.PUBLIC); |
memberAccessCheck(Member.PUBLIC); |
718 |
|
Field field = internalGetField(name); |
719 |
|
if(field != null) |
720 |
|
return field; |
721 |
|
throw new NoSuchFieldException(); |
722 |
|
} |
723 |
|
|
724 |
|
/** |
725 |
|
* Like <code>getField(String)</code> but without the security checks and returns null |
726 |
|
* instead of throwing NoSuchFieldException. |
727 |
|
*/ |
728 |
|
private Field internalGetField(String name) { |
729 |
Field[] fields = getDeclaredFields(true); |
Field[] fields = getDeclaredFields(true); |
730 |
for (int i = 0; i < fields.length; i++) { |
for (int i = 0; i < fields.length; i++) { |
731 |
Field field = fields[i]; |
Field field = fields[i]; |
732 |
if (field.getName().equals(name)) |
if (field.getName().equals(name)) |
733 |
return field; |
return field; |
734 |
} |
} |
735 |
Class[] interfaces = getInterfaces(); |
Class[] interfaces = getInterfaces(); |
736 |
for (int i = 0; i < interfaces.length; i++) { |
for (int i = 0; i < interfaces.length; i++) { |
737 |
try { |
Field field = interfaces[i].internalGetField(name); |
738 |
return interfaces[i].getField(name); |
if(field != null) |
739 |
} catch (NoSuchFieldException e) { |
return field; |
|
} |
|
740 |
} |
} |
741 |
Class superclass = getSuperclass(); |
Class superClass = getSuperclass(); |
742 |
if (superclass != null) |
if (superClass != null) |
743 |
return superclass.getField(name); |
return superClass.internalGetField(name); |
744 |
throw new NoSuchFieldException(); |
return null; |
745 |
} |
} |
746 |
|
|
747 |
/** |
/** |
748 |
* Get a public method declared or inherited in this class, where name is |
* Get a public method declared or inherited in this class, where name is |
749 |
* its simple name. The implicit methods of Object are not available from |
* its simple name. The implicit methods of Object are not available from |
750 |
* arrays or interfaces. Constructors (named "<init>" in the class file) |
* interfaces. Constructors (named "<init>" in the class file) and class |
751 |
* and class initializers (name "<clinit>") are not available. The Virtual |
* initializers (name "<clinit>") are not available. The Virtual |
752 |
* Machine allows multiple methods with the same signature but differing |
* Machine allows multiple methods with the same signature but differing |
753 |
* return types, and the class can inherit multiple methods of the same |
* return types, and the class can inherit multiple methods of the same |
754 |
* return type; in such a case the most specific return types are favored, |
* return type; in such a case the most specific return types are favored, |
769 |
public Method getMethod(String name, Class[] args) |
public Method getMethod(String name, Class[] args) |
770 |
throws NoSuchMethodException { |
throws NoSuchMethodException { |
771 |
memberAccessCheck(Member.PUBLIC); |
memberAccessCheck(Member.PUBLIC); |
772 |
for (Class c = this; c != null; c = c.getSuperclass()) { |
Method method = internalGetMethod(name, args); |
773 |
Method match = matchMethod(c.getDeclaredMethods(true), name, args); |
if (method != null) |
774 |
|
return method; |
775 |
|
throw new NoSuchMethodException(); |
776 |
|
} |
777 |
|
|
778 |
|
/** |
779 |
|
* Like <code>getMethod(String,Class[])</code> but without the security |
780 |
|
* checks and returns null instead of throwing NoSuchMethodException. |
781 |
|
*/ |
782 |
|
public Method internalGetMethod(String name, Class[] args) { |
783 |
|
Method match = matchMethod(getDeclaredMethods(true), name, args); |
784 |
|
if (match != null) |
785 |
|
return match; |
786 |
|
Class superClass = getSuperclass(); |
787 |
|
if (superClass != null) { |
788 |
|
match = superClass.internalGetMethod(name, args); |
789 |
|
if(match != null) |
790 |
|
return match; |
791 |
|
} |
792 |
|
Class[] interfaces = getInterfaces(); |
793 |
|
for (int i = 0; i < interfaces.length; i++) { |
794 |
|
match = interfaces[i].internalGetMethod(name, args); |
795 |
if (match != null) |
if (match != null) |
796 |
return match; |
return match; |
|
Class[] interfaces = c.getInterfaces(); |
|
|
for (int i = 0; i < interfaces.length; i++) |
|
|
{ |
|
|
match = matchMethod(interfaces[i].getDeclaredMethods(true), name, args); |
|
|
if (match != null) |
|
|
return match; |
|
|
} |
|
797 |
} |
} |
798 |
throw new NoSuchMethodException(); |
return null; |
799 |
} |
} |
800 |
|
|
801 |
/** |
/** |
838 |
if (types1.length != types2.length) |
if (types1.length != types2.length) |
839 |
return false; |
return false; |
840 |
for (int i = 0; i < types1.length; i++) { |
for (int i = 0; i < types1.length; i++) { |
841 |
if (!types1[i].equals(types2[i])) |
if (types1[i] != types2[i]) |
842 |
return false; |
return false; |
843 |
} |
} |
844 |
return true; |
return true; |