001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package javax.sql.rowset.spi;
019:
020: import javax.sql.RowSetReader;
021: import javax.sql.RowSetWriter;
022:
023: import org.apache.harmony.sql.internal.nls.Messages;
024:
025: class ProviderImpl extends SyncProvider {
026:
027: private String className;
028:
029: private String vendor;
030:
031: private String version;
032:
033: private SyncProvider impl;
034:
035: private String errMsg;
036:
037: public ProviderImpl() {
038: // default constructor
039: }
040:
041: public ProviderImpl(String name) {
042: className = name;
043:
044: try {
045: Class<?> implClass = Class.forName(className, true, Thread
046: .currentThread().getContextClassLoader());
047: impl = (SyncProvider) implClass.newInstance();
048: } catch (ClassNotFoundException e) {
049: errMsg = Messages.getString("sql.40", className); //$NON-NLS-1$
050: } catch (Exception e) {
051: // ignore
052: }
053: }
054:
055: public ProviderImpl(String name, String vendor, String version) {
056: this (name);
057:
058: this .vendor = vendor;
059: this .version = version;
060: }
061:
062: public SyncProvider getImpl() throws SyncFactoryException {
063: if (null == impl) {
064: throw new SyncFactoryException(Messages.getString(
065: "sql.40", className)); //$NON-NLS-1$
066: }
067: return impl;
068: }
069:
070: @Override
071: public int getDataSourceLock() throws SyncProviderException {
072: checkClassNameValid();
073: return impl.getDataSourceLock();
074: }
075:
076: @Override
077: public int getProviderGrade() {
078: return impl == null ? 0 : impl.getProviderGrade();
079: }
080:
081: @Override
082: public String getProviderID() {
083: return impl == null ? className : impl.getProviderID();
084: }
085:
086: @Override
087: public RowSetReader getRowSetReader() {
088: return impl == null ? null : impl.getRowSetReader();
089: }
090:
091: @Override
092: public RowSetWriter getRowSetWriter() {
093: return impl == null ? null : impl.getRowSetWriter();
094: }
095:
096: @Override
097: public String getVendor() {
098: return impl == null ? vendor : impl.getVendor();
099: }
100:
101: @Override
102: public String getVersion() {
103: return impl == null ? version : impl.getVersion();
104: }
105:
106: @Override
107: public void setDataSourceLock(int dataSourceLock)
108: throws SyncProviderException {
109: checkClassNameValid();
110: impl.setDataSourceLock(dataSourceLock);
111: }
112:
113: @Override
114: public int supportsUpdatableView() {
115: return impl == null ? 0 : impl.supportsUpdatableView();
116: }
117:
118: private void checkClassNameValid() throws SyncProviderException {
119: if (null == impl) {
120: throw new SyncProviderException(errMsg);
121: }
122: }
123:
124: }
|