Source Code Cross Referenced for WebContainerBase.java in  » Portal » Open-Portal » com » sun » portal » fabric » tasks » 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 » Portal » Open Portal » com.sun.portal.fabric.tasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: WebContainerBase.java,v 1.49.4.1 2007/04/16 09:46:52 ns208321 Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.fabric.tasks;
014:
015:        import java.io.*;
016:        import java.lang.RuntimeException;
017:        import java.util.*;
018:        import java.util.logging.Level;
019:        import java.util.logging.Logger;
020:        import java.util.logging.LogRecord;
021:
022:        import org.jdom.Document;
023:        import org.jdom.Element;
024:        import org.jdom.JDOMException;
025:        import org.jdom.input.SAXBuilder;
026:
027:        import com.sun.portal.admin.common.InstanceAttributes;
028:        import com.sun.portal.fabric.util.ExecuteUtil;
029:        import com.sun.portal.fabric.util.NetworkUtil;
030:        import com.sun.portal.fabric.util.ClasspathGenUtil;
031:        import com.sun.portal.fabric.util.FileUtil;
032:        import com.sun.portal.admin.common.context.PSConfigContext;
033:        import com.sun.portal.util.ResourceLoader;
034:
035:        import com.sun.portal.log.common.PortalLogger;
036:
037:        abstract public class WebContainerBase implements  WebContainer,
038:                WebContainerTasks {
039:
040:            private String derbyHost = null;
041:            private String derbyPort = null;
042:            private String databaseName = null;
043:            private String resourceName = null;
044:            private String poolName = null;
045:
046:            protected String wcType = null;
047:            protected String wcPrintableInstanceName = null;
048:            protected String psLibDir = null;
049:
050:            private static Logger logger = PortalLogger
051:                    .getLogger(WebContainerBase.class);
052:            protected ExecuteUtil execUtil = null;
053:            protected Map wcAttributes = null;
054:
055:            protected String domainID = null;
056:            protected String portalID = null;
057:            protected String instanceID = null;
058:
059:            //PS7.0 specific jar to see if web-container was configured
060:            static final String PORTAL_TEST_JAR = "ps_util.jar";
061:
062:            /**
063:             * Constructor
064:             *
065:             * @param webContainerProperties WebContainer Information as Map
066:             */
067:            protected WebContainerBase(final Map webContainerProperties) {
068:
069:                execUtil = new ExecuteUtil();
070:                wcAttributes = webContainerProperties;
071:
072:                wcType = (String) wcAttributes
073:                        .get(InstanceAttributes.WEB_CONTAINER_TYPE);
074:                domainID = (String) wcAttributes.get(DOMAIN_ID);
075:                portalID = (String) wcAttributes.get(PORTAL_ID);
076:                instanceID = (String) wcAttributes.get(NAME);
077:            }
078:
079:            /**
080:             * Configures the webcontainer with the Identity
081:             * Server and Portal Server classpath and other
082:             * JVM options.
083:             */
084:            public void configure(PSConfigContext configContext)
085:                    throws ConfigurationException {
086:
087:                try {
088:
089:                    doIdentitySDKConfig(configContext);
090:                    if (!isPortalConfigured()) {
091:
092:                        psLibDir = configContext.getPSBaseDir() + fs + "lib";
093:                        String sPortalConfigDataDir = configContext
094:                                .getPSDataDir()
095:                                + fs
096:                                + "portals"
097:                                + fs
098:                                + portalID
099:                                + fs
100:                                + "config";
101:
102:                        try {
103:                            ConfigDataRecorder recorder = new ConfigDataRecorder(
104:                                    psLibDir, sPortalConfigDataDir);
105:                            if (!recorder.isRecordingFound()) {
106:
107:                                // Get classpath string that needs to be configued into the
108:                                // webcontainer instance
109:                                String classpath = ClasspathGenUtil
110:                                        .getClasspath("server.classpath", false);
111:                                logger.log(Level.FINEST, "PSFB_CSPFT0308",
112:                                        classpath);
113:
114:                                // log message - Recording NOT found, hence record
115:                                recorder
116:                                        .doRecordPath(
117:                                                ConfigDataConstants.PASCONFIG_ATTR_CLASSPATH,
118:                                                classpath);
119:                                recorder.doRecordJVMOption(PORTAL_ID, portalID);
120:                                recorder
121:                                        .doRecordJVMOption(
122:                                                INSTANCE_ID,
123:                                                ConfigDataRecorder.PASCONFIG_INSTANCE_ID);
124:                                recorder.doRecordJVMOption(
125:                                        "com.sun.portal.log.config.file",
126:                                        sPortalConfigDataDir + fs
127:                                                + "PSLogConfig.properties");
128:
129:                                recorder.doRecordJVMOption("jdbc.drivers",
130:                                        "org.apache.derby.jdbc.ClientDriver");
131:
132:                                // Set JVM option for UBT
133:                                // Note this is needed only by psconsole webapp although these settings
134:                                // are being made on the instance on with the portal, psconsole webapps are deployed
135:                                recorder.doRecordJVMOption("java.awt.headless",
136:                                        "true");
137:                                recorder
138:                                        .doRecordResources(sPortalConfigDataDir);
139:                                recorder
140:                                        .doRecordPath(
141:                                                ConfigDataConstants.PASCONFIG_ATTR_NATIVE_LIB_PATH,
142:                                                psLibDir);
143:
144:                                recorder.saveRecording();
145:                            }
146:
147:                            // Recording Found..so Play it
148:                            Map valueMap = new HashMap();
149:                            valueMap.put(
150:                                    ConfigDataRecorder.PASCONFIG_INSTANCE_ID,
151:                                    instanceID);
152:                            valueMap.put("ps.config.location", configContext
153:                                    .getPSConfigDir());
154:                            valueMap.put("ps.product.location", configContext
155:                                    .getPSBaseDir());
156:                            valueMap.put("shared.lib.location", configContext
157:                                    .getSharedLibsDir());
158:                            valueMap.put("derby.lib.location", configContext
159:                                    .getDerbyLibDir());
160:                            valueMap.put("jax.lib.location", configContext
161:                                    .getJAXLibDir());
162:                            //  valueMap.put("jesmf.lib.location", configContext.getJESMFLibDir());
163:                            // Note this is needed only by psconsole webapp although
164:                            // this setting is being made on the instance on which
165:                            // both portal and psconsole webapps are deployed.
166:                            String cacaoBaseDir = configContext
167:                                    .getCacaoBaseDir();
168:
169:                            if (System.getProperty("os.name").indexOf("inux") > 0) {
170:
171:                                cacaoBaseDir = cacaoBaseDir + "/share";
172:                            }
173:
174:                            valueMap
175:                                    .put("cacao.product.location", cacaoBaseDir);
176:
177:                            ConfigDataPlayback player = new ConfigDataPlayback(
178:                                    psLibDir, sPortalConfigDataDir, this ,
179:                                    valueMap);
180:                            // NOTE:: The recording must be found here. If NOT, then it is a SEVERE error
181:                            if (!player.isRecordingFound()) {
182:
183:                                // log message
184:                                logger.log(Level.SEVERE, "PSFB_CSPFT0309",
185:                                        portalID);
186:                                String msg = "Recording missing for portal '"
187:                                        + portalID + "'.";
188:                                throw new ConfigurationException(msg);
189:                            }
190:
191:                            player.doPlayback();
192:                        } catch (ConfigDataRecorderPlaybackException e) {
193:                            // log message
194:                            logger.log(Level.SEVERE, "PSFB_CSPFT0310", e);
195:                            throw new ConfigurationException(e);
196:                        }
197:
198:                        createSymbolicLinks(configContext);
199:                        doMiscTasks(configContext);
200:                    } else {
201:                        logger.log(Level.INFO, "PSFB_CSPFT0034", new String[] {
202:                                wcType, wcPrintableInstanceName });
203:                    }
204:                } catch (Exception e) {
205:                    if (logger.isLoggable(Level.SEVERE)) {
206:                        LogRecord record = new LogRecord(Level.SEVERE,
207:                                "PSFB_CSPFT0035");
208:                        record.setParameters(new String[] { wcType,
209:                                wcPrintableInstanceName });
210:                        record.setThrown(e);
211:                        record.setLoggerName(logger.getName());
212:                        logger.log(record);
213:                    }
214:                }
215:            }
216:
217:            /**
218:             * Removes the Identity Server and Portal Server
219:             * related configuration in the WebContainer
220:             * classpath and JVM options
221:             */
222:            public void unconfigure(PSConfigContext configContext)
223:                    throws ConfigurationException {
224:
225:                try {
226:
227:                    if (isPortalConfigured()) {
228:
229:                        psLibDir = configContext.getPSBaseDir() + fs + "lib";
230:                        String sPortalConfigDataDir = configContext
231:                                .getPSDataDir()
232:                                + fs
233:                                + "portals"
234:                                + fs
235:                                + portalID
236:                                + fs
237:                                + "config";
238:
239:                        try {
240:
241:                            // Recording Found..so Play it
242:                            Map valueMap = new HashMap();
243:                            valueMap.put(
244:                                    ConfigDataRecorder.PASCONFIG_INSTANCE_ID,
245:                                    instanceID);
246:                            valueMap.put("ps.config.location", configContext
247:                                    .getPSConfigDir());
248:                            valueMap.put("ps.product.location", configContext
249:                                    .getPSBaseDir());
250:                            valueMap.put("shared.lib.location", configContext
251:                                    .getSharedLibsDir());
252:                            valueMap.put("derby.lib.location", configContext
253:                                    .getDerbyLibDir());
254:                            valueMap.put("jax.lib.location", configContext
255:                                    .getJAXLibDir());
256:                            // valueMap.put("jesmf.lib.location", configContext.getJESMFLibDir());
257:                            // both portal and psconsole webapps are deployed.
258:                            String cacaoBaseDir = configContext
259:                                    .getCacaoBaseDir();
260:
261:                            if (System.getProperty("os.name").indexOf("inux") > 0) {
262:                                cacaoBaseDir = cacaoBaseDir + "/share";
263:                            }
264:
265:                            valueMap
266:                                    .put("cacao.product.location", cacaoBaseDir);
267:
268:                            ConfigDataPlayback player = new ConfigDataPlayback(
269:                                    psLibDir, sPortalConfigDataDir, this ,
270:                                    valueMap);
271:
272:                            // NOTE:: The recording must be found here. If NOT, then it is a SEVERE error
273:                            if (!player.isRecordingFound()) {
274:
275:                                // log message
276:                                logger.log(Level.SEVERE, "PSFB_CSPFT0326",
277:                                        portalID);
278:                                String msg = "Recording missing for portal '"
279:                                        + portalID + "'.";
280:                                throw new ConfigurationException(msg);
281:                            }
282:
283:                            player.doErase();
284:                        } catch (ConfigDataRecorderPlaybackException e) {
285:                            // log message
286:                            logger.log(Level.SEVERE, "PSFB_CSPFT0327", e);
287:                            throw new ConfigurationException(e);
288:                        }
289:
290:                        deleteSymbolicLinks(configContext);
291:                        undoMiscTasks(configContext);
292:                    } else {
293:                        logger.log(Level.INFO, "PSFB_CSPFT0036", new String[] {
294:                                wcType, wcPrintableInstanceName });
295:                    }
296:                } catch (Exception e) {
297:                    if (logger.isLoggable(Level.SEVERE)) {
298:                        LogRecord record = new LogRecord(Level.SEVERE,
299:                                "PSFB_CSPFT0037");
300:                        record.setParameters(new String[] { wcType,
301:                                wcPrintableInstanceName });
302:                        record.setThrown(e);
303:                        record.setLoggerName(logger.getName());
304:                        logger.log(record);
305:                    }
306:                }
307:            }
308:
309:            /**
310:             * Configures the webcontainer for the portletApp
311:             * given the /conf directory with the standard format
312:             */
313:            public boolean configureApp(String configDir,
314:                    PSConfigContext configContext)
315:                    throws ConfigurationException {
316:
317:                boolean ret = true;
318:
319:                try {
320:
321:                    psLibDir = configContext.getPSBaseDir() + fs + "lib";
322:                    String sPortalConfigDataDir = configContext.getPSDataDir()
323:                            + fs + "portals" + fs + portalID + fs + "config";
324:                    ConfigDataRecorder recorder = new ConfigDataRecorder(
325:                            psLibDir, sPortalConfigDataDir);
326:
327:                    //Configure server classpath
328:                    String serverCP = configDir + fs + "server.classpath";
329:                    File scpFile = new File(serverCP);
330:                    if (scpFile.exists()) {
331:                        String classpath = ClasspathGenUtil.getClasspath(
332:                                serverCP, true);
333:                        recorder.doRecordPath(
334:                                ConfigDataConstants.PASCONFIG_ATTR_CLASSPATH,
335:                                classpath);
336:                        ret = appendClasspath(classpath);
337:                        logger.log(Level.INFO, "PSFB_CSPFT0093", new String[] {
338:                                classpath, ":" + ret });
339:                        if (!ret) {
340:                            return ret;
341:                        }
342:                    }
343:
344:                    // Configure jvm options
345:                    String jvm = configDir + fs + "jvmoptions.properties";
346:                    File jvmFile = new File(jvm);
347:                    if (jvmFile.exists()) {
348:                        try {
349:                            // Works if the user has given absolute path
350:                            InputStream in = new FileInputStream(jvmFile);
351:                            if (in != null) {
352:                                Properties props = new Properties();
353:                                props.load(in);
354:
355:                                for (Enumeration en = props.keys(); en
356:                                        .hasMoreElements();) {
357:                                    String option = (String) en.nextElement();
358:                                    String value = props.getProperty(option);
359:                                    recorder.doRecordJVMOption(option, value);
360:                                    ret = addJVMOption(option, value);
361:                                    logger.log(Level.INFO, "PSFB_CSPFT0096",
362:                                            new String[] { option, value,
363:                                                    ":" + ret });
364:                                    if (!ret) {
365:                                        return ret;
366:                                    }
367:                                }
368:                                in.close();
369:                            }
370:                        } catch (IOException e) {
371:                            ret = false;
372:                        }
373:                    }
374:
375:                    recorder.doRecordResources(configDir);
376:                    createResource(configDir);
377:                    recorder.saveRecording();
378:                } catch (ConfigDataRecorderPlaybackException e) {
379:                    // log message
380:                    logger.log(Level.SEVERE, "PSFB_CSPFT0311", e);
381:                    throw new ConfigurationException(e);
382:                }
383:
384:                return ret;
385:            }
386:
387:            /**
388:             * Configures the WebContainer for Search
389:             */
390:            public void configureSearch(String classpath,
391:                    PSConfigContext configContext)
392:                    throws ConfigurationException {
393:                appendClasspath(classpath);
394:                setNativeLibraryPath(configContext.getPSBaseDir() + fs + "lib");
395:            }
396:
397:            /**
398:             * Removes the Search  related configuration in the WebContainer
399:             */
400:            public void unconfigureSearch(String classpath,
401:                    PSConfigContext configContext)
402:                    throws ConfigurationException {
403:                removeClasspath(classpath);
404:            }
405:
406:            /**
407:             * Deploys the WAR file on to the webcontainer instance
408:             *
409:             * @param warFile WAR file including full path
410:             * @param uri Deployment URI
411:             */
412:            public void deploy(final String warFile, final String uri)
413:                    throws ConfigurationException {
414:
415:                RuntimeException e = new RuntimeException(
416:                        "Method 'deploy' NOT implemented.");
417:                throw e;
418:            }
419:
420:            public void justDeploy(final String warFile, final String uri)
421:                    throws ConfigurationException {
422:
423:                deploy(warFile, uri);
424:            }
425:
426:            public void postDeploy() throws ConfigurationException {
427:            };
428:
429:            /**
430:             * Undeploys the WAR file from the webcontainer instance
431:             *
432:             * @param uri Deployment URI
433:             */
434:            public void undeploy(final String uri)
435:                    throws ConfigurationException {
436:
437:                RuntimeException e = new RuntimeException(
438:                        "Method 'undeploy' NOT implemented.");
439:                throw e;
440:            }
441:
442:            /**
443:             * Starts the webcontainer instance
444:             */
445:            public void start() throws ConfigurationException {
446:
447:                RuntimeException e = new RuntimeException(
448:                        "Method 'start' NOT implemented.");
449:                throw e;
450:            }
451:
452:            /**
453:             * Stops the webcontainer instance
454:             */
455:            public void stop() throws ConfigurationException {
456:
457:                RuntimeException e = new RuntimeException(
458:                        "Method 'stop' NOT implemented.");
459:                throw e;
460:            }
461:
462:            /**
463:             * Validate the data (web container attributes)
464:             */
465:            public void validate() throws ValidationException {
466:
467:                RuntimeException e = new RuntimeException(
468:                        "Method 'validate' NOT implemented.");
469:                throw e;
470:            }
471:
472:            /**
473:             * Post Validate the data (web container attributes)
474:             */
475:            public void postValidationInit() throws ConfigurationException {
476:
477:                RuntimeException e = new RuntimeException(
478:                        "Method 'postValidate' NOT implemented.");
479:                throw e;
480:            }
481:
482:            // Protected functions
483:            protected boolean checkDirExists(final String token,
484:                    final String value) {
485:
486:                File dir = null;
487:                try {
488:
489:                    dir = new File(value);
490:                } catch (Exception e) {
491:
492:                    StringWriter sw = new StringWriter();
493:                    PrintWriter pw = new PrintWriter(sw);
494:                    e.printStackTrace(pw);
495:                    logger.log(Level.SEVERE, e.getMessage() + " \n"
496:                            + sw.toString());
497:                    dir = null;
498:                }
499:
500:                boolean bIsDir = (dir != null) ? dir.isDirectory() : false;
501:                String sLogMsgID = bIsDir ? "PSFB_CSPFT0001" : "PSFB_CSPFT0002";
502:                Level logLevel = bIsDir ? Level.INFO : Level.SEVERE;
503:                logger.log(logLevel, sLogMsgID, new String[] { wcType, token,
504:                        value });
505:
506:                return bIsDir;
507:            }
508:
509:            /**
510:             * Filter out the source classpath to remove duplicate entries that already exist in filterList.
511:             * Maintain order of classpath
512:             * @param sourceCP
513:             * @param filterListCP
514:             * @return filtered source classpath
515:             */
516:            protected String getFilteredClassPath(String sourceCP,
517:                    String filterListCP) {
518:                StringBuffer filteredCP = new StringBuffer();
519:                String[] sourceJars = sourceCP.split(cps);
520:                String sFilterListCP = cps + filterListCP.trim() + cps;
521:                boolean bFirst = true;
522:                for (int idx = 0; idx < sourceJars.length; idx++) {
523:                    String sSourceJar = cps + sourceJars[idx].trim() + cps;
524:                    // Make sure entry is not already in filterListCP
525:                    if ((sSourceJar.length() > 2)
526:                            && (sFilterListCP.indexOf(sSourceJar) < 0)) {
527:                        if (bFirst) {
528:                            bFirst = false;
529:                        } else {
530:                            filteredCP.append(cps);
531:                        }
532:                        filteredCP.append(sourceJars[idx]);
533:                    }
534:                }
535:                return filteredCP.toString();
536:            }
537:
538:            /**
539:             * Prefix filtered source classpath into target classpath.
540:             * i.e.Filter source for entries that already exist in target.
541:             * Maintain order of classpath
542:             * @param sourceCP
543:             * @param targetCP
544:             * @return merged target classpath
545:             */
546:            protected String getMergedClassPath(String sourceCP, String targetCP) {
547:                StringBuffer mergedCP = new StringBuffer();
548:                mergedCP.append(targetCP);
549:                String sFilteredClassPath = getFilteredClassPath(sourceCP,
550:                        targetCP);
551:                if ((sFilteredClassPath != null)
552:                        && !sFilteredClassPath.trim().equals("")) {
553:                    mergedCP.append(cps);
554:                    mergedCP.append(sFilteredClassPath);
555:                    mergedCP.append(cps);
556:                }
557:                return mergedCP.toString();
558:            }
559:
560:            protected boolean checkFileExists(final String token,
561:                    final String value) {
562:
563:                File file = null;
564:                try {
565:
566:                    file = new File(value);
567:                } catch (Exception e) {
568:
569:                    StringWriter sw = new StringWriter();
570:                    PrintWriter pw = new PrintWriter(sw);
571:                    e.printStackTrace(pw);
572:                    logger.log(Level.SEVERE, e.getMessage() + " \n"
573:                            + sw.toString());
574:                    file = null;
575:                }
576:
577:                boolean bIsFile = (file != null) ? file.isFile() : false;
578:                String sLogMsgID = bIsFile ? "PSFB_CSPFT0094"
579:                        : "PSFB_CSPFT0095";
580:                Level logLevel = bIsFile ? Level.INFO : Level.SEVERE;
581:                logger.log(logLevel, sLogMsgID, new String[] { wcType, token,
582:                        value });
583:
584:                return bIsFile;
585:            }
586:
587:            private boolean validateHostNamePort(final String host,
588:                    final String portno, final String sHostPassMsgID,
589:                    final String sHostFailMsgID, final String sPortPassMsgID,
590:                    final String sPortFailMsgID) {
591:
592:                boolean bIsValid = NetworkUtil.isHostValid(host);
593:                Level logLevel = bIsValid ? Level.INFO : Level.SEVERE;
594:                String sLogMsgID = bIsValid ? sHostPassMsgID : sHostFailMsgID;
595:                logger.log(logLevel, sLogMsgID, new String[] { wcType, host });
596:
597:                if (bIsValid) {
598:
599:                    bIsValid = NetworkUtil.isPortValid(host, portno);
600:                    logLevel = bIsValid ? Level.INFO : Level.SEVERE;
601:                    sLogMsgID = bIsValid ? sPortPassMsgID : sPortFailMsgID;
602:                    logger.log(logLevel, sLogMsgID, new String[] { wcType,
603:                            host, portno });
604:                }
605:
606:                return bIsValid;
607:            }
608:
609:            protected boolean validateInstanceHostNamePort(final String host,
610:                    final String port) {
611:
612:                return validateHostNamePort(host, port, "PSFB_CSPFT0004",
613:                        "PSFB_CSPFT0005", "PSFB_CSPFT0008", "PSFB_CSPFT0009");
614:            }
615:
616:            protected boolean validateAdminHostNamePort(final String adminHost,
617:                    final String adminPort) {
618:
619:                return validateHostNamePort(adminHost, adminPort,
620:                        "PSFB_CSPFT0006", "PSFB_CSPFT0007", "PSFB_CSPFT0010",
621:                        "PSFB_CSPFT0011");
622:            }
623:
624:            protected boolean checkNotNull(final String token,
625:                    final String value) {
626:                return checkNotNull(token, value, false);
627:            }
628:
629:            protected boolean checkNotNull(final String token,
630:                    final String value, boolean secure) {
631:                boolean bRet = true;
632:                if (value == null) {
633:
634:                    logger.log(Level.SEVERE, "PSFB_CSPFT0003", new String[] {
635:                            wcType, token });
636:                    bRet = false;
637:                } else {
638:
639:                    String printValue = secure ? value.replaceAll(".", "*")
640:                            : value;
641:                    logger.log(Level.INFO, "PSFB_CSPFT0033", new String[] {
642:                            wcType, token, printValue });
643:                }
644:
645:                return bRet;
646:            }
647:
648:            protected boolean checkNotNullOrEmpty(final String token,
649:                    final String value) {
650:
651:                boolean bRet = true;
652:                if ((value == null) || (value.length() <= 0)) {
653:
654:                    logger.log(Level.SEVERE, "PSFB_CSPFT0032", new String[] {
655:                            wcType, token });
656:                    bRet = false;
657:                } else {
658:
659:                    logger.log(Level.INFO, "PSFB_CSPFT0033", new String[] {
660:                            wcType, token, value });
661:                }
662:
663:                return bRet;
664:            }
665:
666:            private void processResourceAndPoolNames(Element resource) {
667:
668:                resourceName = null;
669:                poolName = null;
670:
671:                if (resource != null) {
672:
673:                    resourceName = resource.getAttributeValue("name");
674:                    int startIndex = resourceName.indexOf("/");
675:                    if (startIndex >= 0) {
676:                        poolName = resourceName.substring(startIndex + 1)
677:                                + "Pool";
678:                    } else {
679:                        poolName = resourceName + "Pool";
680:                    }
681:                }
682:            }
683:
684:            public void createResource(Element resource) {
685:
686:                if (resource != null) {
687:
688:                    processURL(resource.getAttributeValue("url"));
689:                    processResourceAndPoolNames(resource);
690:                    if (poolName != null) {
691:
692:                        configResource(resource, derbyHost, derbyPort,
693:                                databaseName, poolName);
694:                    }
695:                }
696:            }
697:
698:            private void createResource(String sConfigDir) {
699:
700:                try {
701:                    File confDir = new File(sConfigDir);
702:                    List datasourceFiles = new ArrayList();
703:                    // Fill the vector with the set of datasource
704:                    FileUtil.getFiles(confDir, datasourceFiles, "datasource");
705:                    int iDataSourceFiles = (datasourceFiles != null) ? datasourceFiles
706:                            .size()
707:                            : 0;
708:                    for (int i = 0; i < iDataSourceFiles; i++) {
709:
710:                        File datasource = (File) datasourceFiles.get(i);
711:                        SAXBuilder builder = new SAXBuilder();
712:                        Document doc = builder.build(datasource
713:                                .getAbsolutePath());
714:                        logger.log(Level.INFO, "PSFB_CSPFT0085", datasource
715:                                .getAbsolutePath());
716:                        createResource(doc.getRootElement());
717:                    }
718:                } catch (JDOMException e) {
719:                    // indicates a well-formedness error
720:                    logger.log(Level.SEVERE, "PSFB_CSPFT0089", new String[] {
721:                            sConfigDir, e.getMessage() });
722:                } catch (IOException e) {
723:                    logger.log(Level.SEVERE, "PSFB_CSPFT0084", new String[] {
724:                            sConfigDir, e.getMessage() });
725:                }
726:            }
727:
728:            public void deleteResource(Element resource) {
729:
730:                if (resource != null) {
731:
732:                    processResourceAndPoolNames(resource);
733:                    logger.log(Level.FINEST, "Resource Name = " + resourceName
734:                            + ", Pool Name = " + poolName);
735:                    if ((resourceName != null) && (poolName != null)) {
736:
737:                        unConfigResource(resourceName, poolName);
738:                    }
739:                }
740:            }
741:
742:            private void processURL(final String url) {
743:
744:                derbyHost = null;
745:                derbyPort = null;
746:                databaseName = null;
747:
748:                int beginIndx = url.indexOf("//");
749:                String subStr = url.substring(beginIndx + 2);
750:                int endIndx = subStr.indexOf(":");
751:                int indx1 = subStr.indexOf(";");
752:                int indx = subStr.indexOf("/");
753:
754:                if (endIndx == -1) {
755:                    endIndx = subStr.indexOf("/");
756:                    derbyPort = "1527";
757:                } else {
758:                    derbyPort = subStr.substring(endIndx + 1, indx);
759:                }
760:
761:                derbyHost = subStr.substring(0, endIndx);
762:
763:                if (indx1 == -1) {
764:                    databaseName = subStr.substring(indx + 1);
765:                } else {
766:                    databaseName = subStr.substring(indx + 1, indx1);
767:                }
768:                logger.log(Level.INFO, "PSFB_CSPFT0086", new String[] {
769:                        derbyHost, derbyPort, databaseName });
770:            }
771:
772:            public Logger getLogger() {
773:
774:                return logger;
775:            }
776:
777:            public final String getPrintableWebContainerInstanceName() {
778:
779:                return wcPrintableInstanceName;
780:            }
781:
782:            public final String getWebContainerType() {
783:
784:                return wcType;
785:            }
786:
787:            final String getCommand(final String sMainCommand,
788:                    final String[] args) {
789:
790:                String sCommand = sMainCommand;
791:
792:                for (int i = 0; i < args.length; i++) {
793:
794:                    sCommand = sCommand + " " + args[i];
795:                }
796:
797:                return sCommand;
798:            }
799:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.