001: // Copyright (c) 2004-2005 Sun Microsystems Inc., All Rights Reserved.
002:
003: /*
004: * EndpointBean.java
005: *
006: * SUN PROPRIETARY/CONFIDENTIAL.
007: * This software is the proprietary information of Sun Microsystems, Inc.
008: * Use is subject to license terms.
009: *
010: */
011: package com.sun.jbi.binding.file;
012:
013: import com.sun.jbi.binding.file.util.ConfigData;
014:
015: import java.io.Serializable;
016:
017: import java.util.ArrayList;
018: import java.util.HashMap;
019: import java.util.Hashtable;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import javax.jbi.servicedesc.ServiceEndpoint;
024:
025: import javax.xml.namespace.QName;
026:
027: /**
028: * This Bean object holds all the attributes of an endpoint.
029: *
030: * @author Sun Microsystems, Inc.
031: */
032: public final class EndpointBean {
033: /**
034: * File thread corresponding to this endpoint.
035: */
036: private FileThreads mFileThreads;
037:
038: /**
039: * Table that stores the opreation and corresponding MEP.
040: */
041: private HashMap mMessagePatterns = null;
042:
043: /**
044: * Table for storing the xml tags and values present in the config file.
045: * This table stores throws filebinding sepcific configuration
046: * information correspondint to each endpoint.
047: */
048: private Hashtable mConfigTable = null;
049:
050: /**
051: * Operations.
052: */
053: private List mOperations = null;
054:
055: /**
056: * Endpoint Reference as returned by the NMS.
057: */
058: private ServiceEndpoint mServiceEndpoint;
059:
060: /**
061: * Deployment Id.
062: */
063: private String mDeploymentId;
064:
065: /**
066: * Receiver thread.
067: */
068: private Thread mThread;
069:
070: /**
071: * Denotes if an endpoint is consumer or provider
072: */
073: private int mRole;
074:
075: /**
076: * Constructor. Creates a new Table, list.
077: */
078: public EndpointBean() {
079: mConfigTable = new Hashtable();
080: mOperations = new ArrayList();
081: mMessagePatterns = new HashMap();
082: }
083:
084: /**
085: * Returns the default operation, which is normally the first operation
086: * defined in the XML or WSDL.
087: *
088: * @return QName name of the operation.
089: */
090: public QName getDefaultOperation() {
091: QName operation = null;
092:
093: try {
094: OperationBean op = (OperationBean) mOperations.get(0);
095: operation = new QName(op.getNamespace(), op.getName());
096: } catch (Exception e) {
097: ;
098: }
099:
100: return operation;
101: }
102:
103: /**
104: * Sets the deployment Id corresponding to this endpoint Bean.
105: *
106: * @param suId Service unit Id.
107: */
108: public void setDeploymentId(String suId) {
109: mDeploymentId = suId;
110: }
111:
112: /**
113: * Fetches the deployment Id coresponding to this bean.
114: *
115: * @return Service unit ID.
116: */
117: public String getDeploymentId() {
118: return mDeploymentId;
119: }
120:
121: /**
122: * Gets the file extension corresponding to an operation.
123: *
124: * @param operation operation name.
125: *
126: * @return file extension corresponding to operation.
127: */
128: public String getExtension(String operation) {
129: String ext = null;
130: Iterator iter = mOperations.iterator();
131:
132: while (iter.hasNext()) {
133: OperationBean op = (OperationBean) iter.next();
134:
135: if (op.getQName().trim().equals(operation)) {
136: ext = op.getFileExtension();
137:
138: break;
139: }
140: }
141:
142: return ext;
143: }
144:
145: /**
146: * Sets the file thread.
147: *
148: * @param ft File thread object.
149: */
150: public void setFileThread(FileThreads ft) {
151: mFileThreads = ft;
152: }
153:
154: /**
155: * Gets the file thread.
156: *
157: * @return file thread object.
158: */
159: public FileThreads getFileThread() {
160: return mFileThreads;
161: }
162:
163: /**
164: * Returns the input type corresponding to an operation name.
165: *
166: * @param operation operation name.
167: *
168: * @return input message type for the operation.
169: */
170: public String getInputType(String operation) {
171: String inputtype = null;
172: Iterator iter = mOperations.iterator();
173:
174: while (iter.hasNext()) {
175: OperationBean op = (OperationBean) iter.next();
176:
177: if (op.getQName().trim().equals(operation)) {
178: inputtype = op.getInputType();
179:
180: break;
181: }
182: }
183:
184: return inputtype;
185: }
186:
187: /**
188: * Gets the MEP corresponding to the operation name.
189: *
190: * @param operation operation name.
191: *
192: * @return String representing the operation , if not present then null
193: */
194: public String getMEP(String operation) {
195: String mep = null;
196: Iterator iter = mOperations.iterator();
197:
198: while (iter.hasNext()) {
199: OperationBean op = (OperationBean) iter.next();
200:
201: if (op.getQName().trim().equals(operation)) {
202: mep = op.getMep();
203:
204: break;
205: }
206: }
207:
208: return mep;
209: }
210:
211: /**
212: * Gets the operation name corresponding to the input type in WSDL.
213: *
214: * @param input name of the input type.
215: *
216: * @return String representing the operation , if not present then null
217: */
218: public QName getOperation(String input) {
219: QName operation = null;
220:
221: Iterator iter = mOperations.iterator();
222:
223: while (iter.hasNext()) {
224: OperationBean op = (OperationBean) iter.next();
225:
226: if (op.getQName().trim().equals(input)) {
227: operation = new QName(op.getNamespace(), op.getName());
228:
229: break;
230: }
231: }
232:
233: return operation;
234: }
235:
236: /**
237: * Gets the fully qualified name of operation given the position in XML or
238: * WSDL.
239: *
240: * @param index occurence of operation inXML or WSDL.
241: *
242: * @return the QName of operation.
243: */
244: public QName getOperationQName(int index) {
245: String local = ((OperationBean) mOperations.get(index))
246: .getName();
247: String namespace = ((OperationBean) mOperations.get(index))
248: .getNamespace();
249:
250: return new QName(namespace, local);
251: }
252:
253: /**
254: * Returns the number of operations in XML or WSDL.
255: *
256: * @return number of operations for this endpoint.
257: */
258: public int getOperationsCount() {
259: return mOperations.size();
260: }
261:
262: /**
263: * Returns the output type corresponding to an operation.
264: *
265: * @param operation operation name.
266: *
267: * @return output message type.
268: */
269: public String getOutputType(String operation) {
270: String outputtype = null;
271: Iterator iter = mOperations.iterator();
272:
273: while (iter.hasNext()) {
274: OperationBean op = (OperationBean) iter.next();
275:
276: if (op.getQName().trim().equals(operation)) {
277: outputtype = op.getOutputType();
278:
279: break;
280: }
281: }
282:
283: return outputtype;
284: }
285:
286: /**
287: * Gets the file prefix corresponding to an operation.
288: *
289: * @param operation operation name.
290: *
291: * @return output file prefix.
292: */
293: public String getPrefix(String operation) {
294: String prefix = null;
295: Iterator iter = mOperations.iterator();
296:
297: while (iter.hasNext()) {
298: OperationBean op = (OperationBean) iter.next();
299:
300: if (op.getQName().trim().equals(operation)) {
301: prefix = op.getOutputFilePrefix();
302:
303: break;
304: }
305: }
306:
307: return prefix;
308: }
309:
310: /**
311: * Sets the receiver thread.
312: *
313: * @param t thread
314: */
315: public void setReceiverThread(Thread t) {
316: mThread = t;
317: }
318:
319: /**
320: * Returns the receiver thread.
321: *
322: * @return receiver thread object.
323: */
324: public Thread getReceiverThread() {
325: return mThread;
326: }
327:
328: /**
329: * Sets the role of this endpoint, provider or consumer.
330: *
331: * @param role should be provider or comsumer, 0 or 1.
332: */
333: public void setRole(int role) {
334: if ((role != ConfigData.PROVIDER)
335: && (role != ConfigData.CONSUMER)) {
336: mRole = ConfigData.CONSUMER;
337: } else {
338: mRole = role;
339: }
340: }
341:
342: /**
343: * Returns the role.
344: *
345: * @return role
346: */
347: public int getRole() {
348: return mRole;
349: }
350:
351: /**
352: * Sets the endpoint reference once the endpoitn has been activated with
353: * the NMS.
354: *
355: * @param ref endpoint reference
356: */
357: public void setServiceEndpoint(ServiceEndpoint ref) {
358: mServiceEndpoint = ref;
359: }
360:
361: /**
362: * Gets the enpoint reference corresponding to this endpoint.
363: *
364: * @return endpoint reference.
365: */
366: public ServiceEndpoint getServiceEndpoint() {
367: return mServiceEndpoint;
368: }
369:
370: /**
371: * Returns a unique name which is a combination of service name and
372: * endpoint name.
373: *
374: * @return unique name of this endpoint. Its a combination of service name
375: * and endpoint name.
376: */
377: public String getUniqueName() {
378: String servicenamespace = getValue(ConfigData.SERVICE_NAMESPACE);
379: String servicename = getValue(ConfigData.SERVICE_LOCALNAME);
380: String endpointname = getValue(ConfigData.ENDPOINTNAME);
381:
382: if ((servicenamespace != null) && (endpointname != null)) {
383: if (servicenamespace.trim().equals("")) {
384: return servicename + endpointname;
385: } else {
386: return "{" + servicenamespace + "}" + servicename
387: + endpointname;
388: }
389: }
390:
391: return null;
392: }
393:
394: /**
395: * Sets the value for the key in the table.
396: *
397: * @param key for which value has to be retrieved.
398: * @param value corresponding to the key
399: */
400: public void setValue(String key, String value) {
401: if (key == null) {
402: return;
403: }
404:
405: if (value == null) {
406: value = "";
407: }
408:
409: mConfigTable.put(key, value);
410: }
411:
412: /**
413: * Returns the value associated with the key from the table.
414: *
415: * @param key the tag name for which value is required.
416: *
417: * @return value corresponding to the tag as in config file.
418: */
419: public String getValue(String key) {
420: if (key == null) {
421: return null;
422: }
423:
424: return (String) mConfigTable.get(key);
425: }
426:
427: /**
428: * Adds an entry for operation-mep in table.
429: *
430: * @param oper operation name.
431: * @param mep corresponding MEP.
432: */
433: public void addMessagePattern(String oper, String mep) {
434: try {
435: mMessagePatterns.put(oper, mep);
436: } catch (Exception e) {
437: e.printStackTrace();
438: }
439: }
440:
441: /**
442: * Adds an operation to the endpoint.
443: *
444: * @param namespace namespace uri
445: * @param name local name
446: * @param mep exchange pattern.
447: * @param input input message type.
448: * @param output output message type.
449: * @param ext file extension.
450: * @param prefix output file prefix.
451: */
452: public void addOperation(String namespace, String name, String mep,
453: String input, String output, String ext, String prefix) {
454: OperationBean op = new OperationBean(namespace, name, mep,
455: input, output, ext, prefix);
456: mOperations.add(op);
457: }
458: }
|