KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > myeis > MyEIS


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
58 package com.myeis;
59
60 import java.io.*;
61 import org.apache.wsif.providers.jca.toolplugin.*;
62 import com.myeis.repository.*;
63 import com.myeis.services.*;
64 import com.myeis.services.internal.*;
65
66 public class MyEIS {
67
68     public byte[] doIt(byte[] input) {
69         
70         /*
71          * This method represents the actual sample backend (i.e. this method mimics what a real back end system would typically do).
72          * Based on the function name certain tasks are executed.
73          */

74     
75         try {
76             ByteArrayInputStream inputStream = new ByteArrayInputStream(input);
77             
78             // get the function name
79
ObjectInputStream headerInputStream = new ObjectInputStream(inputStream);
80             String JavaDoc functionName = (String JavaDoc)headerInputStream.readObject();
81         
82             if (functionName.equals("IMPORT_PORTTYPES")) {
83                 // import service porttypes
84
ObjectInputStream payloadInputStream = new ObjectInputStream(inputStream);
85                 String JavaDoc queryString = (String JavaDoc)payloadInputStream.readObject();
86                 PortTypeArray portTypeArray = (new Repository()).getPortTypes(queryString);
87                 
88                 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
89                 ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
90                 objectOutputStream.writeObject(portTypeArray);
91                 objectOutputStream.flush();
92             
93                 return outputStream.toByteArray();
94             }
95             if (functionName.equals("IMPORT_DEFINITION")) {
96                 // import service definitions
97
ObjectInputStream payloadInputStream = new ObjectInputStream(inputStream);
98                 PortTypeSelection selection = (PortTypeSelection)payloadInputStream.readObject();
99                 ImportDefinition importDefinition = (new Repository()).getDefinition(selection);
100             
101                 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
102                 ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
103                 objectOutputStream.writeObject(importDefinition);
104                 objectOutputStream.flush();
105             
106                 return outputStream.toByteArray();
107             }
108             if (functionName.equals("IMPORT_RAWMETADATA")) {
109                 // import raw metadata
110
ObjectInputStream payloadInputStream = new ObjectInputStream(inputStream);
111                 String JavaDoc queryString = (String JavaDoc)payloadInputStream.readObject();
112                 byte[] result = (new Repository()).getRawEISMetaData(queryString);
113                 
114                 return result;
115             }
116             if (functionName.equals("CUSTOMERINFO_getCustomer")) {
117                 // invoke a business service
118
ObjectInputStream payloadInputStream = new ObjectInputStream(inputStream);
119                 String JavaDoc number = (String JavaDoc)payloadInputStream.readObject();
120                 CustomerDataObject customer = (new CustomerInfo()).getCustomer(number);
121             
122                 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
123                 ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
124                 objectOutputStream.writeObject(customer);
125                 objectOutputStream.flush();
126             
127                 return outputStream.toByteArray();
128             }
129             if (functionName.equals("PURCHASEORDERINFO_getPurchaseOrder")) {
130                 // invoke a business service
131
ObjectInputStream payloadInputStream = new ObjectInputStream(inputStream);
132                 String JavaDoc number = (String JavaDoc)payloadInputStream.readObject();
133                 PurchaseOrderDataObject purchaseOrder = (new PurchaseOrderInfo()).getPurchaseOrder(number);
134             
135                 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
136                 ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
137                 objectOutputStream.writeObject(purchaseOrder);
138                 objectOutputStream.flush();
139             
140                 return outputStream.toByteArray();
141             }
142             
143             if (functionName.equals("CUSTOMERINFO_getAddress")) {
144                 // invoke a business service
145
ObjectInputStream payloadInputStream = new ObjectInputStream(inputStream);
146                 String JavaDoc number = (String JavaDoc)payloadInputStream.readObject();
147                 AddressDataObject address = (new CustomerInfo()).getAddress(number);
148             
149                 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
150                 ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream);
151                 objectOutputStream.writeObject(address);
152                 objectOutputStream.flush();
153             
154                 return outputStream.toByteArray();
155             }
156             // process other business services here
157

158         } catch (Exception JavaDoc e) {
159             e.printStackTrace();
160         }
161         
162         return null;
163     }
164
165 }
166
167
Popular Tags