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