You are viewing a plain text version of this content. The canonical link for it is here.
Posted to kato-commits@incubator.apache.org by sp...@apache.org on 2009/05/18 08:19:37 UTC

svn commit: r775858 - in /incubator/kato/trunk/org.apache.kato.api: .classpath .settings/org.eclipse.jdt.core.prefs META-INF/MANIFEST.MF src/org/apache/kato/FactoryRegistry.java

Author: spoole
Date: Mon May 18 08:19:37 2009
New Revision: 775858

URL: http://svn.apache.org/viewvc?rev=775858&view=rev
Log:
addition of new Factory Registry class to the API (this is experimental)

Added:
    incubator/kato/trunk/org.apache.kato.api/src/org/apache/kato/FactoryRegistry.java   (with props)
Modified:
    incubator/kato/trunk/org.apache.kato.api/.classpath
    incubator/kato/trunk/org.apache.kato.api/.settings/org.eclipse.jdt.core.prefs
    incubator/kato/trunk/org.apache.kato.api/META-INF/MANIFEST.MF

Modified: incubator/kato/trunk/org.apache.kato.api/.classpath
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.api/.classpath?rev=775858&r1=775857&r2=775858&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.api/.classpath (original)
+++ incubator/kato/trunk/org.apache.kato.api/.classpath Mon May 18 08:19:37 2009
@@ -1,6 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
-	<classpathentry exported="true" kind="lib" path="bin/"/>
 	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
 	<classpathentry kind="src" path="src"/>
 	<classpathentry kind="src" path="testsrc"/>

Modified: incubator/kato/trunk/org.apache.kato.api/.settings/org.eclipse.jdt.core.prefs
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.api/.settings/org.eclipse.jdt.core.prefs?rev=775858&r1=775857&r2=775858&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.api/.settings/org.eclipse.jdt.core.prefs (original)
+++ incubator/kato/trunk/org.apache.kato.api/.settings/org.eclipse.jdt.core.prefs Mon May 18 08:19:37 2009
@@ -1,7 +1,12 @@
-#Wed Sep 24 20:21:18 BST 2008
+#Sun May 17 23:04:59 BST 2009
 eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
-org.eclipse.jdt.core.compiler.compliance=1.4
-org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
-org.eclipse.jdt.core.compiler.source=1.3
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.5

Modified: incubator/kato/trunk/org.apache.kato.api/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.api/META-INF/MANIFEST.MF?rev=775858&r1=775857&r2=775858&view=diff
==============================================================================
--- incubator/kato/trunk/org.apache.kato.api/META-INF/MANIFEST.MF (original)
+++ incubator/kato/trunk/org.apache.kato.api/META-INF/MANIFEST.MF Mon May 18 08:19:37 2009
@@ -5,7 +5,8 @@
 Bundle-Version: 1.3.0.qualifier
 Bundle-Vendor: Apache
 Bundle-RequiredExecutionEnvironment: J2SE-1.4
-Export-Package: org.apache.kato.image,
+Export-Package: org.apache.kato,
+ org.apache.kato.image,
  org.apache.kato.java,
  org.apache.kato.runtime
 

Added: incubator/kato/trunk/org.apache.kato.api/src/org/apache/kato/FactoryRegistry.java
URL: http://svn.apache.org/viewvc/incubator/kato/trunk/org.apache.kato.api/src/org/apache/kato/FactoryRegistry.java?rev=775858&view=auto
==============================================================================
--- incubator/kato/trunk/org.apache.kato.api/src/org/apache/kato/FactoryRegistry.java (added)
+++ incubator/kato/trunk/org.apache.kato.api/src/org/apache/kato/FactoryRegistry.java Mon May 18 08:19:37 2009
@@ -0,0 +1,124 @@
+/*******************************************************************************
+ * Licensed 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.
+ ******************************************************************************/
+package org.apache.kato;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.imageio.spi.ServiceRegistry;
+
+import org.apache.kato.image.ImageFactory;
+
+/**
+ * Experimental addition to the API.
+ * 
+ * This class provides a central registry for image factories
+ * 
+ * Image factories can be registered directly using the {@link #addFactory()} method.
+ * 
+ * The default registry uses {@link  javax.imageio.spi.ServiceRegistry} to discover
+ * ImageFactory implementations.
+ * 
+ * To register an ImageFactory implementation that can be discovered by the registry do the
+ * following :
+ * <ul> 
+ * <li>Create a 'services' directory as a child of the manfest directory 'META-INF'
+ * <li>Within this 'services' directory create a text file called 'org.apache.kato.image.ImageFactory'
+ * <l1>This text file should contain a single line which is the package qualified name of the ImageFactory 
+ * implementation to be registered
+ * </ul>  
+ * 
+ * @experimental
+ *
+ */
+public class FactoryRegistry implements Iterable<ImageFactory>{
+
+	private static FactoryRegistry defaultRegistry=null;
+	private Set<ImageFactory> factories=new HashSet<ImageFactory>();
+	
+	public FactoryRegistry() {
+		
+	}
+	
+	/**
+	 * Returns the default registry.  This registy is preloaded with
+	 * ImageFactory implementations discovered using the {@link  javax.imageio.spi.ServiceRegistry} 
+	 * 
+	 * @return default image factory
+	 */
+	public synchronized static FactoryRegistry getDefaultRegistry() {
+		
+		if(defaultRegistry==null) {
+			defaultRegistry=new FactoryRegistry();
+			defaultRegistry.addLocalFactories();
+			
+			
+		}
+		
+		return defaultRegistry;
+	}
+
+	
+	/**
+	 * Using {@link  javax.imageio.spi.ServiceRegistry} this method
+	 * finds ImageFactory implementations and adds them to this instance
+	 */
+	private void addLocalFactories() {
+		
+	
+		
+		Iterator<ImageFactory> i= ServiceRegistry.lookupProviders(org.apache.kato.image.ImageFactory.class);
+	 
+		while(i.hasNext()) {
+		   ImageFactory localFactory=i.next();
+		   addFactory(localFactory);
+		}
+		
+	}
+
+	/**
+	 * Returns an Iterator of ImageFactories registered
+	 * to this registry. 
+	 */
+	public Iterator<ImageFactory> iterator() {
+		return factories.iterator();
+	}
+
+	/**
+	 * Adds an ImageFactory to the registry instance
+	 * If the factory instance is already in the 
+	 * registry it is not added again.
+	 *  
+	 * @param factory
+	 * @throws IllegalArgument if factory is null
+	 * @return true if factory added 
+	 */
+	public boolean addFactory(ImageFactory factory) {
+		if(factory==null) throw new IllegalArgumentException("factory parameter is null");
+		return factories.add(factory);
+		
+	}
+
+	/**
+	 * Returns the factories in the registry as an array
+	 * 
+	 * Always returns an array even if the registry is empty
+	 * 
+	 */
+	public ImageFactory[] getFactories() {
+		
+		return factories.toArray(new ImageFactory[0]);
+	}
+}

Propchange: incubator/kato/trunk/org.apache.kato.api/src/org/apache/kato/FactoryRegistry.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain