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