Source Code Cross Referenced for pack.java in  » Database-Client » SQLMinus » isql » 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 » Database Client » SQLMinus » isql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package isql;
002:
003:        import java.io.*;
004:        import java.util.*;
005:        import java.lang.reflect.*;
006:        import util.*;
007:
008:        public class pack {
009:            // takes a String and parses the import statements
010:            // it maintains a list of imports it has taken care of
011:            // for each import what are the class/s (could be one fixed or many)
012:            // for the above what methods are available
013:            //
014:            /** the imports that have been processed */
015:            ArrayList imports = new ArrayList();
016:            /** packages and their classes 
017:             * Will have entried such as 
018:             *   | java.util.Vector | java.util.Vector |
019:             *or | java.util.*      | Vector, Hashtable,....
020:             *                    
021:             * */
022:            Map htPackageClasses = new HashMap();
023:            /** classes and their methods 
024:             * Will have entried such as 
025:             *   | java.util.Vector | add, put, delete
026:             */
027:            Map htClassMethods = new HashMap(128);
028:
029:            public static void main(String args[]) {
030:                String s = "package xxx;\nimport java.io.*;\n import java.util.*;import java.util.Vector;";
031:                System.out.println("string:<<<" + s + ">>>");
032:                pack p = new pack(s);
033:                /*
034:                p.print();
035:                String full = p.getFullClass("Hashtable");
036:                String methods[] = p.getClassMethods(full);
037:                System.out.println("Fullname:"+full);
038:                System.out.println("Methods:"+methods.toString());
039:                for( int i = 0; i < methods.length; i++) 
040:                    System.out.println("  :"+methods[i]);
041:
042:                full = p.getFullClass("ClassMethodTabExpander");
043:                System.out.println(  "full:"+ full);
044:                methods = p.getClassMethods(full);
045:                System.out.println("2 Fullname:"+full);
046:                System.out.println("2 Methods:"+methods.toString());
047:                for( int i = 0; i < methods.length; i++) 
048:                    System.out.println("  :"+methods[i]);
049:
050:                 */
051:                ClassMethodTabExpander cmte = new ClassMethodTabExpander(
052:                        p.htClassMethods, p.htPackageClasses);
053:                System.out.println("FileReader:rea...");
054:                System.out.println(cmte.getNextExpansion("FileReader:rea"));
055:                System.out.println(cmte.getNextExpansion("FileReader:rea"));
056:                System.out.println(cmte.getNextExpansion("FileReader:rea"));
057:                System.out.println("ClassMethodTabExpander:get...");
058:                String ss[] = cmte.getExpansions("ClassMethodTabExpander:get");
059:                for (int i = 0; i < ss.length; i++)
060:                    System.out.println("  .." + ss[i]);
061:                System.out.println("java.util.Random:nextB...");
062:                ss = cmte.getExpansions("java.util.Random:nextB");
063:                for (int i = 0; i < ss.length; i++)
064:                    System.out.println("  .." + ss[i]);
065:                System.out.println("java.util.Random:...");
066:                ss = cmte.getExpansions("java.util.Random:");
067:                for (int i = 0; i < ss.length; i++)
068:                    System.out.println("  .." + ss[i]);
069:            }
070:
071:            public pack(String s) {
072:                try {
073:                    BufferedReader br = new BufferedReader(new StringReader(s));
074:                    String t;
075:                    while ((t = br.readLine()) != null) {
076:                        String tmp[] = ArrayUtil.split(t, ';');
077:                        // each import statement
078:                        for (int i = 0; i < tmp.length; i++) {
079:                            String path = tmp[i].trim();
080:                            int pos;
081:                            if ((pos = path.indexOf("import ")) == -1)
082:                                continue;
083:                            // if we encounter class or interface which is not
084:                            // in comments we should break out
085:                            // Also, hopefully the word import did not come in
086:                            // some comment
087:                            imports.add(path);
088:                        }
089:                    }
090:                } catch (Exception exc) {
091:                    System.err.println("EXC:78:" + exc.toString());
092:                }
093:
094:                imports.add("import .");
095:                Iterator it = imports.iterator();
096:                while (it.hasNext()) {
097:                    String path = (String) it.next();
098:                    int pos = path.indexOf("import ");
099:                    String tpath = path.substring(pos + 1 + 6).trim();
100:                    System.out.println("import=" + tpath);
101:
102:                    ArrayList allp = null;
103:                    if (tpath.equals(".")) {
104:                        // get all the classes in current package
105:                        listpackage lp = new listpackage(tpath);
106:                        allp = lp.getClasses();
107:                        // get the classes and methods
108:                        /*
109:                        for( int i = 0; i < allp.size(); i++ ){ 
110:                            String classname = (String)allp.get(i);
111:                            htClassMethods.put( classname,
112:                                    retrieveMethods(classname));
113:                        }
114:                         */
115:                    } else if (tpath.indexOf('*') != -1) {
116:                        // get all the classes in that package
117:                        listpackage lp = new listpackage(tpath);
118:                        allp = lp.getClasses();
119:                    } else {
120:                        // just one class name in import
121:                        allp = new ArrayList();
122:                        allp.add(tpath);
123:                        htClassMethods.put(tpath, retrieveMethods(tpath));
124:                    }
125:                    System.out.println("putting:" + tpath + ":" + allp.size());
126:                    htPackageClasses.put(tpath, allp);
127:                } // while
128:            }
129:
130:            public void print() {
131:                System.out.println(" IMPORTS: ");
132:                for (int i = 0; i < imports.size(); i++)
133:                    System.out.println("  " + (String) imports.get(i));
134:                Iterator e = htPackageClasses.keySet().iterator();
135:                while (e.hasNext()) {
136:                    // can be java.io.* or java.io.IOException
137:                    String packpattern = (String) e.next(); // get package name
138:                    System.out.println("=" + packpattern);
139:                    ArrayList al = (ArrayList) htPackageClasses
140:                            .get(packpattern);
141:                    for (int i = 0; i < al.size(); i++) {
142:                        System.out.println("  -" + (String) al.get(i) + '-');
143:                        // retrieve all method names for class
144:                        String[] sarr = (String[]) (htClassMethods
145:                                .get((String) al.get(i)));
146:                        if (sarr != null)
147:                            for (int j = 0; j < sarr.length; j++) {
148:                                System.out.println("     +" + sarr[j]);
149:                            }
150:                    }
151:                }
152:            }
153:
154:            /** given a classname without package name, returns the class name
155:             * prefixed by package: given "FileReader" will return
156:             * "java.io.FileReader". However, java.io must be in the import
157:             * list, and the jar file containing the class should be in
158:             * classpath.
159:             */
160:            public String getFullClass(String partclassname) {
161:                Iterator e = htPackageClasses.keySet().iterator();
162:                System.out.println("getFullClass:" + partclassname);
163:                while (e.hasNext()) {
164:                    // can be java.io.* or java.io.IOException
165:                    String packpattern = (String) e.next(); // get package name
166:                    System.out.println("  PACKAGE:" + packpattern);
167:                    // this is a specific class import, not just a package
168:                    if (packpattern.indexOf('*') == -1
169:                            && !packpattern.equals(".")) {
170:                        if (packpattern.endsWith('.' + partclassname))
171:                            return packpattern;
172:                        continue;
173:                    }
174:                    ArrayList al = (ArrayList) htPackageClasses
175:                            .get(packpattern);
176:                    if (al == null)
177:                        System.err.println("AL WAS NULL:" + packpattern);
178:                    System.out.println("checking package contents :"
179:                            + al.size());
180:                    for (int i = 0; i < al.size(); i++) {
181:                        System.out.print("   " + i + ":" + al.get(i));
182:                        if (partclassname.equals((String) al.get(i)))
183:                            return packpattern.substring(0, packpattern
184:                                    .length() - 1)
185:                                    + partclassname;
186:                    }
187:                }
188:                System.out.println("Couldn t find:" + partclassname);
189:                return null;
190:            }
191:
192:            /** given a fully qualified classname, returns the names of methods
193:             * and constructors from cache, if not found it reflects and adds to
194:             * cache.
195:             */
196:            public String[] getClassMethods(String classname) {
197:                String[] sarr = (String[]) (htClassMethods.get(classname));
198:                if (sarr != null)
199:                    return sarr;
200:                else {
201:                    sarr = retrieveMethods(classname);
202:                    if (sarr != null)
203:                        htClassMethods.put(classname, sarr);
204:                }
205:                return sarr;
206:            }
207:
208:            /** Reflects on the fully qualified classname, returning its
209:             * methods.
210:             */
211:            private String[] retrieveMethods(String classname) {
212:
213:                try {
214:                    System.out.println("retrive: " + classname);
215:                    Class cl = Class.forName(classname);
216:                    Method[] methods = cl.getMethods();
217:                    ArrayList v = new ArrayList(methods.length);
218:                    for (int j = 0; j < methods.length; j++) {
219:                        String params = join(methods[j].getParameterTypes(),
220:                                ',');
221:                        v.add(methods[j].getName() + '(' + params + ')');
222:                    }
223:                    Constructor[] conss = cl.getConstructors();
224:                    for (int j = 0; j < conss.length; j++) {
225:                        String params = join(methods[j].getParameterTypes(),
226:                                ',');
227:                        v.add(conss[j].getName() + '(' + params + ')');
228:                    }
229:                    String[] sarr = new String[v.size()];
230:                    v.toArray(sarr);
231:                    Arrays.sort(sarr);
232:                    return sarr;
233:                } catch (Exception exc) {
234:                    System.err.println("EXC:" + exc.toString());
235:                    return null;
236:                }
237:            }
238:
239:            /** appends each index of string using getName and given separator.
240:             * This would work only for methods having a get Name such as class
241:             * and Method
242:             */
243:            public static String join(Class[] sarr, char csep) {
244:                int len = sarr.length;
245:                StringBuffer sbuf = new StringBuffer(len * 10);
246:                for (int i = 0; i < len; i++) {
247:                    if (i == len - 1)
248:                        sbuf.append(sarr[i].getName());
249:                    else
250:                        sbuf.append(sarr[i].getName()).append(csep);
251:                }
252:                return sbuf.toString();
253:            }
254:
255:        }// class
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.