build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / dbaccess / source / core / dataaccess / ComponentDefinition.cxx
blobab20721186326292634246aaf457ab75d4e4466c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "dbastrings.hrc"
24 #include <tools/debug.hxx>
25 #include <osl/diagnose.h>
26 #include <comphelper/sequence.hxx>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <comphelper/property.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;
38 namespace dbaccess
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;
46 protected:
47 virtual ~OColumnPropertyListener() override {}
48 public:
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*/ ) throw (RuntimeException, std::exception) override
55 if ( m_pComponent )
56 m_pComponent->notifyDataSourceModified();
58 // XEventListener
59 virtual void SAL_CALL disposing( const EventObject& /*_rSource*/ ) throw (RuntimeException, std::exception) 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 ) throw(Exception, std::exception)
78 OUString rName;
79 if( (aArguments.getLength() == 1) && (aArguments[0] >>= rName) )
81 Sequence< Any > aNewArgs(1);
82 PropertyValue aValue;
83 aValue.Name = PROPERTY_NAME;
84 aValue.Value <<= rName;
85 aNewArgs[0] <<= aValue;
86 OContentHelper::initialize(aNewArgs);
88 else
89 OContentHelper::initialize(aArguments);
92 void OComponentDefinition::registerProperties()
94 m_xColumnPropertyListener = new OColumnPropertyListener(this);
95 OComponentDefinition_Impl& rDefinition( getDefinition() );
96 ODataSettings::registerPropertiesFor( &rDefinition );
98 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY|PropertyAttribute::CONSTRAINED,
99 &rDefinition.m_aProps.aTitle, cppu::UnoType<decltype(rDefinition.m_aProps.aTitle)>::get());
101 if ( m_bTable )
103 registerProperty(PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME, PropertyAttribute::BOUND,
104 &rDefinition.m_sSchemaName, cppu::UnoType<decltype(rDefinition.m_sSchemaName)>::get());
106 registerProperty(PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME, PropertyAttribute::BOUND,
107 &rDefinition.m_sCatalogName, cppu::UnoType<decltype(rDefinition.m_sCatalogName)>::get());
111 OComponentDefinition::OComponentDefinition(const Reference< XComponentContext >& _xORB
112 ,const Reference< XInterface >& _xParentContainer
113 ,const TContentPtr& _pImpl
114 ,bool _bTable)
115 :OContentHelper(_xORB,_xParentContainer,_pImpl)
116 ,ODataSettings(OContentHelper::rBHelper,!_bTable)
117 ,m_bTable(_bTable)
119 registerProperties();
122 OComponentDefinition::~OComponentDefinition()
126 OComponentDefinition::OComponentDefinition( const Reference< XInterface >& _rxContainer
127 ,const OUString& _rElementName
128 ,const Reference< XComponentContext >& _xORB
129 ,const TContentPtr& _pImpl
130 ,bool _bTable)
131 :OContentHelper(_xORB,_rxContainer,_pImpl)
132 ,ODataSettings(OContentHelper::rBHelper,!_bTable)
133 ,m_bTable(_bTable)
135 registerProperties();
137 m_pImpl->m_aProps.aTitle = _rElementName;
138 OSL_ENSURE(!m_pImpl->m_aProps.aTitle.isEmpty(), "OComponentDefinition::OComponentDefinition : invalid name !");
141 css::uno::Sequence<sal_Int8> OComponentDefinition::getImplementationId()
142 throw (css::uno::RuntimeException, std::exception)
144 return css::uno::Sequence<sal_Int8>();
147 IMPLEMENT_GETTYPES3(OComponentDefinition,ODataSettings,OContentHelper,OComponentDefinition_BASE);
148 IMPLEMENT_FORWARD_XINTERFACE3( OComponentDefinition,OContentHelper,ODataSettings,OComponentDefinition_BASE)
150 OUString SAL_CALL OComponentDefinition::getImplementationName() throw(RuntimeException, std::exception)
152 return OUString("com.sun.star.comp.dba.OComponentDefinition");
155 Sequence< OUString > SAL_CALL OComponentDefinition::getSupportedServiceNames() throw(RuntimeException, std::exception)
157 return { "com.sun.star.sdb.TableDefinition", "com.sun.star.ucb.Content" };
160 void SAL_CALL OComponentDefinition::disposing()
162 OContentHelper::disposing();
163 if ( m_xColumns.is() )
164 m_xColumns->disposing();
165 m_xColumns.clear();
166 m_xColumnPropertyListener->clear();
167 m_xColumnPropertyListener.clear();
170 IPropertyArrayHelper& OComponentDefinition::getInfoHelper()
172 return *getArrayHelper();
175 IPropertyArrayHelper* OComponentDefinition::createArrayHelper( ) const
177 Sequence< Property > aProps;
178 describeProperties(aProps);
179 return new OPropertyArrayHelper(aProps);
182 Reference< XPropertySetInfo > SAL_CALL OComponentDefinition::getPropertySetInfo( ) throw(RuntimeException, std::exception)
184 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
185 return xInfo;
188 OUString OComponentDefinition::determineContentType() const
190 return m_bTable
191 ? OUString( "application/vnd.org.openoffice.DatabaseTable" )
192 : OUString( "application/vnd.org.openoffice.DatabaseCommandDefinition" );
195 Reference< XNameAccess> OComponentDefinition::getColumns() throw (RuntimeException, std::exception)
197 ::osl::MutexGuard aGuard(m_aMutex);
198 ::connectivity::checkDisposed(OContentHelper::rBHelper.bDisposed);
200 if ( !m_xColumns.is() )
202 ::std::vector< OUString> aNames;
204 const OComponentDefinition_Impl& rDefinition( getDefinition() );
205 aNames.reserve( rDefinition.size() );
207 OComponentDefinition_Impl::const_iterator aIter = rDefinition.begin();
208 OComponentDefinition_Impl::const_iterator aEnd = rDefinition.end();
209 for ( ; aIter != aEnd; ++aIter )
210 aNames.push_back( aIter->first );
212 m_xColumns = new OColumns( *this, m_aMutex, true, aNames, this, nullptr, true, false, false );
213 m_xColumns->setParent( *this );
215 return m_xColumns.get();
218 OColumn* OComponentDefinition::createColumn(const OUString& _rName) const
220 const OComponentDefinition_Impl& rDefinition( getDefinition() );
221 OComponentDefinition_Impl::const_iterator aFind = rDefinition.find( _rName );
222 if ( aFind != rDefinition.end() )
224 aFind->second->addPropertyChangeListener(OUString(),m_xColumnPropertyListener.get());
225 return new OTableColumnWrapper( aFind->second, aFind->second, true );
227 OSL_FAIL( "OComponentDefinition::createColumn: is this a valid case?" );
228 // This here is the last place creating a OTableColumn, and somehow /me thinks it is not needed ...
229 return new OTableColumn( _rName );
232 Reference< XPropertySet > OComponentDefinition::createColumnDescriptor()
234 return new OTableColumnDescriptor( true );
237 void OComponentDefinition::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception, std::exception)
239 ODataSettings::setFastPropertyValue_NoBroadcast(nHandle,rValue);
240 notifyDataSourceModified();
243 void OComponentDefinition::columnDropped(const OUString& _sName)
245 getDefinition().erase( _sName );
246 notifyDataSourceModified();
249 void OComponentDefinition::columnAppended( const Reference< XPropertySet >& _rxSourceDescriptor )
251 OUString sName;
252 _rxSourceDescriptor->getPropertyValue( PROPERTY_NAME ) >>= sName;
254 Reference<XPropertySet> xColDesc = new OTableColumnDescriptor( true );
255 ::comphelper::copyProperties( _rxSourceDescriptor, xColDesc );
256 getDefinition().insert( sName, xColDesc );
258 // formerly, here was a setParent at the xColDesc. The parent used was an adapter (ChildHelper_Impl)
259 // which held another XChild weak, and forwarded all getParent requests to this other XChild.
260 // m_pColumns was used for this. This was nonsense, since m_pColumns dies when our instance dies,
261 // but xColDesc will live longer than this. So effectively, the setParent call was pretty useless.
263 // The intention for this parenting was that the column descriptor is able to find the data source,
264 // by traveling up the parent hierarchy until there's an XDataSource. This didn't work (which
265 // for instance causes #i65023#). We need another way to properly ensure this.
267 notifyDataSourceModified();
270 } // namespace dbaccess
272 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* SAL_CALL
273 com_sun_star_comp_dba_OComponentDefinition(css::uno::XComponentContext* context,
274 css::uno::Sequence<css::uno::Any> const &)
276 return cppu::acquire(new dbaccess::OComponentDefinition(
277 context, nullptr, dbaccess::TContentPtr(new dbaccess::OComponentDefinition_Impl)));
280 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */