update dev300-m58
[ooovba.git] / dbaccess / source / core / dataaccess / ComponentDefinition.cxx
bloba118a4087fb6b34dd06d89ddab9307ba119f3dc9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ComponentDefinition.cxx,v $
10 * $Revision: 1.16 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 #ifndef DBA_COREDATAACESS_COMPONENTDEFINITION_HXX
35 #include "ComponentDefinition.hxx"
36 #endif
37 #ifndef _DBASHARED_APITOOLS_HXX_
38 #include "apitools.hxx"
39 #endif
40 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
41 #include "dbastrings.hrc"
42 #endif
43 #include "module_dba.hxx"
45 #ifndef _TOOLS_DEBUG_HXX
46 #include <tools/debug.hxx>
47 #endif
48 #ifndef _COMPHELPER_SEQUENCE_HXX_
49 #include <comphelper/sequence.hxx>
50 #endif
51 #ifndef _COM_SUN_STAR_LANG_DISPOSEDEXCEPTION_HPP_
52 #include <com/sun/star/lang/DisposedException.hpp>
53 #endif
54 #ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_
55 #include <com/sun/star/beans/PropertyAttribute.hpp>
56 #endif
57 #ifndef _COMPHELPER_PROPERTY_HXX_
58 #include <comphelper/property.hxx>
59 #endif
60 #ifndef _DBACORE_DEFINITIONCOLUMN_HXX_
61 #include "definitioncolumn.hxx"
62 #endif
63 #include <cppuhelper/implbase1.hxx>
64 #include <comphelper/componentcontext.hxx>
66 using namespace ::com::sun::star::uno;
67 using namespace ::com::sun::star::sdbc;
68 using namespace ::com::sun::star::lang;
70 using namespace ::com::sun::star::beans;
71 using namespace ::com::sun::star::container;
72 using namespace ::osl;
73 using namespace ::comphelper;
74 using namespace ::cppu;
76 extern "C" void SAL_CALL createRegistryInfo_OComponentDefinition()
78 static ::dba::OAutoRegistration< ::dbaccess::OComponentDefinition > aAutoRegistration;
81 //........................................................................
82 namespace dbaccess
84 //........................................................................
85 /// helper class for column property change events which holds the OComponentDefinition weak
86 typedef ::cppu::WeakImplHelper1 < XPropertyChangeListener > TColumnPropertyListener_BASE;
87 class OColumnPropertyListener : public TColumnPropertyListener_BASE
89 OComponentDefinition* m_pComponent;
91 OColumnPropertyListener(const OColumnPropertyListener&);
92 void operator =(const OColumnPropertyListener&);
93 protected:
94 virtual ~OColumnPropertyListener(){}
95 public:
96 OColumnPropertyListener(OComponentDefinition* _pComponent) : m_pComponent(_pComponent){}
97 // XPropertyChangeListener
98 virtual void SAL_CALL propertyChange( const PropertyChangeEvent& /*_rEvent*/ ) throw (RuntimeException)
100 if ( m_pComponent )
101 m_pComponent->notifyDataSourceModified();
103 // XEventListener
104 virtual void SAL_CALL disposing( const EventObject& /*_rSource*/ ) throw (RuntimeException)
107 void clear() { m_pComponent = NULL; }
109 DBG_NAME(OComponentDefinition_Impl)
110 OComponentDefinition_Impl::OComponentDefinition_Impl()
112 DBG_CTOR(OComponentDefinition_Impl,NULL);
114 // -----------------------------------------------------------------------------
115 OComponentDefinition_Impl::~OComponentDefinition_Impl()
117 DBG_DTOR(OComponentDefinition_Impl,NULL);
119 //==========================================================================
120 //= OComponentDefinition
121 //==========================================================================
122 //--------------------------------------------------------------------------
123 DBG_NAME(OComponentDefinition)
124 //--------------------------------------------------------------------------
125 void OComponentDefinition::registerProperties()
127 m_xColumnPropertyListener = ::comphelper::ImplementationReference<OColumnPropertyListener,XPropertyChangeListener>(new OColumnPropertyListener(this));
128 OComponentDefinition_Impl& rDefinition( getDefinition() );
129 ODataSettings::registerPropertiesFor( &rDefinition );
131 registerProperty(PROPERTY_NAME, PROPERTY_ID_NAME, PropertyAttribute::BOUND | PropertyAttribute::READONLY|PropertyAttribute::CONSTRAINED,
132 &rDefinition.m_aProps.aTitle, ::getCppuType(&rDefinition.m_aProps.aTitle));
134 if ( m_bTable )
136 registerProperty(PROPERTY_SCHEMANAME, PROPERTY_ID_SCHEMANAME, PropertyAttribute::BOUND,
137 &rDefinition.m_sSchemaName, ::getCppuType(&rDefinition.m_sSchemaName));
139 registerProperty(PROPERTY_CATALOGNAME, PROPERTY_ID_CATALOGNAME, PropertyAttribute::BOUND,
140 &rDefinition.m_sCatalogName, ::getCppuType(&rDefinition.m_sCatalogName));
144 //--------------------------------------------------------------------------
145 OComponentDefinition::OComponentDefinition(const Reference< XMultiServiceFactory >& _xORB
146 ,const Reference< XInterface >& _xParentContainer
147 ,const TContentPtr& _pImpl
148 ,sal_Bool _bTable)
149 :OContentHelper(_xORB,_xParentContainer,_pImpl)
150 ,ODataSettings(OContentHelper::rBHelper,!_bTable)
151 ,m_bTable(_bTable)
153 DBG_CTOR(OComponentDefinition, NULL);
154 registerProperties();
156 //--------------------------------------------------------------------------
157 OComponentDefinition::~OComponentDefinition()
159 DBG_DTOR(OComponentDefinition, NULL);
162 //--------------------------------------------------------------------------
163 OComponentDefinition::OComponentDefinition( const Reference< XInterface >& _rxContainer
164 ,const ::rtl::OUString& _rElementName
165 ,const Reference< XMultiServiceFactory >& _xORB
166 ,const TContentPtr& _pImpl
167 ,sal_Bool _bTable)
168 :OContentHelper(_xORB,_rxContainer,_pImpl)
169 ,ODataSettings(OContentHelper::rBHelper,!_bTable)
170 ,m_bTable(_bTable)
172 DBG_CTOR(OComponentDefinition, NULL);
173 registerProperties();
175 m_pImpl->m_aProps.aTitle = _rElementName;
176 DBG_ASSERT(m_pImpl->m_aProps.aTitle.getLength() != 0, "OComponentDefinition::OComponentDefinition : invalid name !");
179 //--------------------------------------------------------------------------
180 IMPLEMENT_IMPLEMENTATION_ID(OComponentDefinition);
181 IMPLEMENT_GETTYPES3(OComponentDefinition,ODataSettings,OContentHelper,OComponentDefinition_BASE);
182 IMPLEMENT_FORWARD_XINTERFACE3( OComponentDefinition,OContentHelper,ODataSettings,OComponentDefinition_BASE)
183 //--------------------------------------------------------------------------
184 ::rtl::OUString OComponentDefinition::getImplementationName_static( ) throw(RuntimeException)
186 return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.dba.OComponentDefinition"));
189 //--------------------------------------------------------------------------
190 ::rtl::OUString SAL_CALL OComponentDefinition::getImplementationName( ) throw(RuntimeException)
192 return getImplementationName_static();
195 //--------------------------------------------------------------------------
196 Sequence< ::rtl::OUString > OComponentDefinition::getSupportedServiceNames_static( ) throw(RuntimeException)
198 Sequence< ::rtl::OUString > aServices(2);
199 aServices.getArray()[0] = SERVICE_SDB_TABLEDEFINITION;
200 aServices.getArray()[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.ucb.Content"));
202 return aServices;
205 //--------------------------------------------------------------------------
206 Sequence< ::rtl::OUString > SAL_CALL OComponentDefinition::getSupportedServiceNames( ) throw(RuntimeException)
208 return getSupportedServiceNames_static();
210 //------------------------------------------------------------------------------
211 Reference< XInterface > OComponentDefinition::Create( const Reference< XComponentContext >& _rxContext )
213 ::comphelper::ComponentContext aContext( _rxContext );
214 return *(new OComponentDefinition( aContext.getLegacyServiceFactory(), NULL, TContentPtr( new OComponentDefinition_Impl ) ) );
216 // -----------------------------------------------------------------------------
217 void SAL_CALL OComponentDefinition::disposing()
219 OContentHelper::disposing();
220 if ( m_pColumns.get() )
221 m_pColumns->disposing();
222 m_xColumnPropertyListener->clear();
223 m_xColumnPropertyListener.dispose();
225 // -----------------------------------------------------------------------------
226 IPropertyArrayHelper& OComponentDefinition::getInfoHelper()
228 return *getArrayHelper();
230 //--------------------------------------------------------------------------
231 IPropertyArrayHelper* OComponentDefinition::createArrayHelper( ) const
233 Sequence< Property > aProps;
234 describeProperties(aProps);
235 return new OPropertyArrayHelper(aProps);
237 //--------------------------------------------------------------------------
238 Reference< XPropertySetInfo > SAL_CALL OComponentDefinition::getPropertySetInfo( ) throw(RuntimeException)
240 Reference<XPropertySetInfo> xInfo( createPropertySetInfo( getInfoHelper() ) );
241 return xInfo;
244 // -----------------------------------------------------------------------------
245 ::rtl::OUString OComponentDefinition::determineContentType() const
247 return m_bTable
248 ? ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.org.openoffice.DatabaseTable" ) )
249 : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.org.openoffice.DatabaseCommandDefinition" ) );
252 // -----------------------------------------------------------------------------
253 Reference< XNameAccess> OComponentDefinition::getColumns() throw (RuntimeException)
255 ::osl::MutexGuard aGuard(m_aMutex);
256 ::connectivity::checkDisposed(OContentHelper::rBHelper.bDisposed);
258 if ( !m_pColumns.get() )
260 ::std::vector< ::rtl::OUString> aNames;
262 const OComponentDefinition_Impl& rDefinition( getDefinition() );
263 aNames.reserve( rDefinition.size() );
265 OComponentDefinition_Impl::const_iterator aIter = rDefinition.begin();
266 OComponentDefinition_Impl::const_iterator aEnd = rDefinition.end();
267 for ( ; aIter != aEnd; ++aIter )
268 aNames.push_back( aIter->first );
270 m_pColumns.reset( new OColumns( *this, m_aMutex, sal_True, aNames, this, NULL, sal_True, sal_False, sal_False ) );
271 m_pColumns->setParent( *this );
273 return m_pColumns.get();
275 // -----------------------------------------------------------------------------
276 OColumn* OComponentDefinition::createColumn(const ::rtl::OUString& _rName) const
278 const OComponentDefinition_Impl& rDefinition( getDefinition() );
279 OComponentDefinition_Impl::const_iterator aFind = rDefinition.find( _rName );
280 if ( aFind != rDefinition.end() )
282 aFind->second->addPropertyChangeListener(::rtl::OUString(),m_xColumnPropertyListener.getRef());
283 return new OTableColumnWrapper( aFind->second, aFind->second, sal_True );
285 return new OTableColumn( _rName );
287 // -----------------------------------------------------------------------------
288 Reference< XPropertySet > OComponentDefinition::createColumnDescriptor()
290 return new OTableColumnDescriptor();
292 // -----------------------------------------------------------------------------
293 void OComponentDefinition::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle,const Any& rValue) throw (Exception)
295 ODataSettings::setFastPropertyValue_NoBroadcast(nHandle,rValue);
296 notifyDataSourceModified();
298 // -----------------------------------------------------------------------------
299 void OComponentDefinition::columnDropped(const ::rtl::OUString& _sName)
301 getDefinition().erase( _sName );
302 notifyDataSourceModified();
304 // -----------------------------------------------------------------------------
305 void OComponentDefinition::columnAppended( const Reference< XPropertySet >& _rxSourceDescriptor )
307 ::rtl::OUString sName;
308 _rxSourceDescriptor->getPropertyValue( PROPERTY_NAME ) >>= sName;
310 Reference<XPropertySet> xColDesc = new OTableColumnDescriptor();
311 ::comphelper::copyProperties( _rxSourceDescriptor, xColDesc );
312 getDefinition().insert( sName, xColDesc );
314 // formerly, here was a setParent at the xColDesc. The parent used was an adapter (ChildHelper_Impl)
315 // which held another XChild weak, and forwarded all getParent requests to this other XChild.
316 // m_pColumns was used for this. This was nonsense, since m_pColumns dies when our instance dies,
317 // but xColDesc will live longer than this. So effectively, the setParent call was pretty useless.
319 // The intention for this parenting was that the column descriptor is able to find the data source,
320 // by traveling up the parent hierachy until there's an XDataSource. This didn't work (which
321 // for instance causes #i65023#). We need another way to properly ensure this.
323 notifyDataSourceModified();
326 //........................................................................
327 } // namespace dbaccess
328 //........................................................................