Source Code Cross Referenced for JEditComplexTransform.java in  » UML » jrefactory » org » acm » seguin » ide » jedit » 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 » UML » jrefactory » org.acm.seguin.ide.jedit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  Author:  Chris Seguin
003:         *  Author:  Mike Atkinson
004:         *
005:         *  This software has been developed under the copyleft
006:         *  rules of the GNU General Public License.  Please
007:         *  consult the GNU General Public License for more
008:         *  details about use and distribution of this software.
009:         */
010:        package org.acm.seguin.ide.jedit;
011:
012:        import java.util.ArrayList;
013:        import java.io.File;
014:        import java.io.IOException;
015:        import net.sourceforge.jrefactory.ast.SimpleNode;
016:        import org.acm.seguin.pretty.PrettyPrintFile;
017:        import org.acm.seguin.refactor.ComplexTransform;
018:        import org.acm.seguin.refactor.TransformAST;
019:        import org.acm.seguin.refactor.undo.UndoAction;
020:        import org.acm.seguin.version.VersionControl;
021:        import org.acm.seguin.version.VersionControlFactory;
022:        import org.acm.seguin.awt.ExceptionPrinter;
023:        import net.sourceforge.jrefactory.factory.FileParserFactory;
024:        import net.sourceforge.jrefactory.factory.ParserFactory;
025:
026:        /**
027:         *  Base class for a program that reads in an abstract syntax tree, transforms
028:         *  the code, and rewrites the file to disk.
029:         *
030:         *@author     Chris Seguin
031:         *@author     <a href="mailto:JRefactoryPlugin@ladyshot.demon.co.uk">Mike
032:         *      Atkinson</a>
033:         *@created    23 July 2003
034:         *@version    $Id: JEditComplexTransform.java,v 1.4 2003/10/30 15:24:22 mikeatkinson Exp $
035:         *@since      0.0.1
036:         */
037:        public class JEditComplexTransform implements  ComplexTransform {
038:            //  Instance Variables
039:            private ArrayList transforms;
040:            private UndoAction undo;
041:
042:            /**
043:             *  Constructor for the JEditComplexTransform object
044:             */
045:            public JEditComplexTransform() {
046:                transforms = new ArrayList();
047:            }
048:
049:            /**
050:             *  Sets the undoAction attribute of the JEditComplexTransform object
051:             *
052:             *@param  init  The new undoAction value
053:             */
054:            public void setUndoAction(UndoAction init) {
055:                undo = init;
056:            }
057:
058:            /**
059:             *  Adds a syntax tree transformation
060:             *
061:             *@param  value  Description of Parameter
062:             */
063:            public void add(TransformAST value) {
064:                //System.out.println("JEditComplexTransform.add(TransformAST)");
065:                if (value != null) {
066:                    transforms.add(value);
067:                }
068:            }
069:
070:            /**
071:             *  Clears all the transforms
072:             */
073:            public void clear() {
074:                //System.out.println("JEditComplexTransform.clear()");
075:                transforms.clear();
076:            }
077:
078:            /**
079:             *  Is it worth applying the transforms
080:             *
081:             *@return    true if there is any
082:             */
083:            public boolean hasAnyChanges() {
084:                //System.out.println("JEditComplexTransform.hasAnyChanges() => " + (transforms.size() > 0));
085:                return (transforms.size() > 0);
086:            }
087:
088:            /**
089:             *  Given a file, applies a set of transformations to it
090:             *
091:             *@param  inputFile   Description of Parameter
092:             *@param  outputFile  Description of Parameter
093:             */
094:            public void apply(File inputFile, File outputFile) {
095:                //System.out.println("JEditComplexTransform.apply(" + inputFile + "," + outputFile + ")");
096:                //  Get the abstract syntax tree
097:                ParserFactory factory = new FileParserFactory(inputFile);
098:                SimpleNode root = factory.getAbstractSyntaxTree(false,
099:                        ExceptionPrinter.getInstance());
100:
101:                //  Apply each individual transformation
102:                int last = transforms.size();
103:                for (int ndx = 0; ndx < last; ndx++) {
104:                    TransformAST next = (TransformAST) transforms.get(ndx);
105:                    next.update(root);
106:                }
107:
108:                //  Check it out if it is read only
109:                if (!inputFile.canWrite()) {
110:                    checkOut(inputFile);
111:                }
112:
113:                //  Print it
114:                undo.add(inputFile, outputFile);
115:                createParent(outputFile);
116:                try {
117:                    (new PrettyPrintFile()).apply(outputFile, root);
118:                } catch (Throwable thrown) {
119:                    ExceptionPrinter.print(thrown, false);
120:                }
121:            }
122:
123:            /**
124:             *  Creates a new file
125:             *
126:             *@param  file  Description of Parameter
127:             */
128:            public void createFile(File file) {
129:                //System.out.println("JEditComplexTransform.createFile(" + file + ")");
130:                undo.add(null, file);
131:            }
132:
133:            /**
134:             *  Removes an old file
135:             *
136:             *@param  file  Description of Parameter
137:             */
138:            public void removeFile(File file) {
139:                //System.out.println("JEditComplexTransform.removeFile(" + file + ")");
140:                undo.add(file, null);
141:            }
142:
143:            /**
144:             *  Creates the parent directory if it does not exist
145:             *
146:             *@param  file  the file that is about to be created
147:             */
148:            private void createParent(File file) {
149:                File parent = file.getParentFile();
150:                if (!parent.exists()) {
151:                    parent.mkdirs();
152:                }
153:            }
154:
155:            /**
156:             *  Checks out the specific file from the repository
157:             *
158:             *@param  file  the file to check out
159:             */
160:            private void checkOut(File file) {
161:                VersionControl controller = VersionControlFactory.get();
162:                String filename;
163:
164:                try {
165:                    filename = file.getCanonicalPath();
166:                } catch (IOException ioe) {
167:                    filename = file.getPath();
168:                }
169:
170:                controller.checkOut(filename);
171:            }
172:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.