home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-cocoon-addon-1.4.9-installer.exe / java.xml < prev    next >
Encoding:
Extensible Markup Language  |  2004-07-12  |  5.0 KB  |  165 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.   Copyright 1999-2004 The Apache Software Foundation
  4.  
  5.   Licensed under the Apache License, Version 2.0 (the "License");
  6.   you may not use this file except in compliance with the License.
  7.   You may obtain a copy of the License at
  8.  
  9.       http://www.apache.org/licenses/LICENSE-2.0
  10.  
  11.   Unless required by applicable law or agreed to in writing, software
  12.   distributed under the License is distributed on an "AS IS" BASIS,
  13.   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.   See the License for the specific language governing permissions and
  15.   limitations under the License.
  16. -->
  17. <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.0//EN" "document-v10.dtd">
  18.  
  19. <document>
  20.   <header>
  21.     <title>Advanced Control Flow</title>
  22.     <authors>
  23.       <person name="Christopher Oliver" email="coliver@apache.org"/>
  24.     </authors>
  25.   </header>
  26.  
  27.   <body>
  28.     <anchor id="Java"/><s1 title="Calling Java">
  29.     <p>
  30.     You can easily call Java code from your Flowscripts, for example:
  31.     </p>
  32.     <source>
  33.     var map = new java.util.HashMap();
  34.     map.put("foo", "bar");
  35.     </source>
  36.    <s2 title="Imports">
  37.  
  38.     <p>Classes in packages under <code>java</code> are accessible directly in your scripts.</p>
  39.     <p>Note that classes under <code>java.lang</code> are not automatically imported, however:</p>
  40.  
  41.     <source>var n = new java.lang.Integer(3);</source>
  42.  
  43.     <p>All other java packages and classes are accessible under the property <code>Packages</code>:</p>
  44.  
  45.     <source>var tree = new Packages.javax.swing.JTree();</source>
  46.  
  47.     <p>You can get the effect of Java imports using the <code>importPackage()</code> and <code>importClass()</code> functions:</p>
  48.     <table>
  49.      <tr>
  50.        <td>
  51.        In Java:
  52.        </td>
  53.        <td>
  54.        In JavaScript:
  55.        </td>
  56.      </tr>
  57.      <tr>
  58.        <td>
  59.        import foo.*;
  60.        </td>
  61.        <td>
  62.        importPackage(Packages.foo);
  63.        </td>
  64.      </tr>
  65.      <tr>
  66.        <td>
  67.        import foo.Bar;
  68.        </td>
  69.        <td>
  70.        importClass(Packages.foo.Bar);
  71.        </td>
  72.      </tr>
  73.     </table>
  74.     <p>Example:</p>
  75.      <source>
  76.     importPackage(java.util);   
  77.     var set = new TreeSet();</source>     
  78.     <p>
  79.     </p>
  80.    </s2>
  81.    <s2 title="Bean Properties">
  82.     <p>
  83.       If your Java classes have getters and setters you can access them as properties in JavaScript:</p>
  84. <source>
  85.     var d = new java.util.Date();
  86.     d.year = 2003;    // same effect as d.setYear(2003);
  87. </source>     
  88.       <p/>
  89.    </s2>
  90.    <s2 title="Dynamic Compilation">
  91.    <p> 
  92.     Cocoon includes an embedded Java compiler that can dynamically compile Java source files and load and execute the resulting classes at runtime. During development you can take advantage of this capability to rapidly develop, test, and debug your applications. The Cocoon source resolver is used to locate source files.
  93.    </p>
  94.    <p>Example:</p>
  95. <source>
  96.  
  97.       // Cause com.xyz.MyClass to be compiled and loaded:
  98.       importClass(Packages.com.xyz.MyClass); 
  99.  
  100.       var obj = new MyClass("foo", 123); // call a constructor
  101.  
  102.       obj.someMethod();              // call a method
  103.  
  104. </source>
  105.    <p/>
  106.    <s3 title="Configuration">
  107.  <p>You control this behavior by specifying configuration properties in the <code>cocoon.xconf</code> file located in the WEB-INF/ directory of your application. These properties are located in the <code>component-instance</code> element under <code>flow-interpreters</code> whose <code>name</code> attribute has the value <code>"javascript"</code>. The following properties may be set:
  108.  </p>
  109.     <table>
  110.      <tr>
  111.        <td>
  112.        Property:
  113.        </td>
  114.        <td>
  115.        Description:
  116.        </td>
  117.      </tr>
  118.      <tr>
  119.        <td>
  120.        reload-scripts
  121.        </td>
  122.        <td>
  123.        Determines whether Cocoon should attempt to detect changes to source files and reload them. This applies to both JavaScript and Java source files
  124.        </td>
  125.      </tr>
  126.      <tr>
  127.        <td>
  128.        check-time
  129.        </td>
  130.        <td>
  131.        Specifies an interval in milliseconds after which Cocoon will check for changes to source files (ignored if reload-scripts is false or unspecified)
  132.        </td>
  133.      </tr>
  134.      <tr>
  135.        <td>
  136.        classpath
  137.        </td>
  138.        <td>
  139.        A semicolon separated list of URL's that will be searched for Java source files
  140.        </td>
  141.      </tr>
  142.     </table>
  143.     <p>Example:</p>
  144. <source><![CDATA[
  145.   <flow-interpreters default="javascript" logger="flow">
  146.     <!-- FOM (Flow Object Model) -->
  147.     <component-instance 
  148. class="org.apache.cocoon.components.flow.
  149. javascript.fom.FOM_JavaScriptInterpreter" name="javascript">
  150.       <load-on-startup>resource://org/apache/cocoon/components/
  151. flow/javascript/fom/fom_system.js</load-on-startup>
  152.       <reload-scripts>true</reload-scripts>
  153.       <check-time>4000</check-time>
  154.       <classpath>file:C:/dev/myPackages;src/java</classpath>
  155.       <debugger>enabled</debugger> 
  156.     </component-instance>
  157.   </flow-interpreters>
  158. ]]></source>
  159.    </s3>
  160.    </s2>
  161.     <p/>
  162.     </s1>
  163.   </body>
  164. </document>
  165.