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_connectivity.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 ) throw(RuntimeException)
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 : public ::std::unary_function< Property, void >
73             {
operator ()connectivity::sdbcx::__anon1f08d6b50111::ResetROAttribute74                 void operator ()( Property& _rProperty ) const
75                 {
76                     _rProperty.Attributes &= ~PropertyAttribute::READONLY;
77                 }
78             };
79             struct SetROAttribute : public ::std::unary_function< Property, void >
80             {
operator ()connectivity::sdbcx::__anon1f08d6b50111::SetROAttribute81                 void operator ()( Property& _rProperty ) const
82                 {
83                     _rProperty.Attributes |= PropertyAttribute::READONLY;
84                 }
85             };
86         }
87 
88         // -----------------------------------------------------------------------------
doCreateArrayHelper() const89         ::cppu::IPropertyArrayHelper* ODescriptor::doCreateArrayHelper() const
90         {
91             Sequence< Property > aProperties;
92             describeProperties( aProperties );
93 
94             if ( isNew() )
95                 ::std::for_each( aProperties.getArray(), aProperties.getArray() + aProperties.getLength(), ResetROAttribute() );
96             else
97                 ::std::for_each( aProperties.getArray(), aProperties.getArray() + aProperties.getLength(), SetROAttribute() );
98 
99             return new ::cppu::OPropertyArrayHelper( aProperties );
100         }
101 
102         // -----------------------------------------------------------------------------
isNew(const Reference<XInterface> & _rxDescriptor)103         sal_Bool ODescriptor::isNew( const Reference< XInterface >& _rxDescriptor )
104         {
105             ODescriptor* pImplementation = getImplementation( _rxDescriptor );
106             return pImplementation != NULL ? pImplementation->isNew() : sal_False;
107         }
108 
109 		// -----------------------------------------------------------------------------
getUnoTunnelImplementationId()110 		Sequence< sal_Int8 > ODescriptor::getUnoTunnelImplementationId()
111 		{
112 			static ::cppu::OImplementationId * pId = 0;
113 			if (! pId)
114 			{
115 				::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
116 				if (! pId)
117 				{
118 					static ::cppu::OImplementationId aId;
119 					pId = &aId;
120 				}
121 			}
122 			return pId->getImplementationId();
123 		}
124 
125 		// -----------------------------------------------------------------------------
queryInterface(const Type & rType)126 		Any SAL_CALL ODescriptor::queryInterface( const Type & rType ) throw(RuntimeException)
127 		{
128 			Any aRet = ::cppu::queryInterface(rType,static_cast< XUnoTunnel*> (this));
129 			return aRet.hasValue() ? aRet : ODescriptor_PBASE::queryInterface(rType);
130 		}
131 
132 		// -----------------------------------------------------------------------------
setNew(sal_Bool _bNew)133 		void ODescriptor::setNew(sal_Bool _bNew)
134 		{
135 			m_bNew = _bNew;
136 		}
137 
138 		// -----------------------------------------------------------------------------
getTypes()139 		Sequence< Type > SAL_CALL ODescriptor::getTypes(  ) throw(RuntimeException)
140 		{
141 			::cppu::OTypeCollection aTypes(	::getCppuType( (const Reference< XMultiPropertySet > *)0 ),
142 											::getCppuType( (const Reference< XFastPropertySet > *)0 ),
143 											::getCppuType( (const Reference< XPropertySet > *)0 ),
144 											::getCppuType( (const Reference< XUnoTunnel > *)0 ));
145 			return aTypes.getTypes();
146 		}
147 
148 	}
149 }
150 
151 
152