merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / DevelopersGuide / Database / DriverSkeleton / SDriver.cxx
blobd6d64430f15f874c77e704ad6277f6892f380177
1 /*************************************************************************
3 * $RCSfile: SDriver.cxx,v $
5 * $Revision: 1.5 $
7 * last change: $Author: kz $ $Date: 2006-11-06 15:00:59 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 #include "SDriver.hxx"
42 #include "SConnection.hxx"
44 using namespace com::sun::star::uno;
45 using namespace com::sun::star::lang;
46 using namespace com::sun::star::beans;
47 using namespace com::sun::star::sdbc;
48 using namespace connectivity::skeleton;
50 namespace connectivity
52 namespace skeleton
54 //------------------------------------------------------------------
55 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > SAL_CALL SkeletonDriver_CreateInstance(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxFactory) throw( ::com::sun::star::uno::Exception )
57 return *(new SkeletonDriver());
61 // --------------------------------------------------------------------------------
62 SkeletonDriver::SkeletonDriver()
63 : ODriver_BASE(m_aMutex)
66 // --------------------------------------------------------------------------------
67 void SkeletonDriver::disposing()
69 ::osl::MutexGuard aGuard(m_aMutex);
71 // when driver will be destroied so all our connections have to be destroied as well
72 for (OWeakRefArray::iterator i = m_xConnections.begin(); m_xConnections.end() != i; ++i)
74 Reference< XComponent > xComp(i->get(), UNO_QUERY);
75 if (xComp.is())
76 xComp->dispose();
78 m_xConnections.clear();
80 ODriver_BASE::disposing();
83 // static ServiceInfo
84 //------------------------------------------------------------------------------
85 rtl::OUString SkeletonDriver::getImplementationName_Static( ) throw(RuntimeException)
87 return rtl::OUString::createFromAscii("com.sun.star.comp.sdbc.SkeletonDriver");
88 // this name is referenced in the configuration and in the skeleton.xml
89 // Please take care when changing it.
91 //------------------------------------------------------------------------------
92 Sequence< ::rtl::OUString > SkeletonDriver::getSupportedServiceNames_Static( ) throw (RuntimeException)
94 // which service is supported
95 // for more information @see com.sun.star.sdbc.Driver
96 Sequence< ::rtl::OUString > aSNS( 1 );
97 aSNS[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
98 return aSNS;
101 //------------------------------------------------------------------
102 ::rtl::OUString SAL_CALL SkeletonDriver::getImplementationName( ) throw(RuntimeException)
104 return getImplementationName_Static();
107 //------------------------------------------------------------------
108 sal_Bool SAL_CALL SkeletonDriver::supportsService( const ::rtl::OUString& _rServiceName ) throw(RuntimeException)
110 Sequence< ::rtl::OUString > aSupported(getSupportedServiceNames());
111 const ::rtl::OUString* pSupported = aSupported.getConstArray();
112 const ::rtl::OUString* pEnd = pSupported + aSupported.getLength();
113 for (;pSupported != pEnd && !pSupported->equals(_rServiceName); ++pSupported)
116 return pSupported != pEnd;
119 //------------------------------------------------------------------
120 Sequence< ::rtl::OUString > SAL_CALL SkeletonDriver::getSupportedServiceNames( ) throw(RuntimeException)
122 return getSupportedServiceNames_Static();
125 // --------------------------------------------------------------------------------
126 Reference< XConnection > SAL_CALL SkeletonDriver::connect( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
128 // create a new connection with the given properties and append it to our vector
129 OConnection* pCon = new OConnection(this);
130 Reference< XConnection > xCon = pCon; // important here because otherwise the connection could be deleted inside (refcount goes -> 0)
131 pCon->construct(url,info); // late constructor call which can throw exception and allows a correct dtor call when so
132 m_xConnections.push_back(WeakReferenceHelper(*pCon));
134 return xCon;
136 // --------------------------------------------------------------------------------
137 sal_Bool SAL_CALL SkeletonDriver::acceptsURL( const ::rtl::OUString& url )
138 throw(SQLException, RuntimeException)
140 // here we have to look if we support this url format
141 // change the URL format to your needs, but please aware that the first on who accepts the URl wins.
142 return (!url.compareTo(::rtl::OUString::createFromAscii("sdbc:skeleton:"),14));
144 // --------------------------------------------------------------------------------
145 Sequence< DriverPropertyInfo > SAL_CALL SkeletonDriver::getPropertyInfo( const ::rtl::OUString& url, const Sequence< PropertyValue >& info ) throw(SQLException, RuntimeException)
147 // if you have somthing special to say, return it here :-)
148 return Sequence< DriverPropertyInfo >();
150 // --------------------------------------------------------------------------------
151 sal_Int32 SAL_CALL SkeletonDriver::getMajorVersion( ) throw(RuntimeException)
153 return 0; // depends on you
155 // --------------------------------------------------------------------------------
156 sal_Int32 SAL_CALL SkeletonDriver::getMinorVersion( ) throw(RuntimeException)
158 return 1; // depends on you
160 // --------------------------------------------------------------------------------
162 //.........................................................................
163 namespace connectivity
165 namespace skeleton
167 //.........................................................................
169 void release(oslInterlockedCount& _refCount,
170 ::cppu::OBroadcastHelper& rBHelper,
171 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
172 ::com::sun::star::lang::XComponent* _pObject)
174 if (osl_decrementInterlockedCount( &_refCount ) == 0)
176 osl_incrementInterlockedCount( &_refCount );
178 if (!rBHelper.bDisposed && !rBHelper.bInDispose)
180 // remember the parent
181 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xParent;
183 ::osl::MutexGuard aGuard( rBHelper.rMutex );
184 xParent = _xInterface;
185 _xInterface = NULL;
188 // First dispose
189 _pObject->dispose();
191 // only the alive ref holds the object
192 OSL_ASSERT( _refCount == 1 );
194 // release the parent in the ~
195 if (xParent.is())
197 ::osl::MutexGuard aGuard( rBHelper.rMutex );
198 _xInterface = xParent;
202 else
203 osl_incrementInterlockedCount( &_refCount );
206 void checkDisposed(sal_Bool _bThrow) throw ( DisposedException )
208 if (_bThrow)
209 throw DisposedException();
212 //.........................................................................
215 //.........................................................................