Source Code Cross Referenced for JTask.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » ant » jonasbase » 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 » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.ant.jonasbase 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 2004 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * Initial developer: Florent BENOIT
022:         * --------------------------------------------------------------------------
023:         * $Id: JTask.java 6618 2005-04-22 11:15:08Z benoitf $
024:         * --------------------------------------------------------------------------
025:         */package org.objectweb.jonas.ant.jonasbase;
026:
027:        import java.io.File;
028:        import java.io.FileInputStream;
029:        import java.io.FileNotFoundException;
030:        import java.io.FileOutputStream;
031:        import java.io.IOException;
032:        import java.io.OutputStream;
033:        import java.util.Properties;
034:
035:        import org.apache.tools.ant.BuildException;
036:        import org.objectweb.jonas.ant.BootstrapTask;
037:
038:        /**
039:         * Defines a common task
040:         * @author Florent Benoit
041:         */
042:        public class JTask extends BootstrapTask implements  BaseTaskItf {
043:
044:            /**
045:             * Property separators (4 spaces)
046:             */
047:            public static final String SEPARATORS = "    ";
048:
049:            /**
050:             * configuration file used
051:             */
052:            private String configurationFile = null;
053:
054:            /**
055:             * Information for the logger
056:             */
057:            private String logInfo = null;
058:
059:            /**
060:             * Destination directory (JONAS_BASE)
061:             */
062:            private File destDir = null;
063:
064:            /**
065:             * Sets the configuration file
066:             * @param configurationFile The configurationFile to set.
067:             */
068:            public void setConfigurationFile(String configurationFile) {
069:                this .configurationFile = configurationFile;
070:            }
071:
072:            /**
073:             * @param destDir The destDir to set.
074:             */
075:            public void setDestDir(File destDir) {
076:                this .destDir = destDir;
077:            }
078:
079:            /**
080:             * Gets logger info (to be displayed)
081:             * @return logger info
082:             * @see org.objectweb.jonas.ant.jonasbase.BaseTaskItf#getLogInfo()
083:             */
084:            public String getLogInfo() {
085:                return logInfo;
086:            }
087:
088:            /**
089:             * Set the info to be displayed by the logger
090:             * @param logInfo information to be displayed
091:             * @see org.objectweb.jonas.ant.jonasbase.BaseTaskItf#setLogInfo(java.lang.String)
092:             */
093:            public void setLogInfo(String logInfo) {
094:                this .logInfo = logInfo;
095:            }
096:
097:            /**
098:             * Gets the destination directory
099:             * @return the destination directory
100:             */
101:            public File getDestDir() {
102:                return destDir;
103:            }
104:
105:            /**
106:             * Write properties object to a file with some logging info
107:             * @param info header for logging
108:             * @param props Properties to write
109:             * @param f file for writing
110:             */
111:            protected void writePropsToFile(String info, Properties props,
112:                    File f) {
113:                OutputStream fOut = null;
114:                try {
115:                    fOut = new FileOutputStream(f);
116:                } catch (FileNotFoundException e) {
117:                    throw new BuildException(info + "File is invalid", e);
118:                }
119:
120:                // Write properties to file
121:                try {
122:                    props.store(fOut, "");
123:                    fOut.close();
124:                } catch (IOException ioe) {
125:                    throw new BuildException(info
126:                            + "Error while writing properties", ioe);
127:                }
128:
129:            }
130:
131:            /**
132:             * Add a value for a specific property in a configuration file.
133:             * The separator uses between the property name and the property value is the default separator value.
134:             * @param info text to be displayed for header
135:             * @param confDir configuration directory (can be JONAS_BASE/conf)
136:             * @param confFile configuration file (can be jonas.properties)
137:             * @param property which must be found in confFile
138:             * @param name value for the property to add
139:             * @param add if true, add it, else replace
140:             */
141:            protected void changeValueForKey(String info, String confDir,
142:                    String confFile, String property, String name, boolean add) {
143:                changeValueForKey(info, confDir, confFile, property, name,
144:                        SEPARATORS, add);
145:            }
146:
147:            /**
148:             * Add a value for a specific property in a configuration file
149:             * @param info text to be displayed for header
150:             * @param confDir configuration directory (can be JONAS_BASE/conf)
151:             * @param confFile configuration file (can be jonas.properties)
152:             * @param property which must be found in confFile
153:             * @param name value for the property to add
154:             * @param separators separator using between the property name and the property value
155:             * @param add if true, add it, else replace
156:             */
157:            protected void changeValueForKey(String info, String confDir,
158:                    String confFile, String property, String name,
159:                    String separators, boolean add) {
160:
161:                // Read current value
162:                Properties currentProps = new Properties();
163:                File f = null;
164:                try {
165:                    f = new File(confDir + File.separator + confFile);
166:                    currentProps.load(new FileInputStream(f));
167:                } catch (Exception e) {
168:                    throw new BuildException(
169:                            "Cannot load current properties for file '" + f
170:                                    + "'.", e);
171:                }
172:
173:                String valueOfProperty = currentProps.getProperty(property);
174:
175:                // Now, add/replace mail value
176:                JReplace propertyReplace = new JReplace();
177:                propertyReplace.setProject(getProject());
178:                propertyReplace.setConfigurationFile(confFile);
179:                propertyReplace.setDestDir(new java.io.File(getDestDir()
180:                        .getPath()));
181:                if (valueOfProperty == null || valueOfProperty.length() == 0) {
182:                    propertyReplace.setToken(property);
183:                    propertyReplace.setValue(property + separators + name);
184:                } else if (!add) {
185:                    propertyReplace.setToken(property + separators
186:                            + valueOfProperty);
187:                    propertyReplace.setValue(property + separators + name);
188:                } else {
189:                    valueOfProperty = valueOfProperty.trim();
190:                    propertyReplace.setToken(property + separators
191:                            + valueOfProperty);
192:                    valueOfProperty += ", " + name;
193:                    String replaceVal = property + separators + valueOfProperty;
194:                    replaceVal = replaceVal.trim();
195:                    propertyReplace.setValue(replaceVal);
196:                }
197:                if (add) {
198:                    log(info + "Adding '" + name + "' in " + confFile
199:                            + " file to property '" + property + "'.");
200:                } else {
201:                    log(info + "Replacing the property '" + property + "' in "
202:                            + confFile + " file .");
203:                }
204:                propertyReplace.execute();
205:            }
206:
207:            /**
208:             * @return the configurationFile.
209:             */
210:            protected String getConfigurationFile() {
211:                return configurationFile;
212:            }
213:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.