205 lines
7.4 KiB
Java
205 lines
7.4 KiB
Java
/*
|
|
* Copyright 2004-2008 IDCA. All rights reserved.
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the
|
|
* following conditions are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright notice, this list of conditions and
|
|
* the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
|
|
* and the following disclaimer in the documentation and/or other materials provided with the
|
|
* distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY IDCA AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IDCA OR
|
|
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
* The views and conclusions contained in the software and documentation are those of the authors and
|
|
* should not be interpreted as representing official policies, either expressed or implied, of IDCA.
|
|
*/
|
|
|
|
package com.idcanet.foei.ee.jca.cci;
|
|
|
|
import java.io.PrintWriter;
|
|
import java.util.HashMap;
|
|
import java.util.Iterator;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.logging.Logger;
|
|
|
|
import javax.naming.Context;
|
|
import javax.resource.ResourceException;
|
|
import javax.resource.spi.ConnectionManager;
|
|
import javax.resource.spi.ConnectionRequestInfo;
|
|
import javax.resource.spi.ManagedConnection;
|
|
import javax.resource.spi.ManagedConnectionFactory;
|
|
import javax.resource.spi.ResourceAdapter;
|
|
import javax.resource.spi.ResourceAdapterAssociation;
|
|
import javax.security.auth.Subject;
|
|
|
|
import com.idcanet.foei.core.EventExecutorManager;
|
|
import com.idcanet.foei.core.FoeiContext;
|
|
import com.idcanet.foei.core.FoeiProcessManager;
|
|
import com.idcanet.foei.core.impl.FoeiConfiguratorImpl;
|
|
import com.idcanet.foei.core.impl.FoeiContextImpl;
|
|
import com.idcanet.foei.ee.jca.spi.FoeiResourceAdapter;
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @author Willem Cazander
|
|
* @version 1.0 Apr 19, 2008
|
|
*/
|
|
@SuppressWarnings("serial")
|
|
public class FoeiManagedConnectionFactory implements ManagedConnectionFactory,ResourceAdapterAssociation {
|
|
|
|
private Logger logger = Logger.getLogger(FoeiManagedConnectionFactory.class.getName());
|
|
|
|
/** Log writer */
|
|
private transient PrintWriter writer;
|
|
|
|
/** Path to file system repository */
|
|
private String foeiContextName = null;
|
|
|
|
private FoeiContext foeiContext = null;
|
|
|
|
private ResourceAdapter resourceAdapter = null;
|
|
|
|
/**
|
|
* @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory(javax.resource.spi.ConnectionManager)
|
|
*/
|
|
public Object createConnectionFactory(ConnectionManager cm) throws ResourceException {
|
|
|
|
if (foeiContext==null) {
|
|
logger.info("Starting foeiContext: "+foeiContextName);
|
|
Context objectContext = null;
|
|
EventExecutorManager eventExecutorManager = null;
|
|
FoeiProcessManager foeiProcessManager = null;
|
|
|
|
Map<String,String> properties = new HashMap<String,String>(0);
|
|
try {
|
|
objectContext = FoeiConfiguratorImpl.newContext(properties);
|
|
//eventExecutorManager = new JCAEventExecutorManager((FoeiResourceAdapter)getResourceAdapter());
|
|
eventExecutorManager = FoeiConfiguratorImpl.newEventExecutorManager(properties);
|
|
foeiProcessManager = FoeiConfiguratorImpl.newFoeiProcessManager(properties);
|
|
|
|
// inject ejb beans per process
|
|
foeiProcessManager.addFoeiProcessListener(new EJBFoeiProcessListener((FoeiResourceAdapter)getResourceAdapter()));
|
|
|
|
FoeiConfiguratorImpl.loadEventThreadListeners(properties,eventExecutorManager);
|
|
} catch (Exception e) {
|
|
throw new ResourceException("Error while building childs objects:",e);
|
|
}
|
|
foeiContext = new FoeiContextImpl(foeiContextName,objectContext,eventExecutorManager,properties,foeiProcessManager);
|
|
}
|
|
|
|
return new FoeiConnectionFactoryImpl(this, cm);
|
|
}
|
|
|
|
/**
|
|
* @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory()
|
|
*/
|
|
public Object createConnectionFactory() throws ResourceException {
|
|
return createConnectionFactory(null);
|
|
}
|
|
|
|
/**
|
|
* @see javax.resource.spi.ManagedConnectionFactory#createManagedConnection(javax.security.auth.Subject, javax.resource.spi.ConnectionRequestInfo)
|
|
*/
|
|
public ManagedConnection createManagedConnection(Subject subj,ConnectionRequestInfo conReqInfo) throws ResourceException {
|
|
return new FoeiManagedConnection(conReqInfo, writer, foeiContext);
|
|
}
|
|
|
|
/**
|
|
* @see javax.resource.spi.ManagedConnectionFactory#matchManagedConnections(java.util.Set, javax.security.auth.Subject, javax.resource.spi.ConnectionRequestInfo)
|
|
*/
|
|
@SuppressWarnings("unchecked")
|
|
public ManagedConnection matchManagedConnections(Set set, Subject subj, ConnectionRequestInfo conReqInfo) throws ResourceException {
|
|
Iterator itr = set.iterator();
|
|
if (itr.hasNext()) {
|
|
Object obj = itr.next();
|
|
if (obj instanceof FoeiManagedConnection) {
|
|
return (FoeiManagedConnection)obj;
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @see javax.resource.spi.ManagedConnectionFactory#setLogWriter(java.io.PrintWriter)
|
|
*/
|
|
public void setLogWriter(PrintWriter out) throws ResourceException {
|
|
this.writer = out;
|
|
}
|
|
|
|
/**
|
|
* @see javax.resource.spi.ManagedConnectionFactory#getLogWriter()
|
|
*/
|
|
public PrintWriter getLogWriter() throws ResourceException {
|
|
return writer;
|
|
}
|
|
|
|
/**
|
|
* @see javax.resource.spi.ManagedConnectionFactory#hashCode()
|
|
*/
|
|
public int hashCode() {
|
|
if (foeiContextName == null) {
|
|
return super.hashCode();
|
|
} else {
|
|
return foeiContextName.hashCode();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @see javax.resource.spi.ManagedConnectionFactory#equals(java.lang.Object)
|
|
*/
|
|
public boolean equals(Object obj) {
|
|
if (this == obj) {
|
|
return true;
|
|
}
|
|
if (!(obj instanceof FoeiManagedConnectionFactory)) {
|
|
return false;
|
|
}
|
|
if (foeiContextName == null) {
|
|
return false;
|
|
}
|
|
return foeiContextName.equals(((FoeiManagedConnectionFactory)obj).getFoeiContextName());
|
|
}
|
|
|
|
/**
|
|
* @return the foeiContextName
|
|
*/
|
|
public String getFoeiContextName() {
|
|
return foeiContextName;
|
|
}
|
|
|
|
/**
|
|
* @param foeiContextName the foeiContextName to set
|
|
*/
|
|
public void setFoeiContextName(String foeiContextName) {
|
|
this.foeiContextName = foeiContextName;
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* @see javax.resource.spi.ResourceAdapterAssociation#getResourceAdapter()
|
|
*/
|
|
public ResourceAdapter getResourceAdapter() {
|
|
return resourceAdapter;
|
|
}
|
|
|
|
/**
|
|
* @see javax.resource.spi.ResourceAdapterAssociation#setResourceAdapter(javax.resource.spi.ResourceAdapter)
|
|
*/
|
|
public void setResourceAdapter(ResourceAdapter resourceAdapter) throws ResourceException {
|
|
this.resourceAdapter=resourceAdapter;
|
|
}
|
|
}
|