LibreOffice Module dbaccess (master) 1
ComponentDefinition.cxx
Go to the documentation of this file.
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
21#include <stringconstants.hxx>
22#include <strings.hxx>
23
24#include <osl/diagnose.h>
25#include <com/sun/star/beans/PropertyAttribute.hpp>
26//#include <cppuhelper/interfacecontainer.hxx>
29#include <definitioncolumn.hxx>
30
31using namespace ::com::sun::star::uno;
32using namespace ::com::sun::star::sdbc;
33using namespace ::com::sun::star::lang;
34using namespace ::com::sun::star::beans;
35using namespace ::com::sun::star::container;
36using namespace ::cppu;
37
38namespace dbaccess
39{
40
43 public ::cppu::WeakImplHelper< XPropertyChangeListener >
44{
46protected:
47 virtual ~OColumnPropertyListener() override {}
48public:
49 explicit OColumnPropertyListener(OComponentDefinition* _pComponent) : m_pComponent(_pComponent){}
52 // XPropertyChangeListener
53 virtual void SAL_CALL propertyChange( const PropertyChangeEvent& /*_rEvent*/ ) override
54 {
55 if ( m_pComponent )
57 }
58 // XEventListener
59 virtual void SAL_CALL disposing( const EventObject& /*_rSource*/ ) override
60 {
61 }
62 void clear() { m_pComponent = nullptr; }
63};
64
66{
67}
68
70{
71}
72
73// OComponentDefinition
74
75
76void OComponentDefinition::initialize( const Sequence< Any >& aArguments )
77{
78 OUString rName;
79 if( (aArguments.getLength() == 1) && (aArguments[0] >>= rName) )
80 {
81 Sequence<Any> aNewArgs(comphelper::InitAnyPropertySequence(
82 {
83 {PROPERTY_NAME, Any(rName)}
84 }));
86 }
87 else
89}
90
92{
96
97 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY|PropertyAttribute::CONSTRAINED,
98 &rDefinition.m_aProps.aTitle, cppu::UnoType<decltype(rDefinition.m_aProps.aTitle)>::get());
99
100 if ( m_bTable )
101 {
103 &rDefinition.m_sSchemaName, cppu::UnoType<decltype(rDefinition.m_sSchemaName)>::get());
104
106 &rDefinition.m_sCatalogName, cppu::UnoType<decltype(rDefinition.m_sCatalogName)>::get());
107 }
108}
109
110OComponentDefinition::OComponentDefinition(const Reference< XComponentContext >& _xORB
111 ,const Reference< XInterface >& _xParentContainer
112 ,const TContentPtr& _pImpl
113 ,bool _bTable)
114 :OContentHelper(_xORB,_xParentContainer,_pImpl)
115 ,ODataSettings(OContentHelper::rBHelper,!_bTable)
116 ,m_bTable(_bTable)
117{
119}
120
122{
123}
124
125OComponentDefinition::OComponentDefinition( const Reference< XInterface >& _rxContainer
126 ,const OUString& _rElementName
127 ,const Reference< XComponentContext >& _xORB
128 ,const TContentPtr& _pImpl
129 ,bool _bTable)
130 :OContentHelper(_xORB,_rxContainer,_pImpl)
131 ,ODataSettings(OContentHelper::rBHelper,!_bTable)
132 ,m_bTable(_bTable)
133{
135
136 m_pImpl->m_aProps.aTitle = _rElementName;
137 OSL_ENSURE(!m_pImpl->m_aProps.aTitle.isEmpty(), "OComponentDefinition::OComponentDefinition : invalid name !");
138}
139
140css::uno::Sequence<sal_Int8> OComponentDefinition::getImplementationId()
141{
142 return css::uno::Sequence<sal_Int8>();
143}
144
145css::uno::Sequence< css::uno::Type > OComponentDefinition::getTypes()
146{
147 return ::comphelper::concatSequences(
148 ODataSettings::getTypes( ),
149 OContentHelper::getTypes( ),
151 );
152}
154
155OUString SAL_CALL OComponentDefinition::getImplementationName()
156{
157 return "com.sun.star.comp.dba.OComponentDefinition";
158}
159
161{
162 return { "com.sun.star.sdb.TableDefinition", "com.sun.star.ucb.Content" };
163}
164
166{
168 if (m_pColumns)
169 {
170 m_pColumns->disposing();
171 }
174}
175
177{
178 return *getArrayHelper();
179}
180
181IPropertyArrayHelper* OComponentDefinition::createArrayHelper( ) const
182{
183 Sequence< Property > aProps;
184 describeProperties(aProps);
185 return new OPropertyArrayHelper(aProps);
186}
187
188Reference< XPropertySetInfo > SAL_CALL OComponentDefinition::getPropertySetInfo( )
189{
190 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
191 return xInfo;
192}
193
195{
196 return m_bTable
197 ? OUString( "application/vnd.org.openoffice.DatabaseTable" )
198 : OUString( "application/vnd.org.openoffice.DatabaseCommandDefinition" );
199}
200
201Reference< XNameAccess> OComponentDefinition::getColumns()
202{
203 ::osl::MutexGuard aGuard(m_aMutex);
204 ::connectivity::checkDisposed(OContentHelper::rBHelper.bDisposed);
205
206 if (!m_pColumns)
207 {
208 std::vector< OUString> aNames;
209
210 const OComponentDefinition_Impl& rDefinition( getDefinition() );
211 aNames.reserve( rDefinition.size() );
212
213 for (auto const& definition : rDefinition)
214 aNames.push_back(definition.first);
215
216 m_pColumns.reset(new OColumns(*this, m_aMutex, true, aNames, this, nullptr, true, false, false));
217 m_pColumns->setParent(*this);
218 }
219 // see OCollection::acquire
220 return m_pColumns.get();
221}
222
224{
225 const OComponentDefinition_Impl& rDefinition( getDefinition() );
226 OComponentDefinition_Impl::const_iterator aFind = rDefinition.find( _rName );
227 if ( aFind != rDefinition.end() )
228 {
229 aFind->second->addPropertyChangeListener(OUString(),m_xColumnPropertyListener);
230 return new OTableColumnWrapper( aFind->second, aFind->second, true );
231 }
232 OSL_FAIL( "OComponentDefinition::createColumn: is this a valid case?" );
233 // This here is the last place creating a OTableColumn, and somehow /me thinks it is not needed ...
234 return new OTableColumn( _rName );
235}
236
238{
239 return new OTableColumnDescriptor( true );
240}
241
242void OComponentDefinition::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue)
243{
246}
247
248void OComponentDefinition::columnDropped(const OUString& _sName)
249{
250 getDefinition().erase( _sName );
252}
253
254void OComponentDefinition::columnAppended( const Reference< XPropertySet >& _rxSourceDescriptor )
255{
256 OUString sName;
257 _rxSourceDescriptor->getPropertyValue( PROPERTY_NAME ) >>= sName;
258
259 Reference<XPropertySet> xColDesc = new OTableColumnDescriptor( true );
260 ::comphelper::copyProperties( _rxSourceDescriptor, xColDesc );
261 getDefinition().insert( sName, xColDesc );
262
263 // formerly, here was a setParent at the xColDesc. The parent used was an adapter (ChildHelper_Impl)
264 // which held another XChild weak, and forwarded all getParent requests to this other XChild.
265 // m_pColumns was used for this. This was nonsense, since m_pColumns dies when our instance dies,
266 // but xColDesc will live longer than this. So effectively, the setParent call was pretty useless.
267 //
268 // The intention for this parenting was that the column descriptor is able to find the data source,
269 // by traveling up the parent hierarchy until there's an XDataSource. This didn't work (which
270 // for instance causes #i65023#). We need another way to properly ensure this.
271
273}
274
275} // namespace dbaccess
276
277extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
278com_sun_star_comp_dba_OComponentDefinition(css::uno::XComponentContext* context,
279 css::uno::Sequence<css::uno::Any> const &)
280{
281 return cppu::acquire(new dbaccess::OComponentDefinition(
282 context, nullptr, std::make_shared<dbaccess::OComponentDefinition_Impl>()));
283}
284
285/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_dba_OComponentDefinition(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
OptionalString sName
void describeProperties(css::uno::Sequence< css::beans::Property > &_rProps) const
void registerProperty(const OUString &_rName, sal_Int32 _nHandle, sal_Int32 _nAttributes, void *_pPointerToMember, const css::uno::Type &_rMemberType)
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
mutable::osl::Mutex m_aMutex
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() SAL_OVERRIDE
helper class for column property change events which holds the OComponentDefinition weak
OColumnPropertyListener(OComponentDefinition *_pComponent)
const OColumnPropertyListener & operator=(const OColumnPropertyListener &)=delete
virtual void SAL_CALL disposing(const EventObject &) override
virtual void SAL_CALL propertyChange(const PropertyChangeEvent &) override
OColumnPropertyListener(const OColumnPropertyListener &)=delete
void insert(const OUString &_rName, const css::uno::Reference< css::beans::XPropertySet > &_rxColumn)
const_iterator find(const OUString &_rName) const
void erase(const OUString &_rName)
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
std::unique_ptr< OColumns > m_pColumns
virtual css::uno::Sequence< sal_Int8 > SAL_CALL getImplementationId() override
virtual void SAL_CALL initialize(css::uno::Sequence< css::uno::Any > const &rArguments) override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual OUString determineContentType() const override
virtual void columnAppended(const css::uno::Reference< css::beans::XPropertySet > &_rxSourceDescriptor) override
notifies that a column, created from a column descriptor, has been appended
const OComponentDefinition_Impl & getDefinition() const
virtual void SAL_CALL disposing() override
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const override
virtual void columnDropped(const OUString &_sName) override
notifies that a column with a given name has been dropped
OComponentDefinition(const css::uno::Reference< css::uno::XComponentContext > &, const css::uno::Reference< css::uno::XInterface > &_xParentContainer, const TContentPtr &_pImpl, bool _bTable=true)
virtual rtl::Reference< OColumn > createColumn(const OUString &_rName) const override
creates an OColumn object which should represent the column with a given name
virtual css::uno::Sequence< css::uno::Type > SAL_CALL getTypes() override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Reference< css::beans::XPropertySet > createColumnDescriptor() override
creates a column descriptor object.
rtl::Reference< OColumnPropertyListener > m_xColumnPropertyListener
virtual void SAL_CALL setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const css::uno::Any &rValue) override
virtual css::uno::Reference< css::container::XNameAccess > SAL_CALL getColumns() override
virtual void SAL_CALL disposing() override
virtual void SAL_CALL initialize(const css::uno::Sequence< css::uno::Any > &aArguments) override
void registerPropertiesFor(ODataSettings_Base *_pItem)
register the properties from the param given.
provides the properties for description.
describes all properties for a columns of a table.
describes a column of a table
Sequence< PropertyValue > aArguments
Definition: intercept.cxx:88
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
std::shared_ptr< OContentHelper_Impl > TContentPtr
sal_Int32 nHandle
#define PROPERTY_ID_NAME
#define PROPERTY_ID_CATALOGNAME
#define PROPERTY_ID_SCHEMANAME
constexpr OUStringLiteral PROPERTY_SCHEMANAME(u"SchemaName")
constexpr OUStringLiteral PROPERTY_CATALOGNAME(u"CatalogName")
constexpr OUStringLiteral PROPERTY_NAME(u"Name")
#define IMPLEMENT_FORWARD_XINTERFACE3(classname, refcountbase, baseclass2, baseclass3)