Class PlexusXmlBeanConverter

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static java.lang.String CONVERSION_ERROR  
      private java.util.Collection<com.google.inject.spi.TypeConverterBinding> typeConverterBindings  
    • Constructor Summary

      Constructors 
      Constructor Description
      PlexusXmlBeanConverter​(com.google.inject.Injector injector)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object convert​(com.google.inject.TypeLiteral role, java.lang.String value)
      Converts the given constant value to a bean of the given type.
      private java.lang.Object convertText​(java.lang.String value, com.google.inject.TypeLiteral<?> toType)
      Converts the given string to the target type, using TypeConverters registered with the Injector.
      private static java.lang.Class<?> loadImplementation​(java.lang.String name, java.lang.Class<?> defaultClazz)
      Attempts to load the named implementation, uses default implementation if no name is given.
      private static <T> T newImplementation​(java.lang.Class<T> clazz)
      Creates an instance of the given implementation using the default constructor.
      private static <T> T newImplementation​(java.lang.Class<T> clazz, java.lang.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, java.lang.Class<T> defaultClazz)
      Creates an instance of the implementation named in the current XML element, or the default if no name is given.
      private java.lang.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 java.lang.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 java.lang.Object parseBean​(org.codehaus.plexus.util.xml.pull.MXParser parser, com.google.inject.TypeLiteral<?> toType, java.lang.Class<?> rawType)
      Parses a sequence of XML elements and converts them to the appropriate bean type.
      private java.util.Collection<java.lang.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 appropriate Collection type.
      private static java.lang.String parseImplementation​(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)
      Parses an XML element looking for the name of a custom implementation.
      private java.util.Map<java.lang.String,​java.lang.Object> 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 appropriate Map type.
      private static java.util.Properties parseProperties​(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)
      Parses a sequence of XML elements and converts them to the appropriate Properties 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 the Xpp3Dom type.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CONVERSION_ERROR

        private static final java.lang.String CONVERSION_ERROR
        See Also:
        Constant Field Values
      • typeConverterBindings

        private final java.util.Collection<com.google.inject.spi.TypeConverterBinding> typeConverterBindings
    • Constructor Detail

      • PlexusXmlBeanConverter

        @Inject
        PlexusXmlBeanConverter​(com.google.inject.Injector injector)
    • Method Detail

      • convert

        public java.lang.Object convert​(com.google.inject.TypeLiteral role,
                                        java.lang.String value)
        Description copied from interface: PlexusBeanConverter
        Converts the given constant value to a bean of the given type.
        Specified by:
        convert in interface PlexusBeanConverter
        Parameters:
        role - The expected bean type
        value - The constant value
        Returns:
        Bean of the given type, based on the given constant value
      • parse

        private java.lang.Object parse​(org.codehaus.plexus.util.xml.pull.MXParser parser,
                                       com.google.inject.TypeLiteral<?> toType)
                                throws java.lang.Exception
        Parses a sequence of XML elements and converts them to the given target type.
        Parameters:
        parser - The XML parser
        toType - The target type
        Returns:
        Converted instance of the target type
        Throws:
        java.lang.Exception
      • parseXpp3Dom

        private static org.codehaus.plexus.util.xml.Xpp3Dom parseXpp3Dom​(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)
                                                                  throws java.lang.Exception
        Parses an XML subtree and converts it to the Xpp3Dom type.
        Parameters:
        parser - The XML parser
        Returns:
        Converted Xpp3Dom instance
        Throws:
        java.lang.Exception
      • parseProperties

        private static java.util.Properties parseProperties​(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)
                                                     throws java.lang.Exception
        Parses a sequence of XML elements and converts them to the appropriate Properties type.
        Parameters:
        parser - The XML parser
        Returns:
        Converted Properties instance
        Throws:
        java.lang.Exception
      • parseMap

        private java.util.Map<java.lang.String,​java.lang.Object> parseMap​(org.codehaus.plexus.util.xml.pull.MXParser parser,
                                                                                com.google.inject.TypeLiteral<?> toType)
                                                                         throws java.lang.Exception
        Parses a sequence of XML elements and converts them to the appropriate Map type.
        Parameters:
        parser - The XML parser
        Returns:
        Converted Map instance
        Throws:
        java.lang.Exception
      • parseCollection

        private java.util.Collection<java.lang.Object> parseCollection​(org.codehaus.plexus.util.xml.pull.MXParser parser,
                                                                       com.google.inject.TypeLiteral<?> toType)
                                                                throws java.lang.Exception
        Parses a sequence of XML elements and converts them to the appropriate Collection type.
        Parameters:
        parser - The XML parser
        Returns:
        Converted Collection instance
        Throws:
        java.lang.Exception
      • parseArray

        private java.lang.Object parseArray​(org.codehaus.plexus.util.xml.pull.MXParser parser,
                                            com.google.inject.TypeLiteral<?> toType)
                                     throws java.lang.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:
        java.lang.Exception
      • parseBean

        private java.lang.Object parseBean​(org.codehaus.plexus.util.xml.pull.MXParser parser,
                                           com.google.inject.TypeLiteral<?> toType,
                                           java.lang.Class<?> rawType)
                                    throws java.lang.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:
        java.lang.Exception
      • parseImplementation

        private static java.lang.String parseImplementation​(org.codehaus.plexus.util.xml.pull.XmlPullParser parser)
        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

        private static java.lang.Class<?> loadImplementation​(java.lang.String name,
                                                             java.lang.Class<?> defaultClazz)
        Attempts to load the named implementation, uses default implementation if no name is given.
        Parameters:
        name - The optional implementation name
        defaultClazz - The default implementation type
        Returns:
        Custom implementation type if one was given; otherwise default implementation type
      • newImplementation

        private static <T> T newImplementation​(java.lang.Class<T> clazz)
        Creates an instance of the given implementation using the default constructor.
        Parameters:
        clazz - The implementation type
        Returns:
        Instance of given implementation
      • newImplementation

        private static <T> T newImplementation​(java.lang.Class<T> clazz,
                                               java.lang.String value)
        Creates an instance of the given implementation using the given string, assumes a public string constructor.
        Parameters:
        clazz - The implementation type
        value - 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,
                                               java.lang.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 parser
        defaultClazz - The default implementation type
        Returns:
        Instance of custom implementation if one was given; otherwise instance of default type
      • convertText

        private java.lang.Object convertText​(java.lang.String value,
                                             com.google.inject.TypeLiteral<?> toType)
        Converts the given string to the target type, using TypeConverters registered with the Injector.
        Parameters:
        value - The string value
        toType - The target type
        Returns:
        Converted instance of the target type