FileDocCategorySizeDatePackage
ProfileClient.javaAPI DocExample2737Wed Apr 05 11:25:42 BST 2000stateless

ProfileClient

public class ProfileClient extends Object

Fields Summary
Constructors Summary
Methods Summary
public static javax.naming.ContextgetInitialContext()
Gets an initial context.

return
Context
exception
java.lang.Exception if there is an error in getting a Context

    Properties p = new Properties();
    p.put(Context.INITIAL_CONTEXT_FACTORY,
          "weblogic.jndi.T3InitialContextFactory");
    p.put(Context.PROVIDER_URL, "t3://localhost:7001");
    return new InitialContext(p);
  
public static voidmain(java.lang.String[] args)

    String name = args[0];

    try {
      // Get a JNDI context for our EJB server
      Properties p = new Properties();
      p.put(Context.INITIAL_CONTEXT_FACTORY,
	    // For Ejbhome server
	    "com.ejbhome.naming.spi.rmi.RMIInitCtxFactory");
            // Following two lines for WebLogic server
// 	    "weblogic.jndi.T3InitialContextFactory");
//       p.put(Context.PROVIDER_URL, "t3://localhost:7001");
      Context context = new InitialContext(p);

      // Create a profile server
      ProfileServerHome psHome =
	(ProfileServerHome)context.lookup("stateless.ProfileServerHome");
      ProfileServer server = psHome.create();

      // Ask the server for the person's profile
      System.out.println("Finding profile for " + name);
      Object obj = server.getProfile(name);
      System.out.println("Got " + obj);
      Profile profile = (Profile)obj;

      // Get/set some entries in the profile
      System.out.println("Setting profile entries for " + name);
      profile.setProfileEntry("favoriteColor", "blue");
      profile.setProfileEntry("language", "German");

      System.out.println("Getting profile entries for " + name);
      System.out.println("\tFavorite color: " +
			 profile.getProfileEntry("favoriteColor"));
      System.out.println("\tLanguage: " +
			 profile.getProfileEntry("language"));
    }
    catch (NoSuchPersonException nspe) {
      System.out.println("Invalid person: " + name);
      nspe.printStackTrace();
    } 
    catch (Exception e) {
      System.out.println("Error while creating/using profile server.");
      e.printStackTrace();
    }