[jboss-cvs] jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/jca/ex1/ra ...
Norman Richards
norman.richards at jboss.com
Wed Nov 1 13:14:14 EST 2006
User: nrichards
Date: 06/11/01 13:14:14
Added: jbossas/j2ee/examples/src/main/org/jboss/book/jca/ex1/ra
DirContextFactory.java DirContextFactoryImpl.java
FSDirContext.java FSManagedConnection.java
FSManagedConnectionFactory.java
FSManagedConnectionMetaData.java FSRequestInfo.java
ra.xml
Log:
modified for j2ee guide
Revision Changes Path
1.1 date: 2006/11/01 18:14:14; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/jca/ex1/ra/DirContextFactory.java
Index: DirContextFactory.java
===================================================================
package org.jboss.book.jca.ex1.ra;
import java.io.Serializable;
import javax.naming.NamingException;
import javax.naming.directory.DirContext;
import javax.resource.Referenceable;
/**
*
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public interface DirContextFactory
extends Referenceable,
Serializable
{
public DirContext getConnection()
throws NamingException;
}
1.1 date: 2006/11/01 18:14:14; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/jca/ex1/ra/DirContextFactoryImpl.java
Index: DirContextFactoryImpl.java
===================================================================
package org.jboss.book.jca.ex1.ra;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.naming.directory.InitialDirContext;
import javax.naming.directory.DirContext;
import javax.naming.Reference;
import javax.resource.ResourceException;
import javax.resource.spi.ConnectionManager;
import javax.resource.spi.ManagedConnectionFactory;
import org.apache.log4j.Category;
/**
*
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public class DirContextFactoryImpl implements DirContextFactory
{
static Category log = Category.getInstance(DirContextFactoryImpl.class);
private transient ConnectionManager manager;
private transient ManagedConnectionFactory factory;
private transient FSRequestInfo fsInfo;
private Reference reference;
DirContextFactoryImpl(ConnectionManager manager,
ManagedConnectionFactory factory, FSRequestInfo fsInfo)
{
this.manager = manager;
this.factory = factory;
this.fsInfo = fsInfo;
log.debug("ctor, fsInfo="+fsInfo);
}
public DirContext getConnection() throws NamingException
{
log.debug("getConnection", new Exception("CalledBy:"));
DirContext dc = null;
try
{
dc = (DirContext) manager.allocateConnection(factory, fsInfo);
}
catch(ResourceException e)
{
throw new NamingException("Unable to get Connection: "+e);
}
return dc;
}
public DirContext getConnection(String user, String password) throws NamingException
{
log.debug("getConnection, user="+user);
DirContext dc = null;
try
{
dc = (DirContext) manager.allocateConnection(factory, fsInfo);
}
catch(ResourceException e)
{
throw new NamingException("Unable to get Connection: "+e);
}
return dc;
}
public void setReference(Reference reference)
{
log.debug("setReference, reference="+reference, new Exception("CalledBy:"));
this.reference = reference;
}
public Reference getReference() throws NamingException
{
log.debug("getReference");
return reference;
}
}
1.1 date: 2006/11/01 18:14:14; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/jca/ex1/ra/FSDirContext.java
Index: FSDirContext.java
===================================================================
package org.jboss.book.jca.ex1.ra;
import java.util.Hashtable;
import javax.naming.Name;
import javax.naming.Context;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.NameParser;
import javax.naming.directory.ModificationItem;
import javax.naming.directory.SearchControls;
import javax.naming.directory.DirContext;
import javax.naming.directory.Attributes;
import org.apache.log4j.Category;
/**
*
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public class FSDirContext implements DirContext
{
static Category log = Category.getInstance(FSDirContext.class);
FSManagedConnection mc;
/** Creates new FSDirContext */
public FSDirContext(FSManagedConnection mc)
{
this.mc = mc;
}
protected void setManagedConnection(FSManagedConnection mc)
{
this.mc = mc;
}
public Attributes getAttributes(Name name, String[] str) throws NamingException
{
return null;
}
public void close() throws NamingException
{
log.debug("close");
mc.close();
}
public NamingEnumeration list(String str) throws NamingException
{
return null;
}
public void unbind(Name name) throws NamingException
{
}
public DirContext getSchemaClassDefinition(Name name) throws NamingException
{
return null;
}
public DirContext createSubcontext(String str, Attributes attributes) throws NamingException
{
return null;
}
public String getNameInNamespace() throws NamingException
{
return null;
}
public Object addToEnvironment(String str, Object obj) throws NamingException
{
return null;
}
public NamingEnumeration listBindings(Name name) throws NamingException
{
return null;
}
public void bind(Name name, Object obj) throws NamingException
{
}
public NamingEnumeration search(String str, Attributes attributes, String[] str2) throws NamingException
{
return null;
}
public void modifyAttributes(Name name, int param, Attributes attributes) throws NamingException
{
}
public Hashtable getEnvironment() throws NamingException
{
return null;
}
public void bind(String str, Object obj) throws NamingException
{
}
public void rebind(String str, Object obj, Attributes attributes) throws NamingException
{
}
public DirContext getSchema(Name name) throws NamingException
{
return null;
}
public DirContext getSchemaClassDefinition(String str) throws NamingException
{
return null;
}
public Object lookup(String str) throws NamingException
{
return null;
}
public void destroySubcontext(String str) throws NamingException
{
}
public Context createSubcontext(Name name) throws NamingException
{
return null;
}
public Object lookupLink(String str) throws NamingException
{
return null;
}
public DirContext getSchema(String str) throws NamingException
{
return null;
}
public Object lookup(Name name) throws NamingException
{
return null;
}
public void destroySubcontext(Name name) throws NamingException
{
}
public NamingEnumeration listBindings(String str) throws NamingException
{
return null;
}
public void rebind(String str, Object obj) throws NamingException
{
}
public Object removeFromEnvironment(String str) throws NamingException
{
return null;
}
public void bind(String str, Object obj, Attributes attributes) throws NamingException
{
}
public NamingEnumeration search(Name name, Attributes attributes) throws NamingException
{
return null;
}
public NameParser getNameParser(String str) throws NamingException
{
return null;
}
public void bind(Name name, Object obj, Attributes attributes) throws NamingException
{
}
public Attributes getAttributes(String str) throws NamingException
{
return null;
}
public void rename(String str, String str1) throws NamingException
{
}
public void rename(Name name, Name name1) throws NamingException
{
}
public DirContext createSubcontext(Name name, Attributes attributes) throws NamingException
{
return null;
}
public void rebind(Name name, Object obj, Attributes attributes) throws NamingException
{
}
public NamingEnumeration list(Name name) throws NamingException
{
return null;
}
public Context createSubcontext(String str) throws NamingException
{
return null;
}
public void modifyAttributes(String str, int param, Attributes attributes) throws NamingException
{
}
public NamingEnumeration search(String str, Attributes attributes) throws NamingException
{
return null;
}
public Name composeName(Name name, Name name1) throws NamingException
{
return null;
}
public String composeName(String str, String str1) throws NamingException
{
return null;
}
public NamingEnumeration search(Name name, Attributes attributes, String[] str) throws NamingException
{
return null;
}
public void rebind(Name name, Object obj) throws NamingException
{
}
public void modifyAttributes(Name name, ModificationItem[] modificationItem) throws NamingException
{
}
public NamingEnumeration search(Name name, String str, SearchControls searchControls) throws NamingException
{
return null;
}
public NamingEnumeration search(Name name, String str, Object[] obj, SearchControls searchControls) throws NamingException
{
return null;
}
public void unbind(String str) throws NamingException
{
}
public void modifyAttributes(String str, ModificationItem[] modificationItem) throws NamingException
{
}
public Attributes getAttributes(Name name) throws NamingException
{
return null;
}
public Object lookupLink(Name name) throws NamingException
{
return null;
}
public NameParser getNameParser(Name name) throws NamingException
{
return null;
}
public Attributes getAttributes(String str, String[] str1) throws NamingException
{
return null;
}
public NamingEnumeration search(String str, String str1, SearchControls searchControls) throws NamingException
{
return null;
}
public NamingEnumeration search(String str, String str1, Object[] obj, SearchControls searchControls) throws NamingException
{
return null;
}
}
1.1 date: 2006/11/01 18:14:14; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/jca/ex1/ra/FSManagedConnection.java
Index: FSManagedConnection.java
===================================================================
package org.jboss.book.jca.ex1.ra;
import java.util.ArrayList;
import javax.resource.ResourceException;
import javax.resource.spi.LocalTransaction;
import javax.resource.spi.ManagedConnectionMetaData;
import javax.resource.spi.ConnectionRequestInfo;
import javax.resource.spi.ManagedConnection;
import javax.resource.spi.ConnectionEvent;
import javax.resource.spi.ConnectionEventListener;
import javax.security.auth.Subject;
import javax.transaction.xa.XAResource;
import java.io.PrintWriter;
import org.apache.log4j.Category;
/**
*
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public class FSManagedConnection implements ManagedConnection
{
static Category log = Category.getInstance(FSManagedConnection.class);
ArrayList listeners = new ArrayList();
FSDirContext conn;
/** Creates new FSManagedConnection */
public FSManagedConnection(Subject subject,
FSRequestInfo fsInfo)
{
log.debug("ctor, fsInfo="+fsInfo);
}
public void addConnectionEventListener(ConnectionEventListener connectionEventListener)
{
log.debug("addConnectionEventListener, listener="+connectionEventListener,
new Exception("CalledBy:"));
listeners.add(connectionEventListener);
}
public void removeConnectionEventListener(ConnectionEventListener connectionEventListener)
{
log.debug("removeConnectionEventListener, listener="+connectionEventListener,
new Exception("CalledBy:"));
listeners.remove(connectionEventListener);
}
public void associateConnection(Object obj) throws ResourceException
{
log.debug("associateConnection, obj="+obj, new Exception("CalledBy:"));
conn = (FSDirContext) obj;
conn.setManagedConnection(this);
}
public void cleanup() throws ResourceException
{
log.debug("cleanup");
}
public void destroy() throws ResourceException
{
log.debug("destroy");
}
public Object getConnection(Subject subject, ConnectionRequestInfo info)
throws ResourceException
{
log.debug("getConnection, subject="+subject+", info="+info,
new Exception("CalledBy:"));
if( conn == null )
conn = new FSDirContext(this);
return conn;
}
public LocalTransaction getLocalTransaction() throws ResourceException
{
log.debug("getLocalTransaction");
return null;
}
public ManagedConnectionMetaData getMetaData() throws ResourceException
{
log.debug("getMetaData");
return new FSManagedConnectionMetaData();
}
public XAResource getXAResource() throws ResourceException
{
log.debug("getXAResource");
return null;
}
public PrintWriter getLogWriter() throws ResourceException
{
return null;
}
public void setLogWriter(PrintWriter out) throws ResourceException
{
}
protected void close()
{
ConnectionEvent ce = new ConnectionEvent(this, ConnectionEvent.CONNECTION_CLOSED);
ce.setConnectionHandle(conn);
fireConnectionEvent(ce);
}
protected void fireConnectionEvent(ConnectionEvent evt)
{
for(int i=listeners.size()-1; i >= 0; i--)
{
ConnectionEventListener listener = (ConnectionEventListener) listeners.get(i);
if(evt.getId() == ConnectionEvent.CONNECTION_CLOSED)
listener.connectionClosed(evt);
else if(evt.getId() == ConnectionEvent.CONNECTION_ERROR_OCCURRED)
listener.connectionErrorOccurred(evt);
}
}
}
1.1 date: 2006/11/01 18:14:14; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/jca/ex1/ra/FSManagedConnectionFactory.java
Index: FSManagedConnectionFactory.java
===================================================================
package org.jboss.book.jca.ex1.ra;
import java.io.File;
import java.io.PrintWriter;
import java.io.Serializable;
import java.util.Set;
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.security.auth.Subject;
import org.apache.log4j.Category;
/**
*
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public class FSManagedConnectionFactory
implements ManagedConnectionFactory,
Serializable
{
static Category log = Category.getInstance(FSManagedConnectionFactory.class);
private String rootDirPath;
private transient File rootDir;
/** Creates new FSManagedConnectionFactory */
public FSManagedConnectionFactory()
{
}
public Object createConnectionFactory()
throws ResourceException
{
log.debug("createConnectionFactory");
throw new UnsupportedOperationException("Cannot be used in unmanaged env");
}
public Object createConnectionFactory(ConnectionManager cm)
throws ResourceException
{
log.debug("createConnectionFactory, cm=" + cm, new Exception("CalledBy:"));
FSRequestInfo fsInfo = new FSRequestInfo(rootDir);
return new DirContextFactoryImpl(cm, this, fsInfo);
}
public ManagedConnection createManagedConnection(Subject subject,
ConnectionRequestInfo info)
throws ResourceException
{
log.debug("createManagedConnection, subject=" + subject + ", info=" + info,
new Exception("CalledBy:"));
FSRequestInfo fsInfo = (FSRequestInfo) info;
return new FSManagedConnection(subject, fsInfo);
}
public ManagedConnection matchManagedConnections(Set connectionSet,
Subject subject,
ConnectionRequestInfo info)
throws ResourceException
{
log.debug("matchManagedConnections, connectionSet=" +
connectionSet + ", subject=" + subject +", info=" +info);
return (ManagedConnection) connectionSet.iterator().next();
}
public PrintWriter getLogWriter()
throws ResourceException
{
return null;
}
public void setLogWriter(PrintWriter out)
throws ResourceException
{
}
public boolean equals(Object other)
{
return super.equals(other);
}
public int hashCode()
{
return super.hashCode();
}
public void setFileSystemRootDir(String rootDirPath)
{
this.rootDirPath = rootDirPath;
rootDir = new File(rootDirPath);
if (rootDir.exists() == false) {
rootDir.mkdirs();
}
log.debug("setFileSystemRootDir, rootDir=" + rootDir.getAbsolutePath(),
new Exception("CalledBy:"));
}
}
1.1 date: 2006/11/01 18:14:14; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/jca/ex1/ra/FSManagedConnectionMetaData.java
Index: FSManagedConnectionMetaData.java
===================================================================
/*
* FSManagedConnectionMetaData.java
*
* Created on October 31, 2001, 8:04 PM
*/
package org.jboss.book.jca.ex1.ra;
import javax.resource.ResourceException;
import javax.resource.spi.ManagedConnectionMetaData;
/**
*
* @author Scott.Stark at jboss.org
* @version
*/
public class FSManagedConnectionMetaData implements ManagedConnectionMetaData
{
/** Creates new FSManagedConnectionMetaData */
public FSManagedConnectionMetaData()
{
}
public String getEISProductName() throws ResourceException
{
return "Local File System Adaptor";
}
public String getEISProductVersion() throws ResourceException
{
return "JBoss 2.4.x JCA";
}
public int getMaxConnections() throws ResourceException
{
return 100;
}
public String getUserName() throws ResourceException
{
return "nobody";
}
}
1.1 date: 2006/11/01 18:14:14; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/jca/ex1/ra/FSRequestInfo.java
Index: FSRequestInfo.java
===================================================================
package org.jboss.book.jca.ex1.ra;
import java.io.File;
import javax.resource.spi.ConnectionRequestInfo;
/**
*
* @author Scott.Stark at jboss.org
* @version $Revision: 1.1 $
*/
public class FSRequestInfo implements ConnectionRequestInfo
{
private File rootDir;
/** Creates new FSRequestInfo */
public FSRequestInfo(File rootDir)
{
this.rootDir = rootDir;
}
public boolean equals(Object obj)
{
FSRequestInfo info = (FSRequestInfo) obj;
return rootDir.equals(info.rootDir);
}
public int hashCode()
{
return rootDir.hashCode();
}
public String toString()
{
return "[FSRequestInfo, rootDir="+rootDir.getAbsolutePath()+"]";
}
}
1.1 date: 2006/11/01 18:14:14; author: nrichards; state: Exp;jboss-docs/jbossas/j2ee/examples/src/main/org/jboss/book/jca/ex1/ra/ra.xml
Index: ra.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<connector xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd" version="1.5">
<display-name>File System Adapter</display-name>
<vendor-name>JBoss</vendor-name>
<eis-type>FileSystem</eis-type>
<resourceadapter-version>1.0</resourceadapter-version>
<license>
<description>LGPL</description>
<license-required>false</license-required>
</license>
<resourceadapter>
<resourceadapter-class>org.jboss.resource.deployment.DummyResourceAdapter</resourceadapter-class>
<outbound-resourceadapter>
<connection-definition>
<managedconnectionfactory-class>
org.jboss.book.jca.ex1.ra.FSManagedConnectionFactory
</managedconnectionfactory-class>
<config-property>
<config-property-name>FileSystemRootDir</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value>/tmp/db/fs_store</config-property-value>
</config-property>
<config-property>
<config-property-name>UserName</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value/>
</config-property>
<config-property>
<config-property-name>Password</config-property-name>
<config-property-type>java.lang.String</config-property-type>
<config-property-value/>
</config-property>
<connectionfactory-interface>
org.jboss.book.jca.ex1.ra.DirContextFactory </connectionfactory-interface>
<connectionfactory-impl-class>
org.jboss.book.jca.ex1.ra.DirContextFactoryImpl </connectionfactory-impl-class>
<connection-interface> javax.naming.directory.DirContext </connection-interface>
<connection-impl-class> org.jboss.book.jca.ex1.ra.FSDirContext </connection-impl-class>
</connection-definition>
<transaction-support>NoTransaction</transaction-support>
<authentication-mechanism>
<authentication-mechanism-type>BasicPassword</authentication-mechanism-type>
<credential-interface>javax.resource.spi.security.PasswordCredential</credential-interface>
</authentication-mechanism>
<reauthentication-support>true</reauthentication-support>
</outbound-resourceadapter>
<security-permission>
<description> Read/Write access is required to the contents of the
FileSystemRootDir </description>
<security-permission-spec> permission java.io.FilePermission
"/tmp/db/fs_store/*", "read,write"; </security-permission-spec>
</security-permission>
</resourceadapter>
</connector>
More information about the jboss-cvs-commits
mailing list