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 3 : extern "C" void SAL_CALL createRegistryInfo_OComponentDefinition()
47 : {
48 3 : static ::dba::OAutoRegistration< ::dbaccess::OComponentDefinition > aAutoRegistration;
49 3 : }
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 0 : virtual ~OColumnPropertyListener(){}
64 : public:
65 0 : OColumnPropertyListener(OComponentDefinition* _pComponent) : m_pComponent(_pComponent){}
66 : // XPropertyChangeListener
67 0 : virtual void SAL_CALL propertyChange( const PropertyChangeEvent& /*_rEvent*/ ) throw (RuntimeException)
68 : {
69 0 : if ( m_pComponent )
70 0 : m_pComponent->notifyDataSourceModified();
71 0 : }
72 : // XEventListener
73 0 : virtual void SAL_CALL disposing( const EventObject& /*_rSource*/ ) throw (RuntimeException)
74 : {
75 0 : }
76 0 : void clear() { m_pComponent = NULL; }
77 : };
78 : DBG_NAME(OComponentDefinition_Impl)
79 0 : OComponentDefinition_Impl::OComponentDefinition_Impl()
80 : {
81 : DBG_CTOR(OComponentDefinition_Impl,NULL);
82 0 : }
83 :
84 0 : OComponentDefinition_Impl::~OComponentDefinition_Impl()
85 : {
86 : DBG_DTOR(OComponentDefinition_Impl,NULL);
87 0 : }
88 : //==========================================================================
89 : //= OComponentDefinition
90 : //==========================================================================
91 :
92 : DBG_NAME(OComponentDefinition)
93 :
94 0 : void OComponentDefinition::registerProperties()
95 : {
96 0 : m_xColumnPropertyListener = ::comphelper::ImplementationReference<OColumnPropertyListener,XPropertyChangeListener>(new OColumnPropertyListener(this));
97 0 : OComponentDefinition_Impl& rDefinition( getDefinition() );
98 0 : ODataSettings::registerPropertiesFor( &rDefinition );
99 :
100 : registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY|PropertyAttribute::CONSTRAINED,
101 0 : &rDefinition.m_aProps.aTitle, ::getCppuType(&rDefinition.m_aProps.aTitle));
102 :
103 0 : if ( m_bTable )
104 : {
105 : registerProperty(PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME, PropertyAttribute::BOUND,
106 0 : &rDefinition.m_sSchemaName, ::getCppuType(&rDefinition.m_sSchemaName));
107 :
108 : registerProperty(PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME, PropertyAttribute::BOUND,
109 0 : &rDefinition.m_sCatalogName, ::getCppuType(&rDefinition.m_sCatalogName));
110 : }
111 0 : }
112 :
113 0 : 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 0 : ,m_bTable(_bTable)
120 : {
121 : DBG_CTOR(OComponentDefinition, NULL);
122 0 : registerProperties();
123 0 : }
124 :
125 0 : OComponentDefinition::~OComponentDefinition()
126 : {
127 : DBG_DTOR(OComponentDefinition, NULL);
128 0 : }
129 :
130 :
131 0 : 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 0 : ,m_bTable(_bTable)
139 : {
140 : DBG_CTOR(OComponentDefinition, NULL);
141 0 : registerProperties();
142 :
143 0 : m_pImpl->m_aProps.aTitle = _rElementName;
144 : OSL_ENSURE(!m_pImpl->m_aProps.aTitle.isEmpty(), "OComponentDefinition::OComponentDefinition : invalid name !");
145 0 : }
146 :
147 0 : IMPLEMENT_IMPLEMENTATION_ID(OComponentDefinition);
148 0 : IMPLEMENT_GETTYPES3(OComponentDefinition,ODataSettings,OContentHelper,OComponentDefinition_BASE);
149 0 : IMPLEMENT_FORWARD_XINTERFACE3( OComponentDefinition,OContentHelper,ODataSettings,OComponentDefinition_BASE)
150 :
151 3 : ::rtl::OUString OComponentDefinition::getImplementationName_static( ) throw(RuntimeException)
152 : {
153 3 : 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 3 : Sequence< ::rtl::OUString > OComponentDefinition::getSupportedServiceNames_static( ) throw(RuntimeException)
162 : {
163 3 : Sequence< ::rtl::OUString > aServices(2);
164 3 : aServices.getArray()[0] = SERVICE_SDB_TABLEDEFINITION;
165 3 : aServices.getArray()[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.Content"));
166 :
167 3 : return aServices;
168 : }
169 :
170 0 : Sequence< ::rtl::OUString > SAL_CALL OComponentDefinition::getSupportedServiceNames( ) throw(RuntimeException)
171 : {
172 0 : return getSupportedServiceNames_static();
173 : }
174 :
175 0 : Reference< XInterface > OComponentDefinition::Create( const Reference< XComponentContext >& _rxContext )
176 : {
177 0 : ::comphelper::ComponentContext aContext( _rxContext );
178 0 : return *(new OComponentDefinition( aContext.getLegacyServiceFactory(), NULL, TContentPtr( new OComponentDefinition_Impl ) ) );
179 : }
180 :
181 0 : void SAL_CALL OComponentDefinition::disposing()
182 : {
183 0 : OContentHelper::disposing();
184 0 : if ( m_pColumns.get() )
185 0 : m_pColumns->disposing();
186 0 : m_xColumnPropertyListener->clear();
187 0 : m_xColumnPropertyListener.dispose();
188 0 : }
189 :
190 0 : IPropertyArrayHelper& OComponentDefinition::getInfoHelper()
191 : {
192 0 : return *getArrayHelper();
193 : }
194 :
195 0 : IPropertyArrayHelper* OComponentDefinition::createArrayHelper( ) const
196 : {
197 0 : Sequence< Property > aProps;
198 0 : describeProperties(aProps);
199 0 : return new OPropertyArrayHelper(aProps);
200 : }
201 :
202 0 : Reference< XPropertySetInfo > SAL_CALL OComponentDefinition::getPropertySetInfo( ) throw(RuntimeException)
203 : {
204 0 : Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
205 0 : 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 0 : Reference< XNameAccess> OComponentDefinition::getColumns() throw (RuntimeException)
216 : {
217 0 : ::osl::MutexGuard aGuard(m_aMutex);
218 0 : ::connectivity::checkDisposed(OContentHelper::rBHelper.bDisposed);
219 :
220 0 : if ( !m_pColumns.get() )
221 : {
222 0 : ::std::vector< ::rtl::OUString> aNames;
223 :
224 0 : const OComponentDefinition_Impl& rDefinition( getDefinition() );
225 0 : aNames.reserve( rDefinition.size() );
226 :
227 0 : OComponentDefinition_Impl::const_iterator aIter = rDefinition.begin();
228 0 : OComponentDefinition_Impl::const_iterator aEnd = rDefinition.end();
229 0 : for ( ; aIter != aEnd; ++aIter )
230 0 : aNames.push_back( aIter->first );
231 :
232 0 : m_pColumns.reset( new OColumns( *this, m_aMutex, sal_True, aNames, this, NULL, sal_True, sal_False, sal_False ) );
233 0 : m_pColumns->setParent( *this );
234 : }
235 0 : return m_pColumns.get();
236 : }
237 :
238 0 : OColumn* OComponentDefinition::createColumn(const ::rtl::OUString& _rName) const
239 : {
240 0 : const OComponentDefinition_Impl& rDefinition( getDefinition() );
241 0 : OComponentDefinition_Impl::const_iterator aFind = rDefinition.find( _rName );
242 0 : if ( aFind != rDefinition.end() )
243 : {
244 0 : aFind->second->addPropertyChangeListener(::rtl::OUString(),m_xColumnPropertyListener.getRef());
245 0 : 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 0 : return new OTableColumn( _rName );
250 : }
251 :
252 0 : Reference< XPropertySet > OComponentDefinition::createColumnDescriptor()
253 : {
254 0 : return new OTableColumnDescriptor( true );
255 : }
256 :
257 0 : void OComponentDefinition::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
258 : {
259 0 : ODataSettings::setFastPropertyValue_NoBroadcast(nHandle,rValue);
260 0 : notifyDataSourceModified();
261 0 : }
262 :
263 0 : void OComponentDefinition::columnDropped(const ::rtl::OUString& _sName)
264 : {
265 0 : getDefinition().erase( _sName );
266 0 : notifyDataSourceModified();
267 0 : }
268 :
269 0 : void OComponentDefinition::columnAppended( const Reference< XPropertySet >& _rxSourceDescriptor )
270 : {
271 0 : ::rtl::OUString sName;
272 0 : _rxSourceDescriptor->getPropertyValue( PROPERTY_NAME ) >>= sName;
273 :
274 0 : Reference<XPropertySet> xColDesc = new OTableColumnDescriptor( true );
275 0 : ::comphelper::copyProperties( _rxSourceDescriptor, xColDesc );
276 0 : 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 0 : notifyDataSourceModified();
288 0 : }
289 :
290 : } // namespace dbaccess
291 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|