bump product version to 5.0.4.1
[LibreOffice.git] / extensions / source / plugin / base / plmodel.cxx
blob8ef83b590cd619946e1fceca0de8ce40a92ec0e1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include <plugin/model.hxx>
30 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 #include <cppuhelper/queryinterface.hxx>
33 using namespace com::sun::star::uno;
36 Reference< XInterface > SAL_CALL PluginModel_CreateInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & ) throw( Exception )
38 Reference< XInterface > xService = *new PluginModel();
39 return xService;
42 Any PluginModel::queryAggregation( const Type& type ) throw( RuntimeException, std::exception )
44 Any aRet( ::cppu::queryInterface( type,
45 static_cast< ::com::sun::star::lang::XComponent* >(this),
46 static_cast< ::com::sun::star::io::XPersistObject* >(this ),
47 static_cast< ::com::sun::star::awt::XControlModel* >(this),
48 static_cast< ::com::sun::star::beans::XPropertySet* >(this),
49 static_cast< ::com::sun::star::beans::XMultiPropertySet* >(this),
50 static_cast< ::com::sun::star::beans::XFastPropertySet* >(this)
51 ) );
52 return aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( type );
56 // XPluginManager_Impl
57 Sequence< OUString > PluginModel::getSupportedServiceNames_Static() throw()
59 Sequence< OUString > aSNS( 1 );
60 aSNS[0] = "com.sun.star.plugin.PluginModel";
61 return aSNS;
65 static const char* aCreationURL = "URL";
66 static const char* aMime = "TYPE";
68 static ::osl::Mutex aPropertyMutex;
70 static ::com::sun::star::beans::Property aProps[] =
72 ::com::sun::star::beans::Property(
73 OUString::createFromAscii( aMime ),
75 ::cppu::UnoType<OUString>::get(),
76 ::com::sun::star::beans::PropertyAttribute::BOUND ),
77 ::com::sun::star::beans::Property(
78 OUString::createFromAscii( aCreationURL ),
80 ::cppu::UnoType<OUString>::get(),
81 ::com::sun::star::beans::PropertyAttribute::BOUND )
84 PluginModel::PluginModel() :
85 BroadcasterHelperHolder( aPropertyMutex ),
86 OPropertySetHelper( m_aHelper ),
87 OPropertyArrayHelper( aProps, 2 )
91 PluginModel::PluginModel(const OUString& rURL, const OUString& rMimeType ) :
92 BroadcasterHelperHolder( aPropertyMutex ),
93 OPropertySetHelper( m_aHelper ),
94 OPropertyArrayHelper( aProps, 2 ),
95 m_aCreationURL( rURL ),
96 m_aMimeType( rMimeType )
100 PluginModel::~PluginModel()
104 Reference< ::com::sun::star::beans::XPropertySetInfo > PluginModel::getPropertySetInfo() throw(std::exception)
106 static Reference< ::com::sun::star::beans::XPropertySetInfo > aInfo =
107 createPropertySetInfo( *this );
108 return aInfo;
111 ::cppu::IPropertyArrayHelper& PluginModel::getInfoHelper()
113 return *this;
116 sal_Bool PluginModel::convertFastPropertyValue( Any & rConvertedValue,
117 Any & rOldValue,
118 sal_Int32 nHandle,
119 const Any& rValue ) throw()
121 if( nHandle == 1 || nHandle == 2 )
123 if( rValue.getValueTypeClass() == TypeClass_STRING )
125 rConvertedValue = rValue;
126 if( nHandle == 2 )
127 rOldValue <<= m_aCreationURL;
128 else if( nHandle == 1 )
129 rOldValue <<= m_aMimeType;
130 return sal_True;
133 return sal_False;
136 void PluginModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle,
137 const Any& rValue )
138 throw(::com::sun::star::uno::Exception, std::exception)
140 if( rValue.getValueTypeClass() == TypeClass_STRING ) // FIXME wrong type!
143 if( nHandle == 2 )
144 rValue >>= m_aCreationURL;
145 else if( nHandle == 1 )
146 rValue >>= m_aMimeType;
148 else
149 throw ::com::sun::star::lang::IllegalArgumentException();
152 void PluginModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const throw()
154 if( nHandle == 2 )
155 rValue <<= m_aCreationURL;
156 else if( nHandle == 1 )
157 rValue <<= m_aMimeType;
160 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
161 void PluginModel::addEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) throw(std::exception)
163 m_aDisposeListeners.push_back( l );
166 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
167 void PluginModel::removeEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) throw(std::exception)
169 m_aDisposeListeners.remove( l );
172 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
173 void PluginModel::dispose() throw(std::exception)
175 // send disposing events
176 ::com::sun::star::lang::EventObject aEvt;
177 aEvt.Source = (::cppu::OWeakObject*)this;
178 ::std::list< Reference< ::com::sun::star::lang::XEventListener > > aLocalListeners = m_aDisposeListeners;
179 for( ::std::list< Reference< ::com::sun::star::lang::XEventListener > >::iterator it = aLocalListeners.begin();
180 it != aLocalListeners.end(); ++it )
181 (*it)->disposing( aEvt );
183 m_aDisposeListeners.clear();
185 disposing();
189 // ::com::sun::star::io::XPersistObject
190 OUString PluginModel::getServiceName() throw(std::exception)
192 return OUString("com.sun.star.plugin.PluginModel");
195 void PluginModel::write(const Reference< ::com::sun::star::io::XObjectOutputStream > & OutStream) throw(std::exception)
197 OutStream->writeUTF( m_aCreationURL );
200 void PluginModel::read(const Reference< ::com::sun::star::io::XObjectInputStream > & InStream) throw(std::exception)
202 m_aCreationURL = InStream->readUTF();
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */