Class CodecManager
registerCodec(Class)
or registerAllDeclaredCodecs(). You can then ask the codec manager
to construct new codec objects for you, using the getInputCodecFor... and
getOutputCodecFor... methods.While you can always instantiate your own codec classes yourself, the recommended way to dealing with codec classes is through a codec manager. This separates the world of codecs from the rest of the system, offers a uniform interface to all codecs, and deals with the codec metadata annotations correctly. In other words, we encourage you to never instantiate a codec class yourself, but use a codec manager for it.
- Author:
- Alexander Koller
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPrints an overview of all registered codecs to an output stream.Returns the list of all registered input codecs.Returns the list of all registered output codecs that support the output of multiple solved forms into one file.Returns the list of all registered output codecs.getInputCodecExtension(String codecname) getInputCodecForFilename(String filename, String options) Constructs an input codec object for the input codec associated with the given filename (extension).getInputCodecForFilename(String filename, Map<String, String> options) Constructs an input codec object for the input codec associated with the given filename (extension).getInputCodecForName(String codecname, String options) Constructs an input codec object for the input codec with the given name.getInputCodecForName(String codecname, Map<String, String> options) Constructs an input codec object for the input codec with the given name.getInputCodecNameForFilename(String filename) Figure out the name of the input codec for the given filename.getInputCodecOptionTypes(String codecname) Computes a map representing the parameter types of the constructor of an input codec.getInputCodecParameterDefaultValue(String codecname, String parametername) Returns the default value for a codec parameter of an input codec.getName(InputCodec codec) getName(OutputCodec codec) getOutputCodecExtension(String codecname) getOutputCodecForFilename(String filename, String options) Constructs an output codec object for the output codec associated with the given filename (extension).getOutputCodecForFilename(String filename, Map<String, String> options) Constructs an output codec object for the output codec associated with the given filename (extension).getOutputCodecForName(String codecname, String options) Constructs an output codec object for the output codec with the given name.getOutputCodecForName(String codecname, Map<String, String> options) Constructs an output codec object for the output codec with the given name.getOutputCodecNameForFilename(String filename) Figure out the name of the output codec for the given filename.getOutputCodecOptionTypes(String codecname) Computes a map representing the parameter types of the constructor of an output codec.getOutputCodecParameterDefaultValue(String codecname, String parametername) Returns the default value for a codec parameter of an output codec.booleanisExperimentalInputCodec(String codecname) Determines whether or not an input codec has the status "EXPERIMENTAL".booleanisExperimentalOutputCodec(String codecname) Determines whether or not an output codec has the status "EXPERIMENTAL".booleanisMultiOutputCodec(String codecname) Determines whether or not an output codec supports the output of multiple solved forms into one file.voidRegisters all codecs which are declared in acodecclasses.propertiesfile.voidregisterCodec(Class codecClass) Registers a codec.voidsetAllowExperimentalCodecs(boolean val) stringToValue(String valueAsString, Class asClass) Converts a string representation of a datatype that is admissible as the type of a codec option into that type.
-
Constructor Details
-
CodecManager
public CodecManager()
-
-
Method Details
-
setAllowExperimentalCodecs
public void setAllowExperimentalCodecs(boolean val) -
getName
-
getName
-
getInputCodecOptionTypes
Computes a map representing the parameter types of the constructor of an input codec. The key of each entry is the name of the parameter, as specified in its CodecOption annotation; its value is the class of this parameter. The class may be any primitive type except forvoidandchar, the classString, or any enumeration class. Use this method to query the user for a string value for each parameter. You can then collect these values in a map that assigns (String) values to parameter names, and use this map to construct a new input codec object using the methodgetInputCodecForName(String, Map).- Parameters:
codecname- the name of the input codec whose parameter types you want- Returns:
- a map that assigns to each parameter name, the type of this parameter
-
getOutputCodecOptionTypes
Computes a map representing the parameter types of the constructor of an output codec. The key of each entry is the name of the parameter, as specified in its CodecOption annotation; its value is the class of this parameter. The class may be any primitive type except forvoidandchar, the classString, or any enumeration class. Use this method to query the user for a string value for each parameter. You can then collect these values in a map that assigns (String) values to parameter names, and use this map to construct a new output codec object using the methodgetOutputCodecForName(String, Map).- Parameters:
codecname- the name of the output codec whose parameter types you want- Returns:
- a map that assigns to each parameter name, the type of this parameter
-
getOutputCodecParameterDefaultValue
Returns the default value for a codec parameter of an output codec. The default value is encoded as a string and can be decoded e.g. usingstringToValue(String, Class).- Parameters:
codecname- the name of an output codecparametername- the name of a parameter of this codec's codec constructor, as specified in its CodecOption annotation- Returns:
- the default value of this parameter, or
nullif there is no output codec with this name, or its codec constructor doesn't have a parameter of this name. If you didn't specify a default value for the parameter, the system assumes a default value of "" (the empty string).
-
getInputCodecParameterDefaultValue
Returns the default value for a codec parameter of an input codec. The default value is encoded as a string and can be decoded e.g. usingstringToValue(String, Class).- Parameters:
codecname- the name of an input codecparametername- the name of a parameter of this codec's codec constructor, as specified in its CodecOption annotation- Returns:
- the default value of this parameter, or
nullif there is no input codec with this name, or its codec constructor doesn't have a parameter of this name. If you didn't specify a default value for the parameter, the system assumes a default value of "" (the empty string).
-
stringToValue
Converts a string representation of a datatype that is admissible as the type of a codec option into that type. For instance, it will convert the string "false" into the Boolean object for the value "false".Admissible datatypes (i.e., values for the
asClassparameter are: all wrapper classes for the primitive datatypes, except for void and char; all enum types; and the datatypeString.- Parameters:
valueAsString- the value, encoded as a stringasClass- the datatype into which the value should be converted- Returns:
- an object of the type
asClasswith the value corresponding to the first parameter, ornullif the value could not be converted or the datatype is unsupported.
-
registerCodec
Registers a codec. Pass a codec class (not object) as the argument. This class must be a subclass either ofInputCodecor ofOutputCodec, and is filed under the input or output codecs accordingly.Apart from the subclass requirement, a codec class must obey the following rules:
- It is a class that can be instantiated, i.e. not an abstract class or an interface.
- It has a
CodecMetadataannotation. - It has at least one public constructor. If it has more than one
public constructor, then exactly one public constructor must have a
CodecConstructorannotation. We will the unique public constructor or the unique annotated public constructor the "codec constructor" below. - The codec constructor must not declare to throw any checked exceptions.
- All parameters of the codec constructor must have a
CodecOptionannotation and must be of a primitive type (but notvoidorchar), an enumeration type, or the classString.
- Parameters:
codecClass- a codec class- Throws:
CodecRegistrationException- if the class violates any of the rules specified above.
-
getInputCodecForName
Constructs an input codec object for the input codec with the given name.- Parameters:
codecname- the name of a registered input codecoptions- an options string which is passed to the new codec- Returns:
- an object of this codec class, or null if no codec with this name was registered.
-
getInputCodecForFilename
Constructs an input codec object for the input codec associated with the given filename (extension).- Parameters:
filename- the filename for which we need a codecoptions- an options string which is passed to the new codec- Returns:
- an object of this codec class, or null if no codec is associated with this filename extension
-
getOutputCodecForName
Constructs an output codec object for the output codec with the given name.- Parameters:
codecname- the name of a registered output codecoptions- an options string which is passed to the new codec- Returns:
- an object of this codec class, or null if no codec with this name was registered.
-
getOutputCodecForFilename
Constructs an output codec object for the output codec associated with the given filename (extension).- Parameters:
filename- the filename for which we need a codecoptions- an options string which is passed to the new codec- Returns:
- an object of this codec class, or null if no codec is associated with this filename extension
-
getInputCodecForName
Constructs an input codec object for the input codec with the given name.- Parameters:
codecname- the name of a registered input codecoptions- a map that assigns values to parameter names of the codec class- Returns:
- an object of this codec class, or null if no codec with this name was registered.
-
getInputCodecForFilename
Constructs an input codec object for the input codec associated with the given filename (extension).- Parameters:
filename- the filename for which we need a codecoptions- a map that assigns values to parameter names of the codec class- Returns:
- an object of this codec class, or null if no codec is associated with this filename extension
-
getOutputCodecForName
Constructs an output codec object for the output codec with the given name.- Parameters:
codecname- the name of a registered output codecoptions- a map that assigns values to parameter names of the codec class- Returns:
- an object of this codec class, or null if no codec with this name was registered.
-
getOutputCodecForFilename
Constructs an output codec object for the output codec associated with the given filename (extension).- Parameters:
filename- the filename for which we need a codecoptions- a map that assigns values to parameter names of the codec class- Returns:
- an object of this codec class, or null if no codec is associated with this filename extension
-
displayAllCodecs
Prints an overview of all registered codecs to an output stream.- Parameters:
out- the output stream to which the overview should be printed.
-
getOutputCodecNameForFilename
Figure out the name of the output codec for the given filename.- Parameters:
filename-- Returns:
- the name of the output codec, or null if no codec is associated with this filename.
-
getInputCodecNameForFilename
Figure out the name of the input codec for the given filename.- Parameters:
filename-- Returns:
- the name of the input codec, or null if no codec is associated with this filename.
-
isExperimentalInputCodec
Determines whether or not an input codec has the status "EXPERIMENTAL". If the codecname does not exist or is no input codec, false is returned.- Parameters:
codecname- the codec's String representation- Returns:
- true if the codec is experimental
-
isExperimentalOutputCodec
Determines whether or not an output codec has the status "EXPERIMENTAL". If the codecname does not exist or is no output codec, false is returned.- Parameters:
codecname- the codec's String representation- Returns:
- true if the codec is experimental
-
isMultiOutputCodec
Determines whether or not an output codec supports the output of multiple solved forms into one file. If the codecname does not exist or is no output codec, false is returned.- Parameters:
codecname- the codec's String representation- Returns:
- true if the codec allows the output of multiple solved forms
-
getAllInputCodecs
Returns the list of all registered input codecs.- Returns:
- the names of all input codecs
-
getAllInputCodecExtensions
-
getAllOutputCodecExtensions
-
getAllOutputCodecs
Returns the list of all registered output codecs.- Returns:
- the names of all output codecs
-
getAllMultiOutputCodecs
Returns the list of all registered output codecs that support the output of multiple solved forms into one file.- Returns:
- the list of all such output codecs
-
registerAllDeclaredCodecs
Registers all codecs which are declared in acodecclasses.propertiesfile. This file is assumed to contain the names of codec classes, one per line; all these classes will be registered as codecs in this codec manager.The method looks for the codecclasses file in the directory
de/saar/chorus/domgraph/codecbelow the classpath. If there is more than one file with this pathname on the class path, this method will process each of these files in turn, i.e. the codecs of all files will be registered. This is designed to make it easy to codec developers to write their own codecs and use them from utool/domgraph without having to recompile the domgraph code.Each codec that is registered using this method is still subject to the rules laid out in the documentation of
registerCodec(Class).- Throws:
CodecRegistrationException- if an error occurred while trying to register any of the listed codec classes. This happens when either an I/O error occurred, one of the class names could not be resolved to a class, or one of the classes is not a valid codec.
-
getInputCodecExtension
-
getOutputCodecExtension
-