Class ClassNameResolver
- java.lang.Object
-
- com.inductiveautomation.ignition.common.xmlserialization.ClassNameResolver
-
public class ClassNameResolver extends java.lang.Object
Serves as a bidirectional mapping between classes and their names. Supports aliases and package search paths. Also comes pre-configured with shortened aliases for most common types (primitives, numbers, lists, etc) and search paths for common java packages like lang, util, awt, swing, beans.
-
-
Constructor Summary
Constructors Constructor Description ClassNameResolver()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addAlias(java.lang.Class clazz, java.lang.String alias)
Adds a new alias for this class.void
addDefaults()
void
addSearchPath(java.lang.String path)
Deprecated.This functionality is deprecated.java.lang.Class
classForName(java.lang.String name)
Attempts to find the Class for the given name, in the context of any aliases and search paths that have been previously configuredprotected java.lang.Class
classForNameImpl(java.lang.String name)
static ClassNameResolver
createBasic()
java.lang.String
getName(java.lang.Class clazz)
Returns the inverse ofclassForName(String)
.
-
-
-
Method Detail
-
createBasic
public static ClassNameResolver createBasic()
-
addDefaults
public void addDefaults()
-
addAlias
public void addAlias(java.lang.Class clazz, java.lang.String alias)
Adds a new alias for this class. This alias takes precedence over a search path. Each alias can only be used once, but an class can have more than one alias. The class will resolve to the first alias (name) added for it.
-
addSearchPath
@Deprecated public void addSearchPath(java.lang.String path)
Deprecated.This functionality is deprecated. You can continue to add search paths for the backwards compatibility of de-serializing, but new serialized code will not contain the shortened versions of the classnames.Adds a new search path. For example, if you add the search path of "javax.swing" then the class "javax.swing.JLabel" will map bidirectionally to the string "JLabel"
-
getName
public java.lang.String getName(java.lang.Class clazz)
Returns the inverse ofclassForName(String)
. That is, the appropriate string for which a call to classForName with the return value of this method would return clazz. Makes use of any configured aliases and search paths, and appropriately encodes array types.
-
classForName
public final java.lang.Class classForName(java.lang.String name) throws java.lang.ClassNotFoundException
Attempts to find the Class for the given name, in the context of any aliases and search paths that have been previously configuredLogic is as follows:
- Look through the aliases for the given name. These can be configured manually (see
addAlias(Class, String)
), and will also be added automatically to act as a cache of any of the following steps find the class. - If the name starts with a "[", get call classForName recursively on name.substring(1) to
find the array component type, and then find the array class using
Array.newInstance(Class, int)
- Try Class.forName(name)
- Look through each search path (see
addSearchPath(String)
, looking for Class.forName(searchPath + "." + name)
- Throws:
java.lang.ClassNotFoundException
- Look through the aliases for the given name. These can be configured manually (see
-
classForNameImpl
protected java.lang.Class classForNameImpl(java.lang.String name) throws java.lang.ClassNotFoundException
- Throws:
java.lang.ClassNotFoundException
-
-