//
// Beanshell script to run the aop tree cache demo
//
import org.jboss.cache.PropertyConfigurator;
import org.jboss.cache.aop.PojoCache;
import org.jboss.cache.aop.test.*;
// Tx imports
import javax.transaction.UserTransaction;
import javax.naming.*;
import org.jboss.cache.transaction.DummyTransactionManager;

show();  // verbose mode

// Set up transaction manager
//System.setProperty(Context.INITIAL_CONTEXT_FACTORY,
  //  "org.jboss.cache.transaction.DummyContextFactory");
DummyTransactionManager.getInstance();

prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,
    "org.jboss.cache.transaction.DummyContextFactory");
tx = (UserTransaction)new InitialContext(prop).lookup("UserTransaction");

tree = new PojoCache();
config = new PropertyConfigurator();
// configure tree cache. 
config.configure(tree, "META-INF/replSync-service.xml");

joe = new Person();
joe.setName("Joe Black");
joe.setAge(31);

addr = new Address();
addr.setCity("Sunnyvale");
addr.setStreet("123 Albert Ave");
addr.setZip(94086);

joe.setAddress(addr);

tree.startService();  // kick start tree cache
tree.putObject("/aop/joe", joe); // add aop sanctioned object

// since it is aop-sanctioned, use of plain get/set methods will take care of cache content automatically.
// This is also transacted.
tx.begin();
joe.setAge(41);
tx.commit();



//joe.languages=new ArrayList();
//joe.languages.add("German");
//joe.languages.add("French");

//joe; // this will cause NPE



// tree.stopService(); // will stop the cache
