1 16 19 package com.sun.org.apache.xml.internal.utils.synthetic.reflection; 20 21 import com.sun.org.apache.xml.internal.utils.synthetic.SynthesisException; 22 23 29 30 36 abstract public class EntryPoint implements Member 37 { 38 39 40 protected Object realep; 41 42 43 private com.sun.org.apache.xml.internal.utils.synthetic.Class declaringclass = null; 44 45 46 protected com.sun.org.apache.xml.internal.utils.synthetic.Class returntype = null; 47 48 49 private String [] parameternames = new String [0]; 50 51 52 private com.sun.org.apache.xml.internal.utils.synthetic.Class[] parametertypes = 53 new com.sun.org.apache.xml.internal.utils.synthetic.Class[0]; 54 55 56 private com.sun.org.apache.xml.internal.utils.synthetic.Class[] exceptiontypes = 57 new com.sun.org.apache.xml.internal.utils.synthetic.Class[0]; 58 ; 59 60 61 private int modifiers; 62 63 64 protected String name = null; 66 68 69 private StringBuffer body = null; 70 71 72 private String language = null; 73 74 76 77 Class [] realE, realP; 78 79 87 public EntryPoint(com.sun.org.apache.xml.internal.utils.synthetic.Class declaringclass) 88 { 89 this.declaringclass = declaringclass; 90 } 91 92 100 protected EntryPoint( 101 Object ep, com.sun.org.apache.xml.internal.utils.synthetic.Class declaringclass) 102 throws IllegalArgumentException 103 { 104 105 realep = ep; 106 this.declaringclass = declaringclass; 107 108 if (ep instanceof java.lang.reflect.Method ) 109 { 110 java.lang.reflect.Method m = (java.lang.reflect.Method ) ep; 111 112 if (declaringclass == null) 113 { 114 declaringclass = com.sun.org.apache.xml.internal.utils.synthetic.Class.forClass( 115 m.getDeclaringClass()); 116 } 117 118 name = m.getName(); 119 modifiers = m.getModifiers(); 120 returntype = 121 com.sun.org.apache.xml.internal.utils.synthetic.Class.forClass(m.getReturnType()); 122 realP = m.getParameterTypes(); 123 realE = m.getExceptionTypes(); 124 } 125 else if (ep instanceof java.lang.reflect.Constructor ) 126 { 127 java.lang.reflect.Constructor c = (java.lang.reflect.Constructor ) ep; 128 129 if (declaringclass == null) 130 { 131 declaringclass = com.sun.org.apache.xml.internal.utils.synthetic.Class.forClass( 132 c.getDeclaringClass()); 133 } 134 135 name = declaringclass.getShortName(); 136 modifiers = c.getModifiers(); 137 returntype = declaringclass; 138 realP = c.getParameterTypes(); 139 realE = c.getExceptionTypes(); 140 } 141 else 142 throw new IllegalArgumentException (); 143 } 144 145 152 protected EntryPoint(Object ep) throws IllegalArgumentException 153 { 154 this(ep, null); 155 } 156 157 168 public boolean equals(Object obj) 169 { 170 171 EntryPoint otherep = null; 172 173 if (obj instanceof EntryPoint) 174 otherep = (EntryPoint) obj; 175 else if (obj instanceof java.lang.reflect.Constructor 176 || obj instanceof java.lang.reflect.Method ) 177 otherep = (EntryPoint) obj; 178 179 return (otherep != null && ((this instanceof Constructor && otherep instanceof Constructor) || (this instanceof Method && otherep instanceof Method && this.getName().equals( 180 otherep.getName()))) && otherep.getDeclaringClass().equals( 181 declaringclass) && otherep.getParameterTypes().equals( 182 parametertypes)); 183 } 184 185 191 public com.sun.org.apache.xml.internal.utils.synthetic.Class getDeclaringClass() 192 { 193 return declaringclass; 194 } 195 196 202 public com.sun.org.apache.xml.internal.utils.synthetic.Class getReturnType() 203 { 204 return returntype; 205 } 206 207 215 public com.sun.org.apache.xml.internal.utils.synthetic.Class[] getExceptionTypes() 216 { 217 218 if (realep != null && exceptiontypes == null) 219 { 220 exceptiontypes = 221 new com.sun.org.apache.xml.internal.utils.synthetic.Class[realE.length]; 222 223 for (int i = 0; i < realE.length; ++i) 224 { 225 exceptiontypes[i] = 226 com.sun.org.apache.xml.internal.utils.synthetic.Class.forClass(realE[i]); 227 } 228 229 realE = null; 230 } 231 232 return exceptiontypes; 233 } 234 235 243 public void addExceptionType( 244 com.sun.org.apache.xml.internal.utils.synthetic.Class exception) 245 throws SynthesisException 246 { 247 248 if (realep != null) 249 throw new SynthesisException(SynthesisException.REIFIED); 250 251 com.sun.org.apache.xml.internal.utils.synthetic.Class[] e = 252 new com.sun.org.apache.xml.internal.utils.synthetic.Class[exceptiontypes.length + 1]; 253 254 System.arraycopy(exceptiontypes, 0, e, 0, exceptiontypes.length); 255 256 e[exceptiontypes.length] = exception; 257 exceptiontypes = e; 258 } 259 260 267 public int getModifiers() 268 { 269 return modifiers; 270 } 271 272 278 public java.lang.String getName() 279 { 280 281 if (this instanceof Constructor) 282 return declaringclass.getShortName(); 283 284 return name; 285 } 286 287 297 public void setName(String name) throws SynthesisException 298 { 299 300 if (realep != null) 301 throw new SynthesisException(SynthesisException.REIFIED); 302 303 this.name = name; 304 } 305 306 314 public com.sun.org.apache.xml.internal.utils.synthetic.Class[] getParameterTypes() 315 { 316 317 if (realep != null && parametertypes == null) 318 { 319 parametertypes = 320 new com.sun.org.apache.xml.internal.utils.synthetic.Class[realP.length]; 321 322 for (int i = 0; i < realP.length; ++i) 323 { 324 parametertypes[i] = 325 com.sun.org.apache.xml.internal.utils.synthetic.Class.forClass(realP[i]); 326 } 327 328 realP = null; 329 } 330 331 return parametertypes; 332 } 333 334 340 public String [] getParameterNames() 341 { 342 return parameternames; 343 } 344 345 354 public void addParameter( 355 com.sun.org.apache.xml.internal.utils.synthetic.Class type, String name) 356 throws SynthesisException 357 { 358 359 if (realep != null) 360 throw new SynthesisException(SynthesisException.REIFIED); 361 362 com.sun.org.apache.xml.internal.utils.synthetic.Class[] types = 363 new com.sun.org.apache.xml.internal.utils.synthetic.Class[parametertypes.length + 1]; 364 365 System.arraycopy(parametertypes, 0, types, 0, parametertypes.length); 366 367 types[parametertypes.length] = type; 368 parametertypes = types; 369 370 String [] names = new String [parameternames.length + 1]; 371 372 System.arraycopy(parameternames, 0, names, 0, parameternames.length); 373 374 names[parameternames.length] = name; 375 parameternames = names; 376 } 377 378 386 abstract public int hashCode(); 387 388 397 public void setDeclaringClass( 398 com.sun.org.apache.xml.internal.utils.synthetic.Class declaringClass) 399 throws SynthesisException 400 { 401 402 if (realep != null) 403 throw new SynthesisException(SynthesisException.REIFIED); 404 405 this.declaringclass = declaringClass; 406 } 407 408 416 public void setModifiers(int modifiers) throws SynthesisException 417 { 418 419 if (realep != null) 420 throw new SynthesisException(SynthesisException.REIFIED); 421 422 this.modifiers = modifiers; 423 } 424 425 444 public String toString() 445 { 446 447 StringBuffer sb = 448 new StringBuffer (java.lang.reflect.Modifier.toString(getModifiers())); 449 450 if (this instanceof com.sun.org.apache.xml.internal.utils.synthetic.reflection.Method) 451 sb.append(' ').append(getReturnType()).append( 452 getDeclaringClass().getName()).append('.').append(getName()); 453 else 454 sb.append(getDeclaringClass().getName()); 455 456 sb.append('('); 457 458 com.sun.org.apache.xml.internal.utils.synthetic.Class[] p = getParameterTypes(); 459 460 if (p != null && p.length > 0) 461 { 462 sb.append(p[0].getName()); 463 464 for (int i = 1; i < p.length; ++i) 465 { 466 sb.append(',').append(p[i].getName()); 467 } 468 } 469 470 sb.append(')'); 471 472 if (this instanceof com.sun.org.apache.xml.internal.utils.synthetic.reflection.Method) 473 { 474 p = getExceptionTypes(); 475 476 if (p != null && p.length > 0) 477 { 478 sb.append(" throws ").append(p[0].getName()); 479 480 for (int i = 1; i < p.length; ++i) 481 { 482 sb.append(',').append(p[i].getName()); 483 } 484 } 485 } 486 487 return sb.toString(); 488 } 489 490 499 public void setBody(String language, StringBuffer body) 500 throws SynthesisException 501 { 502 503 if (realep != null) 504 throw new SynthesisException(SynthesisException.REIFIED); 505 506 this.language = language; 507 this.body = body; 508 } 509 510 516 public StringBuffer getBody() 517 { 518 519 if (body == null) 520 body = new StringBuffer (); 521 522 return body; 523 } 524 525 530 public String getLanguage() 531 { 532 return language; 533 } 534 535 541 public String toSource(String basetab) 542 { 543 544 StringBuffer sb = new StringBuffer (); 545 546 sb.append(basetab).append( 547 java.lang.reflect.Modifier.toString(getModifiers())); 548 549 if (this instanceof com.sun.org.apache.xml.internal.utils.synthetic.reflection.Method) 550 { 551 if (returntype != null) 552 sb.append(" ").append(getReturnType().getJavaName()); 553 else 554 sb.append(" void"); 555 } 556 557 sb.append(" ").append(getName()).append("("); 558 559 com.sun.org.apache.xml.internal.utils.synthetic.Class[] types = getParameterTypes(); 560 561 if (types != null & types.length > 0) 562 { 563 sb.append(types[0].getJavaName()); 564 565 if (parameternames != null) 566 sb.append(' ').append(parameternames[0]); 567 568 for (int i = 1; i < types.length; ++i) 569 { 570 sb.append(',').append(types[i].getJavaName()); 571 572 if (parameternames != null) 573 sb.append(' ').append(parameternames[i]); 574 } 575 } 576 577 sb.append(')'); 578 579 types = getExceptionTypes(); 580 581 if (types != null & types.length > 0) 582 { 583 sb.append(" throws ").append(types[0].getJavaName()); 584 585 for (int i = 1; i < types.length; ++i) 586 { 587 sb.append(',').append(types[i].getJavaName()); 588 } 589 } 590 591 if (body == null) 592 sb.append("; // No method body available\n"); 593 else 594 { 595 sb.append("\n" + basetab + "{\n"); 596 597 if (language == null || "java".equals(language)) 598 { 599 sb.append(basetab + "// ***** Should prettyprint this code...\n"); 600 sb.append(basetab + body + "\n"); 601 } 602 else 603 { 604 sb.append(basetab + "// ***** Generate BSF invocation!?\n"); 605 } 606 607 sb.append(basetab + "}\n"); 608 } 609 610 return sb.toString(); 611 } 612 } 613 | Popular Tags |