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