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 
JavaContext(const Reference<XCurrentContext> & ctx)37 JavaContext::JavaContext( const Reference< XCurrentContext > & ctx )
38     :
39     m_aRefCount(0),
40     m_xNextContext( ctx ),
41     m_bShowErrorsOnce(false)
42 {
43 }
44 
JavaContext(const Reference<XCurrentContext> & ctx,bool bShowErrorsOnce)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 
~JavaContext()53 JavaContext::~JavaContext()
54 {
55 }
56 
queryInterface(const Type & aType)57 Any SAL_CALL JavaContext::queryInterface(const Type& aType )
58     throw (RuntimeException)
59 {
60     if (aType == getCppuType(reinterpret_cast<Reference<XInterface>*>(0)))
61         return Any(Reference<XInterface>(static_cast<XInterface*>(this)));
62     else if (aType == getCppuType(reinterpret_cast<Reference<XCurrentContext>*>(0)))
63         return Any(Reference<XCurrentContext>( static_cast<XCurrentContext*>(this)));
64     return Any();
65 }
66 
acquire()67 void SAL_CALL JavaContext::acquire(  ) throw ()
68 {
69     osl_incrementInterlockedCount( &m_aRefCount );
70 }
71 
release()72 void SAL_CALL JavaContext::release(  ) throw ()
73 {
74     if (! osl_decrementInterlockedCount( &m_aRefCount ))
75 		delete this;
76 }
77 
getValueByName(const::rtl::OUString & Name)78 Any SAL_CALL JavaContext::getValueByName( const ::rtl::OUString& Name) throw (RuntimeException)
79 {
80     Any retVal;
81 
82     if ( 0 == Name.compareToAscii( JAVA_INTERACTION_HANDLER_NAME ))
83     {
84         {
85             osl::MutexGuard aGuard(osl::Mutex::getGlobalMutex());
86             if (!m_xHandler.is())
87                 m_xHandler = Reference< XInteractionHandler >(
88                     new JavaInteractionHandler(m_bShowErrorsOnce));
89         }
90         retVal = makeAny(m_xHandler);
91 
92     }
93 	else if( m_xNextContext.is() )
94 	{
95         // Call next context in chain if found
96         retVal = m_xNextContext->getValueByName( Name );
97 	}
98     return retVal;
99 }
100 
101 
102 }
103