Source Code Cross Referenced for TemplateGenerator.java in  » ESB » open-esb » com » sun » jbi » ui » runtime » verifier » 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.ui.runtime.verifier.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:         * @(#)TemplateGenerator.java
025:         * Copyright 2004-2007 Sun Microsystems, Inc. All Rights Reserved.
026:         *
027:         * END_HEADER - DO NOT EDIT
028:         */
029:        package com.sun.jbi.ui.runtime.verifier.util;
030:
031:        import com.sun.jbi.EnvironmentContext;
032:        import com.sun.jbi.ui.runtime.verifier.LocalStringKeys;
033:        import com.sun.jbi.ui.common.I18NBundle;
034:        import com.sun.jbi.ui.runtime.verifier.VerifierException;
035:        import com.sun.jbi.ui.common.JarFactory;
036:        import com.sun.jbi.ui.common.ToolsLogManager;
037:        import java.io.File;
038:        import java.io.FileOutputStream;
039:        import java.io.FileWriter;
040:        import java.io.IOException;
041:        import java.util.ArrayList;
042:        import java.util.HashMap;
043:        import java.util.HashSet;
044:        import java.util.List;
045:        import java.util.logging.Level;
046:        import java.util.Map;
047:        import java.util.Properties;
048:        import java.util.Set;
049:        import javax.management.openmbean.CompositeType;
050:
051:        /**
052:         * This class has utility methods for template generation
053:         */
054:        public class TemplateGenerator {
055:
056:            /**
057:             * Environment Context
058:             */
059:            private EnvironmentContext mEnvCtx;
060:
061:            /**
062:             * verifier utils
063:             */
064:            private VerifierUtils mVerifierUtil;
065:
066:            /**
067:             * tmp dir
068:             */
069:            private static String TMP = "tmp";
070:
071:            /**
072:             * verifier
073:             */
074:            private static String VERIFIER = "verifier";
075:
076:            /**
077:             * file suffix for app var template
078:             */
079:            private static String APPVAR_TEMPLATE_SUFFIX = "-app-var.properties";
080:
081:            /**
082:             * file suffix for app var template
083:             */
084:            private static String APPCONFIG_TEMPLATE_SUFFIX = ".properties";
085:
086:            /** hyphen*/
087:            private static String HYPHEN = "-";
088:
089:            /**
090:             * map to store property file names for app vars
091:             */
092:            private Map<String, File> mAppVarFile = new HashMap<String, File>();
093:
094:            /**
095:             * list to store property file names for app configs
096:             */
097:            private Map<String, File[]> mAppConfigFile = new HashMap<String, File[]>();
098:
099:            /**
100:             * ant script file name
101:             */
102:            private static String ANT_FILE_NAME = "configure.xml";
103:
104:            /**
105:             * task defs file name
106:             */
107:            private static String TASK_DEFS_FILE_NAME = "jbi-taskdefs.xml";
108:
109:            /**
110:             * properties file name
111:             */
112:            private static String PROPERTIES_FILE_NAME = "connection.properties";
113:
114:            /**
115:             * template zip suffix
116:             */
117:            private static String TEMPLATE_ZIP_SUFFIX = "-templates.zip";
118:
119:            /**
120:             * template dir suffix
121:             */
122:            private static String TEMPLATE_DIR_SUFFIX = "-templates";
123:
124:            /**
125:             * property name for the configuration name in the configuration file
126:             */
127:            private static final String CONFIGURATION_NAME = "configurationName";
128:
129:            /**
130:             * resource bundle
131:             */
132:            private I18NBundle mResourceBundle;
133:
134:            /** Constructor */
135:            public TemplateGenerator(EnvironmentContext envCtx,
136:                    I18NBundle resourceBundle) {
137:                this .mEnvCtx = envCtx;
138:                this .mResourceBundle = resourceBundle;
139:                this .mVerifierUtil = new VerifierUtils(resourceBundle);
140:            }
141:
142:            /**
143:             * This method is used to generate template files for 
144:             * setting missing application varibles and application configs
145:             * @param mapAppVars map of component name and missing application variables
146:             * @param mapAppConfigs map of component name and missing application config composite type
147:             * @param includeDeployCommand if deploy command has to be included
148:             * @param target the target for which commands have to be generated
149:             * @param isAnt true if the clinet is ant
150:             * @param saName the saName
151:             * @returns String the name of the zip file that has the templates and the script to run them
152:             * 
153:             */
154:            public String generateTemplates(
155:                    Map<String, List<String>> mapAppVars,
156:                    Map<String, List<String>> mapAppConfigs,
157:                    Map<String, CompositeType> mapAppConfigTypes,
158:                    boolean includeDeployCommand, String target, boolean isAnt,
159:                    String saName, String saPath) {
160:                return generateTemplates(mapAppVars, mapAppConfigs,
161:                        mapAppConfigTypes, includeDeployCommand, target, isAnt,
162:                        saName, saPath, false, null, null);
163:            }
164:
165:            /**
166:             * This method is used to generate template files for 
167:             * setting missing application varibles and application configs
168:             * @param mapAppVars map of component name and missing application variables
169:             * @param mapAppConfigs map of component name and missing application config composite type
170:             * @param includeDeployCommand if deploy command has to be included
171:             * @param target the target for which commands have to be generated
172:             * @param isAnt true if the clinet is ant
173:             * @param saName the saName
174:             * @param fillInValues true if the generated files should include values for app. vars and app. configs
175:             * @param mapAppVarValues map of application vars
176:             * @param mapAppConfigValues of application configs
177:             * @returns String the name of the zip file that has the templates and the script to run them
178:             * 
179:             */
180:            public String generateTemplates(
181:                    Map<String, List<String>> mapAppVars,
182:                    Map<String, List<String>> mapAppConfigs,
183:                    Map<String, CompositeType> mapAppConfigTypes,
184:                    boolean includeDeployCommand, String target, boolean isAnt,
185:                    String saName, String saPath, boolean fillInValues,
186:                    Map<String, Map<String, Object>> mapAppVarValues,
187:                    Map<String, Map<String, Properties>> mapAppConfigValues) {
188:                try {
189:                    File templatesDir = createTemplatesDir(saName);
190:                    Set<String> components = mapAppVars.keySet();
191:                    for (String component : components) {
192:                        Map<String, Object> appVarValues = new HashMap<String, Object>();
193:                        if (fillInValues && mapAppVarValues != null) {
194:                            if (mapAppVarValues.containsKey(component)) {
195:                                appVarValues = mapAppVarValues.get(component);
196:                            }
197:                        }
198:
199:                        File propFile = createPropertiesFile(templatesDir,
200:                                component, mapAppVars.get(component),
201:                                fillInValues, appVarValues);
202:                        if (propFile != null) {
203:                            mAppVarFile.put(component, propFile);
204:                        }
205:
206:                        ToolsLogManager.getRuntimeLogger().finer(
207:                                "Generated app. var. file " + propFile
208:                                        + " for component " + component);
209:
210:                    }
211:
212:                    components = mapAppConfigs.keySet();
213:                    for (String component : components) {
214:                        List<String> appConfigs = mapAppConfigs.get(component);
215:                        List propFileList = new ArrayList();
216:                        for (String config : appConfigs) {
217:                            Map<String, Properties> appConfigValues = new HashMap<String, Properties>();
218:                            if (fillInValues && mapAppConfigValues != null) {
219:                                if (mapAppConfigValues.containsKey(component)) {
220:                                    appConfigValues = mapAppConfigValues
221:                                            .get(component);
222:                                }
223:                            }
224:                            File propFile = createPropertiesFile(templatesDir,
225:                                    component,
226:                                    mapAppConfigTypes.get(component), config,
227:                                    fillInValues, appConfigValues);
228:                            propFileList.add(propFile);
229:                        }
230:                        File[] propFileArray = new File[propFileList.size()];
231:                        mAppConfigFile.put(component, (File[]) propFileList
232:                                .toArray(propFileArray));
233:                    }
234:
235:                    if (isAnt) {
236:                        generateAntScript(templatesDir, includeDeployCommand,
237:                                target, mAppVarFile, mAppConfigFile, saPath);
238:                        ToolsLogManager.getRuntimeLogger().finer(
239:                                "Generated ant script for app. vars");
240:
241:                    }
242:
243:                    try {
244:                        JarFactory jarFactory = new JarFactory(templatesDir
245:                                .getPath());
246:                        File zipFile = new File(templatesDir, saName
247:                                + TEMPLATE_ZIP_SUFFIX);
248:                        if (zipFile.exists()) {
249:                            if (!zipFile.delete()) {
250:                                throw new VerifierException(
251:                                        mResourceBundle
252:                                                .getMessage(LocalStringKeys.VERIFIER_TEMPLATE_ZIP_EXISTS));
253:                            }
254:                        }
255:                        ToolsLogManager.getRuntimeLogger().finer(
256:                                "Creating zip file with templates in "
257:                                        + templatesDir);
258:                        return jarFactory.zip(zipFile.getName());
259:                    } catch (IOException ex) {
260:                        String message = mResourceBundle
261:                                .getMessage(LocalStringKeys.VERIFIER_TEMPLATE_ZIP_NOT_CREATED)
262:                                + ex.getMessage();
263:                        ToolsLogManager.getRuntimeLogger().warning(message);
264:                    }
265:                    return null;
266:                } catch (VerifierException ex) {
267:                    ToolsLogManager.getRuntimeLogger().log(Level.WARNING,
268:                            ex.getMessage(), ex);
269:                    return null;
270:                }
271:
272:            }
273:
274:            /**
275:             * This method is used to create a property file for a given component
276:             * with the given list of app vars/app config fields
277:             * @param templatesDir the templatesDir
278:             * @param componentName component name
279:             * @param varList list of app var / app config fields
280:             * @param fillInValues true if the values of app. vars have to be exported
281:             * @param mapVarValues map of app. var names and values.
282:             * @return file the file handle to the properties file, null if varList is empty
283:             */
284:            private File createPropertiesFile(File templatesDir,
285:                    String componentName, List<String> varList,
286:                    boolean fillInValues, Map<String, Object> mapVarValues)
287:                    throws VerifierException {
288:                try {
289:                    //if the list of missing app. vars is empty return null
290:                    if (varList != null && varList.size() == 0) {
291:                        return null;
292:                    }
293:                    Properties properties = new Properties();
294:                    for (String property : varList) {
295:                        //set the key first. (best effort for export)
296:                        properties.setProperty(property, "");
297:                        if (fillInValues && mapVarValues != null) {
298:                            //try to overwrite the property
299:                            try {
300:                                properties.put(property, mapVarValues
301:                                        .get(property));
302:                            } catch (Throwable th) {
303:                                String message = mResourceBundle
304:                                        .getMessage(
305:                                                LocalStringKeys.VERIFIER_ISSUE_EXPORTING_APP_VAR_VALUE,
306:                                                new Object[] { property });
307:                                ToolsLogManager.getRuntimeLogger().warning(
308:                                        message);
309:                                if (th.getMessage() != null) {
310:                                    ToolsLogManager.getRuntimeLogger().warning(
311:                                            th.getMessage());
312:                                }
313:                            }
314:
315:                        }
316:
317:                    }
318:                    File propertyFile = new File(templatesDir, componentName
319:                            + APPVAR_TEMPLATE_SUFFIX);
320:                    ToolsLogManager.getRuntimeLogger().finer(
321:                            "Creating " + propertyFile + " with properties: "
322:                                    + properties);
323:                    FileOutputStream fileoutputstream = new FileOutputStream(
324:                            propertyFile);
325:
326:                    properties.store(fileoutputstream, PROP_FILE_HEADER);
327:                    return propertyFile;
328:                } catch (IOException ex) {
329:                    throw new VerifierException(ex);
330:                }
331:
332:            }
333:
334:            /**
335:             * This method is used to create a property file for a given component
336:             * with the composite type for the component application configuration type
337:             * @param templatesDir the templatesDir
338:             * @param componentName component name
339:             * @param appConfigType the composite type
340:             * @param configName the name of the missing app config
341:             * @param fillInValues true if the values have to be exported
342:             * @param mapAppConfigValues map of config names and values
343:             * @return file the file handle to the properties file
344:             */
345:            private File createPropertiesFile(File templatesDir,
346:                    String componentName, CompositeType appConfigType,
347:                    String configName, boolean fillInValues,
348:                    Map<String, Properties> mapAppConfigValues)
349:                    throws VerifierException {
350:                try {
351:                    Set<String> appConfigItemNames = new HashSet();
352:                    if (appConfigType != null) {
353:                        appConfigItemNames = appConfigType.keySet();
354:                    }
355:
356:                    Properties properties = new Properties();
357:                    for (String configItem : appConfigItemNames) {
358:                        properties.setProperty(configItem, "");
359:                        if (configItem.equals(CONFIGURATION_NAME)) {
360:                            properties.setProperty(CONFIGURATION_NAME,
361:                                    configName);
362:                        }
363:                    }
364:
365:                    //if export try to overwrite the properties object
366:                    if (fillInValues && mapAppConfigValues != null) {
367:                        try {
368:                            if (mapAppConfigValues.get(configName) != null) {
369:                                properties = mapAppConfigValues.get(configName);
370:                            }
371:                        } catch (Throwable th) {
372:                            //only best case effort to overwrite. otherwise the
373:                            //values will be empty
374:                            String message = mResourceBundle
375:                                    .getMessage(
376:                                            LocalStringKeys.VERIFIER_ISSUE_EXPORTING_APP_CONFIG_VALUE,
377:                                            new Object[] { configName });
378:                            ToolsLogManager.getRuntimeLogger().warning(message);
379:                            if (th.getMessage() != null) {
380:                                ToolsLogManager.getRuntimeLogger().warning(
381:                                        th.getMessage());
382:                            }
383:                        }
384:                    }
385:
386:                    File propertyFile = new File(templatesDir, componentName
387:                            + HYPHEN + configName + APPCONFIG_TEMPLATE_SUFFIX);
388:                    ToolsLogManager.getRuntimeLogger().finer(
389:                            "Creating " + propertyFile + " with properties: "
390:                                    + properties);
391:                    FileOutputStream fileoutputstream = new FileOutputStream(
392:                            propertyFile);
393:
394:                    properties.store(fileoutputstream, PROP_FILE_HEADER);
395:                    return propertyFile;
396:                } catch (IOException ex) {
397:                    throw new VerifierException(ex);
398:                }
399:
400:            }
401:
402:            /**
403:             * This method is used to create a templates dir for the given SA
404:             * @param saName sa name
405:             * @return File the dir created
406:             */
407:            private File createTemplatesDir(String saName) {
408:                File tmpDir = new File(mEnvCtx.getJbiInstanceRoot(), TMP);
409:                File verifierDir = new File(tmpDir, VERIFIER + File.separator
410:                        + saName + TEMPLATE_DIR_SUFFIX);
411:                if (verifierDir.exists()) {
412:                    mVerifierUtil.cleanup(verifierDir.getPath());
413:                }
414:                verifierDir.mkdirs();
415:                ToolsLogManager.getRuntimeLogger().finer(
416:                        "Created templates dir in server " + verifierDir);
417:                return verifierDir;
418:
419:            }
420:
421:            /**
422:             * This method is used to generate an ant script to set
423:             * the application vars and application configs provided
424:             * in the given list of files
425:             * @param templateDir the template dir
426:             * @param includeDeployCommand include deploy command
427:             * @param target target
428:             * @param mapAppVarFile app vars properties file
429:             * @param mapAppConfigFile app config properties file
430:             */
431:            private void generateAntScript(File templateDir,
432:                    boolean includeDeployCommand, String target,
433:                    Map<String, File> mapAppVarFile,
434:                    Map<String, File[]> mapAppConfigFile, String saPath)
435:                    throws VerifierException {
436:                try {
437:                    File taskDefsFile = new File(templateDir,
438:                            TASK_DEFS_FILE_NAME);
439:                    File connPropertiesFile = new File(templateDir,
440:                            PROPERTIES_FILE_NAME);
441:                    File antScriptFile = new File(templateDir, ANT_FILE_NAME);
442:
443:                    createTaskDefsFile(taskDefsFile, includeDeployCommand);
444:                    createConnectionPropertiesFile(connPropertiesFile, target);
445:
446:                    FileWriter fileWriter = new FileWriter(antScriptFile);
447:                    fileWriter.write(ANT_SCRIPT_BEGIN);
448:
449:                    Set<String> components = mapAppVarFile.keySet();
450:                    for (String component : components) {
451:                        fileWriter.write(constructAddAppVariableTask(component,
452:                                mapAppVarFile.get(component)));
453:                        ToolsLogManager.getRuntimeLogger().finer(
454:                                "Added set task for " + component);
455:                    }
456:
457:                    components = mapAppConfigFile.keySet();
458:                    for (String component : components) {
459:                        File[] configFiles = mapAppConfigFile.get(component);
460:                        for (int i = 0; i < configFiles.length; i++) {
461:                            fileWriter.write(constructAddAppConfigurationTask(
462:                                    component, configFiles[i]));
463:                            ToolsLogManager.getRuntimeLogger().finer(
464:                                    "Added set task for " + component);
465:                        }
466:                    }
467:
468:                    if (includeDeployCommand) {
469:                        fileWriter.write(constructDeployTask(target, saPath));
470:                        ToolsLogManager.getRuntimeLogger().finer(
471:                                "Added deploy task for " + saPath);
472:                    }
473:
474:                    fileWriter.write(ANT_SCRIPT_END);
475:                    fileWriter.flush();
476:                    fileWriter.close();
477:                } catch (IOException ex) {
478:                    throw new VerifierException(ex);
479:                }
480:            }
481:
482:            /**
483:             * This method is used to create an ant task to write the
484:             * ant script file
485:             * @param component Name
486:             * @param file name
487:             * @returns String the ant task
488:             */
489:            private String constructAddAppVariableTask(String componentName,
490:                    File propertyFile) {
491:                String fileName = null;
492:                try {
493:
494:                    fileName = propertyFile.getName();
495:                } catch (Exception ex) {
496:                    ToolsLogManager.getRuntimeLogger().warning(ex.getMessage());
497:                    //filename will be null
498:                }
499:                return "\t\t<antcall target=\"create-app-variable\">\n"
500:                        + "\t\t\t<param name=\"component.name\" value=\""
501:                        + componentName + "\"/>\n"
502:                        + "\t\t\t<param name=\"properties.file.name\" value=\""
503:                        + fileName + "\"/>\n" + "\t\t</antcall>\n";
504:
505:            }
506:
507:            /**
508:             * This method is used to create an ant task to deploy the SA
509:             * @param target Name
510:             * @param file name
511:             * @returns String the ant task
512:             */
513:            private String constructDeployTask(String targetName, String saPath) {
514:
515:                return "\t\t<antcall target=\"deploy-application\">\n"
516:                        + "\t\t\t<param name=\"deploy.file\" value=\"" + saPath
517:                        + "\"/>\n " + "\t\t</antcall>\n";
518:            }
519:
520:            /**
521:             * This method is used to create an ant task to write the
522:             * ant script file
523:             * @param component Name
524:             * @param file name
525:             * @returns String the ant task
526:             */
527:            private String constructAddAppConfigurationTask(
528:                    String componentName, File propertyFile) {
529:                String fileName = null;
530:                String configName = "CONFIG";
531:                try {
532:
533:                    fileName = propertyFile.getName();
534:                    //filename is constructed as
535:                    //c:/tmp/component1-config1.properties
536:                    configName = fileName.substring(fileName
537:                            .indexOf(componentName)
538:                            + componentName.length() + 1, fileName
539:                            .lastIndexOf(".properties"));
540:                } catch (Exception ex) {
541:                    ToolsLogManager.getRuntimeLogger().warning(ex.getMessage());
542:                    //filename will be null
543:                }
544:                return "\t\t<antcall target=\"create-app-configuration\">\n"
545:                        + "\t\t\t<param name=\"component.name\" value=\""
546:                        + componentName + "\"/>\n"
547:                        + "\t\t\t<param name=\"config.name\" value=\""
548:                        + configName + "\"/>\n"
549:                        + "\t\t\t<param name=\"properties.file.name\" value=\""
550:                        + fileName + "\"/>\n " + "\t\t</antcall>\n";
551:
552:            }
553:
554:            /**
555:             * This method is used to create the task defs file that includes
556:             * task defs for create-app-variable create-app-configuration
557:             * and deploy-application
558:             * @param taskDefsFile file 
559:             * @param includeDeploy true if task def for include has to be included
560:             *
561:             */
562:            private void createTaskDefsFile(File taskDefsFile,
563:                    boolean includeDeploy) {
564:                try {
565:                    FileWriter fileWriter = new FileWriter(taskDefsFile);
566:                    fileWriter.write(TASKDEFS_HEADER);
567:                    fileWriter.write(TASKDEF_CREATE_APP_VARIABLE);
568:                    fileWriter.write(TASKDEF_CREATE_APP_CONFIG);
569:                    if (includeDeploy) {
570:                        fileWriter.write(TASKDEF_DEPLOY_APP);
571:                    }
572:                    fileWriter.write(TASKDEFS_TAIL);
573:                    fileWriter.flush();
574:                    fileWriter.close();
575:                } catch (Throwable ex) {
576:                    ToolsLogManager.getRuntimeLogger().log(Level.WARNING,
577:                            ex.getMessage(), ex);
578:                }
579:            }
580:
581:            /**
582:             * This method is used to create the properties file that contains
583:             * properties for the connection settings
584:             * @param propertiesFileName file name
585:             * @param targetName target name
586:             *
587:             */
588:            private void createConnectionPropertiesFile(File propertiesFile,
589:                    String targetName) {
590:                try {
591:                    String newLine = "\n";
592:                    StringBuffer connectionProperties = new StringBuffer();
593:                    connectionProperties
594:                            .append("#This file is generated by verifier.");
595:                    connectionProperties.append(newLine);
596:                    connectionProperties.append("jbi.username=admin");
597:                    connectionProperties.append(newLine);
598:                    connectionProperties.append("jbi.password=adminadmin");
599:                    connectionProperties.append(newLine);
600:                    connectionProperties.append("jbi.host=localhost");
601:                    connectionProperties.append(newLine);
602:                    connectionProperties.append("jbi.port=4848");
603:                    connectionProperties.append(newLine);
604:                    connectionProperties.append("jbi.secure=false");
605:                    connectionProperties.append(newLine);
606:                    connectionProperties.append("jbi.target=" + targetName);
607:
608:                    FileWriter fileWriter = new FileWriter(propertiesFile);
609:                    fileWriter.write(connectionProperties.toString());
610:                    fileWriter.flush();
611:                    fileWriter.close();
612:                } catch (Throwable ex) {
613:                    ToolsLogManager.getRuntimeLogger().log(Level.WARNING,
614:                            ex.getMessage(), ex);
615:                }
616:            }
617:
618:            /**
619:             * contents at the beginning of the ant script file
620:             */
621:            private String ANT_SCRIPT_BEGIN = "<!--\n"
622:                    + "# configure.xml\n"
623:                    + "# Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved.\n"
624:                    + "#\n"
625:                    + "# END_HEADER - DO NOT EDIT\n"
626:                    + "-->\n"
627:                    + "<!--\n"
628:                    + "#\n"
629:                    + "# This file is generated by verifier.\n"
630:                    + "#\n"
631:                    + "# Usage:\n"
632:                    + "# 1. Provide/Change values in the properties files for application variables and configurations.\n"
633:                    + "# 2. If needed, modify connection settings connection.properties.\n"
634:                    + "# 3. asant -f configure.xml\n"
635:                    + "-->\n\n"
636:                    + "<project name=\"configure\" default=\"configure\" basedir=\".\">\n"
637:                    + "\t<property file=\"connection.properties\"/>\n"
638:                    + "\t<import file=\"jbi-taskdefs.xml\"/>\n\n\n"
639:                    + "\t<target name=\"configure\">\n";
640:
641:            /**
642:             * contents at the end of the ant file
643:             */
644:            private String ANT_SCRIPT_END = "\t</target>\n</project>";
645:
646:            /**
647:             * prop file header
648:             */
649:            private String PROP_FILE_HEADER = " This file is generated by verifier. Please provide configuration values below";
650:
651:            /** header for the task defs file */
652:            private String TASKDEFS_HEADER = "<!--\n"
653:                    + "# This file is generated by verifier.\n"
654:                    + "-->\n\n"
655:                    + "<!--\n"
656:                    + "# jbi-tasksdefs.xml\n"
657:                    + "# Copyright 2004-2008 Sun Microsystems, Inc. All Rights Reserved.\n"
658:                    + "#\n"
659:                    + "# END_HEADER - DO NOT EDIT\n"
660:                    + "-->\n"
661:                    + "<project name=\"taskdefs\" basedir=\".\">\n"
662:                    + "<taskdef resource=\"com/sun/jbi/ui/ant/antlib.xml\" />\n";
663:
664:            /** end for the taskdefs file */
665:            private String TASKDEFS_TAIL = "\n</project>";
666:
667:            /** task def for create app variable */
668:            private String TASKDEF_CREATE_APP_VARIABLE = "\t<target name=\"create-app-variable\">\n"
669:                    + "\t\t<jbi-create-application-variables\n"
670:                    + "\t\t\tusername=\"${jbi.username}\"\n"
671:                    + "\t\t\tpassword=\"${jbi.password}\"\n"
672:                    + "\t\t\thost=\"${jbi.host}\"\n"
673:                    + "\t\t\tport=\"${jbi.port}\"\n"
674:                    + "\t\t\ttarget=\"${jbi.target}\"\n"
675:                    + "\t\t\tsecure=\"${jbi.secure}\"\n"
676:                    + "\t\t\tfailOnError=\"false\"\n"
677:                    + "\t\t\tcomponentName=\"${component.name}\"\n"
678:                    + "\t\t\tappvariables=\"${properties.file.name}\"/>\n"
679:                    + "\t</target>\n";
680:
681:            /** task def for create app config */
682:            private String TASKDEF_CREATE_APP_CONFIG = "\t<target name=\"create-app-configuration\">\n"
683:                    + "\t\t<jbi-create-application-configuration\n"
684:                    + "\t\t\tusername=\"${jbi.username}\"\n"
685:                    + "\t\t\tpassword=\"${jbi.password}\"\n"
686:                    + "\t\t\thost=\"${jbi.host}\"\n"
687:                    + "\t\t\tport=\"${jbi.port}\"\n"
688:                    + "\t\t\ttarget=\"${jbi.target}\"\n"
689:                    + "\t\t\tsecure=\"${jbi.secure}\"\n"
690:                    + "\t\t\tfailOnError=\"false\"\n"
691:                    + "\t\t\tcomponentName=\"${component.name}\"\n"
692:                    + "\t\t\tname=\"${config.name}\"\n"
693:                    + "\t\t\tparams=\"${properties.file.name}\"/>\n"
694:                    + "\t</target>\n";
695:
696:            /** task def for deploy application */
697:            private String TASKDEF_DEPLOY_APP = "\t<target name=\"deploy-application\">\n"
698:                    + "\t\t<jbi-deploy-service-assembly \n"
699:                    + "\t\t\tusername=\"${jbi.username}\"\n"
700:                    + "\t\t\tpassword=\"${jbi.password}\"\n"
701:                    + "\t\t\thost=\"${jbi.host}\"\n"
702:                    + "\t\t\tport=\"${jbi.port}\"\n"
703:                    + "\t\t\ttarget=\"${jbi.target}\"\n"
704:                    + "\t\t\tsecure=\"${jbi.secure}\"\n"
705:                    + "\t\t\tfailOnError=\"true\"\n"
706:                    + "\t\t\tfile=\"${deploy.file}\">\n"
707:                    + "\t\t</jbi-deploy-service-assembly>\n" + "\t</target>\n";
708:
709:        }
w__w__w_.j_a___v__a___2__s___._c___o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.