Make the following changes to the component implementation:
Add the state accessor methods Add methods with the names specified in the State Methods field in the Persistence/General tab in the Component Properties dialog box. Also add an instance variable of the generated state type. For example:
import TheCart.CartState; private CartState data = new CartState(); private int lastItem = 0; TheCart.CartState getState() { return data; } void setState(TheCart.CartState state) { data = state; }
Add code to initialize the state type Add code to your comonents’ ctsCreate method to initialize the state type. For example:
public void ctsCreate( name, address, phone, capacity) { data.name = name; data.address = address; data.phone = phone; data.items = new ShoppingCartItem[capacity]; }
These assignments correspond to the IDL structure fields in the example above. The items IDL sequence is represented by an array in Java.
Add code to access the state data from business methods Where appropriate, the bean’s business methods should read and write from the state type. For example, these methods add an item to the shopping cart and return the customer’s name, respectively:
public void addItem(String item, int quantity) { .... lastItem++; data.items[lastItem] = new ShoppingCartItem(item, quantity); .... } public String getCartName() { return data.name; }
Copyright © 2005. Sybase Inc. All rights reserved. |