@@ -41,7 +41,7 @@ Clazz.MethodNotFoundException = function (obj, clazz, method, params) {
4141 } else {
4242 leadingStr = "Constructor" ;
4343 }
44- this . message = leadingStr + " " + Clazz . getClassName ( clazz ) + "."
44+ this . message = leadingStr + " " + Clazz . getClassName ( clazz , true ) + "."
4545 + method + "(" + paramStr + ") is not found!" ;
4646 this . toString = function ( ) {
4747 return "MethodNotFoundException:" + this . message ;
@@ -69,15 +69,15 @@ Clazz.prepareCallback = function (objThis, args) {
6969 obs = new Array ( ) ;
7070 objThis [ cbName ] = obs ;
7171 }
72- var className = Clazz . getClassName ( classThisObj ) ;
72+ var className = Clazz . getClassName ( classThisObj , true ) ;
7373 //if (obs[className] == null) { /* == null make no sense! */
7474 //obs[className] = classThisObj;
7575 obs [ className . replace ( / o r g \. e c l i p s e \. s w t \. / , "$wt." ) ] = classThisObj ;
7676 var clazz = Clazz . getClass ( classThisObj ) ;
7777 while ( clazz . superClazz != null ) {
7878 clazz = clazz . superClazz ;
7979 //obs[Clazz.getClassName (clazz)] = classThisObj;
80- obs [ Clazz . getClassName ( clazz )
80+ obs [ Clazz . getClassName ( clazz , true )
8181 . replace ( / o r g \. e c l i p s e \. s w t \. / , "$wt." ) ] = classThisObj ;
8282 }
8383 //}
@@ -588,7 +588,12 @@ Object.prototype.getClass = function () {
588588} ;
589589
590590Object . prototype . clone = function ( ) {
591- return this ;
591+ var o = new Object ( ) ;
592+ for ( var i in this ) {
593+ o [ i ] = this [ i ] ;
594+ }
595+ return o ;
596+ //return this;
592597} ;
593598
594599/*
@@ -611,15 +616,27 @@ w$ = window; // Short for browser's window object
611616d$ = document ; // Short for browser's document object
612617System = {
613618 out : {
619+ __CLASS_NAME__ : "java.io.PrintStream" ,
614620 print : function ( ) { } ,
615621 printf : function ( ) { } ,
616622 println : function ( ) { }
617623 } ,
618624 err : {
625+ __CLASS_NAME__ : "java.io.PrintStream" ,
619626 print : function ( ) { } ,
620627 printf : function ( ) { } ,
621628 println : function ( ) { }
622629 } ,
630+ currentTimeMillis : function ( ) {
631+ return new Date ( ) . getTime ( ) ;
632+ } ,
633+ props : null , //new java.util.Properties (),
634+ getProperties : function ( ) {
635+ return System . props ;
636+ } ,
637+ setProperties : function ( props ) {
638+ System . props = props ;
639+ } ,
623640 arraycopy : function ( src , srcPos , dest , destPos , length ) {
624641 for ( var i = 0 ; i < length ; i ++ ) {
625642 dest [ destPos + i ] = src [ srcPos + i ] ;
@@ -637,3 +654,89 @@ Thread.currentThread = Thread.prototype.currentThread = function () {
637654
638655$_J = Clazz . declarePackage ; $_C = Clazz . decorateAsClass ; $_Z = Clazz . instantialize ; $_I = Clazz . declareInterface ; $_D = Clazz . isClassDefined ; $_H = Clazz . pu$h ; $_P = Clazz . p0p ; $_B = Clazz . prepareCallback ; $_N = Clazz . innerTypeInstance ; $_K = Clazz . makeConstructor ; $_U = Clazz . superCall ; $_R = Clazz . superConstructor ; $_M = Clazz . defineMethod ; $_V = Clazz . overrideMethod ; $_S = Clazz . defineStatics ; $_E = Clazz . defineEnumConstant ; $_F = Clazz . cloneFinals ; $_Y = Clazz . prepareFields ; $_A = Clazz . newArray ; $_O = Clazz . instanceOf ; $_G = Clazz . inheritArgs ; $_X = Clazz . checkPrivateMethod ; $_Q = Clazz . makeFunction ;
639656
657+ var reflect = Clazz . declarePackage ( "java.lang.reflect" ) ;
658+ Clazz . declarePackage ( "java.security" ) ;
659+
660+ Clazz . innerFunctionNames = Clazz . innerFunctionNames . concat ( [ "getSuperclass" ,
661+ "isAssignableFrom" , "getMethods" , "getMethod" , "getDeclaredMethods" ,
662+ "getDeclaredMethod" , "getConstructor" , "getModifiers" , "isArray" , "newInstance" ] ) ;
663+
664+ Clazz . innerFunctions . getSuperclass = function ( ) {
665+ return this . superClazz ;
666+ } ;
667+ Clazz . innerFunctions . isAssignableFrom = function ( clazz ) {
668+ return Clazz . getInheritedLevel ( clazz , this ) >= 0 ;
669+ } ;
670+ Clazz . innerFunctions . getConstructor = function ( ) {
671+ return new java . lang . reflect . Constructor ( this , [ ] , [ ] ,
672+ java . lang . reflect . Modifier . PUBLIC , 0 ) ;
673+ } ;
674+ Clazz . innerFunctions . getDeclaredMethods = Clazz . innerFunctions . getMethods = function ( ) {
675+ var ms = new Array ( ) ;
676+ var p = this . prototype ;
677+ for ( var attr in p ) {
678+ if ( typeof p [ attr ] == "function" && p [ attr ] . __CLASS_NAME__ == null ) {
679+ /* there are polynormical methods. */
680+ ms [ ms . length ] = new java . lang . reflect . Method ( this , attr ,
681+ [ ] , java . lang . Void , [ ] , java . lang . reflect . Modifier . PUBLIC , 0 ) ;
682+ }
683+ }
684+ p = this ;
685+ for ( var attr in p ) {
686+ if ( typeof p [ attr ] == "function" && p [ attr ] . __CLASS_NAME__ == null ) {
687+ ms [ ms . length ] = new java . lang . reflect . Method ( this , attr ,
688+ [ ] , java . lang . Void , [ ] , java . lang . reflect . Modifier . PUBLIC
689+ | java . lang . reflect . Modifier . STATIC , 0 ) ;
690+ }
691+ }
692+ return ms ;
693+ } ;
694+ Clazz . innerFunctions . getDeclaredMethod = Clazz . innerFunctions . getMethod = function ( name , clazzes ) {
695+ var p = this . prototype ;
696+ for ( var attr in p ) {
697+ if ( name == attr && typeof p [ attr ] == "function"
698+ && p [ attr ] . __CLASS_NAME__ == null ) {
699+ /* there are polynormical methods. */
700+ return new java . lang . reflect . Method ( this , attr ,
701+ [ ] , java . lang . Void , [ ] , java . lang . reflect . Modifier . PUBLIC , 0 ) ;
702+ }
703+ }
704+ p = this ;
705+ for ( var attr in p ) {
706+ if ( name == attr && typeof p [ attr ] == "function"
707+ && p [ attr ] . __CLASS_NAME__ == null ) {
708+ return new java . lang . reflect . Method ( this , attr ,
709+ [ ] , java . lang . Void , [ ] , java . lang . reflect . Modifier . PUBLIC
710+ | java . lang . reflect . Modifier . STATIC , 0 ) ;
711+ }
712+ }
713+ return null ;
714+ } ;
715+ Clazz . innerFunctions . getModifiers = function ( ) {
716+ return java . lang . reflect . Modifier . PUBLIC ;
717+ } ;
718+ Clazz . innerFunctions . isArray = function ( ) {
719+ return false ;
720+ } ;
721+ Clazz . innerFunctions . newInstance = function ( ) {
722+ var clz = this ;
723+ return new clz ( ) ;
724+ } ;
725+
726+ //Object.newInstance = Clazz.innerFunctions.newInstance;
727+ {
728+ var inF = Clazz . innerFunctionNames ;
729+ for ( var i = 0 ; i < inF . length ; i ++ ) {
730+ Object [ inF [ i ] ] = Clazz . innerFunctions [ inF [ i ] ] ;
731+ }
732+ }
733+
734+ Clazz . forName = function ( clazzName ) {
735+ if ( window [ "ClazzLoader" ] != null ) {
736+ ClazzLoader . setLoadingMode ( "xhr.sync" ) ;
737+ ClazzLoader . loadClass ( clazzName ) ;
738+ return Clazz . evalType ( clazzName ) ;
739+ } else {
740+ alert ( "[Java2Script] Error: No ClassLoader!" ) ;
741+ }
742+ } ;
0 commit comments