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


001:        /*
002:         *  Author:  Chris Seguin
003:         *
004:         *  This software has been developed under the copyleft
005:         *  rules of the GNU General Public License.  Please
006:         *  consult the GNU General Public License for more
007:         *  details about use and distribution of this software.
008:         */
009:        package org.acm.seguin.refactor.type;
010:
011:        import java.io.File;
012:        import net.sourceforge.jrefactory.ast.*;
013:        import org.acm.seguin.pretty.PrettyPrintFile;
014:        import org.acm.seguin.refactor.RefactoringException;
015:        import org.acm.seguin.summary.PackageSummary;
016:        import org.acm.seguin.summary.Summary;
017:        import org.acm.seguin.summary.TypeDeclSummary;
018:        import org.acm.seguin.summary.TypeSummary;
019:        import org.acm.seguin.summary.query.TopLevelDirectory;
020:        import net.sourceforge.jrefactory.parser.JavaParserTreeConstants;
021:
022:        /**
023:         *  This object creates an interface from nothing. It is responsible for
024:         *  building up the parse tree from scratch to create a new interface.
025:         *
026:         *@author     Grant Watson
027:         *@created    November 28, 2000
028:         */
029:        public class CreateNewInterface {
030:            private String m_interfaceName;
031:            private String m_packageName;
032:            private Summary m_summary;
033:
034:            /**
035:             *  Constructor for the CreateNewInterface object
036:             *
037:             *@param  interfaceName  Description of Parameter
038:             *@param  packageName    Description of Parameter
039:             *@param  summary        Description of Parameter
040:             */
041:            public CreateNewInterface(Summary summary, String packageName,
042:                    String interfaceName) {
043:                m_summary = summary;
044:                m_packageName = packageName;
045:                m_interfaceName = interfaceName;
046:            }
047:
048:            /**
049:             *  Constructor for the CreateNewInterface object
050:             */
051:            CreateNewInterface() {
052:                m_interfaceName = null;
053:                m_packageName = null;
054:            }
055:
056:            /**
057:             *  Creates the the designated class
058:             *
059:             *@return                           Description of the Returned Value
060:             *@exception  RefactoringException  Description of Exception
061:             */
062:            public File run() throws RefactoringException {
063:                if (m_packageName == null) {
064:                    throw new RefactoringException("No package name specified");
065:                }
066:
067:                if (m_interfaceName == null) {
068:                    throw new RefactoringException(
069:                            "No interface name specified");
070:                }
071:
072:                //  Create the AST
073:                ASTCompilationUnit root = new ASTCompilationUnit(0);
074:
075:                //  Create the package statement
076:                int nextIndex = 0;
077:
078:                if ((m_packageName != null) && (m_packageName.length() > 0)) {
079:                    ASTPackageDeclaration packDecl = createPackageDeclaration();
080:                    root.jjtAddChild(packDecl, 0);
081:                    nextIndex++;
082:                }
083:
084:                //  Create the class
085:                ASTTypeDeclaration td = createTypeDeclaration();
086:                root.jjtAddChild(td, nextIndex);
087:
088:                //  Print this new one
089:                File dest = print(m_interfaceName, root);
090:                return dest;
091:            }
092:
093:            /**
094:             *  Creates the package declaration
095:             *
096:             *@return    the package declaration
097:             */
098:            ASTPackageDeclaration createPackageDeclaration() {
099:                ASTPackageDeclaration packDecl = new ASTPackageDeclaration(
100:                        JavaParserTreeConstants.JJTPACKAGEDECLARATION);
101:                ASTName packName = new ASTName();
102:                packName.fromString(m_packageName);
103:                packDecl.jjtAddChild(packName, 0);
104:
105:                return packDecl;
106:            }
107:
108:            /**
109:             *  Creates the type declaration
110:             *
111:             *@return    the modified class
112:             */
113:            ASTTypeDeclaration createTypeDeclaration() {
114:                ASTTypeDeclaration td = new ASTTypeDeclaration();
115:                ASTInterfaceDeclaration id = createModifiedClass();
116:                td.jjtAddChild(id, 0);
117:
118:                return td;
119:            }
120:
121:            /**
122:             *  Creates the modified class
123:             *
124:             *@return    the modified class
125:             */
126:            ASTInterfaceDeclaration createModifiedClass() {
127:                ASTInterfaceDeclaration id = new ASTInterfaceDeclaration(
128:                        JavaParserTreeConstants.JJTINTERFACEDECLARATION);
129:                id.addModifier("public");
130:                ASTUnmodifiedInterfaceDeclaration uid = createClassBody(m_interfaceName);
131:                id.jjtAddChild(uid, 0);
132:                return id;
133:            }
134:
135:            /**
136:             *  Creates the body. The protection level is package so it can be easily
137:             *  tested.
138:             *
139:             *@param  parentName  Description of Parameter
140:             *@return             the class
141:             */
142:            ASTUnmodifiedInterfaceDeclaration createClassBody(String parentName) {
143:                ASTUnmodifiedInterfaceDeclaration uid = new ASTUnmodifiedInterfaceDeclaration(
144:                        JavaParserTreeConstants.JJTUNMODIFIEDINTERFACEDECLARATION);
145:                uid.setName(parentName);
146:                ASTInterfaceBody ib = new ASTInterfaceBody(
147:                        JavaParserTreeConstants.JJTINTERFACEBODY);
148:                uid.jjtAddChild(ib, 0);
149:                return uid;
150:            }
151:
152:            /**
153:             *  Prints the file
154:             *
155:             *@param  root           Description of Parameter
156:             *@param  interfaceName  Description of Parameter
157:             *@return                Description of the Returned Value
158:             */
159:            File print(String interfaceName, SimpleNode root) {
160:                File parent = TopLevelDirectory.getPackageDirectory(m_summary,
161:                        m_packageName);
162:
163:                // Create directory if it doesn't exist
164:                if (!parent.exists()) {
165:                    parent.mkdir();
166:                }
167:                File destFile = new File(parent, interfaceName + ".java");
168:
169:                try {
170:                    (new PrettyPrintFile()).apply(destFile, root);
171:                } catch (Throwable thrown) {
172:                    thrown.printStackTrace(System.out);
173:                }
174:
175:                return destFile;
176:            }
177:
178:            /**
179:             *  Gets the package summary
180:             *
181:             *@param  base  Description of Parameter
182:             *@return       the package summary
183:             */
184:            private PackageSummary getPackageSummary(Summary base) {
185:                Summary current = base;
186:                while (!(current instanceof  PackageSummary)) {
187:                    current = current.getParent();
188:                }
189:                return (PackageSummary) current;
190:            }
191:
192:            /**
193:             *  Gets the SameParent attribute of the AddAbstractParent object
194:             *
195:             *@param  one  Description of Parameter
196:             *@param  two  Description of Parameter
197:             *@return      The SameParent value
198:             */
199:            private boolean isSameParent(TypeSummary one, TypeSummary two) {
200:                if (isObject(one)) {
201:                    return isObject(two);
202:                }
203:
204:                if (isObject(two)) {
205:                    return false;
206:                }
207:
208:                return one.equals(two);
209:            }
210:
211:            /**
212:             *  Gets the Object attribute of the AddAbstractParent object
213:             *
214:             *@param  item  Description of Parameter
215:             *@return       The Object value
216:             */
217:            private boolean isObject(TypeSummary item) {
218:                if (item == null) {
219:                    return true;
220:                }
221:
222:                if (item.getName().equals("Object")) {
223:                    return true;
224:                }
225:
226:                return false;
227:            }
228:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.