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 "dbastrings.hrc"
23 #include "module_dba.hxx"
24 #include "services.hxx"
26 #include <boost/noncopyable.hpp>
27 #include <tools/debug.hxx>
28 #include <osl/diagnose.h>
29 #include <comphelper/sequence.hxx>
30 #include <com/sun/star/lang/DisposedException.hpp>
31 #include <com/sun/star/beans/PropertyAttribute.hpp>
32 #include <comphelper/property.hxx>
33 #include "definitioncolumn.hxx"
34 #include <cppuhelper/implbase1.hxx>
36 using namespace ::com::sun::star::uno
;
37 using namespace ::com::sun::star::sdbc
;
38 using namespace ::com::sun::star::lang
;
40 using namespace ::com::sun::star::beans
;
41 using namespace ::com::sun::star::container
;
42 using namespace ::osl
;
43 using namespace ::comphelper
;
44 using namespace ::cppu
;
46 extern "C" void SAL_CALL
createRegistryInfo_OComponentDefinition()
48 static ::dba::OAutoRegistration
< ::dbaccess::OComponentDefinition
> aAutoRegistration
;
54 /// helper class for column property change events which holds the OComponentDefinition weak
55 typedef ::cppu::WeakImplHelper1
< XPropertyChangeListener
> TColumnPropertyListener_BASE
;
56 class OColumnPropertyListener
:
57 public TColumnPropertyListener_BASE
, private boost::noncopyable
59 OComponentDefinition
* m_pComponent
;
61 virtual ~OColumnPropertyListener(){}
63 OColumnPropertyListener(OComponentDefinition
* _pComponent
) : m_pComponent(_pComponent
){}
64 // XPropertyChangeListener
65 virtual void SAL_CALL
propertyChange( const PropertyChangeEvent
& /*_rEvent*/ ) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
68 m_pComponent
->notifyDataSourceModified();
71 virtual void SAL_CALL
disposing( const EventObject
& /*_rSource*/ ) throw (RuntimeException
, std::exception
) SAL_OVERRIDE
74 void clear() { m_pComponent
= NULL
; }
77 OComponentDefinition_Impl::OComponentDefinition_Impl()
81 OComponentDefinition_Impl::~OComponentDefinition_Impl()
85 // OComponentDefinition
88 void OComponentDefinition::initialize( const Sequence
< Any
>& aArguments
) throw(Exception
, std::exception
)
91 if( (aArguments
.getLength() == 1) && (aArguments
[0] >>= rName
) )
93 Sequence
< Any
> aNewArgs(1);
95 aValue
.Name
= PROPERTY_NAME
;
96 aValue
.Value
<<= rName
;
97 aNewArgs
[0] <<= aValue
;
98 OContentHelper::initialize(aNewArgs
);
101 OContentHelper::initialize(aArguments
);
104 void OComponentDefinition::registerProperties()
106 m_xColumnPropertyListener
= new OColumnPropertyListener(this);
107 OComponentDefinition_Impl
& rDefinition( getDefinition() );
108 ODataSettings::registerPropertiesFor( &rDefinition
);
110 registerProperty(PROPERTY_NAME
, PROPERTY_ID_NAME
, PropertyAttribute::BOUND
| PropertyAttribute::READONLY
|PropertyAttribute::CONSTRAINED
,
111 &rDefinition
.m_aProps
.aTitle
, cppu::UnoType
<decltype(rDefinition
.m_aProps
.aTitle
)>::get());
115 registerProperty(PROPERTY_SCHEMANAME
, PROPERTY_ID_SCHEMANAME
, PropertyAttribute::BOUND
,
116 &rDefinition
.m_sSchemaName
, cppu::UnoType
<decltype(rDefinition
.m_sSchemaName
)>::get());
118 registerProperty(PROPERTY_CATALOGNAME
, PROPERTY_ID_CATALOGNAME
, PropertyAttribute::BOUND
,
119 &rDefinition
.m_sCatalogName
, cppu::UnoType
<decltype(rDefinition
.m_sCatalogName
)>::get());
123 OComponentDefinition::OComponentDefinition(const Reference
< XComponentContext
>& _xORB
124 ,const Reference
< XInterface
>& _xParentContainer
125 ,const TContentPtr
& _pImpl
127 :OContentHelper(_xORB
,_xParentContainer
,_pImpl
)
128 ,ODataSettings(OContentHelper::rBHelper
,!_bTable
)
131 registerProperties();
134 OComponentDefinition::~OComponentDefinition()
138 OComponentDefinition::OComponentDefinition( const Reference
< XInterface
>& _rxContainer
139 ,const OUString
& _rElementName
140 ,const Reference
< XComponentContext
>& _xORB
141 ,const TContentPtr
& _pImpl
143 :OContentHelper(_xORB
,_rxContainer
,_pImpl
)
144 ,ODataSettings(OContentHelper::rBHelper
,!_bTable
)
147 registerProperties();
149 m_pImpl
->m_aProps
.aTitle
= _rElementName
;
150 OSL_ENSURE(!m_pImpl
->m_aProps
.aTitle
.isEmpty(), "OComponentDefinition::OComponentDefinition : invalid name !");
153 css::uno::Sequence
<sal_Int8
> OComponentDefinition::getImplementationId()
154 throw (css::uno::RuntimeException
, std::exception
)
156 return css::uno::Sequence
<sal_Int8
>();
159 IMPLEMENT_GETTYPES3(OComponentDefinition
,ODataSettings
,OContentHelper
,OComponentDefinition_BASE
);
160 IMPLEMENT_FORWARD_XINTERFACE3( OComponentDefinition
,OContentHelper
,ODataSettings
,OComponentDefinition_BASE
)
162 OUString
OComponentDefinition::getImplementationName_static( ) throw(RuntimeException
)
164 return OUString("com.sun.star.comp.dba.OComponentDefinition");
167 OUString SAL_CALL
OComponentDefinition::getImplementationName( ) throw(RuntimeException
, std::exception
)
169 return getImplementationName_static();
172 Sequence
< OUString
> OComponentDefinition::getSupportedServiceNames_static( ) throw(RuntimeException
)
174 Sequence
< OUString
> aServices(2);
175 aServices
[0] = "com.sun.star.sdb.TableDefinition";
176 aServices
[1] = "com.sun.star.ucb.Content";
181 Sequence
< OUString
> SAL_CALL
OComponentDefinition::getSupportedServiceNames( ) throw(RuntimeException
, std::exception
)
183 return getSupportedServiceNames_static();
186 Reference
< XInterface
> OComponentDefinition::Create( const Reference
< XComponentContext
>& _rxContext
)
188 return *(new OComponentDefinition( _rxContext
, NULL
, TContentPtr( new OComponentDefinition_Impl
) ) );
191 void SAL_CALL
OComponentDefinition::disposing()
193 OContentHelper::disposing();
194 if ( m_pColumns
.get() )
195 m_pColumns
->disposing();
196 m_xColumnPropertyListener
->clear();
197 m_xColumnPropertyListener
.clear();
200 IPropertyArrayHelper
& OComponentDefinition::getInfoHelper()
202 return *getArrayHelper();
205 IPropertyArrayHelper
* OComponentDefinition::createArrayHelper( ) const
207 Sequence
< Property
> aProps
;
208 describeProperties(aProps
);
209 return new OPropertyArrayHelper(aProps
);
212 Reference
< XPropertySetInfo
> SAL_CALL
OComponentDefinition::getPropertySetInfo( ) throw(RuntimeException
, std::exception
)
214 Reference
<XPropertySetInfo
> xInfo( createPropertySetInfo( getInfoHelper() ) );
218 OUString
OComponentDefinition::determineContentType() const
221 ? OUString( "application/vnd.org.openoffice.DatabaseTable" )
222 : OUString( "application/vnd.org.openoffice.DatabaseCommandDefinition" );
225 Reference
< XNameAccess
> OComponentDefinition::getColumns() throw (RuntimeException
, std::exception
)
227 ::osl::MutexGuard
aGuard(m_aMutex
);
228 ::connectivity::checkDisposed(OContentHelper::rBHelper
.bDisposed
);
230 if ( !m_pColumns
.get() )
232 ::std::vector
< OUString
> aNames
;
234 const OComponentDefinition_Impl
& rDefinition( getDefinition() );
235 aNames
.reserve( rDefinition
.size() );
237 OComponentDefinition_Impl::const_iterator aIter
= rDefinition
.begin();
238 OComponentDefinition_Impl::const_iterator aEnd
= rDefinition
.end();
239 for ( ; aIter
!= aEnd
; ++aIter
)
240 aNames
.push_back( aIter
->first
);
242 m_pColumns
.reset( new OColumns( *this, m_aMutex
, true, aNames
, this, NULL
, true, false, false ) );
243 m_pColumns
->setParent( *this );
245 return m_pColumns
.get();
248 OColumn
* OComponentDefinition::createColumn(const OUString
& _rName
) const
250 const OComponentDefinition_Impl
& rDefinition( getDefinition() );
251 OComponentDefinition_Impl::const_iterator aFind
= rDefinition
.find( _rName
);
252 if ( aFind
!= rDefinition
.end() )
254 aFind
->second
->addPropertyChangeListener(OUString(),m_xColumnPropertyListener
.get());
255 return new OTableColumnWrapper( aFind
->second
, aFind
->second
, true );
257 OSL_FAIL( "OComponentDefinition::createColumn: is this a valid case?" );
258 // This here is the last place creating a OTableColumn, and somehow /me thinks it is not needed ...
259 return new OTableColumn( _rName
);
262 Reference
< XPropertySet
> OComponentDefinition::createColumnDescriptor()
264 return new OTableColumnDescriptor( true );
267 void OComponentDefinition::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle
,const Any
& rValue
) throw (Exception
, std::exception
)
269 ODataSettings::setFastPropertyValue_NoBroadcast(nHandle
,rValue
);
270 notifyDataSourceModified();
273 void OComponentDefinition::columnDropped(const OUString
& _sName
)
275 getDefinition().erase( _sName
);
276 notifyDataSourceModified();
279 void OComponentDefinition::columnAppended( const Reference
< XPropertySet
>& _rxSourceDescriptor
)
282 _rxSourceDescriptor
->getPropertyValue( PROPERTY_NAME
) >>= sName
;
284 Reference
<XPropertySet
> xColDesc
= new OTableColumnDescriptor( true );
285 ::comphelper::copyProperties( _rxSourceDescriptor
, xColDesc
);
286 getDefinition().insert( sName
, xColDesc
);
288 // formerly, here was a setParent at the xColDesc. The parent used was an adapter (ChildHelper_Impl)
289 // which held another XChild weak, and forwarded all getParent requests to this other XChild.
290 // m_pColumns was used for this. This was nonsense, since m_pColumns dies when our instance dies,
291 // but xColDesc will live longer than this. So effectively, the setParent call was pretty useless.
293 // The intention for this parenting was that the column descriptor is able to find the data source,
294 // by traveling up the parent hierarchy until there's an XDataSource. This didn't work (which
295 // for instance causes #i65023#). We need another way to properly ensure this.
297 notifyDataSourceModified();
300 } // namespace dbaccess
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */