connectorresource.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 914 行 · 第 1/2 页
JAVA
914 行
*/ public void environmentStop(EnvironmentClassLoader loader) { stop(); } @Override public String toString() { return "ConnectorResource[" + _name + "]"; } public class ResourceAdapterConfig { private String _name; private ContainerProgram _init; public void setJndiName(String name) { _name = name; } public String getName() { return _name; } public void setInit(ContainerProgram init) { _init = init; } public ContainerProgram getInit() { return _init; } } public class ConnectionFactory { private String _name; private String _type; private ManagedConnectionFactory _factory; private boolean _localTransactionOptimization = true; private boolean _shareable = true; private ContainerProgram _init; public void setJndiName(String name) { _name = name; } public void setName(String name) { _name = name; } public String getName() { return _name; } public void setType(String type) throws Exception { setClass(type); } public void setClass(String type) throws Exception { _type = type; if (_rar != null) { ObjectConfig factoryConfig = _rar.getConnectionDefinition(type); if (factoryConfig == null) throw new ConfigException(L.l("'{0}' is an unknown type of <connection-factory> for '{1}'. The connector has no matching outbound connection-factory.", type, ConnectorResource.this._type)); _factory = (ManagedConnectionFactory) factoryConfig.instantiate(); } else if (type != null) { ClassLoader loader = Thread.currentThread().getContextClassLoader(); Class factoryClass = null; try { factoryClass = Class.forName(type, false, loader); } catch (Exception e) { throw new ConfigException(L.l("'{0}' is not a known connection factory. The type must match the resource adaptor or managed connection factory of one of the installed *.rar files or specify a ManagedConnectionFactory implementation.", type)); } if (! ManagedConnectionFactory.class.isAssignableFrom(factoryClass)) { throw new ConfigException(L.l("'{0}' does not implement javax.resource.spi.ManagedConnectionFactory. <connection-factory> classes must implement ManagedConnectionFactory.", factoryClass.getName())); } _factory = (ManagedConnectionFactory) factoryClass.newInstance(); } } public String getType() { return _type; } /** * Enables the local transaction optimization. */ public void setLocalTransactionOptimization(boolean enable) { _localTransactionOptimization = enable; } /** * Enables the local transaction optimization. */ public boolean getLocalTransactionOptimization() { return _localTransactionOptimization; } /** * Enables the shareable property */ public void setShareable(boolean enable) { _shareable = enable; } /** * Enables the shareable property */ public boolean getShareable() { return _shareable; } public ManagedConnectionFactory getFactory() { return _factory; } public void setInit(ContainerProgram init) { _init = init; } public ContainerProgram getInit() { return _init; } @PostConstruct public void init() throws Exception { if (_factory == null && _rar != null) { ObjectConfig factoryConfig = _rar.getConnectionDefinition(null); _factory = (ManagedConnectionFactory) factoryConfig.instantiate(); } if (_factory == null) throw new ConfigException(L.l("connection-factory requires a valid type.")); } /** * Configures a connection-factory */ public void start() throws Exception { ManagedConnectionFactory managedFactory = getFactory(); if (getInit() != null) getInit().configure(managedFactory); if (_ra != null && managedFactory instanceof ResourceAdapterAssociation) { ((ResourceAdapterAssociation) managedFactory).setResourceAdapter(_ra); } ResourceManagerImpl rm = ResourceManagerImpl.createLocalManager(); ConnectionPool cm = rm.createConnectionPool(); if (_name != null) cm.setName(_name); if (_rar != null) { String trans = _rar.getTransactionSupport(); if (trans == null) { // guess XA cm.setXATransaction(true); cm.setLocalTransaction(true); } else if (trans.equals("XATransaction")) { cm.setXATransaction(true); cm.setLocalTransaction(true); } else if (trans.equals("NoTransaction")) { cm.setXATransaction(false); cm.setLocalTransaction(false); } else if (trans.equals("LocalTransaction")) { cm.setXATransaction(false); cm.setLocalTransaction(true); } } cm.setLocalTransactionOptimization(getLocalTransactionOptimization()); cm.setShareable(getShareable()); Object connectionFactory = cm.init(managedFactory); cm.start(); WebBeansContainer webBeans = WebBeansContainer.create(); if (getName() != null) { Jndi.bindDeepShort(getName(), connectionFactory); webBeans.addSingleton(connectionFactory, getName()); } else webBeans.addSingleton(connectionFactory); } } public class ConnectionListener { private String _name; private String _type; private ContainerProgram _init; private EndpointFactory _endpointFactory; private MessageEndpointFactory _endpoint; private ActivationSpec _activation; public void setJndiName(String name) { _name = name; } public String getName() { return _name; } public void setType(String type) { _type = type; } public String getType() { return _type; } public void setInit(ContainerProgram init) { _init = init; } public ContainerProgram getInit() { return _init; } public EndpointFactory getEndpointFactory() { return _endpointFactory; } public EndpointFactory createEndpointFactory() { _endpointFactory = new EndpointFactory(); return _endpointFactory; } @PostConstruct public void init() throws ConfigException { if (_endpointFactory == null) throw new ConfigException(L.l("connection-listener needs an endpoint-factory")); } public void setEndpoint(MessageEndpointFactory endpoint) { _endpoint = endpoint; } public MessageEndpointFactory getEndpoint() { return _endpoint; } public void setActivation(ActivationSpec activation) { _activation = activation; } public ActivationSpec getActivation() { return _activation; } } public class EndpointFactory { private String _name; private Class _type; private ContainerProgram _init; public void setJndiName(String name) { _name = name; } public String getName() { return _name; } public void setType(Class type) throws ConfigException { _type = type; Config.checkCanInstantiate(type); } public Class getType() { return _type; } public void setInit(ContainerProgram init) { _init = init; } public ContainerProgram getInit() { return _init; } } public class ConnectorBean { private String _name; private String _type; private ContainerProgram _init; private ObjectConfig _objectConfig; private Object _object; public void setJndiName(String name) { _name = name; } public void setName(String name) { _name = name; } public String getName() { return _name; } public void setType(String type) throws Exception { setClass(type); } public void setClass(String type) throws Exception { _type = type; Object resourceObject = null; if (_rar != null) { _objectConfig = _rar.getAdminObject(type); if (_objectConfig == null) throw new ConfigException(L.l("`{0}' may not have a <resource> section. The connector has no matching <adminobject> defined.", _type)); _object = _objectConfig.instantiate(); } else { ClassLoader loader = Thread.currentThread().getContextClassLoader(); try { Class resourceClass = Class.forName(type, false, loader); _object = resourceClass.newInstance(); } catch (Exception e) { throw new ConfigException(L.l("`{0}' is not a known resource. The type must match the adminobject of one of the installed *.rar files.", _type), e); } } } public String getType() { return _type; } public void setInit(ContainerProgram init) { _init = init; } public ContainerProgram getInit() { return _init; } public Object getObject() { return _object; } @PostConstruct public void init() throws Exception { if (_object == null) throw new ConfigException(L.l("<class> must be set for a bean.")); Object resourceObject = getObject(); if (getInit() != null) getInit().configure(resourceObject); if (_ra != null && resourceObject instanceof ResourceAdapterAssociation) ((ResourceAdapterAssociation) resourceObject).setResourceAdapter(_ra); WebBeansContainer webBeans = WebBeansContainer.create(); if (getName() != null) { Jndi.bindDeepShort(getName(), resourceObject); webBeans.addSingleton(resourceObject, getName()); } else webBeans.addSingleton(resourceObject); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?