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


001:        /* ====================================================================
002:         * The JRefactory License, Version 1.0
003:         *
004:         * Copyright (c) 2001 JRefactory.  All rights reserved.
005:         *
006:         * Redistribution and use in source and binary forms, with or without
007:         * modification, are permitted provided that the following conditions
008:         * are met:
009:         *
010:         * 1. Redistributions of source code must retain the above copyright
011:         *    notice, this list of conditions and the following disclaimer.
012:         *
013:         * 2. Redistributions in binary form must reproduce the above copyright
014:         *    notice, this list of conditions and the following disclaimer in
015:         *    the documentation and/or other materials provided with the
016:         *    distribution.
017:         *
018:         * 3. The end-user documentation included with the redistribution,
019:         *    if any, must include the following acknowledgment:
020:         *       "This product includes software developed by the
021:         *        JRefactory (http://www.sourceforge.org/projects/jrefactory)."
022:         *    Alternately, this acknowledgment may appear in the software itself,
023:         *    if and wherever such third-party acknowledgments normally appear.
024:         *
025:         * 4. The names "JRefactory" must not be used to endorse or promote
026:         *    products derived from this software without prior written
027:         *    permission. For written permission, please contact seguin@acm.org.
028:         *
029:         * 5. Products derived from this software may not be called "JRefactory",
030:         *    nor may "JRefactory" appear in their name, without prior written
031:         *    permission of Chris Seguin.
032:         *
033:         * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
034:         * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
035:         * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
036:         * DISCLAIMED.  IN NO EVENT SHALL THE CHRIS SEGUIN OR
037:         * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
038:         * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
039:         * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
040:         * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
041:         * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
042:         * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
043:         * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
044:         * SUCH DAMAGE.
045:         * ====================================================================
046:         *
047:         * This software consists of voluntary contributions made by many
048:         * individuals on behalf of JRefactory.  For more information on
049:         * JRefactory, please see
050:         * <http://www.sourceforge.org/projects/jrefactory>.
051:         */
052:        package org.acm.seguin.summary.query;
053:
054:        import java.io.File;
055:        import java.io.IOException;
056:        import java.util.Iterator;
057:        import java.util.StringTokenizer;
058:        import net.sourceforge.jrefactory.ast.ASTName;
059:        import net.sourceforge.jrefactory.ast.SimpleNode;
060:        import net.sourceforge.jrefactory.factory.FileParserFactory;
061:        import net.sourceforge.jrefactory.factory.ParserFactory;
062:        import net.sourceforge.jrefactory.query.PackageNameGetter;
063:        import org.acm.seguin.awt.ExceptionPrinter;
064:        import org.acm.seguin.summary.FileSummary;
065:        import org.acm.seguin.summary.PackageSummary;
066:        import org.acm.seguin.summary.Summary;
067:
068:        /**
069:         *  This class is used to infer the top level directory
070:         *
071:         *@author     Chris Seguin
072:         *@created    September 12, 2001
073:         */
074:        public class TopLevelDirectory {
075:            /**
076:             *  Gets the PackageDirectory attribute of the TopLevelDirectory class
077:             *
078:             *@param  initialSummary  Description of Parameter
079:             *@param  packageName     Description of Parameter
080:             *@return                 The PackageDirectory value
081:             */
082:            public static File getPackageDirectory(Summary initialSummary,
083:                    String packageName) {
084:                File rootDir = null;
085:
086:                if (initialSummary != null) {
087:                    FileSummary fileSummary = getFileSummary(initialSummary);
088:                    rootDir = query(fileSummary);
089:                }
090:
091:                if (rootDir == null) {
092:                    rootDir = query();
093:                }
094:
095:                StringTokenizer tok = new StringTokenizer(packageName, ".");
096:                File current = rootDir;
097:                while (tok.hasMoreTokens()) {
098:                    current = new File(current, tok.nextToken());
099:                }
100:
101:                return current;
102:            }
103:
104:            /**
105:             *  Return the top level directory from a FileSummary
106:             *
107:             *@param  fileSummary  Description of Parameter
108:             *@return              Description of the Returned Value
109:             */
110:            public static File query(FileSummary fileSummary) {
111:                File current = fileSummary.getFile();
112:                if (current == null) {
113:                    return null;
114:                }
115:
116:                File currentDir = current.getParentFile();
117:                PackageSummary packageSummary = (PackageSummary) fileSummary
118:                        .getParent();
119:
120:                String name = packageSummary.getName();
121:                if (name.length() == 0) {
122:                    return currentDir;
123:                }
124:
125:                int index = name.indexOf(".");
126:                currentDir = currentDir.getParentFile();
127:
128:                while (index != -1) {
129:                    index = name.indexOf(".", index + 1);
130:                    currentDir = currentDir.getParentFile();
131:                }
132:
133:                return currentDir;
134:            }
135:
136:            /**
137:             *  Return the top level directory
138:             *
139:             *@param  initialDir  Description of Parameter
140:             *@param  filename    Description of Parameter
141:             *@return             the top level directory
142:             */
143:            public static File query(File initialDir, String filename) {
144:                //  Create a factory to get a root
145:                File inputFile = new File(initialDir, filename);
146:                ParserFactory factory = new FileParserFactory(inputFile);
147:                SimpleNode root = factory.getAbstractSyntaxTree(false,
148:                        ExceptionPrinter.getInstance());
149:
150:                File topLevel = getParent(inputFile);
151:                ASTName packageName = PackageNameGetter.query(root);
152:                if (packageName != null) {
153:                    for (int ndx = 0; ndx < packageName.getNameSize(); ndx++) {
154:                        topLevel = getParent(topLevel);
155:                    }
156:                }
157:
158:                //  Return that directory
159:                return topLevel;
160:            }
161:
162:            /**
163:             *  Given a file, it returns the parent file
164:             *
165:             *@param  input  the input file
166:             *@return        the parent of that file
167:             */
168:            private static File getParent(File input) {
169:                try {
170:                    String path = input.getCanonicalPath();
171:                    File temp = new File(path);
172:                    return temp.getParentFile();
173:                } catch (IOException ioe) {
174:                }
175:
176:                return input.getParentFile();
177:            }
178:
179:            /**
180:             *  Gets the FileSummary attribute of the TopLevelDirectory class
181:             *
182:             *@param  initialSummary  Description of Parameter
183:             *@return                 The FileSummary value
184:             */
185:            private static FileSummary getFileSummary(Summary initialSummary) {
186:                Summary currentSummary = initialSummary;
187:                while (!(currentSummary instanceof  FileSummary)) {
188:                    currentSummary = currentSummary.getParent();
189:                    if (currentSummary == null) {
190:                        return null;
191:                    }
192:                }
193:                return (FileSummary) currentSummary;
194:            }
195:
196:            /**
197:             *  Searches all the packages for an appropriate file and infers the source
198:             *  root directory
199:             *
200:             *@return    the root directory
201:             */
202:            private static File query() {
203:                FileSummary appropriate = findFileSummary();
204:                if (appropriate == null) {
205:                    return new File(System.getProperty("user.dir"));
206:                }
207:
208:                PackageSummary packageSummary = (PackageSummary) appropriate
209:                        .getParent();
210:                String packageName = packageSummary.getName();
211:                StringTokenizer tok = new StringTokenizer(packageName, ".");
212:                File startingPoint = null;
213:                try {
214:                    startingPoint = new File(appropriate.getFile()
215:                            .getCanonicalPath());
216:                } catch (IOException ioe) {
217:                    startingPoint = appropriate.getFile();
218:                }
219:
220:                File current = startingPoint.getParentFile();
221:                while (tok.hasMoreTokens()) {
222:                    current = current.getParentFile();
223:                    String value = tok.nextToken();
224:                }
225:
226:                return current;
227:            }
228:
229:            /**
230:             *  Searches for a file summary with a file (rather than a null) in the file
231:             *
232:             *@return    the file summary
233:             */
234:            private static FileSummary findFileSummary() {
235:                Iterator iter = PackageSummary.getAllPackages();
236:                if (iter != null) {
237:                    while (iter.hasNext()) {
238:                        PackageSummary next = (PackageSummary) iter.next();
239:                        Iterator iter2 = next.getFileSummaries();
240:                        while ((iter2 != null) && iter2.hasNext()) {
241:                            FileSummary fileSummary = (FileSummary) iter2
242:                                    .next();
243:                            if (fileSummary.getFile() != null) {
244:                                return fileSummary;
245:                            }
246:                        }
247:                    }
248:                }
249:                return null;
250:            }
251:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.