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