Branch data Line data Source code
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 : :
21 : : #include "ComponentDefinition.hxx"
22 : : #include "apitools.hxx"
23 : : #include "dbastrings.hrc"
24 : : #include "module_dba.hxx"
25 : :
26 : : #include <tools/debug.hxx>
27 : : #include <osl/diagnose.h>
28 : : #include <comphelper/sequence.hxx>
29 : : #include <com/sun/star/lang/DisposedException.hpp>
30 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
31 : : #include <comphelper/property.hxx>
32 : : #include "definitioncolumn.hxx"
33 : : #include <cppuhelper/implbase1.hxx>
34 : : #include <comphelper/componentcontext.hxx>
35 : :
36 : : using namespace ::com::sun::star::uno;
37 : : using namespace ::com::sun::star::sdbc;
38 : : using namespace ::com::sun::star::lang;
39 : :
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;
45 : :
46 : 32 : extern "C" void SAL_CALL createRegistryInfo_OComponentDefinition()
47 : : {
48 [ + - ][ + - ]: 32 : static ::dba::OAutoRegistration< ::dbaccess::OComponentDefinition > aAutoRegistration;
[ + - ][ # # ]
49 : 32 : }
50 : :
51 : : namespace dbaccess
52 : : {
53 : :
54 : : /// helper class for column property change events which holds the OComponentDefinition weak
55 : : typedef ::cppu::WeakImplHelper1 < XPropertyChangeListener > TColumnPropertyListener_BASE;
56 : : class OColumnPropertyListener : public TColumnPropertyListener_BASE
57 : : {
58 : : OComponentDefinition* m_pComponent;
59 : :
60 : : OColumnPropertyListener(const OColumnPropertyListener&);
61 : : void operator =(const OColumnPropertyListener&);
62 : : protected:
63 [ - + ]: 108 : virtual ~OColumnPropertyListener(){}
64 : : public:
65 : 54 : OColumnPropertyListener(OComponentDefinition* _pComponent) : m_pComponent(_pComponent){}
66 : : // XPropertyChangeListener
67 : 480 : virtual void SAL_CALL propertyChange( const PropertyChangeEvent& /*_rEvent*/ ) throw (RuntimeException)
68 : : {
69 [ + - ]: 480 : if ( m_pComponent )
70 : 480 : m_pComponent->notifyDataSourceModified();
71 : 480 : }
72 : : // XEventListener
73 : 848 : virtual void SAL_CALL disposing( const EventObject& /*_rSource*/ ) throw (RuntimeException)
74 : : {
75 : 848 : }
76 : 54 : void clear() { m_pComponent = NULL; }
77 : : };
78 : : DBG_NAME(OComponentDefinition_Impl)
79 [ + - ][ + - ]: 42 : OComponentDefinition_Impl::OComponentDefinition_Impl()
80 : : {
81 : : DBG_CTOR(OComponentDefinition_Impl,NULL);
82 : 42 : }
83 : :
84 [ + - ]: 42 : OComponentDefinition_Impl::~OComponentDefinition_Impl()
85 : : {
86 : : DBG_DTOR(OComponentDefinition_Impl,NULL);
87 [ - + ]: 82 : }
88 : : //==========================================================================
89 : : //= OComponentDefinition
90 : : //==========================================================================
91 : :
92 : : DBG_NAME(OComponentDefinition)
93 : :
94 : 54 : void OComponentDefinition::registerProperties()
95 : : {
96 [ + - ][ + - ]: 54 : m_xColumnPropertyListener = ::comphelper::ImplementationReference<OColumnPropertyListener,XPropertyChangeListener>(new OColumnPropertyListener(this));
97 : 54 : OComponentDefinition_Impl& rDefinition( getDefinition() );
98 : 54 : ODataSettings::registerPropertiesFor( &rDefinition );
99 : :
100 : : registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY|PropertyAttribute::CONSTRAINED,
101 [ + - ]: 54 : &rDefinition.m_aProps.aTitle, ::getCppuType(&rDefinition.m_aProps.aTitle));
102 : :
103 [ + + ]: 54 : if ( m_bTable )
104 : : {
105 : : registerProperty(PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME, PropertyAttribute::BOUND,
106 [ + - ]: 52 : &rDefinition.m_sSchemaName, ::getCppuType(&rDefinition.m_sSchemaName));
107 : :
108 : : registerProperty(PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME, PropertyAttribute::BOUND,
109 [ + - ]: 52 : &rDefinition.m_sCatalogName, ::getCppuType(&rDefinition.m_sCatalogName));
110 : : }
111 : 54 : }
112 : :
113 : 42 : OComponentDefinition::OComponentDefinition(const Reference< XMultiServiceFactory >& _xORB
114 : : ,const Reference< XInterface >& _xParentContainer
115 : : ,const TContentPtr& _pImpl
116 : : ,sal_Bool _bTable)
117 : : :OContentHelper(_xORB,_xParentContainer,_pImpl)
118 : : ,ODataSettings(OContentHelper::rBHelper,!_bTable)
119 [ + - ][ + - ]: 42 : ,m_bTable(_bTable)
[ + - ]
120 : : {
121 : : DBG_CTOR(OComponentDefinition, NULL);
122 [ + - ]: 42 : registerProperties();
123 : 42 : }
124 : :
125 [ + - ][ + - ]: 54 : OComponentDefinition::~OComponentDefinition()
[ + - ][ + - ]
126 : : {
127 : : DBG_DTOR(OComponentDefinition, NULL);
128 [ - + ]: 106 : }
129 : :
130 : :
131 : 12 : OComponentDefinition::OComponentDefinition( const Reference< XInterface >& _rxContainer
132 : : ,const ::rtl::OUString& _rElementName
133 : : ,const Reference< XMultiServiceFactory >& _xORB
134 : : ,const TContentPtr& _pImpl
135 : : ,sal_Bool _bTable)
136 : : :OContentHelper(_xORB,_rxContainer,_pImpl)
137 : : ,ODataSettings(OContentHelper::rBHelper,!_bTable)
138 [ + - ][ + - ]: 12 : ,m_bTable(_bTable)
[ + - ]
139 : : {
140 : : DBG_CTOR(OComponentDefinition, NULL);
141 [ + - ]: 12 : registerProperties();
142 : :
143 : 12 : m_pImpl->m_aProps.aTitle = _rElementName;
144 : : OSL_ENSURE(!m_pImpl->m_aProps.aTitle.isEmpty(), "OComponentDefinition::OComponentDefinition : invalid name !");
145 : 12 : }
146 : :
147 [ # # ][ # # ]: 0 : IMPLEMENT_IMPLEMENTATION_ID(OComponentDefinition);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
148 [ # # ][ # # ]: 0 : IMPLEMENT_GETTYPES3(OComponentDefinition,ODataSettings,OContentHelper,OComponentDefinition_BASE);
[ # # ][ # # ]
[ # # ]
149 [ + + ][ + - ]: 41406 : IMPLEMENT_FORWARD_XINTERFACE3( OComponentDefinition,OContentHelper,ODataSettings,OComponentDefinition_BASE)
[ + + ][ + - ]
150 : :
151 : 32 : ::rtl::OUString OComponentDefinition::getImplementationName_static( ) throw(RuntimeException)
152 : : {
153 : 32 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.dba.OComponentDefinition"));
154 : : }
155 : :
156 : 0 : ::rtl::OUString SAL_CALL OComponentDefinition::getImplementationName( ) throw(RuntimeException)
157 : : {
158 : 0 : return getImplementationName_static();
159 : : }
160 : :
161 : 32 : Sequence< ::rtl::OUString > OComponentDefinition::getSupportedServiceNames_static( ) throw(RuntimeException)
162 : : {
163 : 32 : Sequence< ::rtl::OUString > aServices(2);
164 [ + - ][ + - ]: 32 : aServices.getArray()[0] = SERVICE_SDB_TABLEDEFINITION;
165 [ + - ][ + - ]: 32 : aServices.getArray()[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.Content"));
166 : :
167 : 32 : return aServices;
168 : : }
169 : :
170 : 0 : Sequence< ::rtl::OUString > SAL_CALL OComponentDefinition::getSupportedServiceNames( ) throw(RuntimeException)
171 : : {
172 : 0 : return getSupportedServiceNames_static();
173 : : }
174 : :
175 : 40 : Reference< XInterface > OComponentDefinition::Create( const Reference< XComponentContext >& _rxContext )
176 : : {
177 [ + - ]: 40 : ::comphelper::ComponentContext aContext( _rxContext );
178 [ + - ][ + - ]: 40 : return *(new OComponentDefinition( aContext.getLegacyServiceFactory(), NULL, TContentPtr( new OComponentDefinition_Impl ) ) );
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
179 : : }
180 : :
181 : 54 : void SAL_CALL OComponentDefinition::disposing()
182 : : {
183 : 54 : OContentHelper::disposing();
184 [ + + ]: 54 : if ( m_pColumns.get() )
185 : 40 : m_pColumns->disposing();
186 : 54 : m_xColumnPropertyListener->clear();
187 : 54 : m_xColumnPropertyListener.dispose();
188 : 54 : }
189 : :
190 : 3944 : IPropertyArrayHelper& OComponentDefinition::getInfoHelper()
191 : : {
192 : 3944 : return *getArrayHelper();
193 : : }
194 : :
195 : 32 : IPropertyArrayHelper* OComponentDefinition::createArrayHelper( ) const
196 : : {
197 [ + - ]: 32 : Sequence< Property > aProps;
198 [ + - ]: 32 : describeProperties(aProps);
199 [ + - ][ + - ]: 32 : return new OPropertyArrayHelper(aProps);
200 : : }
201 : :
202 : 440 : Reference< XPropertySetInfo > SAL_CALL OComponentDefinition::getPropertySetInfo( ) throw(RuntimeException)
203 : : {
204 : 440 : Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
205 : 440 : return xInfo;
206 : : }
207 : :
208 : 0 : ::rtl::OUString OComponentDefinition::determineContentType() const
209 : : {
210 : : return m_bTable
211 : : ? ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.org.openoffice.DatabaseTable" ) )
212 [ # # ]: 0 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.org.openoffice.DatabaseCommandDefinition" ) );
213 : : }
214 : :
215 : 40 : Reference< XNameAccess> OComponentDefinition::getColumns() throw (RuntimeException)
216 : : {
217 [ + - ]: 40 : ::osl::MutexGuard aGuard(m_aMutex);
218 [ + - ]: 40 : ::connectivity::checkDisposed(OContentHelper::rBHelper.bDisposed);
219 : :
220 [ + - ]: 40 : if ( !m_pColumns.get() )
221 : : {
222 [ + - ]: 40 : ::std::vector< ::rtl::OUString> aNames;
223 : :
224 [ + - ]: 40 : const OComponentDefinition_Impl& rDefinition( getDefinition() );
225 [ + - ]: 40 : aNames.reserve( rDefinition.size() );
226 : :
227 : 40 : OComponentDefinition_Impl::const_iterator aIter = rDefinition.begin();
228 : 40 : OComponentDefinition_Impl::const_iterator aEnd = rDefinition.end();
229 [ + + ]: 400 : for ( ; aIter != aEnd; ++aIter )
230 [ + - ]: 360 : aNames.push_back( aIter->first );
231 : :
232 [ + - ][ + - ]: 40 : m_pColumns.reset( new OColumns( *this, m_aMutex, sal_True, aNames, this, NULL, sal_True, sal_False, sal_False ) );
233 [ + - ][ + - ]: 40 : m_pColumns->setParent( *this );
234 : : }
235 [ + - ][ + - ]: 40 : return m_pColumns.get();
[ + - ]
236 : : }
237 : :
238 : 848 : OColumn* OComponentDefinition::createColumn(const ::rtl::OUString& _rName) const
239 : : {
240 [ + - ]: 848 : const OComponentDefinition_Impl& rDefinition( getDefinition() );
241 [ + - ]: 848 : OComponentDefinition_Impl::const_iterator aFind = rDefinition.find( _rName );
242 [ + - ]: 848 : if ( aFind != rDefinition.end() )
243 : : {
244 [ + - ][ + - ]: 848 : aFind->second->addPropertyChangeListener(::rtl::OUString(),m_xColumnPropertyListener.getRef());
245 [ + - ]: 848 : return new OTableColumnWrapper( aFind->second, aFind->second, true );
246 : : }
247 : : OSL_FAIL( "OComponentDefinition::createColumn: is this a valid case?" );
248 : : // This here is the last place creating a OTableColumn, and somehow /me thinks it is not needed ...
249 [ # # ]: 848 : return new OTableColumn( _rName );
250 : : }
251 : :
252 : 720 : Reference< XPropertySet > OComponentDefinition::createColumnDescriptor()
253 : : {
254 [ + - ][ + - ]: 720 : return new OTableColumnDescriptor( true );
255 : : }
256 : :
257 : 22 : void OComponentDefinition::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
258 : : {
259 : 22 : ODataSettings::setFastPropertyValue_NoBroadcast(nHandle,rValue);
260 : 22 : notifyDataSourceModified();
261 : 22 : }
262 : :
263 : 0 : void OComponentDefinition::columnDropped(const ::rtl::OUString& _sName)
264 : : {
265 : 0 : getDefinition().erase( _sName );
266 : 0 : notifyDataSourceModified();
267 : 0 : }
268 : :
269 : 360 : void OComponentDefinition::columnAppended( const Reference< XPropertySet >& _rxSourceDescriptor )
270 : : {
271 : 360 : ::rtl::OUString sName;
272 [ + - ][ + - ]: 360 : _rxSourceDescriptor->getPropertyValue( PROPERTY_NAME ) >>= sName;
[ + - ]
273 : :
274 [ + - ][ + - ]: 360 : Reference<XPropertySet> xColDesc = new OTableColumnDescriptor( true );
[ + - ]
275 [ + - ]: 360 : ::comphelper::copyProperties( _rxSourceDescriptor, xColDesc );
276 [ + - ][ + - ]: 360 : getDefinition().insert( sName, xColDesc );
277 : :
278 : : // formerly, here was a setParent at the xColDesc. The parent used was an adapter (ChildHelper_Impl)
279 : : // which held another XChild weak, and forwarded all getParent requests to this other XChild.
280 : : // m_pColumns was used for this. This was nonsense, since m_pColumns dies when our instance dies,
281 : : // but xColDesc will live longer than this. So effectively, the setParent call was pretty useless.
282 : : //
283 : : // The intention for this parenting was that the column descriptor is able to find the data source,
284 : : // by traveling up the parent hierachy until there's an XDataSource. This didn't work (which
285 : : // for instance causes #i65023#). We need another way to properly ensure this.
286 : :
287 [ + - ]: 360 : notifyDataSourceModified();
288 : 360 : }
289 : :
290 : : } // namespace dbaccess
291 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|