1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NDriver.cxx,v $
10 * $Revision: 1.6.56.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "NDriver.hxx"
34 #include "NConnection.hxx"
35 #include <com/sun/star/lang/DisposedException.hpp>
36 #include "connectivity/dbexception.hxx"
37 //#ifndef _CONNECTIVITY_EVOAB_CONFIGACCESS_HXX_
38 //#include "LConfigAccess.hxx"
40 #include <osl/file.hxx>
41 #include "osl/security.hxx"
42 #include <comphelper/processfactory.hxx>
43 #include <com/sun/star/ucb/XContentAccess.hpp>
44 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
45 #include <ucbhelper/content.hxx>
46 #include <tools/debug.hxx>
49 #include "resource/common_res.hrc"
50 #include "resource/sharedresources.hxx"
53 using namespace connectivity::evoab
;
54 //using namespace connectivity::file;
55 using namespace ::com::sun::star::uno
;
56 using namespace ::com::sun::star::beans
;
57 using namespace ::com::sun::star::sdbcx
;
58 using namespace ::com::sun::star::sdbc
;
59 using namespace ::com::sun::star::lang
;
60 using namespace ::com::sun::star::ucb
;
62 // --------------------------------------------------------------------------------
63 OEvoabDriver::OEvoabDriver(const Reference
< XMultiServiceFactory
>& _rxFactory
) :
64 ODriver_BASE( m_aMutex
), m_xFactory( _rxFactory
)
67 // -----------------------------------------------------------------------------
68 OEvoabDriver::~OEvoabDriver()
71 // -----------------------------------------------------------------------------
72 void OEvoabDriver::disposing()
74 ::osl::MutexGuard
aGuard(m_aMutex
);
76 // when driver will be destroied so all our connections have to be destroied as well
77 for (OWeakRefArray::iterator i
= m_xConnections
.begin(); m_xConnections
.end() != i
; ++i
)
79 Reference
< XComponent
> xComp(i
->get(), UNO_QUERY
);
84 catch (com::sun::star::lang::DisposedException e
) {
89 m_xConnections
.clear();
90 connectivity::OWeakRefArray().swap(m_xConnections
); // this really clears
92 ODriver_BASE::disposing();
96 //------------------------------------------------------------------------------
97 rtl::OUString
OEvoabDriver::getImplementationName_Static( ) throw(RuntimeException
)
99 return rtl::OUString::createFromAscii(EVOAB_DRIVER_IMPL_NAME
);
100 // this name is referenced in the configuration and in the evoab.xml
101 // Please take care when changing it.
104 //------------------------------------------------------------------
105 Sequence
< ::rtl::OUString
> OEvoabDriver::getSupportedServiceNames_Static( ) throw (RuntimeException
)
107 // which service is supported
108 // for more information @see com.sun.star.sdbc.Driver
109 Sequence
< ::rtl::OUString
> aSNS( 1 );
110 aSNS
[0] = ::rtl::OUString::createFromAscii("com.sun.star.sdbc.Driver");
113 //------------------------------------------------------------------
114 ::rtl::OUString SAL_CALL
OEvoabDriver::getImplementationName( ) throw(RuntimeException
)
116 return getImplementationName_Static();
118 //------------------------------------------------------------------
119 sal_Bool SAL_CALL
OEvoabDriver::supportsService( const ::rtl::OUString
& _rServiceName
) throw(RuntimeException
)
121 Sequence
< ::rtl::OUString
> aSupported(getSupportedServiceNames());
122 const ::rtl::OUString
* pSupported
= aSupported
.getConstArray();
123 const ::rtl::OUString
* pEnd
= pSupported
+ aSupported
.getLength();
124 for (;pSupported
!= pEnd
&& !pSupported
->equals(_rServiceName
); ++pSupported
)
127 return pSupported
!= pEnd
;
129 //------------------------------------------------------------------
130 Sequence
< ::rtl::OUString
> SAL_CALL
OEvoabDriver::getSupportedServiceNames( ) throw(RuntimeException
)
132 return getSupportedServiceNames_Static();
135 //------------------------------------------------------------------
136 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
> SAL_CALL
connectivity::evoab::OEvoabDriver_CreateInstance(const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XMultiServiceFactory
>& _rxFactory
) throw( ::com::sun::star::uno::Exception
)
138 return *(new OEvoabDriver(_rxFactory
));
140 // --------------------------------------------------------------------------------
141 Reference
< XConnection
> SAL_CALL
OEvoabDriver::connect( const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& info
) throw(SQLException
, RuntimeException
)
143 ::osl::MutexGuard
aGuard( m_aMutex
);
144 if (ODriver_BASE::rBHelper
.bDisposed
)
145 throw DisposedException();
147 if ( ! acceptsURL(url
) )
150 OEvoabConnection
* pCon
= new OEvoabConnection( *this );
151 pCon
->construct(url
,info
);
152 Reference
< XConnection
> xCon
= pCon
;
153 m_xConnections
.push_back(WeakReferenceHelper(*pCon
));
157 // --------------------------------------------------------------------------------
158 sal_Bool SAL_CALL
OEvoabDriver::acceptsURL( const ::rtl::OUString
& url
)
159 throw(SQLException
, RuntimeException
)
161 return acceptsURL_Stat(url
);
164 // --------------------------------------------------------------------------------
165 Sequence
< DriverPropertyInfo
> SAL_CALL
OEvoabDriver::getPropertyInfo( const ::rtl::OUString
& url
, const Sequence
< PropertyValue
>& /*info*/ ) throw(SQLException
, RuntimeException
)
167 if ( ! acceptsURL(url
) )
169 ::connectivity::SharedResources aResources
;
170 const ::rtl::OUString sMessage
= aResources
.getResourceString(STR_URI_SYNTAX_ERROR
);
171 ::dbtools::throwGenericSQLException(sMessage
,*this);
172 } // if ( ! acceptsURL(url) )
174 // if you have somthing special to say return it here :-)
175 return Sequence
< DriverPropertyInfo
>();
178 // --------------------------------------------------------------------------------
179 sal_Int32 SAL_CALL
OEvoabDriver::getMajorVersion( ) throw(RuntimeException
)
183 // --------------------------------------------------------------------------------
184 sal_Int32 SAL_CALL
OEvoabDriver::getMinorVersion( ) throw(RuntimeException
)
188 // --------------------------------------------------------------------------------
189 sal_Bool
OEvoabDriver::acceptsURL_Stat( const ::rtl::OUString
& url
)
191 return (url
.equalsAscii("sdbc:address:evolution:local") || url
.equalsAscii("sdbc:address:evolution:groupwise")||url
.equalsAscii("sdbc:address:evolution:ldap"))&& EApiInit();
193 // -----------------------------------------------------------------------------