# Presentation: 277295

## Java Application Shell 

**Java Application Shell**** **
**A Framework for Interactive Java Applications**
***Goddard Space Flight Center Code 588***
***Advanced Architectures and Automation Branch***
**Phil Miller, Commerce One, Inc.**
**June 28, 2001**

## Agenda	

**what is it?**
**XML for menubars, toolbars**
**plugin framework**
**scripting**
**DAG editor**
**jini browser**
**preferences**
**APIs**
**future directions**
**demonstrations (here after one hour)**
**detail charts, discussions, etc.**

## Contacts

**Carl Hostetter **_**[carl.hostetter@gsfc.nasa.gov ](mailto:carl.hostetter@gsfc.nasa.gov)**_
**Lee Peters **_**[lee.peters@commerceone.com ](mailto:lee.peters@commerceone.com)**_
**Babatunde Akinsanya **_**[babatunde.akinsanya@commerceone.com](mailto:babatunde.akinsanya@commerceone.com)**__** **_
**Phil Miller **_**[philip.miller@commerceone.com](mailto:philip.miller@commerceone.com)**_
**downloads and documentation:**
**http://invision.gsfc.nasa.gov/jas**

## Projects Using/Evaluating JAS

**ASTAT**
**Everett Cary)**
**CVS **
**Jason Coleman**
**GOCG**
**Carl Cornwell**
**Oscar**
**Walt Moleski**

## JAS: What is it?

**infrastructure for an interactive Java application**
**extension of Image2000 infrastructure**
**swing-based **
**features:**
**actions, menubars, toolbars defined in XML**
**plugin framework**
**scripting**
**general-purpose Jini browser**
**property and preference management**
**others: logging, printing, MDI, SDI, JavaHelp, undo/redo**

## Philosophies

**100% Java**
**everything a plugin**
**developer tailorability via factories, subclassing**
**end-user tailorability**
**URL-think:  plugins, scripts, icons ...**
**use work of others (Rhino, Apache logger, ...)**
**scripting:  seamless implementation languages**
**minimize startup time (deferred class loading)**
**automatic CLASSPATH**
**lightweight**

## Actions

**Swing concept: object that implements application function: open, close, help, ...**
**action instance: may appear on any number of menus, toolbars, buttons, etc.**
**maintains enable/disable state **
**and propagates the enable/disable state**
**other attributes:**
**icon, tooltip, title**
**configurable (e.g., zoom, help)**
**plugin: collection of actions**

## Actions cont’d

**MyAction**

**toolbar**

**menubar**

**JComponent**

**actionPerformed()**

**actionPerformed()**

**actionPerformed()**

**proppertyChange()**

**proppertyChange()**

**proppertyChange()**

**application**

**setEnabled()**

**setValue()**

**Note: Action can have properties, i.e., ZoomAction class could have multiple instantiations, one for 200%, one for 300%, ... **

## Action cont’d

**deferred**** ****class loading (instantiation=“deferred”)**

**jas.PluginAction**
**(instantation required during initialization)**

**MyAction**
**(standard Swing Action)**

**GUI components**

**propertyChange()**

**actionPerformed()**

**instantiation**

**actionPerformed()**

**propertyChange()**

## XML Action Definition

- <!-- example action implemented in Java -->
- <java id=“i2k.import-cdf” class="gov.nasa.gsfc.i2k.main.ImportCdf“
- 	title=“import CDF file”  shortDesc=“open image from CDF file”                  	icon=“cdf.gif">
- </java>

- <!-- example action implemented via in-line JavaScript -->
- <script id="memory" title="show memory" icon="script.gif“ 	language=“JavaScript”>
-         totalBytes = java.lang.Runtime.getRuntime().totalMemory();
-         totalBytes = Math.round(totalBytes/1024);
-         alert ("total memory: " + totalBytes + " KBytes" );
- </script>
- <!-- example action reference from file -->
- <script id=“myFeature” title=“My Feature” icon=“mine.jpg”
-    src=“scripts/MyFeature.js”/>

## XML Menubar Definition

-     <menu title="File" mnemonic="F">
-         <menu title="New..." mnemonic="N">
-             <item action=”i2k.import-cdf"  mnemonic="I" />
-             <item action=”i2k.new-stack"  mnemonic="s" />
-             ...
-         </menu>
-         <item action=”i2k.open" accelerator=“control O" mnemonic="O" />
-         <item action=”i2k.save" accelerator=“control A" mnemonic="A" />
-         ...
-     </menu>
- </menuBar>

**XML Menubar Definition**

- Note: Toolbar similar (not shown)

**reference to previously defined Action id**

## Plugin Framework

**an application is:**
**collections of (plugin) actions**
**plus XML to define menubars, toolbars**
**a plugin is a jar file**
**META-INF/jas-plugin.xml**
**plus icons, scripts, classes (resident in the jar file)**
**plugin jar may be remote and/or dynamic**
**JAS discovers plugins during initialization**
**from application tree**
**from user tree**
**jas.plugins property**
**JAS reads XML for menubars *****after***** loading plugins **

## jas-plugin.xml example

**...**
**<plugin id="jas.SampleApp" name="JAS Sample Application"**
**    ****release="1.00.000" helpset="help/help.hs">**
**    ****<actions>**
**        ****<!-- java action to open a new empty child frame of the sample app -->**
**        ****<java id="SampleApp.new"**
**            ****guiPlacement="demo"**
**            ****class="sampleapp.NewAction"**
**            ****title="New Sample Application frame..."**
**            ****shortDesc="new document"**
**            ****icon="new.gif">**
**        ****</java>**
**        ****<!-- this does similar thing as the “new” java action but from a script -**
**        ****<script id="SampleApp.new.script"**
**            ****guiPlacement="demo"**
**            ****src="new.js"**
**            ****title="New Sample Application frame from script..."**
**            ****shortDesc="starts a frame of the Sample Application (via script)"**
**            ****icon="new.gif">**
**        ****</script>**
**        ...**

## jas-plugin.xml example cont’d

**...**
**        ****<!-- init script -->**
**        ****<script id="sampleApp.init"**
**            ****type="init"**
**            ****title="Sample Application initialization script"**
**            ****src="init.js">**
**        ****</script>**
**    ****</actions>**
**    ****<preferencesPanel id="sampleapp.documentsPanel"**
**        ****title="Document Preferences" class="sampleapp.DocumentPanel">**
**        ****<preference name="jas.SampleApp.file.dir"**
**            ****title="Documents Directory"**
**            ****value=“${jas.app.dir}/data"**
**            ****shortDesc="Documents Directory" />**
**        ****<preference name="jas.SampleApp.undo.limit"**
**            ****title="Undo Limit"**
**            ****value="25"**
**            ****shortDesc="Level of Undo/Redo"/>**
**    ****</preferencesPanel>**
**</plugin>**

## Scripting

**provides additional implementation languages**
** ****user-seamless**
**Bean Scripting Framework:**
**from IBM alphaworks (open source)**
**JAS tested with JavaScript, JPython**
**access to underlying Java classes**
**uses for scripting:**
**action implementation **
**initialization, shutdown**
**unit-level Java class testing**
**testing via user simulation**
**remote scripts:  major security hole**

## DAG Editor

**DAG: directed-acyclic graph**
**model: image processing pipeline**
**generalization of the Image2000 DAG editor**
**JAS supplies the editor framework**
**specialization via application subclasses**
** ****DAGs stored as XML**
**or any other format via method override**

## DAG editor cont’d

## Jini Browser

**general-purpose service browser**
**a JAS Action**
**navigates Jini services**
**unicast option: target a specific lookup service**
**display service characteristics**
**activate a registered Action for the interface**
**activate serviceUI of service**
**Beware:  classes-over-the-net**

## Preferences

**preference**
**a property**
**exposed to end-user for GUI editing**
**persistent**
**PropertyChangeEvents to listeners**
**declared as part of plugin**
**preferences grouped into PreferencePanels**
**preference dialog: shows each panel as tab**

## Preferences – cont’d

**stored in {user.home}/*****appname*****/preferences**
**load sequence for properties:**
**application properties**
**user properties**
**preferences**
**open issue: JDK 1.4 preferences architecture**

## APIs

**document and frame management:**
**MDI (several styles) or SDI**
**application code is independent of MDI/SDI**
**based on Swing JInternalFrame, DesktopManager**
**document close, save, saveAs, ...**
**cut/copy/paste**
**per-frame undo/redo stack**
**preference management and notification**

## APIs cont’d

**logging: Apache’s log4j**
**highly recommended**
**dynamically configurable**
**category-based**
**JavaHelp**
**context-sensitive help**
**driven by helpId property on actions**
**general-purpose HelpTopicAction:**
**driven by helpId property**
**help database merging for plugins**
**print and print preview:  from SEA**

## Future Directions

**support plan:**
**June: Release 1.2**
**startup wizard**
**richer graph (DAG) editor**
**InstallAnywhere**
**September: Release 1.3**
**Beyond:  support and maintenance**

## Future Directions cont’d

**candidate features:**
**BSF 2.2: more scripting languages**
**code generation**
**GUI editor for menus, toolbars, plugins**
**security for remote plugins, scripts**
**better support for testing (via user simulation)**
**interactive script editor/runner**

## Demonstration

**general MDI experience, undo/redo, etc.**
**MDI/SDI switch; MDI styles**
**surf the menus **
**DAG editor**
**preferences**
**scripting:**
**scripted-test.js**
**surf the scripts**
**script that asks for eval’d input**
**remote plugins, scripts**

## detail charts	

**XML notes**
**logging with Apache’s log4j**
**AppFrameAction: general-purpose Action**
**security: remote plugins, Jini, remote scripts**
**initialization sequence**
**directory structure, CLASSPATH synthesis**
**problems with URL-think**
**putting existing app under JAS**
**JAS versus Image2000 infrastructure**
**MDI framework**
**undo/redo framework**
**JavaHelp support**
**other features**
**problem areas**

## XML notes

**XML Schemas (new with JAS 1.1)**
**parsing: Apache Xerces and Ant **
**conditional tags:**

**<menu if=“${os.name} = Windows 2000” ...>**
**    ...**
**</menu>**

## logging via Apache’s log4j

**highly recommended**
**characteristics**
**open source**
**highly configurable**
**dynamically configurable**
**low overhead when logging disabled**
**features**
**configure down to class level**
**“****tee” to several destinations**
**source file and line number of logging call**
**rotating file wrap**

## log4 coding

**import org.apache.log4j.Category; **
**public class MyClass { **
**	****static Category log = Category.getInstance(MyClass.class); **
**	****... **
**	****log.debug ("debug output: “ + getCount() + “ bytes handled”); **
**	****log.info ("info output"); **
**	****log.warn ("warn output"); **
**	****log.error ("error output");**
**	****log.debug (someObject);****	****// formatting done AFTER enable check! **
**	****Log.appcat.debug (“debug output”);  // log to common category**
**	****System.out.println (“third party code”);  // JAS can direct to log4j**
**} **

## log4j versus JDK 1.4 logging

**log4j is an Apache open source project**
**JDK 1.4 logging:  from JSR process**
**similar  class architecture:**
**Logger (JDK) == Category (log4j)**
**Level (JDK) == Priority (log4j)**
**Handler (JDK) == Appender (log4j)**
**Formatter (JDK) == Handler (log4j)**
**good argument for log4j at http://jakarta.apache.org/log4j/**

## AppFrameAction

**general-purpose Action class**
**calls method on the active application frame**
**properties:**
**method name**
**features:**
**disables Action when no suitable frame active**
**shows hourglass cursor**
**invokes method (via reflection) on currently-active application frame**
**popup message for exceptions **

## security

**areas of concern:**
**remote plugins (jar files)**
**Jini classes loaded over the net**
**remote scripts**
**java -Djava.security.manager=default**** **
**policy files properly handle remote plugins and Jini classes**
**remote plugins: very dangerous without security manager**
**Jini: requires**** ****security manager**
**remote scripts:  especially dangerous **
**interpreted by trusted classes!**
**variability in security provisions among languages**
**Rhino**** ****JavaScript: good hooks, not mature**

## initialization sequence

**read app properties: {jas.app.url}/properties**
**read user properties: {jas.user.url}/properties**
**read preferences: {jas.user.url}/preferences**
**load plugins (action definition)**
**read app properties: {jas.app.url}/final-properties**
**read user properties: {jas.app.url}/final-properties**
**read preferences again: {jas.user.url}/preferences**
**build menubars, toolbars**
**run initialization actions**
**open command line documents**
**run command line scripts**

## directory structure

**app root**

**jre**

**lib**

**ext**

**lib**

**properties**
**jas-menubars.xml**
**jas-toolbars.xml**

**plugin1.jar**
**plugin2.jar**
**api1.jar**
**api2.jar**
**...**

**jas-N.N.jar**
**jaxp.jar**
**rhino-1.5.jar**
**...**

**bin**

**CLASSPATH synthesis**

## problems with URL-think

**URL-think: **
**all file properties are URLs**
**in XML, relative file rooted at current directory**
**entire application can be remote:**
**java –Djas.app.url=http://xxx/yyy ... jas.main.Main**
**plugins, scripts may be remote**
**however:**
**you will get tired of file://c:/xxxx for c:/xxxx**
**no file discovery within URL directory**
**other APIs want paths not URLs**
**JFileChooser wants a path**
**cannot write to an URL**

## putting existing app under JAS

**identify, code XML for menu Actions:**
**if public classes: straightforward**
**if inner/anonymous classes: use in-line script!**
**code menubars/toolbars as XML**
**use existing main method**
** ****use jas.Main.getInstance() as main Jframe**
**let JAS do its own menus**

## script as “action bridge”

**------ existing code --------**
**    ****...**
**    ****MenuItem item = new MenuItem("Foo");**
**    ****item.addActionListener (new ActionListener() {**
**        ****public void actionPerformed (ActionEvent evt) {**
**           ****doFoo(evt);**
**        ****}**
**    ****});**
**    ****...**
**    ****public static void doFoo(ActionEvent evt) {**
**        ****...**
**    ****}**
**------- JAS XML definition of the menu ---------**
**    ****<script**
**        ****id="app.foo" title="Foo"**
**        ****shortDesc="execute a foo operation"**
**        ****icon="icons/foo.jpg" language="javascript">**
**        ****Packages.gov.nasa.gsfc.irc.Foo.doFoo (_actionEvent);**
**    ****</script>**

## JAS vs Image2000

**plugin is now a jar file and may be remote**
**JAS is 100% Java (no native launcher)**
**generalized scripting: BSF and multiple languages**
**simplified directory structure**
**files more consistently specified as URLs **
**jas-menubars.xml and jas-toolbars.xml**

## Multi-Document Interface

**based on Swing’s JInternalFrame**
**jas.main.AbstractAppFrame: **
**superclass for document frames**
**sets menubar according to frame type**
**printing**
**cut/copy/paste enable/disable actions (per-frame)**
**undo/redo enable/disable actions (per-frame)**
**save => saveAs conversion**
**close: dirty document handling**
**exit: dirty document handling for all frames**
**SEA print and print preview**
**SampleApp demonstrates**

## undo/redo framework

**a fundamental of friendly GUIs **
**framework based on ****javax.swing.undo**
**multi-level undo/redo**
**per-frame undo/redo stack**
**AbstractAppFrame handles enable/disable of the undo/redo actions**
**non-trivial to implement the application part**
**SampleApp demonstrates**

## JavaHelp support

**JavaHelp 1.1 from sun (freebie)**
**no authoring tools**
**JAS actions:  *****Contents*****, *****Index*****, *****Search, On Item, About***
**plugin actions:**
**“****On Item” help available automatically **
**helpId assigned from XML**
**plugins: help database merged automatically**
**general-purpose HelpAction class**
**each instance has helpId property**

## other features

**macro substitution in properties:**
**irc.myprop=${jas.app.dir}/data**
**honored in property files and XML files**
**property ****jas.allow.remote.script**
**menubar/toolbar factory (with scripting)**

## some problem areas

**complexity of the problem (MFC)**
**volume of documentation**
**properties:**
**many sources (preferences, plugins, ...)**
**complex loading sequence**
**Swing bugs**
**security for remote plugins, scripts**