xref: /trunk/main/connectivity/source/sdbcx/VDescriptor.cxx (revision e8df90a080f9dc7518c4b937d7dcd461d7b4d178)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_dbtools.hxx"
26 #include <connectivity/sdbcx/VDescriptor.hxx>
27 #include <cppuhelper/queryinterface.hxx>
28 
29 #include <functional>
30 #include <algorithm>
31 
32 namespace connectivity
33 {
34     namespace sdbcx
35     {
36         using namespace ::com::sun::star::uno;
37         using namespace ::com::sun::star::lang;
38         using namespace ::com::sun::star::beans;
39 
40         // =========================================================================
41         // = ODescriptor
42         // =========================================================================
43         // -------------------------------------------------------------------------
ODescriptor(::cppu::OBroadcastHelper & _rBHelper,sal_Bool _bCase,sal_Bool _bNew)44         ODescriptor::ODescriptor(::cppu::OBroadcastHelper& _rBHelper,sal_Bool _bCase, sal_Bool _bNew)
45             :ODescriptor_PBASE(_rBHelper)
46             ,m_aCase(_bCase)
47             ,m_bNew(_bNew)
48         {
49         }
50 
51         // -------------------------------------------------------------------------
52         // com::sun::star::lang::XUnoTunnel
getSomething(const Sequence<sal_Int8> & rId)53         sal_Int64 SAL_CALL ODescriptor::getSomething( const Sequence< sal_Int8 >& rId )
54         {
55             return (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),  rId.getConstArray(), 16 ) )
56                 ? reinterpret_cast< sal_Int64 >( this )
57                 : 0;
58         }
59 
60         // -----------------------------------------------------------------------------
getImplementation(const Reference<XInterface> & _rxSomeComp)61         ODescriptor* ODescriptor::getImplementation( const Reference< XInterface >& _rxSomeComp )
62         {
63             Reference< XUnoTunnel > xTunnel( _rxSomeComp, UNO_QUERY );
64             if ( xTunnel.is() )
65                 return reinterpret_cast< ODescriptor* >( xTunnel->getSomething( getUnoTunnelImplementationId() ) );
66             return NULL;
67         }
68 
69         // -----------------------------------------------------------------------------
70         namespace
71         {
72             struct ResetROAttribute
73             {
74                 typedef Property argument_type;
75                 typedef void result_type;
operator ()connectivity::sdbcx::__anon0a64a57d0111::ResetROAttribute76                 void operator ()( Property& _rProperty ) const
77                 {
78                     _rProperty.Attributes &= ~PropertyAttribute::READONLY;
79                 }
80             };
81             struct SetROAttribute
82             {
83                 typedef Property argument_type;
84                 typedef void result_type;
operator ()connectivity::sdbcx::__anon0a64a57d0111::SetROAttribute85                 void operator ()( Property& _rProperty ) const
86                 {
87                     _rProperty.Attributes |= PropertyAttribute::READONLY;
88                 }
89             };
90         }
91 
92         // -----------------------------------------------------------------------------
doCreateArrayHelper() const93         ::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         // -----------------------------------------------------------------------------
isNew(const Reference<XInterface> & _rxDescriptor)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         // -----------------------------------------------------------------------------
getUnoTunnelImplementationId()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         // -----------------------------------------------------------------------------
queryInterface(const Type & rType)130         Any SAL_CALL ODescriptor::queryInterface( const Type & rType )
131         {
132             Any aRet = ::cppu::queryInterface(rType,static_cast< XUnoTunnel*> (this));
133             return aRet.hasValue() ? aRet : ODescriptor_PBASE::queryInterface(rType);
134         }
135 
136         // -----------------------------------------------------------------------------
setNew(sal_Bool _bNew)137         void ODescriptor::setNew(sal_Bool _bNew)
138         {
139             m_bNew = _bNew;
140         }
141 
142         // -----------------------------------------------------------------------------
getTypes()143         Sequence< Type > SAL_CALL ODescriptor::getTypes(  )
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