My name is Mathew Sheets, born, raised, and still live in Columbus, OH. I've been developing software for eight years and have worked for consulting and corporate companies.\n\n~JavaScript was actually my second language that I learned. The first was COBOL, and then in '99 I picked up David Flanagan's book "~JavaScript: The Definitive Guide". Back then I didn't know what was under my nose. Then recently the buzz word ''AJAX'' put ~JavaScript on a whole new playing field and now it's one of the hottest languages. I won't bore you with other details about my life.\n\nOne thing I do ask of you, is if you find what I'm trying to do with ''~JavaScript SDK'' a good thing, send me an email at ''mathewsheets [at] gmail [dot] com'' and give me a quick hello and an //Atta Boy//. Any encouragement will help when I'm coding in the middle of the night because I feel ~JavaScript needs some help.\n\n-- Thanks
The ClassLoader object loads the target class. It makes sure that the class you are trying to load hasn't already been loaded. It uses [[ClassTransporter]] to retrieve the class and [[PreProcessor]] to preprocess the source and translate the source into valid ~JavaScript code. It also makes reflection on the class possible and validates that class implements the interfaces.\n\n[[ClassLoader.constructor]]\n{{{\nnew runtime.ClassLoader(_classTransporter, _preProcessor) -> ClassLoader object\n}}}\n[[ClassLoader#loadClass]]\n{{{\nloadClass(_class) -> void\n}}}\n[[ClassLoader#evaluate]]\n{{{\nevaluate(_code) -> void\n}}}
This class transports the ~JavaScript class that will get loaded into the runtime environment.\n\n[[ClassTransporter.constructor]]\n{{{\nnew runtime.ClassTransporter(_classPath, _applicationPath) -> ClassTransporter object\n}}}\n[[ClassTransporter#transportClass]]\n{{{\ntransportClass(_class) -> string of JavaScript source\n}}}\n[[ClassTransporter#getClassesInPkg]]\n{{{\ngetClassesInPkg(_package) -> Array of fully qualified class names\n}}}\n[[ClassTransporter#persistClass]]\n{{{\npersistClass(_package, _class, _code) -> void\n}}}
~JavaScript SDK supplies several Collection class that aid in collection processing. Here's a snapshot of the package/class layout.\n*jsx.collections\n**~AbstractCollection - Base class for all Collection classes, mixes in the Enumerable class\n**~AbstractList - Base class for all List classes, extends the ~AbstractCollection class\n**~AbstractMap - Base class for all Map classes, mixes in the Enumerable class\n**~AbstractSet - Base class for all Set classes, extends the ~AbstractCollection class\n**~ArrayList - Implements the List interface, extends the ~AbstractList class\n**~ArrayStack - a Stack class, extends the ~ArrayList class\n**Collection - Interface, extends the Iterable interface\n**Enumerable - Used to be mixed in. Provides useful methods for collection processing\n**~HashMap - Implements the Map interface, extends the ~AbstractMap class\n**~HashSet - Implements the Set interface, extends the ~AbstractSet class\n**Iterable - Interface, defines how to iterate through the collection\n**List - Interface, extends the Collection interface\n**Map - Interface, extends the Iterable interface\n**Set - Interface, extends the Collection interface
The Constructor object gives you the ability to operate on a constructor of an object.\n*{{{Constructor}}} - \n**{{{getDeclaringClass()}}} - returns the class object of the owning class\n**{{{getParameters()}}} - returns an array of parameters that the constructor accepts\n**{{{getBody()}}} - returns the actual ~JavaScript source code\n**{{{newInstance()}}} - returns a new instance of the class, pass any number of parameters
Since ~JavaScript SDK runs the ~JavaScript source through a ~PreProcessor and retrieves the source via the ~XMLHttpRequest object, debugging is nearly impossible.\n\nTo make debugging work in Firefox and IE make sure that the source is written to your local disk. See [[Persisting]] for details. Once that is done, make sure you have a good debugger for Firefox installed, I use [[Firebug|https://addons.mozilla.org/en-US/firefox/addon/1843]].\n\nOnce Firebug is installed, click on one of the test html files in the ''html'' directory, make sure you see ~JavaScript source on you local. Then see the Firebug instructions on how to debug. Debugging ~JavaScript in IE is not fun, and since it's pretty easy to code ~JavaScript using Firefox and run it under IE there's really no need debug in IE. I haven't successfully been able to debug in IE, if someone has figured this out, please tell me.
Overview
The Environment object uses the $JSRE_CONFIG and the $JSRE_LOCATION objects to build the Class Path and Application Path. It also inspects the query parameters and provide the functionality to get a single parameter or get an object with name/value pair of all the parameters.\n\n[[Environment.constructor]]\n{{{\nnew runtime.Environment(_config, _location) -> Environment object\n}}}\n[[Environment#getApplicationPath]]\n{{{\ngetApplicationPath() -> string\n}}}\n[[Environment#getClassPath]]\n{{{\ngetClassPath() -> string\n}}}\n[[Environment#getRuntimeProperties]]\n{{{\ngetRuntimeProperties() -> object; property name = key, property value = value\n}}}\n[[Environment#getRuntimeProperty]]\n{{{\ngetRuntimeProperty(_key) -> string for the value to the key\n}}}
Coming Soon!
~JavaScript SDK is packed with features that will make ~JavaScript development a ton easier and enable other developers to extend. Current features include but not limited too...\n*[[Lazy Loading]] of ~JavaScript class files; modeled after Java's packaging system\n*[[NameSpace]] for each Class to make the class unique\n*[[Interfaces]] to validate that a class is fulfilling the contract\n*[[Mixins, just like Ruby]] for another way to reuse code\n*[[Nine Native Global Classes]] have many enhancements since ~JavaScript supports open classes\n*[[Additional Standard Classes]] to provide that missing functionality\n*[[Reflection]] on the Class, I have to say it's the best out there\n*[[Event Framework]], cross platform event notification, handles DOM Events and generic event notification\n*[[AJAX Framework]], for your background requests\n*[[Collections Framework]], if you know Java's or C#'s Collections API, this should be easy to grasp\n*[[Test Unit Framework]], very similar to Java's ~JUnit\n*[[Logging Framework]], very similar to Java's Log4j\n*[[PreProcessor]] to make the ~JavaScript core language less verbose and clunky\n*[[Persisting]] of the output from the PreProcessor, to verify the ~JavaScript\n*[[Debugging]] - Thanks for Firefox's Firebug
The Field object gives you the ability to operate on a field of an object or class.\n*{{{Field}}} - \n**{{{getName()}}} - returns the name of the field\n**{{{isStatic()}}} - returns a boolean indicating if the field is static\n**{{{getDeclaringClass()}}} - returns the class object of the owning class\n**{{{getValue(_obj)}}} - returns the value of the field
Installing and Configuring ~JavaScript SDK is meant to be easy and painless. To download ~JavaScript SDK, click [[here|https://sourceforge.net/project/showfiles.php?group_id=194207&package_id=230297&release_id=505772]]. Once you have the distribution, just unzip it into any directory, outside or inside a webcontainer. \n\nThe directories that appear are...\n*api - ~JSDoc API of the classes within ~JavaScript SDK\n*apixml - XML representation of the classes within ~JavaScript SDK\n*browser - files used for testing the ~JavaScript classes within a browser\n*output - default location for persisting classes\n*rhino - files used for testing the ~JavaScript classes within rhino\n*site - this site so is readily available\n*src\n**jsx - source for the actual SDK\n**runtime - loaded classes to make ~JavaScript SDK possible\n***[[Runtime]] - This is what starts everything\n***[[Environment]] - Provides an API to get query parameters and builds the ~ClassPath and ~ApplicationPath\n***[[ClassTransporter]] - Performs a ''GET'' request to retrieve the class file\n***[[PreProcessor]] - Translates source code into valid ~JavaScript code\n***[[ClassLoader]] - Performs the //loading// and validates the loaded class\n***[[Minimizer]] - Compresses the source to reduce the payload\n**test - Unit tests for the SDK and widget examples
Interfaces are just ~JavaScript SDK classes where all the methods are abstract. For example...\n{{{\npackage com.mycomp.mydepart.myapp;\nclass FooInterface\n{\n abstract fooy()\n}\n}}}\n{{{\npackage com.mycomp.mydepart.myapp;\nimport com.mycomp.mydepart.myapp.FooInterface;\nclass BooClass implements FooInterface\n{\n instance fooy()\n {\n var _var = "I am fooy";\n }\n}\n}}}\n\n''Q:'' What will happen if Boo does not have an implementation of Foo.fooy()? ''A:'' For now, nothing. But you can see in the [[Runtime Console]] what classes are not correctly implementing their interface.\n\n''Q:'' How does this happen? ''A:'' Once Foo and Boo have been loaded in the Global Object, [[ClassLoader]] validates that Boo provides a method //fooy//.\n\n''Q:'' Why would you want a feature like this? ''A:'' You don't have to check if an object can respond to a method call, the fact that it implements something you require it to implement should suffice.\n\nSee the jsx.collections package to see how ~JavaScript SDK uses interfaces for the collection classes.
Edit the properties to fit your environment. See the rhino directory and the ~RuntimeLoaderConfig.js file for an example of setting the these properties.\n\n{{{\n$JSRE_CONFIG =\n{\n offlineCP : "../src/" , /* relative path to the jsx source while running in offline mode */\n onlineCP : "../src/" , /* relative path to the jsx source while running in online mode */\n srcDir : "src" , /* relative path to the source file getting persisted */\n outputDir : "output" , /* relative path to the output directory */\n persistClasses : false, /* to persist the output of the processed class file */\n singleFile : false, /* persist to a single file */\n minimize : false, /* minimize classes while persisting */\n includeTests: false/* include tests while persisting */\n};\n}}}\n
Normally there's no need to edit the properties of this object. If you are using Rhino, then the only property you will need to change is the 'pathName'. See the rhino directory and the ~RuntimeLoaderConfig.js file for an example of setting the these properties.\n{{{\n$JSRE_LOCATION =\n{\n protocol : location.protocol,\n hostName : location.hostname,\n port : location.port,\n pathName : location.pathname,\n search : location.search\n};\n}}}
See [[Runtime]] to get an overview of what is needed to make ~JavaScript work.\n\nThe lazy loading is able to work because each class has a class definition that creates a namespace for the class and a list of all the classes that need loaded before the current class get loaded. For example consider class Foo\n{{{\n1. package com.mycompany.mydept.myapp;\n2. import com.mycomany.mydepart.myapp.Bar;\n3. class Foo\n4. {\n5. Foo()\n6. {\n7. }\n8. instance callBar()\n9. {\n10. var hold = Bar.callingAStaticMethod();\n11. }\n12.}\n}}}\nLine 2 indicates that the class com.mycomany.mydepart.myapp.Bar is used somewhere within the com.mycompany.mydept.myapp.Foo class. When Foo is loaded, [[ClassLoader]] knows all the dependent classes that Foo relies on. It will load all the classes prior to loading Foo, in this case Bar will be loaded before Foo.
The LibraryBootstrap is just a ~JavaScript file that builds all the runtime objects and sets them on the GLOBAL object. Here's some of the source...\n{{{\nvar Environment = new runtime.Environment($JSRE_CONFIG, $JSRE_LOCATION);\nvar ClassTransporter = new runtime.ClassTransporter(Environment.classPath, Environment.applicationPath);\nvar Preprocessor = new runtime.PreProcessor(ClassTransporter);\nvar ClassLoader = new runtime.ClassLoader(ClassTransporter, Preprocessor);\n}}}\nIt also loads ~JavaScript class files that should be available immediately in your runtime environment.\n{{{\nClassLoader.loadClass("jsx.lang.*");\nClassLoader.loadClass("jsx.event.*");\n}}}
It's available. If you know Log4j, you already know this logging framework.\n\nScreenshot of the ''~ConsoleAppender''\n[img[LoggingConsoleAppender.png]]
[[Overview]]\n[[User Guide]]\n[[About Me]]
The Method object gives you the ability to operate on a method of an object or class.\n*{{{Method}}}\n**{{{getName()}}} - returns the name of the method\n**{{{isStatic()}}} - returns a boolean indicating if the method is static\n**{{{getDeclaringClass()}}} - returns the class object of the owning class\n**{{{getParameters()}}} - returns an array of parameters that the method accepts\n**{{{getBody()}}} - returns the actual ~JavaScript source code\n**{{{invoke(_obj, _params)}}} - invokes the method. _obj is the context object to call the method on, pass null if the method is a static method. _params are the parameters to pass to the method
The Minimizer object strips out comments and compresses the source to reduce the amount of data that has to be ship across the wire. It is used in the ClassTransporter if the persist classes setting is true.\n\n[[Minimizer.constructor]]\n{{{\nnew runtime.Minimizer() -> Minimizer object\n}}}\n[[Minimizer #minimize]]\n{{{\nminimize(_comment, input, level) -> string\n}}}
Mixing in a Class is an effective way expand your classes functionality. Here's an example of what it looks like to mixin a Class.\n{{{\npackage com.mycomp.mydepart.myapp;\nclass FooMixin\n{\n static methodOne(){ */ code /* }\n static methodTwo(){ */ code /* }\n}\n}}}\n{{{\npackage com.mycomp.mydepart.myapp;\nimport com.mycomp.mydepart.myapp.FooMixin\nclass BooClass mixin FooMixin\n{\n instance booMethod(){ */ code /* }\n}\n}}}\nThis is all you have to do to get ~BooClass to also magically get ~FooMixin's methodOne and methodTwo methods. See jsx.collections.Enumerable for and example of a mixin class that is used by Array, String, jsx.collections.~AbstractCollection and jsx.collections.~AbstractMap classes.
Lets take a look at our Foo class again...\n{{{\n1. package com.mycompany.mydept.myapp;\n2. import com.mycomany.mydepart.myapp.Bar;\n3. class Foo\n4. {\n5. Foo()\n6. {\n7. }\n8. instance callBar()\n9. {\n10. var hold = Bar.callingAStaticMethod();\n11. }\n12.}\n}}}\nLine 1 defines the package for Foo class. Together with the class name Foo from line 3, the fully qualified class or namespace of the class is formed and the final outcome is ''com.mycompany.mydept.myapp.Foo''. This is a completely different class then //com.mycompany.mydept.Foo//... this will not stomp on ''com.mycompany.mydept.myapp.Foo'' or vise versa.\n\nLine 2 indicates that the class com.mycomany.mydepart.myapp.Bar is used somewhere within the com.mycompany.mydept.myapp.Foo class. Instead of always putting //com.mycomany.mydepart.myapp.Bar// wherever Bar is reference, simply put Bar and let ~JavaScript SDK take care of putting the correct namespace.
Core ~JavaScript, meaning the ~JavaScript provided to you by your browser, makes nine classes available to start developing with. These are...\n*Array\n*Boolean\n*Date\n*Function\n*Math\n*Number\n*Object\n*~RegExp\n*String\nSince ~JavaScript supports open classes(the ability to modify the class definition at runtime, in most cases add methods), ~JavaScript SDK added new methods not provided from the core ~JavaScript. The ''String'' classes has many new methods to make the class more robust. View the source or the API to see the new additions.
The main objective of ~JavaScript SDK is to improve the ~JavaScript language. Not that ~JavaScript is a bad language, it just lacks a standard way of doing things. My attempt is to provide a way to avoid the ~JavaScript pains that most developers have faced and deliver a library that will be the de facto for this amazing language.\n\nHere is a brief list of features for ~JavaScript SDK\n* Lazying loading of ~JavaScript class files (Class Loading)\n* Encourage OOP coding style\n* Fix the namespacing clashes common when incorporating many ~JavaScript libraries\n* Made the language less verbose\n* Only one library to use. Finally!!!\n~JavaScript SDK is a cross browser library. The following browsers have been tested with the unit test framework provided with ~JavaScript SDK.\n*Internet Explorer 6 and 7\n*Mozilla Firefox\n*Safari\n*Opera\n*Java using Rhino and JDK 6.0 (not a browser :))\nPlease see the [[User Guide]] for a quick introduction. It contains installation and configuration instructions along with an explanation of the required runtime class files.\nTo download ~JavaScript SDK, click [[here|http://sourceforge.net/project/showfiles.php?group_id=194207&package_id=230297&release_id=505772]].\nTo view the source from Subversion, click [[here|http://js-sdk.svn.sourceforge.net/viewvc/js-sdk/]].\n
The Package object gives you the ability to operate on a package of an object.\n*{{{Package}}} - \n**{{{getName()}}} - returns the name of the package\n**{{{getClasses()}}} - returns an array of class objects that are in the package and have been loaded by the [[ClassLoader]]
Since ~JavaScript SDK syntax is run through a [[PreProcessor]] in to valid ~JavaScript syntax, it would be useful to capture that output so the source can be examined to see if the ~PreProcessor is doing its job correctly.\n\nThe values from ''$~JSRE_CONFIG.persistClasses'', ''$~JSRE_CONFIG.srcDir'', ''$~JSRE_CONFIG.outputDir'' are used to persist the output. Change these values to fit your environment. If you don't change them, create the directory ''output'' in the same directory as ''src'' and change the values of ''$~JSRE_CONFIG.persistClasses'' = ''true''. Run one of the unit test html files in the ''html'' directory to see the output being written to you local disk.
The PreProcessor object accepts the ~JavaScript source and strips the class definition to be able the create a namespace for the class, load dependences, and set up the class hierarchy. It also translates the Method Definition keywords into valid ~JavaScript code. See [[What's this syntax]] for the valid keywords.\n\n[[PrePreprocessor.constructor]]\n{{{\nnew runtime.PreProcessor(_classTransporter) -> PreProcessor object\n}}}\n[[PreProcessor#preprocess]]\n{{{\npreprocess(_jsCode) -> object {\n pakage : pakage,\n clazz : clazz,\n fqClass : fqClass,\n fqSuperClass : fqSuperClass,\n imports : fqcImports,\n mixins : mixins,\n interfaces : interfaces,\n jsCode : newCode,\n nativeCode : _jsCode\n}\n}}}
Having a good reflection mechanism is essential in any programming language. ~JavaScript SDK provides the Class object that gives all your reflection needs. If you are dealing with an object, such as\n{{{var list = new jsx.collections.ArrayList();}}}\n{{{var clazz = list.getClass();}}}\n\nor if you have only a class\n\n{{{var clazz = jsx.collections.ArrayList.klass;}}}\n\nwill get you the Class object.\n\nAs you can see, the static variable on the ~ArrayList class is ''klass''. Unfortanatly ''class'' is a reserved word in core ~JavaScript, the easiest word that came to mind was ''klass''. Once you have the class object, you can start reflecting on the class or object. Here's a glance at the API\n*{{{Class}}}\n**{{{getName()}}} - returns the fully qualified name of the class\n**{{{getSuperclass()}}} - returns the class's parent class object\n**{{{getFields()}}} - returns an array of [[Field]] objects\n**{{{getField(_name)}}} - returns a single Field object for the passed in _name\n**{{{showFields()}}} - returns a string listing all the fields available to the class, climbs up the class hierarchy\n**{{{getDeclaredFields()}}} - returns an array of Field objects only declared on the class\n**{{{getDeclaredField(_name)}}} - returns a single Field object for the passed in _name\n**{{{showDeclaredFields()}}} - returns a string listing all the fields available to the class, does ''not'' climbs up the class hierarchy\n**{{{getMethods}}} - returns an array of [[Method]] objects\n**{{{getMethod(_name)}}} - returns a single Method object for the passed in _name\n**{{{showMethods()}}} - returns a string listing all the methods available to the class, climbs up the class hierarchy\n**{{{getDeclaredMethods()}}} - returns an array of Method objects only declared on the class\n**{{{getDeclaredMethod(_name)}}} - returns a single Method object for the passed in _name\n**{{{showDeclaredMethods()}}} - returns a string listing all the methods available to the class, does ''not'' climbs up the class hierarchy\n**{{{getConstructor()}}} - returns a [[Constructor]] object\n**{{{getPackage()}}} - returns a [[Package]] object\n**{{{newInstance()}}} - returns a new instance of the class, pass any number of parameters\n**{{{getClasses()}}} - returns an array of class objects that the current class has references to\n**{{{getInterfaces()}}} - returns an array of class objects that the current class is implementing\n**{{{getMixins()}}} - returns an array of class objects that the current class is mixing in\n**{{{isChildOf(_object)}}} - returns a boolean indicating if the passed in _object is a child of the current class\n**{{{isSuperOf(_object)}}} - returns a boolean indicating if the passed in _object is a parent of the current class\n**{{{isInstance(_object)}}} - returns a boolean indicating if the passed in _object is an instance of the current class\n**{{{isImplementing(_class)}}} - returns a boolean indicating if the current class is implementing the passed in _class\n**{{{isMixingIn(_class)}}} - returns a boolean indicating if the current class is mixing in the passed in _class
Two items worth mentioning are the global objects below used to configure ~JavaScript SDK. You can define these in your html file and set the declared properties of your choice to override the defaults. Or you can just change the property values directly in Runtime.js\n*$JSRE_CONFIG\n*$JSRE_LOCATION\n\n\n
The Runtime Console will be your best friend during your development using ~JavaScript SDK. To see the Runtime Console in action you must load the ~RuntimeConsole class and instantiate the class.\n{{{\nClassLoader.loadClass("jsx.ui.RuntimeConsole");\nvar rc = new jsx.ui.RuntimeConsole();\n}}}\n\nThis will display a draggable container that shows a tree of the environment and the loaded classes. To drag the container, hold down the control key, left click the mouse, and then move the mouse. Explore the tree, you can see a lot of useful information about the loaded classes. In the near future, you will be able to enter ~JavaScript commands and see them execute.\n\nScreenshot of the ''~RuntimeConsole''\n[img[RuntimeConsole.png]]
What //~JavaScript// should be and can be
//~JavaScript// Software Development Kit
Writing unit tests for your classes improves the reliability of the code that's written. ~JavaScript SDK provides a unit test framework that is very similar to ~JUnit, to help developers unit test their code. See the jsx.tunit.framework, jsx.tunit.runner, jsx.tunit.textui packages for the API.\n\nAll of the ~JavaScript SDK jsx.lang.* and jsx.collections.* classes have unit tests. Please see ''test.jsx.lang'' or ''test.jsx.collections'' packages to see an example of how to use the Test Unit API.\n\nBelow is a list of some of the html test files that runs unit tests and display a graphical out.\n*{{{unit-test.jsx.html}}} - this will run every test under the ''jsx'' package\n*{{{unit-test.jsx.lang.html}}} - this will run tests under the ''jsx.lang'' package\n*{{{unit-test.jsx.lang.util.html}}} - this will run tests under the ''jsx.lang.util'' package\n*{{{unit-test.jsx.collections.html}}} - this will run tests under the ''jsx.collections'' package\n*{{{unit-test.jsx.collections.comparators.html}}} - this will run tests under the ''jsx.collections.comparators'' package
This User Guide is comprised of...\n*[[Features]]\n*[[Installing / Configuring]]\n*[[What's this syntax]]
~JavaScript SDK changed the syntax of the Standard ~JavaScript language. What I do is run the ~JavaScript SDK syntax through a [[PreProcessor]] object to strip out ~JavaScript SDK keywords for the class definition and also translate other syntax into valid ~JavaScript to be run by all browsers. Here's an overview of he syntax to make ~JavaScript SDK possible. If you are familiar with Java or C#, this will be a layup for you.\n*Class Definition keywords \n**''package'' - defines part of the namespace. Only one //package// per Class. If you omit the //package//, you don't have a namespace, the class is a global class, just like Array\n**''import'' - defines a dependency in the class. Many //import//s are allowed. Fully qualified classes will be loaded before the current class is loaded\n**''class'' - defines the final part of the namespace. Only one //class// per Class\n**''extends'' - sets up the class hierarchy. Only one //extends// per Class\n**''implements'' - defines the current Class's behavior. The classes listed after the //implements// keyword are used to validate that current Class implements the correct methods\n**''mixin'' - This is a new one. Only one //mixin// keyword per Class. The classes listed after the //mixin// keyword will make the current Class assume the //static// methods in the mixed in class\n*Method Definition keywords\n**''instance'' - defines an instance method\n**''static'' - defines a static method\n**''abstract'' - defines an instance method that needs to be implemented in a subclass. It just throws a message "<class>.<method> is abstract"\n**''super([arg, arg, ...n])'' - Used this to initialize the parent object during the initialization of the child class.\n**''super.''[~STATIC_VAR | methodName] - This is a reference to a static variable in the super class or call a method in the super class.\n*Constructor\n**{{{MyClass(_text)}}} - every class needs a constructor. You can pass any number of arguments to the constructor to initialize your object. Therefore, {{{var myClass = new MyClass('this is a test')}}} will pass 'this is a test' to the _text local variable to be used in the constructor function\n