Chapter 3 DynaScript Predefined Objects
Allows for manipulation of Java classes within PowerDynamo scripts.
The java object represents an object used for working with a Java class within your Web site.
To use a java method:
java.MethodName( parameter )
To use Java class objects within your Web site, your Web site must be configured to enable Java. Sybase Central allows for easy Java class setup for PowerDynamo Web sites. You should be aware of the following configuration options in the Configuration folder of Sybase Central if you want to create and use instances of Java class objects within your Dynamo scripts:
Java VM
PowerDynamo
supports the Sun Java VM and the Microsoft VM. You must select one
of these VMs for PowerDynamo to support Java.
Java class cache
size
To improve performance, information
about the methods and properties of Java classes is cached. This
option enables you to set the cache size.
Class path for
the mapping
You must specify a path
for class files that are stored in a Dynamo Web site.
Executing from within Sybase Central
To execute scripts that use the Java
object from within Sybase Central, the mapping and Dynamo site name
must be the same.
For more information on PowerDynamo configuration settings in Sybase Central, see "Changing Dynamo configuration settings" in the PowerDynamo User's Guide.
You must specify all parameters when you are working with the java object. Unlike other DynaScript objects, an error occurs if parameters are excluded when calling a Java class method or property.
Accessing Java methods and properties
You can access methods from any Java
class. Properties, however, can be accessed only from JavaBeans.
Let's assume we are working with this class:
class Fibonacchi
{
public long prev1;
public long prev;
public long next;
public long getPrev() { return prev; }
public long getNext() { return next; }
public Fibonacchi()
{
prev1 = 1;
prev = 0;
next = 0;
}
public void generateNext()
{
next = prev1 + prev;
prev = prev1;
prev1 = next;
}
static public double doubleme( double t )
{
return t*2;
}
}
To call this class, your script might look something like this:
// call a static method on the class
result = java.CallStaticMethod( "Fibonacchi", "doubleme", 2.5 );
document.writeln( result );
// create a DynaScript object representing a Java class
fib = java.CreateObject( "Fibonacchi" );
// retrieve a property on the class
document.writeln( "The value of next is " + fib.next + " The value of prev is " + fib.prev );
for( i = 0; i < 20; i++ ) {
// invoke a method on the class
fib.generateNext();
document.writeln( "The value of next is " + fib.next + " The value of prev is " + fib.prev );
}
For more information on using Java in your PowerDynamo scripts see "PowerDynamo and Java" in PowerDynamo User's Guide.
Copyright © 1999 Sybase, Inc. All rights reserved. |