Converter.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* Copyright (C) 1996 Active Software, Inc.
* All rights reserved.
*
* @(#) Converter.java 1.65 - last change made 08/20/97
*/
/**
* Base class for all converters. Converts a type of
* object to a string
* and back again.
*
* @version 1.65, 08/20/97
*/
public abstract class Converter {
/**
* Table of names for each registered converter.
*/
/**
* Table of instances for each converter that has
* been instantiated.
*/
/**
* Adds a new type converter to the global table of converters. A
* converter must be listed for this table in order for the search
* for a converter for that particular type to be successful.
*
* @param typeName the name of the type (what is returned by a
* call to getClass().getType() for an instance of that type)
* @param converterClassName the full name of the converter class
*/
}
/**
* Initialize the type converters for the types we know about.
*/
static {
"sunsoft.jws.visual.rt.type.IntArrayConverter");
"sunsoft.jws.visual.rt.type.DoubleArrayConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.StringConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.StringArrayConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.BooleanConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.CharacterConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.IntegerConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.ColorConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.ColorConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.FontConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.PointConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.DimensionConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.InsetsConverter");
addConverter(/* NOI18N */
"sunsoft.jws.visual.rt.awt.GBConstraints",
/* NOI18N */"sunsoft.jws.visual.rt.type.GBConstraintsConverter");
addConverter(/* NOI18N */
"sunsoft.jws.visual.rt.base.AttributeManager",
/* NOI18N */"sunsoft.jws.visual.rt.type.AMConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.AMRefConverter");
addConverter(/* NOI18N */
"sunsoft.jws.visual.rt.base.Attribute",
/* NOI18N */"sunsoft.jws.visual.rt.type.AttributeConverter");
addConverter(/* NOI18N */
"sunsoft.jws.visual.rt.base.AttributeList",
/* NOI18N */"sunsoft.jws.visual.rt.type.AttributeListConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.ImageRefConverter");
addConverter(/* NOI18N */
"sunsoft.jws.visual.rt.type.AlignmentEnum",
/* NOI18N */"sunsoft.jws.visual.rt.type.BaseEnumConverter");
addConverter(/* NOI18N */
"sunsoft.jws.visual.rt.type.AnchorEnum",
/* NOI18N */"sunsoft.jws.visual.rt.type.BaseEnumConverter");
addConverter(/* NOI18N */
"sunsoft.jws.visual.rt.type.OrientationEnum",
/* NOI18N */"sunsoft.jws.visual.rt.type.BaseEnumConverter");
addConverter(/* NOI18N */
"sunsoft.jws.visual.rt.type.ReliefEnum",
/* NOI18N */"sunsoft.jws.visual.rt.type.BaseEnumConverter");
/* NOI18N */"sunsoft.jws.visual.rt.type.BaseEnumConverter");
"sunsoft.jws.visual.rt.type.UnknownTypeConverter");
}
/**
* Returns an existing converter for the given type. Creates a new
* converter only if necessary (typically the first
* time one is asked for.)
*/
return converter;
(typeName);
if (converterType == null) {
/* JSTYLED */
// Load the class for the type and try again. Some types have
// static initializers that register their converters.
}
if (converterType == null) {
(/* NOI18N */"unknown");
if (converterType == null)
/* JSTYLED */
}
try {
return converter;
}
catch (Exception e) {
throw new Error(e.getMessage());
}
}
// For arrays, use the array type
int i;
for (i = 0; i < len; i++) {
break;
}
i++;
if (i < len)
}
try {
}
catch (ClassNotFoundException ex) {
/* JSTYLED */
System.out.println(Global.getMsg("sunsoft.jws.visual.rt.type.Converter.Class__not__found__for__.21") + typeName + /* NOI18N */"\".");
}
}
/**
* Returns true if there is a converter for the given type.
*/
}
/**
* The type editors (for more complex types.)
*/
/**
* Registers a type editor for a type. At run-time (in generated
* applications) there will typically be no editors, but they are
* needed for the attribute editor in the designer. The designer
* will set up all the standard ones.
*
* @see TypeEditor
*/
}
/**
* Returns true if there is an editor for the given type.
*
* @see TypeEditor
*/
}
/* BEGIN JSTYLED */
/**
* Returns a new instance of a type editor.
* The caller (typically the
* Designer) gets a new one of these every time, one for each
* attribute being edited, even if they are the same type. Caching
* instances of these type editors is up to the caller.
*/
/* END JSTYLED */
if (editorType != null) {
try {
// instances of type editors are NOT cached
return ((TypeEditor) c.newInstance());
}
/* JSTYLED */
}
}
return null;
}
/**
* Returns whether a converter instance has an
* associated type editor.
*
* @see TypeEditor
*/
public boolean hasTypeEditor() {
return (hasTypeEditor(getConverterType()));
}
/**
* Returns a new instance of the type editor associated with this
* converter.
*/
public TypeEditor newTypeEditor() {
return (newTypeEditor(getConverterType()));
}
/* JSTYLED */
// ------ Interfaces for Sub-Classers -----------------------------------
/**
* The name of the type being edited.
*/
protected String converterType;
/**
* An interface that can be overridden in sub-classes
* to whom the type
* converted is important.
*
* @see BaseEnumConverter
*/
}
/**
* Returns the type of object converted by this converter.
*/
public String getConverterType() {
return (converterType);
}
/* BEGIN JSTYLED */
/**
* Returns the string representation for an instance of
* the type this
* converter converts. Must be declared in subclasses
* to convert an
* object of the type specific to that subclass of Converter.
* <p>
* One of the two "convertToString" methods must be overridden in
* the converter sub-class. The overridden "convertToString"
* method
* should NOT call "super.convertToString". It is preferrable to
* override the StringBuffer version (the other one) because this
* will result in better performance.
*/
/* END JSTYLED */
enterConvert(TOSTRING, false);
exitConvert(TOSTRING, false);
}
/**
* Places a string representation of an instance of the type this
* converter converts into a string buffer.
*/
enterConvert(TOSTRING, true);
exitConvert(TOSTRING, true);
}
/**
* Returns a new instance of the type this converter converts, as
* specified by the string given. Must be declared
* in subclasses of
* Converter to convert a string representation into an object of
* the type converted by the subclass.
*/
/**
* Converts an instance of the type into a block of code.
*/
}
/**
* Converts an instance of the type converted into a line of code.
* This method provides a default way for any type to get a
* convertToCode method into it. It generates code that will feed
* the string representation of the object into the
* appropriate type
* converter. The performance isn't as good as customized
* convertToCode functions in subclasses since more classes have to
* be loaded at runtime.
*/
return (/* NOI18N */"convert(\"" +
else
return (/* NOI18N */"null");
}
/**
* Returns the string that should be displayed in the attribute
* editor. Subclassers that want something displayed other than
* what is returned from convertToString should override this
* method to return that.
*/
return (convertToString(obj));
}
/**
* Returns true if this type should be displayed in an editor.
*
* For the attribute editor, a return value of false means that the
* the textfield will be hidden.
*
* @return true
*/
public boolean viewableAsString() {
return true;
}
/**
* Returns true if this type is simple enough to be
* edited as a string
* in an editor.
*
* Sub-classers that represent type too complex for
* this should override
* this function to return false. For the attribute editor,
* this means
* that the textfield will be read-only.
*
* @see #viewableAsString
* @return same as viewableAsString
*/
public boolean editableAsString() {
return viewableAsString();
}
/**
* sub-class is overriding at least one of the "convertToString"
* methods, and at least one of the "convertToCode" methods.
* An error will be thrown at runtime if this in not the case.
* If this check wasn't done here , then the failure to
* override one
* of the methods would result in an infinite loop.
*/
private static final int TOSTRING = 0;
private static final int TOCODE = 1;
private boolean converting[] = {false, false};
private boolean isBuffered[] = {false, false};
private void enterConvert(int c, boolean isBuffered) {
"sunsoft.jws.visual.rt.type.Converter.Sub-classes__of__Conve.22"));
this.isBuffered[c] = isBuffered;
converting[c] = true;
convertRecurse[c]++;
}
private void exitConvert(int c, boolean isBuffered) {
if (!converting[c])
/* BEGIN JSTYLED */
if (this.isBuffered[c] != isBuffered)
/* END JSTYLED */
convertRecurse[c]--;
if (convertRecurse[c] == 0)
converting[c] = false;
}
/* BEGIN JSTYLED */
// ------ Utility Functions ----------------------------------------------
/**
* Returns a string that can be used as a newline.
* This string includes
* a carriage return if we are running on Windows.
*/
/* END JSTYLED */
}
/**
* Appends a newline to buf. This also appends a carriage return
* if we are running on Windows.
*/
}
private static int indentLevel = 0;
/**
* Appends spaces to "buf" based on the current indent level.
*/
for (int i = 0; i < indentLevel; i++)
}
/**
* Appends spaces to "buf" based on the given indent level.
*/
for (int i = 0; i < indentLevel; i++)
}
/**
* Increments the indent level.
*/
protected static void incrIndent() {
indentLevel++;
}
/**
* Decrements the indent level.
*/
protected static void decrIndent() {
indentLevel--;
}
/**
* Returns the current indent level.
*/
protected static int indentLevel() {
return indentLevel;
}
/**
* Returns the last token in a class name. i.e. the name that you
* can use for a class when you've imported the class already.
*/
if (index == -1)
return (className);
else
}
}