Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

DynamicCast – PB Docs 2018 – PowerBuilder Library

DynamicCast – PB Docs 2018

DynamicCast

Description

Converts an instantiated PowerBuilder proxy object to a proxy for
the passed-in proxy name.

Syntax

Argument

Description

javavm

An instance of the JavaVM class

proxyobject

An instantiated PowerBuilder proxy
object

proxyname

A string containing the name of the proxy to be
instantiated

Return value

Powerobject.

A new proxy object for the Java class referenced by proxyname.
This method returns null if the proxy cannot be created.

Examples

  1. In the following example, the object returned from the
    nextElement method is represented by a proxy for the Employee class.
    The GetActualClass method is used to determine whether the object is
    actually a SalariedEmployee, and if it is, the proxy px_Employee is
    down cast to the proxy px_SalariedEmployee so that the adjustSalary
    method can be called:

  2. In this example, getAllItems returns a java.lang.Object in the
    EJB declaration, which maps to the PowerBuilder Any data type. The
    call to GetInterfaces determines whether what is returned is a
    java.util.List. If it is, a call to DynamicCast obtains a proxy for
    List, which is used to obtain the size of the list before using its
    Get method to obtain the elements of the list. A method such as
    getAllItems can be used in many situations, such as to get a list of
    part numbers for any type of product.

Usage

There are two scenarios in which a Java object returned from a
call to an EJB method can be represented by a proxy that does not
provide the methods you need:

  • If the class of a Java object returned from an EJB method call
    is dynamically generated, PowerBuilder uses a proxy for the first
    interface implemented by the Java class.

  • The prototype of an EJB method that actually returns
    someclass can be defined to return a class that someclass extends or
    implements.

    For example, the prototype of a method that actually returns
    an object of type java.util.ArrayList can be defined to return
    java.util.Collection instead. (The java.util.ArrayList class
    inherits from java.util.AbstractList, which inherits from
    java.util.AbstractCollection, which implements
    java.util.Collection.) If the method prototype has a return type of
    java.util.Collection, PowerBuilder uses a proxy for
    java.util.Collection.

The DynamicCast method allows you to cast the returned proxy
object to a proxy for the interface you require, or for the actual class
of the object returned at runtime so that the methods of that object can
be used.

You can obtain the actual class of the object using the
GetActualClass method. You can also use the DynamicCast method with the
GetSuperClass method, which returns the immediate parent of the Java
class, and the GetInterfaces method, which writes a list of interfaces
implemented by the class to an array of strings.

For example, consider the following class:

GetActualClass returns java.util.LinkedList, GetSuperClass returns
java.util.AbstractSequentialList, and GetInterfaces returns 3 and writes
three strings to the referenced string array: java.util.List,
java.lang.Cloneable, and java.io.Serializable.

See also

CreateJavaVM

GetActualClass

GetInterfaces

GetSuperClass


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x