source/service/service.cxx

Go to the documentation of this file.
00001 /*************************************************************************
00002  *
00003  *  The Contents of this file are made available subject to
00004  *  the terms of GNU Lesser General Public License Version 2.1.
00005  *
00006  *
00007  *    GNU Lesser General Public License Version 2.1
00008  *    =============================================
00009  *    Copyright 2005-2008 by Kohei Yoshida.
00010  *    1039 Kingsway Dr., Apex, NC 27502, USA
00011  *
00012  *    This library is free software; you can redistribute it and/or
00013  *    modify it under the terms of the GNU Lesser General Public
00014  *    License version 2.1, as published by the Free Software Foundation.
00015  *
00016  *    This library is distributed in the hope that it will be useful,
00017  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *    Lesser General Public License for more details.
00020  *
00021  *    You should have received a copy of the GNU Lesser General Public
00022  *    License along with this library; if not, write to the Free Software
00023  *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024  *    MA  02111-1307  USA
00025  *
00026  ************************************************************************/
00027 
00028 
00029 #include "solver.hxx"
00030 #include "tool/global.hxx"
00031 #include "dialog.hxx"
00032 #include "lpbuilder.hxx"
00033 #include "xcalc.hxx"
00034 #include "option.hxx"
00035 #include "resmgr.hxx"
00036 #include "solvemodel.hxx"
00037 #include "numeric/matrix.hxx"
00038 
00039 #include "cppuhelper/implementationentry.hxx"
00040 #include "com/sun/star/lang/XComponent.hpp"
00041 #include "com/sun/star/frame/XDispatch.hpp"
00042 
00043 #include <memory>
00044 
00045 using ::rtl::OUString;
00046 
00047 namespace scsolver {
00048 
00049 //--------------------------------------------------------------------------
00050 // Component operations
00051 
00052 static uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames_SolverImpl();
00053 static rtl::OUString getImplementationName_SolverImpl();
00054 static Reference< uno::XInterface > SAL_CALL create_SolverImpl(
00055     Reference< uno::XComponentContext > const & xContext )
00056     SAL_THROW( () );
00057 
00058 
00059 SolverImpl::SolverImpl( Reference< uno::XComponentContext > const & xContext ) :
00060 #ifndef SCSOLVER_UNO_COMPONENT
00061     m_pResMgr(NULL),
00062 #endif    
00063     m_pDlg(NULL), 
00064     m_pCalc(new CalcInterface(xContext)),
00065     m_pOption(new OptionData),
00066     m_pStringResMgr(new StringResMgr(m_pCalc.get()))
00067 {
00068 }
00069 
00070 SolverImpl::~SolverImpl()
00071 {
00072 }
00073 
00074 //--------------------------------------------------------------------------
00075 // UNO Component Interface Methods
00076 
00077 void SolverImpl::initialize( const Sequence< Any >& /*aArgs*/ ) throw( Exception )
00078 {
00079 }
00080 
00081 rtl::OUString SolverImpl::getImplementationName()
00082     throw( RuntimeException )
00083 {
00084     return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLEMENTATION_NAME) );
00085 }
00086 
00087 sal_Bool SolverImpl::supportsService( rtl::OUString const & serviceName )
00088     throw( RuntimeException )
00089 {
00090     return serviceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(SERVICE_NAME) );
00091 }
00092 
00093 Sequence< rtl::OUString > SolverImpl::getSupportedServiceNames()
00094     throw( RuntimeException )
00095 {
00096     return getSupportedServiceNames_SolverImpl();
00097 }
00098 
00099 Reference< frame::XDispatch > SAL_CALL SolverImpl::queryDispatch(
00100     const util::URL& aURL, const ::rtl::OUString& /*sTargetFrameName*/, sal_Int32 /*nSearchFlags*/ )
00101     throw ( RuntimeException )
00102 {
00103     Reference< frame::XDispatch > xRet;
00104     if ( aURL.Protocol.compareToAscii("org.go-oo.comp.CalcSolver:") == 0 )
00105     {
00106         if ( aURL.Path.compareToAscii("execute") == 0 )
00107             xRet = this;
00108     }
00109     return xRet;
00110 }
00111 
00112 Sequence< Reference< frame::XDispatch > > SAL_CALL SolverImpl::queryDispatches(
00113     const Sequence< frame::DispatchDescriptor >& seqDescripts )
00114     throw ( RuntimeException )
00115 {
00116     sal_Int32 nCount = seqDescripts.getLength();
00117     Sequence< Reference< frame::XDispatch > > lDispatcher( nCount );
00118     
00119     for ( sal_Int32 i = 0; i < nCount; ++i )
00120         lDispatcher[i] = queryDispatch( 
00121             seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags );
00122     
00123     return lDispatcher;
00124 }
00125 
00126 void SAL_CALL SolverImpl::dispatch( 
00127     const util::URL& aURL, const Sequence< beans::PropertyValue >& /*lArgs*/ )
00128     throw ( RuntimeException )
00129 {
00130     if ( aURL.Protocol.compareToAscii( "org.go-oo.comp.CalcSolver:" ) == 0 )
00131     {
00132         if ( aURL.Path.compareToAscii( "execute" ) == 0 )
00133         {
00134             execute();
00135         }
00136     }
00137 }
00138 
00139 void SAL_CALL SolverImpl::addStatusListener( 
00140     const Reference< frame::XStatusListener >& /*xControl*/, const util::URL& /*aURL*/ )
00141     throw ( RuntimeException )
00142 {
00143 }
00144 
00145 void SAL_CALL SolverImpl::removeStatusListener( 
00146     const Reference< frame::XStatusListener >& /*xControl*/, const util::URL& /*aURL*/ )
00147     throw ( RuntimeException )
00148 {
00149 }
00150 
00151 void SAL_CALL SolverImpl::dispatchWithNotification(
00152     const util::URL& /*aURL*/, const Sequence< beans::PropertyValue >& /*lArgs*/,
00153     const Reference< frame::XDispatchResultListener >& /*xDRL*/ )
00154     throw ( RuntimeException )
00155 {
00156 }
00157 
00158 SolverDialog* SolverImpl::getMainDialog()
00159 {
00160         if ( m_pDlg.get() == NULL )
00161                 m_pDlg.reset( new SolverDialog( this ) );
00162 
00163         return m_pDlg.get();
00164 }
00165 
00166 CalcInterface* SolverImpl::getCalcInterface() const
00167 {
00168         return m_pCalc.get();
00169 }
00170 
00171 OptionData* SolverImpl::getOptionData() const
00172 {
00173         return m_pOption.get();
00174 }
00175 
00176 void SolverImpl::setTitle( const ::rtl::OUString& /*aTitle*/ )
00177                 throw (uno::RuntimeException)
00178 {
00179 }
00180 
00181 sal_Int16 SolverImpl::execute()
00182                 throw (::com::sun::star::uno::RuntimeException)
00183 {
00184         getMainDialog()->setVisible( true );
00185         return 0;
00186 }
00187 
00188 sal_Bool SolverImpl::solveModel()
00189 {       
00190         Debug("solveModel --------------------------------------------------------");
00191 
00192         ::std::auto_ptr<SolveModel> p( new SolveModel( this ) );
00193         try
00194         {
00195                 p->solve();
00196         }
00197         catch( const RuntimeError& e )
00198         {
00199                 getMainDialog()->showMessage( e.getMessage() );
00200         }
00201 
00202         if ( p->isSolved() )
00203         {
00204                 Debug( "solution available" );
00205                 return true;
00206         }
00207         
00208         return false;
00209 }
00210 
00211 void SolverImpl::initLocale()
00212 {
00213 #ifndef SCSOLVER_UNO_COMPONENT
00214         rtl::OString aModName( "scsolver" );
00215         aModName += rtl::OString::valueOf( sal_Int32( SUPD ) );
00216 
00217         m_pResMgr.reset(ResMgr::CreateResMgr(aModName.getStr(), m_eLocale));
00218 #endif
00219 }
00220 
00221 #ifndef SCSOLVER_UNO_COMPONENT
00222 ResMgr* SolverImpl::getResMgr()
00223 {
00224     if ( !m_pResMgr.get() )
00225         initLocale();
00226     return m_pResMgr.get();
00227 }
00228 #endif
00229 
00230 OUString SolverImpl::getResStr( int resid )
00231 {
00232 #ifdef SCSOLVER_UNO_COMPONENT
00233     return m_pStringResMgr->getLocaleStr(resid);
00234 #else
00235         ResMgr *pResMgr = getResMgr();
00236         if ( pResMgr )
00237         return OUString( String( ResId( resid, *getResMgr() ) ) );
00238     else
00239         return OUString();
00240 #endif
00241 }
00242 
00243 // XLocalizable
00244 
00245 void SAL_CALL SolverImpl::setLocale( const lang::Locale& eLocale )
00246         throw(::com::sun::star::uno::RuntimeException)
00247 {
00248         m_eLocale = eLocale;
00249         initLocale();
00250 }
00251 
00252 lang::Locale SAL_CALL SolverImpl::getLocale()
00253         throw(::com::sun::star::uno::RuntimeException)
00254 {
00255         return m_eLocale;
00256 }
00257 
00258 //---------------------------------------------------------------------------
00259 // Component operations
00260 
00261 static Sequence< rtl::OUString > getSupportedServiceNames_SolverImpl()
00262 {
00263     static Sequence < rtl::OUString > *pNames = 0;
00264     if( !pNames )
00265     {
00266         static Sequence< rtl::OUString > seqNames(1);
00267         seqNames.getArray()[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICE_NAME));
00268         pNames = &seqNames;
00269     }
00270     return *pNames;
00271 }
00272 
00273 static rtl::OUString getImplementationName_SolverImpl()
00274 {
00275     static rtl::OUString *pImplName = 0;
00276     if( !pImplName )
00277     {
00278         static rtl::OUString implName(
00279             RTL_CONSTASCII_USTRINGPARAM(IMPLEMENTATION_NAME));
00280         pImplName = &implName;
00281     }
00282     return *pImplName;
00283 }
00284 
00285 static Reference< uno::XInterface > SAL_CALL create_SolverImpl(
00286     Reference< uno::XComponentContext > const & xContext )
00287     SAL_THROW( () )
00288 {
00289     return static_cast< lang::XTypeProvider * >( new SolverImpl( xContext ) );
00290 }
00291 
00292 
00293 static struct ::cppu::ImplementationEntry s_component_entries [] =
00294 {
00295     {
00296         create_SolverImpl, getImplementationName_SolverImpl,
00297         getSupportedServiceNames_SolverImpl, ::cppu::createSingleComponentFactory,
00298         0, 0
00299     },
00300     { 0, 0, 0, 0, 0, 0 }
00301 };
00302 
00303    
00304 }
00305 
00306 
00307 //------------------------------------------------------------------------------
00308 // Shared library symbol exports
00309 
00310 extern "C"
00311 {
00312     void SAL_DLLPUBLIC_EXPORT component_getImplementationEnvironment(
00313         sal_Char const ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
00314     {
00315         *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
00316     }
00317     
00318     sal_Bool SAL_DLLPUBLIC_EXPORT component_writeInfo(
00319         lang::XMultiServiceFactory * xMgr, registry::XRegistryKey * xRegistry )
00320     {
00321         return ::cppu::component_writeInfoHelper(
00322             xMgr, xRegistry, ::scsolver::s_component_entries );
00323     }
00324 
00325     void SAL_DLLPUBLIC_EXPORT *component_getFactory(
00326         sal_Char const * implName, lang::XMultiServiceFactory * xMgr,
00327         registry::XRegistryKey * xRegistry )
00328     {
00329         return ::cppu::component_getFactoryHelper(
00330             implName, xMgr, xRegistry, ::scsolver::s_component_entries );
00331     }
00332 }

Generated on Mon Jul 28 09:13:20 2008 for scsolver by  doxygen 1.5.3