1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "ComponentDefinition.hxx"
21 #include <apitools.hxx>
22 #include <stringconstants.hxx>
24 #include <osl/diagnose.h>
25 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include <cppuhelper/interfacecontainer.hxx>
27 #include <comphelper/property.hxx>
28 #include <comphelper/propertysequence.hxx>
29 #include <definitioncolumn.hxx>
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::sdbc
;
33 using namespace ::com::sun::star::lang
;
34 using namespace ::com::sun::star::beans
;
35 using namespace ::com::sun::star::container
;
36 using namespace ::cppu
;
41 /// helper class for column property change events which holds the OComponentDefinition weak
42 class OColumnPropertyListener
:
43 public ::cppu::WeakImplHelper
< XPropertyChangeListener
>
45 OComponentDefinition
* m_pComponent
;
47 virtual ~OColumnPropertyListener() override
{}
49 explicit OColumnPropertyListener(OComponentDefinition
* _pComponent
) : m_pComponent(_pComponent
){}
50 OColumnPropertyListener(const OColumnPropertyListener
&) = delete;
51 const OColumnPropertyListener
& operator=(const OColumnPropertyListener
&) = delete;
52 // XPropertyChangeListener
53 virtual void SAL_CALL
propertyChange( const PropertyChangeEvent
& /*_rEvent*/ ) override
56 m_pComponent
->notifyDataSourceModified();
59 virtual void SAL_CALL
disposing( const EventObject
& /*_rSource*/ ) override
62 void clear() { m_pComponent
= nullptr; }
65 OComponentDefinition_Impl::OComponentDefinition_Impl()
69 OComponentDefinition_Impl::~OComponentDefinition_Impl()
73 // OComponentDefinition
76 void OComponentDefinition::initialize( const Sequence
< Any
>& aArguments
)
79 if( (aArguments
.getLength() == 1) && (aArguments
[0] >>= rName
) )
81 Sequence
<Any
> aNewArgs(comphelper::InitAnyPropertySequence(
83 {PROPERTY_NAME
, Any(rName
)}
85 OContentHelper::initialize(aNewArgs
);
88 OContentHelper::initialize(aArguments
);
91 void OComponentDefinition::registerProperties()
93 m_xColumnPropertyListener
= new OColumnPropertyListener(this);
94 OComponentDefinition_Impl
& rDefinition( getDefinition() );
95 ODataSettings::registerPropertiesFor( &rDefinition
);
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());
102 registerProperty(PROPERTY_SCHEMANAME
, PROPERTY_ID_SCHEMANAME
, PropertyAttribute::BOUND
,
103 &rDefinition
.m_sSchemaName
, cppu::UnoType
<decltype(rDefinition
.m_sSchemaName
)>::get());
105 registerProperty(PROPERTY_CATALOGNAME
, PROPERTY_ID_CATALOGNAME
, PropertyAttribute::BOUND
,
106 &rDefinition
.m_sCatalogName
, cppu::UnoType
<decltype(rDefinition
.m_sCatalogName
)>::get());
110 OComponentDefinition::OComponentDefinition(const Reference
< XComponentContext
>& _xORB
111 ,const Reference
< XInterface
>& _xParentContainer
112 ,const TContentPtr
& _pImpl
114 :OContentHelper(_xORB
,_xParentContainer
,_pImpl
)
115 ,ODataSettings(OContentHelper::rBHelper
,!_bTable
)
118 registerProperties();
121 OComponentDefinition::~OComponentDefinition()
125 OComponentDefinition::OComponentDefinition( const Reference
< XInterface
>& _rxContainer
126 ,const OUString
& _rElementName
127 ,const Reference
< XComponentContext
>& _xORB
128 ,const TContentPtr
& _pImpl
130 :OContentHelper(_xORB
,_rxContainer
,_pImpl
)
131 ,ODataSettings(OContentHelper::rBHelper
,!_bTable
)
134 registerProperties();
136 m_pImpl
->m_aProps
.aTitle
= _rElementName
;
137 OSL_ENSURE(!m_pImpl
->m_aProps
.aTitle
.isEmpty(), "OComponentDefinition::OComponentDefinition : invalid name !");
140 css::uno::Sequence
<sal_Int8
> OComponentDefinition::getImplementationId()
142 return css::uno::Sequence
<sal_Int8
>();
145 IMPLEMENT_GETTYPES3(OComponentDefinition
,ODataSettings
,OContentHelper
,OComponentDefinition_BASE
);
146 IMPLEMENT_FORWARD_XINTERFACE3( OComponentDefinition
,OContentHelper
,ODataSettings
,OComponentDefinition_BASE
)
148 OUString SAL_CALL
OComponentDefinition::getImplementationName()
150 return "com.sun.star.comp.dba.OComponentDefinition";
153 Sequence
< OUString
> SAL_CALL
OComponentDefinition::getSupportedServiceNames()
155 return { "com.sun.star.sdb.TableDefinition", "com.sun.star.ucb.Content" };
158 void SAL_CALL
OComponentDefinition::disposing()
160 OContentHelper::disposing();
163 m_pColumns
->disposing();
165 m_xColumnPropertyListener
->clear();
166 m_xColumnPropertyListener
.clear();
169 IPropertyArrayHelper
& OComponentDefinition::getInfoHelper()
171 return *getArrayHelper();
174 IPropertyArrayHelper
* OComponentDefinition::createArrayHelper( ) const
176 Sequence
< Property
> aProps
;
177 describeProperties(aProps
);
178 return new OPropertyArrayHelper(aProps
);
181 Reference
< XPropertySetInfo
> SAL_CALL
OComponentDefinition::getPropertySetInfo( )
183 Reference
<XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
187 OUString
OComponentDefinition::determineContentType() const
190 ? OUString( "application/vnd.org.openoffice.DatabaseTable" )
191 : OUString( "application/vnd.org.openoffice.DatabaseCommandDefinition" );
194 Reference
< XNameAccess
> OComponentDefinition::getColumns()
196 ::osl::MutexGuard
aGuard(m_aMutex
);
197 ::connectivity::checkDisposed(OContentHelper::rBHelper
.bDisposed
);
201 std::vector
< OUString
> aNames
;
203 const OComponentDefinition_Impl
& rDefinition( getDefinition() );
204 aNames
.reserve( rDefinition
.size() );
206 for (auto const& definition
: rDefinition
)
207 aNames
.push_back(definition
.first
);
209 m_pColumns
.reset(new OColumns(*this, m_aMutex
, true, aNames
, this, nullptr, true, false, false));
210 m_pColumns
->setParent(*this);
212 // see OCollection::acquire
213 return m_pColumns
.get();
216 OColumn
* OComponentDefinition::createColumn(const OUString
& _rName
) const
218 const OComponentDefinition_Impl
& rDefinition( getDefinition() );
219 OComponentDefinition_Impl::const_iterator aFind
= rDefinition
.find( _rName
);
220 if ( aFind
!= rDefinition
.end() )
222 aFind
->second
->addPropertyChangeListener(OUString(),m_xColumnPropertyListener
.get());
223 return new OTableColumnWrapper( aFind
->second
, aFind
->second
, true );
225 OSL_FAIL( "OComponentDefinition::createColumn: is this a valid case?" );
226 // This here is the last place creating a OTableColumn, and somehow /me thinks it is not needed ...
227 return new OTableColumn( _rName
);
230 Reference
< XPropertySet
> OComponentDefinition::createColumnDescriptor()
232 return new OTableColumnDescriptor( true );
235 void OComponentDefinition::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
)
237 ODataSettings::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);
238 notifyDataSourceModified();
241 void OComponentDefinition::columnDropped(const OUString
& _sName
)
243 getDefinition().erase( _sName
);
244 notifyDataSourceModified();
247 void OComponentDefinition::columnAppended( const Reference
< XPropertySet
>& _rxSourceDescriptor
)
250 _rxSourceDescriptor
->getPropertyValue( PROPERTY_NAME
) >>= sName
;
252 Reference
<XPropertySet
> xColDesc
= new OTableColumnDescriptor( true );
253 ::comphelper::copyProperties( _rxSourceDescriptor
, xColDesc
);
254 getDefinition().insert( sName
, xColDesc
);
256 // formerly, here was a setParent at the xColDesc. The parent used was an adapter (ChildHelper_Impl)
257 // which held another XChild weak, and forwarded all getParent requests to this other XChild.
258 // m_pColumns was used for this. This was nonsense, since m_pColumns dies when our instance dies,
259 // but xColDesc will live longer than this. So effectively, the setParent call was pretty useless.
261 // The intention for this parenting was that the column descriptor is able to find the data source,
262 // by traveling up the parent hierarchy until there's an XDataSource. This didn't work (which
263 // for instance causes #i65023#). We need another way to properly ensure this.
265 notifyDataSourceModified();
268 } // namespace dbaccess
270 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
271 com_sun_star_comp_dba_OComponentDefinition(css::uno::XComponentContext
* context
,
272 css::uno::Sequence
<css::uno::Any
> const &)
274 return cppu::acquire(new dbaccess::OComponentDefinition(
275 context
, nullptr, std::make_shared
<dbaccess::OComponentDefinition_Impl
>()));
278 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */