Source Code Cross Referenced for DeployDescriptorReader.java in  » ESB » open-esb » com » sun » jbi » binding » jms » deploy » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » open esb » com.sun.jbi.binding.jms.deploy 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * BEGIN_HEADER - DO NOT EDIT
003:         *
004:         * The contents of this file are subject to the terms
005:         * of the Common Development and Distribution License
006:         * (the "License").  You may not use this file except
007:         * in compliance with the License.
008:         *
009:         * You can obtain a copy of the license at
010:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
011:         * See the License for the specific language governing
012:         * permissions and limitations under the License.
013:         *
014:         * When distributing Covered Code, include this CDDL
015:         * HEADER in each file and include the License file at
016:         * https://open-esb.dev.java.net/public/CDDLv1.0.html.
017:         * If applicable add the following below this CDDL HEADER,
018:         * with the fields enclosed by brackets "[]" replaced with
019:         * your own identifying information: Portions Copyright
020:         * [year] [name of copyright owner]
021:         */
022:
023:        /*
024:         * @(#)DeployDescriptorReader.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.binding.jms.deploy;
030:
031:        import com.sun.jbi.StringTranslator;
032:
033:        import com.sun.jbi.binding.jms.JMSBindingContext;
034:        import com.sun.jbi.binding.jms.JMSBindingResources;
035:
036:        import com.sun.jbi.binding.jms.config.ConfigConstants;
037:        import java.util.StringTokenizer;
038:
039:        import java.util.logging.Logger;
040:
041:        import javax.xml.namespace.QName;
042:
043:        import org.w3c.dom.Document;
044:        import org.w3c.dom.NamedNodeMap;
045:        import org.w3c.dom.Node;
046:        import org.w3c.dom.NodeList;
047:        import org.w3c.dom.Element;
048:
049:        /**
050:         * This class reads the SU jbi.xml and loads up the values.
051:         *
052:         * @author Sun Microsystems, Inc.
053:         */
054:        public class DeployDescriptorReader extends UtilBase implements 
055:                JMSBindingResources {
056:            /**
057:             * Document object of the XML config file.
058:             */
059:            private Document mDoc;
060:
061:            /**
062:             * Logger Object.
063:             */
064:            private Logger mLog;
065:
066:            /**
067:             * i18n.
068:             */
069:            private StringTranslator mTranslator;
070:
071:            /**
072:             * List of endpoints in the SU jbi.xml.
073:             */
074:            private EndpointInfo[] mEPList;
075:
076:            /**
077:             * Number of consumers.
078:             */
079:            private int mNoOfConsumers;
080:
081:            /**
082:             * Number of providers.    
083:             */
084:            private int mNoOfProviders;
085:
086:            /**
087:             * Type of artifact file, XML, WSDL11 or WSDL20
088:             */
089:            private String mType;
090:
091:            /**
092:             * Creates a new ConfigReader object.
093:             */
094:            public DeployDescriptorReader() {
095:                mLog = JMSBindingContext.getInstance().getLogger();
096:                mTranslator = JMSBindingContext.getInstance()
097:                        .getStringTranslator();
098:                setValid(true);
099:            }
100:
101:            /**
102:             * Returns the number of consumer endpoints.
103:             *
104:             * @return consumer endpoint count.
105:             */
106:            public int getConsumerCount() {
107:                return mNoOfConsumers;
108:            }
109:
110:            /**
111:             * Sets the endpoint attributes.
112:             *
113:             * @param node mProvider/consumer node.
114:             * @param ep endpoint information.
115:             */
116:            public void setEndpoint(Node node, EndpointInfo ep) {
117:                NamedNodeMap map = node.getAttributes();
118:
119:                try {
120:                    String epname = map.getNamedItem("endpoint-name")
121:                            .getNodeValue();
122:                    String sername = map.getNamedItem("service-name")
123:                            .getNodeValue();
124:                    String intername = map.getNamedItem("interface-name")
125:                            .getNodeValue();
126:                    ep.setServiceName(new QName(getNamespace(sername),
127:                            getLocalName(sername)));
128:                    ep.setInterfaceName(new QName(getNamespace(intername),
129:                            getLocalName(intername)));
130:                    ep.setEndpointName(epname);
131:                } catch (Exception e) {
132:                    e.printStackTrace();
133:                    setError(getError()
134:                            + mTranslator.getString(JMS_LOAD_DD_FAILED) + "\n"
135:                            + e.getMessage());
136:                    setValid(false);
137:                }
138:            }
139:
140:            /**
141:             * Verifies if the endpoint in the artifacts XML file is present in
142:             * the deployment descriptor.
143:             *
144:             * @param sername  service name.
145:             * @param intername  interface name.
146:             * @param epname  endpoint name.
147:             * @param role  role.
148:             *
149:             * @return  true if present.
150:             */
151:            public boolean isPresent(QName sername, QName intername,
152:                    String epname, int role) {
153:
154:                for (int ep = 0; ep < mEPList.length; ep++) {
155:
156:                    if ((mEPList[ep].getServiceName().toString().equals(sername
157:                            .toString()))
158:                            && (mEPList[ep].getInterfaceName().toString()
159:                                    .equals(intername.toString()))
160:                            && (mEPList[ep].getEndpointName().equals(epname))
161:                            && (mEPList[ep].getStyle() == role)) {
162:                        return true;
163:                    }
164:                }
165:
166:                return false;
167:            }
168:
169:            /**
170:             * Returns the number of mProvider endpoints.
171:             *
172:             * @return mProvider endpoint count.
173:             */
174:            public int getProviderCount() {
175:                return mNoOfProviders;
176:            }
177:
178:            /**
179:             * Initializes the config file and loads services.
180:             *
181:             * @param doc Name of the config file.
182:             */
183:            public void init(Document doc) {
184:                try {
185:                    mDoc = doc;
186:                    mDoc.getDocumentElement().normalize();
187:                    load();
188:                } catch (Exception genException) {
189:                    mLog.severe(mTranslator.getString(JMS_LOAD_DD_FAILED));
190:                    genException.printStackTrace();
191:                    setException(genException);
192:                    setError(getError()
193:                            + mTranslator.getString(JMS_LOAD_DD_FAILED) + "\n"
194:                            + genException.getMessage());
195:                    setValid(false);
196:                }
197:            }
198:
199:            /**
200:             * Sets the type of artifact.
201:             */
202:            private void setType(String type) {
203:                mType = type;
204:            }
205:
206:            /**
207:             * Gets the type of artifact
208:             */
209:
210:            public String getType() {
211:                return mType;
212:            }
213:
214:            private void setArtifacts() {
215:                NodeList namelist = mDoc.getElementsByTagNameNS("*",
216:                        "artifactstype");
217:
218:                if (namelist == null) {
219:                    /* This means the tag is not present. default type is WSDL20
220:                     */
221:                    setType("WSDL20");
222:                    return;
223:                }
224:
225:                Element name = (Element) namelist.item(0);
226:                String sValue = null;
227:
228:                try {
229:                    sValue = ((Node) (name.getChildNodes().item(0)))
230:                            .getNodeValue().trim();
231:                } catch (NullPointerException ne) {
232:                    setType("WSDL20");
233:                    return;
234:                }
235:
236:                setType(sValue);
237:            }
238:
239:            /**
240:             * Loads the data.
241:             */
242:            public void load() {
243:                try {
244:
245:                    NodeList providers = mDoc.getElementsByTagName("provides");
246:                    mNoOfProviders = providers.getLength();
247:
248:                    NodeList consumers = mDoc.getElementsByTagName("consumes");
249:                    mNoOfConsumers = consumers.getLength();
250:                    mEPList = new EndpointInfo[mNoOfConsumers + mNoOfProviders];
251:                    setArtifacts();
252:                    for (int i = 0; i < mNoOfProviders; i++) {
253:                        Node node = providers.item(i);
254:                        EndpointInfo sb = new EndpointInfo();
255:                        setEndpoint(node, sb);
256:                        sb.setProvider();
257:
258:                        if (!isValid()) {
259:                            setError(mTranslator.getString(JMS_LOAD_DD_FAILED)
260:                                    + "\n" + getError());
261:
262:                            return;
263:                        }
264:
265:                        mEPList[i] = sb;
266:                    }
267:
268:                    for (int i = 0; i < mNoOfConsumers; i++) {
269:                        Node node = consumers.item(i);
270:                        EndpointInfo sb = new EndpointInfo();
271:                        setEndpoint(node, sb);
272:
273:                        if (!isValid()) {
274:                            setError(mTranslator.getString(JMS_LOAD_DD_FAILED)
275:                                    + "\n" + getError());
276:
277:                            return;
278:                        }
279:
280:                        mEPList[i + mNoOfProviders] = sb;
281:                    }
282:                } catch (Exception e) {
283:                    mLog.severe(mTranslator.getString(JMS_LOAD_DD_FAILED));
284:                    e.printStackTrace();
285:                    setError(getError()
286:                            + mTranslator.getString(JMS_LOAD_DD_FAILED) + "\n"
287:                            + e.getMessage());
288:                    setValid(false);
289:                }
290:            }
291:
292:            /**
293:             * Gets the local name from the quname.
294:             *
295:             * @param qname Qualified name of service.
296:             *
297:             * @return String local name.
298:             */
299:            private String getLocalName(String qname) {
300:                StringTokenizer tok = new StringTokenizer(qname, ":");
301:
302:                try {
303:                    if (tok.countTokens() == 1) {
304:                        return qname;
305:                    }
306:
307:                    tok.nextToken();
308:
309:                    return tok.nextToken();
310:                } catch (Exception e) {
311:                    return "";
312:                }
313:            }
314:
315:            /**
316:             * Gets the namespace from the qname.
317:             *
318:             * @param qname Qname of service.
319:             *
320:             * @return namespace namespace of service.
321:             */
322:            private String getNamespace(String qname) {
323:                StringTokenizer tok = new StringTokenizer(qname, ":");
324:                String prefix = null;
325:
326:                try {
327:                    if (tok.countTokens() == 1) {
328:                        return "";
329:                    }
330:
331:                    prefix = tok.nextToken();
332:
333:                    NamedNodeMap map = mDoc.getDocumentElement()
334:                            .getAttributes();
335:
336:                    for (int j = 0; j < map.getLength(); j++) {
337:                        Node n = map.item(j);
338:
339:                        if (n.getLocalName().trim().equals(prefix.trim())) {
340:                            return n.getNodeValue();
341:                        }
342:                    }
343:                } catch (Exception e) {
344:                    ;
345:                }
346:
347:                return "";
348:            }
349:
350:            /**
351:             * Class which holds the endpoint information.
352:             *
353:             * @author Sun Microsystems, Inc.
354:             */
355:            public class EndpointInfo {
356:                /**
357:                 * Interface name.
358:                 */
359:                private QName mInterfaceName;
360:
361:                /**
362:                 * Service name.
363:                 */
364:                private QName mServiceName;
365:
366:                /**
367:                 *  Endpoint name.
368:                 */
369:                private String mEndpointName;
370:
371:                /**
372:                 * Provider endpoint.
373:                 */
374:                private boolean mProvider = false;
375:
376:                /**
377:                 * Sets the endpoint name.
378:                 *
379:                 * @param epname endpoint name.
380:                 */
381:                public void setEndpointName(String epname) {
382:                    mEndpointName = epname;
383:                }
384:
385:                /**
386:                 * Returns the endpoint name.
387:                 *
388:                 * @return endpoint name.
389:                 */
390:                public String getEndpointName() {
391:                    return mEndpointName;
392:                }
393:
394:                /**
395:                 * Sets the interface name.
396:                 *
397:                 * @param intername interface name.
398:                 */
399:                public void setInterfaceName(QName intername) {
400:                    mInterfaceName = intername;
401:                }
402:
403:                /**
404:                 * Returns the interface name.
405:                 *
406:                 * @return interface name.
407:                 */
408:                public QName getInterfaceName() {
409:                    return mInterfaceName;
410:                }
411:
412:                /**
413:                 * Sets the endpoint as mProvider.
414:                 */
415:                public void setProvider() {
416:                    mProvider = true;
417:                }
418:
419:                /**
420:                 * Returns true if the endpoint is mProvider.
421:                 *
422:                 * @return true if mProvider endpoint.
423:                 */
424:                public boolean getProvider() {
425:                    return mProvider;
426:                }
427:
428:                /**
429:                 * Sets the service name.
430:                 *
431:                 * @param sername service name.
432:                 */
433:                public void setServiceName(QName sername) {
434:                    mServiceName = sername;
435:                }
436:
437:                /**
438:                 * Returns the service name.
439:                 *
440:                 * @return the service name.
441:                 */
442:                public QName getServiceName() {
443:                    return mServiceName;
444:                }
445:
446:                /**
447:                 * Returns the style of endpoint. 
448:                 *
449:                 * @return  mProvider or consumer.
450:                 */
451:                public int getStyle() {
452:                    if (getProvider()) {
453:                        return ConfigConstants.PROVIDER;
454:                    } else {
455:                        return ConfigConstants.CONSUMER;
456:                    }
457:                }
458:            }
459:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.