1 /*************************************************************************
2 *
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2000, 2011 Oracle and/or its affiliates.
6 *
7 * OpenOffice.org - a multi-platform office productivity suite
8 *
9 * This file is part of OpenOffice.org.
10 *
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
14 *
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
20 *
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org.  If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
25 *
26 ************************************************************************/
27 
28 #ifndef INCLUDED_BINARYURP_SOURCE_BRIDGEFACTORY_HXX
29 #define INCLUDED_BINARYURP_SOURCE_BRIDGEFACTORY_HXX
30 
31 #include "sal/config.h"
32 
33 #include <list>
34 #include <map>
35 
36 #include "boost/noncopyable.hpp"
37 #include "com/sun/star/bridge/XBridgeFactory.hpp"
38 #include "com/sun/star/lang/XServiceInfo.hpp"
39 #include "com/sun/star/uno/Exception.hpp"
40 #include "com/sun/star/uno/Reference.hxx"
41 #include "com/sun/star/uno/RuntimeException.hpp"
42 #include "cppuhelper/compbase2.hxx"
43 #include "sal/types.h"
44 
45 namespace com { namespace sun { namespace star {
46     namespace connection { class XConnection; }
47     namespace uno {
48         class XComponentContext;
49         class XInterface;
50     }
51 } } }
52 
53 namespace binaryurp {
54 
55 // That BridgeFactory derives from XComponent appears to be a historic mistake;
56 // the implementation does not care about a disposed state:
57 
58 typedef
59     cppu::WeakComponentImplHelper2<
60         com::sun::star::lang::XServiceInfo,
61         com::sun::star::bridge::XBridgeFactory >
62     BridgeFactoryBase;
63 
64 class BridgeFactory:
65     private osl::Mutex, public BridgeFactoryBase, private boost::noncopyable
66 {
67 public:
68     static com::sun::star::uno::Reference< com::sun::star::uno::XInterface >
69     SAL_CALL static_create(
70         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
71             const & xContext)
72         SAL_THROW((com::sun::star::uno::Exception));
73 
74     static rtl::OUString SAL_CALL static_getImplementationName();
75 
76     static com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
77     static_getSupportedServiceNames();
78 
79     void removeBridge(
80         com::sun::star::uno::Reference< com::sun::star::bridge::XBridge >
81             const & bridge);
82 
83     using BridgeFactoryBase::acquire;
84     using BridgeFactoryBase::release;
85 
86 private:
87     explicit BridgeFactory(
88         com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
89             const & context);
90 
91     virtual ~BridgeFactory();
92 
93     virtual rtl::OUString SAL_CALL getImplementationName()
94         throw (com::sun::star::uno::RuntimeException);
95 
96     virtual sal_Bool SAL_CALL supportsService(rtl::OUString const & ServiceName)
97         throw (com::sun::star::uno::RuntimeException);
98 
99     virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL
100     getSupportedServiceNames() throw (com::sun::star::uno::RuntimeException);
101 
102     virtual com::sun::star::uno::Reference< com::sun::star::bridge::XBridge >
103     SAL_CALL createBridge(
104         rtl::OUString const & sName, rtl::OUString const & sProtocol,
105         com::sun::star::uno::Reference<
106             com::sun::star::connection::XConnection > const & aConnection,
107         com::sun::star::uno::Reference<
108             com::sun::star::bridge::XInstanceProvider > const &
109                 anInstanceProvider)
110         throw (
111             com::sun::star::bridge::BridgeExistsException,
112             com::sun::star::lang::IllegalArgumentException,
113             com::sun::star::uno::RuntimeException);
114 
115     virtual com::sun::star::uno::Reference< com::sun::star::bridge::XBridge >
116     SAL_CALL getBridge(
117         rtl::OUString const & sName)
118         throw (com::sun::star::uno::RuntimeException);
119 
120     virtual
121     com::sun::star::uno::Sequence<
122         com::sun::star::uno::Reference< com::sun::star::bridge::XBridge > >
123     SAL_CALL getExistingBridges() throw (com::sun::star::uno::RuntimeException);
124 
125     typedef
126         std::list<
127             com::sun::star::uno::Reference< com::sun::star::bridge::XBridge > >
128         BridgeList;
129 
130     typedef
131         std::map<
132             rtl::OUString,
133             com::sun::star::uno::Reference< com::sun::star::bridge::XBridge > >
134         BridgeMap;
135 
136     com::sun::star::uno::Reference< com::sun::star::uno::XComponentContext >
137         context_;
138     BridgeList unnamed_;
139     BridgeMap named_;
140 };
141 
142 }
143 
144 #endif
145