package com.sun.s1asdev.jdbc.CustomResourceFactories.ejb; import com.sun.s1asdev.custom.resource.CustomResourceJavaBean; import javax.ejb.*; import javax.naming.*; import javax.sql.*; import java.sql.*; import java.rmi.RemoteException; import java.util.Properties; import java.util.Enumeration; import java.util.Set; import java.util.Iterator; import java.net.URL; public class SimpleBMPBean implements EntityBean { protected Object obj; public void setEntityContext(EntityContext entityContext) { } public boolean testJavaBean(String testValue) { try { InitialContext ic = new InitialContext(); CustomResourceJavaBean o = (CustomResourceJavaBean) ic.lookup("java:comp/env/custom/my-java-bean"); if (o != null) { //System.out.println("Custom Resource : " + o); System.out.println("Custom resource value : " + o.getProperty()); if (o.getProperty().equalsIgnoreCase(testValue)) { return true; }else{ System.out.println("testJavaBean failed"); } } } catch (NamingException e) { e.printStackTrace(); } return false; } public boolean testPrimitives(String type, String value, String resourceName) throws RemoteException { try { InitialContext ic = new InitialContext(); if(!resourceName.startsWith("java:")){ resourceName = "java:comp/env/"+resourceName; } Object o = ic.lookup(resourceName); if (o != null) { System.out.println("Custom resource value : " + o); if (o.toString().equalsIgnoreCase(value)) { return true; } } } catch (NamingException e) { e.printStackTrace(); } return false; } public boolean testProperties(Properties properties, String resourceName) throws RemoteException { try { InitialContext ic = new InitialContext(); Properties p = (Properties) ic.lookup(resourceName); Set keys = p.keySet(); Iterator iterator = keys.iterator(); while (iterator.hasNext()) { String key = (String) iterator.next(); String value = (String) p.get(key); String result = (String) properties.get(key); if (result != null) { if (!result.equalsIgnoreCase(value)) { return false; } } else { return false; } } return true; } catch (NamingException e) { e.printStackTrace(); } return false; } public boolean testURL(String url, String resourceName) throws RemoteException { try { InitialContext ic = new InitialContext(); URL boundURL = (URL) ic.lookup(resourceName); if (boundURL != null) { if (boundURL.toString().equals(url)) return true; } } catch (NamingException e) { e.printStackTrace(); } return false; } public Integer ejbCreate() throws CreateException { return new Integer(1); } public void ejbLoad() { } public void ejbStore() { } public void ejbRemove() { } public void ejbActivate() { } public void ejbPassivate() { } public void unsetEntityContext() { } public void ejbPostCreate() { } }