KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sample > SampleScenario


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 /** SampleScenario.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 SampleScenario {
35
36   public void method() {
37     try {
38       Context nc = new InitialContext();
39
40       // JNDI lookup for ConnectionFactory
41
ConnectionFactory cf = (ConnectionFactory)nc.lookup(
42                  "java:comp/env/eis/ConnectionFactory");
43       Connection cx = cf.getConnection();
44
45       // Create an Interaction
46
Interaction ix = cx.createInteraction();
47
48       // Create an InteractionSpec and set properties
49
InteractionSpecImpl ixSpec = new InteractionSpecImpl();
50       ixSpec.setFunctionName("<NAME OF FUNCTION>");
51       ixSpec.setInteractionVerb(InteractionSpec.SYNC_SEND_RECEIVE);
52
53       RecordFactory rf = cf.getRecordFactory();
54       
55       // Create an input MappedRecord. The name of the Record acts as a
56
// pointer to the meta information (stored in the metadata
57
// repository) for a specific record type.
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 empty output MappedRecord
63
IndexedRecord output = rf.createIndexedRecord("Name of Record");
64       
65       // Execute the Interaction to hold output values that are set
66
// by the execution of the interaction.
67
ix.execute(ixSpec, input, output);
68
69       // Extract data from the output IndexedRecord. Note that the
70
// type mapping is done in the generic IndexedRecord by means
71
// of the type mapping information in the metadata repository.
72
// Since the component uses generic methods on the IndexedRecord,
73
// the component code does the required type casting.
74
Iterator JavaDoc iterator = output.iterator();
75       while (iterator.hasNext()) {
76     // Get a record element and extract value
77
}
78     }
79     catch (NamingException ne) {
80       return;
81     }
82      catch (ResourceException JavaDoc e) {
83       return;
84     }
85   }
86
87
88   public static void main(String JavaDoc[] args) {
89   }
90
91 }
92
Popular Tags