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 : class CBlankNode:
34 : public ::cppu::WeakImplHelper3<
35 : css::lang::XServiceInfo,
36 : css::lang::XInitialization,
37 : css::rdf::XBlankNode>
38 : {
39 : public:
40 : explicit CBlankNode(css::uno::Reference< css::uno::XComponentContext > const & context);
41 66 : virtual ~CBlankNode() {}
42 :
43 : // ::com::sun::star::lang::XServiceInfo:
44 : virtual OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException);
45 : virtual ::sal_Bool SAL_CALL supportsService(const OUString & ServiceName) throw (css::uno::RuntimeException);
46 : virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException);
47 :
48 : // ::com::sun::star::lang::XInitialization:
49 : virtual void SAL_CALL initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception);
50 :
51 : // ::com::sun::star::rdf::XNode:
52 : virtual OUString SAL_CALL getStringValue() throw (css::uno::RuntimeException);
53 :
54 : private:
55 : CBlankNode(const CBlankNode &); // not defined
56 : CBlankNode& operator=(const CBlankNode &); // not defined
57 :
58 : css::uno::Reference< css::uno::XComponentContext > m_xContext;
59 :
60 : OUString m_NodeID;
61 : };
62 :
63 33 : CBlankNode::CBlankNode(css::uno::Reference< css::uno::XComponentContext > const & context) :
64 33 : m_xContext(context), m_NodeID()
65 33 : {}
66 :
67 : // com.sun.star.uno.XServiceInfo:
68 0 : OUString SAL_CALL CBlankNode::getImplementationName() throw (css::uno::RuntimeException)
69 : {
70 0 : return comp_CBlankNode::_getImplementationName();
71 : }
72 :
73 0 : ::sal_Bool SAL_CALL CBlankNode::supportsService(OUString const & serviceName) throw (css::uno::RuntimeException)
74 : {
75 0 : css::uno::Sequence< OUString > serviceNames = comp_CBlankNode::_getSupportedServiceNames();
76 0 : for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
77 0 : if (serviceNames[i] == serviceName)
78 0 : return sal_True;
79 : }
80 0 : return sal_False;
81 : }
82 :
83 0 : css::uno::Sequence< OUString > SAL_CALL CBlankNode::getSupportedServiceNames() throw (css::uno::RuntimeException)
84 : {
85 0 : return comp_CBlankNode::_getSupportedServiceNames();
86 : }
87 :
88 : // ::com::sun::star::lang::XInitialization:
89 33 : void SAL_CALL CBlankNode::initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception)
90 : {
91 33 : if (aArguments.getLength() != 1) {
92 : throw css::lang::IllegalArgumentException(
93 : OUString("CBlankNode::initialize: "
94 0 : "must give exactly 1 argument"), *this, 1);
95 : }
96 :
97 33 : OUString arg;
98 33 : if (!(aArguments[0] >>= arg)) {
99 : throw css::lang::IllegalArgumentException(
100 : OUString("CBlankNode::initialize: "
101 0 : "argument must be string"), *this, 0);
102 : }
103 :
104 : //FIXME: what is legal?
105 33 : if (!arg.isEmpty()) {
106 33 : m_NodeID = arg;
107 : } else {
108 : throw css::lang::IllegalArgumentException(
109 : OUString("CBlankNode::initialize: "
110 0 : "argument is not valid blank node ID"), *this, 0);
111 33 : }
112 33 : }
113 :
114 : // ::com::sun::star::rdf::XNode:
115 44 : OUString SAL_CALL CBlankNode::getStringValue() throw (css::uno::RuntimeException)
116 : {
117 44 : return m_NodeID;
118 : }
119 :
120 : } // closing anonymous implementation namespace
121 :
122 :
123 :
124 : // component helper namespace
125 : namespace comp_CBlankNode {
126 :
127 65 : OUString SAL_CALL _getImplementationName() {
128 65 : return OUString( "CBlankNode");
129 : }
130 :
131 2 : css::uno::Sequence< OUString > SAL_CALL _getSupportedServiceNames()
132 : {
133 2 : css::uno::Sequence< OUString > s(1);
134 2 : s[0] = "com.sun.star.rdf.BlankNode";
135 2 : return s;
136 : }
137 :
138 33 : css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
139 : const css::uno::Reference< css::uno::XComponentContext > & context)
140 : SAL_THROW((css::uno::Exception))
141 : {
142 33 : return static_cast< ::cppu::OWeakObject * >(new CBlankNode(context));
143 : }
144 :
145 : } // closing component helper namespace
146 :
147 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|