Source Code Cross Referenced for DeployHelper.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:         * @(#)DeployHelper.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.EndpointBean;
034:        import com.sun.jbi.binding.jms.JMSBindingContext;
035:        import com.sun.jbi.binding.jms.JMSBindingResolver;
036:        import com.sun.jbi.binding.jms.JMSBindingResources;
037:
038:        import com.sun.jbi.binding.jms.config.ConfigConstants;
039:
040:        import com.sun.jbi.common.ConfigFileValidator;
041:        import com.sun.jbi.common.FileListing;
042:
043:        import com.sun.jbi.wsdl2.Description;
044:
045:        import java.io.File;
046:
047:        import java.util.logging.Logger;
048:
049:        import javax.xml.namespace.QName;
050:
051:        import org.w3c.dom.Document;
052:
053:        /**
054:         * This class ia  a Helper clas to do deployment.
055:         *
056:         * @author Sun Microsystems Inc.
057:         * 
058:         */
059:        public class DeployHelper extends com.sun.jbi.binding.jms.util.UtilBase
060:                implements  JMSBindingResources {
061:
062:            /**
063:             * Reader object to read config XML file.
064:             */
065:            private ConfigReader mConfigReader;
066:
067:            /**
068:             * Resolver object.
069:             */
070:            private JMSBindingResolver mResolver;
071:
072:            /**
073:             * Jbi.xml deployment descriptor file.
074:             */
075:            private String mDeploymentDescriptor;
076:
077:            /**
078:             * Logger object.
079:             */
080:            private Logger mLogger;
081:
082:            /**
083:             * Name of the endpoint config XMl file.
084:             */
085:            private String mEndpointFile;
086:
087:            /**
088:             * Application Sub assembly of deployment.
089:             */
090:            private String mSUID;
091:
092:            /**
093:             * Name of the schema file.
094:             */
095:            private String mSchemaFile;
096:            /**
097:             *    Status.
098:             */
099:            private String mStatus = "";
100:
101:            /**
102:             * Path of the sub assembly.
103:             */
104:            private String mSuPath;
105:
106:            /**
107:             * Wsdl file name.
108:             */
109:            private String mWsdlFile;
110:
111:            /**
112:             * String translator.
113:             */
114:            private StringTranslator mStringTranslator;
115:
116:            /**
117:             * Wsdl 2.0 reader.
118:             */
119:            private WSDLFileReader mWsdlReader;
120:
121:            /**
122:             * WSDL 1.1 reader
123:             */
124:            private WSDL11FileReader mWsdl11Reader;
125:            /**
126:             * List of endpoints.
127:             */
128:            private EndpointBean[] mEndpointList;
129:
130:            /**
131:             * Deployment descriptor schema.
132:             */
133:            private String mDDSchema;
134:
135:            /**
136:             * Deploy descriptor reader.
137:             */
138:            private DeployDescriptorReader mDeployDescriptorReader;
139:
140:            /**
141:             * Creates a new DeployHelper object.
142:             *
143:             * @param suId application sub assembly Id.
144:             * @param suPath service unit path.
145:             * @param context binding context.
146:             * @param reslv RESOLVER
147:             */
148:            public DeployHelper(String suId, String suPath,
149:                    javax.jbi.component.ComponentContext context,
150:                    JMSBindingResolver reslv) {
151:                mSUID = suId;
152:                mResolver = reslv;
153:                mEndpointFile = FileListing.getXMLFile(suPath);
154:                mWsdlFile = FileListing.getWSDLFile(suPath);
155:                mSchemaFile = context.getInstallRoot()
156:                        + ConfigConstants.JMS_DEPLOY_SCHEMA_FILE;
157:                mDDSchema = JMSBindingContext.getInstance().getContext()
158:                        .getInstallRoot()
159:                        + ConfigConstants.JMS_DD_FILE_SCHEMA;
160:                mLogger = JMSBindingContext.getInstance().getLogger();
161:                mDeploymentDescriptor = suPath + File.separatorChar
162:                        + "META-INF" + File.separatorChar
163:                        + ConfigConstants.DEPLOY_DESCRIPTOR;
164:                mStringTranslator = JMSBindingContext.getInstance()
165:                        .getStringTranslator();
166:                setValid(true);
167:            }
168:
169:            /**
170:             * Returns the status message.
171:             *
172:             * @return sttaus message corresponding to the operation perfomed.
173:             */
174:            public String getStatusMessage() {
175:                return mStatus;
176:            }
177:
178:            /**
179:             * Method which does the actual deployment.
180:             *
181:             * @param isDeploy denotes if its during deployment or start.
182:             */
183:            public void doDeploy(boolean isDeploy) {
184:                super .clear();
185:
186:                try {
187:                    if ((mDeploymentDescriptor != null)
188:                            && (new File(mDeploymentDescriptor)).exists()) {
189:                        doDDParsing();
190:                        if ((!isValid()) && isDeploy) {
191:                            return;
192:                        }
193:                    }
194:
195:                    String type = "WSDL20";
196:                    if (mDeployDescriptorReader != null) {
197:                        type = mDeployDescriptorReader.getType();
198:                        mLogger.warning(mStringTranslator
199:                                .getString(JMS_DESCRIPTOR_NOT_FOUND));
200:                    }
201:
202:                    if (mDeployDescriptorReader.getType().equalsIgnoreCase(
203:                            "WSDL20")
204:                            && (mWsdlFile != null)
205:                            && (new File(mWsdlFile)).exists()) {
206:                        doWSDLDeploy();
207:                    } else if (mDeployDescriptorReader.getType()
208:                            .equalsIgnoreCase("WSDL11")
209:                            && (mWsdlFile != null)
210:                            && (new File(mWsdlFile)).exists()) {
211:                        doWSDL11Deploy();
212:                    } else if ((mEndpointFile != null)
213:                            && (new File(mEndpointFile)).exists()) {
214:                        doConfigDeploy();
215:                    } else {
216:                        setError(mStringTranslator
217:                                .getString(JMS_ARTIFACT_NOT_FOUND));
218:                        mLogger.info(mStringTranslator
219:                                .getString(JMS_ARTIFACT_NOT_FOUND));
220:                        return;
221:                    }
222:                    if (mDeployDescriptorReader != null) {
223:                        if (isValid()) {
224:                            checkConsistency();
225:                        }
226:                    }
227:
228:                    /**
229:                     * Here we have a violation of spec 1.0. The spec says that
230:                     * a jbi.xml must be present in an SU, 
231:                     * But we are making it optional here, just to make a backward
232:                     * compatibility.  
233:                     * This optionality will be made mandatory in future.
234:                     *  
235:                     */
236:
237:                    /*
238:                     else
239:                     {
240:                         setError(mStringTranslator.getString(JMS_NO_DD) + "\n" + getError());
241:                         mLog.info(mStringTranslator.getString(JMS_NO_DD));
242:                         setValid(false);
243:
244:                         return;
245:                     }
246:                     */
247:
248:                    if ((!isValid()) && isDeploy) {
249:                        return;
250:                    }
251:                    deployEndpoints();
252:                    EndpointRegistry dr = JMSBindingContext.getInstance()
253:                            .getRegistry();
254:                    dr.persist();
255:                } catch (Exception de) {
256:                    setError(de.getMessage());
257:                    setException(de);
258:                    de.printStackTrace();
259:                }
260:            }
261:
262:            /**
263:             * Sets the status message.
264:             *
265:             * @param status string for status.
266:             */
267:            private void setStatusMessage(String status) {
268:                mStatus = status;
269:            }
270:
271:            /**
272:             * Deploys the endpoints.
273:             */
274:            private void deployEndpoints() {
275:                EndpointRegistry dr = JMSBindingContext.getInstance()
276:                        .getRegistry();
277:                int dups = 0;
278:                for (int i = 0; i < mEndpointList.length; i++) {
279:                    String epName = mEndpointList[i].getUniqueName();
280:
281:                    if (dr.containsEndpoint(mEndpointList[i])
282:                            || dr.containsDestination(mEndpointList[i])) {
283:                        dups++;
284:                        mLogger.warning(mStringTranslator.getString(
285:                                JMS_DUPLICATE_ENDPOINT, epName));
286:                        setWarning(mStringTranslator.getString(
287:                                JMS_DUPLICATE_ENDPOINT, epName));
288:                    } else {
289:                        //Register the endpoint with the Deployment Registry   
290:                        String regKey = dr.registerEndpoint(mEndpointList[i]);
291:                    }
292:
293:                    if (mEndpointList.length == dups) {
294:                        setError(mStringTranslator
295:                                .getString(JMS_DUPLICATE_ENDPOINTS));
296:                        return;
297:                    }
298:                }
299:            }
300:
301:            /**
302:             * Deployment in case of an XML file.
303:             */
304:            private void doConfigDeploy() {
305:                ConfigFileValidator validator = new ConfigFileValidator(
306:                        mSchemaFile, mEndpointFile);
307:                validator.setValidating();
308:                validator.validate();
309:
310:                Document d = validator.getDocument();
311:
312:                if ((!validator.isValid()) || (d == null)) {
313:                    mLogger.severe(mStringTranslator.getString(
314:                            JMS_INVALID_CONFIG_FILE, mEndpointFile));
315:                    setError(mStringTranslator.getString(
316:                            JMS_INVALID_CONFIG_FILE, mEndpointFile)
317:                            + " " + validator.getError());
318:
319:                    return;
320:                }
321:
322:                mConfigReader = new ConfigReader();
323:                mConfigReader.init(d);
324:
325:                if (!mConfigReader.isValid()) {
326:                    mLogger.severe(mStringTranslator.getString(
327:                            JMS_INVALID_CONFIG_FILE, mEndpointFile));
328:                    setError(mStringTranslator.getString(
329:                            JMS_INVALID_CONFIG_FILE, mEndpointFile)
330:                            + " " + mConfigReader.getError());
331:
332:                    return;
333:                }
334:
335:                setWarning(mConfigReader.getWarning());
336:                mEndpointList = mConfigReader.getEndpoint();
337:
338:                for (int i = 0; i < mEndpointList.length; i++) {
339:                    mEndpointList[i].setDeploymentId(mSUID);
340:                }
341:            }
342:
343:            /**
344:             * Deployment for a WSDL 1.1 file.
345:             */
346:            private void doWSDL11Deploy() {
347:                mWsdl11Reader = new WSDL11FileReader(mResolver);
348:                mWsdl11Reader.init(mWsdlFile);
349:
350:                if (!mWsdl11Reader.isValid()) {
351:                    mLogger.severe(mStringTranslator.getString(
352:                            JMS_INVALID_WSDL_FILE, mWsdlFile));
353:                    setError(mStringTranslator.getString(JMS_INVALID_WSDL_FILE,
354:                            mWsdlFile)
355:                            + " " + mWsdl11Reader.getError());
356:
357:                    return;
358:                }
359:
360:                setWarning(mWsdl11Reader.getWarning());
361:
362:                mEndpointList = mWsdl11Reader.getEndpoint();
363:
364:                for (int i = 0; i < mEndpointList.length; i++) {
365:                    mEndpointList[i].setDeploymentId(mSUID);
366:                }
367:            }
368:
369:            /**
370:             * Deployment for a WSDL file.
371:             */
372:            private void doWSDLDeploy() {
373:                WSDLFileValidator validator = null;
374:                validator = new WSDLFileValidator(mWsdlFile);
375:                validator.validate();
376:
377:                Description d = validator.getDocument();
378:
379:                if ((!validator.isValid()) || (d == null)) {
380:                    mLogger.severe(mStringTranslator.getString(
381:                            JMS_INVALID_WSDL_FILE, mWsdlFile));
382:                    setError(mStringTranslator.getString(JMS_INVALID_WSDL_FILE,
383:                            mWsdlFile)
384:                            + " " + validator.getError());
385:
386:                    return;
387:                }
388:
389:                mWsdlReader = new WSDLFileReader(mResolver);
390:                mWsdlReader.init(d);
391:
392:                if (!mWsdlReader.isValid()) {
393:                    mLogger.severe(mStringTranslator.getString(
394:                            JMS_INVALID_WSDL_FILE, mWsdlFile));
395:                    setError(mStringTranslator.getString(JMS_INVALID_WSDL_FILE,
396:                            mWsdlFile)
397:                            + " " + mWsdlReader.getError());
398:
399:                    return;
400:                }
401:
402:                setWarning(mWsdlReader.getWarning());
403:
404:                mEndpointList = mWsdlReader.getEndpoint();
405:
406:                for (int i = 0; i < mEndpointList.length; i++) {
407:                    mEndpointList[i].setDeploymentId(mSUID);
408:                }
409:            }
410:
411:            /**
412:             * Parses the deployment descriptor jbi.xml.
413:             */
414:            private void doDDParsing() {
415:                ConfigFileValidator validator = new ConfigFileValidator(
416:                        mDDSchema, mDeploymentDescriptor);
417:                validator.setValidating();
418:                validator.validate();
419:
420:                Document d = validator.getDocument();
421:
422:                if ((!validator.isValid()) || (d == null)) {
423:                    mLogger.severe(mStringTranslator.getString(JMS_INVALID_DD,
424:                            mDeploymentDescriptor));
425:                    setError(mStringTranslator.getString(JMS_INVALID_DD,
426:                            mDeploymentDescriptor)
427:                            + " " + validator.getError());
428:                    setValid(false);
429:
430:                    return;
431:                }
432:
433:                /**
434:                 * Match service names in artifacts file ( endpoints.xml) and the DD.
435:                 * Every endpoint in the the DD file should be present in the
436:                 * artifacts file. We dont care if the artifacts file has more
437:                 * endpoints. Those will be ignored. The condition is the DD XML file
438:                 * should be a sub-set of artifacts file. The spec does not govern
439:                 * this logic so it is upto the component to decide how to veryify
440:                 * consistence between  DD and its artifacts.
441:                 */
442:                /**
443:                 * A valid question that arises here is why are we having 2 XML files
444:                 * to decorate an endpoint. The artifacts XML file is the older form
445:                 * which was used when the  spec did not accomodate any DD for an SU.
446:                 * So that is still around.  Any component specific decoration for the
447:                 * endpoints can be done  through the DD jbi.xml also. And that would
448:                 * be the correct way to do it. We dont do it that way because there
449:                 * are other modules that might           depend on the endpoints.xml
450:                 * file, so to maintain their functionality  the older endpoints.xml
451:                 * file is still used to decorate endpoints.
452:                 */
453:                mDeployDescriptorReader = new DeployDescriptorReader();
454:                mDeployDescriptorReader.init(d);
455:
456:                if (!mDeployDescriptorReader.isValid()) {
457:                    mLogger.severe(mStringTranslator.getString(JMS_INVALID_DD,
458:                            mEndpointFile));
459:                    setError(mStringTranslator.getString(JMS_INVALID_DD,
460:                            mEndpointFile)
461:                            + " " + mDeployDescriptorReader.getError());
462:                    setValid(false);
463:
464:                    return;
465:                }
466:
467:            }
468:
469:            /**
470:             * Checks the consistency of information between the jbi.xml and
471:             * a configuration file.
472:             */
473:
474:            private void checkConsistency() {
475:                if (getProviderCount() != mDeployDescriptorReader
476:                        .getProviderCount()) {
477:                    setError(mStringTranslator
478:                            .getString(JMS_INCONSISTENT_PROVIDER_DATA));
479:
480:                    return;
481:                }
482:
483:                if (getConsumerCount() != mDeployDescriptorReader
484:                        .getConsumerCount()) {
485:                    setError(mStringTranslator
486:                            .getString(JMS_INCONSISTENT_CONSUMER_DATA));
487:
488:                    return;
489:                }
490:
491:                if (mEndpointList != null) {
492:                    for (int i = 0; i < mEndpointList.length; i++) {
493:                        EndpointBean eb = mEndpointList[i];
494:                        QName sername = new QName(eb
495:                                .getValue(ConfigConstants.SERVICE_NAMESPACE),
496:                                eb.getValue(ConfigConstants.SERVICENAME));
497:                        QName intername = new QName(
498:                                eb
499:                                        .getValue(ConfigConstants.INTERFACE_NAMESPACE),
500:                                eb
501:                                        .getValue(ConfigConstants.INTERFACE_LOCALNAME));
502:                        String epname = eb
503:                                .getValue(ConfigConstants.ENDPOINTNAME);
504:                        int role = eb.getRole();
505:
506:                        if (!mDeployDescriptorReader.isPresent(sername,
507:                                intername, epname, role)) {
508:                            setError(mStringTranslator.getString(
509:                                    JMS_INCONSISTENT_DATA, sername, intername,
510:                                    epname));
511:
512:                            return;
513:                        }
514:                    }
515:                }
516:            }
517:
518:            /**
519:             * Returns the consumer endpoint count.
520:             *
521:             * @return  consumer endpoints.
522:             */
523:            public int getConsumerCount() {
524:                int count = 0;
525:                if (mEndpointList == null) {
526:                    return 0;
527:                }
528:                for (int i = 0; i < mEndpointList.length; i++) {
529:                    EndpointBean eb = mEndpointList[i];
530:
531:                    if (eb.getRole() == ConfigConstants.CONSUMER) {
532:                        count++;
533:                    }
534:                }
535:
536:                return count;
537:            }
538:
539:            /**
540:             * Returns the number of provider endpoints in the artifacts file.
541:             *
542:             * @return  provider endpoint count.
543:             */
544:            public int getProviderCount() {
545:                int count = 0;
546:
547:                if (mEndpointList == null) {
548:                    return 0;
549:                }
550:                for (int i = 0; i < mEndpointList.length; i++) {
551:                    EndpointBean eb = mEndpointList[i];
552:
553:                    if (eb.getRole() == ConfigConstants.PROVIDER) {
554:                        count++;
555:                    }
556:                }
557:
558:                return count;
559:            }
560:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.