Try OpenEdge Now
skip to main content
Java Open Clients
Extending Proxy Objects : Example of extending proxy objects
 

Example of extending proxy objects

For the Java client, ProxyGen generates two class files for each object. One contains the implementation, and the other is a delegating class that just calls this implementation class. The Java client code accesses the delegating classes. The delegating classes are created so the Java client is not exposed to implementation details of the proxy. These delegating classes are available for inheritance in Java while the implementation classes are final and cannot be extended.
Caution: Direct editing of any delegating class generated by ProxyGen is not supported. To modify a delegating class, you must extend (subclass) it.
For example, if we have an Account AppObject and a Tax SubAppObject, ProxyGen generates the implementation classes AccountImpl.java and TaxImpl.java and the delegating classes Account.java and Tax.java.
The following table shows a skeleton of the Account delegating class.

Example: Delegating class

Public class Account
{ protected AccountImpl m_accountImpl;
public Account(connect-parameters)
{
m_accountImpl = new AccountImpl(connect-parameters);
}
public void Add(add-parameters)
{
m_accountImpl.Add(add-parameters);
}
public Tax createAO_Tax()
{
return new Tax(m_accountImpl);
}
public AccountInfo createPO_AccountInfo(AccountInfo-parameters)
{
return new AccountInfo(m_accountImpl, AccountInfo-parameters);
}
public _release()
{
m_accountImpl._release();
}
...
}
Note the protected member variable m_accountImpl. If a SubAppObject or a ProcObject is created, this variable must be passed to its constructor.
The following example shows the constructor in the Tax class.

Example: SubAppObject/ProcObject constructor

Public class Tax
{  protected TaxImpl m_taxImpl;
  public Tax(AccountImpl accountImpl)
{
    m_taxImpl = new TaxImpl(accountImpl);
}
   
}
The member variables are protected rather than private, to allow a Java client to extend these classes.
The following example shows how a client might extend the Account and Tax classes.

Example: Class extensions

Public class MyAccount extends Account
{ public MyAccount(parameters)
{
super(parameters);
}
public MyTax createAO_MyTax()
{
return new MyTax(m_accountImpl);
}
public sendMail() // a new method
{
/*** Do my own thing ***/
}
}Public class MyTax extends Tax
{ public MyTax(AccountImpl accountImpl)
{
super(accountImpl);
}
public SetStatus(int status) // override Tax's method
{
/*** Do my own thing and then defer to superclass ***/
super.SetStatus(status);
}
}
Note: To extend a SubAppObject or ProcObject, you also must extend the associated AppObject.