KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > SampleBeanScenario


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /** SampleBeanScenario.java
25  */

26
27 package sample;
28
29 import javax.naming.*;
30 import javax.resource.cci.*;
31 import java.util.Iterator JavaDoc;
32 import javax.resource.ResourceException JavaDoc;
33
34 public class SampleBeanScenario {
35
36   public void method() {
37     
38     try {
39       Context nc = new InitialContext();
40
41       // JNDI lookup for ConnectionFactory
42
ConnectionFactory cf = (ConnectionFactory)nc.lookup(
43                  "java:comp/env/eis/ConnectionFactory");
44       Connection cx = cf.getConnection();
45
46       // Create an Interaction
47
Interaction ix = cx.createInteraction();
48
49       // Create an InteractionSpec and set properties
50
InteractionSpecImpl ixSpec = new InteractionSpecImpl();
51       ixSpec.setFunctionName("<NAME OF FUNCTION>");
52       ixSpec.setInteractionVerb(InteractionSpec.SYNC_SEND_RECEIVE);
53
54       // Get a RecordFactory to create input/output generic Records
55
RecordFactory rf = cf.getRecordFactory();
56       
57       // Create an input MappedRecord
58
MappedRecord input = rf.createMappedRecord("Name of Record");
59       input.put("<key: element1>", new String JavaDoc("<VALUE1>"));
60       input.put("<key: element2>", new String JavaDoc("<VALUE2>"));
61
62       // Create an output custom Record
63
EmployeeRecord employee = new EmployeeRecordImpl();
64
65       // Execute the Interaction
66
ix.execute(ixSpec, input, employee);
67
68       // Check the EmployeeRecord
69
System.out.println( employee.getName() + ":" +
70               employee.getId());
71     }
72     catch (NamingException ne) {
73       return;
74     }
75      catch (ResourceException JavaDoc e) {
76       return;
77     }
78   }
79
80
81   public static void main(String JavaDoc[] args) {
82   }
83
84 }
85
Popular Tags