1 18 19 package sync4j.server.syncbean; 20 21 import javax.ejb.*; 22 import javax.naming.*; 23 24 import javax.rmi.PortableRemoteObject ; 25 26 import java.io.*; 27 import java.util.Map ; 28 import java.util.logging.Logger ; 29 import java.util.logging.Level ; 30 31 import sync4j.framework.core.*; 32 import sync4j.framework.server.SyncResponse; 33 import sync4j.framework.logging.Sync4jLogger; 34 import sync4j.framework.config.ConfigClassLoader; 35 import sync4j.framework.config.ConfigurationException; 36 import sync4j.framework.protocol.ProtocolException; 37 38 import sync4j.framework.core.Sync4jException; 39 import sync4j.framework.core.RepresentationException; 40 import sync4j.framework.server.session.SessionExpiredException; 41 import sync4j.framework.server.error.*; 42 43 import sync4j.server.config.Configuration; 44 import sync4j.server.engine.SyncAdapter; 45 import sync4j.server.session.SyncSessionHandler; 46 47 import sync4j.server.admin.*; 48 import sync4j.server.admin.ejb.*; 49 50 63 public class SyncBean 64 implements javax.ejb.SessionBean { 65 66 68 private static final String ENV_ADMIN_NAME 69 = "java:comp/env/ejb/LocalAdminBean"; 70 71 73 private transient Logger log = null; 74 75 private SessionContext sessionContext = null; 76 77 private SyncSessionHandler sessionHandler = null; 78 79 private Configuration config = null; 80 81 private String sessionId = null; 82 83 private SyncAdapter syncAdapter = null; 84 85 87 public void ejbCreate(String sessionId) throws CreateException { 88 89 log = Sync4jLogger.getLogger("server"); 90 91 loadAdminBean(); 92 93 try { 94 syncAdapter = new SyncAdapter(config); 95 syncAdapter.beginSync(sessionId); 96 } catch (Exception e) { 97 log.throwing("SyncBean", "ejbCreate", e); 98 throw new CreateException( "Error " 99 + e.getClass().getName() 100 + " creating the SyncBean: " 101 + e.getMessage() 102 ); 103 } 104 this.sessionId = sessionId; 105 } 106 107 110 private void loadAdminBean() throws CreateException { 111 112 try { 113 114 InitialContext ctx = new InitialContext(); 115 116 Object obj = ctx.lookup(ENV_ADMIN_NAME); 117 AdminHomeLocal home = 118 (AdminHomeLocal)PortableRemoteObject.narrow(obj, AdminHomeLocal.class); 119 AdminLocal admin = home.create(); 120 121 config = admin.getConfig(); 122 123 } catch (NamingException e) { 124 e.printStackTrace(); 125 log.throwing("SyncBean", "loadAdminBean", e); 126 throw new CreateException( "Error " 127 + e.getClass().getName() 128 + " creating the AdminBean: " 129 + e.getMessage() 130 ); 131 } catch (Exception e) { 132 e.printStackTrace(); 133 log.throwing("SyncBean", "loadAdminBean", e); 134 throw new CreateException( "Error " 135 + e.getClass().getName() 136 + " creating the AdminBean: " 137 + e.getMessage() 138 ); 139 } 140 } 141 142 143 150 public void ejbRemove() { 151 syncAdapter.endSync(); 152 } 153 154 public void ejbActivate() { 155 log = Sync4jLogger.getLogger(); 156 } 157 158 public void ejbPassivate() { 159 log = null; 160 } 161 162 public void setSessionContext (SessionContext sessionContext) 163 throws EJBException { 164 this.sessionContext = sessionContext; 165 } 166 167 178 public SyncResponse processXMLMessage(final byte[] msg , 179 final Map parameters , 180 final Map headers ) 181 throws ServerException { 182 return (SyncResponse) syncAdapter.processXMLMessage(msg, parameters, headers); 183 } 184 185 196 public SyncResponse processWBXMLMessage(final byte[] msg , 197 final Map parameters , 198 final Map headers ) 199 throws ServerException { 200 return (SyncResponse) syncAdapter.processWBXMLMessage(msg, parameters, headers); 201 } 202 203 212 public SyncResponse processStatusCode(int statusCode, String info){ 213 return syncAdapter.processStatusCode(statusCode, info); 214 } 215 } 216 | Popular Tags |