Client-side facade
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   java_rine
Posted On:   Monday, February 25, 2002 12:59 AM

hi, I'm new to the j2ee architecture and would like to seek advice on some of its design patterns (facade). I've read in one of the j2ee design pattern articles regarding session facades that sometimes it might be advisable to use client-side facades on top of server-side facades(normally implemented by session beans). Can anyone give me a case where client-side facades are necessary? I've also come across in one of the sample aplications in Jbuilder5(ESite.jpx) where they have a class called SessionBean which looks like this : ========================================= package com.borland.samples.web; import javax.rmi.*; import javax.naming.*;    More>>

hi,

I'm new to the j2ee architecture and would like to seek advice on some of its design patterns (facade).

I've read in one of the j2ee design pattern articles regarding session facades that sometimes it might be advisable to use client-side facades on top of server-side facades(normally implemented by session beans). Can anyone give me a case where client-side facades are necessary?

I've also come across in one of the sample aplications in Jbuilder5(ESite.jpx) where they have a class called SessionBean which looks like this :

=========================================

			package com.borland.samples.web;
			

import javax.rmi.*;
import javax.naming.*;
import com.borland.dx.dataset.*;
import com.borland.samples.ejb.*;
import com.borland.samples.dm.*;

public class SessionBean {

private Cart cart;
private ClientDataModule clientDataModule;
String bookSearchString = null;

public SessionBean() {
try {
jbInit();
Context context = new InitialContext();
Object object = context.lookup("Cart");
CartHome cartHome = (CartHome) PortableRemoteObject.narrow(object, CartHome.class);
cart = cartHome.create();
clientDataModule.getSessionBeanConnection().setSessionBeanRemote(cart);
// System.out.println("Instantiated sessionBean and Cart reference");
}
catch (Exception ex) {
ex.printStackTrace();
}
}

public Cart getCart() {
return cart;
}
private void jbInit() throws Exception {
clientDataModule = new com.borland.samples.dm.ClientDataModule();
}
public ClientDataModule getClientDataModule() {
return clientDataModule;
}
public void setBookSearchString(String bookSearchString) {
this.bookSearchString = "%" + bookSearchString.toUpperCase() + "%";
}
public String getBookSearchString() {
return bookSearchString;
}
public void addItem(Integer inventoryId) {
try {
cart.addToShoppingCart(inventoryId);
}
catch (Exception ex) {
throw new RuntimeException(ex.toString());
}
}
public boolean addUser(String username) {
try {
DataSetData dataSetData = DataSetData.extractDataSetChanges(clientDataModule.getUserDataSet());
return cart.addUser(new DataSetData [] {dataSetData}, username);
}
catch (Exception ex) {
return false;
}

}
public void removeItem(Integer inventoryId) {
try {
cart.removeFromShoppingCart(inventoryId);
}
catch (Exception ex) {
throw new RuntimeException(ex.toString());
}
}

/**
* Returns true if passed a valid user/password
*/

public boolean logIn(String user, String password) {
try {
return cart.logIn(user, password);
}
catch(Exception ex) {
return false;
}
}
public void logOut() {
try {
cart.logOut();
}
catch (Exception ex) {
ex.printStackTrace();
}

}
public boolean isLoggedIn() {
try {
return cart.isLoggedIn();
}
catch (Exception ex) {
ex.printStackTrace();
return false;
}
}
public Integer getUserId() {
try {
return cart.getUserId();
}
catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}


=============================================

Is this class ( i presume its a JavaBean ) acting as a client-side facade in this case? I expect that it is because in its constructor method SessionBean() , it looks up the the Cart ejb and gets the remote interface of Cart.
Then in the application's JSPs they use codes like :

sessionBean.getCart().getUserId();

From this i guess that they are hiding the complexity of looking up the EJBs by encapsulating it in the SessionBean class and thus, the SessionBean is acting as a client-side facade. Am i right in saying so?

Can anyone pls enlighten me? Thanx :)

   <<Less
About | Sitemap | Contact