1*5900e8ecSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5900e8ecSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5900e8ecSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5900e8ecSAndrew Rist * distributed with this work for additional information 6*5900e8ecSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5900e8ecSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5900e8ecSAndrew Rist * "License"); you may not use this file except in compliance 9*5900e8ecSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*5900e8ecSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*5900e8ecSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5900e8ecSAndrew Rist * software distributed under the License is distributed on an 15*5900e8ecSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5900e8ecSAndrew Rist * KIND, either express or implied. See the License for the 17*5900e8ecSAndrew Rist * specific language governing permissions and limitations 18*5900e8ecSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*5900e8ecSAndrew Rist *************************************************************/ 21*5900e8ecSAndrew Rist 22*5900e8ecSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_svtools.hxx" 26cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx" 27cdf0e10cSrcweir #include "com/sun/star/uno/Type.hxx" 28cdf0e10cSrcweir #include <svtools/svtdata.hxx> 29cdf0e10cSrcweir #include <svtools/javacontext.hxx> 30cdf0e10cSrcweir #include <svtools/javainteractionhandler.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir using namespace com::sun::star::uno; 33cdf0e10cSrcweir using namespace com::sun::star::task; 34cdf0e10cSrcweir namespace svt 35cdf0e10cSrcweir { 36cdf0e10cSrcweir 37cdf0e10cSrcweir JavaContext::JavaContext( const Reference< XCurrentContext > & ctx ) 38cdf0e10cSrcweir : 39cdf0e10cSrcweir m_aRefCount(0), 40cdf0e10cSrcweir m_xNextContext( ctx ), 41cdf0e10cSrcweir m_bShowErrorsOnce(false) 42cdf0e10cSrcweir { 43cdf0e10cSrcweir } 44cdf0e10cSrcweir 45cdf0e10cSrcweir JavaContext::JavaContext( const Reference< XCurrentContext > & ctx, 46cdf0e10cSrcweir bool bShowErrorsOnce) 47cdf0e10cSrcweir : m_aRefCount(0), 48cdf0e10cSrcweir m_xNextContext( ctx ), 49cdf0e10cSrcweir m_bShowErrorsOnce(bShowErrorsOnce) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir } 52cdf0e10cSrcweir 53cdf0e10cSrcweir JavaContext::~JavaContext() 54cdf0e10cSrcweir { 55cdf0e10cSrcweir } 56cdf0e10cSrcweir 57cdf0e10cSrcweir Any SAL_CALL JavaContext::queryInterface(const Type& aType ) 58cdf0e10cSrcweir throw (RuntimeException) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir if (aType == getCppuType(reinterpret_cast<Reference<XInterface>*>(0))) 61cdf0e10cSrcweir return Any(Reference<XInterface>(static_cast<XInterface*>(this))); 62cdf0e10cSrcweir else if (aType == getCppuType(reinterpret_cast<Reference<XCurrentContext>*>(0))) 63cdf0e10cSrcweir return Any(Reference<XCurrentContext>( static_cast<XCurrentContext*>(this))); 64cdf0e10cSrcweir return Any(); 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir void SAL_CALL JavaContext::acquire( ) throw () 68cdf0e10cSrcweir { 69cdf0e10cSrcweir osl_incrementInterlockedCount( &m_aRefCount ); 70cdf0e10cSrcweir } 71cdf0e10cSrcweir 72cdf0e10cSrcweir void SAL_CALL JavaContext::release( ) throw () 73cdf0e10cSrcweir { 74cdf0e10cSrcweir if (! osl_decrementInterlockedCount( &m_aRefCount )) 75cdf0e10cSrcweir delete this; 76cdf0e10cSrcweir } 77cdf0e10cSrcweir 78cdf0e10cSrcweir Any SAL_CALL JavaContext::getValueByName( const ::rtl::OUString& Name) throw (RuntimeException) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir Any retVal; 81cdf0e10cSrcweir 82cdf0e10cSrcweir if ( 0 == Name.compareToAscii( JAVA_INTERACTION_HANDLER_NAME )) 83cdf0e10cSrcweir { 84cdf0e10cSrcweir { 85cdf0e10cSrcweir osl::MutexGuard aGuard(osl::Mutex::getGlobalMutex()); 86cdf0e10cSrcweir if (!m_xHandler.is()) 87cdf0e10cSrcweir m_xHandler = Reference< XInteractionHandler >( 88cdf0e10cSrcweir new JavaInteractionHandler(m_bShowErrorsOnce)); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir retVal = makeAny(m_xHandler); 91cdf0e10cSrcweir 92cdf0e10cSrcweir } 93cdf0e10cSrcweir else if( m_xNextContext.is() ) 94cdf0e10cSrcweir { 95cdf0e10cSrcweir // Call next context in chain if found 96cdf0e10cSrcweir retVal = m_xNextContext->getValueByName( Name ); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir return retVal; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir 102cdf0e10cSrcweir } 103