Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <connectivity/sdbcx/VDescriptor.hxx>
21 : #include <cppuhelper/queryinterface.hxx>
22 :
23 : #include <functional>
24 : #include <algorithm>
25 : #include <string.h>
26 :
27 : namespace connectivity
28 : {
29 : namespace sdbcx
30 : {
31 : using namespace ::com::sun::star::uno;
32 : using namespace ::com::sun::star::lang;
33 : using namespace ::com::sun::star::beans;
34 :
35 :
36 : // = ODescriptor
37 :
38 :
39 3128 : ODescriptor::ODescriptor(::cppu::OBroadcastHelper& _rBHelper, bool _bCase, bool _bNew)
40 : :ODescriptor_PBASE(_rBHelper)
41 : ,m_aCase(_bCase)
42 3128 : ,m_bNew(_bNew)
43 : {
44 3128 : }
45 :
46 :
47 : // com::sun::star::lang::XUnoTunnel
48 0 : sal_Int64 SAL_CALL ODescriptor::getSomething( const Sequence< sal_Int8 >& rId ) throw(RuntimeException, std::exception)
49 : {
50 0 : return (rId.getLength() == 16 && 0 == memcmp(getUnoTunnelImplementationId().getConstArray(), rId.getConstArray(), 16 ) )
51 : ? reinterpret_cast< sal_Int64 >( this )
52 0 : : 0;
53 : }
54 :
55 :
56 213 : ODescriptor* ODescriptor::getImplementation( const Reference< XInterface >& _rxSomeComp )
57 : {
58 213 : Reference< XUnoTunnel > xTunnel( _rxSomeComp, UNO_QUERY );
59 213 : if ( xTunnel.is() )
60 0 : return reinterpret_cast< ODescriptor* >( xTunnel->getSomething( getUnoTunnelImplementationId() ) );
61 213 : return NULL;
62 : }
63 :
64 :
65 : namespace
66 : {
67 : struct ResetROAttribute : public ::std::unary_function< Property, void >
68 : {
69 0 : void operator ()( Property& _rProperty ) const
70 : {
71 0 : _rProperty.Attributes &= ~PropertyAttribute::READONLY;
72 0 : }
73 : };
74 : struct SetROAttribute : public ::std::unary_function< Property, void >
75 : {
76 971 : void operator ()( Property& _rProperty ) const
77 : {
78 971 : _rProperty.Attributes |= PropertyAttribute::READONLY;
79 971 : }
80 : };
81 : }
82 :
83 :
84 78 : ::cppu::IPropertyArrayHelper* ODescriptor::doCreateArrayHelper() const
85 : {
86 78 : Sequence< Property > aProperties;
87 78 : describeProperties( aProperties );
88 :
89 78 : if ( isNew() )
90 0 : ::std::for_each( aProperties.getArray(), aProperties.getArray() + aProperties.getLength(), ResetROAttribute() );
91 : else
92 78 : ::std::for_each( aProperties.getArray(), aProperties.getArray() + aProperties.getLength(), SetROAttribute() );
93 :
94 78 : return new ::cppu::OPropertyArrayHelper( aProperties );
95 : }
96 :
97 :
98 0 : bool ODescriptor::isNew( const Reference< XInterface >& _rxDescriptor )
99 : {
100 0 : ODescriptor* pImplementation = getImplementation( _rxDescriptor );
101 0 : return pImplementation && pImplementation->isNew();
102 : }
103 :
104 :
105 0 : Sequence< sal_Int8 > ODescriptor::getUnoTunnelImplementationId()
106 : {
107 : static ::cppu::OImplementationId * pId = 0;
108 0 : if (! pId)
109 : {
110 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
111 0 : if (! pId)
112 : {
113 0 : static ::cppu::OImplementationId aId;
114 0 : pId = &aId;
115 0 : }
116 : }
117 0 : return pId->getImplementationId();
118 : }
119 :
120 :
121 18732 : Any SAL_CALL ODescriptor::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
122 : {
123 18732 : Any aRet = ::cppu::queryInterface(rType,static_cast< XUnoTunnel*> (this));
124 18732 : return aRet.hasValue() ? aRet : ODescriptor_PBASE::queryInterface(rType);
125 : }
126 :
127 :
128 0 : void ODescriptor::setNew(bool _bNew)
129 : {
130 0 : m_bNew = _bNew;
131 0 : }
132 :
133 :
134 0 : Sequence< Type > SAL_CALL ODescriptor::getTypes( ) throw(RuntimeException, std::exception)
135 : {
136 0 : ::cppu::OTypeCollection aTypes( cppu::UnoType<XMultiPropertySet>::get(),
137 0 : cppu::UnoType<XFastPropertySet>::get(),
138 0 : cppu::UnoType<XPropertySet>::get(),
139 0 : cppu::UnoType<XUnoTunnel>::get());
140 0 : return aTypes.getTypes();
141 : }
142 :
143 : }
144 : }
145 :
146 :
147 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|