Class ServiceUtil

  • All Implemented Interfaces:
    Constants

    public final class ServiceUtil
    extends java.lang.Object
    implements Constants
    Core utility methods that support Abdera's internal operation
    • Method Detail

      • newInstance

        public static java.lang.Object newInstance​(java.lang.String id,
                                                   java.lang.String _default,
                                                   Abdera abdera)
        Returns a new instance of the identified object class. This will use the Abdera configuration mechanism to look up the implementation class for the specified id. Several places will be checked: the abdera.properties file, the /META-INF/services directory, and the System properties. If no instance is configured, the default class name will be used. Returns null if no instance can be created.
      • newInstance

        public static java.lang.Object newInstance​(java.lang.String id,
                                                   java.lang.String _default,
                                                   Abdera abdera,
                                                   java.lang.Object... args)
        Returns a new instance of the identified object class. This will use the Abdera configuration mechanism to look up the implementation class for the specified id. Several places will be checked: the abdera.properties file, the /META-INF/services directory, and the System properties. If no instance is configured, the default class name will be used. Returns null if no instance can be created.
      • newXPathInstance

        public static XPath newXPathInstance​(Abdera abdera)
        Utility method for returning an instance of the default Abdera XPath instance
      • newParserInstance

        public static org.apache.abdera.parser.Parser newParserInstance​(Abdera abdera)
        Utility method for returning an instance of the default Abdera Parser instance
      • newFactoryInstance

        public static Factory newFactoryInstance​(Abdera abdera)
        Utility method for returning an instance of the defaul Abdera Factory instance
      • newParserFactoryInstance

        public static org.apache.abdera.parser.ParserFactory newParserFactoryInstance​(Abdera abdera)
      • newWriterFactoryInstance

        public static WriterFactory newWriterFactoryInstance​(Abdera abdera)
      • newWriterInstance

        public static Writer newWriterInstance​(Abdera abdera)
      • newStreamWriterInstance

        public static StreamWriter newStreamWriterInstance​(Abdera abdera)
      • locate

        public static java.lang.Object locate​(java.lang.String id,
                                              java.lang.String _default,
                                              Abdera abdera)
      • locate

        public static java.lang.Object locate​(java.lang.String id,
                                              java.lang.String _default,
                                              Abdera abdera,
                                              java.lang.Object... args)
      • locate

        public static java.lang.Object locate​(java.lang.String id,
                                              Abdera abdera)
        Locate a class instance for the given id
      • locateInstance

        public static java.lang.Object locateInstance​(java.lang.String id,
                                                      Abdera abdera)
      • locateInstance

        public static java.lang.Object locateInstance​(java.lang.String id,
                                                      Abdera abdera,
                                                      boolean classesonly)
      • locateInstance

        public static java.lang.Object locateInstance​(java.lang.String id,
                                                      Abdera abdera,
                                                      java.lang.Object... args)
      • locateStream

        public static java.io.InputStream locateStream​(java.lang.String id)
      • locateResources

        public static java.util.Enumeration<java.net.URL> locateResources​(java.lang.String id)
      • loadimpls

        public static <T> java.util.List<T> loadimpls​(java.lang.String sid)
      • loadimpls

        public static <T> java.util.List<T> loadimpls​(java.lang.String sid,
                                                      boolean classesonly)
      • getResource

        public static java.net.URL getResource​(java.lang.String resourceName,
                                               java.lang.Class<?> callingClass)
        Load a given resource.

        This method will try to load the resource using the following methods (in order):

        • From Thread.currentThread().getContextClassLoader()
        • From ClassLoaderUtil.class.getClassLoader()
        • callingClass.getClassLoader()
        Parameters:
        resourceName - The name of the resource to load
        callingClass - The Class object of the calling object
      • getResources

        public static java.util.Enumeration<java.net.URL> getResources​(java.lang.String resourceName,
                                                                       java.lang.Class<?> callingClass)
                                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • getResourceAsStream

        public static java.io.InputStream getResourceAsStream​(java.lang.String resourceName,
                                                              java.lang.Class<?> callingClass)
        This is a convenience method to load a resource as a stream.

        The algorithm used to find the resource is given in getResource()

        Parameters:
        resourceName - The name of the resource to load
        callingClass - The Class object of the calling object
      • loadClass

        public static java.lang.Class<?> loadClass​(java.lang.String className,
                                                   java.lang.Class<?> callingClass)
                                            throws java.lang.ClassNotFoundException
        Load a class with a given name.

        It will try to load the class in the following order:

        • From Thread.currentThread().getContextClassLoader()
        • Using the basic Class.forName()
        • From ClassLoaderUtil.class.getClassLoader()
        • From the callingClass.getClassLoader()
        Parameters:
        className - The name of the class to load
        callingClass - The Class object of the calling object
        Throws:
        java.lang.ClassNotFoundException - If the class cannot be found anywhere.