Chapter 3 DynaScript Predefined Objects


java object

Object

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.

Syntax

To use a java method:

java.MethodName( parameter ) 

Description

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:

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.

Note  

Accessing Java methods and properties
You can access methods from any Java class. Properties, however, can be accessed only from JavaBeans.

Example

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.