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