Package org.eclipse.sisu.plexus
Class PlexusXmlBeanConverter
java.lang.Object
org.eclipse.sisu.plexus.PlexusXmlBeanConverter
- All Implemented Interfaces:
PlexusBeanConverter
PlexusBeanConverter
Module
that converts Plexus XML configuration into beans.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final String
private final Collection<com.google.inject.spi.TypeConverterBinding>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionConverts the given constant value to a bean of the given type.private Object
convertText
(String value, com.google.inject.TypeLiteral<?> toType) Converts the given string to the target type, usingTypeConverter
s registered with theInjector
.private static Class<?>
loadImplementation
(String name, Class<?> defaultClazz) Attempts to load the named implementation, uses default implementation if no name is given.private static <T> T
newImplementation
(Class<T> clazz) Creates an instance of the given implementation using the default constructor.private static <T> T
newImplementation
(Class<T> clazz, String value) Creates an instance of the given implementation using the given string, assumes a public string constructor.private static <T> T
newImplementation
(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Class<T> defaultClazz) Creates an instance of the implementation named in the current XML element, or the default if no name is given.private Object
parse
(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType) Parses a sequence of XML elements and converts them to the given target type.private Object
parseArray
(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType) Parses a sequence of XML elements and converts them to the appropriate array type.private Object
parseBean
(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType, Class<?> rawType) Parses a sequence of XML elements and converts them to the appropriate bean type.private Collection<Object>
parseCollection
(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType) Parses a sequence of XML elements and converts them to the appropriateCollection
type.private static String
parseImplementation
(org.codehaus.plexus.util.xml.pull.XmlPullParser parser) Parses an XML element looking for the name of a custom implementation.parseMap
(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType) Parses a sequence of XML elements and converts them to the appropriateMap
type.private static Properties
parseProperties
(org.codehaus.plexus.util.xml.pull.XmlPullParser parser) Parses a sequence of XML elements and converts them to the appropriateProperties
type.private static org.codehaus.plexus.util.xml.Xpp3Dom
parseXpp3Dom
(org.codehaus.plexus.util.xml.pull.XmlPullParser parser) Parses an XML subtree and converts it to theXpp3Dom
type.
-
Field Details
-
CONVERSION_ERROR
- See Also:
-
typeConverterBindings
-
-
Constructor Details
-
PlexusXmlBeanConverter
@Inject PlexusXmlBeanConverter(com.google.inject.Injector injector)
-
-
Method Details
-
convert
Description copied from interface:PlexusBeanConverter
Converts the given constant value to a bean of the given type.- Specified by:
convert
in interfacePlexusBeanConverter
- Parameters:
role
- The expected bean typevalue
- The constant value- Returns:
- Bean of the given type, based on the given constant value
-
parse
private Object parse(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType) throws Exception Parses a sequence of XML elements and converts them to the given target type.- Parameters:
parser
- The XML parsertoType
- The target type- Returns:
- Converted instance of the target type
- Throws:
Exception
-
parseXpp3Dom
private static org.codehaus.plexus.util.xml.Xpp3Dom parseXpp3Dom(org.codehaus.plexus.util.xml.pull.XmlPullParser parser) throws Exception Parses an XML subtree and converts it to theXpp3Dom
type.- Parameters:
parser
- The XML parser- Returns:
- Converted Xpp3Dom instance
- Throws:
Exception
-
parseProperties
private static Properties parseProperties(org.codehaus.plexus.util.xml.pull.XmlPullParser parser) throws Exception Parses a sequence of XML elements and converts them to the appropriateProperties
type.- Parameters:
parser
- The XML parser- Returns:
- Converted Properties instance
- Throws:
Exception
-
parseMap
private Map<String,Object> parseMap(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType) throws Exception Parses a sequence of XML elements and converts them to the appropriateMap
type.- Parameters:
parser
- The XML parser- Returns:
- Converted Map instance
- Throws:
Exception
-
parseCollection
private Collection<Object> parseCollection(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType) throws Exception Parses a sequence of XML elements and converts them to the appropriateCollection
type.- Parameters:
parser
- The XML parser- Returns:
- Converted Collection instance
- Throws:
Exception
-
parseArray
private Object parseArray(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType) throws Exception Parses a sequence of XML elements and converts them to the appropriate array type.- Parameters:
parser
- The XML parser- Returns:
- Converted array instance
- Throws:
Exception
-
parseBean
private Object parseBean(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType, Class<?> rawType) throws Exception Parses a sequence of XML elements and converts them to the appropriate bean type.- Parameters:
parser
- The XML parser- Returns:
- Converted bean instance
- Throws:
Exception
-
parseImplementation
Parses an XML element looking for the name of a custom implementation.- Parameters:
parser
- The XML parser- Returns:
- Name of the custom implementation; otherwise
null
-
loadImplementation
Attempts to load the named implementation, uses default implementation if no name is given.- Parameters:
name
- The optional implementation namedefaultClazz
- The default implementation type- Returns:
- Custom implementation type if one was given; otherwise default implementation type
-
newImplementation
Creates an instance of the given implementation using the default constructor.- Parameters:
clazz
- The implementation type- Returns:
- Instance of given implementation
-
newImplementation
Creates an instance of the given implementation using the given string, assumes a public string constructor.- Parameters:
clazz
- The implementation typevalue
- The string argument- Returns:
- Instance of given implementation, constructed using the the given string
-
newImplementation
private static <T> T newImplementation(org.codehaus.plexus.util.xml.pull.XmlPullParser parser, Class<T> defaultClazz) Creates an instance of the implementation named in the current XML element, or the default if no name is given.- Parameters:
parser
- The XML parserdefaultClazz
- The default implementation type- Returns:
- Instance of custom implementation if one was given; otherwise instance of default type
-
convertText
Converts the given string to the target type, usingTypeConverter
s registered with theInjector
.- Parameters:
value
- The string valuetoType
- The target type- Returns:
- Converted instance of the target type
-