Package ptolemy.cg.kernel.generic
Class CodeGeneratorUtilities
- java.lang.Object
-
- ptolemy.cg.kernel.generic.CodeGeneratorUtilities
-
public class CodeGeneratorUtilities extends java.lang.Object
Utilities that are useful for code generators.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Christopher Brooks
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Green (cxh)
-
-
Constructor Summary
Constructors Constructor Description CodeGeneratorUtilities()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.HashMap<java.lang.String,java.lang.String>
newMap(NamedObj namedObj)
Given a NamedObj, generate a HashMap containing String key/value pairs where each key is a Variable contained in the namedObj argument, and each value is the value of the Variable.static java.io.BufferedReader
openAsFileOrURL(java.lang.String inputFileName)
Given a string that names a file, URL or resource, try to open as a file, and then as a URL, then as a resource.static void
substitute(java.io.BufferedReader inputFile, java.util.Map<java.lang.String,java.lang.String> substituteMap, java.lang.String outputFileName)
Read in the contents of inputFile, and replace each matching String key found in substituteMap with the corresponding String value and write the results to outputFileName.static java.lang.String
substitute(java.lang.String input, java.util.Map<java.lang.String,java.lang.String> substituteMap)
Given a string and a Map containing String key/value pairs, substitute any keys found in the input with the corresponding values.static void
substitute(java.lang.String inputFileName, java.util.Map<java.lang.String,java.lang.String> substituteMap, java.lang.String outputFileName)
Read in the contents of inputFileName, and replace each matching String key found in substituteMap with the corresponding String value and write the results to outputFileName.static java.lang.String
substitute(java.lang.String inputFileName, NamedObj namedObj)
Read in the contents of inputFileName, and for each Parameter in namedObj, search for strings like@ParameterName@
in inputFileName, and substitute in the value of the Parameter and return the results.
-
-
-
Method Detail
-
newMap
public static java.util.HashMap<java.lang.String,java.lang.String> newMap(NamedObj namedObj) throws IllegalActionException
Given a NamedObj, generate a HashMap containing String key/value pairs where each key is a Variable contained in the namedObj argument, and each value is the value of the Variable.- Parameters:
namedObj
- The NamedObj that contains Variables- Returns:
- The HashMap consisting of key/value Strings.
- Throws:
IllegalActionException
- If there is a problem getting the Variables.
-
openAsFileOrURL
public static java.io.BufferedReader openAsFileOrURL(java.lang.String inputFileName) throws java.io.FileNotFoundException, java.io.IOException
Given a string that names a file, URL or resource, try to open as a file, and then as a URL, then as a resource.- Parameters:
inputFileName
- The name of the file or URL to open- Returns:
- A BufferedReader that refers to the inputFileName
- Throws:
java.io.FileNotFoundException
- If the file cannot be found.java.io.IOException
- If there were problems creating the BufferedReader.
-
substitute
public static java.lang.String substitute(java.lang.String input, java.util.Map<java.lang.String,java.lang.String> substituteMap)
Given a string and a Map containing String key/value pairs, substitute any keys found in the input with the corresponding values.- Parameters:
input
- The input string that contains substrings like "@codeBase@". If the string "@help:all@" appears, then all the key/value pairs are echoed.substituteMap
- The Map of String keys like "@codeBase@" and String values like "../../..".- Returns:
- A string with the keys properly substituted with their corresponding values.
-
substitute
public static java.lang.String substitute(java.lang.String inputFileName, NamedObj namedObj) throws java.io.FileNotFoundException, java.io.IOException
Read in the contents of inputFileName, and for each Parameter in namedObj, search for strings like@ParameterName@
in inputFileName, and substitute in the value of the Parameter and return the results.- Parameters:
inputFileName
- The name of the file to read from.namedObj
- The NamedObj that contains Parameters to be searched for in inputFileName.- Returns:
- The contents of inputFileName after doing the substitutions
- Throws:
java.io.FileNotFoundException
- If the input file cannot be found.java.io.IOException
- If there is a problem creating the substitution map.
-
substitute
public static void substitute(java.io.BufferedReader inputFile, java.util.Map<java.lang.String,java.lang.String> substituteMap, java.lang.String outputFileName) throws java.io.FileNotFoundException, java.io.IOException
Read in the contents of inputFile, and replace each matching String key found in substituteMap with the corresponding String value and write the results to outputFileName.- Parameters:
inputFile
- A BufferedReader that refers to the file to be read in. This BufferedReader is always closed by this method.substituteMap
- The Map of String keys like "@codeBase@" and String values like "../../..".outputFileName
- The name of the file to write to.- Throws:
java.io.FileNotFoundException
- If the input file cannot be found.java.io.IOException
- If there is a problem creating the substitution map.- See Also:
substitute(String, Map, String)
-
substitute
public static void substitute(java.lang.String inputFileName, java.util.Map<java.lang.String,java.lang.String> substituteMap, java.lang.String outputFileName) throws java.io.FileNotFoundException, java.io.IOException
Read in the contents of inputFileName, and replace each matching String key found in substituteMap with the corresponding String value and write the results to outputFileName.- Parameters:
inputFileName
- The name of the file to read from.substituteMap
- The Map of String keys like "@codeBase@" and String values like "../../..".outputFileName
- The name of the file to write to.- Throws:
java.io.FileNotFoundException
- If the input file cannot be found.java.io.IOException
- If there is a problem creating the substitution map.- See Also:
substitute(BufferedReader, Map, String)
-
-