update credits
[LibreOffice.git] / extensions / source / plugin / base / plmodel.cxx
blob6942c39c956aea6fd00fcd8da139edfd183659f1
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>
32 using namespace com::sun::star::uno;
34 //==================================================================================================
35 Reference< XInterface > SAL_CALL PluginModel_CreateInstance( const Reference< ::com::sun::star::lang::XMultiServiceFactory > & ) throw( Exception )
37 Reference< XInterface > xService = *new PluginModel();
38 return xService;
41 Any PluginModel::queryAggregation( const Type& type ) throw( RuntimeException )
43 Any aRet( ::cppu::queryInterface( type,
44 static_cast< ::com::sun::star::lang::XComponent* >(this),
45 static_cast< ::com::sun::star::io::XPersistObject* >(this ),
46 static_cast< ::com::sun::star::awt::XControlModel* >(this),
47 static_cast< ::com::sun::star::beans::XPropertySet* >(this),
48 static_cast< ::com::sun::star::beans::XMultiPropertySet* >(this),
49 static_cast< ::com::sun::star::beans::XFastPropertySet* >(this)
50 ) );
51 return aRet.hasValue() ? aRet : OWeakAggObject::queryAggregation( type );
55 // XPluginManager_Impl
56 Sequence< OUString > PluginModel::getSupportedServiceNames_Static(void) throw()
58 Sequence< OUString > aSNS( 1 );
59 aSNS.getArray()[0] = OUString("com.sun.star.plugin.PluginModel");
60 return aSNS;
64 static const char* aCreationURL = "URL";
65 static const char* aMime = "TYPE";
67 static ::osl::Mutex aPropertyMutex;
69 static ::com::sun::star::beans::Property aProps[] =
71 ::com::sun::star::beans::Property(
72 OUString::createFromAscii( aMime ),
74 ::getCppuType((const OUString*)0),
75 ::com::sun::star::beans::PropertyAttribute::BOUND ),
76 ::com::sun::star::beans::Property(
77 OUString::createFromAscii( aCreationURL ),
79 ::getCppuType((const OUString*)0),
80 ::com::sun::star::beans::PropertyAttribute::BOUND )
83 PluginModel::PluginModel() :
84 BroadcasterHelperHolder( aPropertyMutex ),
85 OPropertySetHelper( m_aHelper ),
86 OPropertyArrayHelper( aProps, 2 )
90 PluginModel::PluginModel(const OUString& rURL, const OUString& rMimeType ) :
91 BroadcasterHelperHolder( aPropertyMutex ),
92 OPropertySetHelper( m_aHelper ),
93 OPropertyArrayHelper( aProps, 2 ),
94 m_aCreationURL( rURL ),
95 m_aMimeType( rMimeType )
99 PluginModel::~PluginModel()
103 Reference< ::com::sun::star::beans::XPropertySetInfo > PluginModel::getPropertySetInfo() throw()
105 static Reference< ::com::sun::star::beans::XPropertySetInfo > aInfo =
106 createPropertySetInfo( *this );
107 return aInfo;
110 ::cppu::IPropertyArrayHelper& PluginModel::getInfoHelper()
112 return *this;
115 sal_Bool PluginModel::convertFastPropertyValue( Any & rConvertedValue,
116 Any & rOldValue,
117 sal_Int32 nHandle,
118 const Any& rValue ) throw()
120 if( nHandle == 1 || nHandle == 2 )
122 if( rValue.getValueTypeClass() == TypeClass_STRING )
124 rConvertedValue = rValue;
125 if( nHandle == 2 )
126 rOldValue <<= m_aCreationURL;
127 else if( nHandle == 1 )
128 rOldValue <<= m_aMimeType;
129 return sal_True;
132 return sal_False;
135 void PluginModel::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle,
136 const Any& rValue )
137 throw(::com::sun::star::uno::Exception)
139 if( rValue.getValueTypeClass() == TypeClass_STRING ) // FIXME wrong type!
142 if( nHandle == 2 )
143 rValue >>= m_aCreationURL;
144 else if( nHandle == 1 )
145 rValue >>= m_aMimeType;
147 else
148 throw ::com::sun::star::lang::IllegalArgumentException();
151 void PluginModel::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) const throw()
153 if( nHandle == 2 )
154 rValue <<= m_aCreationURL;
155 else if( nHandle == 1 )
156 rValue <<= m_aMimeType;
159 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
160 void PluginModel::addEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) throw()
162 m_aDisposeListeners.push_back( l );
165 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
166 void PluginModel::removeEventListener( const Reference< ::com::sun::star::lang::XEventListener > & l ) throw()
168 m_aDisposeListeners.remove( l );
171 //---- ::com::sun::star::lang::XComponent ----------------------------------------------------------------------------------
172 void PluginModel::dispose(void) throw()
174 // send disposing events
175 ::com::sun::star::lang::EventObject aEvt;
176 aEvt.Source = (::cppu::OWeakObject*)this;
177 ::std::list< Reference< ::com::sun::star::lang::XEventListener > > aLocalListeners = m_aDisposeListeners;
178 for( ::std::list< Reference< ::com::sun::star::lang::XEventListener > >::iterator it = aLocalListeners.begin();
179 it != aLocalListeners.end(); ++it )
180 (*it)->disposing( aEvt );
182 m_aDisposeListeners.clear();
184 disposing();
188 // ::com::sun::star::io::XPersistObject
189 OUString PluginModel::getServiceName() throw()
191 return OUString("com.sun.star.plugin.PluginModel");
194 void PluginModel::write(const Reference< ::com::sun::star::io::XObjectOutputStream > & OutStream) throw()
196 OutStream->writeUTF( m_aCreationURL );
199 void PluginModel::read(const Reference< ::com::sun::star::io::XObjectInputStream > & InStream) throw()
201 m_aCreationURL = InStream->readUTF();
204 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */