Source Code Cross Referenced for DeployDescriptorReader.java in  » Workflow-Engines » Dalma » com » sun » jbi » binding » file » util » 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 » Workflow Engines » Dalma » com.sun.jbi.binding.file.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // Copyright (c) 2004-2005 Sun Microsystems Inc., All Rights Reserved.
002:
003:        /*
004:         * DeployDecriptorReader.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.util;
012:
013:        import com.sun.jbi.binding.file.EndpointBean;
014:        import com.sun.jbi.binding.file.FileBindingContext;
015:        import com.sun.jbi.binding.file.FileBindingResources;
016:
017:        import org.w3c.dom.Document;
018:        import org.w3c.dom.Element;
019:        import org.w3c.dom.NamedNodeMap;
020:        import org.w3c.dom.Node;
021:        import org.w3c.dom.NodeList;
022:
023:        import java.util.StringTokenizer;
024:        import java.util.logging.Logger;
025:
026:        import javax.xml.namespace.QName;
027:        import javax.xml.parsers.DocumentBuilderFactory;
028:
029:        /**
030:         * This class reads the SU jbi.xml and loads up the values.
031:         *
032:         * @author Sun Microsystems, Inc.
033:         */
034:        public class DeployDescriptorReader extends UtilBase implements 
035:                FileBindingResources {
036:            /**
037:             * Document object of the XML config file.
038:             */
039:            private Document mDoc;
040:
041:            /**
042:             * Logger Object
043:             */
044:            private Logger mLog;
045:
046:            /**
047:             * i18n
048:             */
049:            private StringTranslator mTranslator;
050:
051:            /**
052:             * List of endpoints in the SU jbi.xml.
053:             */
054:            private EndpointInfo[] mEPList;
055:
056:            /**
057:             * Number of consumers.
058:             */
059:            private int mNoOfConsumers;
060:
061:            /**
062:             * Number of providers.    
063:             */
064:            private int mNoOfProviders;
065:
066:            /**
067:             * The total number of end points in the config file
068:             */
069:            private int mTotalEndpoints = 0;
070:
071:            /**
072:             * Creates a new ConfigReader object.
073:             */
074:            public DeployDescriptorReader() {
075:                mLog = FileBindingContext.getInstance().getLogger();
076:                mTranslator = new StringTranslator();
077:                setValid(true);
078:            }
079:
080:            /**
081:             * Returns the number of consumer endpoints.
082:             *
083:             * @return consumer endpoint count.
084:             */
085:            public int getConsumerCount() {
086:                return mNoOfConsumers;
087:            }
088:
089:            /**
090:             * Sets the endpoitn attributes.
091:             *
092:             * @param node provider/consumer node.
093:             * @param ep endpoint information.
094:             */
095:            public void setEndpoint(Node node, EndpointInfo ep) {
096:                NamedNodeMap map = node.getAttributes();
097:
098:                try {
099:                    String epname = map.getNamedItem("endpoint-name")
100:                            .getNodeValue();
101:                    String sername = map.getNamedItem("service-name")
102:                            .getNodeValue();
103:                    String intername = map.getNamedItem("interface-name")
104:                            .getNodeValue();
105:                    ep.setServiceName(new QName(getNamespace(sername),
106:                            getLocalName(sername)));
107:                    ep.setInterfaceName(new QName(getNamespace(intername),
108:                            getLocalName(intername)));
109:                    ep.setEndpointName(epname);
110:                } catch (Exception e) {
111:                    e.printStackTrace();
112:                    setError(getError()
113:                            + mTranslator.getString(FBC_LOAD_DD_FAILED) + "\n"
114:                            + e.getMessage());
115:                    setValid(false);
116:                }
117:            }
118:
119:            /**
120:             * Verifies if the endpoint in the artifacts XML file is present in
121:             * the deployment descriptor.
122:             *
123:             * @param sername  service name.
124:             * @param intername  interface name.
125:             * @param epname  endpoint name.
126:             * @param role  role.
127:             *
128:             * @return  true if present.
129:             */
130:            public boolean isPresent(QName sername, QName intername,
131:                    String epname, int role) {
132:
133:                for (int ep = 0; ep < mEPList.length; ep++) {
134:
135:                    if ((mEPList[ep].getServiceName().toString().equals(sername
136:                            .toString()))
137:                            && (mEPList[ep].getInterfaceName().toString()
138:                                    .equals(intername.toString()))
139:                            && (mEPList[ep].getEndpointName().equals(epname))
140:                            && (mEPList[ep].getStyle() == role)) {
141:                        return true;
142:                    }
143:                }
144:
145:                return false;
146:            }
147:
148:            /**
149:             * Returns the number of provider endpoints.
150:             *
151:             * @return provider endpoint count.
152:             */
153:            public int getProviderCount() {
154:                return mNoOfProviders;
155:            }
156:
157:            /**
158:             * Initializes the config file and loads services.
159:             *
160:             * @param doc Name of the config file.
161:             */
162:            public void init(Document doc) {
163:                try {
164:                    mDoc = doc;
165:                    mDoc.getDocumentElement().normalize();
166:                    load();
167:                } catch (Exception genException) {
168:                    mLog.severe(mTranslator.getString(FBC_LOAD_DD_FAILED));
169:                    genException.printStackTrace();
170:                    setException(genException);
171:                    setError(getError()
172:                            + mTranslator.getString(FBC_LOAD_DD_FAILED) + "\n"
173:                            + genException.getMessage());
174:                    setValid(false);
175:                }
176:            }
177:
178:            /**
179:             * Loads the data.
180:             */
181:            public void load() {
182:                try {
183:                    NodeList providers = mDoc.getElementsByTagName("provides");
184:                    mNoOfProviders = providers.getLength();
185:
186:                    NodeList consumers = mDoc.getElementsByTagName("consumes");
187:                    mNoOfConsumers = consumers.getLength();
188:                    mEPList = new EndpointInfo[mNoOfConsumers + mNoOfProviders];
189:
190:                    for (int i = 0; i < mNoOfProviders; i++) {
191:                        Node node = providers.item(i);
192:                        EndpointInfo sb = new EndpointInfo();
193:                        setEndpoint(node, sb);
194:                        sb.setProvider();
195:
196:                        if (!isValid()) {
197:                            setError(mTranslator.getString(FBC_LOAD_DD_FAILED)
198:                                    + "\n" + getError());
199:
200:                            return;
201:                        }
202:
203:                        mEPList[i] = sb;
204:                    }
205:
206:                    for (int i = 0; i < mNoOfConsumers; i++) {
207:                        Node node = consumers.item(i);
208:                        EndpointInfo sb = new EndpointInfo();
209:                        setEndpoint(node, sb);
210:
211:                        if (!isValid()) {
212:                            setError(mTranslator.getString(FBC_LOAD_DD_FAILED)
213:                                    + "\n" + getError());
214:
215:                            return;
216:                        }
217:
218:                        mEPList[i + mNoOfProviders] = sb;
219:                    }
220:                } catch (Exception e) {
221:                    mLog.severe("Failed loading DD");
222:                    e.printStackTrace();
223:                    setError(getError()
224:                            + mTranslator.getString(FBC_LOAD_DD_FAILED) + "\n"
225:                            + e.getMessage());
226:                    setValid(false);
227:                }
228:            }
229:
230:            /**
231:             * Gets the local name from the quname.
232:             *
233:             * @param qname Qualified name of service.
234:             *
235:             * @return String local name
236:             */
237:            private String getLocalName(String qname) {
238:                StringTokenizer tok = new StringTokenizer(qname, ":");
239:
240:                try {
241:                    if (tok.countTokens() == 1) {
242:                        return qname;
243:                    }
244:
245:                    tok.nextToken();
246:
247:                    return tok.nextToken();
248:                } catch (Exception e) {
249:                    return "";
250:                }
251:            }
252:
253:            /**
254:             * Gets the namespace from the qname.
255:             *
256:             * @param qname Qname of service
257:             *
258:             * @return namespace namespace of service
259:             */
260:            private String getNamespace(String qname) {
261:                StringTokenizer tok = new StringTokenizer(qname, ":");
262:                String prefix = null;
263:
264:                try {
265:                    if (tok.countTokens() == 1) {
266:                        return "";
267:                    }
268:
269:                    prefix = tok.nextToken();
270:
271:                    NamedNodeMap map = mDoc.getDocumentElement()
272:                            .getAttributes();
273:
274:                    for (int j = 0; j < map.getLength(); j++) {
275:                        Node n = map.item(j);
276:
277:                        if (n.getLocalName().trim().equals(prefix.trim())) {
278:                            return n.getNodeValue();
279:                        }
280:                    }
281:                } catch (Exception e) {
282:                    ;
283:                }
284:
285:                return "";
286:            }
287:
288:            /**
289:             * Class which holds the endpoint information.
290:             *
291:             * @author Sun Microsystems, Inc.
292:             */
293:            public class EndpointInfo {
294:                /**
295:                 * Interface name.
296:                 */
297:                QName interfacename;
298:
299:                /**
300:                 * Service name.
301:                 */
302:                QName servicename;
303:
304:                /**
305:                 *  Endpoint name.
306:                 */
307:                String endpointname;
308:
309:                /**
310:                 * Provider endpoint.
311:                 */
312:                boolean provider = false;
313:
314:                /**
315:                 * Sets the endpoint name.
316:                 *
317:                 * @param epname endpoint name.
318:                 */
319:                public void setEndpointName(String epname) {
320:                    endpointname = epname;
321:                }
322:
323:                /**
324:                 * Returns the endpoint name.
325:                 *
326:                 * @return endpoint name.
327:                 */
328:                public String getEndpointName() {
329:                    return endpointname;
330:                }
331:
332:                /**
333:                 * Sets the interface name.
334:                 *
335:                 * @param intername interface name.
336:                 */
337:                public void setInterfaceName(QName intername) {
338:                    interfacename = intername;
339:                }
340:
341:                /**
342:                 * Returns the interface name.
343:                 *
344:                 * @return interface name.
345:                 */
346:                public QName getInterfaceName() {
347:                    return interfacename;
348:                }
349:
350:                /**
351:                 * Sets the endpoint as provider.
352:                 */
353:                public void setProvider() {
354:                    provider = true;
355:                }
356:
357:                /**
358:                 * Returns true if the endpoint is provider.
359:                 *
360:                 * @return true if provider endpoint.
361:                 */
362:                public boolean getProvider() {
363:                    return provider;
364:                }
365:
366:                /**
367:                 * Sets the service name.
368:                 *
369:                 * @param sername service name.
370:                 */
371:                public void setServiceName(QName sername) {
372:                    servicename = sername;
373:                }
374:
375:                /**
376:                 * Returns the service name.
377:                 *
378:                 * @return the service name.
379:                 */
380:                public QName getServiceName() {
381:                    return servicename;
382:                }
383:
384:                /**
385:                 * Returns the style of endpoint. 
386:                 *
387:                 * @return  provider or consumer.
388:                 */
389:                public int getStyle() {
390:                    if (getProvider()) {
391:                        return ConfigData.PROVIDER;
392:                    } else {
393:                        return ConfigData.CONSUMER;
394:                    }
395:                }
396:            }
397:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.