Source Code Cross Referenced for DeployHelper.java in  » ESB » open-esb » com » sun » jbi » engine » sequencing » 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.engine.sequencing.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.engine.sequencing.util;
030:
031:        import com.sun.jbi.engine.sequencing.DeploymentRegistry;
032:        import com.sun.jbi.engine.sequencing.SequencingEngineContext;
033:        import com.sun.jbi.engine.sequencing.SequencingEngineResources;
034:        import com.sun.jbi.engine.sequencing.servicelist.ServiceBean;
035:        import com.sun.jbi.engine.sequencing.servicelist.ServicelistBean;
036:        import com.sun.jbi.engine.sequencing.servicelist.ServicelistReader;
037:        import com.sun.jbi.engine.sequencing.servicelist.ServicelistValidator;
038:
039:        import org.w3c.dom.Document;
040:
041:        import java.io.File;
042:
043:        import java.util.logging.Logger;
044:
045:        import javax.xml.namespace.QName;
046:
047:        /**
048:         * This class ia  aHelper clas to do deployment.
049:         *
050:         * @author Sun Microsystems, Inc.
051:         */
052:        public class DeployHelper extends UtilBase implements 
053:                SequencingEngineResources {
054:            /**
055:             * Engine Context object.
056:             */
057:            private javax.jbi.component.ComponentContext mContext;
058:
059:            /**
060:             * DD reader
061:             */
062:            private DeployDescriptorReader mDeployDescriptorReader;
063:
064:            /**
065:             * Logger object.
066:             */
067:            private Logger mLog;
068:
069:            /**
070:             * List of endpoints.
071:             */
072:            private ServicelistBean mServicelist;
073:
074:            /**
075:             * Reader object to read config XML file.
076:             */
077:            private ServicelistReader mServicelistReader;
078:
079:            /**
080:             * Deployment Descriptor schema
081:             */
082:            private String mDDSchema;
083:
084:            /**
085:             * DeploymentDescriptor file
086:             */
087:            private String mDeploymentDescriptor;
088:
089:            /**
090:             * Service unit of deployment.
091:             */
092:            private String mSUID;
093:
094:            /**
095:             * Name of the schema file.
096:             */
097:            private String mSchemaFile;
098:
099:            /**
100:             * Name of the endpoint config XMl file.
101:             */
102:            private String mServicelistFile;
103:
104:            /**
105:             * Translator object for internationalization.
106:             */
107:            private StringTranslator mTranslator;
108:
109:            /**
110:             * Creates a new DeployHelper object.
111:             *
112:             * @param suId service unit id
113:             * @param suPath path of su.
114:             */
115:            public DeployHelper(String suId, String suPath) {
116:                mSUID = suId;
117:                mContext = SequencingEngineContext.getInstance().getContext();
118:                mServicelistFile = FileListing.getXMLFile(suPath);
119:                mSchemaFile = mContext.getInstallRoot() + File.separatorChar
120:                        + ConfigData.SCHEMA_FILE;
121:                mDeploymentDescriptor = suPath + File.separatorChar
122:                        + "META-INF" + File.separatorChar
123:                        + ConfigData.DEPLOY_DESCRIPTOR;
124:                mDDSchema = SequencingEngineContext.getInstance().getContext()
125:                        .getInstallRoot()
126:                        + File.separatorChar + ConfigData.JBI_SCHEMA_FILE;
127:                mLog = SequencingEngineContext.getInstance().getLogger();
128:                mTranslator = new StringTranslator();
129:                setValid(true);
130:            }
131:
132:            /**
133:             * Method which does the actual deployment.
134:             *
135:             * @param isDeploy true if deployment false if starting
136:             */
137:            public void doDeploy(boolean isDeploy) {
138:                mLog.fine(SEQ_FINE_DOING_DEPLOY);
139:
140:                try {
141:                    ServicelistValidator validator = new ServicelistValidator(
142:                            mSchemaFile, mServicelistFile);
143:                    validator.setValidating();
144:                    validator.validate();
145:
146:                    Document d = validator.getDocument();
147:
148:                    if ((!validator.isValid()) || (d == null)) {
149:                        mLog.severe(mTranslator.getString(
150:                                SEQ_INVALID_CONFIG_FILE, mServicelistFile));
151:                        mLog.severe(validator.getError());
152:                        setError(getError()
153:                                + "\n"
154:                                + mTranslator.getString(
155:                                        SEQ_INVALID_CONFIG_FILE,
156:                                        mServicelistFile) + "\n"
157:                                + validator.getError());
158:                        setValid(false);
159:
160:                        return;
161:                    }
162:
163:                    mServicelistReader = new ServicelistReader();
164:                    mServicelistReader.init(d);
165:                    mServicelist = mServicelistReader.getServicelistBean();
166:
167:                    if ((!mServicelistReader.isValid())
168:                            || (mServicelist == null)) {
169:                        mLog
170:                                .severe(mTranslator
171:                                        .getString(SEQ_CONFIGDATA_ERROR));
172:                        setError(mTranslator.getString(SEQ_CONFIGDATA_ERROR)
173:                                + "\n" + getError());
174:                        setValid(false);
175:
176:                        return;
177:                    }
178:
179:                    mServicelist.setDeploymentId(mSUID);
180:
181:                    if ((mDeploymentDescriptor != null)
182:                            && (new File(mDeploymentDescriptor)).exists()) {
183:                        doDDParsing();
184:                    }
185:
186:                    /**
187:                     * Here we have a violation of spec 1.0. The spec says that
188:                     * a jbi.xml must be present in an SU, 
189:                     * But we are making it optional here, just to make a backward
190:                     * compatibility.  
191:                     * This optionality will be made mandatory in future.
192:                     *  
193:                     */
194:                    /*else
195:                    {
196:                        setError(mTranslator.getString(SEQ_NO_DD) + "\n" + getError());
197:                        mLog.info(mTranslator.getString(SEQ_NO_DD));
198:                        setValid(false);
199:
200:                        return;
201:                    }
202:                     */
203:
204:                    if (isValid()) {
205:                        registerService();
206:                    }
207:
208:                    dump(mServicelist);
209:                } catch (Exception de) {
210:                    de.printStackTrace();
211:                    setException(de);
212:                    setValid(false);
213:                }
214:            }
215:
216:            /**
217:             * Verifies if a bean object is populated properly.
218:             *
219:             * @param eb servicelist bean
220:             *
221:             * @return true/ false
222:             */
223:            public boolean verify(ServicelistBean eb) {
224:                if (eb.getServicename().equals("")) {
225:                    mLog.severe(mTranslator
226:                            .getString(SEQ_INVALID_SERVICELIST_NAME));
227:
228:                    return false;
229:                }
230:
231:                int count = eb.getServiceCount();
232:
233:                for (int i = 0; i < count; i++) {
234:                    try {
235:                        ServiceBean sb = eb.getService(i);
236:
237:                        if (!verifyService(sb)) {
238:                            return false;
239:                        }
240:                    } catch (Exception e) {
241:                        mLog.warning(e.getMessage());
242:
243:                        return false;
244:                    }
245:                }
246:
247:                return true;
248:            }
249:
250:            /**
251:             * Verifies the registry for duplicate entries.
252:             */
253:            private void checkRegistry() {
254:                DeploymentRegistry dr = DeploymentRegistry.getInstance();
255:                String ser = mServicelist.getServicename();
256:
257:                if (dr.isDeployed(ser)) {
258:                    mLog.warning(mTranslator.getString(SEQ_DUPLICATE_ENDPOINT,
259:                            ser));
260:                }
261:            }
262:
263:            /**
264:             * Parses the deployment descriptor jbi.xml.
265:             */
266:            private void doDDParsing() {
267:                ServicelistValidator validator = new ServicelistValidator(
268:                        mDDSchema, mDeploymentDescriptor);
269:                validator.validate();
270:
271:                Document d = validator.getDocument();
272:
273:                if ((!validator.isValid()) || (d == null)) {
274:                    mLog.severe(mTranslator.getString(SEQ_INVALID_DD,
275:                            mDeploymentDescriptor));
276:                    setError(mTranslator.getString(SEQ_INVALID_DD,
277:                            mDeploymentDescriptor)
278:                            + " " + validator.getError());
279:                    setValid(false);
280:
281:                    return;
282:                }
283:
284:                /**
285:                 * Match service names in artifacts file ( endpoints.xml) and the DD.
286:                 * Every endpoint in the the DD file should be present in the
287:                 * artifacts file. We dont care if the artifacts file has more
288:                 * endpoints. Those will be ignored. The condition is the DD XML file
289:                 * should be a sub-set of artifacts file. The spec does not govern
290:                 * this logic so it is upto the component to decide how to veryify
291:                 * consistence between  DD and its artifacts.
292:                 */
293:                /**
294:                 * A valid question that arises here is why are we having 2 XML files
295:                 * to decorate an endpoint. The artifacts XML file is the older form
296:                 * which was used when the  spec did not accomodate any DD for an SU.
297:                 * So that is still around.  Any component specific decoration for the
298:                 * endpoints can be done  through the DD jbi.xml also. And that would
299:                 * be the correct way to do it. We dont do it that way because there
300:                 * are other modules that might           depend on the endpoints.xml
301:                 * file, so to maintain their functionality  the older endpoints.xml
302:                 * file is still used to decorate endpoints.
303:                 */
304:                mDeployDescriptorReader = new DeployDescriptorReader();
305:                mDeployDescriptorReader.init(d);
306:
307:                if (!mDeployDescriptorReader.isValid()) {
308:                    mLog.severe(mTranslator.getString(SEQ_INVALID_DD,
309:                            ConfigData.DEPLOY_DESCRIPTOR));
310:                    setError(mTranslator.getString(SEQ_INVALID_DD,
311:                            ConfigData.DEPLOY_DESCRIPTOR)
312:                            + " " + mDeployDescriptorReader.getError());
313:                    setValid(false);
314:
315:                    return;
316:                }
317:
318:                if (mDeployDescriptorReader.getConsumerCount() != 0) {
319:                    setError(mTranslator
320:                            .getString(SEQ_INCONSISTENT_CONSUMER_DATA));
321:
322:                    return;
323:                }
324:
325:                if (mDeployDescriptorReader.getProviderCount() != 1) {
326:                    setError(mTranslator
327:                            .getString(SEQ_INCONSISTENT_PROVIDER_DATA));
328:
329:                    return;
330:                }
331:
332:                QName sername = new QName(mServicelist.getNamespace(),
333:                        mServicelist.getServicename());
334:                QName intername = new QName(mServicelist
335:                        .getInterfaceNamespace(), mServicelist
336:                        .getInterfaceName());
337:                String epname = mServicelist.getEndpointName();
338:
339:                if (!mDeployDescriptorReader.isPresent(sername, intername,
340:                        epname)) {
341:                    setError(mTranslator.getString(SEQ_INCONSISTENT_DATA));
342:
343:                    return;
344:                }
345:            }
346:
347:            /**
348:             * Dumps deployment information.
349:             *
350:             * @param slb list bean
351:             */
352:            private void dump(ServicelistBean slb) {
353:                mLog.fine("Dumping contents of Config file ");
354:                mLog.fine("Deployment id " + slb.getDeploymentId()
355:                        + " has a list with name " + slb.getServicename()
356:                        + " with namespace " + slb.getNamespace()
357:                        + " and endpoint name " + slb.getEndpointName()
358:                        + " and operation " + slb.getOperation());
359:                mLog.fine("With " + slb.getServiceCount() + " services ");
360:
361:                int count = slb.getServiceCount();
362:
363:                for (int j = 0; j < count; j++) {
364:                    ServiceBean sb = slb.getService(j);
365:                    mLog.fine("Service " + j + " with name " + sb.getName()
366:                            + " and description " + sb.getDescription()
367:                            + " and serviceid " + sb.getServiceid()
368:                            + " will be invoked with operation "
369:                            + sb.getOperation() + " with a time out of "
370:                            + sb.getTimeout());
371:                }
372:            }
373:
374:            /**
375:             * Registers a bean and service name with registry.
376:             */
377:            private void registerService() {
378:                DeploymentRegistry dr = DeploymentRegistry.getInstance();
379:                String ser = mServicelist.getNamespace()
380:                        + mServicelist.getServicename()
381:                        + mServicelist.getEndpointName()
382:                        + mServicelist.getOperation();
383:
384:                if (dr.isDeployed(ser)) {
385:                    mLog.warning(mTranslator.getString(SEQ_DUPLICATE_ENDPOINT,
386:                            ser));
387:                    setError(getError()
388:                            + "\n"
389:                            + mTranslator
390:                                    .getString(SEQ_DUPLICATE_ENDPOINT, ser));
391:                    setValid(false);
392:
393:                    return;
394:                }
395:
396:                if (!verify(mServicelist)) {
397:                    mLog.severe(mTranslator
398:                            .getString(SEQ_INVALID_CONFIG_FILE_INFO));
399:                    setError(getError()
400:                            + "\n"
401:                            + mTranslator
402:                                    .getString(SEQ_INVALID_CONFIG_FILE_INFO));
403:                    setValid(false);
404:                } else {
405:                    dr.registerService(ser, mServicelist);
406:                }
407:            }
408:
409:            /**
410:             * Checks if the service bean info is valid.
411:             *
412:             * @param sb service bean
413:             *
414:             * @return true if valid
415:             */
416:            private boolean verifyService(ServiceBean sb) {
417:                if (sb == null) {
418:                    return false;
419:                }
420:
421:                if ((sb.getName() == null) || (sb.getName().equals(""))) {
422:                    mLog.severe(mTranslator.getString(SEQ_INVALID_SERVICE));
423:                    setError(getError() + "\n"
424:                            + mTranslator.getString(SEQ_INVALID_SERVICE));
425:
426:                    return false;
427:                }
428:
429:                if ((sb.getServiceid() == null)
430:                        || (sb.getServiceid().equals(""))) {
431:                    mLog.severe(mTranslator.getString(SEQ_INVALID_SERVICEID, sb
432:                            .getName()));
433:                    setError(getError()
434:                            + "\n"
435:                            + mTranslator.getString(SEQ_INVALID_SERVICEID, sb
436:                                    .getName()));
437:
438:                    return false;
439:                }
440:
441:                if ((sb.getOperation() == null)
442:                        || (sb.getOperation().equals(""))) {
443:                    mLog.severe(mTranslator.getString(SEQ_INVALID_OPERATION, sb
444:                            .getServiceid()));
445:                    setError(getError()
446:                            + "\n"
447:                            + mTranslator.getString(SEQ_INVALID_OPERATION, sb
448:                                    .getServiceid()));
449:
450:                    return false;
451:                }
452:
453:                return true;
454:            }
455:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.