1 package jfun.yan.xml; 2 3 import jfun.yan.Component; 4 import jfun.yan.SimpleComponent; 5 6 12 final class NutsContinuation implements NutsFunction { 13 private final Object id; 14 private final String name; 15 private final Location loc; 16 private static final String [] pnames = {Constants.RESULT}; 17 18 NutsContinuation(String name, Location loc, Object id) { 19 this.id = id; 20 this.loc = loc; 21 this.name = name; 22 } 23 24 public Object call(Object [] args) { 25 final Object result = args[0]; 26 return new SimpleComponent(null){ 27 public Object create(){ 28 throw getContinuation(id, result); 29 } 30 public String toString(){ 31 return name + " " + result; 32 } 33 }; 34 } 35 36 public String getName() { 37 return name; 38 } 39 40 public int getParameterCount() { 41 return 1; 42 } 43 44 public Class getReturnType() { 45 return Component.class; 46 } 47 48 public String [] getParameterNames() { 49 return pnames; 50 } 51 52 public Location getLocation() { 53 return loc; 54 } 55 56 public boolean equals(Object obj) { 57 if(obj instanceof NutsContinuation){ 58 final NutsContinuation other = (NutsContinuation)obj; 59 return id==other.id; 60 } 61 else return false; 62 } 63 64 public int hashCode() { 65 return System.identityHashCode(id); 66 } 67 68 public String toString() { 69 return name; 70 } 71 private static ContinuationEscapeException getContinuation(Object id, Object result){ 72 final ContinuationEscapeException ex = (ContinuationEscapeException) 73 exception.get(); 74 ex.clearResolutionTrace(); 75 ex.setId(id); 76 ex.setResult(result); 77 return ex; 78 } 79 private static final ThreadLocal exception = new ThreadLocal (){ 80 protected Object initialValue() { 81 return new ContinuationEscapeException("continuation"); 82 } 83 }; 84 } 85 | Popular Tags |