Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/myeis/j2c/MyEISManagedConnection.java


1   /*
2    * The Apache Software License, Version 1.1
3    *
4    *
5    * Copyright (c) 2002 The Apache Software Foundation.  All rights 
6    * reserved.
7    *
8    * Redistribution and use in source and binary forms, with or without
9    * modification, are permitted provided that the following conditions
10   * are met:
11   *
12   * 1. Redistributions of source code must retain the above copyright
13   *    notice, this list of conditions and the following disclaimer. 
14   *
15   * 2. Redistributions in binary form must reproduce the above copyright
16   *    notice, this list of conditions and the following disclaimer in
17   *    the documentation and/or other materials provided with the
18   *    distribution.
19   *
20   * 3. The end-user documentation included with the redistribution,
21   *    if any, must include the following acknowledgment:  
22   *       "This product includes software developed by the
23   *        Apache Software Foundation (http://www.apache.org/)."
24   *    Alternately, this acknowledgment may appear in the software itself,
25   *    if and wherever such third-party acknowledgments normally appear.
26   *
27   * 4. The names "WSIF" and "Apache Software Foundation" must
28   *    not be used to endorse or promote products derived from this
29   *    software without prior written permission. For written 
30   *    permission, please contact apache@apache.org.
31   *
32   * 5. Products derived from this software may not be called "Apache",
33   *    nor may "Apache" appear in their name, without prior written
34   *    permission of the Apache Software Foundation.
35   *
36   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47   * SUCH DAMAGE.
48   * ====================================================================
49   *
50   * This software consists of voluntary contributions made by many
51   * individuals on behalf of the Apache Software Foundation and was
52   * originally based on software copyright (c) 2001, 2002, International
53   * Business Machines, Inc., http://www.apache.org.  For more
54   * information on the Apache Software Foundation, please see
55   * <http://www.apache.org/>.
56   */
57  package com.myeis.j2c;
58  
59  import java.io.*;
60  import javax.resource.*;
61  import javax.resource.cci.*;
62  import javax.resource.spi.*;
63  import javax.security.auth.*;
64  import javax.transaction.xa.XAResource;
65  import org.apache.wsif.providers.jca.toolplugin.*;
66  import org.apache.wsif.providers.jca.WSIFFormatHandler_JCA;
67  import com.myeis.repository.*;
68  import com.myeis.*;
69  import org.apache.wsif.WSIFException;
70  import org.apache.wsif.providers.jca.*;
71  
72  public class MyEISManagedConnection implements ManagedConnection {
73  
74    private Subject fieldSubject = null;
75    private ConnectionRequestInfo fieldConnectionRequestInfo = null;
76    private MyEISManagedConnectionFactory fieldManagedConnectionFactory = null;
77  
78    /**
79     * Constructor
80     */
81    public MyEISManagedConnection(Subject subject, ConnectionRequestInfo connectionRequestInfo, ManagedConnectionFactory managedConnectionFactory) {
82  
83      this.fieldSubject = subject;
84      this.fieldConnectionRequestInfo = connectionRequestInfo;
85      this.fieldManagedConnectionFactory = (MyEISManagedConnectionFactory) managedConnectionFactory;
86    }
87  
88    /**
89     * @see ManagedConnection#getConnection(Subject, ConnectionRequestInfo)
90     */
91    public Object getConnection(Subject arg0, ConnectionRequestInfo arg1) throws ResourceException {
92  
93      return new MyEISConnection(this);
94    }
95  
96    /**
97     * @see ManagedConnection#destroy()
98     */
99    public void destroy() throws ResourceException {
100   }
101 
102   /**
103    * @see ManagedConnection#cleanup()
104    */
105   public void cleanup() throws ResourceException {
106   }
107 
108   /**
109    * @see ManagedConnection#associateConnection(Object)
110    */
111   public void associateConnection(Object arg0) throws ResourceException {
112   }
113 
114   /**
115    * @see ManagedConnection#addConnectionEventListener(ConnectionEventListener)
116    */
117   public void addConnectionEventListener(ConnectionEventListener arg0) {
118   }
119 
120   /**
121    * @see ManagedConnection#removeConnectionEventListener(ConnectionEventListener)
122    */
123   public void removeConnectionEventListener(ConnectionEventListener arg0) {
124   }
125 
126   /**
127    * @see ManagedConnection#getXAResource()
128    */
129   public XAResource getXAResource() throws ResourceException {
130     return null;
131   }
132 
133   /**
134    * @see ManagedConnection#getLocalTransaction()
135    */
136   public javax.resource.spi.LocalTransaction getLocalTransaction() throws ResourceException {
137     return null;
138   }
139 
140   /**
141    * @see ManagedConnection#getMetaData()
142    */
143   public ManagedConnectionMetaData getMetaData() throws ResourceException {
144     return null;
145   }
146 
147   /**
148    * @see ManagedConnection#setLogWriter(PrintWriter)
149    */
150   public void setLogWriter(PrintWriter arg0) throws ResourceException {
151   }
152 
153   /**
154    * @see ManagedConnection#getLogWriter()
155    */
156   public PrintWriter getLogWriter() throws ResourceException {
157     return null;
158   }
159 
160   /**
161    * close()
162    */
163   public void close() throws ResourceException {
164 
165   }
166 
167   /**
168    * call
169    */
170   public boolean call(InteractionSpec interactionSpec, Record inputRecord, Record outputRecord) throws ResourceException {
171     /*
172      * Depending on the capabilities of the real EIS backend, the implementation of this method will differ. If the backend system
173      * supports the metadata browsing capabilities (as part of its normal business functions) then this method can simply delegate
174      * all the calls to the backend. If the EIS does not have this capability, then the resource adapter needs to implement the logic
175      * to run the getDefinition and getPortTypes operations.
176      * 
177      * In the myEIS sample, the backend implements the import service as business functions. Hence all calls can be passed directly to 
178      * the backend. As an illustration of how the resource adapter can implement the functions, we introduced the 'local' setting on the 'RepositoryLocation'
179      * property. If the property is set to 'local' then the resource adapter implements the logic.
180      */
181         try {
182           /*
183            * If the repository is 'local' then perform the import service logic here.
184            */
185       if ((this.fieldManagedConnectionFactory.getRepositoryLocation().equals("local")) && (((MyEISInteractionSpec) interactionSpec).getFunctionName().equals("IMPORT_PORTTYPES"))) {
186         // local import
187         String queryString = (String) ((WSIFMessage_JCAStreamable) inputRecord).getObjectPart("queryString");
188         PortTypeArray portTypeArray = (new Repository()).getPortTypes(queryString);
189         ((WSIFMessage_JCAStreamable) outputRecord).setObjectPart("result", portTypeArray);
190   
191         return true;
192       }
193       if ((this.fieldManagedConnectionFactory.getRepositoryLocation().equals("local")) && (((MyEISInteractionSpec) interactionSpec).getFunctionName().equals("IMPORT_DEFINITION"))) {
194         // local import
195         PortTypeSelection selection = (PortTypeSelection) ((WSIFMessage_JCAStreamable) inputRecord).getObjectPart("portTypeSelection");
196         ImportDefinition importDefinition = (new Repository()).getDefinition(selection);
197         ((WSIFMessage_JCAStreamable) outputRecord).setObjectPart("result", importDefinition);
198   
199         return true;
200       }
201         } catch (WSIFException e) {
202       e.printStackTrace();
203       throw new ResourceException(e.getMessage());
204         }
205 
206     // invocation of remote import and all other business services
207     try {
208       ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
209 
210       ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
211       objectOutputStream.writeObject(((MyEISInteractionSpec) interactionSpec).getFunctionName());
212       objectOutputStream.flush();
213 
214       ((WSIFMessage_JCAStreamable) inputRecord).write(outputStream);
215 
216       // call my EIS
217       MyEIS myEIS = new MyEIS();
218       byte[] outBytes = myEIS.doIt(outputStream.toByteArray());
219 
220       ByteArrayInputStream inputStream = new ByteArrayInputStream(outBytes);
221       ((WSIFMessage_JCAStreamable) outputRecord).read(inputStream);
222     }
223     catch (IOException e) {
224       e.printStackTrace();
225       throw new ResourceException(e.getMessage());
226     }
227 
228     return true;
229   }
230 }