abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r772417 - in /abdera/java/trunk: client/src/main/java/org/apache/abdera/protocol/client/ core/src/main/java/org/apache/abdera/factory/ core/src/main/java/org/apache/abdera/util/ parser/src/main/java/org/apache/abdera/parser/stax/ parser/src...
Date Wed, 06 May 2009 20:36:22 GMT
Author: jmsnell
Date: Wed May  6 20:36:21 2009
New Revision: 772417

URL: http://svn.apache.org/viewvc?rev=772417&view=rev
Log:
Refactoring of some of the base level class discovery code. The moves things to a more logical location, improves the reliability of the implementation and simplifies the code structure a bit.

Added:
    abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Discover.java
    abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MultiIterator.java
Modified:
    abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
    abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/StreamBuilder.java
    abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaConfiguration.java
    abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java
    abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Constants.java
    abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java
    abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java
    abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
    abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
    abdera/java/trunk/security/src/main/java/org/apache/abdera/security/AbderaSecurity.java
    abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java

Modified: abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java (original)
+++ abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java Wed May  6 20:36:21 2009
@@ -49,8 +49,8 @@
 import org.apache.abdera.protocol.error.Error;
 import org.apache.abdera.protocol.error.ProtocolException;
 import org.apache.abdera.protocol.util.CacheControlUtil;
+import org.apache.abdera.util.Discover;
 import org.apache.abdera.util.EntityTag;
-import org.apache.abdera.util.ServiceUtil;
 import org.apache.abdera.util.Version;
 import org.apache.commons.httpclient.Cookie;
 import org.apache.commons.httpclient.Credentials;
@@ -154,7 +154,7 @@
 
   private CacheFactory initCacheFactory() {
     CacheFactory cacheFactory = 
-      (CacheFactory)ServiceUtil.newInstance(
+      (CacheFactory)Discover.locate(
         CacheFactory.class.getName(),
         LRUCacheFactory.class.getName(), 
         abdera);

Modified: abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/StreamBuilder.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/StreamBuilder.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/StreamBuilder.java (original)
+++ abdera/java/trunk/core/src/main/java/org/apache/abdera/factory/StreamBuilder.java Wed May  6 20:36:21 2009
@@ -74,7 +74,7 @@
   }
   
   public StreamBuilder(Abdera abdera) {
-    super("fom");
+    super(abdera,"fom");
     this.abdera = abdera;
   }
 

Modified: abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaConfiguration.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaConfiguration.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaConfiguration.java (original)
+++ abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbderaConfiguration.java Wed May  6 20:36:21 2009
@@ -19,6 +19,7 @@
 
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
+import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
@@ -96,12 +97,22 @@
     this.bundle = (bundle != null) ? bundle : 
       AbderaConfiguration.getBundle( 
         Locale.getDefault());
-    factories = ServiceUtil.loadExtensionFactories();
+    factories = loadExtensionFactories();
     writers = initNamedWriters();
     parsers = initNamedParsers();
     streamwriters = initStreamWriters();
   }  
   
+  private static synchronized List<ExtensionFactory> loadExtensionFactories() {
+    List<ExtensionFactory> list = 
+      new ArrayList<ExtensionFactory>();
+    Iterable<ExtensionFactory> factories =
+      Discover.locate("org.apache.abdera.factory.ExtensionFactory");
+    for (ExtensionFactory factory : factories)
+      list.add(factory);
+    return list;
+  }
+  
   private ResourceBundle getBundle() {
     return bundle;
   }
@@ -173,8 +184,8 @@
    */
   private Map<String,NamedWriter> initNamedWriters() {
     Map<String,NamedWriter> writers = null;
-    List<NamedWriter> _writers = 
-      ServiceUtil._loadimpls(NAMED_WRITER);
+    Iterable<NamedWriter> _writers = 
+      Discover.locate(NAMED_WRITER);
     writers = Collections.synchronizedMap(new HashMap<String,NamedWriter>());
     for (NamedWriter writer : _writers) {
       writers.put(writer.getName().toLowerCase(), writer);
@@ -188,8 +199,8 @@
    */
   private Map<String,Class<? extends StreamWriter>> initStreamWriters() {
     Map<String,Class<? extends StreamWriter>> writers = null;
-    List<Class<? extends StreamWriter>> _writers = 
-      ServiceUtil._loadimpls(STREAM_WRITER,true);
+    Iterable<Class<? extends StreamWriter>> _writers =
+      Discover.locate(STREAM_WRITER, true);
     writers = Collections.synchronizedMap(new HashMap<String,Class<? extends StreamWriter>>());
     for (Class<? extends StreamWriter> writer : _writers) {
       String name = getName(writer);
@@ -258,7 +269,7 @@
    */
   private Map<String,NamedParser> initNamedParsers() {
     Map<String,NamedParser> parsers = null;
-    List<NamedParser> _parsers = ServiceUtil._loadimpls(NAMED_PARSER);
+    Iterable<NamedParser> _parsers = Discover.locate(NAMED_PARSER);
     parsers = Collections.synchronizedMap(new HashMap<String,NamedParser>());
     for (NamedParser parser : _parsers) {
       parsers.put(parser.getName().toLowerCase(), parser);
@@ -287,8 +298,16 @@
    * 
    * @return A new factory instance
    */
-  public Factory newFactoryInstance(Abdera abdera) {
-    return ServiceUtil.newFactoryInstance(abdera);
+  public Factory newFactoryInstance(
+    Abdera abdera) {
+      return (Factory) Discover.locate(
+          CONFIG_FACTORY, 
+          abdera
+            .getConfiguration()
+            .getConfigurationOption(
+              CONFIG_FACTORY, 
+              DEFAULT_FACTORY),
+          abdera);
   }
     
   /**
@@ -296,8 +315,16 @@
    * 
    * @return A new parser instance
    */
-  public Parser newParserInstance(Abdera abdera) {
-    return ServiceUtil.newParserInstance(abdera);
+  public Parser newParserInstance(
+    Abdera abdera) {
+      return (Parser) Discover.locate(
+          CONFIG_PARSER, 
+          abdera
+            .getConfiguration()
+            .getConfigurationOption(
+              CONFIG_PARSER, 
+              DEFAULT_PARSER),
+          abdera);
   }
     
   /**
@@ -305,12 +332,22 @@
    * 
    * @return A new XPath instance
    */
-  public XPath newXPathInstance(Abdera abdera) {
-    try {
-      return ServiceUtil.newXPathInstance(abdera);
-    } catch (NoClassDefFoundError n) {
-      throw new RuntimeException(Localizer.sprintf("IMPLEMENTATION.NOT.AVAILABLE","XPath"),n);
-    }
+  public XPath newXPathInstance(
+    Abdera abdera) {
+      try {
+        return (XPath) Discover.locate(
+            CONFIG_XPATH,
+            abdera
+              .getConfiguration()
+              .getConfigurationOption(
+                CONFIG_XPATH, 
+                DEFAULT_XPATH), 
+            abdera);
+      } catch (Throwable n) {
+        throw throwex(
+          "IMPLEMENTATION.NOT.AVAILABLE",
+          "XPath",n);
+      }
   }
     
   /**
@@ -318,12 +355,22 @@
    * 
    * @return A new ParserFactory instance
    */
-  public ParserFactory newParserFactoryInstance(Abdera abdera) {
-    try {
-      return ServiceUtil.newParserFactoryInstance(abdera);
-    } catch (NoClassDefFoundError n) {
-      throw new RuntimeException(Localizer.sprintf("IMPLEMENTATION.NOT.AVAILABLE","Parser"),n);
-    }
+  public ParserFactory newParserFactoryInstance(
+    Abdera abdera) {
+      try {
+        return (ParserFactory) Discover.locate(
+            CONFIG_PARSERFACTORY,
+            abdera
+              .getConfiguration()
+              .getConfigurationOption(
+                CONFIG_PARSERFACTORY, 
+                DEFAULT_PARSERFACTORY),
+            abdera);
+      } catch (Throwable n) {
+        throw throwex(
+          "IMPLEMENTATION.NOT.AVAILABLE",
+          "Parser",n);
+      }
   }
     
   /**
@@ -331,12 +378,22 @@
    * 
    * @return A new WriterFactory instance
    */
-  public WriterFactory newWriterFactoryInstance(Abdera abdera) {
-    try {
-      return ServiceUtil.newWriterFactoryInstance(abdera);
-    } catch (NoClassDefFoundError n) {
-      throw new RuntimeException(Localizer.sprintf("IMPLEMENTATION.NOT.AVAILABLE","WriterFactory"),n);
-    }
+  public WriterFactory newWriterFactoryInstance(
+    Abdera abdera) {
+      try {
+        return (WriterFactory) Discover.locate(
+            CONFIG_WRITERFACTORY,
+            abdera
+              .getConfiguration()
+              .getConfigurationOption(
+                CONFIG_WRITERFACTORY, 
+                DEFAULT_WRITERFACTORY),
+            abdera) ;
+      } catch (Throwable n) {
+        throw throwex(
+          "IMPLEMENTATION.NOT.AVAILABLE",
+          "WriterFactory",n);
+      }
   }
     
   /**
@@ -344,12 +401,22 @@
    * 
    * @return A new default writer implementation instance
    */
-  public Writer newWriterInstance(Abdera abdera) {
-    try {
-      return ServiceUtil.newWriterInstance(abdera);
-    } catch (NoClassDefFoundError n) {
-      throw new RuntimeException(Localizer.sprintf("IMPLEMENTATION.NOT.AVAILABLE","Writer"),n);
-    }
+  public Writer newWriterInstance(
+    Abdera abdera) {
+      try {
+        return (Writer) Discover.locate(
+            CONFIG_WRITER,
+            abdera
+              .getConfiguration()
+              .getConfigurationOption(
+                CONFIG_WRITER, 
+                DEFAULT_WRITER),
+            abdera);
+      } catch (Throwable n) {
+        throw throwex(
+            "IMPLEMENTATION.NOT.AVAILABLE",
+            "Writer",n);
+      }
   }
   
   /**
@@ -357,12 +424,31 @@
    * 
    * @return A new default writer implementation instance
    */
-  public StreamWriter newStreamWriterInstance(Abdera abdera) {
-    try {
-      return ServiceUtil.newStreamWriterInstance(abdera);
-    } catch (NoClassDefFoundError n) {
-      throw new RuntimeException(Localizer.sprintf("IMPLEMENTATION.NOT.AVAILABLE","StreamWriter"),n);
-    }
+  public StreamWriter newStreamWriterInstance(
+    Abdera abdera) {
+      try {
+        return (StreamWriter) Discover.locate(
+            CONFIG_STREAMWRITER,
+            abdera
+              .getConfiguration()
+              .getConfigurationOption(
+                CONFIG_STREAMWRITER, 
+                DEFAULT_STREAMWRITER),
+            abdera);    
+      } catch (Throwable n) {
+        throw throwex(
+         "IMPLEMENTATION.NOT.AVAILABLE",
+         "StreamWriter",n);
+      }
   }  
 
+  private RuntimeException throwex(
+    String id, 
+    String arg, 
+    Throwable t) {
+      return new RuntimeException(
+        Localizer.sprintf(
+          id,arg),t);
+  }
+  
 }

Modified: abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java (original)
+++ abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java Wed May  6 20:36:21 2009
@@ -29,6 +29,7 @@
 import javax.activation.DataHandler;
 import javax.xml.namespace.QName;
 
+import org.apache.abdera.Abdera;
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.i18n.rfc4646.Lang;
 import org.apache.abdera.model.AtomDate;
@@ -41,13 +42,17 @@
 public abstract class AbstractStreamWriter 
   implements StreamWriter {
   
+  protected final Abdera abdera;
   protected final String name;
   protected boolean autoflush = false;
   protected boolean autoclose = false;
   protected boolean autoindent = false;
   
-  protected AbstractStreamWriter(String name) {
-    this.name = name;
+  protected AbstractStreamWriter(
+    Abdera abdera, 
+    String name) {
+      this.abdera = abdera;
+      this.name = name;
   }
   
   public StreamWriter setAutoflush(boolean auto) {

Modified: abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Constants.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Constants.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Constants.java (original)
+++ abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Constants.java Wed May  6 20:36:21 2009
@@ -35,9 +35,9 @@
   public static final String DEFAULT_WRITERFACTORY= "org.apache.abdera.parser.stax.FOMWriterFactory";
   public static final String DEFAULT_WRITER       = "org.apache.abdera.parser.stax.FOMWriter";
   public static final String DEFAULT_STREAMWRITER = "org.apache.abdera.parser.stax.StaxStreamWriter";
-  public static final String NAMED_WRITER         = "META-INF/services/org.apache.abdera.writer.NamedWriter";
-  public static final String NAMED_PARSER         = "META-INF/services/org.apache.abdera.parser.NamedParser";
-  public static final String STREAM_WRITER        = "META-INF/services/org.apache.abdera.writer.StreamWriter";
+  public static final String NAMED_WRITER         = "org.apache.abdera.writer.NamedWriter";
+  public static final String NAMED_PARSER         = "org.apache.abdera.parser.NamedParser";
+  public static final String STREAM_WRITER        = "org.apache.abdera.writer.StreamWriter";
   public static final String PREFIX               = "";
   public static final String APP_PREFIX           = "";
   public static final String CONTROL_PREFIX       = "";

Added: abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Discover.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Discover.java?rev=772417&view=auto
==============================================================================
--- abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Discover.java (added)
+++ abdera/java/trunk/core/src/main/java/org/apache/abdera/util/Discover.java Wed May  6 20:36:21 2009
@@ -0,0 +1,365 @@
+package org.apache.abdera.util;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+
+@SuppressWarnings("unchecked")
+public final class Discover {
+  
+  private Discover() {}
+
+  public static <T>T locate(
+    String id, 
+    String defaultImpl, 
+    Object... args) {
+      return locate(
+        id,
+        defaultImpl,
+        getLoader(),
+        args);
+  }
+  
+  public static <T>T locate(
+    String id, 
+    String defaultImpl, 
+    ClassLoader loader, 
+    Object... args) {
+      try {
+        T instance = null;
+        Iterable<T> items = 
+          locate(
+            id,
+            loader,
+            args);
+        for (T i : items) {
+          instance = i;
+          break;
+        }
+        if (instance == null) {
+          instance = 
+            load(
+              loader,
+              defaultImpl,
+              false,
+              args);
+        }
+        return instance;
+      } catch (Throwable t) {
+        throw new RuntimeException(t);
+      }
+  }
+  
+  private static ClassLoader getLoader() {
+    return Thread
+      .currentThread()
+      .getContextClassLoader();
+  }
+
+  public static <T>Iterable<T> locate(
+    String id, 
+    ClassLoader cl,
+    Object... args) {
+      return locate(id,false,cl,args);
+  }
+  
+  public static <T>Iterable<T> locate(
+    String id, 
+    boolean classesonly,
+    ClassLoader cl,
+    Object... args) {
+      return locate(
+        id,
+        classesonly,
+        new DefaultLoader<T>(id,classesonly,args,cl));
+  }
+
+  public static <T>Iterable<T> locate(
+    String id,
+    Object...args) {
+      return locate(id,false,args);
+  }
+  
+  public static <T>Iterable<T> locate(
+    String id,
+    boolean classesonly,
+    Object...args) {
+      return locate(
+        id,
+        new DefaultLoader<T>(id,classesonly,args));
+  }
+
+  public static <T>Iterable<T> locate(
+    String id,
+    Iterable<T> loader) {
+      List<T> impls = 
+        Collections.synchronizedList(
+          new ArrayList<T>());
+      try {
+        for (T instance : loader) {
+          if (instance != null)
+            impls.add(instance);
+        }
+      } catch (Throwable t) {
+        t.printStackTrace();
+      }
+      return impls;
+  }
+
+  public static class DefaultLoader<T> 
+    implements Iterable<T> {
+      protected final ClassLoader loader;
+      protected final String id;
+      protected final Iterator<T> iterator;
+      protected final Object[] args;
+      public DefaultLoader(
+        String id,
+        boolean classesonly,
+        Object[] args) {
+          this(
+            id,
+            classesonly,
+            args,
+            getLoader());
+      }
+      public DefaultLoader(
+        String id,
+        boolean classesonly,
+        Object[] args,
+        ClassLoader loader) {
+          this.loader = 
+            loader != null ? 
+              loader : 
+              getLoader();
+          this.id = id;
+          this.iterator= init(classesonly);
+          this.args = args;
+      }
+      private Iterator<T> init(boolean classesonly) {
+        try {
+          List<Iterator<T>> list = 
+            new ArrayList<Iterator<T>>();
+          Enumeration<URL> e = 
+            locateResources(
+              "META-INF/services/" + id,                                         //$NON-NLS-1$ 
+              loader, 
+              Discover.class);
+          while(e.hasMoreElements()) {
+            Iterator<T> i = 
+              new DefaultLoaderIterator<T>(
+                loader,
+                e.nextElement().openStream(),
+                classesonly,
+                args);
+            list.add(i);
+          }
+          return new MultiIterator<T>(list);
+        } catch (Throwable t) {
+          throw new RuntimeException(t);
+        }
+      }
+      public Iterator<T> iterator() {
+        return iterator;
+    }
+  }
+  
+  public static class DefaultLoaderIterator<T> 
+    extends LineReaderLoaderIterator<T> { 
+    public DefaultLoaderIterator(
+      ClassLoader cl,
+      InputStream in,
+      boolean classesonly,
+      Object[] args) {
+        super(cl,in,classesonly,args);
+    }
+    public T next() {
+      try {
+        if (!hasNext()) return null;
+        return create(read(),args);
+      } catch (Throwable t) {
+        return null;
+      }
+    } 
+    protected T create(String spec, Object[] args) {
+      try {
+        return load(cl,spec,classesonly,args);
+      } catch (RuntimeException e) {
+        throw e;
+      } catch (Throwable t) {
+        throw new RuntimeException(t);
+      }
+    }
+  }
+  
+  private static <T>T load(
+    ClassLoader loader, 
+    String spec, 
+    boolean classesonly,
+    Object[] args) 
+      throws Exception {
+    if (classesonly) {
+      return (T)getClass(loader,spec);
+    } else {
+      Class<T> _class = 
+        getClass(loader,spec);
+      Class<?>[] types = 
+        new Class<?>[args != null ? args.length : 0];
+      if (args != null) {
+        for (int n = 0; n < args.length; n++) {
+          types[n] = args[n].getClass();
+        }
+        return _class.getConstructor(types)
+          .newInstance(args);
+      } else {
+        return _class.newInstance();
+      }
+    }
+  }
+  
+  private static <T>Class<T> getClass(
+    ClassLoader loader, 
+    String spec) {
+    Class<T> c = null;
+      try {
+        c = (Class<T>) loader.loadClass(spec);
+        c = (Class<T>) (c != null ? c : 
+          getClass(Discover.class.getClassLoader(), spec));
+      } catch (ClassNotFoundException e) {
+        throw new RuntimeException(e);
+      }
+      return c;
+  }
+  
+  public static abstract class LineReaderLoaderIterator<T> 
+    extends LoaderIterator<T> {
+    private BufferedReader buf = null;
+    private String line = null;
+    protected final Object[] args;
+    protected final boolean classesonly;
+    protected LineReaderLoaderIterator(
+      ClassLoader cl, 
+      InputStream in,
+      boolean classesonly,
+      Object[] args) {
+        super(cl);
+        this.args = args;
+        this.classesonly = classesonly;
+        try {
+          InputStreamReader reader = new InputStreamReader(in);
+          buf = new BufferedReader(reader);
+          line = readNext();
+        } catch (Throwable t) {
+          throw new RuntimeException(t);
+        }
+    }
+    public boolean hasNext() {
+      return line != null;
+    }
+    protected String readNext() {
+      try {
+        String line = null;
+        while((line = buf.readLine()) != null) {
+          line = line.trim();
+          if (!line.startsWith("#")) break;                                      //$NON-NLS-1$
+        }
+        return line;
+      } catch (Throwable t) {
+        throw new RuntimeException(t);
+      }
+    }
+    protected String read() {
+      String val = line;
+      line = readNext();
+      return val;
+    }
+  }
+  
+  public static abstract class LoaderIterator<T> 
+    implements Iterator<T> {
+      protected final ClassLoader cl;
+      protected LoaderIterator(
+        ClassLoader cl) {
+          this.cl = cl;
+      }
+      public void remove() {}
+  }
+    
+  public static URL locateResource(
+    String id, 
+    ClassLoader loader,
+    Class<?> callingClass) {
+      URL url = loader.getResource(id);
+      if (url == null && id.startsWith("/"))
+        url = loader.getResource(
+          id.substring(1));
+      if (url == null)
+        url = locateResource(
+          id,
+          Discover.class.getClassLoader(),
+          callingClass);
+      if (url == null && callingClass != null)
+        url = locateResource(
+          id,
+          callingClass.getClassLoader(),
+          null);
+      if (url == null) {
+        url = 
+          callingClass
+            .getResource(id);
+      }      
+      if ((url == null) && id.startsWith("/")) {
+        url = 
+          callingClass
+            .getResource(
+              id.substring(1));
+      }
+      return url;
+  }
+
+  public static Enumeration<URL> locateResources(
+    String id, 
+    ClassLoader loader,
+    Class<?> callingClass) 
+      throws IOException {
+        Enumeration<URL> urls =
+          loader.getResources(id);
+        if (urls == null && id.startsWith("/"))
+          urls = loader.getResources(
+            id.substring(1));
+        if (urls == null)
+          urls = locateResources(
+            id,
+            Discover.class.getClassLoader(),
+            callingClass);
+        if (urls == null)
+          urls = locateResources(
+            id,
+            callingClass.getClassLoader(),
+            callingClass);
+        return urls;
+    }
+  
+    public static InputStream locateResourceAsStream(
+      String resourceName, 
+      ClassLoader loader,
+      Class<?> callingClass) {
+        URL url = 
+          locateResource(
+            resourceName, 
+            loader, 
+            callingClass);
+        try {
+          return (url != null) ? 
+            url.openStream() : null;
+        } catch (IOException e) {
+          return null;
+        }
+    }
+}

Added: abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MultiIterator.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MultiIterator.java?rev=772417&view=auto
==============================================================================
--- abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MultiIterator.java (added)
+++ abdera/java/trunk/core/src/main/java/org/apache/abdera/util/MultiIterator.java Wed May  6 20:36:21 2009
@@ -0,0 +1,72 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements.  The ASF licenses this file to You
+* under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*     http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.  For additional information regarding
+* copyright in this work, please see the NOTICE file in the top level
+* directory of this distribution.
+*/
+package org.apache.abdera.util;
+
+import java.util.Arrays;
+import java.util.Iterator;
+
+/**
+ * Iterator implementation that wraps multiple iterators and invokes them
+ * in sequence.
+ */
+public final class MultiIterator<T> 
+  implements Iterator<T> {
+
+  private Iterator<Iterator<T>> iterators;
+  private Iterator<T> current;
+  
+  public MultiIterator(Iterable<Iterator<T>> i) {
+    this(i.iterator());
+  }
+  
+  public MultiIterator(Iterator<T>... iterators) {
+    this(Arrays.asList(iterators).iterator());
+  }
+  
+  public MultiIterator(Iterator<Iterator<T>> iterators) {
+    this.iterators = iterators;
+    current = selectCurrent();
+  }
+  
+  private Iterator<T> selectCurrent() {
+    if (current == null) {
+      if (iterators.hasNext())
+        current = iterators.next();
+    } else if (!current.hasNext() && iterators.hasNext()) { 
+      current = iterators.next();
+    }
+    return current;
+  }
+  
+  public boolean hasNext() {
+    Iterator<T> c = selectCurrent();
+    return c != null ? c.hasNext() : false;
+  }
+
+  public T next() {
+    if (hasNext())
+      return selectCurrent().next();
+    else 
+      return null;
+  }
+
+  public void remove() {
+    throw new UnsupportedOperationException();
+  }
+  
+}
\ No newline at end of file

Modified: abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java (original)
+++ abdera/java/trunk/core/src/main/java/org/apache/abdera/util/ServiceUtil.java Wed May  6 20:36:21 2009
@@ -17,15 +17,7 @@
 */
 package org.apache.abdera.util;
 
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Constructor;
-import java.net.URL;
 import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Enumeration;
 import java.util.List;
 
 import org.apache.abdera.Abdera;
@@ -40,6 +32,7 @@
 
 /**
  * Core utility methods that support Abdera's internal operation
+ * @deprecated
  */
 public final class ServiceUtil 
   implements Constants {
@@ -47,478 +40,170 @@
   ServiceUtil() {}
   
   /**
-   * 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.
-   */
-  public static Object newInstance(String id, String _default, Abdera abdera) {
-    return locate(id, _default, 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.
-   */
-  public static Object newInstance(String id, String _default, Abdera abdera, Object... args) {
-    return locate(id, _default, abdera, args);
-  }
-
-  /**
    * Utility method for returning an instance of the default Abdera XPath instance
+   * @deprecated
    */
-  public static XPath newXPathInstance(Abdera abdera) {
-    return (XPath) newInstance(
-      CONFIG_XPATH,
-      abdera.getConfiguration().getConfigurationOption(CONFIG_XPATH, DEFAULT_XPATH), 
-      abdera);
+  public static XPath newXPathInstance(
+    Abdera abdera) {
+      return (XPath) Discover.locate(
+        CONFIG_XPATH,
+        abdera
+          .getConfiguration()
+          .getConfigurationOption(
+            CONFIG_XPATH, 
+            DEFAULT_XPATH), 
+        abdera);
   }
   
   /**
    * Utility method for returning an instance of the default Abdera Parser instance
+   * @deprecated
    */
-  public static Parser newParserInstance(Abdera abdera) {
-    return (Parser) newInstance(
-      CONFIG_PARSER, 
-      abdera.getConfiguration().getConfigurationOption(CONFIG_PARSER, DEFAULT_PARSER),
-      abdera);
+  public static Parser newParserInstance(
+    Abdera abdera) {
+      return (Parser) Discover.locate(
+        CONFIG_PARSER, 
+        abdera
+          .getConfiguration()
+          .getConfigurationOption(
+            CONFIG_PARSER, 
+            DEFAULT_PARSER),
+        abdera);
   }
 
   /**
    * Utility method for returning an instance of the defaul Abdera Factory instance
+   * @deprecated
    */
-  public static Factory newFactoryInstance(Abdera abdera) {
-    return (Factory) newInstance(
-      CONFIG_FACTORY, 
-      abdera.getConfiguration().getConfigurationOption(CONFIG_FACTORY, DEFAULT_FACTORY),
-      abdera);
-  }
-  
-  public static ParserFactory newParserFactoryInstance(Abdera abdera) {
-    return (ParserFactory) newInstance(
-      CONFIG_PARSERFACTORY,
-      abdera.getConfiguration().getConfigurationOption(CONFIG_PARSERFACTORY, DEFAULT_PARSERFACTORY),
-      abdera);
-  }
-  
-  public static WriterFactory newWriterFactoryInstance(Abdera abdera) {
-    return (WriterFactory) newInstance(
-      CONFIG_WRITERFACTORY,
-      abdera.getConfiguration().getConfigurationOption(CONFIG_WRITERFACTORY, DEFAULT_WRITERFACTORY),
-      abdera) ;
+  public static Factory newFactoryInstance(
+    Abdera abdera) {
+      return (Factory) Discover.locate(
+        CONFIG_FACTORY, 
+        abdera
+          .getConfiguration()
+          .getConfigurationOption(
+            CONFIG_FACTORY, 
+            DEFAULT_FACTORY),
+        abdera);
   }
   
-  public static Writer newWriterInstance(Abdera abdera) {
-    return (Writer) newInstance(
-      CONFIG_WRITER,
-      abdera.getConfiguration().getConfigurationOption(CONFIG_WRITER, DEFAULT_WRITER),
-      abdera);
+  /**
+   * @deprecated
+   */
+  public static ParserFactory newParserFactoryInstance(
+    Abdera abdera) {
+      return (ParserFactory) Discover.locate(
+        CONFIG_PARSERFACTORY,
+        abdera
+          .getConfiguration()
+          .getConfigurationOption(
+            CONFIG_PARSERFACTORY, 
+            DEFAULT_PARSERFACTORY),
+        abdera);
   }
   
-  public static StreamWriter newStreamWriterInstance(Abdera abdera) {
-    return (StreamWriter) newInstance(
-      CONFIG_STREAMWRITER,
-      abdera.getConfiguration().getConfigurationOption(CONFIG_STREAMWRITER, DEFAULT_STREAMWRITER),
-      abdera);    
+  /**
+   * @deprecated
+   */
+  public static WriterFactory newWriterFactoryInstance(
+    Abdera abdera) {
+      return (WriterFactory) Discover.locate(
+        CONFIG_WRITERFACTORY,
+        abdera
+          .getConfiguration()
+          .getConfigurationOption(
+            CONFIG_WRITERFACTORY, 
+            DEFAULT_WRITERFACTORY),
+        abdera) ;
   }
   
-  public static Object locate(
-    String id, 
-    String _default, 
+  /**
+   * @deprecated
+   */
+  public static Writer newWriterInstance(
     Abdera abdera) {
-      Object object = locate(id, abdera);
-      if (object == null && _default != null) {
-        object = locateInstance(_default, abdera);
-      }
-      return object;
+      return (Writer) Discover.locate(
+        CONFIG_WRITER,
+        abdera
+          .getConfiguration()
+          .getConfigurationOption(
+            CONFIG_WRITER, 
+            DEFAULT_WRITER),
+        abdera);
   }
   
-  public static Object locate(
-    String id, 
-    String _default, 
-    Abdera abdera,
-    Object... args) {
-      Object object = locate(id, abdera);
-      if (object == null && _default != null) {
-        object = locateInstance(_default, abdera, args);
-      }
-      return object;
-  }
-
   /**
-   * Locate a class instance for the given id
+   * @deprecated
    */
-  public static Object locate(String id, Abdera abdera) {
-    Object service = checkAbderaConfiguration(id, abdera);
-    return ((service != null) ? service : checkMetaInfServices(id, abdera));
-  }
-  
-  @SuppressWarnings("unchecked")
-  private static Object _create(Class _class, Abdera abdera) {
-    if (_class == null) return null;
-    try {
-      if (abdera != null) {
-        Constructor c = _class.getConstructor(new Class[] {Abdera.class});
-        return c.newInstance(new Object[] {abdera});
-      }
-    } catch (Exception e) {
-      // Nothing
-    }
-    try {
-      return _class.newInstance();
-    } catch (Exception e) {
-      // Nothing
-    }
-    return null;
-  }
-  
-  @SuppressWarnings("unchecked")
-  private static Object _create(Class _class, Abdera abdera, Object... args) {
-    Class[] types = null;
-    Object[] values = null;
-    if (_class == null) return null;
-    try {
-      if (abdera != null) {
-        types = new Class[args.length + 1];
-        values = new Object[args.length + 1];
-        types[0] = Abdera.class;
-        values[0] = abdera;
-        for (int n = 0; n < args.length; n++) {
-          types[n+1] = args[n].getClass();
-          values[n+1] = args[n];
-        }
-        Constructor c = _class.getConstructor(types);
-        return c.newInstance(values);
-      }
-    } catch (Exception e) {
-      // Nothing
-    }
-    try {
-      types = new Class[args.length];
-      for (int n = 0; n < args.length; n++)
-        types[n] = args[n].getClass();
-      return _class.getConstructor(types).newInstance(args);
-    } catch (Exception e) {
-      // Nothing
-    }
-    return null;
-  }
-  
-  public static Object locateInstance(String id, Abdera abdera) {
-    return locateInstance(id,abdera,false);
-  }
-  
-  @SuppressWarnings("unchecked")
-  public static Object locateInstance(String id, Abdera abdera, boolean classesonly) {
-    try {
-      Class _class = loadClass(id, ServiceUtil.class);
-      return classesonly ? _class : _create(_class, abdera);
-    } catch (Exception e) {
-      // Nothing
-    }
-    try {
-      Class _class = ClassLoader.getSystemClassLoader().loadClass(id);
-      return classesonly ? _class : _create(_class, abdera);
-    } catch (Exception e) {
-      // Nothing
-    }
-    return null;
-  }
-  
-  @SuppressWarnings("unchecked")
-  public static Object locateInstance(String id, Abdera abdera, Object... args) {
-    try {
-      Class _class = loadClass(id, ServiceUtil.class);
-      return _create(_class, abdera, args);
-    } catch (Exception e) {
-      // Nothing
-    }
-    try {
-      Class _class = ClassLoader.getSystemClassLoader().loadClass(id);
-      return _create(_class, abdera, args);
-    } catch (Exception e) {
-      // Nothing
-    }
-    return null;
-  }
-  
-  public static InputStream locateStream(String id) {
-    InputStream in = getResourceAsStream(id, ServiceUtil.class);
-    return (in != null) ? in : ClassLoader.getSystemResourceAsStream(id);
-  }
-  
-  public static Enumeration<URL> locateResources(String id) {
-    try {
-      return getResources(id,ServiceUtil.class);
-    } catch (Exception e) {
-      // Nothing
-    }
-    try {
-      return ClassLoader.getSystemResources(id);
-    } catch (Exception e) {
-      // Nothing
-    }
-    return null;
-  }
-  
-  private static Object checkAbderaConfiguration(String id, Abdera abdera) {
-    String s = abdera.getConfiguration().getConfigurationOption(id);
-    return (s != null) ? locateInstance(id, abdera) : null;
-  }
-  
-  private static Object checkMetaInfServices(String id, Abdera abdera) {
-    Object object = null;
-    String sid = "META-INF/services/" + id;
-    BufferedReader buf = null;
-    try {
-      InputStream is = locateStream(sid);
-      if (is != null) {
-        buf = new BufferedReader(new InputStreamReader(is));
-        String line = buf.readLine();
-        if (line != null) {
-          String s = line.split("#",2)[0].trim();
-          object = locateInstance(s, abdera);
-        }
-      }
-    } catch (Exception e) {
-      // Nothing
-    } finally {
-      if (buf != null) {
-        try {
-          buf.close();
-        } catch (IOException ioe) {
-          // Nothing
-        }
-      }
-    }
-    return object;
+  public static StreamWriter newStreamWriterInstance(
+    Abdera abdera) {
+      return (StreamWriter) Discover.locate(
+        CONFIG_STREAMWRITER,
+        abdera
+          .getConfiguration()
+          .getConfigurationOption(
+            CONFIG_STREAMWRITER, 
+            DEFAULT_STREAMWRITER),
+        abdera);    
   }
   
-  protected static synchronized List<ExtensionFactory> loadExtensionFactories() {
-      List<ExtensionFactory> factories =
-        _loadimpls(
-          "META-INF/services/org.apache.abdera.factory.ExtensionFactory");
-      return factories;
-  }
-  
-  public static synchronized <T>List<T> loadimpls(String sid) {
-    return loadimpls(sid,false);
-  }
-  
-  public static synchronized <T>List<T> loadimpls(String sid, boolean classesonly) {
-    return _loadimpls(sid,classesonly);
-  }
-  
-  @SuppressWarnings("unchecked")
-  protected static <T>List<T> _loadimpls(String sid, boolean classesonly) {
-    List<T> impls = Collections.synchronizedList(new ArrayList<T>());
-    try {
-      Enumeration<URL> e = locateResources(sid);
-      for (;e.hasMoreElements();) {
-        BufferedReader buf = null;
-        try {
-          URL url = (URL) e.nextElement();
-          InputStream is = url.openStream();
-          if (is != null) {
-            buf = new BufferedReader(new InputStreamReader(is));
-            String line;
-            while ((line = buf.readLine()) != null) {
-              String s = line.split("#",2)[0].trim();
-              if (!"".equals(s)) { 
-                T impl = (T) locateInstance(s, null);
-                if (impl != null)
-                  impls.add(impl);
-              }
-            }
-          }
-        } catch (Exception ex) {
-          // Nothing
-        } finally {
-          if (buf != null) {
-            try {
-              buf.close();
-            } catch (IOException ioe) {
-              // Nothing
-            }
-          }
-        }
-      }
-    } catch (Exception e) {
-      // Nothing
-    }
-    
-    return impls;
-  }
- 
-  protected static <T>List<T> _loadimpls(String sid) {
-    return _loadimpls(sid,false);
-  }
-  
-  
-  // The following class loader functions were adopted from 
-  // http://svn.apache.org/repos/asf/cxf/trunk/common/common/src/main/java/org/apache/cxf/common/classloader/ClassLoaderUtils.java
-  // CXF is an Apache project licensed under the ASF License 2.0
-  // License statement from the file:
-  /**
-   * Licensed to the Apache Software Foundation (ASF) under one
-   * or more contributor license agreements. See the NOTICE file
-   * distributed with this work for additional information
-   * regarding copyright ownership. The ASF licenses this file
-   * to you under the Apache License, Version 2.0 (the
-   * "License"); you may not use this file except in compliance
-   * with the License. You may obtain a copy of the License at
-   *
-   * http://www.apache.org/licenses/LICENSE-2.0
-   *
-   * Unless required by applicable law or agreed to in writing,
-   * software distributed under the License is distributed on an
-   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-   * KIND, either express or implied. See the License for the
-   * specific language governing permissions and limitations
-   * under the License.
+  /**
+   * @deprecated
    */
-
+  protected static synchronized List<ExtensionFactory> loadExtensionFactories() {
+    List<ExtensionFactory> list = 
+      new ArrayList<ExtensionFactory>();
+    Iterable<ExtensionFactory> factories =
+      Discover.locate("org.apache.abdera.factory.ExtensionFactory");
+    for (ExtensionFactory factory : factories)
+      list.add(factory);
+    return list;
+  }
   
   /**
-   * Load a given resource. <p/> This method will try to load the resource
-   * using the following methods (in order):
-   * <ul>
-   * <li>From Thread.currentThread().getContextClassLoader()
-   * <li>From ClassLoaderUtil.class.getClassLoader()
-   * <li>callingClass.getClassLoader()
-   * </ul>
-   * 
-   * @param resourceName The name of the resource to load
-   * @param callingClass The Class object of the calling object
-   */
-  public static URL getResource(
-    String resourceName, 
-    Class<?> callingClass) {
-      URL url = Thread.currentThread().getContextClassLoader().getResource(resourceName);
-      if (url == null && resourceName.startsWith("/")) {
-        //certain classloaders need it without the leading /
-        url = Thread.currentThread().getContextClassLoader()
-            .getResource(resourceName.substring(1));
-      }
-      if (url == null) {
-        url = ServiceUtil.class.getClassLoader().getResource(resourceName);
-      }
-      if (url == null && resourceName.startsWith("/")) {
-        //certain classloaders need it without the leading /
-        url = ServiceUtil.class.getClassLoader()
-            .getResource(resourceName.substring(1));
-      }
-      if (url == null) {
-        ClassLoader cl = callingClass.getClassLoader();
-        if (cl != null) {
-          url = cl.getResource(resourceName);
-        }
-      }
-      if (url == null) {
-        url = callingClass.getResource(resourceName);
-      }      
-      if ((url == null) && (resourceName != null) && (resourceName.charAt(0) != '/')) {
-        return getResource('/' + resourceName, callingClass);
-      }
-      return url;
-  }
-
-  public static Enumeration<URL> getResources(
-    String resourceName, 
-    Class<?> callingClass) 
-      throws IOException {
-    Enumeration<URL> url = Thread.currentThread().getContextClassLoader().getResources(resourceName);
-    if (url == null && resourceName.startsWith("/")) {
-      //certain classloaders need it without the leading /
-      url = Thread.currentThread().getContextClassLoader()
-          .getResources(resourceName.substring(1));
-    }
-    if (url == null) {
-      url = ServiceUtil.class.getClassLoader().getResources(resourceName);
-    }
-    if (url == null && resourceName.startsWith("/")) {
-      //certain classloaders need it without the leading /
-      url = ServiceUtil.class.getClassLoader()
-          .getResources(resourceName.substring(1));
-    }
-    if (url == null) {
-      ClassLoader cl = callingClass.getClassLoader();
-      if (cl != null) {
-        url = cl.getResources(resourceName);
-      }
-    }      
-    if ((url == null) && (resourceName != null) && (resourceName.charAt(0) != '/')) {
-      return getResources('/' + resourceName, callingClass);
-    }
-    return url;
+   * @deprecated
+   */
+  public static synchronized <T>Iterable<T> loadimpls(String sid) {
+    return Discover.locate(sid);
   }
   
   /**
-   * This is a convenience method to load a resource as a stream. <p/> The
-   * algorithm used to find the resource is given in getResource()
-   * 
-   * @param resourceName The name of the resource to load
-   * @param callingClass The Class object of the calling object
-   */
-  public static InputStream getResourceAsStream(
-    String resourceName, 
-    Class<?> callingClass) {
-      URL url = getResource(resourceName, callingClass);
-      try {
-        return (url != null) ? url.openStream() : null;
-      } catch (IOException e) {
-        return null;
-      }
+   * @deprecated
+   */
+  public static synchronized <T>Iterable<T> loadimpls(String sid, boolean classesonly) {
+    return Discover.locate(sid,classesonly);
   }
 
   /**
-   * Load a class with a given name. <p/> It will try to load the class in the
-   * following order:
-   * <ul>
-   * <li>From Thread.currentThread().getContextClassLoader()
-   * <li>Using the basic Class.forName()
-   * <li>From ClassLoaderUtil.class.getClassLoader()
-   * <li>From the callingClass.getClassLoader()
-   * </ul>
-   * 
-   * @param className The name of the class to load
-   * @param callingClass The Class object of the calling object
-   * @throws ClassNotFoundException If the class cannot be found anywhere.
-   */
-  public static Class<?> loadClass(
-    String className, 
-    Class<?> callingClass) 
-      throws ClassNotFoundException {
-    try {
-      ClassLoader cl = Thread.currentThread().getContextClassLoader();
-      if (cl != null) {
-        return cl.loadClass(className);
-      }      
-      return loadClass2(className, callingClass);
-    } catch (ClassNotFoundException e) {
-      return loadClass2(className, callingClass);
-    }
+   * 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.
+   * @deprecated
+   */
+  public static Object newInstance(
+    String id, 
+    String _default, 
+    Abdera abdera) {
+      return Discover.locate(id,_default,abdera);
   }
-
-  private static Class<?> loadClass2(
-    String className, 
-    Class<?> callingClass) 
-      throws ClassNotFoundException {
-    try {
-      return Class.forName(className);
-    } catch (ClassNotFoundException ex) {
-      try {
-        return ServiceUtil.class.getClassLoader().loadClass(className);
-      } catch (ClassNotFoundException exc) {
-        return callingClass.getClassLoader().loadClass(className);
-      }
-    }
+  
+  /**
+   * 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.
+   * @deprecated
+   */
+  public static Object newInstance(
+    String id, 
+    String _default, 
+    Object... args) {
+      return Discover.locate(id,_default,args);
   }
 
 }

Modified: abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java (original)
+++ abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/FOMXPath.java Wed May  6 20:36:21 2009
@@ -24,6 +24,7 @@
 
 import javax.xml.namespace.QName;
 
+import org.apache.abdera.Abdera;
 import org.apache.abdera.model.Base;
 import org.apache.abdera.model.ElementWrapper;
 import org.apache.abdera.parser.stax.util.ResolveFunction;
@@ -46,7 +47,7 @@
   private final Map<QName,Function> functions;
   private final Map<QName,Object> variables;
   
-  public FOMXPath() {
+  public FOMXPath(Abdera abdera) {
     this(null,null,null);
   }
   

Modified: abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java (original)
+++ abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java Wed May  6 20:36:21 2009
@@ -30,6 +30,7 @@
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamWriter;
 
+import org.apache.abdera.Abdera;
 import org.apache.abdera.parser.stax.util.FOMHelper;
 import org.apache.abdera.util.AbstractStreamWriter;
 import org.apache.abdera.util.Constants;
@@ -45,26 +46,30 @@
   private int depth = 0;
   private int textwritten = 0;
   
-  public StaxStreamWriter() {
-    super(NAME);
+  public StaxStreamWriter(
+    Abdera abdera) {
+      super(abdera,NAME);
   }
   
   public StaxStreamWriter(
+    Abdera abdera,
     Writer writer) {
-    super(NAME);
+    super(abdera,NAME);
     setWriter(writer);
   }
 
   public StaxStreamWriter(
+    Abdera abdera,
     OutputStream out) {
-      super(NAME);
+      super(abdera,NAME);
       setOutputStream(out);
   }
   
   public StaxStreamWriter(
+    Abdera abdera,
     OutputStream out, 
     String charset) {
-    super(NAME);
+    super(abdera,NAME);
     setOutputStream(out,charset);
   }
 

Modified: abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java (original)
+++ abdera/java/trunk/parser/src/test/java/org/apache/abdera/test/parser/stax/FOMTest.java Wed May  6 20:36:21 2009
@@ -790,7 +790,7 @@
     edoc.writeTo(w);
     
     in = new ByteArrayInputStream(out.toByteArray());
-
+    
     entry = (Entry) abdera.getParser().parse(in).getRoot();
 
     assertEquals("tóst", entry.getContent());

Modified: abdera/java/trunk/security/src/main/java/org/apache/abdera/security/AbderaSecurity.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/security/src/main/java/org/apache/abdera/security/AbderaSecurity.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/security/src/main/java/org/apache/abdera/security/AbderaSecurity.java (original)
+++ abdera/java/trunk/security/src/main/java/org/apache/abdera/security/AbderaSecurity.java Wed May  6 20:36:21 2009
@@ -19,7 +19,7 @@
 
 import org.apache.abdera.Abdera;
 import org.apache.abdera.util.Configuration;
-import org.apache.abdera.util.ServiceUtil;
+import org.apache.abdera.util.Discover;
 
 /**
  * The AbderaSecurity class provides the entry point for using XML Digital
@@ -54,7 +54,7 @@
    */
   public Encryption newEncryption() {
     return
-      (Encryption) ServiceUtil.newInstance(
+      (Encryption) Discover.locate(
           "org.apache.abdera.security.Encryption", 
           "org.apache.abdera.security.xmlsec.XmlEncryption",
           getAbdera());
@@ -72,7 +72,7 @@
    */
   public Signature newSignature() {
     return
-      (Signature) ServiceUtil.newInstance(
+      (Signature) Discover.locate(
         "org.apache.abdera.security.Signature", 
         "org.apache.abdera.security.xmlsec.XmlSignature",
         getAbdera());

Modified: abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java
URL: http://svn.apache.org/viewvc/abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java?rev=772417&r1=772416&r2=772417&view=diff
==============================================================================
--- abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java (original)
+++ abdera/java/trunk/server/src/main/java/org/apache/abdera/protocol/server/ServiceManager.java Wed May  6 20:36:21 2009
@@ -22,7 +22,7 @@
 import org.apache.abdera.Abdera;
 import org.apache.abdera.i18n.text.Localizer;
 import org.apache.abdera.protocol.server.impl.DefaultProvider;
-import org.apache.abdera.util.ServiceUtil;
+import org.apache.abdera.util.Discover;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
@@ -65,7 +65,7 @@
     String instance = properties.get(PROVIDER);
     log.debug(Localizer.sprintf("CREATING.NEW.INSTANCE","Provider"));
     Provider provider = 
-      (Provider) ServiceUtil.newInstance(
+      (Provider) Discover.locate(
         PROVIDER, 
         (instance != null) ? 
           instance : 



Mime
View raw message