⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 syncfactory.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */        public static Enumeration<SyncProvider> getRegisteredProviders()         throws SyncFactoryException {        initMapIfNecessary();        // return a collection of classnames        // of type SyncProvider        return implementations.elements();    }            /**     * Sets the logging object to be used by the <code>SyncProvider</code>      * implementation provided by the <code>SyncFactory</code>. All     * <code>SyncProvider</code> implementations can log their events to      * this object and the application can retrieve a handle to this      * object using the <code>getLogger</code> method.     *      * @param logger A Logger object instance     */    public static void setLogger(Logger logger) {        rsLogger = logger;    }    /**     * Sets the logging object that is used by <code>SyncProvider</code>     * implementations provided by the <code>SyncFactory</code> SPI. All     * <code>SyncProvider</code> implementations can log their events       * to this object and the application can retrieve a handle to this     * object using the <code>getLogger</code> method.     *     * @param logger a Logger object instance     * @param level a Level object instance indicating the degree of logging     * required     */    public static void setLogger(Logger logger, Level level) {	// singleton        	rsLogger = logger;	rsLogger.setLevel(level);    }    /**     * Returns the logging object for applications to retrieve      * synchronization events posted by SyncProvider implementations.     *     * @throws SyncFactoryException if no logging object has been set.     */    public static Logger getLogger() throws SyncFactoryException {	// only one logger per session	if(rsLogger == null){	   throw new SyncFactoryException("(SyncFactory) : No logger has been set");	}	return rsLogger;    }   /**    * Sets the initial JNDI context from which SyncProvider implementations     * can be retrieved from a JNDI namespace    *    * @param ctx a valid JNDI context    * @throws SyncFactoryException if the supplied JNDI context is null    */    public static void setJNDIContext(javax.naming.Context ctx) 	throws SyncFactoryException {	if (ctx == null) {	    throw new SyncFactoryException("Invalid JNDI context supplied");	}	ic = ctx;                jndiCtxEstablished = true;   }        /**     * Controls JNDI context intialization.     *     * @throws SyncFactoryException if an error occurs parsing the JNDI context     */        private static void initJNDIContext() throws SyncFactoryException {                                        if (jndiCtxEstablished && (ic != null) && (lazyJNDICtxRefresh == false)) {            try {                                                parseProperties(parseJNDIContext());                lazyJNDICtxRefresh = true; // touch JNDI namespace once.            } catch (NamingException e) {		e.printStackTrace();                throw new SyncFactoryException("SPI: NamingException: " + e.getExplanation());            } catch (Exception e) {		e.printStackTrace();	throw new SyncFactoryException("SPI: Exception: " + e.getMessage());	    }        }               }    /**     * Internal switch indicating whether the JNDI namespace should be re-read.     */    private static boolean lazyJNDICtxRefresh = false;            /**     * Parses the set JNDI Context and passes bindings to the enumerateBindings     * method when complete.     */    private static Properties parseJNDIContext() throws NamingException {                        NamingEnumeration bindings = ic.listBindings("");        Properties properties = new Properties();                        // Hunt one level below context for available SyncProvider objects                            	enumerateBindings(bindings, properties);        return properties;    }    /**     * Scans each binding on JNDI context and determines if any binding is an      * instance of SyncProvider, if so, add this to the registry and continue to     * scan the current context using a re-entrant call to this method until all     * bindings have been enumerated.          */    private static void enumerateBindings(NamingEnumeration bindings, 	Properties properties) throws NamingException {	boolean syncProviderObj = false; // move to parameters ?	try {	    Binding bd = null;	    Object elementObj = null;	    String element = null;	    while (bindings.hasMore()) {	        bd = (Binding)bindings.next();	        element = bd.getName();	        elementObj = bd.getObject();	        if (!(ic.lookup(element) instanceof Context)) {		     // skip directories/sub-contexts	             if (ic.lookup(element) instanceof SyncProvider) {			syncProviderObj = true;		     }		}		if (syncProviderObj) {		    SyncProvider sync = (SyncProvider)elementObj;		    properties.put(SyncFactory.ROWSET_SYNC_PROVIDER,			sync.getProviderID());		    syncProviderObj = false; // reset		}            }	} catch (javax.naming.NotContextException e) {	    bindings.next();	    // Re-entrant call into method	    enumerateBindings(bindings, properties);	}    }}   /**     * Internal class that defines the lazy reference construct for each registered      * SyncProvider implementation.     */   class ProviderImpl extends SyncProvider {        private String className = null;        private String vendorName = null;        private String ver = null;        private int index;        public void setClassname(String classname) {            className = classname;        }        public String getClassname() {            return className;        }        public void setVendor(String vendor) {            vendorName = vendor;        }        public String getVendor() {            return vendorName;        }        public void setVersion(String providerVer) {            ver = providerVer;        }                    public String getVersion() {            return ver;        }        public void setIndex(int i) {            index = i;        }                    public int getIndex() {            return index;        }                public int getDataSourceLock() throws SyncProviderException {                   int dsLock = 0;            try             {               dsLock = SyncFactory.getInstance(className).getDataSourceLock();            } catch(SyncFactoryException sfEx) {                             throw new SyncProviderException(sfEx.getMessage());             }                         return dsLock;        }                public int getProviderGrade() {                   int grade = 0;                      try            {              grade =  SyncFactory.getInstance(className).getProviderGrade();           } catch(SyncFactoryException sfEx) {               //            }                      return grade;        }                public String getProviderID() {            return className;        }                /*        public javax.sql.RowSetInternal getRowSetInternal() {            try            {                        return SyncFactory.getInstance(className).getRowSetInternal();           } catch(SyncFactoryException sfEx) {               //            }        }        */                public javax.sql.RowSetReader getRowSetReader() {                RowSetReader rsReader = null;;                try         {            rsReader = SyncFactory.getInstance(className).getRowSetReader();         } catch(SyncFactoryException sfEx) {               //          }                    return rsReader;                 }                public javax.sql.RowSetWriter getRowSetWriter() {                RowSetWriter rsWriter = null;        try            {             rsWriter =  SyncFactory.getInstance(className).getRowSetWriter();                   } catch(SyncFactoryException sfEx) {               //            }                      return rsWriter;        }        public void setDataSourceLock(int param)         throws SyncProviderException {                   try            {                SyncFactory.getInstance(className).setDataSourceLock(param);           } catch(SyncFactoryException sfEx) {                              throw new SyncProviderException(sfEx.getMessage());           }           }                public int supportsUpdatableView() {                int view = 0;                try          {            view = SyncFactory.getInstance(className).supportsUpdatableView();         } catch(SyncFactoryException sfEx) {               //          }                  return view;         }             }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -