harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r537286 - in /harmony/enhanced/classlib/trunk: depends/files/ make/ modules/sql/src/main/java/javax/sql/rowset/spi/ modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/
Date Fri, 11 May 2007 20:51:47 GMT
Author: tellison
Date: Fri May 11 13:51:46 2007
New Revision: 537286

URL: http://svn.apache.org/viewvc?view=rev&rev=537286
Log:
Apply modified patch for HARMONY-3828 ([classlib][sql] 3 new methods in javax.sql.rowset.spi.SyncFactory)

Added:
    harmony/enhanced/classlib/trunk/depends/files/rowset.properties   (with props)
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/ProviderImpl.java
  (with props)
Modified:
    harmony/enhanced/classlib/trunk/make/build-java.xml
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/SyncFactory.java
    harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties

Added: harmony/enhanced/classlib/trunk/depends/files/rowset.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/depends/files/rowset.properties?view=auto&rev=537286
==============================================================================
--- harmony/enhanced/classlib/trunk/depends/files/rowset.properties (added)
+++ harmony/enhanced/classlib/trunk/depends/files/rowset.properties Fri May 11 13:51:46 2007
@@ -0,0 +1,23 @@
+# 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.
+
+
+rowset.provider.classname.0=
+rowset.provider.vendor.0=
+rowset.provider.version.0=
+
+rowset.provider.classname.1=
+rowset.provider.vendor.1=
+rowset.provider.version.1=

Propchange: harmony/enhanced/classlib/trunk/depends/files/rowset.properties
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/make/build-java.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/make/build-java.xml?view=diff&rev=537286&r1=537285&r2=537286
==============================================================================
--- harmony/enhanced/classlib/trunk/make/build-java.xml (original)
+++ harmony/enhanced/classlib/trunk/make/build-java.xml Fri May 11 13:51:46 2007
@@ -280,6 +280,12 @@
                 <include name="net.properties" />
             </fileset>
         </copy>
+
+        <copy todir="${hy.jdk}/jre/lib">
+            <fileset dir="${depends.files}">
+                <include name="rowset.properties" />
+            </fileset>
+        </copy>
     </target>
 
 

Added: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/ProviderImpl.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/ProviderImpl.java?view=auto&rev=537286
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/ProviderImpl.java
(added)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/ProviderImpl.java
Fri May 11 13:51:46 2007
@@ -0,0 +1,98 @@
+package javax.sql.rowset.spi;
+
+import javax.sql.RowSetReader;
+import javax.sql.RowSetWriter;
+
+import org.apache.harmony.sql.internal.nls.Messages;
+
+class ProviderImpl extends SyncProvider {
+
+    private String className;
+
+    private String vendor;
+
+    private String version;
+
+    private SyncProvider impl;
+
+    private String errMsg;
+
+    public ProviderImpl() {
+        // default constructor
+    }
+
+    public ProviderImpl(String name) {
+        className = name;
+
+        try {
+            Class<?> implClass = Class.forName(className);
+            impl = (SyncProvider) implClass.newInstance();
+        } catch (ClassNotFoundException e) {
+            errMsg = Messages.getString("sql.40", className); //$NON-NLS-1$
+        } catch (Exception e) {
+            // ignore
+        }
+    }
+    
+    public ProviderImpl(String name, String vendor, String version) {
+        this(name);
+        
+        this.vendor = vendor;
+        this.version = version;
+    }
+
+    @Override
+    public int getDataSourceLock() throws SyncProviderException {
+        checkClassNameValid();
+        return impl.getDataSourceLock();
+    }
+
+    @Override
+    public int getProviderGrade() {
+        return impl == null ? 0 : impl.getProviderGrade();
+    }
+
+    @Override
+    public String getProviderID() {
+        return impl == null ? className : impl.getProviderID();
+    }
+
+    @Override
+    public RowSetReader getRowSetReader() {
+        return impl == null ? null : impl.getRowSetReader();
+    }
+
+    @Override
+    public RowSetWriter getRowSetWriter() {
+        return impl == null ? null : impl.getRowSetWriter();
+    }
+
+    @Override
+    public String getVendor() {
+        return impl == null ? vendor : impl.getVendor();
+    }
+
+    @Override
+    public String getVersion() {
+        return impl == null ? version : impl.getVersion();
+    }
+
+    @Override
+    public void setDataSourceLock(int dataSourceLock)
+            throws SyncProviderException {
+        checkClassNameValid();
+        impl.setDataSourceLock(dataSourceLock);
+    }
+
+    @Override
+    public int supportsUpdatableView() {
+        return impl == null ? 0 : impl.supportsUpdatableView();
+    }
+
+    private void checkClassNameValid() throws SyncProviderException {
+        if (null == impl) {
+            throw new SyncProviderException(errMsg);
+        }
+    }
+
+}

Propchange: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/ProviderImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/SyncFactory.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/SyncFactory.java?view=diff&rev=537286&r1=537285&r2=537286
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/SyncFactory.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/javax/sql/rowset/spi/SyncFactory.java
Fri May 11 13:51:46 2007
@@ -17,41 +17,162 @@
 
 package javax.sql.rowset.spi;
 
+import java.io.FileInputStream;
+import java.io.IOException;
 import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Properties;
 import java.util.logging.Level;
 import java.util.logging.Logger;
+
+import javax.naming.Binding;
 import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+
+import org.apache.harmony.sql.internal.nls.Messages;
 
+/**
+ * A singleton factory class that generates SyncProvider instances. There are
+ * three places to search SyncProviders: system properties, resource files and
+ * the JNDI context.
+ * 
+ * Applications can also use it to add and remove SyncProviders at runtime. By
+ * default there are two providers offered by RI:
+ * com.sun.rowset.providers.RIOptimisticProvider and
+ * com.sun.rowset.providers.RIXMLProvider. The former is the default provider
+ * for RowSet that does not specify any provider while the latter is usually
+ * used for WebRowSet instances.
+ * 
+ */
 public class SyncFactory {
     public static String ROWSET_SYNC_PROVIDER = "rowset.provider.classname"; //$NON-NLS-1$
 
     public static String ROWSET_SYNC_VENDOR = "rowset.provider.vendor"; //$NON-NLS-1$
 
     public static String ROWSET_SYNC_PROVIDER_VERSION = "rowset.provider.version"; //$NON-NLS-1$
-    
+
+    private static SyncFactory instance = new SyncFactory();
+
+    private static final String ROWSET_PROPERTIES = "rowset.properties"; //$NON-NLS-1$
+
+    private static Hashtable<String, SyncProvider> providers = new Hashtable<String,
SyncProvider>();
+
+    private static Context ctx;
+
+    private static String resLocation;
+
+    private static boolean initialized;
+
+    static {
+        // the properties file is located at ${java.home}/lib/rowset.properties
+        // In RI, it is in ${java.home}/lib/resources.jar/rowset.properties
+        resLocation = new StringBuilder(System.getProperty("java.home")).append( //$NON-NLS-1$
+                        System.getProperty("file.separator")).append("lib").append( //$NON-NLS-1$
//$NON-NLS-2$
+                        System.getProperty("file.separator")).append(ROWSET_PROPERTIES) //$NON-NLS-1$
+                .toString();
+    }
+
+    private static String getProviderProperties(Properties prop, String inital,
+            int index) {
+        StringBuilder builder = new StringBuilder(inital);
+        builder.append("."); //$NON-NLS-1$
+        builder.append(index);
+
+        return prop.getProperty(builder.toString());
+    }
+
+    private static Enumeration<SyncProvider> getRegisteredProvidersImpl() {
+        if (!initialized) {
+            // 1. load from System property
+            String sysProvider = System.getProperty(ROWSET_SYNC_PROVIDER);
+            if (sysProvider != null) {
+                providers.put(sysProvider, new ProviderImpl(sysProvider));
+            }
+
+            // 2. looks in the resource file
+            Properties rowsetProp = new Properties();
+            try {
+                FileInputStream resInput = new FileInputStream(resLocation);
+                rowsetProp.load(resInput);
+                resInput.close();
+            } catch (IOException e) {
+                // ignore
+            }
+            int index = 0;
+            while (true) {
+                String className = getProviderProperties(rowsetProp,
+                        ROWSET_SYNC_PROVIDER, index);
+                if (null == className) {
+                    break;
+                }
+
+                String vendor = getProviderProperties(rowsetProp,
+                        ROWSET_SYNC_VENDOR, index);
+                String version = getProviderProperties(rowsetProp,
+                        ROWSET_SYNC_PROVIDER_VERSION, index);
+                providers.put(className, new ProviderImpl(className, vendor,
+                        version));
+                index++;
+            }
+
+            // 3. checks the JNDI context that has been set
+            if (ctx != null) {
+                try {
+                    NamingEnumeration<Binding> bindings = ctx.listBindings("");
+                    while (bindings.hasMore()) {
+                        Binding bind = bindings.next();
+                        providers.put(bind.getName(), (SyncProvider) bind
+                                .getObject());
+                    }
+                } catch (NamingException e) {
+                    // ignore
+                }
+            }
+            initialized = true;
+        }
+        return providers.elements();
+    }
+
     // This class does not have public constructor
     private SyncFactory() {
+        // do nothing
     }
 
-    public static void registerProvider(String providerID) throws SyncFactoryException {
+    public static void registerProvider(String providerID)
+            throws SyncFactoryException {
         throw new UnsupportedOperationException();
     }
 
+    /**
+     * Answers the singleton instance of the SyncFactory.
+     * 
+     * @return - the singleton instance of the SyncFactory.
+     */
     public static SyncFactory getSyncFactory() {
-        throw new UnsupportedOperationException();
+        return instance;
     }
 
-    public static void unregisterProvider(String providerID) throws SyncFactoryException
{
+    public static void unregisterProvider(String providerID)
+            throws SyncFactoryException {
         throw new UnsupportedOperationException();
     }
 
-    public static SyncProvider getInstance(String providerID) throws SyncFactoryException
{
+    public static SyncProvider getInstance(String providerID)
+            throws SyncFactoryException {
         throw new UnsupportedOperationException();
     }
 
+    /**
+     * Answers the collection of SyncProvider instances that can be retrieved.
+     * RowSet implementation is able to use any member in this enumeration.
+     * 
+     * @return - the collection of SyncProvider registered in SyncFactory.
+     * @throws SyncFactoryException
+     */
     public static Enumeration<SyncProvider> getRegisteredProviders()
             throws SyncFactoryException {
-        throw new UnsupportedOperationException();
+        return getRegisteredProvidersImpl();
     }
 
     public static void setLogger(Logger logger) {
@@ -66,7 +187,19 @@
         throw new UnsupportedOperationException();
     }
 
+    /**
+     * Sets the JNDI context from which the implementation of SyncProvider can
+     * be got.
+     * 
+     * @param ctx -
+     *            the JNDI context
+     * @throws SyncFactoryException -
+     *             if the given JNDI context is null
+     */
     public static void setJNDIContext(Context ctx) throws SyncFactoryException {
-        throw new UnsupportedOperationException();
+        if (null == ctx) {
+            throw new SyncFactoryException(Messages.getString("sql.41")); //$NON-NLS-1$
+        }
+        SyncFactory.ctx = ctx;
     }
 }

Modified: harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties?view=diff&rev=537286&r1=537285&r2=537286
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
(original)
+++ harmony/enhanced/classlib/trunk/modules/sql/src/main/java/org/apache/harmony/sql/internal/nls/messages.properties
Fri May 11 13:51:46 2007
@@ -47,7 +47,9 @@
 sql.30=Invalid column display size. Cannot be less than zero
 sql.31=Invalid precision value. Cannot be less than zero
 sql.32=Invalid scale size. Cannot be less than zero
+sql.40=ClassNotFoundException: {0}
+sql.41=Invalid JNDI context supplied
 sql.33=Cannot instantiate a SQLOutputImpl instance with null parameters
 sql.34=Cannot instantiate a SQLInputImpl instance with null parameters
 sql.35=SQLInputImpl exception: Invalid read position
-sql.37=Operation not supported
\ No newline at end of file
+sql.37=Operation not supported



Mime
View raw message