xref: /trunk/main/connectivity/source/sdbcx/VDescriptor.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_connectivity.hxx"
30 #include <connectivity/sdbcx/VDescriptor.hxx>
31 #include <cppuhelper/queryinterface.hxx>
32 
33 #include <functional>
34 #include <algorithm>
35 
36 namespace connectivity
37 {
38     namespace sdbcx
39     {
40         using namespace ::com::sun::star::uno;
41         using namespace ::com::sun::star::lang;
42         using namespace ::com::sun::star::beans;
43 
44         // =========================================================================
45         // = ODescriptor
46         // =========================================================================
47         // -------------------------------------------------------------------------
48         ODescriptor::ODescriptor(::cppu::OBroadcastHelper& _rBHelper,sal_Bool _bCase, sal_Bool _bNew)
49             :ODescriptor_PBASE(_rBHelper)
50             ,m_aCase(_bCase)
51             ,m_bNew(_bNew)
52         {
53         }
54 
55         // -------------------------------------------------------------------------
56         // com::sun::star::lang::XUnoTunnel
57         sal_Int64 SAL_CALL ODescriptor::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException)
58         {
59             return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),  rId.getConstArray(), 16 ) )
60                 ? reinterpret_cast< sal_Int64 >( this )
61                 : 0;
62         }
63 
64         // -----------------------------------------------------------------------------
65         ODescriptor* ODescriptor::getImplementation( const Reference< XInterface >& _rxSomeComp )
66         {
67             Reference< XUnoTunnel > xTunnel( _rxSomeComp, UNO_QUERY );
68             if ( xTunnel.is() )
69                 return reinterpret_cast< ODescriptor* >( xTunnel->getSomething( getUnoTunnelImplementationId() ) );
70             return NULL;
71         }
72 
73         // -----------------------------------------------------------------------------
74         namespace
75         {
76             struct ResetROAttribute : public ::std::unary_function< Property, void >
77             {
78                 void operator ()( Property& _rProperty ) const
79                 {
80                     _rProperty.Attributes &= ~PropertyAttribute::READONLY;
81                 }
82             };
83             struct SetROAttribute : public ::std::unary_function< Property, void >
84             {
85                 void operator ()( Property& _rProperty ) const
86                 {
87                     _rProperty.Attributes |= PropertyAttribute::READONLY;
88                 }
89             };
90         }
91 
92         // -----------------------------------------------------------------------------
93         ::cppu::IPropertyArrayHelper* ODescriptor::doCreateArrayHelper() const
94         {
95             Sequence< Property > aProperties;
96             describeProperties( aProperties );
97 
98             if ( isNew() )
99                 ::std::for_each( aProperties.getArray(), aProperties.getArray() + aProperties.getLength(), ResetROAttribute() );
100             else
101                 ::std::for_each( aProperties.getArray(), aProperties.getArray() + aProperties.getLength(), SetROAttribute() );
102 
103             return new ::cppu::OPropertyArrayHelper( aProperties );
104         }
105 
106         // -----------------------------------------------------------------------------
107         sal_Bool ODescriptor::isNew( const Reference< XInterface >& _rxDescriptor )
108         {
109             ODescriptor* pImplementation = getImplementation( _rxDescriptor );
110             return pImplementation != NULL ? pImplementation->isNew() : sal_False;
111         }
112 
113         // -----------------------------------------------------------------------------
114         Sequence< sal_Int8 > ODescriptor::getUnoTunnelImplementationId()
115         {
116             static ::cppu::OImplementationId * pId = 0;
117             if (! pId)
118             {
119                 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
120                 if (! pId)
121                 {
122                     static ::cppu::OImplementationId aId;
123                     pId = &aId;
124                 }
125             }
126             return pId->getImplementationId();
127         }
128 
129         // -----------------------------------------------------------------------------
130         Any SAL_CALL ODescriptor::queryInterface( const Type & rType ) throw(RuntimeException)
131         {
132             Any aRet = ::cppu::queryInterface(rType,static_cast< XUnoTunnel*> (this));
133             return aRet.hasValue() ? aRet : ODescriptor_PBASE::queryInterface(rType);
134         }
135 
136         // -----------------------------------------------------------------------------
137         void ODescriptor::setNew(sal_Bool _bNew)
138         {
139             m_bNew = _bNew;
140         }
141 
142         // -----------------------------------------------------------------------------
143         Sequence< Type > SAL_CALL ODescriptor::getTypes(  ) throw(RuntimeException)
144         {
145             ::cppu::OTypeCollection aTypes( ::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
146                                             ::getCppuType( (const Reference< XFastPropertySet > *)0 ),
147                                             ::getCppuType( (const Reference< XPropertySet > *)0 ),
148                                             ::getCppuType( (const Reference< XUnoTunnel > *)0 ));
149             return aTypes.getTypes();
150         }
151 
152     }
153 }
154 
155 
156