diff options
Diffstat (limited to 'ucbhelper/source')
-rw-r--r-- | ucbhelper/source/client/commandenvironment.cxx | 191 | ||||
-rw-r--r-- | ucbhelper/source/client/content.cxx | 1069 | ||||
-rw-r--r-- | ucbhelper/source/client/contentbroker.cxx | 299 | ||||
-rw-r--r-- | ucbhelper/source/client/makefile.mk | 91 | ||||
-rw-r--r-- | ucbhelper/source/provider/configureucb.cxx | 167 | ||||
-rw-r--r-- | ucbhelper/source/provider/contenthelper.cxx | 1250 | ||||
-rw-r--r-- | ucbhelper/source/provider/contentidentifier.cxx | 262 | ||||
-rw-r--r-- | ucbhelper/source/provider/contentinfo.cxx | 475 | ||||
-rw-r--r-- | ucbhelper/source/provider/makefile.mk | 98 | ||||
-rw-r--r-- | ucbhelper/source/provider/propertyvalueset.cxx | 925 | ||||
-rw-r--r-- | ucbhelper/source/provider/providerhelper.cxx | 614 | ||||
-rw-r--r-- | ucbhelper/source/provider/registerucb.cxx | 249 | ||||
-rw-r--r-- | ucbhelper/source/provider/resultset.cxx | 1706 | ||||
-rw-r--r-- | ucbhelper/source/provider/resultsethelper.cxx | 369 | ||||
-rw-r--r-- | ucbhelper/source/provider/resultsetmetadata.cxx | 588 |
15 files changed, 8353 insertions, 0 deletions
diff --git a/ucbhelper/source/client/commandenvironment.cxx b/ucbhelper/source/client/commandenvironment.cxx new file mode 100644 index 000000000000..feef034704cf --- /dev/null +++ b/ucbhelper/source/client/commandenvironment.cxx @@ -0,0 +1,191 @@ +/************************************************************************* + * + * $RCSfile: commandenvironment.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIERFACTORY_HPP_ +#include <com/sun/star/ucb/XContentIdentifierFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERMANAGER_HPP_ +#include <com/sun/star/ucb/XContentProviderManager.hpp> +#endif + +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif + +#ifndef _UCBHELPER_COMMANDENVIRONMENT_HXX +#include <ucbhelper/commandenvironment.hxx> +#endif + +using namespace com::sun::star::lang; +using namespace com::sun::star::task; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace rtl; + +namespace ucb +{ + +//========================================================================= +//========================================================================= +// +// struct CommandEnvironment_Impl. +// +//========================================================================= +//========================================================================= + +struct CommandEnvironment_Impl +{ + Reference< XInteractionHandler > m_xInteractionHandler; + Reference< XProgressHandler > m_xProgressHandler; + + CommandEnvironment_Impl( + const Reference< XInteractionHandler >& rxInteractionHandler, + const Reference< XProgressHandler >& rxProgressHandler ) + : m_xInteractionHandler( rxInteractionHandler ), + m_xProgressHandler( rxProgressHandler ) {} +}; + +//========================================================================= +//========================================================================= +// +// CommandEnvironment Implementation. +// +//========================================================================= +//========================================================================= + +CommandEnvironment::CommandEnvironment( + const Reference< XInteractionHandler >& rxInteractionHandler, + const Reference< XProgressHandler >& rxProgressHandler ) +{ + m_pImpl = new CommandEnvironment_Impl( rxInteractionHandler, + rxProgressHandler ); +} + +//========================================================================= +// virtual +CommandEnvironment::~CommandEnvironment() +{ + delete m_pImpl; +} + +//========================================================================= +// +// XInterface methods +// +//========================================================================= + +XINTERFACE_IMPL_2( CommandEnvironment, + XTypeProvider, + XCommandEnvironment ); + +//========================================================================= +// +// XTypeProvider methods +// +//========================================================================= + +XTYPEPROVIDER_IMPL_2( CommandEnvironment, + XTypeProvider, + XCommandEnvironment ); + +//========================================================================= +// +// XCommandEnvironemnt methods. +// +//========================================================================= + +// virtual +Reference< XInteractionHandler > SAL_CALL +CommandEnvironment::getInteractionHandler() + throw ( RuntimeException ) +{ + return m_pImpl->m_xInteractionHandler; +} + +//========================================================================= +// virtual +Reference< XProgressHandler > SAL_CALL +CommandEnvironment::getProgressHandler() + throw ( RuntimeException ) +{ + return m_pImpl->m_xProgressHandler; +} + +} /* namespace ucb */ + diff --git a/ucbhelper/source/client/content.cxx b/ucbhelper/source/client/content.cxx new file mode 100644 index 000000000000..7de4a7d38f41 --- /dev/null +++ b/ucbhelper/source/client/content.cxx @@ -0,0 +1,1069 @@ +/************************************************************************* + * + * $RCSfile: content.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _VOS_REFERNCE_HXX_ +#include <vos/refernce.hxx> +#endif + +#ifndef _COM_SUN_STAR_UCB_XCOMMANDENVIRONMENT_HPP_ +#include <com/sun/star/ucb/XCommandEnvironment.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDINFO_HPP_ +#include <com/sun/star/ucb/XCommandInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCOMMANDPROCESSOR_HPP_ +#include <com/sun/star/ucb/XCommandProcessor.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_COMMAND_HPP_ +#include <com/sun/star/ucb/Command.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_COMMANDINFO_HPP_ +#include <com/sun/star/ucb/CommandInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENCOMMANDARGUMENT2_HPP_ +#include <com/sun/star/ucb/OpenCommandArgument2.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_INSERTCOMMANDARGUMENT_HPP_ +#include <com/sun/star/ucb/InsertCommandArgument.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_OPENMODE_HPP_ +#include <com/sun/star/ucb/OpenMode.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTCREATOR_HPP_ +#include <com/sun/star/ucb/XContentCreator.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIERFACTORY_HPP_ +#include <com/sun/star/ucb/XContentIdentifierFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERMANAGER_HPP_ +#include <com/sun/star/ucb/XContentProviderManager.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XDYNAMICRESULTSET_HPP_ +#include <com/sun/star/ucb/XDynamicResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_ +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include <com/sun/star/beans/Property.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XRESULTSET_HPP_ +#include <com/sun/star/sdbc/XResultSet.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XROW_HPP_ +#include <com/sun/star/sdbc/XRow.hpp> +#endif + +#ifndef _UCBHELPER_CONTENT_HXX +#include <ucbhelper/content.hxx> +#endif +#ifndef _UCBHELPER_CONTENTBROKER_HXX +#include <ucbhelper/contentbroker.hxx> +#endif + +using namespace com::sun::star::container; +using namespace com::sun::star::beans; +using namespace com::sun::star::io; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace rtl; + +namespace ucb +{ + +//========================================================================= +//========================================================================= +// +// class Content_Impl. +// +//========================================================================= +//========================================================================= + +class Content_Impl : public vos::OReference +{ + Reference< XMultiServiceFactory > m_xSMgr; + Reference< XContent > m_xContent; + Reference< XCommandProcessor > m_xCommandProcessor; + Reference< XCommandEnvironment > m_xEnv; + vos::OMutex m_aMutex; + sal_Int32 m_aCommandId; + +public: + inline Content_Impl( const Reference< XMultiServiceFactory >& rSMgr, + const Reference< XContent >& rContent, + const Reference< XCommandEnvironment >& rEnv ); + + virtual ~Content_Impl(); + + Reference< XContent > getContent() const { return m_xContent; } + Reference< XCommandProcessor > getCommandProcessor(); + sal_Int32 getCommandId(); + + Any executeCommand( const Command& rCommand ); + void abortCommand(); + Reference< XCommandEnvironment > getEnvironment() const { return m_xEnv; } +}; + +//========================================================================= +inline Content_Impl::Content_Impl( + const Reference< XMultiServiceFactory >& rSMgr, + const Reference< XContent >& rContent, + const Reference< XCommandEnvironment >& rEnv ) +: m_xSMgr( rSMgr ), + m_xContent( rContent ), + m_xEnv( rEnv ), + m_aCommandId( 0 ) +{ +} + +//========================================================================= +//========================================================================= +// +// Content Implementation. +// +//========================================================================= +//========================================================================= + +Content::Content() +{ +} + +//========================================================================= +Content::Content( const OUString& rURL, + const Reference< XCommandEnvironment >& rEnv ) + throw ( ContentCreationException, RuntimeException ) +{ + ucb::ContentBroker* pBroker = ucb::ContentBroker::get(); + if ( !pBroker ) + throw ContentCreationException( + ContentCreationException::NO_CONTENT_BROKER ); + + VOS_ENSURE( pBroker->getContentProviderManagerInterface() + ->queryContentProviders().getLength(), + "Content Broker not configured (no providers)!" ); + + Reference< XContentIdentifierFactory > xIdFac + = pBroker->getContentIdentifierFactoryInterface(); + if ( !xIdFac.is() ) + throw ContentCreationException( + ContentCreationException::NO_IDENTIFIER_FACTORY ); + + Reference< XContentIdentifier > xId + = xIdFac->createContentIdentifier( rURL ); + if ( !xId.is() ) + throw ContentCreationException( + ContentCreationException::IDENTIFIER_CREATION_FAILED ); + + Reference< XContentProvider > xProvider + = pBroker->getContentProviderInterface(); + if ( !xProvider.is() ) + throw ContentCreationException( + ContentCreationException::NO_CONTENT_PROVIDER ); + + Reference< XContent > xContent; + try + { + xContent = xProvider->queryContent( xId ); + } + catch ( IllegalIdentifierException ) + { + throw ContentCreationException( + ContentCreationException::CONTENT_CREATION_FAILED ); + } + + if ( !xContent.is() ) + throw ContentCreationException( + ContentCreationException::CONTENT_CREATION_FAILED ); + + m_xImpl = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv ); +} + +//========================================================================= +Content::Content( const Reference< XContentIdentifier >& rId, + const Reference< XCommandEnvironment >& rEnv ) + throw ( ContentCreationException, RuntimeException ) +{ + ucb::ContentBroker* pBroker = ucb::ContentBroker::get(); + if ( !pBroker ) + throw ContentCreationException( + ContentCreationException::NO_CONTENT_BROKER ); + + VOS_ENSURE( pBroker->getContentProviderManagerInterface() + ->queryContentProviders().getLength(), + "Content Broker not configured (no providers)!" ); + + Reference< XContentProvider > xProvider + = pBroker->getContentProviderInterface(); + if ( !xProvider.is() ) + throw ContentCreationException( + ContentCreationException::NO_CONTENT_PROVIDER ); + + Reference< XContent > xContent; + try + { + xContent = xProvider->queryContent( rId ); + } + catch ( IllegalIdentifierException ) + { + throw ContentCreationException( + ContentCreationException::CONTENT_CREATION_FAILED ); + } + + if ( !xContent.is() ) + throw ContentCreationException( + ContentCreationException::CONTENT_CREATION_FAILED ); + + m_xImpl = new Content_Impl( pBroker->getServiceManager(), xContent, rEnv ); +} + +//========================================================================= +Content::Content( const Reference< XContent >& rContent, + const Reference< XCommandEnvironment >& rEnv ) +{ + ucb::ContentBroker* pBroker = ucb::ContentBroker::get(); + if ( !pBroker ) + throw ContentCreationException( + ContentCreationException::NO_CONTENT_BROKER ); + + VOS_ENSURE( pBroker->getContentProviderManagerInterface() + ->queryContentProviders().getLength(), + "Content Broker not configured (no providers)!" ); + + m_xImpl = new Content_Impl( pBroker->getServiceManager(), rContent, rEnv ); +} + +//========================================================================= +Content::Content( const Content& rOther ) +{ + m_xImpl = rOther.m_xImpl; +} + +//========================================================================= +Content::~Content() +{ +} + +//========================================================================= +Content& Content::operator=( const Content& rOther ) +{ + m_xImpl = rOther.m_xImpl; + return *this; +} + +//========================================================================= +Reference< XContent > Content::get() const +{ + return m_xImpl->getContent(); +} + +//========================================================================= +Reference< XCommandInfo > Content::getCommands() + throw( CommandAbortedException, RuntimeException, Exception ) +{ + Command aCommand; + aCommand.Name = OUString::createFromAscii( "getCommandInfo" ); + aCommand.Handle = -1; // n/a + aCommand.Argument = Any(); + + Any aResult = m_xImpl->executeCommand( aCommand ); + + Reference< XCommandInfo > xInfo; + aResult >>= xInfo; + return xInfo; +} + +//========================================================================= +Reference< XPropertySetInfo > Content::getProperties() + throw( CommandAbortedException, RuntimeException, Exception ) +{ + Command aCommand; + aCommand.Name = OUString::createFromAscii( "getPropertySetInfo" ); + aCommand.Handle = -1; // n/a + aCommand.Argument = Any(); + + Any aResult = m_xImpl->executeCommand( aCommand ); + + Reference< XPropertySetInfo > xInfo; + aResult >>= xInfo; + return xInfo; +} + +//========================================================================= +Any Content::getPropertyValue( const OUString& rPropertyName ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + Sequence< OUString > aNames( 1 ); + aNames.getArray()[ 0 ] = rPropertyName; + + Sequence< Any > aRet = getPropertyValues( aNames ); + return aRet.getConstArray()[ 0 ]; +} + +//========================================================================= +Any Content::getPropertyValue( sal_Int32 nPropertyHandle ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + Sequence< sal_Int32 > aHandles( 1 ); + aHandles.getArray()[ 0 ] = nPropertyHandle; + + Sequence< Any > aRet = getPropertyValues( aHandles ); + return aRet.getConstArray()[ 0 ]; +} + +//========================================================================= +void Content::setPropertyValue( const OUString& rName, + const Any& rValue ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + Sequence< OUString > aNames( 1 ); + aNames.getArray()[ 0 ] = rName; + + Sequence< Any > aValues( 1 ); + aValues.getArray()[ 0 ] = rValue; + + setPropertyValues( aNames, aValues ); +} + +//========================================================================= +void Content::setPropertyValue( const sal_Int32 nPropertyHandle, + const Any& rValue ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + Sequence< sal_Int32 > aHandles( 1 ); + aHandles.getArray()[ 0 ] = nPropertyHandle; + + Sequence< Any > aValues( 1 ); + aValues.getArray()[ 0 ] = rValue; + + setPropertyValues( aHandles, aValues ); +} + +//========================================================================= +Sequence< Any > Content::getPropertyValues( + const Sequence< OUString >& rPropertyNames ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + Reference< XRow > xRow = getPropertyValuesInterface( rPropertyNames ); + + sal_Int32 nCount = rPropertyNames.getLength(); + Sequence< Any > aValues( nCount ); + Any* pValues = aValues.getArray(); + + for ( sal_Int32 n = 0; n < nCount; ++n ) + pValues[ n ] = xRow->getObject( n + 1, Reference< XNameAccess >() ); + + return aValues; +} + +//========================================================================= +Sequence< Any > Content::getPropertyValues( + const Sequence< sal_Int32 >& nPropertyHandles ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + Reference< XRow > xRow = getPropertyValuesInterface( nPropertyHandles ); + + sal_Int32 nCount = nPropertyHandles.getLength(); + Sequence< Any > aValues( nCount ); + Any* pValues = aValues.getArray(); + + for ( sal_Int32 n = 0; n < nCount; ++n ) + pValues[ n ] = xRow->getObject( n + 1, Reference< XNameAccess >() ); + + return aValues; +} + +//========================================================================= +Reference< XRow > Content::getPropertyValuesInterface( + const Sequence< OUString >& rPropertyNames ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + sal_Int32 nCount = rPropertyNames.getLength(); + Sequence< Property > aProps( nCount ); + Property* pProps = aProps.getArray(); + + const OUString* pNames = rPropertyNames.getConstArray(); + + for ( sal_Int32 n = 0; n< nCount; ++n ) + { + Property& rProp = pProps[ n ]; + + rProp.Name = pNames[ n ]; + rProp.Handle = -1; // n/a +// rProp.Type = +// rProp.Attributes = ; + } + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "getPropertyValues" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aProps; + + Any aResult = m_xImpl->executeCommand( aCommand ); + + Reference< XRow > xRow; + aResult >>= xRow; + return xRow; +} + +//========================================================================= +Reference< XRow > Content::getPropertyValuesInterface( + const Sequence< sal_Int32 >& nPropertyHandles ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + sal_Int32 nCount = nPropertyHandles.getLength(); + Sequence< Property > aProps( nCount ); + Property* pProps = aProps.getArray(); + + const sal_Int32* pHandles = nPropertyHandles.getConstArray(); + + for ( sal_Int32 n = 0; n< nCount; ++n ) + { + Property& rProp = pProps[ n ]; + + rProp.Name = OUString(); // n/a + rProp.Handle = pHandles[ n ]; +// rProp.Type = +// rProp.Attributes = ; + } + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "getPropertyValues" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aProps; + + Any aResult = m_xImpl->executeCommand( aCommand ); + + Reference< XRow > xRow; + aResult >>= xRow; + return xRow; +} + +//========================================================================= +void Content::setPropertyValues( + const Sequence< OUString >& rPropertyNames, + const Sequence< Any >& rValues ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( rPropertyNames.getLength() != rValues.getLength() ) + throw CommandAbortedException(); + + sal_Int32 nCount = rValues.getLength(); + Sequence< PropertyValue > aProps( nCount ); + PropertyValue* pProps = aProps.getArray(); + + const OUString* pNames = rPropertyNames.getConstArray(); + const Any* pValues = rValues.getConstArray(); + + for ( sal_Int32 n = 0; n< nCount; ++n ) + { + PropertyValue& rProp = pProps[ n ]; + + rProp.Name = pNames[ n ]; + rProp.Handle = -1; // n/a + rProp.Value = pValues[ n ]; +// rProp.State = ; + } + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "setPropertyValues" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aProps; + + m_xImpl->executeCommand( aCommand ); +} + +//========================================================================= +void Content::setPropertyValues( + const Sequence< sal_Int32 >& nPropertyHandles, + const Sequence< Any >& rValues ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( nPropertyHandles.getLength() != rValues.getLength() ) + throw CommandAbortedException(); + + sal_Int32 nCount = rValues.getLength(); + Sequence< PropertyValue > aProps( nCount ); + PropertyValue* pProps = aProps.getArray(); + + const sal_Int32* pHandles = nPropertyHandles.getConstArray(); + const Any* pValues = rValues.getConstArray(); + + for ( sal_Int32 n = 0; n< nCount; ++n ) + { + PropertyValue& rProp = pProps[ n ]; + + rProp.Name = OUString(); // n/a + rProp.Handle = pHandles[ n ]; + rProp.Value = pValues[ n ]; +// rProp.State = ; + } + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "setPropertyValues" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aProps; + + m_xImpl->executeCommand( aCommand ); +} + +//========================================================================= +Any Content::executeCommand( const OUString& rCommandName, + const Any& rCommandArgument ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + Command aCommand; + aCommand.Name = rCommandName; + aCommand.Handle = -1; // n/a + aCommand.Argument = rCommandArgument; + + return m_xImpl->executeCommand( aCommand ); +} + +//========================================================================= +Any Content::executeCommand( sal_Int32 nCommandHandle, + const Any& rCommandArgument ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + Command aCommand; + aCommand.Name = OUString(); // n/a + aCommand.Handle = nCommandHandle; + aCommand.Argument = rCommandArgument; + + return m_xImpl->executeCommand( aCommand ); +} + +//========================================================================= +void Content::abortCommand() +{ + m_xImpl->abortCommand(); +} + +//========================================================================= +Reference< XCommandEnvironment > Content::getCommandEnvironment() +{ + return m_xImpl->getEnvironment(); +} + +//========================================================================= +Reference< XResultSet > Content::createCursor( + const Sequence< OUString >& rPropertyNames, + ResultSetInclude eMode ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( !isFolder() ) + return Reference< XResultSet >(); + + sal_Int32 nCount = rPropertyNames.getLength(); + Sequence< Property > aProps( nCount ); + Property* pProps = aProps.getArray(); + const OUString* pNames = rPropertyNames.getConstArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + Property& rProp = pProps[ n ]; + rProp.Name = pNames[ n ]; + rProp.Handle = -1; // n/a + } + + OpenCommandArgument2 aArg; + aArg.Mode = ( eMode == INCLUDE_FOLDERS_ONLY ) + ? OpenMode::FOLDERS + : ( eMode == INCLUDE_DOCUMENTS_ONLY ) + ? OpenMode::DOCUMENTS : OpenMode::ALL; + aArg.Priority = 0; // unused + aArg.Sink = Reference< XInterface >(); // unused + aArg.Properties = aProps; + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "open" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aArg; + + Any aResult = m_xImpl->executeCommand( aCommand ); + + Reference< XDynamicResultSet > xDynSet; + Reference< XResultSet > xStaticSet; + if ( aResult >>= xDynSet ) + xStaticSet = xDynSet->getStaticResultSet(); + + VOS_ENSURE( xStaticSet.is(), "Content::createCursor - no cursor!" ); + + if ( !xStaticSet.is() ) + { + // Former, the open command directly returned a XResultSet. + aResult >>= xStaticSet; + + VOS_ENSURE( !xStaticSet.is(), + "Content::createCursor - open-Command must " + "return a Reference< XDynnamicResultSet >!" ); + } + + return xStaticSet; +} + +//========================================================================= +Reference< XResultSet > Content::createCursor( + const Sequence< sal_Int32 >& rPropertyHandles, + ResultSetInclude eMode ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( !isFolder() ) + return Reference< XResultSet >(); + + sal_Int32 nCount = rPropertyHandles.getLength(); + Sequence< Property > aProps( nCount ); + Property* pProps = aProps.getArray(); + const sal_Int32* pHandles = rPropertyHandles.getConstArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + Property& rProp = pProps[ n ]; + rProp.Name = OUString(); // n/a + rProp.Handle = pHandles[ n ]; + } + + OpenCommandArgument2 aArg; + aArg.Mode = ( eMode == INCLUDE_FOLDERS_ONLY ) + ? OpenMode::FOLDERS + : ( eMode == INCLUDE_DOCUMENTS_ONLY ) + ? OpenMode::DOCUMENTS : OpenMode::ALL; + aArg.Priority = 0; // unused + aArg.Sink = Reference< XInterface >(); // unused + aArg.Properties = aProps; + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "open" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aArg; + + Any aResult = m_xImpl->executeCommand( aCommand ); + + Reference< XDynamicResultSet > xDynSet; + Reference< XResultSet > xStaticSet; + if ( aResult >>= xDynSet ) + xStaticSet = xDynSet->getStaticResultSet(); + + VOS_ENSURE( xStaticSet.is(), "Content::createCursor - no cursor!" ); + + if ( !xStaticSet.is() ) + { + // Former, the open command directly returned a XResultSet. + aResult >>= xStaticSet; + + VOS_ENSURE( !xStaticSet.is(), + "Content::createCursor - open-Command must " + "return a Reference< XDynnamicResultSet >!" ); + } + + return xStaticSet; +} + +//========================================================================= +Reference< XDynamicResultSet > Content::createDynamicCursor( + const Sequence< OUString >& rPropertyNames, + ResultSetInclude eMode ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( !isFolder() ) + return Reference< XDynamicResultSet >(); + + sal_Int32 nCount = rPropertyNames.getLength(); + Sequence< Property > aProps( nCount ); + Property* pProps = aProps.getArray(); + const OUString* pNames = rPropertyNames.getConstArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + Property& rProp = pProps[ n ]; + rProp.Name = pNames[ n ]; + rProp.Handle = -1; // n/a + } + + OpenCommandArgument2 aArg; + aArg.Mode = ( eMode == INCLUDE_FOLDERS_ONLY ) + ? OpenMode::FOLDERS + : ( eMode == INCLUDE_DOCUMENTS_ONLY ) + ? OpenMode::DOCUMENTS : OpenMode::ALL; + aArg.Priority = 0; // unused + aArg.Sink = Reference< XInterface >(); // unused + aArg.Properties = aProps; + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "open" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aArg; + + Reference< XDynamicResultSet > xSet; + m_xImpl->executeCommand( aCommand ) >>= xSet; + + VOS_ENSURE( xSet.is(), "Content::createDynamicCursor - no cursor!" ); + + return xSet; +} + +//========================================================================= +Reference< XDynamicResultSet > Content::createDynamicCursor( + const Sequence< sal_Int32 >& rPropertyHandles, + ResultSetInclude eMode ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( !isFolder() ) + return Reference< XDynamicResultSet >(); + + sal_Int32 nCount = rPropertyHandles.getLength(); + Sequence< Property > aProps( nCount ); + Property* pProps = aProps.getArray(); + const sal_Int32* pHandles = rPropertyHandles.getConstArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + Property& rProp = pProps[ n ]; + rProp.Name = OUString(); // n/a + rProp.Handle = pHandles[ n ]; + } + + OpenCommandArgument2 aArg; + aArg.Mode = ( eMode == INCLUDE_FOLDERS_ONLY ) + ? OpenMode::FOLDERS + : ( eMode == INCLUDE_DOCUMENTS_ONLY ) + ? OpenMode::DOCUMENTS : OpenMode::ALL; + aArg.Priority = 0; // unused + aArg.Sink = Reference< XInterface >(); // unused + aArg.Properties = aProps; + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "open" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aArg; + + Reference< XDynamicResultSet > xSet; + m_xImpl->executeCommand( aCommand ) >>= xSet; + + VOS_ENSURE( xSet.is(), "Content::createDynamicCursor - no cursor!" ); + + return xSet; +} + +//========================================================================= +sal_Bool Content::openStream( const Reference< XActiveDataSink >& rSink ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( !isDocument() ) + return sal_False; + + OpenCommandArgument2 aArg; + aArg.Mode = OpenMode::DOCUMENT; + aArg.Priority = 0; // unused + aArg.Sink = rSink; + aArg.Properties = Sequence< Property >( 0 ); // unused + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "open" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aArg; + + m_xImpl->executeCommand( aCommand ); + + return sal_True; +} + +//========================================================================= +sal_Bool Content::openStream( const Reference< XOutputStream >& rStream ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( !isDocument() ) + return sal_False; + + OpenCommandArgument2 aArg; + aArg.Mode = OpenMode::DOCUMENT; + aArg.Priority = 0; // unused + aArg.Sink = rStream; + aArg.Properties = Sequence< Property >( 0 ); // unused + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "open" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aArg; + + m_xImpl->executeCommand( aCommand ); + + return sal_True; +} + +//========================================================================= +void Content::writeStream( const Reference< XInputStream >& rStream, + sal_Bool bReplaceExisting ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( !rStream.is() ) + return; + + if ( !isDocument() ) + return; + + InsertCommandArgument aArg; + aArg.Data = rStream; + aArg.ReplaceExisting = bReplaceExisting; + + Command aCommand; + aCommand.Name = OUString::createFromAscii( "insert" ); + aCommand.Handle = -1; // n/a + aCommand.Argument <<= aArg; + + m_xImpl->executeCommand( aCommand ); +} + +//========================================================================= +sal_Bool Content::insertNewContent( const OUString& rContentType, + const Sequence< OUString >& rPropertyNames, + const Sequence< Any >& rPropertyValues, + Content& rNewContent ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + return insertNewContent( rContentType, + rPropertyNames, + rPropertyValues, + Reference< XInputStream >(), + rNewContent ); +} + +//========================================================================= +sal_Bool Content::insertNewContent( const OUString& rContentType, + const Sequence< sal_Int32 >& nPropertyHandles, + const Sequence< Any >& rPropertyValues, + Content& rNewContent ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + return insertNewContent( rContentType, + nPropertyHandles, + rPropertyValues, + Reference< XInputStream >(), + rNewContent ); +} + +//========================================================================= +sal_Bool Content::insertNewContent( const OUString& rContentType, + const Sequence< OUString >& rPropertyNames, + const Sequence< Any >& rPropertyValues, + const Reference< XInputStream >& rData, + Content& rNewContent ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( rContentType.getLength() == 0 ) + return sal_False; + + Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY ); + + VOS_ENSURE( xCreator.is(), + "Content::insertNewContent - Not a XContentCreator!" ); + + if ( !xCreator.is() ) + return sal_False; + + ContentInfo aInfo; + aInfo.Type = rContentType; + aInfo.Attributes = 0; + + Reference< XContent > xNew = xCreator->createNewContent( aInfo ); + if ( !xNew.is() ) + return sal_False; + + Content aNewContent( xNew, m_xImpl->getEnvironment() ); + aNewContent.setPropertyValues( rPropertyNames, rPropertyValues ); + aNewContent.executeCommand( OUString::createFromAscii( "insert" ), + makeAny( + InsertCommandArgument( + rData, + sal_False /* ReplaceExisting */ ) ) ); + rNewContent = aNewContent; + return sal_True; +} + +//========================================================================= +sal_Bool Content::insertNewContent( const OUString& rContentType, + const Sequence< sal_Int32 >& nPropertyHandles, + const Sequence< Any >& rPropertyValues, + const Reference< XInputStream >& rData, + Content& rNewContent ) + throw( CommandAbortedException, RuntimeException, Exception ) +{ + if ( rContentType.getLength() == 0 ) + return sal_False; + + Reference< XContentCreator > xCreator( m_xImpl->getContent(), UNO_QUERY ); + + VOS_ENSURE( xCreator.is(), + "Content::insertNewContent - Not a XContentCreator!" ); + + if ( !xCreator.is() ) + return sal_False; + + ContentInfo aInfo; + aInfo.Type = rContentType; + aInfo.Attributes = 0; + + Reference< XContent > xNew = xCreator->createNewContent( aInfo ); + if ( !xNew.is() ) + return sal_False; + + Content aNewContent( xNew, m_xImpl->getEnvironment() ); + aNewContent.setPropertyValues( nPropertyHandles, rPropertyValues ); + aNewContent.executeCommand( OUString::createFromAscii( "insert" ), + makeAny( + InsertCommandArgument( + rData, + sal_False /* ReplaceExisting */ ) ) ); + rNewContent = aNewContent; + return sal_True; +} + +//========================================================================= +sal_Bool Content::isFolder() + throw( CommandAbortedException, RuntimeException, Exception ) +{ + sal_Bool bFolder = sal_False; + getPropertyValue( OUString::createFromAscii( "IsFolder" ) ) >>= bFolder; + return bFolder; +} + +//========================================================================= +sal_Bool Content::isDocument() + throw( CommandAbortedException, RuntimeException, Exception ) +{ + sal_Bool bDoc = sal_False; + getPropertyValue( OUString::createFromAscii( "IsDocument" ) ) >>= bDoc; + return bDoc; +} + +//========================================================================= +//========================================================================= +// +// Content_Impl Implementation. +// +//========================================================================= +//========================================================================= + +//========================================================================= +// virtual +Content_Impl::~Content_Impl() +{ +} + +//========================================================================= +Reference< XCommandProcessor > Content_Impl::getCommandProcessor() +{ + vos::OGuard aGuard( m_aMutex ); + + if ( !m_xCommandProcessor.is() ) + m_xCommandProcessor + = Reference< XCommandProcessor >( m_xContent, UNO_QUERY ); + + return m_xCommandProcessor; +} + +//========================================================================= +sal_Int32 Content_Impl::getCommandId() +{ + vos::OGuard aGuard( m_aMutex ); + + if ( m_aCommandId == 0 ) + { + Reference< XCommandProcessor > xProc = getCommandProcessor(); + if ( xProc.is() ) + m_aCommandId = xProc->createCommandIdentifier(); + } + + return m_aCommandId; +} + +//========================================================================= +Any Content_Impl::executeCommand( const Command& rCommand ) +{ + Reference< XCommandProcessor > xProc = getCommandProcessor(); + if ( !xProc.is() ) + return Any(); + + // Execute command + return xProc->execute( rCommand, getCommandId(), m_xEnv ); +} + +//========================================================================= +void Content_Impl::abortCommand() +{ + if ( ( m_aCommandId != 0 ) && m_xCommandProcessor.is() ) + m_xCommandProcessor->abort( m_aCommandId ); +} + +} /* namespace ucb */ + diff --git a/ucbhelper/source/client/contentbroker.cxx b/ucbhelper/source/client/contentbroker.cxx new file mode 100644 index 000000000000..d6ad6c9f1a18 --- /dev/null +++ b/ucbhelper/source/client/contentbroker.cxx @@ -0,0 +1,299 @@ +/************************************************************************* + * + * $RCSfile: contentbroker.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XCOMPONENT_HPP_ +#include <com/sun/star/lang/XComponent.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTIDENTIFIERFACTORY_HPP_ +#include <com/sun/star/ucb/XContentIdentifierFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERMANAGER_HPP_ +#include <com/sun/star/ucb/XContentProviderManager.hpp> +#endif + +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif + +#ifndef _UCBHELPER_CONTENTBROKER_HXX +#include <ucbhelper/contentbroker.hxx> +#endif + +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace rtl; + +namespace ucb +{ + +//========================================================================= +//========================================================================= +// +// class ContentBroker_Impl. +// +//========================================================================= +//========================================================================= + +class ContentBroker_Impl +{ + Reference< XMultiServiceFactory > m_xSMgr; + Reference< XContentIdentifierFactory > m_xIdFac; + Reference< XContentProvider > m_xProvider; + Reference< XContentProviderManager > m_xProviderMgr; + Sequence< Any > m_aArguments; + vos::OMutex m_aMutex; + sal_Bool m_bInitDone; + +private: + void init() const; + void init(); + +public: + ContentBroker_Impl( const Reference< XMultiServiceFactory >& rSMgr, + const Sequence< Any >& rArguments ) + : m_xSMgr( rSMgr ), m_aArguments( rArguments ), m_bInitDone( sal_False ) + {} + + ~ContentBroker_Impl(); + + const Reference< XMultiServiceFactory >& getServiceManager() const + { return m_xSMgr; } + + const Reference< XContentIdentifierFactory >& getIdFactory() const + { init(); return m_xIdFac; } + + const Reference< XContentProvider >& getProvider() const + { init(); return m_xProvider; } + + const Reference< XContentProviderManager >& getProviderManager() const + { init(); return m_xProviderMgr; } +}; + +//========================================================================= +//========================================================================= +// +// ContentBroker Implementation. +// +//========================================================================= +//========================================================================= + +// static member! +ContentBroker* ContentBroker::m_pTheBroker = 0; + +//========================================================================= +ContentBroker::ContentBroker( const Reference< XMultiServiceFactory >& rSMgr, + const Sequence< Any >& rArguments ) +{ + m_pImpl = new ContentBroker_Impl( rSMgr, rArguments ); +} + +//========================================================================= +ContentBroker::~ContentBroker() +{ + delete m_pImpl; +} + +//========================================================================= +Reference< XMultiServiceFactory > ContentBroker::getServiceManager() const +{ + return m_pImpl->getServiceManager(); +} + +//========================================================================= +Reference< XContentIdentifierFactory > + ContentBroker::getContentIdentifierFactoryInterface() const +{ + return m_pImpl->getIdFactory(); +} + +//========================================================================= +Reference< XContentProvider > + ContentBroker::getContentProviderInterface() const +{ + return m_pImpl->getProvider(); +} + +//========================================================================= +Reference< XContentProviderManager > + ContentBroker::getContentProviderManagerInterface() const +{ + return m_pImpl->getProviderManager(); +} + +//========================================================================= +// static +sal_Bool ContentBroker::initialize( + const Reference< XMultiServiceFactory >& rSMgr, + const Sequence< Any >& rArguments ) +{ + vos::OGuard aGuard( vos::OMutex::getGlobalMutex() ); + + VOS_ENSURE( !m_pTheBroker, + "ContentBroker::create - already created!" ); + + if ( !m_pTheBroker ) + m_pTheBroker = new ContentBroker( rSMgr, rArguments ); + + return m_pTheBroker != 0; +} + +//========================================================================= +// static +void ContentBroker::deinitialize() +{ + vos::OGuard aGuard( vos::OMutex::getGlobalMutex() ); + + delete m_pTheBroker; + m_pTheBroker = 0; +} + +//========================================================================= +// static +ContentBroker* ContentBroker::get() +{ + return m_pTheBroker; +} + +//========================================================================= +//========================================================================= +// +// ContentBroker_Impl Implementation. +// +//========================================================================= +//========================================================================= + +ContentBroker_Impl::~ContentBroker_Impl() +{ + Reference< XComponent > xComponent( m_xProvider, UNO_QUERY ); + if ( xComponent.is() ) // must not exist, if init() was never called. + { + m_xIdFac = 0; + m_xProvider = 0; + m_xProviderMgr = 0; + + xComponent->dispose(); + } +} + +//========================================================================= +void ContentBroker_Impl::init() const +{ + const_cast< ContentBroker_Impl * >( this )->init(); +} + +//========================================================================= +void ContentBroker_Impl::init() +{ + vos::OGuard aGuard( m_aMutex ); + + if ( !m_bInitDone ) + { + m_bInitDone = sal_True; + + Reference< XInterface > xIfc + = m_xSMgr->createInstanceWithArguments( + OUString::createFromAscii( + "com.sun.star.ucb.UniversalContentBroker" ), + m_aArguments ); + + VOS_ENSURE( xIfc.is(), "Error creating UCB service!" ); + + if ( xIfc.is() ) + { + m_xIdFac + = Reference< XContentIdentifierFactory >( xIfc, UNO_QUERY ); + + VOS_ENSURE( m_xIdFac.is(), + "UCB without XContentIdentifierFactory!" ); + + m_xProvider + = Reference< XContentProvider >( xIfc, UNO_QUERY ); + + VOS_ENSURE( m_xProvider.is(), + "UCB without XContentProvider!" ); + + m_xProviderMgr + = Reference< XContentProviderManager >( xIfc, UNO_QUERY ); + + VOS_ENSURE( m_xProviderMgr.is(), + "UCB without XContentProviderManager!" ); + } + } +} + +} /* namespace ucb */ + diff --git a/ucbhelper/source/client/makefile.mk b/ucbhelper/source/client/makefile.mk new file mode 100644 index 000000000000..2b2079e1c44c --- /dev/null +++ b/ucbhelper/source/client/makefile.mk @@ -0,0 +1,91 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME= ucbhelper +TARGET= client +AUTOSEG= TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files -------------------------------------------------------- + +.IF "$(header)" == "" + +SLOFILES=\ + $(SLO)$/content.obj \ + $(SLO)$/contentbroker.obj \ + $(SLO)$/commandenvironment.obj + +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/ucbhelper/source/provider/configureucb.cxx b/ucbhelper/source/provider/configureucb.cxx new file mode 100644 index 000000000000..56f16ebe0e99 --- /dev/null +++ b/ucbhelper/source/provider/configureucb.cxx @@ -0,0 +1,167 @@ +/************************************************************************* + * + * $RCSfile: configureucb.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UCBHELPER_CONFIGUREUCB_HXX_ +#include <ucbhelper/configureucb.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_ILLEGALARGUMENTEXCEPTION_HPP_ +#include <com/sun/star/lang/IllegalArgumentException.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_CONTENTPROVIDERSERVICEINFO2_HPP_ +#include <com/sun/star/ucb/ContentProviderServiceInfo2.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_DUPLICATEPROVIDEREXCEPTION_HPP_ +#include <com/sun/star/ucb/DuplicateProviderException.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERCONFIGURATION_HPP_ +#include <com/sun/star/ucb/XContentProviderConfiguration.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERCONFIGURATIONMANAGER_HPP_ +#include <com/sun/star/ucb/XContentProviderConfigurationManager.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERMANAGER_HPP_ +#include <com/sun/star/ucb/XContentProviderManager.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPARAMETERIZEDCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XParameterizedContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_EXCEPTION_HPP_ +#include <com/sun/star/uno/Exception.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_REFERENCE_HXX_ +#include <com/sun/star/uno/Reference.hxx> +#endif +#ifndef _COM_SUN_STAR_UNO_RUNTIMEEXCEPTION_HPP_ +#include <com/sun/star/uno/RuntimeException.hpp> +#endif +#ifndef _COM_SUN_STAR_UNO_SEQUENCE_HXX_ +#include <com/sun/star/uno/Sequence.hxx> +#endif +#ifndef _RTL_USTRING_HXX_ +#include <rtl/ustring.hxx> +#endif + +#ifndef _UCBHELPER_REGISTERUCB_HXX_ +#include <ucbhelper/registerucb.hxx> +#endif + +using namespace com::sun; +using namespace com::sun::star; + +//============================================================================ +// +// configureUcb +// +//============================================================================ + +namespace ucb { + +bool +configureUcb( + uno::Reference< star::ucb::XContentProviderManager > const & rUcb, + uno::Reference< lang::XMultiServiceFactory > const & rFactory, + rtl::OUString const & rConfigurationKey) + throw (uno::RuntimeException) +{ + if (!(rUcb.is() && rFactory.is())) + return false; + + uno::Reference< star::ucb::XContentProviderConfigurationManager > + xManager; + try + { + xManager + = uno::Reference< + star::ucb::XContentProviderConfigurationManager >( + rFactory-> + createInstance(rtl::OUString::createFromAscii( + "com.sun.star.ucb.Configuration")), + uno::UNO_QUERY); + } + catch (uno::RuntimeException const &) { throw; } + catch (uno::Exception const &) {} + if (!xManager.is()) + return false; + + uno::Reference< star::ucb::XContentProviderConfiguration > + xConfiguration(xManager->queryContentProviderConfiguration( + rConfigurationKey)); + if (!xConfiguration.is()) + return false; + + registerAtUcb(rUcb, + rFactory, + xConfiguration-> + queryContentProviderServiceInfo(rtl::OUString()), + 0); + return true; +} + +} + + diff --git a/ucbhelper/source/provider/contenthelper.cxx b/ucbhelper/source/provider/contenthelper.cxx new file mode 100644 index 000000000000..3e5e875ddbe6 --- /dev/null +++ b/ucbhelper/source/provider/contenthelper.cxx @@ -0,0 +1,1250 @@ +/************************************************************************* + * + * $RCSfile: contenthelper.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef __HASH_MAP__ +#include <stl/hash_map> +#endif +#ifndef _COM_SUN_STAR_UCB_CONTENTACTION_HPP_ +#include <com/sun/star/ucb/ContentAction.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_COMMANDINFOCHANGE_HPP_ +#include <com/sun/star/ucb/CommandInfoChange.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPERSISTENTPROPERTYSET_HPP_ +#include <com/sun/star/ucb/XPersistentPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYSETINFOCHANGE_HPP_ +#include <com/sun/star/beans/PropertySetInfoChange.hpp> +#endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _VOS_MUTEX_HXX_ +#include <vos/mutex.hxx> +#endif + +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include <ucbhelper/contentidentifier.hxx> +#endif +#ifndef _UCBHELPER_CONTENTHELPER_HXX +#include <ucbhelper/contenthelper.hxx> +#endif +#ifndef _UCBHELPER_PROVIDERHELPER_HXX +#include <ucbhelper/providerhelper.hxx> +#endif +#ifndef _UCBHELPER_CONTENTINFO_HXX +#include <ucbhelper/contentinfo.hxx> +#endif + +using namespace com::sun::star::container; +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::task; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace cppu; +using namespace rtl; +using namespace vos; +using namespace ucb; + +namespace ucb_impl +{ + +//========================================================================= +// +// class PropertyEventSequence. +// +//========================================================================= + +class PropertyEventSequence +{ + Sequence< PropertyChangeEvent > m_aSeq; + sal_uInt32 m_nPos; + +public: + PropertyEventSequence( sal_uInt32 nSize ) + : m_aSeq( nSize ), m_nPos( 0 ) {}; + + void append( const PropertyChangeEvent& rEvt ) + { m_aSeq.getArray()[ m_nPos ] = rEvt; ++m_nPos; } + + const Sequence< PropertyChangeEvent >& getEvents() + { m_aSeq.realloc( m_nPos ); return m_aSeq; } +}; + +//========================================================================= +// +// PropertiesEventListenerMap. +// +//========================================================================= + +typedef void* XPropertiesChangeListenerPtr; // -> Compiler problems! + +struct equalPtr +{ + bool operator()( const XPropertiesChangeListenerPtr& rp1, + const XPropertiesChangeListenerPtr& rp2 ) const + { + return ( rp1 == rp2 ); + } +}; + +struct hashPtr +{ + size_t operator()( const XPropertiesChangeListenerPtr& rp ) const + { + return (size_t)rp; + } +}; + +typedef std::hash_map +< + XPropertiesChangeListenerPtr, + PropertyEventSequence*, + hashPtr, + equalPtr +> +PropertiesEventListenerMap; + +//========================================================================= +// +// PropertyChangeListenerContainer. +// +//========================================================================= + +struct equalStr +{ + bool operator()( const OUString& s1, const OUString& s2 ) const + { + return !!( s1 == s2 ); + } +}; + +struct hashStr +{ + size_t operator()( const OUString& rName ) const + { + return rName.hashCode(); + } +}; + +typedef OMultiTypeInterfaceContainerHelperVar +< + OUString, + hashStr, + equalStr +> PropertyChangeListeners; + +//========================================================================= +// +// struct ContentImplHelper_Impl +// +//========================================================================= + +struct ContentImplHelper_Impl +{ + vos::ORef< PropertySetInfo > m_xPropSetInfo; + vos::ORef< CommandProcessorInfo > m_xCommandsInfo; + cppu::OInterfaceContainerHelper* m_pDisposeEventListeners; + cppu::OInterfaceContainerHelper* m_pContentEventListeners; + cppu::OInterfaceContainerHelper* m_pPropSetChangeListeners; + cppu::OInterfaceContainerHelper* m_pCommandChangeListeners; + PropertyChangeListeners* m_pPropertyChangeListeners; + + ContentImplHelper_Impl() + : m_pDisposeEventListeners( 0 ), + m_pContentEventListeners( 0 ), + m_pPropSetChangeListeners( 0 ), + m_pCommandChangeListeners( 0 ), + m_pPropertyChangeListeners( 0 ) {} + + ~ContentImplHelper_Impl() + { + delete m_pDisposeEventListeners; + delete m_pContentEventListeners; + delete m_pPropSetChangeListeners; + delete m_pCommandChangeListeners; + delete m_pPropertyChangeListeners; + } +}; + +} // namespace ucb_impl + +using namespace ucb_impl; + +//========================================================================= +//========================================================================= +// +// ContentImplHelper Implementation. +// +//========================================================================= +//========================================================================= + +ContentImplHelper::ContentImplHelper( + const Reference< XMultiServiceFactory >& rxSMgr, + const vos::ORef< ContentProviderImplHelper >& rxProvider, + const Reference< XContentIdentifier >& Identifier, + sal_Bool bRegisterAtProvider ) +: m_pImpl( new ContentImplHelper_Impl ), + m_xSMgr( rxSMgr ), + m_xProvider( rxProvider ), + m_xIdentifier( Identifier ), + m_nCommandId( 0 ) +{ + if ( bRegisterAtProvider ) + m_xProvider->addContent( this ); +} + +//========================================================================= +// virtual +ContentImplHelper::~ContentImplHelper() +{ + m_xProvider->removeContent( this ); + delete m_pImpl; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_10( ContentImplHelper, + XTypeProvider, + XServiceInfo, + XComponent, + XContent, + XCommandProcessor, + XPropertiesChangeNotifier, + XCommandInfoChangeNotifier, + XPropertyContainer, + XPropertySetInfoChangeNotifier, + XChild ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_10( ContentImplHelper, + XTypeProvider, + XServiceInfo, + XComponent, + XContent, + XCommandProcessor, + XPropertiesChangeNotifier, + XCommandInfoChangeNotifier, + XPropertyContainer, + XPropertySetInfoChangeNotifier, + XChild ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +/* + + Pure virtual. Must be implemented by derived classes! + +// virtual +OUString SAL_CALL ContentImplHelper::getImplementationName() + throw( RuntimeException ) +{ +} + +//========================================================================= +// virtual +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL +ContentImplHelper::getSupportedServiceNames() + throw( RuntimeException ) +{ +} + +*/ + +//========================================================================= +// virtual +sal_Bool SAL_CALL ContentImplHelper::supportsService( + const OUString& ServiceName ) + throw( RuntimeException ) +{ + Sequence< OUString > aSNL = getSupportedServiceNames(); + const OUString* pArray = aSNL.getConstArray(); + for ( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) + { + if ( pArray[ i ] == ServiceName ) + return sal_True; + } + + return sal_False; +} + +//========================================================================= +// +// XComponent methods. +// +//========================================================================= + +// virtual +void SAL_CALL ContentImplHelper::dispose() + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_pImpl->m_pDisposeEventListeners && + m_pImpl->m_pDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XComponent * >( this ); + m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt ); + } + + if ( m_pImpl->m_pContentEventListeners && + m_pImpl->m_pContentEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XContent * >( this ); + m_pImpl->m_pContentEventListeners->disposeAndClear( aEvt ); + } + + if ( m_pImpl->m_pPropSetChangeListeners && + m_pImpl->m_pPropSetChangeListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertySetInfoChangeNotifier * >( this ); + m_pImpl->m_pPropSetChangeListeners->disposeAndClear( aEvt ); + } + + if ( m_pImpl->m_pCommandChangeListeners && + m_pImpl->m_pCommandChangeListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XCommandInfoChangeNotifier * >( this ); + m_pImpl->m_pCommandChangeListeners->disposeAndClear( aEvt ); + } + + if ( m_pImpl->m_pPropertyChangeListeners ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertiesChangeNotifier * >( this ); + m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt ); + } +} + +//========================================================================= +// virtual +void SAL_CALL ContentImplHelper::addEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pImpl->m_pDisposeEventListeners ) + m_pImpl->m_pDisposeEventListeners + = new OInterfaceContainerHelper( m_aMutex ); + + m_pImpl->m_pDisposeEventListeners->addInterface( Listener ); +} + +//========================================================================= +// virtual +void SAL_CALL ContentImplHelper::removeEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_pImpl->m_pDisposeEventListeners ) + m_pImpl->m_pDisposeEventListeners->removeInterface( Listener ); +} + +//========================================================================= +// +// XContent methods. +// +//========================================================================= + +// virtual +Reference< XContentIdentifier > SAL_CALL ContentImplHelper::getIdentifier() + throw( RuntimeException ) +{ + return m_xIdentifier; +} + +/* + + Pure virtual. Must be implemented by derived classes! + +//========================================================================= +// virtual +OUString SAL_CALL ContentImplHelper::getContentType() + throw( RuntimeException ) +{ +} + +*/ + +//========================================================================= +// virtual +void SAL_CALL ContentImplHelper::addContentEventListener( + const Reference< XContentEventListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pImpl->m_pContentEventListeners ) + m_pImpl->m_pContentEventListeners + = new OInterfaceContainerHelper( m_aMutex ); + + m_pImpl->m_pContentEventListeners->addInterface( Listener ); +} + +//========================================================================= +// virtual +void SAL_CALL ContentImplHelper::removeContentEventListener( + const Reference< XContentEventListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_pImpl->m_pContentEventListeners ) + m_pImpl->m_pContentEventListeners->removeInterface( Listener ); +} + +//========================================================================= +// +// XCommandProcessor methods. +// +//========================================================================= + +// virtual +sal_Int32 SAL_CALL ContentImplHelper::createCommandIdentifier() + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + // Just increase counter on every call to generate an identifier. + return ++m_nCommandId; +} + +/* + + Pure virtual. Must be implemented by derived classes! + +//========================================================================= +// virtual +Any SAL_CALL ContentImplHelper::execute( const Command& aCommand, + sal_Int32 CommandId, + const Reference< + XCommandEnvironment >& Environment ) + throw( Exception, CommandAbortedException, RuntimeException ) +{ + if ( aCommand.Name.compareToAscii( "getPropertyValues" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // getPropertyValues + ////////////////////////////////////////////////////////////////// + + Sequence< Property > Properties; + if ( !( aCommand.Argument >>= Properties ) ) + { + VOS_ENSURE( sal_False, "Wrong argument type!" ) + return Any(); + } + + // Note: GET + empty sequence means "get all property values". + } + else if ( aCommand.Name.compareToAscii( "setPropertyValues" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // setPropertyValues + ////////////////////////////////////////////////////////////////// + + Sequence< PropertyValue > Properties; + if ( !( aCommand.Argument >>= Properties ) ) + { + VOS_ENSURE( sal_False, "Wrong argument type!" ) + return Any(); + } + + if ( !Properties.getLength() ) + { + VOS_ENSURE( sal_False, "No properties!" ) + return Any(); + } + } + else if ( aCommand.Name.compareToAscii( "getPropertySetInfo" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // getPropertySetInfo + ////////////////////////////////////////////////////////////////// + + aRet <<= getPropertySetInfo(); + } + else if ( aCommand.Name.compareToAscii( "getCommandInfo" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // getCommandInfo + ////////////////////////////////////////////////////////////////// + + aRet <<= getCommandInfo(); + } + else if ( ( aCommand.Name.compareToAscii( "open" ) == 0 ) && + ( open_command_arg contains no data sink ) ) + { + ////////////////////////////////////////////////////////////////// + // open command for a folder content + ////////////////////////////////////////////////////////////////// + + Reference< XDynamicResultSet > xSet + = new DynamicResultSet( m_xSMgr, this, aCommand, Environment ); + aRet <<= xSet; + } + else if ( aCommand.Name.compareToAscii( "search" ) == 0 ) + { + ////////////////////////////////////////////////////////////////// + // search command + ////////////////////////////////////////////////////////////////// + + Reference< XDynamicResultSet > xSet + = new DynamicResultSet( m_xSMgr, this, aCommand, Environment ); + aRet <<= xSet; + } + else + { + ////////////////////////////////////////////////////////////////// + // any other command + ////////////////////////////////////////////////////////////////// + + // Check the command... + if ( !aCommand.Name.getLength() && ( aCommand.Handle == -1 ) ) + { + VOS_ENSURE( sal_False, "No command!" ) + return Any(); + } + + } + + return aRet; +} + +//========================================================================= +// virtual +void SAL_CALL ContentImplHelper::abort( sal_Int32 CommandId ) + throw( RuntimeException ) +{ +} + +*/ + +//========================================================================= +// +// XPropertiesChangeNotifier methods. +// +//========================================================================= + +// virtual +void SAL_CALL ContentImplHelper::addPropertiesChangeListener( + const Sequence< OUString >& PropertyNames, + const Reference< XPropertiesChangeListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pImpl->m_pPropertyChangeListeners ) + m_pImpl->m_pPropertyChangeListeners + = new PropertyChangeListeners( m_aMutex ); + + sal_Int32 nCount = PropertyNames.getLength(); + if ( !nCount ) + { + // Note: An empty sequence means a listener for "all" properties. + m_pImpl->m_pPropertyChangeListeners->addInterface( + OUString(), Listener ); + } + else + { + const OUString* pSeq = PropertyNames.getConstArray(); + + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const OUString& rName = pSeq[ n ]; + if ( rName.getLength() ) + m_pImpl->m_pPropertyChangeListeners->addInterface( + rName, Listener ); + } + } +} + +//========================================================================= +// virtual +void SAL_CALL ContentImplHelper::removePropertiesChangeListener( + const Sequence< OUString >& PropertyNames, + const Reference< XPropertiesChangeListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pImpl->m_pPropertyChangeListeners ) + return; + + sal_Int32 nCount = PropertyNames.getLength(); + if ( !nCount ) + { + // Note: An empty sequence means a listener for "all" properties. + m_pImpl->m_pPropertyChangeListeners->removeInterface( + OUString(), Listener ); + } + else + { + const OUString* pSeq = PropertyNames.getConstArray(); + + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const OUString& rName = pSeq[ n ]; + if ( rName.getLength() ) + m_pImpl->m_pPropertyChangeListeners->removeInterface( + rName, Listener ); + } + } +} + +//========================================================================= +// +// XCommandInfoChangeNotifier methods. +// +//========================================================================= + +// virtual +void SAL_CALL ContentImplHelper::addCommandInfoChangeListener( + const Reference< XCommandInfoChangeListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pImpl->m_pCommandChangeListeners ) + m_pImpl->m_pCommandChangeListeners + = new OInterfaceContainerHelper( m_aMutex ); + + m_pImpl->m_pCommandChangeListeners->addInterface( Listener ); +} + +//========================================================================= +// virtual +void SAL_CALL ContentImplHelper::removeCommandInfoChangeListener( + const Reference< XCommandInfoChangeListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_pImpl->m_pCommandChangeListeners ) + m_pImpl->m_pCommandChangeListeners->removeInterface( Listener ); +} + +//========================================================================= +// +// XPropertyContainer methods. +// +//========================================================================= + +// virtual +void SAL_CALL ContentImplHelper::addProperty( + const OUString& Name, sal_Int16 Attributes, const Any& DefaultValue ) + throw( PropertyExistException, + IllegalTypeException, + IllegalArgumentException, + RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + ////////////////////////////////////////////////////////////////////// + // Make sure a property with the requested name does not already + // exist in dynamic and static(!) properties. + ////////////////////////////////////////////////////////////////////// + + if ( getPropertySetInfo()->hasPropertyByName( Name ) ) + { + // Property does already exist. + throw PropertyExistException(); + } + + ////////////////////////////////////////////////////////////////////// + // Add a new dynamic property. + ////////////////////////////////////////////////////////////////////// + + // Open/create persistent property set. + Reference< XPersistentPropertySet > xSet( + getAdditionalPropertySet( sal_True ) ); + + VOS_ENSURE( xSet.is(), "ContentImplHelper::addProperty - No property set!" ); + + if ( xSet.is() ) + { + Reference< XPropertyContainer > xContainer( xSet, UNO_QUERY ); + + VOS_ENSURE( xContainer.is(), + "ContentImplHelper::addProperty - No property container!" ); + + if ( xContainer.is() ) + { + // Property is always removeable. + Attributes |= PropertyAttribute::REMOVEABLE; + + try + { + xContainer->addProperty( Name, Attributes, DefaultValue ); + } + catch ( PropertyExistException& e ) + { + VOS_ENSURE( sal_False, + "ContentImplHelper::addProperty - Exists!" ); + throw e; + } + catch ( IllegalTypeException& e ) + { + VOS_ENSURE( sal_False, + "ContentImplHelper::addProperty - Wrong Type!" ); + throw e; + } + catch ( IllegalArgumentException& e ) + { + VOS_ENSURE( sal_False, + "ContentImplHelper::addProperty - Illegal Arg!" ); + throw e; + } + + // Success! + + if ( m_pImpl->m_xPropSetInfo.isValid() ) + { + // Info cached in propertyset info is invalid now! + m_pImpl->m_xPropSetInfo->reset(); + } + + // Notify propertyset info change listeners. + if ( m_pImpl->m_pPropSetChangeListeners && + m_pImpl->m_pPropSetChangeListeners->getLength() ) + { + PropertySetInfoChangeEvent evt( + static_cast< OWeakObject * >( this ), + Name, + -1, // No handle available + PropertySetInfoChange::PROPERTY_INSERTED ); + notifyPropertySetInfoChange( evt ); + } + } + } +} + +//========================================================================= +// virtual +void SAL_CALL ContentImplHelper::removeProperty( const OUString& Name ) + throw( UnknownPropertyException, + NotRemoveableException, + RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + try + { + Property aProp = getPropertySetInfo()->getPropertyByName( Name ); + + if ( !( aProp.Attributes & PropertyAttribute::REMOVEABLE ) ) + { + // Not removeable! + throw NotRemoveableException(); + } + } + catch ( UnknownPropertyException& e ) + { + VOS_ENSURE( sal_False, "ContentImplHelper::removeProperty - Unknown!" ); + throw e; + } + + ////////////////////////////////////////////////////////////////////// + // Try to remove property from dynamic property set. + ////////////////////////////////////////////////////////////////////// + + // Open persistent property set, if exists. + Reference< XPersistentPropertySet > xSet( + getAdditionalPropertySet( sal_False ) ); + if ( xSet.is() ) + { + Reference< XPropertyContainer > xContainer( xSet, UNO_QUERY ); + + VOS_ENSURE( xContainer.is(), + "ContentImplHelper::removeProperty - No property container!" ); + + if ( xContainer.is() ) + { + try + { + xContainer->removeProperty( Name ); + } + catch ( UnknownPropertyException& e ) + { + VOS_ENSURE( sal_False, + "ContentImplHelper::removeProperty - Unknown!" ); + throw e; + } + catch ( NotRemoveableException& e ) + { + VOS_ENSURE( sal_False, + "ContentImplHelper::removeProperty - Unremoveable!" ); + throw e; + } + + xContainer = 0; + + // Success! + + if ( xSet->getPropertySetInfo()->getProperties().getLength() == 0 ) + { + // Remove empty propertyset from registry. + Reference< XPropertySetRegistry > xReg = xSet->getRegistry(); + if ( xReg.is() ) + { + OUString aKey( xSet->getKey() ); + xSet = 0; + xReg->removePropertySet( aKey ); + } + } + + if ( m_pImpl->m_xPropSetInfo.isValid() ) + { + // Info cached in propertyset info is invalid now! + m_pImpl->m_xPropSetInfo->reset(); + } + + // Notify propertyset info change listeners. + if ( m_pImpl->m_pPropSetChangeListeners && + m_pImpl->m_pPropSetChangeListeners->getLength() ) + { + PropertySetInfoChangeEvent evt( + static_cast< OWeakObject * >( this ), + Name, + -1, // No handle available + PropertySetInfoChange::PROPERTY_REMOVED ); + notifyPropertySetInfoChange( evt ); + } + } + } +} + +//========================================================================= +// +// XPropertySetInfoChangeNotifier methods. +// +//========================================================================= + +// virtual +void SAL_CALL ContentImplHelper::addPropertySetInfoChangeListener( + const Reference< XPropertySetInfoChangeListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pImpl->m_pPropSetChangeListeners ) + m_pImpl->m_pPropSetChangeListeners + = new OInterfaceContainerHelper( m_aMutex ); + + m_pImpl->m_pPropSetChangeListeners->addInterface( Listener ); +} + +//========================================================================= +// virtual +void SAL_CALL ContentImplHelper::removePropertySetInfoChangeListener( + const Reference< XPropertySetInfoChangeListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_pImpl->m_pPropSetChangeListeners ) + m_pImpl->m_pPropSetChangeListeners->removeInterface( Listener ); +} + +//========================================================================= +// +// XChild methods. +// +//========================================================================= + +// virtual +Reference< XInterface > SAL_CALL ContentImplHelper::getParent() + throw( RuntimeException ) +{ + OUString aURL = getParentURL(); + + if ( aURL.getLength() ) + { + Reference< XContentIdentifier > xId( + new ::ucb::ContentIdentifier( m_xSMgr, aURL ) ); + return m_xProvider->queryContent( xId ); + } + + return Reference< XInterface >(); +} + +//========================================================================= +// virtual +void SAL_CALL ContentImplHelper::setParent( + const Reference< XInterface >& Parent ) + throw( NoSupportException, RuntimeException ) +{ + throw NoSupportException(); +} + +//========================================================================= +// +// Non-interface methods +// +//========================================================================= + +Reference< XPersistentPropertySet > + ContentImplHelper::getAdditionalPropertySet( sal_Bool bCreate ) +{ + // Get propertyset from provider. + return m_xProvider->getAdditionalPropertySet( + m_xIdentifier->getContentIdentifier(), bCreate ); +} + +//========================================================================= +sal_Bool ContentImplHelper::renameAdditionalPropertySet( + const OUString& rOldKey, + const OUString& rNewKey, + sal_Bool bRecursive ) +{ + return m_xProvider->renameAdditionalPropertySet( + rOldKey, rNewKey, bRecursive ); +} + +//========================================================================= +sal_Bool ContentImplHelper::removeAdditionalPropertySet( sal_Bool bRecursive ) +{ + return m_xProvider->removeAdditionalPropertySet( + m_xIdentifier->getContentIdentifier(), bRecursive ); +} + +//========================================================================= +void ContentImplHelper::notifyPropertiesChange( + const Sequence< PropertyChangeEvent >& evt ) const +{ + if ( !m_pImpl->m_pPropertyChangeListeners ) + return; + + sal_Int32 nCount = evt.getLength(); + if ( nCount ) + { + // First, notify listeners interested in changes of every property. + OInterfaceContainerHelper* pAllPropsContainer + = m_pImpl->m_pPropertyChangeListeners->getContainer( OUString() ); + if ( pAllPropsContainer ) + { + OInterfaceIteratorHelper aIter( *pAllPropsContainer ); + while ( aIter.hasMoreElements() ) + { + // Propagate event. + Reference< XPropertiesChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->propertiesChange( evt ); + } + } + + PropertiesEventListenerMap aListeners; + + const PropertyChangeEvent* pEvents = evt.getConstArray(); + + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const PropertyChangeEvent& rEvent = pEvents[ n ]; + const OUString& rName = rEvent.PropertyName; + + OInterfaceContainerHelper* pPropsContainer + = m_pImpl->m_pPropertyChangeListeners->getContainer( rName ); + if ( pPropsContainer ) + { + OInterfaceIteratorHelper aIter( *pPropsContainer ); + while ( aIter.hasMoreElements() ) + { + PropertyEventSequence* pEvents = NULL; + + XPropertiesChangeListener* pListener = + static_cast< XPropertiesChangeListener * >( + aIter.next() ); + PropertiesEventListenerMap::iterator it = + aListeners.find( pListener ); + if ( it == aListeners.end() ) + { + // Not in map - create and insert new entry. + pEvents = new PropertyEventSequence( nCount ); + aListeners[ pListener ] = pEvents; + } + else + pEvents = (*it).second; + + if ( pEvents ) + pEvents->append( rEvent ); + } + } + } + + // Notify listeners. + PropertiesEventListenerMap::iterator it = aListeners.begin(); + while ( !aListeners.empty() ) + { + XPropertiesChangeListener* pListener = + static_cast< XPropertiesChangeListener * >( (*it).first ); + PropertyEventSequence* pSeq = (*it).second; + + // Remove current element. + aListeners.erase( it ); + + // Propagate event. + pListener->propertiesChange( pSeq->getEvents() ); + + delete pSeq; + + it = aListeners.begin(); + } + } +} + +//========================================================================= +void ContentImplHelper::notifyPropertySetInfoChange( + const PropertySetInfoChangeEvent& evt ) const +{ + if ( !m_pImpl->m_pPropSetChangeListeners ) + return; + + // Notify event listeners. + OInterfaceIteratorHelper aIter( *m_pImpl->m_pPropSetChangeListeners ); + while ( aIter.hasMoreElements() ) + { + // Propagate event. + Reference< XPropertySetInfoChangeListener > + xListener( aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->propertySetInfoChange( evt ); + } +} + +//========================================================================= +void ContentImplHelper::notifyCommandInfoChange( + const CommandInfoChangeEvent& evt ) const +{ + if ( !m_pImpl->m_pCommandChangeListeners ) + return; + + // Notify event listeners. + OInterfaceIteratorHelper aIter( *m_pImpl->m_pCommandChangeListeners ); + while ( aIter.hasMoreElements() ) + { + // Propagate event. + Reference< XCommandInfoChangeListener > + xListener( aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->commandInfoChange( evt ); + } +} + +//========================================================================= +void ContentImplHelper::notifyContentEvent( const ContentEvent& evt ) const +{ + if ( !m_pImpl->m_pContentEventListeners ) + return; + + // Notify event listeners. + OInterfaceIteratorHelper aIter( *m_pImpl->m_pContentEventListeners ); + while ( aIter.hasMoreElements() ) + { + // Propagate event. + Reference< XContentEventListener > xListener( aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->contentEvent( evt ); + } +} + +//========================================================================= +void ContentImplHelper::inserted() +{ + // Content is not yet registered at provider. + m_xProvider->addContent( this ); + + // If the parent content is currently not instanciated, there can be + // no listeners interested in changes ;-) + + vos::ORef< ContentImplHelper > xParent + = m_xProvider->queryExistingContent( getParentURL() ); + + if ( xParent.isValid() ) + { + ContentEvent aEvt( static_cast< OWeakObject * >( + xParent.getBodyPtr() ), // Source + ContentAction::INSERTED, // Action + this, // Content + xParent->getIdentifier() ); // Id + xParent->notifyContentEvent( aEvt ); + } +} + +//========================================================================= +void ContentImplHelper::deleted() +{ + Reference< XContent > xThis = this; + + vos::ORef< ContentImplHelper > xParent + = m_xProvider->queryExistingContent( getParentURL() ); + + if ( xParent.isValid() ) + { + // Let parent notify "REMOVED" event. + ContentEvent aEvt( static_cast< OWeakObject * >( xParent.getBodyPtr() ), + ContentAction::REMOVED, + this, + xParent->getIdentifier() ); + xParent->notifyContentEvent( aEvt ); + } + + // Notify "DELETED" event. + ContentEvent aEvt1( static_cast< OWeakObject * >( this ), + ContentAction::DELETED, + this, + getIdentifier() ); + notifyContentEvent( aEvt1 ); + + m_xProvider->removeContent( this ); +} + +//========================================================================= +sal_Bool ContentImplHelper::exchange( + const Reference< XContentIdentifier >& rNewId ) +{ + Reference< XContent > xThis = this; + + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + + vos::ORef< ContentImplHelper > xContent + = m_xProvider->queryExistingContent( rNewId ); + if ( xContent.isValid() ) + { + // @@@ + // Big trouble. Another object with the new identity exists. + // How shall I mutate to / merge with the other object? + return sal_False; + } + + Reference< XContentIdentifier > xOldId = getIdentifier(); + + // Re-insert at provider. + m_xProvider->removeContent( this ); + m_xIdentifier = rNewId; + m_xProvider->addContent( this ); + + aGuard.clear(); + + // Notify "EXCHANGED" event. + ContentEvent aEvt( static_cast< OWeakObject * >( this ), + ContentAction::EXCHANGED, + this, + xOldId ); + notifyContentEvent( aEvt ); + return sal_True; +} + +//========================================================================= +Reference< XCommandInfo > ContentImplHelper::getCommandInfo() +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pImpl->m_xCommandsInfo.isValid() ) + m_pImpl->m_xCommandsInfo = new CommandProcessorInfo( m_xSMgr, this ); + + return Reference< XCommandInfo >( m_pImpl->m_xCommandsInfo.getBodyPtr() ); +} + +//========================================================================= +Reference< XPropertySetInfo > ContentImplHelper::getPropertySetInfo() +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pImpl->m_xPropSetInfo.isValid() ) + m_pImpl->m_xPropSetInfo = new PropertySetInfo( m_xSMgr, this ); + + return Reference< XPropertySetInfo >( + m_pImpl->m_xPropSetInfo.getBodyPtr() ); +} + diff --git a/ucbhelper/source/provider/contentidentifier.cxx b/ucbhelper/source/provider/contentidentifier.cxx new file mode 100644 index 000000000000..115c44414960 --- /dev/null +++ b/ucbhelper/source/provider/contentidentifier.cxx @@ -0,0 +1,262 @@ +/************************************************************************* + * + * $RCSfile: contentidentifier.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include <ucbhelper/contentidentifier.hxx> +#endif + +#ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ +#include <cppuhelper/typeprovider.hxx> +#endif + +#ifndef _OSL_MUTEX_HXX_ +#include <osl/mutex.hxx> +#endif + +using namespace rtl; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::ucb; + +namespace ucb +{ + +//========================================================================= +//========================================================================= +// +// struct ContentIdentifier_Impl. +// +//========================================================================= +//========================================================================= + +struct ContentIdentifier_Impl +{ + Reference< XMultiServiceFactory > m_xSMgr; + OUString m_aContentId; + OUString m_aProviderScheme; + osl::Mutex m_aMutex; + + ContentIdentifier_Impl( const Reference< XMultiServiceFactory >& rSMgr, + const OUString& rURL ); +}; + +//========================================================================= +// +// ContentIdentifier_Impl Implementation. +// +//========================================================================= + +ContentIdentifier_Impl::ContentIdentifier_Impl( + const Reference< XMultiServiceFactory >& rSMgr, + const OUString& rURL ) +: m_xSMgr( rSMgr ) +{ + // Normalize URL scheme ( it's case insensitive ). + + // The content provider scheme is the part before the first ':' + // within the content id. + sal_Int32 nPos = rURL.indexOf( ':', 0 ); + if ( nPos != -1 ) + { + OUString aScheme( rURL.copy( 0, nPos ) ); + m_aProviderScheme = aScheme.toLowerCase(); + m_aContentId = rURL.replaceAt( 0, nPos, aScheme ); + } +} + +//========================================================================= +// +// ContentIdentifier Implementation. +// +//========================================================================= + +ContentIdentifier::ContentIdentifier( + const Reference< XMultiServiceFactory >& rxSMgr, + const OUString& rURL ) +{ + m_pImpl = new ContentIdentifier_Impl( rxSMgr, rURL ); +} + +//========================================================================= +ContentIdentifier::ContentIdentifier( const OUString& rURL ) +{ + m_pImpl = new ContentIdentifier_Impl( + Reference< XMultiServiceFactory >(), rURL ); +} + +//========================================================================= +// virtual +ContentIdentifier::~ContentIdentifier() +{ + delete m_pImpl; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +//========================================================================= +// virtual +void SAL_CALL ContentIdentifier::acquire() + throw( RuntimeException ) +{ + OWeakObject::acquire(); +} + +//========================================================================= +// virtual +void SAL_CALL ContentIdentifier::release() + throw( RuntimeException ) +{ + OWeakObject::release(); +} + +//========================================================================= +// virtual +Any SAL_CALL +ContentIdentifier::queryInterface( const Type & rType ) + throw ( RuntimeException ) +{ + Any aRet = cppu::queryInterface( rType, + static_cast< XTypeProvider * >( this ), + static_cast< XContentIdentifier * >( this ) ); + + return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType ); +} + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +// virtual +Sequence< sal_Int8 > SAL_CALL +ContentIdentifier::getImplementationId() + throw( RuntimeException ) +{ + static cppu::OImplementationId* pId = NULL; + if ( !pId ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if ( !pId ) + { + static cppu::OImplementationId id( sal_False ); + pId = &id; + } + } + return (*pId).getImplementationId(); +} + +//========================================================================= +// virtual +Sequence< com::sun::star::uno::Type > SAL_CALL +ContentIdentifier::getTypes() + throw( RuntimeException ) +{ + static cppu::OTypeCollection* pCollection = NULL; + if ( !pCollection ) + { + osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); + if ( !pCollection ) + { + static cppu::OTypeCollection collection( + getCppuType( static_cast< + Reference < XTypeProvider > * >( 0 ) ), + getCppuType( static_cast< + Reference< XContentIdentifier > * >( 0 ) ) ); + pCollection = &collection; + } + } + return (*pCollection).getTypes(); +} + +//========================================================================= +// +// XContentIdentifier methods. +// +//========================================================================= + +// virtual +OUString SAL_CALL ContentIdentifier::getContentIdentifier() + throw( RuntimeException ) +{ + return m_pImpl->m_aContentId; +} + +//========================================================================= +// virtual +OUString SAL_CALL ContentIdentifier::getContentProviderScheme() + throw( RuntimeException ) +{ + return m_pImpl->m_aProviderScheme; +} + +} /* namespace ucb */ + diff --git a/ucbhelper/source/provider/contentinfo.cxx b/ucbhelper/source/provider/contentinfo.cxx new file mode 100644 index 000000000000..588eabbf6e22 --- /dev/null +++ b/ucbhelper/source/provider/contentinfo.cxx @@ -0,0 +1,475 @@ +/************************************************************************* + * + * $RCSfile: contentinfo.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_BEANS_PROPERTYVALUE_HPP_ +#include <com/sun/star/beans/PropertyValue.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROPERTYSETREGISTRY_HPP_ +#include <com/sun/star/ucb/XPropertySetRegistry.hpp> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _UCBHELPER_CONTENTHELPER_HXX +#include <ucbhelper/contenthelper.hxx> +#endif +#ifndef _UCBHELPER_CONTENTINFO_HXX +#include <ucbhelper/contentinfo.hxx> +#endif + +using namespace rtl; +using namespace vos; +using namespace com::sun::star::uno; +using namespace com::sun::star::lang; +using namespace com::sun::star::beans; +using namespace com::sun::star::ucb; +using namespace ucb; + +//========================================================================= +//========================================================================= +// +// PropertySetInfo Implementation. +// +//========================================================================= +//========================================================================= + +PropertySetInfo::PropertySetInfo( + const Reference< XMultiServiceFactory >& rxSMgr, + ContentImplHelper* pContent ) +: m_xSMgr( rxSMgr ), + m_pProps( 0 ), + m_pContent( pContent ) +{ +} + +//========================================================================= +// virtual +PropertySetInfo::~PropertySetInfo() +{ + delete m_pProps; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_2( PropertySetInfo, + XTypeProvider, + XPropertySetInfo ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_2( PropertySetInfo, + XTypeProvider, + XPropertySetInfo ); + +//========================================================================= +// +// XPropertySetInfo methods. +// +//========================================================================= + +// virtual +Sequence< Property > SAL_CALL PropertySetInfo::getProperties() + throw( RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( !m_pProps ) + { + m_pProps = new Sequence< Property >( 128 ); + Property* pProps = m_pProps->getArray(); + sal_Int32 nPos = 0; + sal_Int32 nSize = m_pProps->getLength(); + + ////////////////////////////////////////////////////////////////// + // Get info for core ( native) properties. + ////////////////////////////////////////////////////////////////// + + const ::ucb::PropertyInfoTableEntry& rCoreProps + = m_pContent->getPropertyInfoTable(); + const ::ucb::PropertyInfoTableEntry* pCurr = &rCoreProps; + while ( pCurr->pName ) + { + if ( nSize <= nPos ) + { + m_pProps->realloc( 128 ); + nSize += 128; + } + + Property& rProp = pProps[ nPos ]; + + VOS_ENSURE( pCurr->pType, + "PropertySetInfo::getProperties - No type!" ); + + rProp.Name = OUString::createFromAscii( pCurr->pName ); + rProp.Handle = pCurr->nHandle; + rProp.Type = *pCurr->pType; + rProp.Attributes = pCurr->nAttributes; + + nPos++; + pCurr++; + } + + if ( nPos > 0 ) + { + m_pProps->realloc( nPos ); + nSize = m_pProps->getLength(); + } + + ////////////////////////////////////////////////////////////////// + // Get info for additional properties. + ////////////////////////////////////////////////////////////////// + + Reference< XPersistentPropertySet > xSet ( + m_pContent->getAdditionalPropertySet( sal_False ) ); + + if ( xSet.is() ) + { + // Get property set info. + Reference< XPropertySetInfo > xInfo( xSet->getPropertySetInfo() ); + if ( xInfo.is() ) + { + const Sequence< Property >& rAddProps = xInfo->getProperties(); + sal_Int32 nAddProps = rAddProps.getLength(); + if ( nAddProps > 0 ) + { + m_pProps->realloc( nSize + nAddProps ); + pProps = m_pProps->getArray(); + + const Property* pAddProps = rAddProps.getConstArray(); + for ( sal_Int32 n = 0; n < nAddProps; ++n, ++nPos ) + pProps[ nPos ] = pAddProps[ n ]; + } + } + } + } + return *m_pProps; +} + +//========================================================================= +// virtual +Property SAL_CALL PropertySetInfo::getPropertyByName( const OUString& aName ) + throw( UnknownPropertyException, RuntimeException ) +{ + Property aProp; + if ( queryProperty( aName, aProp ) ) + return aProp; + + throw UnknownPropertyException(); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const OUString& Name ) + throw( RuntimeException ) +{ + Property aProp; + return queryProperty( Name, aProp ); +} + +//========================================================================= +// +// Non-Interface methods. +// +//========================================================================= + +void PropertySetInfo::reset() +{ + vos::OGuard aGuard( m_aMutex ); + delete m_pProps; + m_pProps = 0; +} + +//========================================================================= +sal_Bool PropertySetInfo::queryProperty( + const OUString& rName, Property& rProp ) +{ + vos::OGuard aGuard( m_aMutex ); + + getProperties(); + + const Property* pProps = m_pProps->getConstArray(); + sal_Int32 nCount = m_pProps->getLength(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const Property& rCurrProp = pProps[ n ]; + if ( rCurrProp.Name == rName ) + { + rProp = rCurrProp; + return sal_True; + } + } + + return sal_False; +} + +//========================================================================= +//========================================================================= +// +// CommandProcessorInfo Implementation. +// +//========================================================================= +//========================================================================= + +CommandProcessorInfo::CommandProcessorInfo( + const Reference< XMultiServiceFactory >& rxSMgr, + ContentImplHelper* pContent ) +: m_xSMgr( rxSMgr ), + m_pCommands( 0 ), + m_pContent( pContent ) +{ +} + +//========================================================================= +// virtual +CommandProcessorInfo::~CommandProcessorInfo() +{ + delete m_pCommands; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_2( CommandProcessorInfo, + XTypeProvider, + XCommandInfo ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_2( CommandProcessorInfo, + XTypeProvider, + XCommandInfo ); + +//========================================================================= +// +// XCommandInfo methods. +// +//========================================================================= + +// virtual +Sequence< CommandInfo > SAL_CALL CommandProcessorInfo::getCommands() + throw( RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( !m_pCommands ) + { + m_pCommands = new Sequence< CommandInfo >( 128 ); + CommandInfo* pCommands = m_pCommands->getArray(); + sal_Int32 nPos = 0; + sal_Int32 nSize = m_pCommands->getLength(); + + ////////////////////////////////////////////////////////////////// + // Get info for commands. + ////////////////////////////////////////////////////////////////// + + const ::ucb::CommandInfoTableEntry& rCommands + = m_pContent->getCommandInfoTable(); + const ::ucb::CommandInfoTableEntry* pCurr = &rCommands; + while ( pCurr->pName ) + { + if ( nSize <= nPos ) + { + m_pCommands->realloc( 128 ); + nSize += 128; + } + + CommandInfo& rCommand = pCommands[ nPos ]; + + rCommand.Name = OUString::createFromAscii( pCurr->pName ); + rCommand.Handle = pCurr->nHandle; + if ( pCurr->pArgType ) + rCommand.ArgType = *pCurr->pArgType; + + nPos++; + pCurr++; + } + + if ( nPos > 0 ) + m_pCommands->realloc( nPos ); + } + return *m_pCommands; +} + +//========================================================================= +// virtual +CommandInfo SAL_CALL CommandProcessorInfo::getCommandInfoByName( + const OUString& Name ) + throw( UnsupportedCommandException, RuntimeException ) +{ + CommandInfo aInfo; + if ( queryCommand( Name, aInfo ) ) + return aInfo; + + throw UnsupportedCommandException(); +} + +//========================================================================= +// virtual +CommandInfo SAL_CALL CommandProcessorInfo::getCommandInfoByHandle( + sal_Int32 Handle ) + throw( UnsupportedCommandException, RuntimeException ) +{ + CommandInfo aInfo; + if ( queryCommand( Handle, aInfo ) ) + return aInfo; + + throw UnsupportedCommandException(); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByName( const OUString& Name ) + throw( RuntimeException ) +{ + CommandInfo aInfo; + return queryCommand( Name, aInfo ); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL CommandProcessorInfo::hasCommandByHandle( sal_Int32 Handle ) + throw( RuntimeException ) +{ + CommandInfo aInfo; + return queryCommand( Handle, aInfo ); +} + +//========================================================================= +// +// Non-Interface methods. +// +//========================================================================= + +void CommandProcessorInfo::reset() +{ + vos::OGuard aGuard( m_aMutex ); + delete m_pCommands; + m_pCommands = 0; +} + + +//========================================================================= +sal_Bool CommandProcessorInfo::queryCommand( const OUString& rName, + CommandInfo& rCommand ) +{ + vos::OGuard aGuard( m_aMutex ); + + getCommands(); + + const CommandInfo* pCommands = m_pCommands->getConstArray(); + sal_Int32 nCount = m_pCommands->getLength(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const CommandInfo& rCurrCommand = pCommands[ n ]; + if ( rCurrCommand.Name == rName ) + { + rCommand = rCurrCommand; + return sal_True; + } + } + + return sal_False; +} + +//========================================================================= +sal_Bool CommandProcessorInfo::queryCommand( sal_Int32 nHandle, + CommandInfo& rCommand ) +{ + vos::OGuard aGuard( m_aMutex ); + + getCommands(); + + const CommandInfo* pCommands = m_pCommands->getConstArray(); + sal_Int32 nCount = m_pCommands->getLength(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const CommandInfo& rCurrCommand = pCommands[ n ]; + if ( rCurrCommand.Handle == nHandle ) + { + rCommand = rCurrCommand; + return sal_True; + } + } + + return sal_False; +} + diff --git a/ucbhelper/source/provider/makefile.mk b/ucbhelper/source/provider/makefile.mk new file mode 100644 index 000000000000..2f76091e63a1 --- /dev/null +++ b/ucbhelper/source/provider/makefile.mk @@ -0,0 +1,98 @@ +#************************************************************************* +# +# $RCSfile: makefile.mk,v $ +# +# $Revision: 1.1.1.1 $ +# +# last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ +# +# The Contents of this file are made available subject to the terms of +# either of the following licenses +# +# - GNU Lesser General Public License Version 2.1 +# - Sun Industry Standards Source License Version 1.1 +# +# Sun Microsystems Inc., October, 2000 +# +# GNU Lesser General Public License Version 2.1 +# ============================================= +# Copyright 2000 by Sun Microsystems, Inc. +# 901 San Antonio Road, Palo Alto, CA 94303, USA +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1, as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, +# MA 02111-1307 USA +# +# +# Sun Industry Standards Source License Version 1.1 +# ================================================= +# The contents of this file are subject to the Sun Industry Standards +# Source License Version 1.1 (the "License"); You may not use this file +# except in compliance with the License. You may obtain a copy of the +# License at http://www.openoffice.org/license.html. +# +# Software provided under this License is provided on an "AS IS" basis, +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, +# MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. +# See the License for the specific provisions governing your rights and +# obligations concerning the Software. +# +# The Initial Developer of the Original Code is: Sun Microsystems, Inc. +# +# Copyright: 2000 by Sun Microsystems, Inc. +# +# All Rights Reserved. +# +# Contributor(s): _______________________________________ +# +# +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME= ucbhelper +TARGET= provider +AUTOSEG= TRUE + +ENABLE_EXCEPTIONS=TRUE + +# --- Settings ----------------------------------------------------- + +.INCLUDE : svpre.mk +.INCLUDE : settings.mk +.INCLUDE : sv.mk + +# --- Files -------------------------------------------------------- + +.IF "$(header)" == "" + +SLOFILES=\ + $(SLO)$/configureucb.obj \ + $(SLO)$/contentidentifier.obj \ + $(SLO)$/providerhelper.obj \ + $(SLO)$/contenthelper.obj \ + $(SLO)$/contentinfo.obj \ + $(SLO)$/propertyvalueset.obj \ + $(SLO)$/registerucb.obj \ + $(SLO)$/resultsetmetadata.obj \ + $(SLO)$/resultset.obj \ + $(SLO)$/resultsethelper.obj + +.ENDIF + +# --- Targets ------------------------------------------------------ + +.INCLUDE : target.mk + diff --git a/ucbhelper/source/provider/propertyvalueset.cxx b/ucbhelper/source/provider/propertyvalueset.cxx new file mode 100644 index 000000000000..db4bdf68f48b --- /dev/null +++ b/ucbhelper/source/provider/propertyvalueset.cxx @@ -0,0 +1,925 @@ +/************************************************************************* + * + * $RCSfile: propertyvalueset.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef __VECTOR__ +#include <stl/vector> +#endif + +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include <com/sun/star/beans/Property.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYACCESS_HPP_ +#include <com/sun/star/beans/XPropertyAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSET_HPP_ +#include <com/sun/star/beans/XPropertySet.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_ +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_SCRIPT_XTYPECONVERTER_HPP_ +#include <com/sun/star/script/XTypeConverter.hpp> +#endif + +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif + +#ifndef _UCBHELPER_PROPERTYVALUESET_HXX +#include <ucbhelper/propertyvalueset.hxx> +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::container; +using namespace com::sun::star::io; +using namespace com::sun::star::lang; +using namespace com::sun::star::script; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace rtl; +using namespace ucb; + +namespace ucb_impl +{ + +//========================================================================= +// +// PropertyValue. +// +//========================================================================= + +const sal_uInt32 NO_VALUE_SET = 0x00000000; +const sal_uInt32 STRING_VALUE_SET = 0x00000001; +const sal_uInt32 BOOLEAN_VALUE_SET = 0x00000002; +const sal_uInt32 BYTE_VALUE_SET = 0x00000004; +const sal_uInt32 SHORT_VALUE_SET = 0x00000008; +const sal_uInt32 INT_VALUE_SET = 0x00000010; +const sal_uInt32 LONG_VALUE_SET = 0x00000020; +const sal_uInt32 FLOAT_VALUE_SET = 0x00000040; +const sal_uInt32 DOUBLE_VALUE_SET = 0x00000080; +const sal_uInt32 BYTES_VALUE_SET = 0x00000100; +const sal_uInt32 DATE_VALUE_SET = 0x00000200; +const sal_uInt32 TIME_VALUE_SET = 0x00000400; +const sal_uInt32 TIMESTAMP_VALUE_SET = 0x00000800; +const sal_uInt32 BINARYSTREAM_VALUE_SET = 0x00001000; +const sal_uInt32 CHARACTERSTREAM_VALUE_SET = 0x00002000; +const sal_uInt32 REF_VALUE_SET = 0x00004000; +const sal_uInt32 BLOB_VALUE_SET = 0x00008000; +const sal_uInt32 CLOB_VALUE_SET = 0x00010000; +const sal_uInt32 ARRAY_VALUE_SET = 0x00020000; +const sal_uInt32 OBJECT_VALUE_SET = 0x00040000; + +struct PropertyValue +{ + Property aProperty; + + sal_uInt32 nPropsSet; + sal_uInt32 nOrigValue; + + OUString aString; // getString + sal_Bool bBoolean; // getBoolean + sal_Int8 nByte; // getByte + sal_Int16 nShort; // getShort + sal_Int32 nInt; // getInt + sal_Int64 nLong; // getLong + float nFloat; // getFloat + double nDouble; // getDouble + + Sequence< sal_Int8 > aBytes; // getBytes + Date aDate; // getDate + Time aTime; // getTime + DateTime aTimestamp; // getTimestamp + Reference< XInputStream > xBinaryStream; // getBinaryStream + Reference< XInputStream > xCharacterStream; // getCharacterStream + Reference< XRef > xRef; // getRef + Reference< XBlob > xBlob; // getBlob + Reference< XClob > xClob; // getClob + Reference< XArray > xArray; // getArray + Any aObject; // getObject + + inline PropertyValue() + : nPropsSet( NO_VALUE_SET ), nOrigValue( NO_VALUE_SET ) {} +}; + +} // namespace ucb_impl + +using namespace ucb_impl; + +namespace ucb +{ + +//========================================================================= +// +// class PropertyValues. +// +//========================================================================= + +typedef std::vector< ucb_impl::PropertyValue > PropertyValuesVector; + +class PropertyValues : public PropertyValuesVector {}; + +} // namespace ucb + +//========================================================================= +// +// Welcome to the macro hell... +// +//========================================================================= + +#define GETVALUE_IMPL_TYPE( _type_, _type_name_, _member_name_, _cppu_type_ ) \ + \ + vos::OGuard aGuard( m_aMutex ); \ + \ + _type_ aValue = _type_(); /* default ctor */ \ + \ + m_bWasNull = sal_True; \ + \ + if ( ( columnIndex < 1 ) || ( columnIndex > m_pValues->size() ) ) \ + { \ + VOS_ENSURE( sal_False, "PropertyValueSet - index out of range!" ); \ + } \ + else \ + { \ + ucb_impl::PropertyValue& rValue = (*m_pValues)[ columnIndex - 1 ]; \ + \ + if ( rValue.nOrigValue != NO_VALUE_SET ) \ + { \ + if ( rValue.nPropsSet & _type_name_ ) \ + { \ + /* Values is present natively... */ \ + aValue = rValue._member_name_; \ + m_bWasNull = sal_False; \ + } \ + else \ + { \ + if ( !(rValue.nPropsSet & OBJECT_VALUE_SET) ) \ + { \ + /* Value is not (yet) available as Any. Create it. */ \ + getObject( columnIndex, Reference< XNameAccess >() ); \ + } \ + \ + if ( rValue.nPropsSet & OBJECT_VALUE_SET ) \ + { \ + /* Value is available as Any. */ \ + \ + /* Try to convert into native value. */ \ + if ( rValue.aObject >>= aValue ) \ + { \ + rValue._member_name_ = aValue; \ + rValue.nPropsSet |= _type_name_; \ + m_bWasNull = sal_False; \ + } \ + else \ + { \ + /* Last chance. Try type converter service... */ \ + \ + Reference< XTypeConverter > xConverter \ + = getTypeConverter(); \ + if ( xConverter.is() ) \ + { \ + try \ + { \ + Any aConvAny = xConverter->convertTo( \ + rValue.aObject, \ + _cppu_type_ ); \ + \ + if ( aConvAny >>= aValue ) \ + { \ + rValue._member_name_ = aValue; \ + rValue.nPropsSet |= _type_name_; \ + m_bWasNull = sal_False; \ + } \ + } \ + catch ( IllegalArgumentException ) \ + { \ + } \ + catch ( CannotConvertException ) \ + { \ + } \ + } \ + } \ + } \ + } \ + } \ + } \ + return aValue; + +#define GETVALUE_IMPL( _type_, _type_name_, _member_name_ ) \ + GETVALUE_IMPL_TYPE( _type_, \ + _type_name_, \ + _member_name_, \ + getCppuType( static_cast< const _type_ * >( 0 ) ) ) + +#define SETVALUE_IMPL( _property_, _type_name_, _member_name_, _value_ ) \ + \ + vos::OGuard aGuard( m_aMutex ); \ + \ + ucb_impl::PropertyValue aNewValue; \ + aNewValue.aProperty = _property_; \ + aNewValue.nPropsSet = _type_name_; \ + aNewValue.nOrigValue = _type_name_; \ + aNewValue._member_name_ = _value_; \ + \ + m_pValues->push_back( aNewValue ); + +//========================================================================= +//========================================================================= +// +// PropertyValueSet Implementation. +// +//========================================================================= +//========================================================================= + +PropertyValueSet::PropertyValueSet( + const Reference< XMultiServiceFactory >& rxSMgr ) +: m_xSMgr( rxSMgr ), + m_bWasNull( sal_False ), + m_bTriedToGetTypeConverter( sal_False ) +{ + m_pValues = new PropertyValues; +} + +//========================================================================= +// virtual +PropertyValueSet::~PropertyValueSet() +{ + delete m_pValues; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_3( PropertyValueSet, + XTypeProvider, + XRow, + XColumnLocate ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_3( PropertyValueSet, + XTypeProvider, + XRow, + XColumnLocate ); + +//========================================================================= +// +// XRow methods. +// +//========================================================================= + +// virtual +sal_Bool SAL_CALL PropertyValueSet::wasNull() + throw( SQLException, RuntimeException ) +{ + // This method can not be implemented correctly!!! Imagine different + // threads doing a getXYZ - wasNull calling sequence on the same + // implementation object... + return m_bWasNull; +} + +//========================================================================= +// virtual +OUString SAL_CALL PropertyValueSet::getString( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( OUString, STRING_VALUE_SET, aString ); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL PropertyValueSet::getBoolean( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL_TYPE( + sal_Bool, BOOLEAN_VALUE_SET, bBoolean, getCppuBooleanType() ); +} + +//========================================================================= +// virtual +sal_Int8 SAL_CALL PropertyValueSet::getByte( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( sal_Int8, BYTE_VALUE_SET, nByte ); +} + +//========================================================================= +// virtual +sal_Int16 SAL_CALL PropertyValueSet::getShort( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( sal_Int16, SHORT_VALUE_SET, nShort ); +} + +//========================================================================= +// virtual +sal_Int32 SAL_CALL PropertyValueSet::getInt( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( sal_Int32, INT_VALUE_SET, nInt ); +} + +//========================================================================= +// virtual +sal_Int64 SAL_CALL PropertyValueSet::getLong( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( sal_Int64, LONG_VALUE_SET, nLong ); +} + +//========================================================================= +// virtual +float SAL_CALL PropertyValueSet::getFloat( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( float, FLOAT_VALUE_SET, nFloat ); +} + +//========================================================================= +// virtual +double SAL_CALL PropertyValueSet::getDouble( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( double, DOUBLE_VALUE_SET, nDouble ); +} + +//========================================================================= +// virtual +Sequence< sal_Int8 > SAL_CALL +PropertyValueSet::getBytes( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( Sequence< sal_Int8 >, BYTES_VALUE_SET, aBytes ); +} + +//========================================================================= +// virtual +Date SAL_CALL PropertyValueSet::getDate( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( Date, DATE_VALUE_SET, aDate ); +} + +//========================================================================= +// virtual +Time SAL_CALL PropertyValueSet::getTime( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( Time, TIME_VALUE_SET, aTime ); +} + +//========================================================================= +// virtual +DateTime SAL_CALL PropertyValueSet::getTimestamp( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( DateTime, TIMESTAMP_VALUE_SET, aTimestamp ); +} + +//========================================================================= +// virtual +Reference< XInputStream > SAL_CALL +PropertyValueSet::getBinaryStream( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( + Reference< XInputStream >, BINARYSTREAM_VALUE_SET, xBinaryStream ); +} + +//========================================================================= +// virtual +Reference< XInputStream > SAL_CALL +PropertyValueSet::getCharacterStream( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( + Reference< XInputStream >, CHARACTERSTREAM_VALUE_SET, xCharacterStream ); +} + +//========================================================================= +// virtual +Any SAL_CALL PropertyValueSet::getObject( + sal_Int32 columnIndex, + const Reference< XNameAccess >& typeMap ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + Any aValue; + + m_bWasNull = sal_True; + + if ( ( columnIndex < 1 ) || ( columnIndex > m_pValues->size() ) ) + { + VOS_ENSURE( sal_False, "PropertyValueSet - index out of range!" ); + } + else + { + ucb_impl::PropertyValue& rValue = (*m_pValues)[ columnIndex - 1 ]; + + if ( rValue.nPropsSet & OBJECT_VALUE_SET ) + { + // Values is present natively... + aValue = rValue.aObject; + m_bWasNull = sal_False; + } + else + { + // Make Any from original value. + + switch ( rValue.nOrigValue ) + { + case NO_VALUE_SET: + break; + + case STRING_VALUE_SET: + aValue <<= rValue.aString; + break; + + case BOOLEAN_VALUE_SET: + aValue <<= rValue.bBoolean; + break; + + case BYTE_VALUE_SET: + aValue <<= rValue.nByte; + break; + + case SHORT_VALUE_SET: + aValue <<= rValue.nShort; + break; + + case INT_VALUE_SET: + aValue <<= rValue.nInt; + break; + + case LONG_VALUE_SET: + aValue <<= rValue.nLong; + break; + + case FLOAT_VALUE_SET: + aValue <<= rValue.nFloat; + break; + + case DOUBLE_VALUE_SET: + aValue <<= rValue.nDouble; + break; + + case BYTES_VALUE_SET: + aValue <<= rValue.aBytes; + break; + + case DATE_VALUE_SET: + aValue <<= rValue.aDate; + break; + + case TIME_VALUE_SET: + aValue <<= rValue.aTime; + break; + + case TIMESTAMP_VALUE_SET: + aValue <<= rValue.aTimestamp; + break; + + case BINARYSTREAM_VALUE_SET: + aValue <<= rValue.xBinaryStream; + break; + + case CHARACTERSTREAM_VALUE_SET: + aValue <<= rValue.xCharacterStream; + break; + + case REF_VALUE_SET: + aValue <<= rValue.xRef; + break; + + case BLOB_VALUE_SET: + aValue <<= rValue.xBlob; + break; + + case CLOB_VALUE_SET: + aValue <<= rValue.xClob; + break; + + case ARRAY_VALUE_SET: + aValue <<= rValue.xArray; + break; + + case OBJECT_VALUE_SET: + // Fall-through is intended! + default: + VOS_ENSURE( sal_False, + "PropertyValueSet::getObject - " + "Wrong original type" ); + break; + } + + if ( aValue.hasValue() ) + { + rValue.aObject = aValue; + rValue.nPropsSet |= OBJECT_VALUE_SET; + m_bWasNull = sal_False; + } + } + } + + return aValue; +} + +//========================================================================= +// virtual +Reference< XRef > SAL_CALL PropertyValueSet::getRef( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( Reference< XRef >, REF_VALUE_SET, xRef ); +} + +//========================================================================= +// virtual +Reference< XBlob > SAL_CALL PropertyValueSet::getBlob( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( Reference< XBlob >, BLOB_VALUE_SET, xBlob ); +} + +//========================================================================= +// virtual +Reference< XClob > SAL_CALL PropertyValueSet::getClob( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( Reference< XClob >, CLOB_VALUE_SET, xClob ); +} + +//========================================================================= +// virtual +Reference< XArray > SAL_CALL PropertyValueSet::getArray( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + GETVALUE_IMPL( Reference< XArray >, ARRAY_VALUE_SET, xArray ); +} + +//========================================================================= +// +// XColumnLocate methods. +// +//========================================================================= + +// virtual +sal_Int32 SAL_CALL PropertyValueSet::findColumn( const OUString& columnName ) + throw( SQLException, RuntimeException ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( columnName.getLength() ) + { + sal_Int32 nCount = m_pValues->size(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + if ( (*m_pValues)[ n ].aProperty.Name.equals( columnName ) ) + return sal_Int32( n + 1 ); // Index is 1-based. + } + } + return 0; +} + +//========================================================================= +// +// Non-interface methods. +// +//========================================================================= + +const Reference< XTypeConverter >& PropertyValueSet::getTypeConverter() +{ + vos::OGuard aGuard( m_aMutex ); + + if ( !m_bTriedToGetTypeConverter && !m_xTypeConverter.is() ) + { + m_bTriedToGetTypeConverter = sal_True; + m_xTypeConverter = Reference< XTypeConverter >( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.script.Converter" ) ), + UNO_QUERY ); + + VOS_ENSURE( m_xTypeConverter.is(), + "PropertyValueSet::getTypeConverter() - " + "Service 'com.sun.star.script.Converter' n/a!" ); + } + return m_xTypeConverter; +} + +//========================================================================= +sal_Int32 PropertyValueSet::getLength() const +{ + return m_pValues->size(); +} + +//========================================================================= +void PropertyValueSet::appendString( const Property& rProp, + const OUString& rValue ) +{ + SETVALUE_IMPL( rProp, STRING_VALUE_SET, aString, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendBoolean( const Property& rProp, + sal_Bool bValue ) +{ + SETVALUE_IMPL( rProp, BOOLEAN_VALUE_SET, bBoolean, bValue ); +} + +//========================================================================= +void PropertyValueSet::appendByte( const Property& rProp, + sal_Int8 nValue ) +{ + SETVALUE_IMPL( rProp, BYTE_VALUE_SET, nByte, nValue ); +} + +//========================================================================= +void PropertyValueSet::appendShort( const Property& rProp, + sal_Int16 nValue ) +{ + SETVALUE_IMPL( rProp, SHORT_VALUE_SET, nShort, nValue ); +} + +//========================================================================= +void PropertyValueSet::appendInt( const Property& rProp, + sal_Int32 nValue ) +{ + SETVALUE_IMPL( rProp, INT_VALUE_SET, nInt, nValue ); +} + +//========================================================================= +void PropertyValueSet::appendLong( const Property& rProp, + sal_Int64 nValue ) +{ + SETVALUE_IMPL( rProp, LONG_VALUE_SET, nLong, nValue ); +} + +//========================================================================= +void PropertyValueSet::appendFloat( const Property& rProp, + float nValue ) +{ + SETVALUE_IMPL( rProp, FLOAT_VALUE_SET, nFloat, nValue ); +} + +//========================================================================= +void PropertyValueSet::appendDouble( const Property& rProp, + double nValue ) +{ + SETVALUE_IMPL( rProp, DOUBLE_VALUE_SET, nDouble, nValue ); +} + +//========================================================================= +void PropertyValueSet::appendBytes( const Property& rProp, + const Sequence< sal_Int8 >& rValue ) +{ + SETVALUE_IMPL( rProp, BYTES_VALUE_SET, aBytes, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendDate( const Property& rProp, + const Date& rValue ) +{ + SETVALUE_IMPL( rProp, DATE_VALUE_SET, aDate, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendTime( const Property& rProp, + const Time& rValue ) +{ + SETVALUE_IMPL( rProp, TIME_VALUE_SET, aTime, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendTimestamp( const Property& rProp, + const DateTime& rValue ) +{ + SETVALUE_IMPL( rProp, TIMESTAMP_VALUE_SET, aTimestamp, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendBinaryStream( + const Property& rProp, + const Reference< XInputStream >& rValue ) +{ + SETVALUE_IMPL( rProp, BINARYSTREAM_VALUE_SET, xBinaryStream, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendCharacterStream( + const Property& rProp, + const Reference< XInputStream >& rValue ) +{ + SETVALUE_IMPL( rProp, CHARACTERSTREAM_VALUE_SET, xCharacterStream, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendObject( const Property& rProp, + const Any& rValue ) +{ + SETVALUE_IMPL( rProp, OBJECT_VALUE_SET, aObject, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendRef( const Property& rProp, + const Reference< XRef >& rValue ) +{ + SETVALUE_IMPL( rProp, REF_VALUE_SET, xRef, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendBlob( const Property& rProp, + const Reference< XBlob >& rValue ) +{ + SETVALUE_IMPL( rProp, BLOB_VALUE_SET, xBlob, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendClob( const Property& rProp, + const Reference< XClob >& rValue ) +{ + SETVALUE_IMPL( rProp, CLOB_VALUE_SET, xClob, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendArray( const Property& rProp, + const Reference< XArray >& rValue ) +{ + SETVALUE_IMPL( rProp, ARRAY_VALUE_SET, xArray, rValue ); +} + +//========================================================================= +void PropertyValueSet::appendVoid( const Property& rProp ) +{ + SETVALUE_IMPL( rProp, NO_VALUE_SET, aObject, Any() ); +} + +//========================================================================= +void PropertyValueSet::appendPropertySet( + const Reference< XPropertySet >& rxSet ) +{ + if ( rxSet.is() ) + { + Reference< XPropertySetInfo > xInfo = rxSet->getPropertySetInfo(); + if ( xInfo.is() ) + { + Sequence< Property > aProps = xInfo->getProperties(); + const Property* pProps = aProps.getConstArray(); + sal_Int32 nPropsCount = aProps.getLength(); + + Reference< XPropertyAccess > xPropertyAccess( rxSet, UNO_QUERY ); + if ( xPropertyAccess.is() ) + { + // Efficient: Get all prop values with one ( remote) call. + + Sequence< ::com::sun::star::beans::PropertyValue > aPropValues + = xPropertyAccess->getPropertyValues(); + + const ::com::sun::star::beans::PropertyValue* pPropValues + = aPropValues.getConstArray(); + + sal_Int32 nValuesCount = aPropValues.getLength(); + for ( sal_Int32 n = 0; n < nValuesCount; ++n ) + { + const ::com::sun::star::beans::PropertyValue& rPropValue + = pPropValues[ n ]; + + // Find info for current property value. + for ( sal_Int32 m = 0; m < nPropsCount; ++m ) + { + const Property& rProp = pProps[ m ]; + if ( rProp.Name == rPropValue.Name ) + { + // Found! + appendObject( rProp, rPropValue.Value ); + break; + } + } + } + } + else + { + // Get every single prop value with one ( remote) call. + + for ( sal_Int32 n = 0; n < nPropsCount; ++n ) + { + const Property& rProp = pProps[ n ]; + + try + { + Any aValue = rxSet->getPropertyValue( rProp.Name ); + + if ( aValue.hasValue() ) + appendObject( rProp, aValue ); + } + catch ( UnknownPropertyException ) + { + } + catch ( WrappedTargetException ) + { + } + } + } + } + } +} + +//========================================================================= +sal_Bool PropertyValueSet::appendPropertySetValue( + const Reference< XPropertySet >& rxSet, + const Property& rProperty ) +{ + if ( rxSet.is() ) + { + try + { + Any aValue = rxSet->getPropertyValue( rProperty.Name ); + if ( aValue.hasValue() ) + { + appendObject( rProperty, aValue ); + return sal_True; + } + } + catch ( UnknownPropertyException ) + { + } + catch ( WrappedTargetException ) + { + } + } + + // Error. + return sal_False; +} + diff --git a/ucbhelper/source/provider/providerhelper.cxx b/ucbhelper/source/provider/providerhelper.cxx new file mode 100644 index 000000000000..2d646f2943b8 --- /dev/null +++ b/ucbhelper/source/provider/providerhelper.cxx @@ -0,0 +1,614 @@ +/************************************************************************* + * + * $RCSfile: providerhelper.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef __HASH_MAP__ +#include <stl/hash_map> +#endif +#ifndef _OSL_FILE_HXX_ +#include <osl/file.hxx> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMEACCESS_HPP_ +#include <com/sun/star/container/XNameAccess.hpp> +#endif +#ifndef _COM_SUN_STAR_CONTAINER_XNAMED_HPP_ +#include <com/sun/star/container/XNamed.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROPERTYSETREGISTRYFACTORY_HPP_ +#include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPROPERTYSETREGISTRY_HPP_ +#include <com/sun/star/ucb/XPropertySetRegistry.hpp> +#endif +#ifndef _COM_SUN_STAR_REGISTRY_XSIMPLEREGISTRY_HPP_ +#include <com/sun/star/registry/XSimpleRegistry.hpp> +#endif +#ifndef _COM_SUN_STAR_FRAME_XCONFIGMANAGER_HPP_ +#include <com/sun/star/frame/XConfigManager.hpp> +#endif +#ifndef _VOS_DIAGNOSE_HXX_ +#include <vos/diagnose.hxx> +#endif +#ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX +#include <ucbhelper/contentidentifier.hxx> +#endif +#ifndef _UCBHELPER_PROVIDERHELPER_HXX +#include <ucbhelper/providerhelper.hxx> +#endif +#ifndef _UCBHELPER_CONTENTHELPER_HXX +#include <ucbhelper/contenthelper.hxx> +#endif + +#define PROPSET_REGISTRY_FILE_NAME "dynprops.rdb" + +using namespace rtl; +using namespace com::sun::star::container; +using namespace com::sun::star::frame; +using namespace com::sun::star::lang; +using namespace com::sun::star::registry; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace ucb; + +namespace ucb_impl +{ + +//========================================================================= +// +// Contents. +// +//========================================================================= + +struct equalString +{ + bool operator()( const OUString& rKey11, const OUString& rKey22 ) const + { + return !!( rKey11 == rKey22 ); + } +}; + +struct hashString +{ + size_t operator()( const OUString & rName ) const + { + return rName.hashCode(); + } +}; + +typedef std::hash_map +< + OUString, + ContentImplHelper*, + hashString, + equalString +> +Contents; + +//========================================================================= +// +// struct ContentProviderImplHelper_Impl. +// +//========================================================================= + +struct ContentProviderImplHelper_Impl +{ + Reference< XPropertySetRegistry > m_xPropertySetRegistry; + Contents m_aContents; +}; + +} // namespace ucb_impl + +using namespace ucb_impl; + +//========================================================================= +//========================================================================= +// +// ContentProviderImplHelper Implementation. +// +//========================================================================= +//========================================================================= + +ContentProviderImplHelper::ContentProviderImplHelper( + const Reference< XMultiServiceFactory >& rXSMgr ) +: m_xSMgr( rXSMgr ), + m_pImpl( new ucb_impl::ContentProviderImplHelper_Impl ) +{ +} + +//========================================================================= +// virtual +ContentProviderImplHelper::~ContentProviderImplHelper() +{ + delete m_pImpl; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_3( ContentProviderImplHelper, + XTypeProvider, + XServiceInfo, + XContentProvider ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_3( ContentProviderImplHelper, + XTypeProvider, + XServiceInfo, + XContentProvider ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +/* + + Pure virtual. Must be implemented by derived classes! + +// virtual +OUString SAL_CALL ContentProviderImplHelper::getImplementationName() + throw( RuntimeException ) +{ +} + +//========================================================================= +// virtual +::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL +ContentProviderImplHelper::getSupportedServiceNames() + throw( RuntimeException ) +{ +} + +*/ + +//========================================================================= +// virtual +sal_Bool SAL_CALL ContentProviderImplHelper::supportsService( + const OUString& ServiceName ) + throw( RuntimeException ) +{ + Sequence< OUString > aSNL = getSupportedServiceNames(); + const OUString* pArray = aSNL.getConstArray(); + for ( sal_Int32 i = 0; i < aSNL.getLength(); i++ ) + { + if ( pArray[ i ] == ServiceName ) + return sal_True; + } + + return sal_False; +} + +//========================================================================= +// +// XContentProvider methods. +// +//========================================================================= + +/* + + Pure virtual. Must be implemented by derived classes! + +// virtual +Reference< XContent > SAL_CALL ContentProviderImplHelper::queryContent( + const Reference< XContentIdentifier >& Identifier ) + throw( IllegalIdentifierException, RuntimeException ) +{ +} + +*/ + +//========================================================================= +// virtual +sal_Int32 SAL_CALL ContentProviderImplHelper::compareContentIds( + const Reference< XContentIdentifier >& Id1, + const Reference< XContentIdentifier >& Id2 ) + throw( RuntimeException ) +{ + // Simply do a string compare. + + OUString aURL1( Id1->getContentIdentifier() ); + OUString aURL2( Id2->getContentIdentifier() ); + + return aURL1.compareTo( aURL2 );; +} + +//========================================================================= +// +// Non-interface methods +// +//========================================================================= + +void ContentProviderImplHelper::addContent( + ::ucb::ContentImplHelper* pContent ) +{ + vos::OGuard aGuard( m_aMutex ); + + const OUString aURL( pContent->getIdentifier()->getContentIdentifier() ); + +#ifdef _DEBUG + Contents::const_iterator it = m_pImpl->m_aContents.find( aURL ); + VOS_ENSURE( it == m_pImpl->m_aContents.end(), + "ContentProviderImplHelper::addContent - Already registered!" ); +#endif + + m_pImpl->m_aContents[ aURL ] = pContent; +} + +//========================================================================= +void ContentProviderImplHelper::removeContent( + ::ucb::ContentImplHelper* pContent ) +{ + vos::OGuard aGuard( m_aMutex ); + + const OUString aURL( pContent->getIdentifier()->getContentIdentifier() ); + removeContent( aURL ); +} + +//========================================================================= +void ContentProviderImplHelper::removeContent( const OUString& rURL ) +{ + vos::OGuard aGuard( m_aMutex ); + + Contents::iterator it = m_pImpl->m_aContents.find( rURL ); + +// VOS_ENSURE( it != m_pImpl->m_aContents.end(), +// "ContentProviderImplHelper::removeContent - Not registered!" ); + + if ( it != m_pImpl->m_aContents.end() ) + m_pImpl->m_aContents.erase( it ); +} + +//========================================================================= +vos::ORef< ContentImplHelper > +ContentProviderImplHelper::queryExistingContent( + const Reference< XContentIdentifier >& Identifier ) +{ + return queryExistingContent( Identifier->getContentIdentifier() ); +} + +//========================================================================= +vos::ORef< ContentImplHelper > +ContentProviderImplHelper::queryExistingContent( const OUString& rURL ) +{ + vos::OGuard aGuard( m_aMutex ); + + // Check, if a content with given id already exists... + + Contents::const_iterator it = m_pImpl->m_aContents.find( rURL ); + if ( it != m_pImpl->m_aContents.end() ) + { + // Already there. Return it. + return vos::ORef< ContentImplHelper >( (*it).second ); + } + + return vos::ORef< ContentImplHelper >(); +} + +//========================================================================= +void ContentProviderImplHelper::queryExistingContents( + ContentRefList& rContents ) +{ + vos::OGuard aGuard( m_aMutex ); + + Contents::const_iterator it = m_pImpl->m_aContents.begin(); + Contents::const_iterator end = m_pImpl->m_aContents.end(); + + while ( it != end ) + { + rContents.push_back( ContentImplHelperRef( (*it).second ) ); + ++it; + } +} + +//========================================================================= +Reference< XPropertySetRegistry > +ContentProviderImplHelper::getAdditionalPropertySetRegistry() +{ + // Get propertyset registry. + + vos::OGuard aGuard( m_aMutex ); + + if ( !m_pImpl->m_xPropertySetRegistry.is() ) + { + Reference< XPropertySetRegistryFactory > xRegFac( + m_xSMgr->createInstance( + OUString::createFromAscii( "com.sun.star.ucb.Store" ) ), + UNO_QUERY ); + + VOS_ENSURE( xRegFac.is(), + "ContentProviderImplHelper::getAdditionalPropertySet - " + "No UCB-Store service!" ); + + Reference< XSimpleRegistry > xCfgReg( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.config.SpecialConfigManager" ) ), + UNO_QUERY ); + + VOS_ENSURE( xCfgReg.is(), + "ContentProviderImplHelper::getAdditionalPropertySet - " + "No ConfigManager service!" ); + + Reference< XConfigManager > xCfgMgr; + if ( xCfgReg.is() ) + xCfgMgr = Reference< XConfigManager >( xCfgReg, UNO_QUERY ); + + VOS_ENSURE( xCfgMgr.is(), + "ContentProviderImplHelper::getAdditionalPropertySet - " + "No XConfigManager!" ); + + if ( xRegFac.is() && xCfgReg.is() && xCfgMgr.is() ) + { + OUString aRegURL; + + try + { + Reference< XRegistryKey > xRegistryKey( xCfgReg->getRootKey() ); + if ( xRegistryKey.is() ) + xRegistryKey = xRegistryKey->openKey( + OUString::createFromAscii( "Directories/Storage-Dir") ); + + if ( xRegistryKey.is() ) + aRegURL = xRegistryKey->getStringValue(); + } + catch ( InvalidRegistryException& ) + { + } + + aRegURL = xCfgMgr->substituteVariables( aRegURL ); + + VOS_ENSURE( aRegURL.getLength(), + "ContentProviderImplHelper::getAdditionalPropertySet - " + "Unable to get Store-directory!" ); + + if ( aRegURL.getLength() ) + { + // Convert path to a URL. + OUString aUNCPath; + osl::FileBase::RC + eErr = osl::FileBase::normalizePath( aRegURL, aUNCPath ); + + if ( eErr == osl::FileBase::E_None ) + { + eErr = osl::FileBase::getFileURLFromNormalizedPath( + aUNCPath, aRegURL ); + if ( eErr == osl::FileBase::E_None ) + { + OUString aLastChar( + aRegURL.copy( aRegURL.getLength() - 1 ) ); + OUString aTmpOWStr = OUString::createFromAscii ( "/" ); + if ( aLastChar != aTmpOWStr ) + aRegURL += aTmpOWStr; + + aRegURL += OUString::createFromAscii( + PROPSET_REGISTRY_FILE_NAME ); + + // Open/create a registry. + m_pImpl->m_xPropertySetRegistry + = xRegFac->createPropertySetRegistry( aRegURL ); + } + } + + VOS_ENSURE( m_pImpl->m_xPropertySetRegistry.is(), + "ContentProviderImplHelper::getAdditionalPropertySet - " + "Error opening registry!" ); + } + } + } + + return m_pImpl->m_xPropertySetRegistry; +} + + +//========================================================================= +Reference< XPersistentPropertySet > +ContentProviderImplHelper::getAdditionalPropertySet( const OUString& rKey, + sal_Bool bCreate ) +{ + // Get propertyset registry. + getAdditionalPropertySetRegistry(); + + if ( m_pImpl->m_xPropertySetRegistry.is() ) + { + // Open/create persistent property set. + return Reference< XPersistentPropertySet >( + m_pImpl->m_xPropertySetRegistry->openPropertySet( + rKey, bCreate ) ); + } + + return Reference< XPersistentPropertySet >(); +} + +//========================================================================= +sal_Bool ContentProviderImplHelper::renameAdditionalPropertySet( + const OUString& rOldKey, + const OUString& rNewKey, + sal_Bool bRecursive ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( bRecursive ) + { + // Get propertyset registry. + getAdditionalPropertySetRegistry(); + + if ( m_pImpl->m_xPropertySetRegistry.is() ) + { + Reference< XNameAccess > xNameAccess( + m_pImpl->m_xPropertySetRegistry, UNO_QUERY ); + if ( xNameAccess.is() ) + { + Sequence< OUString > aKeys = xNameAccess->getElementNames(); + sal_Int32 nCount = aKeys.getLength(); + if ( nCount > 0 ) + { + const OUString* pKeys = aKeys.getConstArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const OUString& rKey = pKeys[ n ]; + if ( rKey.compareTo( + rOldKey, rOldKey.getLength() ) == 0 ) + { + OUString aNewKey + = rKey.replaceAt( + 0, rOldKey.getLength(), rNewKey ); + if ( !renameAdditionalPropertySet( + rKey, aNewKey, sal_False ) ) + return sal_False; + } + } + } + } + else + return sal_False; + } + else + return sal_False; + } + else + { + // Get old property set, if exists. + Reference< XPersistentPropertySet > xOldSet + = getAdditionalPropertySet( rOldKey, sal_False ); + if ( xOldSet.is() ) + { + // Rename property set. + Reference< XNamed > xNamed( xOldSet, UNO_QUERY ); + if ( xNamed.is() ) + { + // ??? throws no exceptions and has no return value ??? + xNamed->setName( rNewKey ); + } + else + return sal_False; + } + } + return sal_True; +} + +//========================================================================= +sal_Bool ContentProviderImplHelper::removeAdditionalPropertySet( + const OUString& rKey, + sal_Bool bRecursive ) +{ + vos::OGuard aGuard( m_aMutex ); + + if ( bRecursive ) + { + // Get propertyset registry. + getAdditionalPropertySetRegistry(); + + if ( m_pImpl->m_xPropertySetRegistry.is() ) + { + Reference< XNameAccess > xNameAccess( + m_pImpl->m_xPropertySetRegistry, UNO_QUERY ); + if ( xNameAccess.is() ) + { + Sequence< OUString > aKeys = xNameAccess->getElementNames(); + sal_Int32 nCount = aKeys.getLength(); + if ( nCount > 0 ) + { + const OUString* pKeys = aKeys.getConstArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + const OUString& rCurrKey = pKeys[ n ]; + if ( rCurrKey.compareTo( rKey, rKey.getLength() ) == 0 ) + { + if ( !removeAdditionalPropertySet( + rCurrKey, sal_False ) ) + return sal_False; + } + } + } + } + else + return sal_False; + } + else + return sal_False; + } + else + { + // Get propertyset registry. + getAdditionalPropertySetRegistry(); + + if ( m_pImpl->m_xPropertySetRegistry.is() ) + m_pImpl->m_xPropertySetRegistry->removePropertySet( rKey ); + else + return sal_False; + } + return sal_True; +} + diff --git a/ucbhelper/source/provider/registerucb.cxx b/ucbhelper/source/provider/registerucb.cxx new file mode 100644 index 000000000000..a86aa199427e --- /dev/null +++ b/ucbhelper/source/provider/registerucb.cxx @@ -0,0 +1,249 @@ +/************************************************************************* + * + * $RCSfile: registerucb.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +#ifndef _UCBHELPER_REGISTERUCB_HXX_ +#include <ucbhelper/registerucb.hxx> +#endif + +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_CONTENTPROVIDERSERVICEINFO2_HPP_ +#include <com/sun/star/ucb/ContentProviderServiceInfo2.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERMANAGER_HPP_ +#include <com/sun/star/ucb/XContentProviderManager.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XPARAMETERIZEDCONTENTPROVIDER_HPP_ +#include <com/sun/star/ucb/XParameterizedContentProvider.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCONTENTPROVIDERFACTORY_HPP_ +#include <com/sun/star/ucb/XContentProviderFactory.hpp> +#endif + +using namespace com::sun; +using namespace com::sun::star; + +//============================================================================ +// +// registerAtUcb +// +//============================================================================ + +namespace ucb { + +void +registerAtUcb( + uno::Reference< star::ucb::XContentProviderManager > const & rUcb, + uno::Reference< lang::XMultiServiceFactory > const & rFactory, + uno::Sequence< star::ucb::ContentProviderServiceInfo2 > const & + rProviders, + std::vector< ContentProviderRegistrationInfo > * pResults) + throw (uno::RuntimeException) +{ + uno::Reference< star::ucb::XContentProviderFactory > xFac; + try + { + xFac = uno::Reference< star::ucb::XContentProviderFactory >( + rFactory->createInstance( + rtl::OUString::createFromAscii( + "com.sun.star.ucb.ContentProviderProxyFactory")), + uno::UNO_QUERY); + } + catch (uno::RuntimeException const &) { throw; } + catch (uno::Exception const &) {} + + star::ucb::ContentProviderServiceInfo2 const * pInfo + = rProviders.getConstArray(); + for (sal_Int32 n = rProviders.getLength(); n > 0; --n) + { + uno::Reference< star::ucb::XContentProvider > xProvider; + if (xFac.is()) + { + // Try to instantiate proxy for provider. + xProvider = xFac->createContentProvider(pInfo->Service); + } + + if (!xProvider.is()) + { + // Try to instantiate provider directly. + try + { + xProvider = uno::Reference< star::ucb::XContentProvider >( + rFactory->createInstance(pInfo->Service), + uno::UNO_QUERY); + } + catch (uno::RuntimeException const &) { throw; } + catch (uno::Exception const &) {} + } + + uno::Reference< star::ucb::XContentProvider > + xOriginalProvider(xProvider); + uno::Reference< star::ucb::XParameterizedContentProvider > + xParameterized(xProvider, uno::UNO_QUERY); + if (xParameterized.is()) + { + uno::Reference< star::ucb::XContentProvider > xInstance; + try + { + xInstance + = xParameterized->registerInstance(pInfo->Scheme, + pInfo->Arguments, + pInfo-> + ReplaceExisting); + //@@@ if this call replaces an old instance, the commit- + // or-rollback code below will not work + } + catch (lang::IllegalArgumentException const &) {} + + if (xInstance.is()) + xProvider = xInstance; + } + + if (rUcb.is() && xProvider.is()) + try + { + rUcb->registerContentProvider(xProvider, pInfo->Scheme, + pInfo->ReplaceExisting); + } + catch (star::ucb::DuplicateProviderException const &) + { + if (xParameterized.is()) + try + { + xParameterized->deregisterInstance(pInfo->Scheme, + pInfo->Arguments); + } + catch (lang::IllegalArgumentException const &) {} + xOriginalProvider = 0; + } + catch (...) + { + if (xParameterized.is()) + try + { + xParameterized->deregisterInstance(pInfo->Scheme, + pInfo->Arguments); + } + catch (lang::IllegalArgumentException const &) {} + throw; + } + + if (pResults) + pResults-> + push_back(ContentProviderRegistrationInfo(xOriginalProvider, + pInfo->Arguments, + pInfo->Scheme)); + + ++pInfo; + } +} + +//============================================================================ +// +// deregisterFromUcb +// +//============================================================================ + +void +deregisterFromUcb( + uno::Reference< star::ucb::XContentProviderManager > const & rUcb, + std::vector< ContentProviderRegistrationInfo > const & rProviders) + throw (uno::RuntimeException) +{ + std::vector< ContentProviderRegistrationInfo >::const_iterator + aEnd(rProviders.end()); + for (std::vector< ContentProviderRegistrationInfo >::const_iterator + aIt(rProviders.begin()); + aIt != aEnd; ++aIt) + { + uno::Reference< star::ucb::XContentProvider > + xProvider(aIt->m_xProvider); + if (xProvider.is()) + { + uno::Reference< star::ucb::XParameterizedContentProvider > + xParameterized(xProvider, uno::UNO_QUERY); + if (xParameterized.is()) + { + uno::Reference< star::ucb::XContentProvider > xInstance; + try + { + xInstance + = xParameterized-> + deregisterInstance(aIt->m_aTemplate, + aIt->m_aArguments); + } + catch (lang::IllegalArgumentException const &) {} + + if (xInstance.is()) + xProvider = xInstance; + } + + if (rUcb.is() && xProvider.is()) + rUcb->deregisterContentProvider(xProvider, aIt->m_aTemplate); + //@@@ if this fails, a roll-back of deregisterInstance() + // is missing + } + } +} + +} + diff --git a/ucbhelper/source/provider/resultset.cxx b/ucbhelper/source/provider/resultset.cxx new file mode 100644 index 000000000000..38fba0cd09b4 --- /dev/null +++ b/ucbhelper/source/provider/resultset.cxx @@ -0,0 +1,1706 @@ +/************************************************************************* + * + * $RCSfile: resultset.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + *************************************************************************/ + +#ifndef __HASH_MAP__ +#include <stl/hash_map> +#endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif +#ifndef _COM_SUN_STAR_BEANS_PROPERTYATTRIBUTE_HPP_ +#include <com/sun/star/beans/PropertyAttribute.hpp> +#endif +#ifndef _UCBHELPER_RESULTSET_HXX +#include <ucbhelper/resultset.hxx> +#endif +#ifndef _UCBHELPER_RESULTSETMETADATA_HXX +#include <ucbhelper/resultsetmetadata.hxx> +#endif + +using namespace cppu; +using namespace com::sun::star::beans; +using namespace com::sun::star::container; +using namespace com::sun::star::io; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace rtl; +using namespace ucb; + +//========================================================================= + +namespace ucb_impl +{ + +struct PropertyInfo +{ + const char* pName; + sal_Int32 nHandle; + sal_Int16 nAttributes; + const com::sun::star::uno::Type& (*pGetCppuType)(); +}; + +static const com::sun::star::uno::Type& sal_uInt32_getCppuType() +{ + // ! uInt -> Int, because of Java !!! + return getCppuType( static_cast< const sal_Int32 * >( 0 ) ); +} + +static const com::sun::star::uno::Type& sal_Bool_getCppuType() +{ + return getCppuBooleanType(); +} + +static PropertyInfo aPropertyTable[] = +{ + { "IsRowCountFinal", + 1000, + PropertyAttribute::BOUND | PropertyAttribute::READONLY, + &sal_Bool_getCppuType + }, + { "RowCount", + 1001, + PropertyAttribute::BOUND | PropertyAttribute::READONLY, + &sal_uInt32_getCppuType + }, + { 0, + 0, + 0, + 0 + } +}; + +#define RESULTSET_PROPERTY_COUNT 2 + +//========================================================================= +// +// class PropertySetInfo +// +//========================================================================= + +class PropertySetInfo : + public OWeakObject, public XTypeProvider, public XPropertySetInfo +{ + Reference< XMultiServiceFactory > m_xSMgr; + Sequence< Property >* m_pProps; + +private: + sal_Bool queryProperty( const rtl::OUString& aName, Property& rProp ); + +public: + PropertySetInfo( const Reference< XMultiServiceFactory >& rxSMgr, + const PropertyInfo* pProps, + sal_uInt32 nProps ); + virtual ~PropertySetInfo(); + + // XInterface + XINTERFACE_DECL() + + // XTypeProvider + XTYPEPROVIDER_DECL() + + // XPropertySetInfo + virtual Sequence< Property > SAL_CALL getProperties() + throw( RuntimeException ); + virtual Property SAL_CALL getPropertyByName( const rtl::OUString& aName ) + throw( UnknownPropertyException, RuntimeException ); + virtual sal_Bool SAL_CALL hasPropertyByName( const rtl::OUString& Name ) + throw( RuntimeException ); +}; + +//========================================================================= +// +// PropertyChangeListenerContainer. +// +//========================================================================= + +struct equalStr_Impl +{ + bool operator()( const OUString& s1, const OUString& s2 ) const + { + return !!( s1 == s2 ); + } +}; + +struct hashStr_Impl +{ + size_t operator()( const OUString& rName ) const + { + return rName.hashCode(); + } +}; + +typedef OMultiTypeInterfaceContainerHelperVar +< + OUString, + hashStr_Impl, + equalStr_Impl +> PropertyChangeListenerContainer; + +//========================================================================= +// +// class PropertyChangeListeners. +// +//========================================================================= + +class PropertyChangeListeners : public PropertyChangeListenerContainer +{ +public: + PropertyChangeListeners( osl::Mutex& rMutex ) + : PropertyChangeListenerContainer( rMutex ) {} +}; + +} // namespace ucb_impl + +using namespace ucb_impl; + +namespace ucb +{ + +//========================================================================= +// +// struct ResultSet_Impl. +// +//========================================================================= + +struct ResultSet_Impl +{ + Reference< XMultiServiceFactory > m_xSMgr; + Reference< XPropertySetInfo > m_xPropSetInfo; + Reference< XResultSetMetaData > m_xMetaData; + Sequence< Property > m_aProperties; + vos::ORef< ResultSetDataSupplier > m_xDataSupplier; + osl::Mutex m_aMutex; + cppu::OInterfaceContainerHelper* m_pDisposeEventListeners; + PropertyChangeListeners* m_pPropertyChangeListeners; + sal_Int32 m_nPos; + sal_Bool m_bWasNull; + sal_Bool m_bAfterLast; + + inline ResultSet_Impl( const Reference< XMultiServiceFactory >& rxSMgr, + const Sequence< Property >& rProperties, + const vos::ORef< + ResultSetDataSupplier >& rDataSupplier ); + inline ~ResultSet_Impl(); +}; + +} // namespace ucb + +inline ResultSet_Impl::ResultSet_Impl( + const Reference< XMultiServiceFactory >& rxSMgr, + const Sequence< Property >& rProperties, + const vos::ORef< ResultSetDataSupplier >& rDataSupplier ) +: m_xSMgr( rxSMgr ), + m_aProperties( rProperties ), + m_xDataSupplier( rDataSupplier ), + m_pDisposeEventListeners( 0 ), + m_pPropertyChangeListeners( 0 ), + m_nPos( 0 ), // Position is one-based. Zero means: before first element. + m_bWasNull( sal_False ), + m_bAfterLast( sal_False ) +{ +} + +//========================================================================= +inline ResultSet_Impl::~ResultSet_Impl() +{ + delete m_pDisposeEventListeners; + delete m_pPropertyChangeListeners; +} + +//========================================================================= +//========================================================================= +// +// ResultSet Implementation. +// +//========================================================================= +//========================================================================= + +ResultSet::ResultSet( const Reference< XMultiServiceFactory >& rxSMgr, + const Sequence< Property >& rProperties, + const vos::ORef< ResultSetDataSupplier >& rDataSupplier ) +: m_pImpl( new ResultSet_Impl( rxSMgr, rProperties, rDataSupplier ) ) +{ + rDataSupplier->m_pResultSet = this; +} + +//========================================================================= +// virtual +ResultSet::~ResultSet() +{ + delete m_pImpl; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_9( ResultSet, + XTypeProvider, + XServiceInfo, + XComponent, + XContentAccess, + XResultSet, + XResultSetMetaDataSupplier, + XRow, + XCloseable, + XPropertySet ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_9( ResultSet, + XTypeProvider, + XServiceInfo, + XComponent, + XContentAccess, + XResultSet, + XResultSetMetaDataSupplier, + XRow, + XCloseable, + XPropertySet ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_NOFACTORY_IMPL_1( ResultSet, + OUString::createFromAscii( "ResultSet" ), + OUString::createFromAscii( RESULTSET_SERVICE_NAME ) ); + +//========================================================================= +// +// XComponent methods. +// +//========================================================================= + +// virtual +void SAL_CALL ResultSet::dispose() + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( m_pImpl->m_pDisposeEventListeners && + m_pImpl->m_pDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XComponent * >( this ); + m_pImpl->m_pDisposeEventListeners->disposeAndClear( aEvt ); + } + + if ( m_pImpl->m_pPropertyChangeListeners ) + { + EventObject aEvt; + aEvt.Source = static_cast< XPropertySet * >( this ); + m_pImpl->m_pPropertyChangeListeners->disposeAndClear( aEvt ); + } + + m_pImpl->m_xDataSupplier->close(); +} + +//========================================================================= +// virtual +void SAL_CALL ResultSet::addEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( !m_pImpl->m_pDisposeEventListeners ) + m_pImpl->m_pDisposeEventListeners = + new OInterfaceContainerHelper( m_pImpl->m_aMutex ); + + m_pImpl->m_pDisposeEventListeners->addInterface( Listener ); +} + +//========================================================================= +// virtual +void SAL_CALL ResultSet::removeEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( m_pImpl->m_pDisposeEventListeners ) + m_pImpl->m_pDisposeEventListeners->removeInterface( Listener ); +} + +//========================================================================= +// +// XResultSetMetaDataSupplier methods. +// +//========================================================================= + +// virtual +Reference< XResultSetMetaData > SAL_CALL ResultSet::getMetaData() + throw( SQLException, RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( !m_pImpl->m_xMetaData.is() ) + m_pImpl->m_xMetaData = new ResultSetMetaData( m_pImpl->m_xSMgr, + m_pImpl->m_aProperties ); + + return m_pImpl->m_xMetaData; +} + +//========================================================================= +// +// XResultSet methods. +// +//========================================================================= + +// virtual +sal_Bool SAL_CALL ResultSet::next() + throw( SQLException, RuntimeException ) +{ + // Note: Cursor is initially positioned before the first row. + // First call to 'next()' moves it to first row. + + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( m_pImpl->m_bAfterLast ) + { + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + + // getResult works zero-based! + if ( !m_pImpl->m_xDataSupplier->getResult( m_pImpl->m_nPos ) ) + { + m_pImpl->m_bAfterLast = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + + m_pImpl->m_nPos++; + m_pImpl->m_xDataSupplier->validate(); + return sal_True; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::isBeforeFirst() + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_bAfterLast ) + { + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + + // getResult works zero-based! + if ( !m_pImpl->m_xDataSupplier->getResult( 0 ) ) + { + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + + m_pImpl->m_xDataSupplier->validate(); + return ( m_pImpl->m_nPos == 0 ); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::isAfterLast() + throw( SQLException, RuntimeException ) +{ + m_pImpl->m_xDataSupplier->validate(); + return m_pImpl->m_bAfterLast; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::isFirst() + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_bAfterLast ) + { + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + + m_pImpl->m_xDataSupplier->validate(); + return ( m_pImpl->m_nPos == 1 ); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::isLast() + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_bAfterLast ) + { + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + + sal_uInt32 nCount = m_pImpl->m_xDataSupplier->totalCount(); + if ( !nCount ) + { + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + + m_pImpl->m_xDataSupplier->validate(); + return ( m_pImpl->m_nPos == nCount ); +} + +//========================================================================= +// virtual +void SAL_CALL ResultSet::beforeFirst() + throw( SQLException, RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_False; + m_pImpl->m_nPos = 0; + m_pImpl->m_xDataSupplier->validate(); +} + +//========================================================================= +// virtual +void SAL_CALL ResultSet::afterLast() + throw( SQLException, RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_True; + m_pImpl->m_xDataSupplier->validate(); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::first() + throw( SQLException, RuntimeException ) +{ + // getResult works zero-based! + if ( m_pImpl->m_xDataSupplier->getResult( 0 ) ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_False; + m_pImpl->m_nPos = 1; + m_pImpl->m_xDataSupplier->validate(); + return sal_True; + } + + m_pImpl->m_xDataSupplier->validate(); + return sal_False; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::last() + throw( SQLException, RuntimeException ) +{ + sal_uInt32 nCount = m_pImpl->m_xDataSupplier->totalCount(); + if ( nCount ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_False; + m_pImpl->m_nPos = nCount; + m_pImpl->m_xDataSupplier->validate(); + return sal_True; + } + + m_pImpl->m_xDataSupplier->validate(); + return sal_False; +} + +//========================================================================= +// virtual +sal_Int32 SAL_CALL ResultSet::getRow() + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_bAfterLast ) + { + m_pImpl->m_xDataSupplier->validate(); + return 0; + } + + m_pImpl->m_xDataSupplier->validate(); + return m_pImpl->m_nPos; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::absolute( sal_Int32 row ) + throw( SQLException, RuntimeException ) +{ +/* + If the row number is positive, the cursor moves to the given row number + with respect to the beginning of the result set. The first row is row 1, + the second is row 2, and so on. + + If the given row number is negative, the cursor moves to an absolute row + position with respect to the end of the result set. For example, calling + absolaute( -1 ) positions the cursor on the last row, absolaute( -2 ) + indicates the next-to-last row, and so on. + + An attempt to position the cursor beyond the first/last row in the result + set leaves the cursor before/after the first/last row, respectively. + + Calling absolute( 1 ) is the same as calling first(). + + Calling absolute( -1 ) is the same as calling last(). +*/ + if ( row < 0 ) + { + sal_uInt32 nCount = m_pImpl->m_xDataSupplier->totalCount(); + + if ( ( row * -1 ) > nCount ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_False; + m_pImpl->m_nPos = 0; + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + else // |row| <= nCount + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_False; + m_pImpl->m_nPos = ( nCount + row + 1 ); + m_pImpl->m_xDataSupplier->validate(); + return sal_True; + } + } + else if ( row == 0 ) + { + // @throws SQLException + // ... if row is 0 ... + throw SQLException(); + } + else // row > 0 + { + sal_uInt32 nCount = m_pImpl->m_xDataSupplier->totalCount(); + + if ( row <= nCount ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_False; + m_pImpl->m_nPos = row; + m_pImpl->m_xDataSupplier->validate(); + return sal_True; + } + else // row > nCount + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + } + + // unreachable... +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::relative( sal_Int32 rows ) + throw( SQLException, RuntimeException ) +{ +/* + Attempting to move beyond the first/last row in the result set + positions the cursor before/after the the first/last row. + + Calling relative( 0 ) is valid, but does not change the cursor position. + + Calling relative( 1 ) is different from calling next() because it makes + sense to call next() when there is no current row, for example, when + the cursor is positioned before the first row or after the last row of + the result set. +*/ + if ( m_pImpl->m_bAfterLast || ( m_pImpl->m_nPos == 0 ) ) + { + // "No current row". + throw SQLException(); + } + + if ( rows < 0 ) + { + if ( ( m_pImpl->m_nPos + rows ) > 0 ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_False; + m_pImpl->m_nPos = ( m_pImpl->m_nPos + rows ); + m_pImpl->m_xDataSupplier->validate(); + return sal_True; + } + else + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_False; + m_pImpl->m_nPos = 0; + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + } + else if ( rows == 0 ) + { + // nop. + m_pImpl->m_xDataSupplier->validate(); + return sal_True; + } + else // rows > 0 + { + sal_uInt32 nCount = m_pImpl->m_xDataSupplier->totalCount(); + if ( ( m_pImpl->m_nPos + rows ) <= nCount ) + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_False; + m_pImpl->m_nPos = ( m_pImpl->m_nPos + rows ); + m_pImpl->m_xDataSupplier->validate(); + return sal_True; + } + else + { + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + m_pImpl->m_bAfterLast = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return sal_False; + } + } + + // unreachable... +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::previous() + throw( SQLException, RuntimeException ) +{ +/* + previous() is not the same as relative( -1 ) because it makes sense + to call previous() when there is no current row. +*/ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( m_pImpl->m_bAfterLast ) + { + m_pImpl->m_bAfterLast = sal_False; + sal_uInt32 nCount = m_pImpl->m_xDataSupplier->totalCount(); + m_pImpl->m_nPos = nCount; + } + else if ( m_pImpl->m_nPos ) + m_pImpl->m_nPos--; + + if ( m_pImpl->m_nPos ) + { + m_pImpl->m_xDataSupplier->validate(); + return sal_True; + } + + m_pImpl->m_xDataSupplier->validate(); + return sal_False; +} + +//========================================================================= +// virtual +void SAL_CALL ResultSet::refreshRow() + throw( SQLException, RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + if ( m_pImpl->m_bAfterLast || ( m_pImpl->m_nPos == 0 ) ) + return; + + m_pImpl->m_xDataSupplier->releasePropertyValues( m_pImpl->m_nPos ); + m_pImpl->m_xDataSupplier->validate(); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::rowUpdated() + throw( SQLException, RuntimeException ) +{ + m_pImpl->m_xDataSupplier->validate(); + return sal_False; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::rowInserted() + throw( SQLException, RuntimeException ) +{ + m_pImpl->m_xDataSupplier->validate(); + return sal_False; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::rowDeleted() + throw( SQLException, RuntimeException ) +{ + m_pImpl->m_xDataSupplier->validate(); + return sal_False; +} + +//========================================================================= +// virtual +Reference< XInterface > SAL_CALL ResultSet::getStatement() + throw( SQLException, RuntimeException ) +{ +/* + returns the Statement that produced this ResultSet object. If the + result set was generated some other way, ... this method returns null. +*/ + m_pImpl->m_xDataSupplier->validate(); + return Reference< XInterface >(); +} + +//========================================================================= +// +// XRow methods. +// +//========================================================================= + +// virtual +sal_Bool SAL_CALL ResultSet::wasNull() + throw( SQLException, RuntimeException ) +{ + // This method can not be implemented correctly!!! Imagine different + // threads doing a getXYZ - wasNull calling sequence on the same + // implementation object... + + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_xDataSupplier->validate(); + return xValues->wasNull(); + } + } + + m_pImpl->m_xDataSupplier->validate(); + return m_pImpl->m_bWasNull; +} + +//========================================================================= +// virtual +OUString SAL_CALL ResultSet::getString( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getString( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return OUString(); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSet::getBoolean( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getBoolean( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return sal_False; +} + +//========================================================================= +// virtual +sal_Int8 SAL_CALL ResultSet::getByte( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getByte( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return 0; +} + +//========================================================================= +// virtual +sal_Int16 SAL_CALL ResultSet::getShort( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getShort( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return 0; +} + +//========================================================================= +// virtual +sal_Int32 SAL_CALL ResultSet::getInt( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getInt( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return 0; +} + +//========================================================================= +// virtual +sal_Int64 SAL_CALL ResultSet::getLong( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getLong( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return 0; +} + +//========================================================================= +// virtual +float SAL_CALL ResultSet::getFloat( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getFloat( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return 0; +} + +//========================================================================= +// virtual +double SAL_CALL ResultSet::getDouble( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getDouble( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return 0; +} + +//========================================================================= +// virtual +Sequence< sal_Int8 > SAL_CALL +ResultSet::getBytes( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getBytes( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return Sequence< sal_Int8 >(); +} + +//========================================================================= +// virtual +Date SAL_CALL ResultSet::getDate( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getDate( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return Date(); +} + +//========================================================================= +// virtual +Time SAL_CALL ResultSet::getTime( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getTime( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return Time(); +} + +//========================================================================= +// virtual +com::sun::star::util::DateTime SAL_CALL +ResultSet::getTimestamp( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getTimestamp( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return com::sun::star::util::DateTime(); +} + +//========================================================================= +// virtual +Reference< XInputStream > SAL_CALL +ResultSet::getBinaryStream( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getBinaryStream( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return Reference< XInputStream >(); +} + +//========================================================================= +// virtual +Reference< XInputStream > SAL_CALL +ResultSet::getCharacterStream( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getCharacterStream( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return Reference< XInputStream >(); +} + +//========================================================================= +// virtual +Any SAL_CALL ResultSet::getObject( sal_Int32 columnIndex, + const Reference< XNameAccess >& typeMap ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getObject( columnIndex, typeMap ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return Any(); +} + +//========================================================================= +// virtual +Reference< XRef > SAL_CALL ResultSet::getRef( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getRef( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return Reference< XRef >(); +} + +//========================================================================= +// virtual +Reference< XBlob > SAL_CALL ResultSet::getBlob( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getBlob( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return Reference< XBlob >(); +} + +//========================================================================= +// virtual +Reference< XClob > SAL_CALL ResultSet::getClob( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getClob( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return Reference< XClob >(); +} + +//========================================================================= +// virtual +Reference< XArray > SAL_CALL ResultSet::getArray( sal_Int32 columnIndex ) + throw( SQLException, RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + { + Reference< XRow > xValues + = m_pImpl->m_xDataSupplier->queryPropertyValues( + m_pImpl->m_nPos - 1 ); + if ( xValues.is() ) + { + m_pImpl->m_bWasNull = sal_False; + m_pImpl->m_xDataSupplier->validate(); + return xValues->getArray( columnIndex ); + } + } + + m_pImpl->m_bWasNull = sal_True; + m_pImpl->m_xDataSupplier->validate(); + return Reference< XArray >(); +} + +//========================================================================= +// +// XCloseable methods. +// +//========================================================================= + +// virtual +void SAL_CALL ResultSet::close() + throw( SQLException, RuntimeException ) +{ + m_pImpl->m_xDataSupplier->close(); + m_pImpl->m_xDataSupplier->validate(); +} + +//========================================================================= +// +// XContentAccess methods. +// +//========================================================================= + +// virtual +OUString SAL_CALL ResultSet::queryContentIdentfierString() + throw( RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + return m_pImpl->m_xDataSupplier->queryContentIdentifierString( + m_pImpl->m_nPos - 1 ); + + return OUString(); +} + +//========================================================================= +// virtual +Reference< XContentIdentifier > SAL_CALL ResultSet::queryContentIdentifier() + throw( RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + return m_pImpl->m_xDataSupplier->queryContentIdentifier( + m_pImpl->m_nPos - 1 ); + + return Reference< XContentIdentifier >(); +} + +//========================================================================= +// virtual +Reference< XContent > SAL_CALL ResultSet::queryContent() + throw( RuntimeException ) +{ + if ( m_pImpl->m_nPos && !m_pImpl->m_bAfterLast ) + return m_pImpl->m_xDataSupplier->queryContent( m_pImpl->m_nPos - 1 ); + + return Reference< XContent >(); +} + +//========================================================================= +// +// XPropertySet methods. +// +//========================================================================= + +// virtual +Reference< XPropertySetInfo > SAL_CALL ResultSet::getPropertySetInfo() + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( !m_pImpl->m_xPropSetInfo.is() ) + m_pImpl->m_xPropSetInfo + = new PropertySetInfo( m_pImpl->m_xSMgr, + aPropertyTable, + RESULTSET_PROPERTY_COUNT ); + return m_pImpl->m_xPropSetInfo; +} + +//========================================================================= +// virtual +void SAL_CALL ResultSet::setPropertyValue( const OUString& aPropertyName, + const Any& aValue ) + throw( UnknownPropertyException, + PropertyVetoException, + IllegalArgumentException, + WrappedTargetException, + RuntimeException ) +{ + if ( !aPropertyName.getLength() ) + throw UnknownPropertyException(); + + if ( aPropertyName.equals( + OUString::createFromAscii( "RowCount" ) ) ) + { + // property is read-only. + throw IllegalArgumentException(); + } + else if ( aPropertyName.equals( + OUString::createFromAscii( "IsRowCountFinal" ) ) ) + { + // property is read-only. + throw IllegalArgumentException(); + } + else + { + throw UnknownPropertyException(); + } +} + +//========================================================================= +// virtual +Any SAL_CALL ResultSet::getPropertyValue( const OUString& PropertyName ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + if ( !PropertyName.getLength() ) + throw UnknownPropertyException(); + + Any aValue; + + if ( PropertyName.equals( + OUString::createFromAscii( "RowCount" ) ) ) + { + aValue <<= m_pImpl->m_xDataSupplier->currentCount(); + } + else if ( PropertyName.equals( + OUString::createFromAscii( "IsRowCountFinal" ) ) ) + { + aValue <<= m_pImpl->m_xDataSupplier->isCountFinal(); + } + else + { + throw UnknownPropertyException(); + } + + return aValue; +} + +//========================================================================= +// virtual +void SAL_CALL ResultSet::addPropertyChangeListener( + const OUString& aPropertyName, + const Reference< XPropertyChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + // Note: An empty property name means a listener for "all" properties. + + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( aPropertyName.getLength() && + !aPropertyName.equals( + OUString::createFromAscii( "RowCount" ) ) && + !aPropertyName.equals( + OUString::createFromAscii( "IsRowCountFinal" ) ) ) + throw UnknownPropertyException(); + + if ( !m_pImpl->m_pPropertyChangeListeners ) + m_pImpl->m_pPropertyChangeListeners + = new PropertyChangeListeners( m_pImpl->m_aMutex ); + + m_pImpl->m_pPropertyChangeListeners->addInterface( + aPropertyName, xListener ); +} + +//========================================================================= +// virtual +void SAL_CALL ResultSet::removePropertyChangeListener( + const OUString& aPropertyName, + const Reference< XPropertyChangeListener >& xListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( aPropertyName.getLength() && + !aPropertyName.equals( + OUString::createFromAscii( "RowCount" ) ) && + !aPropertyName.equals( + OUString::createFromAscii( "IsRowCountFinal" ) ) ) + throw UnknownPropertyException(); + + if ( m_pImpl->m_pPropertyChangeListeners ) + m_pImpl->m_pPropertyChangeListeners->removeInterface( + aPropertyName, xListener ); + +} + +//========================================================================= +// virtual +void SAL_CALL ResultSet::addVetoableChangeListener( + const OUString& PropertyName, + const Reference< XVetoableChangeListener >& aListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + // No constrained props. at the moment. +} + +//========================================================================= +// virtual +void SAL_CALL ResultSet::removeVetoableChangeListener( + const OUString& PropertyName, + const Reference< XVetoableChangeListener >& aListener ) + throw( UnknownPropertyException, + WrappedTargetException, + RuntimeException ) +{ + // No constrained props. at the moment. +} + +//========================================================================= +// +// Non-interface methods. +// +//========================================================================= + +void ResultSet::propertyChanged( const PropertyChangeEvent& rEvt ) +{ +// osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( !m_pImpl->m_pPropertyChangeListeners ) + return; + + // Notify listeners interested especially in the changed property. + OInterfaceContainerHelper* pPropsContainer + = m_pImpl->m_pPropertyChangeListeners->getContainer( + rEvt.PropertyName ); + if ( pPropsContainer ) + { + OInterfaceIteratorHelper aIter( *pPropsContainer ); + while ( aIter.hasMoreElements() ) + { + Reference< XPropertyChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->propertyChange( rEvt ); + } + } + + // Notify listeners interested in all properties. + pPropsContainer + = m_pImpl->m_pPropertyChangeListeners->getContainer( OUString() ); + if ( pPropsContainer ) + { + OInterfaceIteratorHelper aIter( *pPropsContainer ); + while ( aIter.hasMoreElements() ) + { + Reference< XPropertyChangeListener > xListener( + aIter.next(), UNO_QUERY ); + if ( xListener.is() ) + xListener->propertyChange( rEvt ); + } + } +} + +//========================================================================= +void ResultSet::rowCountChanged( sal_uInt32 nOld, sal_uInt32 nNew ) +{ + VOS_ENSURE( nOld < nNew, "ResultSet::rowCountChanged - nOld >= nNew!" ); + +// osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( !m_pImpl->m_pPropertyChangeListeners ) + return; + + propertyChanged( + PropertyChangeEvent( static_cast< OWeakObject * >( this ), + OUString::createFromAscii( "RowCount" ), + sal_False, + 1001, + makeAny( nOld ), // old value + makeAny( nNew ) ) ); // new value +} + +//========================================================================= +void ResultSet::rowCountFinal() +{ +// osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( !m_pImpl->m_pPropertyChangeListeners ) + return; + + propertyChanged( + PropertyChangeEvent( static_cast< OWeakObject * >( this ), + OUString::createFromAscii( "IsRowCountFinal" ), + sal_False, + 1000, + makeAny( sal_False ), // old value + makeAny( sal_True ) ) ); // new value +} + +//========================================================================= +const Sequence< Property >& ResultSet::getProperties() +{ + return m_pImpl->m_aProperties; +} + +//========================================================================= +//========================================================================= +// +// PropertySetInfo Implementation. +// +//========================================================================= +//========================================================================= + +PropertySetInfo::PropertySetInfo( + const Reference< XMultiServiceFactory >& rxSMgr, + const PropertyInfo* pProps, + sal_uInt32 nProps ) +: m_xSMgr( rxSMgr ) +{ + m_pProps = new Sequence< Property >( nProps ); + + if ( nProps ) + { + const PropertyInfo* pEntry = pProps; + Property* pProperties = m_pProps->getArray(); + + for ( sal_uInt32 n = 0; n < nProps; ++n ) + { + Property& rProp = pProperties[ n ]; + + rProp.Name = rtl::OUString::createFromAscii( pEntry->pName ); + rProp.Handle = pEntry->nHandle; + rProp.Type = pEntry->pGetCppuType(); + rProp.Attributes = pEntry->nAttributes; + + pEntry++; + } + } +} + +//========================================================================= +// virtual +PropertySetInfo::~PropertySetInfo() +{ + delete m_pProps; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_2( PropertySetInfo, + XTypeProvider, + XPropertySetInfo ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_2( PropertySetInfo, + XTypeProvider, + XPropertySetInfo ); + +//========================================================================= +// +// XPropertySetInfo methods. +// +//========================================================================= + +// virtual +Sequence< Property > SAL_CALL PropertySetInfo::getProperties() + throw( RuntimeException ) +{ + return Sequence< Property >( *m_pProps ); +} + +//========================================================================= +// virtual +Property SAL_CALL PropertySetInfo::getPropertyByName( const OUString& aName ) + throw( UnknownPropertyException, RuntimeException ) +{ + Property aProp; + if ( queryProperty( aName, aProp ) ) + return aProp; + + throw UnknownPropertyException(); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL PropertySetInfo::hasPropertyByName( const OUString& Name ) + throw( RuntimeException ) +{ + Property aProp; + return queryProperty( Name, aProp ); +} + +//========================================================================= +sal_Bool PropertySetInfo::queryProperty( + const OUString& aName, Property& rProp ) +{ + sal_uInt32 nCount = m_pProps->getLength(); + const Property* pProps = m_pProps->getConstArray(); + for ( sal_uInt32 n = 0; n < nCount; ++n ) + { + const Property& rCurr = pProps[ n ]; + if ( rCurr.Name == aName ) + { + rProp = rCurr; + return sal_True; + } + } + + return sal_False; +} + diff --git a/ucbhelper/source/provider/resultsethelper.cxx b/ucbhelper/source/provider/resultsethelper.cxx new file mode 100644 index 000000000000..eaaad700aaa5 --- /dev/null +++ b/ucbhelper/source/provider/resultsethelper.cxx @@ -0,0 +1,369 @@ +/************************************************************************* + * + * $RCSfile: resultsethelper.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + - This implementation is far away from completion. It has no interface + for changes notifications etc. + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_UCB_LISTACTIONTYPE_HPP_ +#include <com/sun/star/ucb/ListActionType.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_WELCOMEDYNAMICRESULTSETSTRUCT_HPP_ +#include <com/sun/star/ucb/WelcomeDynamicResultSetStruct.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XCACHEDDYNAMICRESULTSETSTUBFACTORY_HPP_ +#include <com/sun/star/ucb/XCachedDynamicResultSetStubFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_UCB_XSOURCEINITIALIZATION_HPP_ +#include <com/sun/star/ucb/XSourceInitialization.hpp> +#endif +#ifndef _CPPUHELPER_INTERFACECONTAINER_HXX_ +#include <cppuhelper/interfacecontainer.hxx> +#endif +#ifndef _UCBHELPER_RESULTSETHELPER_HXX +#include <ucbhelper/resultsethelper.hxx> +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::ucb; +using namespace com::sun::star::uno; +using namespace cppu; +using namespace rtl; +using namespace ucb; + +//========================================================================= +//========================================================================= +// +// ResultSetImplHelper Implementation. +// +//========================================================================= +//========================================================================= + +#define RESULTSETHELPER_INIT() \ + m_xSMgr( rxSMgr ), \ + m_pDisposeEventListeners( 0 ), \ + m_bInitDone( sal_False ), \ + m_bStatic( sal_False ) + +//========================================================================= +ResultSetImplHelper::ResultSetImplHelper( + const Reference< XMultiServiceFactory >& rxSMgr ) +: RESULTSETHELPER_INIT() +{ +} + +//========================================================================= +ResultSetImplHelper::ResultSetImplHelper( + const Reference< XMultiServiceFactory >& rxSMgr, + const OpenCommandArgument2& rCommand ) +: RESULTSETHELPER_INIT(), + m_aCommand( rCommand ) +{ +} + +//========================================================================= +// virtual +ResultSetImplHelper::~ResultSetImplHelper() +{ + delete m_pDisposeEventListeners; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_4( ResultSetImplHelper, + XTypeProvider, + XServiceInfo, + XComponent, /* base of XDynamicResultSet */ + XDynamicResultSet ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_3( ResultSetImplHelper, + XTypeProvider, + XServiceInfo, + XDynamicResultSet ); + +//========================================================================= +// +// XServiceInfo methods. +// +//========================================================================= + +XSERVICEINFO_NOFACTORY_IMPL_1( ResultSetImplHelper, + OUString::createFromAscii( "ResultSetImplHelper" ), + OUString::createFromAscii( DYNAMICRESULTSET_SERVICE_NAME ) ); + +//========================================================================= +// +// XComponent methods. +// +//========================================================================= + +// virtual +void SAL_CALL ResultSetImplHelper::dispose() + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() ) + { + EventObject aEvt; + aEvt.Source = static_cast< XComponent * >( this ); + m_pDisposeEventListeners->disposeAndClear( aEvt ); + } +} + +//========================================================================= +// virtual +void SAL_CALL ResultSetImplHelper::addEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_pDisposeEventListeners ) + m_pDisposeEventListeners = new OInterfaceContainerHelper( m_aMutex ); + + m_pDisposeEventListeners->addInterface( Listener ); +} + +//========================================================================= +// virtual +void SAL_CALL ResultSetImplHelper::removeEventListener( + const Reference< XEventListener >& Listener ) + throw( RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_pDisposeEventListeners ) + m_pDisposeEventListeners->removeInterface( Listener ); +} + +//========================================================================= +// +// XDynamicResultSet methods. +// +//========================================================================= + +// virtual +Reference< XResultSet > SAL_CALL ResultSetImplHelper::getStaticResultSet() + throw( ListenerAlreadySetException, RuntimeException ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_xListener.is() ) + throw ListenerAlreadySetException(); + + init( sal_True ); + return m_xResultSet1; +} + +//========================================================================= +// virtual +void SAL_CALL ResultSetImplHelper::setListener( + const Reference< XDynamicResultSetListener >& Listener ) + throw( ListenerAlreadySetException, RuntimeException ) +{ + osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex ); + + if ( m_bStatic || m_xListener.is() ) + throw ListenerAlreadySetException(); + + m_xListener = Listener; + + ////////////////////////////////////////////////////////////////////// + // Create "welcome event" and send it to listener. + ////////////////////////////////////////////////////////////////////// + + // Note: We only have the implementation for a static result set at the + // moment (src590). The dynamic result sets passed to the listener + // are a fake. This implementation will never call "notify" at the + // listener to propagate any changes!!! + + init( sal_False ); + + Any aInfo; + aInfo <<= WelcomeDynamicResultSetStruct( m_xResultSet1 /* "old" */, + m_xResultSet2 /* "new" */ ); + + Sequence< ListAction > aActions( 1 ); + aActions.getArray()[ 0 ] = ListAction( 0, // Position; not used + 0, // Count; not used + ListActionType::WELCOME, + aInfo ); + aGuard.clear(); + + Listener->notify( + ListEvent( static_cast< OWeakObject * >( this ), aActions ) ); +} + +//========================================================================= +// virtual +sal_Int16 SAL_CALL ResultSetImplHelper::getCapabilities() + throw( RuntimeException ) +{ + // ! ContentResultSetCapability::SORTED + return 0; +} + +//========================================================================= +// virtual +void SAL_CALL ResultSetImplHelper::connectToCache( + const Reference< XDynamicResultSet > & xCache ) + throw( ListenerAlreadySetException, + AlreadyInitializedException, + ServiceNotFoundException, + RuntimeException ) +{ + if ( m_xListener.is() ) + throw ListenerAlreadySetException(); + + if ( m_bStatic ) + throw ListenerAlreadySetException(); + + Reference< XSourceInitialization > xTarget( xCache, UNO_QUERY ); + if ( xTarget.is() ) + { + Reference< XCachedDynamicResultSetStubFactory > xStubFactory( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.ucb.CachedDynamicResultSetStubFactory" ) ), + UNO_QUERY ); + if ( xStubFactory.is() ) + { + xStubFactory->connectToCache( + this, xCache, m_aCommand.SortingInfo, 0 ); + return; + } + } + throw ServiceNotFoundException(); +} + +//========================================================================= +// +// Non-interface methods. +// +//========================================================================= + +void ResultSetImplHelper::init( sal_Bool bStatic ) +{ + osl::Guard< osl::Mutex > aGuard( m_aMutex ); + + if ( !m_bInitDone ) + { + if ( bStatic ) + { + // virtual... derived class fills m_xResultSet1 + initStatic(); + + VOS_ENSURE( m_xResultSet1.is(), + "ResultSetImplHelper::init - No 1st result set!" ); + m_bStatic = sal_True; + } + else + { + // virtual... derived class fills m_xResultSet1 and m_xResultSet2 + initDynamic(); + + VOS_ENSURE( m_xResultSet1.is(), + "ResultSetImplHelper::init - No 1st result set!" ); + VOS_ENSURE( m_xResultSet2.is(), + "ResultSetImplHelper::init - No 2nd result set!" ); + m_bStatic = sal_False; + } + m_bInitDone = sal_True; + } + +} + +/* + +pure virtual + +//========================================================================= +// virtual +void ResultSetImplHelper::initStatic() +{ +} + +//========================================================================= +// virtual +void ResultSetImplHelper::initDynamic() +{ +} + +*/ + diff --git a/ucbhelper/source/provider/resultsetmetadata.cxx b/ucbhelper/source/provider/resultsetmetadata.cxx new file mode 100644 index 000000000000..8647ea0c60e0 --- /dev/null +++ b/ucbhelper/source/provider/resultsetmetadata.cxx @@ -0,0 +1,588 @@ +/************************************************************************* + * + * $RCSfile: resultsetmetadata.cxx,v $ + * + * $Revision: 1.1.1.1 $ + * + * last change: $Author: hr $ $Date: 2000-09-18 17:03:37 $ + * + * The Contents of this file are made available subject to the terms of + * either of the following licenses + * + * - GNU Lesser General Public License Version 2.1 + * - Sun Industry Standards Source License Version 1.1 + * + * Sun Microsystems Inc., October, 2000 + * + * GNU Lesser General Public License Version 2.1 + * ============================================= + * Copyright 2000 by Sun Microsystems, Inc. + * 901 San Antonio Road, Palo Alto, CA 94303, USA + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License version 2.1, as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, + * MA 02111-1307 USA + * + * + * Sun Industry Standards Source License Version 1.1 + * ================================================= + * The contents of this file are subject to the Sun Industry Standards + * Source License Version 1.1 (the "License"); You may not use this file + * except in compliance with the License. You may obtain a copy of the + * License at http://www.openoffice.org/license.html. + * + * Software provided under this License is provided on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, + * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, + * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. + * See the License for the specific provisions governing your rights and + * obligations concerning the Software. + * + * The Initial Developer of the Original Code is: Sun Microsystems, Inc. + * + * Copyright: 2000 by Sun Microsystems, Inc. + * + * All Rights Reserved. + * + * Contributor(s): _______________________________________ + * + * + ************************************************************************/ + +/************************************************************************** + TODO + ************************************************************************** + + - Search for @@@ in this file to find out what's to do + + *************************************************************************/ + +#ifndef _COM_SUN_STAR_BEANS_PROPERTY_HPP_ +#include <com/sun/star/beans/Property.hpp> +#endif +#ifndef _COM_SUN_STAR_BEANS_XPROPERTYSETINFO_HPP_ +#include <com/sun/star/beans/XPropertySetInfo.hpp> +#endif +#ifndef _COM_SUN_STAR_IO_XINPUTSTREAM_HPP_ +#include <com/sun/star/io/XInputStream.hpp> +#endif +#ifndef _COM_SUN_STAR_LANG_XMULTISERVICEFACTORY_HPP_ +#include <com/sun/star/lang/XMultiServiceFactory.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_COLUMNVALUE_HPP_ +#include <com/sun/star/sdbc/ColumnValue.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_DATATYPE_HPP_ +#include <com/sun/star/sdbc/DataType.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XARRAY_HPP_ +#include <com/sun/star/sdbc/XArray.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XBLOB_HPP_ +#include <com/sun/star/sdbc/XBlob.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XCLOB_HPP_ +#include <com/sun/star/sdbc/XClob.hpp> +#endif +#ifndef _COM_SUN_STAR_SDBC_XREF_HPP_ +#include <com/sun/star/sdbc/XRef.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_DATE_HPP_ +#include <com/sun/star/util/Date.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_TIME_HPP_ +#include <com/sun/star/util/Time.hpp> +#endif +#ifndef _COM_SUN_STAR_UTIL_DATETIME_HPP_ +#include <com/sun/star/util/DateTime.hpp> +#endif + +#ifndef _UCBHELPER_RESULTSETMETADATA_HXX +#include <ucbhelper/resultsetmetadata.hxx> +#endif + +using namespace com::sun::star::beans; +using namespace com::sun::star::io; +using namespace com::sun::star::lang; +using namespace com::sun::star::sdbc; +using namespace com::sun::star::uno; +using namespace com::sun::star::util; +using namespace rtl; +using namespace ucb; + +namespace ucb +{ + +struct ResultSetMetaData_Impl +{ + osl::Mutex m_aMutex; + sal_Bool m_bObtainedTypes; + + ResultSetMetaData_Impl() : m_bObtainedTypes( sal_False ) {} +}; + +} + +//========================================================================= +//========================================================================= +// +// ResultSetMetaData Implementation. +// +//========================================================================= +//========================================================================= + +ResultSetMetaData::ResultSetMetaData( + const Reference< XMultiServiceFactory >& rxSMgr, + const Sequence< Property >& rProps, + sal_Bool bReadOnly ) +: m_pImpl( new ResultSetMetaData_Impl ), + m_xSMgr( rxSMgr ), + m_aProps( rProps ), + m_bReadOnly( bReadOnly ) +{ +} + +//========================================================================= +// virtual +ResultSetMetaData::~ResultSetMetaData() +{ + delete m_pImpl; +} + +//========================================================================= +// +// XInterface methods. +// +//========================================================================= + +XINTERFACE_IMPL_2( ResultSetMetaData, + XTypeProvider, + XResultSetMetaData ); + +//========================================================================= +// +// XTypeProvider methods. +// +//========================================================================= + +XTYPEPROVIDER_IMPL_2( ResultSetMetaData, + XTypeProvider, + XResultSetMetaData ); + +//========================================================================= +// +// XResultSetMetaData methods. +// +//========================================================================= + +// virtual +sal_Int32 SAL_CALL ResultSetMetaData::getColumnCount() + throw( SQLException, RuntimeException ) +{ + return m_aProps.getLength(); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSetMetaData::isAutoIncrement( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Checks whether column is automatically numbered, which makes it + read-only. + */ + + return m_bReadOnly; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSetMetaData::isCaseSensitive( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + // @@@ + return sal_False; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSetMetaData::isSearchable( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Checks whether the value stored in column can be used in a + WHERE clause. + */ + + // @@@ + return sal_False; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSetMetaData::isCurrency( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Checks whether column is a cash value. + */ + + // @@@ + return sal_False; +} + +//========================================================================= +// virtual +sal_Int32 SAL_CALL ResultSetMetaData::isNullable( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Checks whether a NULL can be stored in column. + Possible values: see com/sun/star/sdbc/ColumnValue.idl + */ + + // All columns may contain NULL. Think of result sets containing + // UCB contents of different types... + return ColumnValue::NULLABLE; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSetMetaData::isSigned( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Checks whether the value stored in column is a signed number. + */ + + // @@@ + return sal_False; +} + +//========================================================================= +// virtual +sal_Int32 SAL_CALL ResultSetMetaData::getColumnDisplaySize( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Gets the normal maximum width in characters for column. + */ + + // @@@ + return 16; +} + +//========================================================================= +// virtual +OUString SAL_CALL ResultSetMetaData::getColumnLabel( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Gets the suggested column title for column, to be used in print- + outs and displays. + */ + + if ( ( column < 1 ) || ( column > m_aProps.getLength() ) ) + return OUString(); + + return m_aProps.getConstArray()[ column - 1 ].Name; +} + +//========================================================================= +// virtual +OUString SAL_CALL ResultSetMetaData::getColumnName( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Gets the name of column. + */ + + if ( ( column < 1 ) || ( column > m_aProps.getLength() ) ) + return OUString(); + + return m_aProps.getConstArray()[ column - 1 ].Name; +} + +//========================================================================= +// virtual +OUString SAL_CALL ResultSetMetaData::getSchemaName( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Gets the schema name for the table from which column of this + result set was derived. + Because this feature is not widely supported, the return value + for many DBMSs will be an empty string. + */ + + return OUString(); +} + +//========================================================================= +// virtual +sal_Int32 SAL_CALL ResultSetMetaData::getPrecision( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + For number types, getprecision gets the number of decimal digits + in column. + For character types, it gets the maximum length in characters for + column. + For binary types, it gets the maximum length in bytes for column. + */ + + // @@@ + return -1; +} + +//========================================================================= +// virtual +sal_Int32 SAL_CALL ResultSetMetaData::getScale( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Gets the number of digits to the right of the decimal point for + values in column. + */ + + // @@@ + return 0; +} + +//========================================================================= +// virtual +OUString SAL_CALL ResultSetMetaData::getTableName( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Gets the name of the table from which column of this result set + was derived or "" if there is none (for example, for a join). + Because this feature is not widely supported, the return value + for many DBMSs will be an empty string. + */ + + return OUString(); +} + +//========================================================================= +// virtual +OUString SAL_CALL ResultSetMetaData::getCatalogName( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Gets the catalog name for the table from which column of this + result set was derived. + Because this feature is not widely supported, the return value + for many DBMSs will be an empty string. + */ + + return OUString(); +} + +//========================================================================= +// virtual +sal_Int32 SAL_CALL ResultSetMetaData::getColumnType( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Gets the JDBC type for the value stored in column. ... The STRUCT + and DISTINCT type codes are always returned for structured and + distinct types, regardless of whether the value will be mapped + according to the standard mapping or be a custom mapping. + */ + + if ( ( column < 1 ) || ( column > m_aProps.getLength() ) ) + return DataType::SQLNULL; + + if ( m_aProps.getConstArray()[ column - 1 ].Type + == getCppuVoidType() ) + { + // No type given. Try UCB's Properties Manager... + + osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex ); + + if ( !m_pImpl->m_bObtainedTypes ) + { + try + { + Reference< XPropertySetInfo > xInfo( + m_xSMgr->createInstance( + OUString::createFromAscii( + "com.sun.star.ucb.PropertiesManager" ) ), + UNO_QUERY ); + if ( xInfo.is() ) + { +#if 0 + // Convenient... + + sal_Int32 nCount = m_pImpl->m_aProps.getLength(); + Property* pProps = m_pImpl->m_aProps.getArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + Property& rProp = pProps[ n ]; + + try + { + Property aProp + = xInfo->getPropertyByName( rProp.Name ); + rProp.Type = aProp.Type; + } + catch ( UnknownPropertyException& ) + { + // getPropertyByName + } + } +#else + // Less (remote) calls... + + Sequence< Property > aProps = xInfo->getProperties(); + const Property* pProps1 = aProps.getConstArray(); + sal_Int32 nCount1 = aProps.getLength(); + + sal_Int32 nCount = m_aProps.getLength(); + Property* pProps = m_aProps.getArray(); + for ( sal_Int32 n = 0; n < nCount; ++n ) + { + Property& rProp = pProps[ n ]; + + for ( sal_Int32 m = 0; m < nCount1; ++m ) + { + const Property& rProp1 = pProps1[ m ]; + if ( rProp.Name == rProp1.Name ) + { + // Found... + rProp.Type = rProp1.Type; + break; + } + } + } +#endif + } + } + catch ( RuntimeException& ) + { + throw; + } + catch ( Exception& ) + { + // createInstance + } + + m_pImpl->m_bObtainedTypes = sal_True; + } + } + + const Type& rType = m_aProps.getConstArray()[ column - 1 ].Type; + sal_Int32 nType = DataType::OTHER; + + if ( rType == getCppuType( static_cast< const rtl::OUString * >( 0 ) ) ) + nType = DataType::VARCHAR; // XRow::getString + else if ( rType == getCppuBooleanType() ) + nType = DataType::BIT; // XRow::getBoolean + else if ( rType == getCppuType( static_cast< const sal_Int32 * >( 0 ) ) ) + nType = DataType::INTEGER; // XRow::getInt + else if ( rType == getCppuType( static_cast< const sal_Int64 * >( 0 ) ) ) + nType = DataType::BIGINT; // XRow::getLong + else if ( rType == getCppuType( static_cast< const sal_Int16 * >( 0 ) ) ) + nType = DataType::SMALLINT; // XRow::getShort + else if ( rType == getCppuType( static_cast< const sal_Int8 * >( 0 ) ) ) + nType = DataType::TINYINT; // XRow::getByte + else if ( rType == getCppuType( static_cast< const float * >( 0 ) ) ) + nType = DataType::REAL; // XRow::getFloat + else if ( rType == getCppuType( static_cast< const double * >( 0 ) ) ) + nType = DataType::DOUBLE; // XRow::getDouble + else if ( rType == getCppuType( static_cast< const Sequence< sal_Int8 > * >( 0 ) ) ) + nType = DataType::VARBINARY;// XRow::getBytes + else if ( rType == getCppuType( static_cast< const Date * >( 0 ) ) ) + nType = DataType::DATE; // XRow::getDate + else if ( rType == getCppuType( static_cast< const Time * >( 0 ) ) ) + nType = DataType::TIME; // XRow::getTime + else if ( rType == getCppuType( static_cast< const DateTime * >( 0 ) ) ) + nType = DataType::TIMESTAMP;// XRow::getTimestamp + else if ( rType == getCppuType( static_cast< Reference< XInputStream > * >( 0 ) ) ) + nType = DataType::LONGVARBINARY; // XRow::getBinaryStream +// nType = DataType::LONGVARCHAR; // XRow::getCharacterStream + else if ( rType == getCppuType( static_cast< Reference< XClob > * >( 0 ) ) ) + nType = DataType::CLOB; // XRow::getClob + else if ( rType == getCppuType( static_cast< Reference< XBlob > * >( 0 ) ) ) + nType = DataType::BLOB; // XRow::getBlob + else if ( rType == getCppuType( static_cast< Reference< XArray > * >( 0 ) ) ) + nType = DataType::ARRAY;// XRow::getArray + else if ( rType == getCppuType( static_cast< Reference< XRef > * >( 0 ) ) ) + nType = DataType::REF;// XRow::getRef + else + nType = DataType::OBJECT;// XRow::getObject + + return nType; +} + +//========================================================================= +// virtual +OUString SAL_CALL ResultSetMetaData::getColumnTypeName( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Gets the type name used by this particular data source for the + values stored in column. If the type code for the type of value + stored in column is STRUCT, DISTINCT or JAVA_OBJECT, this method + returns a fully-qualified SQL type name. + */ + + if ( ( column < 1 ) || ( column > m_aProps.getLength() ) ) + return OUString(); + + // @@@ According to DG, the type name may be empty. + return OUString(); +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSetMetaData::isReadOnly( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + // ContentResultSet's are completely read-only. + return m_bReadOnly; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSetMetaData::isWritable( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + // ContentResultSet's are completely read-only. + return !m_bReadOnly; +} + +//========================================================================= +// virtual +sal_Bool SAL_CALL ResultSetMetaData::isDefinitelyWritable( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + // ContentResultSet's are completely read-only. + return !m_bReadOnly; +} + +//========================================================================= +// virtual +OUString SAL_CALL ResultSetMetaData::getColumnServiceName( sal_Int32 column ) + throw( SQLException, RuntimeException ) +{ + /* + Returns the fully-qualified name of the service whose instances + are manufactured if XResultSet::getObject is called to retrieve + a value from the column. + */ + + return OUString(); +} + |