tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: r375756 - in /incubator/tuscany/java: sdo/impl/src/main/java/commonj/sdo/impl/ sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/ sdo/impl/src/main/resources/META-INF/services/ spec/sdo/ spec/sdo/src/main/java/commonj/sdo/impl/ spec/sdo/...
Date Tue, 07 Feb 2006 22:37:40 GMT
Author: jboynes
Date: Tue Feb  7 14:37:37 2006
New Revision: 375756

URL: http://svn.apache.org/viewcvs?rev=375756&view=rev
Log:
version of HelperProvider that uses JAR service lookup to find the implementation
changed copyright on HelperProvider.java as this is a new implementation


Added:
    incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java
  (contents, props changed)
      - copied, changed from r375405, incubator/tuscany/java/sdo/impl/src/main/java/commonj/sdo/impl/HelperProviderImpl.java
    incubator/tuscany/java/sdo/impl/src/main/resources/META-INF/services/
    incubator/tuscany/java/sdo/impl/src/main/resources/META-INF/services/commonj.sdo.impl.HelperProvider
    incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/NoHelperProviderException.java
  (with props)
    incubator/tuscany/java/spec/sdo/src/test/
    incubator/tuscany/java/spec/sdo/src/test/java/
    incubator/tuscany/java/spec/sdo/src/test/java/commonj/
    incubator/tuscany/java/spec/sdo/src/test/java/commonj/sdo/
    incubator/tuscany/java/spec/sdo/src/test/java/commonj/sdo/impl/
    incubator/tuscany/java/spec/sdo/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java
  (with props)
    incubator/tuscany/java/spec/sdo/src/test/java/test/
    incubator/tuscany/java/spec/sdo/src/test/java/test/DefaultHelperProvider.java   (with
props)
    incubator/tuscany/java/spec/sdo/src/test/java/test/TCCL1HelperProvider.java   (with props)
    incubator/tuscany/java/spec/sdo/src/test/resources/
    incubator/tuscany/java/spec/sdo/src/test/resources/META-INF/
    incubator/tuscany/java/spec/sdo/src/test/resources/META-INF/services/
    incubator/tuscany/java/spec/sdo/src/test/resources/META-INF/services/commonj.sdo.impl.HelperProvider
    incubator/tuscany/java/spec/sdo/src/test/resources/tccl1/
    incubator/tuscany/java/spec/sdo/src/test/resources/tccl1/META-INF/
    incubator/tuscany/java/spec/sdo/src/test/resources/tccl1/META-INF/services/
    incubator/tuscany/java/spec/sdo/src/test/resources/tccl1/META-INF/services/commonj.sdo.impl.HelperProvider
Removed:
    incubator/tuscany/java/sdo/impl/src/main/java/commonj/sdo/impl/
Modified:
    incubator/tuscany/java/spec/sdo/pom.xml
    incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/HelperProvider.java

Copied: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java
(from r375405, incubator/tuscany/java/sdo/impl/src/main/java/commonj/sdo/impl/HelperProviderImpl.java)
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java?p2=incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java&p1=incubator/tuscany/java/sdo/impl/src/main/java/commonj/sdo/impl/HelperProviderImpl.java&r1=375405&r2=375756&rev=375756&view=diff
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/java/commonj/sdo/impl/HelperProviderImpl.java
(original)
+++ incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java
Tue Feb  7 14:37:37 2006
@@ -14,7 +14,7 @@
  *  See the License for the specific language governing permissions and
  *  limitations under the License.
  */
-package commonj.sdo.impl;
+package org.apache.tuscany.sdo.helper;
 
 
 import org.apache.tuscany.sdo.helper.CopyHelperImpl;
@@ -30,6 +30,7 @@
 import commonj.sdo.helper.XMLHelper;
 import commonj.sdo.helper.XSDHelper;
 import commonj.sdo.impl.ExternalizableDelegator.Resolvable;
+import commonj.sdo.impl.HelperProvider;
 
 
 /**
@@ -51,7 +52,7 @@
 
   protected XSDHelper xsdHelper;
 
-  HelperProviderImpl()
+  public HelperProviderImpl()
   {
     typeHelper = SDOUtil.createTypeHelper();
     dataFactory = SDOUtil.createDataFactory(typeHelper);
@@ -62,47 +63,47 @@
     dataHelper = new DataHelperImpl();
   }
 
-  CopyHelper copyHelper()
+  public CopyHelper copyHelper()
   {
     return copyHelper;
   }
 
-  DataFactory dataFactory()
+  public DataFactory dataFactory()
   {
     return dataFactory;
   }
 
-  DataHelper dataHelper()
+  public DataHelper dataHelper()
   {
     return dataHelper;
   }
 
-  EqualityHelper equalityHelper()
+  public EqualityHelper equalityHelper()
   {
     return equalityHelper;
   }
 
-  TypeHelper typeHelper()
+  public TypeHelper typeHelper()
   {
     return typeHelper;
   }
 
-  XMLHelper xmlHelper()
+  public XMLHelper xmlHelper()
   {
     return xmlHelper;
   }
 
-  XSDHelper xsdHelper()
+  public XSDHelper xsdHelper()
   {
     return xsdHelper;
   }
 
-  Resolvable resolvable()
+  public Resolvable resolvable()
   {
     throw new UnsupportedOperationException(); //TODO
   }
 
-  Resolvable resolvable(Object target)
+  public Resolvable resolvable(Object target)
   {
     throw new UnsupportedOperationException(); //TODO
   }

Propchange: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/sdo/impl/src/main/java/org/apache/tuscany/sdo/helper/HelperProviderImpl.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: incubator/tuscany/java/sdo/impl/src/main/resources/META-INF/services/commonj.sdo.impl.HelperProvider
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/sdo/impl/src/main/resources/META-INF/services/commonj.sdo.impl.HelperProvider?rev=375756&view=auto
==============================================================================
--- incubator/tuscany/java/sdo/impl/src/main/resources/META-INF/services/commonj.sdo.impl.HelperProvider
(added)
+++ incubator/tuscany/java/sdo/impl/src/main/resources/META-INF/services/commonj.sdo.impl.HelperProvider
Tue Feb  7 14:37:37 2006
@@ -0,0 +1 @@
+org.apache.tuscany.sdo.helper.HelperProviderImpl
\ No newline at end of file

Modified: incubator/tuscany/java/spec/sdo/pom.xml
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/spec/sdo/pom.xml?rev=375756&r1=375755&r2=375756&view=diff
==============================================================================
--- incubator/tuscany/java/spec/sdo/pom.xml (original)
+++ incubator/tuscany/java/spec/sdo/pom.xml Tue Feb  7 14:37:37 2006
@@ -26,4 +26,12 @@
     <name>SDO API</name>
     <version>SNAPSHOT</version>
 
+    <dependencies>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>3.8.1</version>
+            <scope>test</scope>
+        </dependency>
+    </dependencies>
 </project>

Modified: incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/HelperProvider.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/HelperProvider.java?rev=375756&r1=375755&r2=375756&view=diff
==============================================================================
--- incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/HelperProvider.java (original)
+++ incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/HelperProvider.java Tue
Feb  7 14:37:37 2006
@@ -1,18 +1,29 @@
 /**
- * <copyright>
  *
- * Service Data Objects
- * Version 2.0
- * Licensed Materials - Property of BEA and IBM
+ * Copyright 2006 The Apache Software Foundation
  *
- * (c) Copyright BEA Systems, Inc. and International Business Machines Corp 2005.  All rights
reserved.
+ *  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
  *
- * </copyright>
- * 
+ *     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 commonj.sdo.impl;
 
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
 
 import commonj.sdo.helper.CopyHelper;
 import commonj.sdo.helper.DataFactory;
@@ -21,122 +32,325 @@
 import commonj.sdo.helper.TypeHelper;
 import commonj.sdo.helper.XMLHelper;
 import commonj.sdo.helper.XSDHelper;
-import commonj.sdo.impl.ExternalizableDelegator.Resolvable;
 
 /**
- * This class instantiates a HelperProviderImpl that returns concrete helpers.
- * This class may be replaced by another implementation.
+ * A HelperProvider obtains specific default helpers and other
+ * implementation-specific objects used by a Java implementation of SDO.
+ *
+ * @version $Rev$ $Date$
  */
-public abstract class HelperProvider
-{
-  static HelperProvider INSTANCE = getHelperProviderImpl();
-  
-  static HelperProvider getHelperProviderImpl() 
-  {
-    try
-    {
-      return (HelperProvider)Class.forName("commonj.sdo.impl.HelperProviderImpl").newInstance();
-    } catch (Exception e)
-    {
-      throw new RuntimeException(e);
-    }
-  } // end method getHelperProvider()
-  
-  HelperProvider()
-  {
-  }
-  
-  /**
-   * Gets a CopyHelper
-   * @return a CopyHelper object
-   */
-  public static CopyHelper getCopyHelper()
-  {
-    return INSTANCE.copyHelper();
-  }
-
-  /**
-   * Gets a DataFactory
-   * @return a DataFactory object
-   */
-  public static DataFactory getDataFactory()
-  {
-    return INSTANCE.dataFactory();
-  }
-
-  /**
-   * Gets a DataHelper
-   * @return a DataHelper object
-   */
-  public static DataHelper getDataHelper()
-  {
-    return INSTANCE.dataHelper();
-  }
-
-  /**
-   * Gets an EqualityHelper
-   * @return an EqualityHelper object
-   */
-  public static EqualityHelper getEqualityHelper()
-  {
-    return INSTANCE.equalityHelper();
-  }
-  
-  /**
-   * Gets a TypeHelper 
-   * @return a TypeHelper object
-   */
-  public static TypeHelper getTypeHelper()
-  {
-    return INSTANCE.typeHelper();
-  }
-
-  /**
-   * Gets an XMLHelper
-   * @return an XMLHelper object
-   */
-  public static XMLHelper getXMLHelper()
-  {
-    return INSTANCE.xmlHelper();
-  }
-  
-  /**
-   * Gets an XSDHelper 
-   * @return an XSDHelper object
-   */
-  public static XSDHelper getXSDHelper()
-  {
-    return INSTANCE.xsdHelper();
-  }
-
-  /**
-   * Gets a Resolvable 
-   * @return a Resolvable object
-   * @see ExternalizableDelegator
-   */
-  public static Resolvable createResolvable()
-  {
-    return INSTANCE.resolvable();
-  }
-  
-  /**
-   * Gets a Resolvable 
-   * @param target the target object for the Resolvable
-   * @return a Resolvable object
-   * @see ExternalizableDelegator
-   */
-  public static Resolvable createResolvable(Object target)
-  {
-    return INSTANCE.resolvable(target);
-  }
-
-  abstract CopyHelper copyHelper();
-  abstract DataFactory dataFactory();
-  abstract DataHelper dataHelper();
-  abstract EqualityHelper equalityHelper();
-  abstract TypeHelper typeHelper();
-  abstract XMLHelper xmlHelper();
-  abstract XSDHelper xsdHelper();
-  abstract Resolvable resolvable();
-  abstract Resolvable resolvable(Object target);
-}
+public abstract class HelperProvider {
+    /**
+     * The default HelperProvider INSTANCE. This is located using the ClassLoader used
+     * to load the HelperProvider class itself and if no default implementation is available
+     * this field will be set to null.
+     */
+    public static final HelperProvider INSTANCE;
+
+    /**
+     * The name of the resource that is used for service location.
+     */
+    public static final String SERVICE_RESOURCE_NAME = "META-INF/services/commonj.sdo.impl.HelperProvider";
+
+    /**
+     * The name of the system property that will be checked for an implementation name.
+     */
+    public static final String PROPERTY_NAME = "commonj.sdo.impl.HelperProvider";
+
+    static {
+        // initialize the default instance using this class's classloader
+        // set to null if none could be located (implies no default implementation)
+        HelperProvider provider;
+        try {
+            provider = getInstance(HelperProvider.class.getClassLoader());
+        } catch (NoHelperProviderException e) {
+            provider = null;
+        }
+        INSTANCE = provider;
+    }
+
+    /**
+     * Locate and instantiate a HelperProvider.
+     * <p/>
+     * Attempt to locate a HelperProvider using first the Thread's current context classloader
and then,
+     * if that is not set, not readable, or does not provide an implementation, using the
classloader
+     * used to load the HelperProvider class itself.
+     *
+     * @return an implementation of HelperProvider
+     * @throws NoHelperProviderException if no provider implmentation was defined or it could
not be instantiated
+     */
+    public static HelperProvider getInstance() throws NoHelperProviderException {
+        String implName = getImplementationName();
+
+        ClassLoader cl = getContextClassLoader();
+        if (cl != null) {
+            HelperProvider provider = loadImplementation(cl, implName);
+            if (provider != null) {
+                return provider;
+            }
+        }
+
+        cl = HelperProvider.class.getClassLoader();
+        HelperProvider provider = loadImplementation(cl, implName);
+        if (provider != null) {
+            return provider;
+        }
+
+        throw new NoHelperProviderException(implName);
+    }
+
+
+    /**
+     * Locate and instantiate a HelperProvider using the supplied ClassLoader.
+     * <p/>
+     * The name of the implementation to use is determined by the value of the "commonj.sdo.impl.HelperProvider"
+     * system property. If this is not set or this code does not have permission to read
it then the name
+     * will be retrieved from the META-INF/services/commonj.sdo.impl.HelperProvider resource
as returned
+     * by the supplied classloader as described
+     *
+     * @param cl the classloader to use to locate and instantiate the implementation
+     * @return the specified implementation of HelperProvider
+     * @throws NoHelperProviderException if no provider implmentation was defined or it could
not be instantiated
+     */
+    public static HelperProvider getInstance(ClassLoader cl) throws NoHelperProviderException
{
+        String implName = getImplementationName();
+        HelperProvider provider = loadImplementation(cl, implName);
+        if (provider == null) {
+            throw new NoHelperProviderException(implName);
+        }
+        return provider;
+    }
+
+    private static ClassLoader getContextClassLoader() {
+        try {
+            return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
{
+                public ClassLoader run() {
+                    return Thread.currentThread().getContextClassLoader();
+                }
+            });
+        } catch (SecurityException e) {
+            return null;
+        }
+    }
+
+    private static HelperProvider loadImplementation(ClassLoader cl, String implName) throws
NoHelperProviderException {
+        // if no name is requested, locate using the supplied classloader
+        if (implName == null) {
+            implName = getImplementationName(cl);
+        }
+        // no implementation to try, return null
+        if (implName == null) {
+            return null;
+        }
+
+        // try an instantiate the implementation
+        try {
+            return (HelperProvider) cl.loadClass(implName).newInstance();
+        } catch (InstantiationException e) {
+            throw new NoHelperProviderException(implName, e);
+        } catch (IllegalAccessException e) {
+            throw new NoHelperProviderException(implName, e);
+        } catch (ClassNotFoundException e) {
+            throw new NoHelperProviderException(implName, e);
+        }
+    }
+
+    private static String getImplementationName() {
+        try {
+            return AccessController.doPrivileged(new PrivilegedAction<String>() {
+                @SuppressWarnings({"AccessOfSystemProperties"})
+                public String run() {
+                    return System.getProperty(PROPERTY_NAME);
+                }
+            });
+        } catch (SecurityException e) {
+            return null;
+        }
+    }
+
+    private static String getImplementationName(ClassLoader cl) {
+        InputStream is = cl.getResourceAsStream(SERVICE_RESOURCE_NAME);
+        if (is == null) {
+            return null;
+        }
+
+        InputStreamReader in;
+        try {
+            in = new InputStreamReader(is, "UTF-8");
+        } catch (UnsupportedEncodingException e) {
+            throw new AssertionError("UTF-8 encoding not available");
+        }
+
+        try {
+            BufferedReader reader = new BufferedReader(in, 128);
+            try {
+                String line;
+                while ((line = reader.readLine()) != null) {
+                    int i = line.indexOf('#');
+                    if (i != -1) {
+                        line = line.substring(0, i);
+                    }
+                    line = line.trim();
+                    if (line.length() > 0) {
+                        return line;
+                    }
+                }
+                return null;
+            } finally {
+                reader.close();
+            }
+        } catch (IOException e) {
+            throw new NoHelperProviderException(e);
+        }
+    }
+
+    // implementation specific methods for users that don't want to use the default implementation
+
+    /**
+     * Returns a CopyHelper obtained from this implementation.
+     *
+     * @return a CopyHelper obtained from this implementation
+     */
+    public abstract CopyHelper copyHelper();
+
+    /**
+     * Returns a DataFactory obtained from this implementation.
+     *
+     * @return a DataFactory obtained from this implementation
+     */
+    public abstract DataFactory dataFactory();
+
+    /**
+     * Returns a DataHelper obtained from this implementation.
+     *
+     * @return a DataHelper obtained from this implementation
+     */
+    public abstract DataHelper dataHelper();
+
+    /**
+     * Returns a EqualityHelper obtained from this implementation.
+     *
+     * @return a EqualityHelper obtained from this implementation
+     */
+    public abstract EqualityHelper equalityHelper();
+
+    /**
+     * Returns a TypeHelper obtained from this implementation.
+     *
+     * @return a TypeHelper obtained from this implementation
+     */
+    public abstract TypeHelper typeHelper();
+
+    /**
+     * Returns a XMLHelper obtained from this implementation.
+     *
+     * @return a XMLHelper obtained from this implementation
+     */
+    public abstract XMLHelper xmlHelper();
+
+    /**
+     * Returns a XSDHelper obtained from this implementation.
+     *
+     * @return a XSDHelper obtained from this implementation
+     */
+    public abstract XSDHelper xsdHelper();
+
+    /**
+     * Create a Resolvable using this implementation
+     *
+     * @return a Resolvable created using this implementation
+     */
+    public abstract ExternalizableDelegator.Resolvable resolvable();
+
+    /**
+     * Create a Resolvable using this implementation
+     *
+     * @param target the object to be resolved
+     * @return a Resolvable created using this implementation
+     */
+    public abstract ExternalizableDelegator.Resolvable resolvable(Object target);
+
+    // static helper methods required by the specification
+
+    /**
+     * Returns a CopyHelper obtained from the default HelperProvider.
+     *
+     * @return a CopyHelper obtained from the default HelperProvider
+     */
+    public static CopyHelper getCopyHelper() {
+        return INSTANCE.copyHelper();
+    }
+
+    /**
+     * Returns a DataFactory obtained from the default HelperProvider.
+     *
+     * @return a DataFactory obtained from the default HelperProvider
+     */
+    public static DataFactory getDataFactory() {
+        return INSTANCE.dataFactory();
+    }
+
+    /**
+     * Returns a DataHelper obtained from the default HelperProvider.
+     *
+     * @return a DataHelper obtained from the default HelperProvider
+     */
+    public static DataHelper getDataHelper() {
+        return INSTANCE.dataHelper();
+    }
+
+    /**
+     * Returns a EqualityHelper obtained from the default HelperProvider.
+     *
+     * @return a EqualityHelper obtained from the default HelperProvider
+     */
+    public static EqualityHelper getEqualityHelper() {
+        return INSTANCE.equalityHelper();
+    }
+
+    /**
+     * Returns a TypeHelper obtained from the default HelperProvider.
+     *
+     * @return a TypeHelper obtained from the default HelperProvider
+     */
+    public static TypeHelper getTypeHelper() {
+        return INSTANCE.typeHelper();
+    }
+
+    /**
+     * Returns a XMLHelper obtained from the default HelperProvider.
+     *
+     * @return a XMLHelper obtained from the default HelperProvider
+     */
+    public static XMLHelper getXMLHelper() {
+        return INSTANCE.xmlHelper();
+    }
+
+    /**
+     * Returns a XSDHelper obtained from the default HelperProvider.
+     *
+     * @return a XSDHelper obtained from the default HelperProvider
+     */
+    public static XSDHelper getXSDHelper() {
+        return INSTANCE.xsdHelper();
+    }
+
+    /**
+     * Create a Resolvable using the default HelperProvider
+     *
+     * @return a Resolvable created using the default HelperProvider
+     */
+    public static ExternalizableDelegator.Resolvable createResolvable() {
+        return INSTANCE.resolvable();
+    }
+
+    /**
+     * Create a Resolvable using the default HelperProvider
+     *
+     * @param target the object to be resolved
+     * @return a Resolvable created using the default HelperProvider
+     */
+    public static ExternalizableDelegator.Resolvable createResolvable(Object target) {
+        return INSTANCE.resolvable(target);
+    }
+}
\ No newline at end of file

Added: incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/NoHelperProviderException.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/NoHelperProviderException.java?rev=375756&view=auto
==============================================================================
--- incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/NoHelperProviderException.java
(added)
+++ incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/NoHelperProviderException.java
Tue Feb  7 14:37:37 2006
@@ -0,0 +1,54 @@
+/**
+ *
+ * Copyright 2005 International Business Machines Corporation
+ *
+ *  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 commonj.sdo.impl;
+
+/**
+ * Exception indicating that a HelperProvider could not be located or instantiated.
+ * The message will be set to the name of the implementation class; a null value
+ * indicates that the name of the implementation could not be determined.
+ * The cause will be set to the Throwable that prevented the provider from being
+ * located or created.
+ *
+ * @version $Revision$ $Date$
+ */
+public class NoHelperProviderException extends RuntimeException {
+    private static final long serialVersionUID = 727646133930924084L;
+
+    public NoHelperProviderException() {
+    }
+
+    public NoHelperProviderException(String message) {
+        super(message);
+    }
+
+    public NoHelperProviderException(String message, Throwable cause) {
+        super(message, cause);
+    }
+
+    public NoHelperProviderException(Throwable cause) {
+        super(cause);
+    }
+
+    /**
+     * Return the name of the implementation class that could not be provided.
+     *
+     * @return the name of the implementation class; may be null if not known
+     */
+    public String getImplementationName() {
+        return getMessage();
+    }
+}

Propchange: incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/NoHelperProviderException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/spec/sdo/src/main/java/commonj/sdo/impl/NoHelperProviderException.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/spec/sdo/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/spec/sdo/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java?rev=375756&view=auto
==============================================================================
--- incubator/tuscany/java/spec/sdo/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java
(added)
+++ incubator/tuscany/java/spec/sdo/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java
Tue Feb  7 14:37:37 2006
@@ -0,0 +1,87 @@
+/**
+ *
+ * Copyright 2005 International Business Machines Corporation
+ *
+ *  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 commonj.sdo.impl;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+
+import junit.framework.TestCase;
+import test.DefaultHelperProvider;
+import test.TCCL1HelperProvider;
+
+/**
+ * @version $Revision$ $Date$
+ */
+@SuppressWarnings({"ClassLoader2Instantiation"})
+public class HelperProviderTestCase extends TestCase {
+    private URL classes;
+    private URL testClasses;
+    private URL tccl1;
+
+    public void testInstanceIsNullWithNoImplementation() throws Exception {
+        ClassLoader cl = new URLClassLoader(new URL[]{classes}, null);
+        Class<?> providerClass = cl.loadClass("commonj.sdo.impl.HelperProvider");
+        assertNull(providerClass.getField("INSTANCE").get(null));
+    }
+
+    public void testDefaultInstance() {
+        assertNotNull(HelperProvider.INSTANCE);
+        assertEquals(DefaultHelperProvider.class, HelperProvider.INSTANCE.getClass());
+    }
+
+    public void testLocateFromClassLoader() throws Exception {
+        ClassLoader cl = new URLClassLoader(new URL[]{classes, tccl1, testClasses}, null);
+        Class<?> providerClass = cl.loadClass(HelperProvider.class.getName());
+        Object provider = providerClass.getMethod("getInstance", ClassLoader.class).invoke(null,
cl);
+        assertNotNull(provider);
+        assertEquals(TCCL1HelperProvider.class.getName(), provider.getClass().getName());
+    }
+
+    public void testThreadContextInstance() throws Exception {
+        ClassLoader cl = new URLClassLoader(new URL[]{classes, tccl1, testClasses}, null);
+        ClassLoader tccl = Thread.currentThread().getContextClassLoader();
+        try {
+            Thread.currentThread().setContextClassLoader(cl);
+            Class<?> providerClass = cl.loadClass(HelperProvider.class.getName());
+            Object provider = providerClass.getMethod("getInstance").invoke(null);
+            assertNotNull(provider);
+            assertEquals(TCCL1HelperProvider.class.getName(), provider.getClass().getName());
+        } finally {
+            Thread.currentThread().setContextClassLoader(tccl);
+        }
+
+    }
+
+    @SuppressWarnings({"AccessOfSystemProperties"})
+    public void testSystemProperty() {
+        System.setProperty("commonj.sdo.impl.HelperProvider", "test.TCCL1HelperProvider");
+        try {
+            HelperProvider provider = HelperProvider.getInstance();
+            assertNotNull(provider);
+            assertEquals(TCCL1HelperProvider.class, provider.getClass());
+        } finally {
+            System.getProperties().remove("commonj.sdo.impl.HelperProvider");
+        }
+    }
+
+    protected void setUp() throws Exception {
+        super.setUp();
+        classes = new URL(HelperProvider.class.getResource("HelperProvider.class"), "../../..");
+        testClasses = new URL(HelperProviderTestCase.class.getResource("HelperProviderTestCase.class"),
"../../..");
+        tccl1 = new URL(testClasses, "tccl1/");
+    }
+}

Propchange: incubator/tuscany/java/spec/sdo/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/spec/sdo/src/test/java/commonj/sdo/impl/HelperProviderTestCase.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/spec/sdo/src/test/java/test/DefaultHelperProvider.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/spec/sdo/src/test/java/test/DefaultHelperProvider.java?rev=375756&view=auto
==============================================================================
--- incubator/tuscany/java/spec/sdo/src/test/java/test/DefaultHelperProvider.java (added)
+++ incubator/tuscany/java/spec/sdo/src/test/java/test/DefaultHelperProvider.java Tue Feb
 7 14:37:37 2006
@@ -0,0 +1,58 @@
+/* =====================================================================
+ *
+ * Copyright (c) 2005 Jeremy Boynes.  All rights reserved.
+ *
+ * =====================================================================
+ */
+package test;
+
+import commonj.sdo.impl.HelperProvider;
+import commonj.sdo.impl.ExternalizableDelegator;
+import commonj.sdo.helper.CopyHelper;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.DataHelper;
+import commonj.sdo.helper.EqualityHelper;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class DefaultHelperProvider extends HelperProvider {
+    public CopyHelper copyHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public DataFactory dataFactory() {
+        throw new UnsupportedOperationException();
+    }
+
+    public DataHelper dataHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public EqualityHelper equalityHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public TypeHelper typeHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public XMLHelper xmlHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public XSDHelper xsdHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public ExternalizableDelegator.Resolvable resolvable() {
+        throw new UnsupportedOperationException();
+    }
+
+    public ExternalizableDelegator.Resolvable resolvable(Object target) {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: incubator/tuscany/java/spec/sdo/src/test/java/test/DefaultHelperProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/spec/sdo/src/test/java/test/DefaultHelperProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/spec/sdo/src/test/java/test/TCCL1HelperProvider.java
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/spec/sdo/src/test/java/test/TCCL1HelperProvider.java?rev=375756&view=auto
==============================================================================
--- incubator/tuscany/java/spec/sdo/src/test/java/test/TCCL1HelperProvider.java (added)
+++ incubator/tuscany/java/spec/sdo/src/test/java/test/TCCL1HelperProvider.java Tue Feb  7
14:37:37 2006
@@ -0,0 +1,58 @@
+/* =====================================================================
+ *
+ * Copyright (c) 2005 Jeremy Boynes.  All rights reserved.
+ *
+ * =====================================================================
+ */
+package test;
+
+import commonj.sdo.impl.HelperProvider;
+import commonj.sdo.impl.ExternalizableDelegator;
+import commonj.sdo.helper.CopyHelper;
+import commonj.sdo.helper.DataFactory;
+import commonj.sdo.helper.DataHelper;
+import commonj.sdo.helper.EqualityHelper;
+import commonj.sdo.helper.TypeHelper;
+import commonj.sdo.helper.XMLHelper;
+import commonj.sdo.helper.XSDHelper;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class TCCL1HelperProvider extends HelperProvider {
+    public CopyHelper copyHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public DataFactory dataFactory() {
+        throw new UnsupportedOperationException();
+    }
+
+    public DataHelper dataHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public EqualityHelper equalityHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public TypeHelper typeHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public XMLHelper xmlHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public XSDHelper xsdHelper() {
+        throw new UnsupportedOperationException();
+    }
+
+    public ExternalizableDelegator.Resolvable resolvable() {
+        throw new UnsupportedOperationException();
+    }
+
+    public ExternalizableDelegator.Resolvable resolvable(Object target) {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: incubator/tuscany/java/spec/sdo/src/test/java/test/TCCL1HelperProvider.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/tuscany/java/spec/sdo/src/test/java/test/TCCL1HelperProvider.java
------------------------------------------------------------------------------
    svn:keywords = Rev,Date

Added: incubator/tuscany/java/spec/sdo/src/test/resources/META-INF/services/commonj.sdo.impl.HelperProvider
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/spec/sdo/src/test/resources/META-INF/services/commonj.sdo.impl.HelperProvider?rev=375756&view=auto
==============================================================================
--- incubator/tuscany/java/spec/sdo/src/test/resources/META-INF/services/commonj.sdo.impl.HelperProvider
(added)
+++ incubator/tuscany/java/spec/sdo/src/test/resources/META-INF/services/commonj.sdo.impl.HelperProvider
Tue Feb  7 14:37:37 2006
@@ -0,0 +1,3 @@
+# test comment and blank line
+
+  test.DefaultHelperProvider # comment

Added: incubator/tuscany/java/spec/sdo/src/test/resources/tccl1/META-INF/services/commonj.sdo.impl.HelperProvider
URL: http://svn.apache.org/viewcvs/incubator/tuscany/java/spec/sdo/src/test/resources/tccl1/META-INF/services/commonj.sdo.impl.HelperProvider?rev=375756&view=auto
==============================================================================
--- incubator/tuscany/java/spec/sdo/src/test/resources/tccl1/META-INF/services/commonj.sdo.impl.HelperProvider
(added)
+++ incubator/tuscany/java/spec/sdo/src/test/resources/tccl1/META-INF/services/commonj.sdo.impl.HelperProvider
Tue Feb  7 14:37:37 2006
@@ -0,0 +1 @@
+test.TCCL1HelperProvider
\ No newline at end of file



Mime
View raw message