001: /*
002: * This file is part of the WfMOpen project.
003: * Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU BTS.
004: * All rights reserved.
005: *
006: * This program is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU General Public License as published by
008: * the Free Software Foundation; either version 2 of the License, or
009: * (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * $Id: PropsRmsManagedConnectionFactory.java,v 1.3 2007/05/17 21:53:00 mlipp Exp $
021: *
022: * $Log: PropsRmsManagedConnectionFactory.java,v $
023: * Revision 1.3 2007/05/17 21:53:00 mlipp
024: * Refactored resource adaptors.
025: *
026: * Revision 1.2 2006/09/29 12:32:07 drmlipp
027: * Consistently using WfMOpen as projct name now.
028: *
029: * Revision 1.1 2006/09/24 20:57:16 mlipp
030: * Moved RMS implementations in own sub-package.
031: *
032: * Revision 1.5 2006/07/11 11:13:13 drmlipp
033: * Props RMS running.
034: *
035: * Revision 1.4 2006/07/10 19:18:07 mlipp
036: * Improved equals.
037: *
038: * Revision 1.3 2006/07/10 13:47:46 drmlipp
039: * Some issues (preliminaryly) fixed.
040: *
041: * Revision 1.2 2006/07/07 14:12:08 drmlipp
042: * Added configuration properties.
043: *
044: * Revision 1.1 2006/07/05 10:58:52 drmlipp
045: * Renamed package.
046: *
047: * Revision 1.1 2006/07/05 10:53:26 drmlipp
048: * Separated generic RMS adapter client from properties based adapter.
049: *
050: */
051: package de.danet.an.workflow.rmsimpls.propsrmsra;
052:
053: import java.io.File;
054: import java.io.FileInputStream;
055: import java.io.IOException;
056: import java.io.Serializable;
057: import java.net.URI;
058: import java.net.URISyntaxException;
059: import java.util.Properties;
060:
061: import javax.resource.ResourceException;
062: import javax.resource.spi.ConnectionManager;
063: import javax.resource.spi.ConnectionRequestInfo;
064: import javax.resource.spi.ManagedConnection;
065: import javax.resource.spi.ManagedConnectionFactory;
066: import javax.resource.spi.ManagedConnectionMetaData;
067: import javax.resource.spi.ResourceAdapterInternalException;
068: import javax.security.auth.Subject;
069:
070: import de.danet.an.util.ra.ManagedConnectionFactorySupport;
071:
072: /**
073: * The managed connection factory of the resource adapter for the properties
074: * files based RMS.
075: * @author Michael Lipp
076: */
077: public class PropsRmsManagedConnectionFactory extends
078: ManagedConnectionFactorySupport implements Serializable {
079:
080: private String propertiesDirUrl;
081: private String usersPropertiesFile;
082: private String groupsPropertiesFile;
083: private String rolesPropertiesFile;
084:
085: private Properties usersProps = null;
086: private Properties groupsProps = null;
087: private Properties rolesProps = null;
088:
089: /* (non-Javadoc)
090: * @see javax.resource.spi.ManagedConnectionFactory#createConnectionFactory
091: */
092: public Object createConnectionFactory(
093: ConnectionManager connectionManager)
094: throws ResourceException {
095: return new PropsRmsConnectionFactory(this , connectionManager);
096: }
097:
098: /* (non-Javadoc)
099: * @see javax.resource.spi.ManagedConnectionFactory#createManagedConnection
100: */
101: public ManagedConnection createManagedConnection(Subject subject,
102: ConnectionRequestInfo requestInfo) throws ResourceException {
103: if (usersProps == null) {
104: try {
105: File propsDir = new File(new URI(propertiesDirUrl));
106: usersProps = new Properties();
107: if (usersPropertiesFile != null) {
108: usersProps.load(new FileInputStream(new File(
109: propsDir, usersPropertiesFile)));
110: }
111: groupsProps = new Properties();
112: if (groupsPropertiesFile != null) {
113: groupsProps.load(new FileInputStream(new File(
114: propsDir, groupsPropertiesFile)));
115: }
116: rolesProps = new Properties();
117: if (rolesPropertiesFile != null) {
118: rolesProps.load(new FileInputStream(new File(
119: propsDir, rolesPropertiesFile)));
120: }
121: } catch (URISyntaxException e) {
122: throw (ResourceException) (new ResourceAdapterInternalException(
123: "Cannot access properties files: "
124: + e.getMessage()).initCause(e));
125: } catch (IOException e) {
126: throw (ResourceException) (new ResourceAdapterInternalException(
127: "Cannot access properties files: "
128: + e.getMessage()).initCause(e));
129: }
130: }
131: return new PropsRmsManagedConnection(this , subject, usersProps,
132: groupsProps, rolesProps);
133: }
134:
135: /* (non-Javadoc)
136: * Comment copied from interface or superclass.
137: */
138: public ManagedConnectionMetaData createMetaData(String user) {
139: return new PropsRmsManagedConnectionMetaData(user);
140: }
141:
142: /* (non-Javadoc)
143: * @see java.lang.Object#equals(java.lang.Object)
144: */
145: public boolean equals(Object obj) {
146: PropsRmsManagedConnectionFactory other = (PropsRmsManagedConnectionFactory) obj;
147: return equals(propertiesDirUrl, other.propertiesDirUrl)
148: && equals(usersPropertiesFile,
149: other.usersPropertiesFile)
150: && equals(groupsPropertiesFile,
151: other.groupsPropertiesFile)
152: && equals(rolesPropertiesFile,
153: other.rolesPropertiesFile);
154: }
155:
156: /* (non-Javadoc)
157: * @see java.lang.Object#hashCode()
158: */
159: public int hashCode() {
160: return propertiesDirUrl.hashCode();
161: }
162:
163: /**
164: * @return Returns the propertiesDirUrl.
165: */
166: public String getPropertiesDirUrl() {
167: return propertiesDirUrl;
168: }
169:
170: /**
171: * @param propertiesDirUrl The propertiesDirUrl to set.
172: */
173: public void setPropertiesDirUrl(String propertiesDirUrl) {
174: this .propertiesDirUrl = propertiesDirUrl;
175: }
176:
177: /**
178: * @return Returns the userPropertiesFile.
179: */
180: public String getUsersPropertiesFile() {
181: return usersPropertiesFile;
182: }
183:
184: /**
185: * @param userPropertiesFile The userPropertiesFile to set.
186: */
187: public void setUsersPropertiesFile(String userPropertiesFile) {
188: this .usersPropertiesFile = userPropertiesFile;
189: }
190:
191: /**
192: * @return Returns the groupsPropertiesFile.
193: */
194: public String getGroupsPropertiesFile() {
195: return groupsPropertiesFile;
196: }
197:
198: /**
199: * @param groupsPropertiesFile The groupsPropertiesFile to set.
200: */
201: public void setGroupsPropertiesFile(String groupsPropertiesFile) {
202: this .groupsPropertiesFile = groupsPropertiesFile;
203: }
204:
205: /**
206: * @return Returns the rolesPropertiesFile.
207: */
208: public String getRolesPropertiesFile() {
209: return rolesPropertiesFile;
210: }
211:
212: /**
213: * @param rolesPropertiesFile The rolesPropertiesFile to set.
214: */
215: public void setRolesPropertiesFile(String rolesPropertiesFile) {
216: this.rolesPropertiesFile = rolesPropertiesFile;
217: }
218:
219: }
|