jscheme
changeset 9:f0cd7a30ed85
Rename files and finish documentation.
| author | gnu_andrew@member.fsf.org |
|---|---|
| date | Sun Jun 08 23:58:11 2008 +0100 (2008-06-08) |
| parents | edf1ec681d8e |
| children | 20ca0223e096 |
| files | com/sun/tools/corba/se/logutil/Input.java com/sun/tools/corba/se/logutil/InputCode.java com/sun/tools/corba/se/logutil/InputException.java com/sun/tools/corba/se/logutil/InputExceptionGroup.java com/sun/tools/corba/se/logutil/MC.java |
line diff
1.1 --- a/com/sun/tools/corba/se/logutil/Input.java Sun Jun 08 23:34:30 2008 +0100 1.2 +++ b/com/sun/tools/corba/se/logutil/Input.java Sun Jun 08 23:58:11 2008 +0100 1.3 @@ -40,14 +40,29 @@ 1.4 1.5 public class Input { 1.6 1.7 + /** 1.8 + * The name of the package this class will inhabit. 1.9 + */ 1.10 private String packageName; 1.11 1.12 + /** 1.13 + * The name of the generated class. 1.14 + */ 1.15 private String className; 1.16 1.17 - private String exceptionName; 1.18 + /** 1.19 + * The name of the group of exceptions handled by the class. 1.20 + */ 1.21 + private String groupName; 1.22 1.23 - private Queue<InputExceptionGroup> exceptionGroups; 1.24 + /** 1.25 + * The group of exceptions. 1.26 + */ 1.27 + private Queue<InputException> exceptions; 1.28 1.29 + /** 1.30 + * Represents the current state of parsing the input. 1.31 + */ 1.32 private enum State 1.33 { 1.34 OUTER, 1.35 @@ -55,16 +70,27 @@ 1.36 IN_EXCEPTION_LIST 1.37 }; 1.38 1.39 + /** 1.40 + * Regular expression to match each code line. 1.41 + */ 1.42 private static final Pattern EXCEPTION_INFO_REGEX = 1.43 Pattern.compile("(\\w+)\\s*(\\d+)\\s*(\\w+)"); 1.44 1.45 + /** 1.46 + * Parses the specified file to create a new {@link Input} 1.47 + * object. 1.48 + * 1.49 + * @param filename the file to parse. 1.50 + * @throws FileNotFoundException if the file can't be found. 1.51 + * @throws IOException if an I/O error occurs. 1.52 + */ 1.53 public Input(final String filename) 1.54 throws FileNotFoundException, IOException { 1.55 BufferedReader r = 1.56 new BufferedReader(new InputStreamReader(new FileInputStream(filename))); 1.57 State state = State.OUTER; 1.58 - InputExceptionGroup currentCode = null; 1.59 - exceptionGroups = new LinkedList<InputExceptionGroup>(); 1.60 + InputException current = null; 1.61 + exceptions = new LinkedList<InputException>(); 1.62 String line; 1.63 while ((line = r.readLine()) != null) { 1.64 // Skip ; comments 1.65 @@ -81,7 +107,7 @@ 1.66 String[] classInfo = line.substring(index).split(" "); 1.67 packageName = classInfo[0].substring(2, classInfo[0].length() - 1); 1.68 className = classInfo[1].substring(1, classInfo[1].length() - 1); 1.69 - exceptionName = classInfo[2]; 1.70 + groupName = classInfo[2]; 1.71 break; 1.72 case IN_CLASS: 1.73 state = State.IN_EXCEPTION_LIST; 1.74 @@ -94,9 +120,9 @@ 1.75 Queue<String> lines = new LinkedList<String>(); 1.76 for (int a = start; a < line.length(); ++a) { 1.77 if (line.charAt(a) == '(' && !inCode && !inQuote) { 1.78 - if (currentCode == null) 1.79 - currentCode = 1.80 - new InputExceptionGroup(line.substring(start, a).trim()); 1.81 + if (current == null) 1.82 + current = 1.83 + new InputException(line.substring(start, a).trim()); 1.84 start = a + 1; 1.85 inCode = true; 1.86 } 1.87 @@ -116,44 +142,68 @@ 1.88 int stringStart = l.indexOf("\""); 1.89 Matcher matcher = EXCEPTION_INFO_REGEX.matcher(l.substring(0, stringStart)); 1.90 if (matcher.find()) 1.91 - currentCode.add(new InputException(matcher.group(1), 1.92 - Integer.parseInt(matcher.group(2)), 1.93 - matcher.group(3), 1.94 - l.substring(stringStart + 1, l.length()))); 1.95 + current.add(new InputCode(matcher.group(1), 1.96 + Integer.parseInt(matcher.group(2)), 1.97 + matcher.group(3), 1.98 + l.substring(stringStart + 1, l.length()))); 1.99 } 1.100 - System.out.println("Adding currentCode: " + currentCode); 1.101 - exceptionGroups.offer(currentCode); 1.102 - currentCode = null; 1.103 + exceptions.offer(current); 1.104 + current = null; 1.105 break; 1.106 } 1.107 } 1.108 } 1.109 1.110 - public String getExceptionName() 1.111 + /** 1.112 + * Returns the name of this group of exceptions. 1.113 + * 1.114 + * @return the name of this group of exceptions. 1.115 + */ 1.116 + public String getGroupName() 1.117 { 1.118 - return exceptionName; 1.119 + return groupName; 1.120 } 1.121 1.122 + /** 1.123 + * Returns the name of the package this class will go in. 1.124 + * 1.125 + * @return the name of the package. 1.126 + */ 1.127 public String getPackageName() 1.128 { 1.129 return packageName; 1.130 } 1.131 1.132 + /** 1.133 + * Returns the name of the generated class. 1.134 + * 1.135 + * @return the name of the class. 1.136 + */ 1.137 public String getClassName() 1.138 { 1.139 return className; 1.140 } 1.141 1.142 - public Queue<InputExceptionGroup> getExceptionGroups() { 1.143 - return exceptionGroups; 1.144 + /** 1.145 + * Returns the exceptions contained in this class. 1.146 + * 1.147 + * @return the exceptions. 1.148 + */ 1.149 + public Queue<InputException> getExceptions() { 1.150 + return exceptions; 1.151 } 1.152 1.153 + /** 1.154 + * Returns a textual representation of this input. 1.155 + * 1.156 + * @return a textual representation. 1.157 + */ 1.158 public String toString() { 1.159 return getClass().getName() + 1.160 "[packageName=" + packageName + 1.161 ",className=" + className + 1.162 - ",exceptionName=" + exceptionName + 1.163 - ",exceptionGroups=" + exceptionGroups + 1.164 + ",groupName=" + groupName + 1.165 + ",exceptions=" + exceptions + 1.166 "]"; 1.167 } 1.168
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/com/sun/tools/corba/se/logutil/InputCode.java Sun Jun 08 23:58:11 2008 +0100 2.3 @@ -0,0 +1,116 @@ 2.4 +/* 2.5 + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. Sun designates this 2.11 + * particular file as subject to the "Classpath" exception as provided 2.12 + * by Sun in the LICENSE file that accompanied this code. 2.13 + * 2.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.17 + * version 2 for more details (a copy is included in the LICENSE file that 2.18 + * accompanied this code). 2.19 + * 2.20 + * You should have received a copy of the GNU General Public License version 2.21 + * 2 along with this work; if not, write to the Free Software Foundation, 2.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.23 + * 2.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2.25 + * CA 95054 USA or visit www.sun.com if you need additional information or 2.26 + * have any questions. 2.27 + */ 2.28 +package com.sun.tools.corba.se.logutil; 2.29 + 2.30 +public class InputCode { 2.31 + 2.32 + /** 2.33 + * The name of this code. 2.34 + */ 2.35 + private final String name; 2.36 + 2.37 + /** 2.38 + * The code. 2.39 + */ 2.40 + private final int code; 2.41 + 2.42 + /** 2.43 + * The log level for this code. 2.44 + */ 2.45 + private final String logLevel; 2.46 + 2.47 + /** 2.48 + * The error message for this code. 2.49 + */ 2.50 + private final String message; 2.51 + 2.52 + /** 2.53 + * Creates a new error code with the specified name, code, 2.54 + * log level and error message. 2.55 + * 2.56 + * @param name the name of the new code. 2.57 + * @param code the code itself. 2.58 + * @param logLevel the level of severity of this error. 2.59 + * @param message the error message for this code. 2.60 + */ 2.61 + public InputCode(final String name, final int code, 2.62 + final String logLevel, final String message) { 2.63 + this.name = name; 2.64 + this.code = code; 2.65 + this.logLevel = logLevel; 2.66 + this.message = message; 2.67 + } 2.68 + 2.69 + /** 2.70 + * Returns the name of this code. 2.71 + * 2.72 + * @return the name of the code. 2.73 + */ 2.74 + public String getName() { 2.75 + return name; 2.76 + } 2.77 + 2.78 + /** 2.79 + * Returns the code. 2.80 + * 2.81 + * @return the code. 2.82 + */ 2.83 + public int getCode() { 2.84 + return code; 2.85 + } 2.86 + 2.87 + /** 2.88 + * Returns the severity of this code. 2.89 + * 2.90 + * @return the log level severity of the code. 2.91 + */ 2.92 + public String getLogLevel() { 2.93 + return logLevel; 2.94 + } 2.95 + 2.96 + /** 2.97 + * Returns the error message for this code. 2.98 + * 2.99 + * @return the error message for this code. 2.100 + */ 2.101 + public String getMessage() { 2.102 + return message; 2.103 + } 2.104 + 2.105 + /** 2.106 + * Returns a textual representation of this code. 2.107 + * 2.108 + * @return a textual representation. 2.109 + */ 2.110 + public String toString() { 2.111 + return getClass().getName() + 2.112 + "[name=" + name + 2.113 + ",code=" + code + 2.114 + ",logLevel=" + logLevel + 2.115 + ",message=" + message + 2.116 + "]"; 2.117 + } 2.118 + 2.119 +}
3.1 --- a/com/sun/tools/corba/se/logutil/InputException.java Sun Jun 08 23:34:30 2008 +0100 3.2 +++ b/com/sun/tools/corba/se/logutil/InputException.java Sun Jun 08 23:58:11 2008 +0100 3.3 @@ -24,47 +24,72 @@ 3.4 */ 3.5 package com.sun.tools.corba.se.logutil; 3.6 3.7 +import java.util.LinkedList; 3.8 +import java.util.Queue; 3.9 + 3.10 public class InputException { 3.11 3.12 + /** 3.13 + * The name of this exception. 3.14 + */ 3.15 private final String name; 3.16 3.17 - private final int code; 3.18 + /** 3.19 + * The codes associated with this exception. 3.20 + */ 3.21 + private final Queue<InputCode> codes; 3.22 3.23 - private final String logLevel; 3.24 - 3.25 - private final String message; 3.26 - 3.27 - public InputException(final String name, final int code, 3.28 - final String logLevel, final String message) { 3.29 + /** 3.30 + * Constructs a new {@link InputException} with the 3.31 + * specified name. 3.32 + * 3.33 + * @param name the name of the new exception; 3.34 + */ 3.35 + public InputException(final String name) { 3.36 this.name = name; 3.37 - this.code = code; 3.38 - this.logLevel = logLevel; 3.39 - this.message = message; 3.40 + codes = new LinkedList<InputCode>(); 3.41 } 3.42 3.43 + /** 3.44 + * Adds a new code to this exception. 3.45 + * 3.46 + * @param c the code to add. 3.47 + */ 3.48 + public void add(InputCode c) 3.49 + { 3.50 + codes.offer(c); 3.51 + } 3.52 + 3.53 + /** 3.54 + * Returns the name of this exception. 3.55 + * 3.56 + * @return the exception's name. 3.57 + */ 3.58 public String getName() { 3.59 return name; 3.60 } 3.61 3.62 - public int getCode() { 3.63 - return code; 3.64 + /** 3.65 + * Returns the codes associated with this exception. 3.66 + * 3.67 + * @return the exception's codes. 3.68 + */ 3.69 + public Queue<InputCode> getCodes() { 3.70 + return codes; 3.71 } 3.72 3.73 - public String getLogLevel() { 3.74 - return logLevel; 3.75 + /** 3.76 + * Returns a textual representation of this exception. 3.77 + * 3.78 + * @return a textual representation. 3.79 + */ 3.80 + public String toString() { 3.81 + return getClass().getName() 3.82 + + "[name=" + name 3.83 + + ",codes=" + codes 3.84 + + "]"; 3.85 } 3.86 3.87 - public String getMessage() { 3.88 - return message; 3.89 - } 3.90 - 3.91 - public String toString() { 3.92 - return getClass().getName() + 3.93 - "[name=" + name + 3.94 - ",code=" + code + 3.95 - ",logLevel=" + logLevel + 3.96 - ",message=" + message + 3.97 - "]"; 3.98 - } 3.99 3.100 } 3.101 +
4.1 --- a/com/sun/tools/corba/se/logutil/InputExceptionGroup.java Sun Jun 08 23:34:30 2008 +0100 4.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 4.3 @@ -1,63 +0,0 @@ 4.4 -/* 4.5 - * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. 4.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 - * 4.8 - * This code is free software; you can redistribute it and/or modify it 4.9 - * under the terms of the GNU General Public License version 2 only, as 4.10 - * published by the Free Software Foundation. Sun designates this 4.11 - * particular file as subject to the "Classpath" exception as provided 4.12 - * by Sun in the LICENSE file that accompanied this code. 4.13 - * 4.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 4.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.17 - * version 2 for more details (a copy is included in the LICENSE file that 4.18 - * accompanied this code). 4.19 - * 4.20 - * You should have received a copy of the GNU General Public License version 4.21 - * 2 along with this work; if not, write to the Free Software Foundation, 4.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.23 - * 4.24 - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 4.25 - * CA 95054 USA or visit www.sun.com if you need additional information or 4.26 - * have any questions. 4.27 - */ 4.28 -package com.sun.tools.corba.se.logutil; 4.29 - 4.30 -import java.util.LinkedList; 4.31 -import java.util.Queue; 4.32 - 4.33 -public class InputExceptionGroup { 4.34 - 4.35 - private final String groupName; 4.36 - 4.37 - private final Queue<InputException> exceptions; 4.38 - 4.39 - public InputExceptionGroup(final String groupName) { 4.40 - this.groupName = groupName; 4.41 - exceptions = new LinkedList<InputException>(); 4.42 - } 4.43 - 4.44 - public void add(InputException e) 4.45 - { 4.46 - exceptions.offer(e); 4.47 - } 4.48 - 4.49 - public String getGroupName() { 4.50 - return groupName; 4.51 - } 4.52 - 4.53 - public Queue<InputException> getExceptions() { 4.54 - return exceptions; 4.55 - } 4.56 - 4.57 - public String toString() { 4.58 - return getClass().getName() 4.59 - + "[groupName=" + groupName 4.60 - + ",exceptions=" + exceptions 4.61 - + "]"; 4.62 - } 4.63 - 4.64 - 4.65 -} 4.66 -
5.1 --- a/com/sun/tools/corba/se/logutil/MC.java Sun Jun 08 23:34:30 2008 +0100 5.2 +++ b/com/sun/tools/corba/se/logutil/MC.java Sun Jun 08 23:58:11 2008 +0100 5.3 @@ -89,12 +89,12 @@ 5.4 throws FileNotFoundException { 5.5 String packageName = input.getPackageName(); 5.6 String className = input.getClassName(); 5.7 - String exceptionName = input.getExceptionName(); 5.8 - Queue<InputExceptionGroup> exceptionGroups = input.getExceptionGroups(); 5.9 + String groupName = input.getGroupName(); 5.10 + Queue<InputException> exceptions = input.getExceptions(); 5.11 FileOutputStream file = new FileOutputStream(outDir + File.separator + className + ".java"); 5.12 IndentingPrintWriter pw = new IndentingPrintWriter(file); 5.13 5.14 - writeClassHeader(inFile, exceptionName, pw); 5.15 + writeClassHeader(inFile, groupName, pw); 5.16 pw.printMsg("package @ ;", packageName); 5.17 pw.println(); 5.18 pw.println("import java.util.logging.Logger ;"); 5.19 @@ -111,7 +111,7 @@ 5.20 pw.println(); 5.21 pw.println( "import com.sun.corba.se.spi.logging.LogWrapperBase;"); 5.22 pw.println(); 5.23 - writeImports(exceptionGroups, pw); 5.24 + writeImports(exceptions, pw); 5.25 pw.println(); 5.26 pw.indent(); 5.27 pw.printMsg("public class @ extends LogWrapperBase {", className); 5.28 @@ -124,8 +124,8 @@ 5.29 pw.println( "}"); 5.30 pw.println(); 5.31 pw.flush(); 5.32 - writeFactoryMethod(className, exceptionName, pw); 5.33 - writeExceptions(exceptionName, exceptionGroups, className, pw); 5.34 + writeFactoryMethod(className, groupName, pw); 5.35 + writeExceptions(groupName, exceptions, className, pw); 5.36 pw.undent(); 5.37 pw.println( ); 5.38 pw.println( "}"); 5.39 @@ -137,16 +137,16 @@ 5.40 * Writes out the header of a Java source file. 5.41 * 5.42 * @param inFile the input file the file was generated from. 5.43 - * @param exceptionGroupName the group of exceptions the Java source file is for. 5.44 + * @param groupName the group of exceptions the Java source file is for. 5.45 * @param pw the print writer used to write the output. 5.46 */ 5.47 - private void writeClassHeader(String inFile, String exceptionName, 5.48 + private void writeClassHeader(String inFile, String groupName, 5.49 IndentingPrintWriter pw) { 5.50 - if (exceptionName.equals("OMG")) 5.51 + if (groupName.equals("OMG")) 5.52 pw.println("// Log wrapper class for standard exceptions"); 5.53 else 5.54 pw.printMsg("// Log wrapper class for Sun private system exceptions in group @", 5.55 - exceptionName); 5.56 + groupName); 5.57 pw.println("//"); 5.58 pw.printMsg("// Generated by MC.java version @, DO NOT EDIT BY HAND!", VERSION); 5.59 pw.printMsg("// Generated from input file @ on @", inFile, new Date()); 5.60 @@ -156,18 +156,25 @@ 5.61 /** 5.62 * Write out the import list for the exceptions. 5.63 * 5.64 - * @param groups the exception groups that were parsed. 5.65 + * @param groups the exceptions that were parsed. 5.66 * @param pw the {@link IndentingPrintWriter} for writing to the file. 5.67 */ 5.68 - private void writeImports(Queue<InputExceptionGroup> groups, 5.69 + private void writeImports(Queue<InputException> exceptions, 5.70 IndentingPrintWriter pw) { 5.71 - if (groups == null) 5.72 + if (exceptions == null) 5.73 return; 5.74 - for (InputExceptionGroup g : groups) 5.75 - pw.println("import org.omg.CORBA." + g.getGroupName() + " ;"); 5.76 + for (InputException e : exceptions) 5.77 + pw.println("import org.omg.CORBA." + e.getName() + " ;"); 5.78 } 5.79 5.80 - private void writeFactoryMethod(String className, String exceptionName, 5.81 + /** 5.82 + * Write out the factory method for this group of exceptions. 5.83 + * 5.84 + * @param className the name of the generated class. 5.85 + * @param groupName the name of this group of exceptions. 5.86 + * @param pw the {@link IndentingPrintWriter} for writing to the file. 5.87 + */ 5.88 + private void writeFactoryMethod(String className, String groupName, 5.89 IndentingPrintWriter pw) { 5.90 pw.indent(); 5.91 pw.println( "private static LogWrapperFactory factory = new LogWrapperFactory() {"); 5.92 @@ -189,7 +196,7 @@ 5.93 pw.printMsg( "(@) orb.getLogWrapper( logDomain, ", className); 5.94 pw.undent(); 5.95 pw.undent(); 5.96 - pw.printMsg( "\"@\", factory ) ;", exceptionName); 5.97 + pw.printMsg( "\"@\", factory ) ;", groupName); 5.98 pw.undent(); 5.99 pw.println( "return wrapper ;" ); 5.100 pw.println( "} " ); 5.101 @@ -203,23 +210,31 @@ 5.102 pw.printMsg( "(@) ORB.staticGetLogWrapper( logDomain, ", className); 5.103 pw.undent(); 5.104 pw.undent(); 5.105 - pw.printMsg( "\"@\", factory ) ;", exceptionName); 5.106 + pw.printMsg( "\"@\", factory ) ;", groupName); 5.107 pw.undent(); 5.108 pw.println( "return wrapper ;" ); 5.109 pw.println( "} " ); 5.110 pw.println(); 5.111 } 5.112 5.113 - private void writeExceptions(String groupName, Queue<InputExceptionGroup> groups, 5.114 + /** 5.115 + * Writes out the exceptions themselves. 5.116 + * 5.117 + * @param groupName the name of this group of exceptions. 5.118 + * @param exceptions the exceptions to write out. 5.119 + * @param className the name of the generated class. 5.120 + * @param pw the {@link IndentingPrintWriter} for writing to the file. 5.121 + */ 5.122 + private void writeExceptions(String groupName, Queue<InputException> exceptions, 5.123 String className, IndentingPrintWriter pw) { 5.124 - for (InputExceptionGroup g : groups) { 5.125 + for (InputException e : exceptions) { 5.126 pw.println("///////////////////////////////////////////////////////////"); 5.127 - pw.printMsg("// @", g.getGroupName()); 5.128 + pw.printMsg("// @", e.getName()); 5.129 pw.println("///////////////////////////////////////////////////////////"); 5.130 pw.println(); 5.131 - for (InputException e : g.getExceptions()) 5.132 - writeMethods(groupName, g.getGroupName(), e.getName(), e.getCode(), 5.133 - e.getLogLevel(), className, StringUtil.countArgs(e.getMessage()), pw); 5.134 + for (InputCode c : e.getCodes()) 5.135 + writeMethods(groupName, e.getName(), c.getName(), c.getCode(), 5.136 + c.getLogLevel(), className, StringUtil.countArgs(c.getMessage()), pw); 5.137 pw.flush(); 5.138 } 5.139 } 5.140 @@ -423,10 +438,24 @@ 5.141 return "SUNVMCID.value + " + (code + getSunBaseNumber(groupName)); 5.142 } 5.143 5.144 + /** 5.145 + * Returns the base number for Sun-specific exceptions. 5.146 + * 5.147 + * @return the base number. 5.148 + */ 5.149 private int getSunBaseNumber(String groupName) { 5.150 return 200 * SUN_EXCEPTION_GROUPS.indexOf(groupName); 5.151 } 5.152 5.153 + /** 5.154 + * Entry point for running the generator from the command 5.155 + * line. Users can specify either "make-class" or "make-resource" 5.156 + * as the first argument to generate the specified type of file. 5.157 + * 5.158 + * @param args the command-line arguments. 5.159 + * @throws FileNotFoundException if the input file can not be found. 5.160 + * @throws IOException if an I/O error occurs. 5.161 + */ 5.162 public static void main(String[] args) 5.163 throws FileNotFoundException, IOException 5.164 {
