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