/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* A utlity for generating a BeanInfo source file from a template and a
* Hashtable with hints that were generated from a doclet.
* it's neccessary to write things like the per property descriptions
* by hand. To run the application:
* <pre>
* java GenSwingBeanInfo <class name>
* </pre>
* Code for a bean info class is written to out. If the class is
* swing package, you don't need to fully specify its name.
*
* @author Hans Muller
* @author Rich Schiavi
* @author Mark Davidson
*/
public class GenSwingBeanInfo {
// Tokens in @(...)
private boolean DEBUG = false;
/**
* Public constructor
* @param fileDir Location to put the generated source files.
* @param templateFilename Location of the BeanInfo template
* @param debug Flag to turn on debugging
*/
this.templateFilename = templateFilename;
}
/**
* Opens a BeanInfo PrintStream for the class.
*/
try {
return new PrintStream(out);
} catch (IOException e){
// System.err.println("GenSwingBeanInfo: " + e.toString());
}
return null;
}
}
/**
* Load the contents of the BeanInfo template into a string and
* return the string.
*/
try {
int c;
}
} catch (IOException e) {
}
return template;
}
/**
* Generates a string for the BeanDescriptor
*/
// we support export, hidden, preferred
code += " sun.swing.BeanInfoUtils.EXPERT, Boolean.TRUE,\n";
code += " sun.swing.BeanInfoUtils.HIDDEN, Boolean.TRUE,\n";
/* 1.2 only - make sure build flag build using 1.2 */
code += " sun.swing.BeanInfoUtils.PREFERRED, Boolean.TRUE,\n";
}
return code;
}
/**
* Generates the code for the attributes table.
*/
// Substitute the "true" and "false" for codegen Boolean values.
value = "Boolean.TRUE";
else
value = "Boolean.FALSE";
} else {
}
}
}
/**
* Generates the code for the enumeration.
* XXX - side effect: Modifies the enumcode field variable.
*/
}
// Close the statically initialized Object[]
// Add this string to the enumeration code.
// Return the PropertyDescriptor init string;
}
/**
* Generate the createPropertyDescriptor() calls, one per property.
* A fully specified createPropertyDescriptor() call looks like this:
* <pre>
* createPropertyDescriptor("contentPane", new Object[] {
* BOUND, Boolean.TRUE,
* CONSTRAINED, Boolean.TRUE,
* PROPERTYEDITORCLASS, package.MyEditor.cl
* WRITEMETHOD, "setContentPane",
* DISPLAYNAME, "contentPane",
* EXPERT, Boolean.FALSE,
* HIDDEN, Boolean.FALSE,
* PREFERRED, Boolean.TRUE,
* SHORTDESCRIPTION, "A top level window with a window manager border",
* "random attribute","random value"
* }
* );
* </pre>
*
* @param info The actual BeanInfo class generated from from the Intospector.
* @param dochash Set of DocBeanInfo pairs for each property. This information
* is used to suplement the instrospected properties.
* @return A snippet of source code which would construct all the PropertyDescriptors.
*/
boolean hash_match = false;
if (DEBUG)
// BeanInfo pds using our DocBeanInfo class values
hash_match = true;
if (DEBUG)
} else {
hash_match = false;
}
// Do I need to do anything with this property descriptor
if (hash_match) {
code += " sun.swing.BeanInfoUtils.BOUND, Boolean.TRUE,\n";
} else {
code += " sun.swing.BeanInfoUtils.BOUND, Boolean.FALSE,\n";
}
}
if (pds[i].isConstrained()) {
code += " sun.swing.BeanInfoUtils.CONSTRAINED, Boolean.TRUE,\n";
}
}
}
}
}
code += " sun.swing.BeanInfoUtils.EXPERT, Boolean.TRUE,\n";
}
code += " sun.swing.BeanInfoUtils.HIDDEN, Boolean.TRUE,\n";
}
if (pds[i].isPreferred()) {
code += " sun.swing.BeanInfoUtils.PREFERRED, Boolean.TRUE,\n";
}
// user attributes
if (hash_match) {
}
}
// Print the closing brackets. If this is the last array initializer,
// don't print the trailing comma.
code += " }\n)\n";
} else {
code += " }\n),\n";
}
} // end if ( readMethod != null )
} // end for
return code;
}
/**
* Sets properties from the BeanInfo supplement on the
* introspected PropertyDescriptor
*/
pds.setConstrained(true);
pds.setPreferred(true);
}
}
}
/**
* Generates the BeanInfo source file using instrospection and a
* Hashtable full of hints. This the only public method in this class.
*
* @param classname Root name of the class. i.e., JButton
* @param dochash A hashtable containing the DocBeanInfo.
*/
// The following initial values are just examples. All of these
// fields are initialized below.
}
// Get the output stream.
// Run the Introspector and initialize the variables
try {
// Go all the way up the heirarchy for JComponent
} else {
}
} catch (IntrospectionException e) {
}
if (DEBUG){
}
// Generate the Class BeanDescriptor information first
if (DEBUG)
} else
} else
// Generate the Property descriptors
// Dump the template to out, substituting values for
// @(token) tokens as they're encountered.
int currentIndex = 0;
// not loading this to get around build issue for now
// This loop substitutes the "@(...)" tags in the template with the ones for the
// current class.
// Find the Token
if (tokenStart != -1) {
if (tokenEnd == -1) {
}
}
// Ignore the @(#) Version Control tag if it exists.
} else {
}
} else {
// tokenStart == -1 - We are finsihed.
break;
}
}
}
/**
* Returns the class from the package name and the class root name.
*
* @param packageName The name of the package of the containing class.
* @param rootname The root name of the class. i.e, JButton
* @return The class instance or null.
*/
}
try {
} catch (ClassNotFoundException e) {
// Fail silently.
}
return cls;
}
/**
* Prints the formated descriptors to the PrintStream
* @param out Open PrintStream
* @param s String descriptor
* @param template Template
* @param tokenStart Index into the template
*/
// Find the newline that preceeds @(BeanPropertyDescriptors) to
// calculate the indent.
for (int i = tokenStart; i >= 0; i--) {
char[] chars = new char[tokenStart - i];
chars[j] = ' ';
}
break;
}
}
int i = 0;
while(i < s.length()) {
i = nlIndex + 1;
}
}
}