Coverage Report - org.webslinger.ext.bsf.javaclass.JavaclassCallKey
 
Classes in this File Line Coverage Branch Coverage Complexity
JavaclassCallKey
0%
0/34
0%
0/6
0
 
 1  
 package org.webslinger.ext.bsf.javaclass;
 2  
 
 3  
 import java.lang.reflect.Method;
 4  
 
 5  
 import org.apache.bsf.BSFException;
 6  
 
 7  
 import org.webslinger.bsf.Compiler;
 8  
 import org.webslinger.bsf.GenericEngine;
 9  
 import org.webslinger.bsf.Key;
 10  
 
 11  0
 public final class JavaclassCallKey extends Key<Class<Object>> {
 12  
     private final Class type;
 13  
     private final String name;
 14  
     private final Class[] types;
 15  
     private final boolean hasType;
 16  
 
 17  
     public JavaclassCallKey(Class type, String name, Class[] types) throws BSFException {
 18  0
         super(null);
 19  0
         this.type = type;
 20  0
         this.name = name;
 21  0
         this.types = types;
 22  
         try {
 23  0
             Method method = ClassTypeUtil.findMostApplicableMethod(type, name, types);
 24  0
             Class returnType = method.getReturnType();
 25  0
             hasType = returnType != Void.TYPE;
 26  0
         } catch (SecurityException e) {
 27  0
             throw (BSFException) new BSFException(BSFException.REASON_INVALID_ARGUMENT, e.getMessage(), e).initCause(e);
 28  0
         } catch (NoSuchMethodException e) {
 29  0
             throw (BSFException) new BSFException(BSFException.REASON_INVALID_ARGUMENT, e.getMessage(), e).initCause(e);
 30  0
         }
 31  0
     }
 32  
 
 33  
     public Class getType() {
 34  0
         return type;
 35  
     }
 36  
 
 37  
     public String getName() {
 38  0
         return name;
 39  
     }
 40  
 
 41  
     public Class[] getTypes() {
 42  0
         return types;
 43  
     }
 44  
 
 45  
     public boolean hasType() {
 46  0
         return hasType;
 47  
     }
 48  
 
 49  
     protected int computeHashCode() {
 50  0
         int tmpHashCode = getType().hashCode() ^ getName().hashCode();
 51  0
         for (Class type: getTypes()) {
 52  0
             tmpHashCode ^= type.hashCode();
 53  
         }
 54  0
         return tmpHashCode;
 55  
     }
 56  
 
 57  
     protected boolean keyEquals(Key key) {
 58  0
         JavaclassCallKey other = (JavaclassCallKey) key;
 59  0
         if (!getType().equals(other.getType())) return false;
 60  0
         if (!getName().equals(other.getName())) return false;
 61  0
         Class[] myTypes = getTypes();
 62  0
         Class[] otherTypes = other.getTypes();
 63  0
         for (int i = 0; i < myTypes.length; i++) {
 64  0
             if (!myTypes[i].equals(otherTypes[i])) return false;
 65  
         }
 66  0
         return true;
 67  
     }
 68  
 
 69  
     public long getLastModifiedTime(GenericEngine engine) {
 70  0
         return 0;
 71  
     }
 72  
 
 73  
     public String getText(GenericEngine engine) throws BSFException {
 74  0
         return "";
 75  
     }
 76  
 
 77  
     public <V> Class<Object> compile(Compiler<V, Class<Object>> compiler, Compiler<V, Class<Object>>.CompilerContext context) throws BSFException {
 78  0
         return ((JavaclassCompiler) compiler).compileKey(this, context);
 79  
     }
 80  
 
 81  
     public ClassLoader getParentClassLoader(GenericEngine engine) {
 82  0
         return getType().getClassLoader();
 83  
     }
 84  
 }