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 <com/sun/star/beans/PropertyAttribute.hpp>
22 #include <comphelper/servicehelper.hxx>
23 #include <cppuhelper/queryinterface.hxx>
24 #include <cppuhelper/typeprovider.hxx>
25 
26 #include <algorithm>
27 
28 namespace connectivity::sdbcx
29 {
30         using namespace ::com::sun::star::uno;
31         using namespace ::com::sun::star::lang;
32         using namespace ::com::sun::star::beans;
33 
34 
35         // = ODescriptor
36 
37 
ODescriptor(::cppu::OBroadcastHelper & _rBHelper,bool _bCase,bool _bNew)38         ODescriptor::ODescriptor(::cppu::OBroadcastHelper& _rBHelper, bool _bCase, bool _bNew)
39             :ODescriptor_PBASE(_rBHelper)
40             ,m_aCase(_bCase)
41             ,m_bNew(_bNew)
42         {
43         }
44 
45 
46         // css::lang::XUnoTunnel
getSomething(const Sequence<sal_Int8> & rId)47         sal_Int64 SAL_CALL ODescriptor::getSomething( const Sequence< sal_Int8 >& rId )
48         {
49             return (isUnoTunnelId<ODescriptor>(rId))
50                 ? reinterpret_cast< sal_Int64 >( this )
51                 : 0;
52         }
53 
54 
55         namespace
56         {
57             struct ResetROAttribute
58             {
operator ()connectivity::sdbcx::__anon4128cc340111::ResetROAttribute59                 void operator ()( Property& _rProperty ) const
60                 {
61                     _rProperty.Attributes &= ~PropertyAttribute::READONLY;
62                 }
63             };
64             struct SetROAttribute
65             {
operator ()connectivity::sdbcx::__anon4128cc340111::SetROAttribute66                 void operator ()( Property& _rProperty ) const
67                 {
68                     _rProperty.Attributes |= PropertyAttribute::READONLY;
69                 }
70             };
71         }
72 
73 
doCreateArrayHelper() const74         ::cppu::IPropertyArrayHelper* ODescriptor::doCreateArrayHelper() const
75         {
76             Sequence< Property > aProperties;
77             describeProperties( aProperties );
78 
79             if ( isNew() )
80                 std::for_each( aProperties.begin(), aProperties.end(), ResetROAttribute() );
81             else
82                 std::for_each( aProperties.begin(), aProperties.end(), SetROAttribute() );
83 
84             return new ::cppu::OPropertyArrayHelper( aProperties );
85         }
86 
87 
isNew(const Reference<XInterface> & _rxDescriptor)88         bool ODescriptor::isNew( const Reference< XInterface >& _rxDescriptor )
89         {
90             ODescriptor* pImplementation = comphelper::getUnoTunnelImplementation<ODescriptor>( _rxDescriptor );
91             return pImplementation && pImplementation->isNew();
92         }
93 
94 
getUnoTunnelId()95         Sequence< sal_Int8 > ODescriptor::getUnoTunnelId()
96         {
97             static ::cppu::OImplementationId implId;
98 
99             return implId.getImplementationId();
100         }
101 
102 
queryInterface(const Type & rType)103         Any SAL_CALL ODescriptor::queryInterface( const Type & rType )
104         {
105             Any aRet = ::cppu::queryInterface(rType,static_cast< XUnoTunnel*> (this));
106             return aRet.hasValue() ? aRet : ODescriptor_PBASE::queryInterface(rType);
107         }
108 
109 
setNew(bool _bNew)110         void ODescriptor::setNew(bool _bNew)
111         {
112             m_bNew = _bNew;
113         }
114 
115 
getTypes()116         Sequence< Type > SAL_CALL ODescriptor::getTypes(  )
117         {
118             ::cppu::OTypeCollection aTypes( cppu::UnoType<XMultiPropertySet>::get(),
119                                             cppu::UnoType<XFastPropertySet>::get(),
120                                             cppu::UnoType<XPropertySet>::get(),
121                                             cppu::UnoType<XUnoTunnel>::get());
122             return aTypes.getTypes();
123         }
124 
125 }
126 
127 
128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
129