Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #include "CNodes.hxx"
21 : :
22 : : #include <cppuhelper/implbase3.hxx>
23 : : #include <com/sun/star/lang/XServiceInfo.hpp>
24 : : #include <com/sun/star/lang/XInitialization.hpp>
25 : : #include <com/sun/star/rdf/XBlankNode.hpp>
26 : :
27 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
28 : :
29 : :
30 : : /// anonymous implementation namespace
31 : : namespace {
32 : :
33 : : namespace css = ::com::sun::star;
34 : :
35 : : class CBlankNode:
36 : : public ::cppu::WeakImplHelper3<
37 : : css::lang::XServiceInfo,
38 : : css::lang::XInitialization,
39 : : css::rdf::XBlankNode>
40 : : {
41 : : public:
42 : : explicit CBlankNode(css::uno::Reference< css::uno::XComponentContext > const & context);
43 [ - + ]: 128 : virtual ~CBlankNode() {}
44 : :
45 : : // ::com::sun::star::lang::XServiceInfo:
46 : : virtual ::rtl::OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException);
47 : : virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException);
48 : : virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException);
49 : :
50 : : // ::com::sun::star::lang::XInitialization:
51 : : virtual void SAL_CALL initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception);
52 : :
53 : : // ::com::sun::star::rdf::XNode:
54 : : virtual ::rtl::OUString SAL_CALL getStringValue() throw (css::uno::RuntimeException);
55 : :
56 : : private:
57 : : CBlankNode(const CBlankNode &); // not defined
58 : : CBlankNode& operator=(const CBlankNode &); // not defined
59 : :
60 : : css::uno::Reference< css::uno::XComponentContext > m_xContext;
61 : :
62 : : ::rtl::OUString m_NodeID;
63 : : };
64 : :
65 : 64 : CBlankNode::CBlankNode(css::uno::Reference< css::uno::XComponentContext > const & context) :
66 : 64 : m_xContext(context), m_NodeID()
67 : 64 : {}
68 : :
69 : : // com.sun.star.uno.XServiceInfo:
70 : 0 : ::rtl::OUString SAL_CALL CBlankNode::getImplementationName() throw (css::uno::RuntimeException)
71 : : {
72 : 0 : return comp_CBlankNode::_getImplementationName();
73 : : }
74 : :
75 : 0 : ::sal_Bool SAL_CALL CBlankNode::supportsService(::rtl::OUString const & serviceName) throw (css::uno::RuntimeException)
76 : : {
77 [ # # ]: 0 : css::uno::Sequence< ::rtl::OUString > serviceNames = comp_CBlankNode::_getSupportedServiceNames();
78 [ # # ]: 0 : for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
79 [ # # ][ # # ]: 0 : if (serviceNames[i] == serviceName)
80 : 0 : return sal_True;
81 : : }
82 [ # # ]: 0 : return sal_False;
83 : : }
84 : :
85 : 0 : css::uno::Sequence< ::rtl::OUString > SAL_CALL CBlankNode::getSupportedServiceNames() throw (css::uno::RuntimeException)
86 : : {
87 : 0 : return comp_CBlankNode::_getSupportedServiceNames();
88 : : }
89 : :
90 : : // ::com::sun::star::lang::XInitialization:
91 : 64 : void SAL_CALL CBlankNode::initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception)
92 : : {
93 [ - + ]: 64 : if (aArguments.getLength() != 1) {
94 : : throw css::lang::IllegalArgumentException(
95 : : ::rtl::OUString("CBlankNode::initialize: "
96 [ # # ][ # # ]: 0 : "must give exactly 1 argument"), *this, 1);
97 : : }
98 : :
99 : 64 : ::rtl::OUString arg;
100 [ - + ]: 64 : if (!(aArguments[0] >>= arg)) {
101 : : throw css::lang::IllegalArgumentException(
102 : : ::rtl::OUString("CBlankNode::initialize: "
103 [ # # ][ # # ]: 0 : "argument must be string"), *this, 0);
104 : : }
105 : :
106 : : //FIXME: what is legal?
107 [ + - ]: 64 : if (!arg.isEmpty()) {
108 : 64 : m_NodeID = arg;
109 : : } else {
110 : : throw css::lang::IllegalArgumentException(
111 : : ::rtl::OUString("CBlankNode::initialize: "
112 [ # # ][ # # ]: 0 : "argument is not valid blank node ID"), *this, 0);
113 : 64 : }
114 : 64 : }
115 : :
116 : : // ::com::sun::star::rdf::XNode:
117 : 88 : ::rtl::OUString SAL_CALL CBlankNode::getStringValue() throw (css::uno::RuntimeException)
118 : : {
119 : 88 : return m_NodeID;
120 : : }
121 : :
122 : : } // closing anonymous implementation namespace
123 : :
124 : :
125 : :
126 : : // component helper namespace
127 : : namespace comp_CBlankNode {
128 : :
129 : 50 : ::rtl::OUString SAL_CALL _getImplementationName() {
130 : 50 : return ::rtl::OUString( "CBlankNode");
131 : : }
132 : :
133 : 4 : css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames()
134 : : {
135 : 4 : css::uno::Sequence< ::rtl::OUString > s(1);
136 [ + - ]: 4 : s[0] = ::rtl::OUString( "com.sun.star.rdf.BlankNode");
137 : 4 : return s;
138 : : }
139 : :
140 : 64 : css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
141 : : const css::uno::Reference< css::uno::XComponentContext > & context)
142 : : SAL_THROW((css::uno::Exception))
143 : : {
144 [ + - ]: 64 : return static_cast< ::cppu::OWeakObject * >(new CBlankNode(context));
145 : : }
146 : :
147 : : } // closing component helper namespace
148 : :
149 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|