xref: /aoo42x/main/unoxml/source/rdf/CBlankNode.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #include "CNodes.hxx"
29*cdf0e10cSrcweir 
30*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>
31*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
33*cdf0e10cSrcweir #include <com/sun/star/rdf/XBlankNode.hpp>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir /// anonymous implementation namespace
39*cdf0e10cSrcweir namespace {
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir namespace css = ::com::sun::star;
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir class CBlankNode:
44*cdf0e10cSrcweir     public ::cppu::WeakImplHelper3<
45*cdf0e10cSrcweir         css::lang::XServiceInfo,
46*cdf0e10cSrcweir         css::lang::XInitialization,
47*cdf0e10cSrcweir         css::rdf::XBlankNode>
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir public:
50*cdf0e10cSrcweir     explicit CBlankNode(css::uno::Reference< css::uno::XComponentContext > const & context);
51*cdf0e10cSrcweir     virtual ~CBlankNode() {}
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir     // ::com::sun::star::lang::XServiceInfo:
54*cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getImplementationName() throw (css::uno::RuntimeException);
55*cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL supportsService(const ::rtl::OUString & ServiceName) throw (css::uno::RuntimeException);
56*cdf0e10cSrcweir     virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException);
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir     // ::com::sun::star::lang::XInitialization:
59*cdf0e10cSrcweir     virtual void SAL_CALL initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception);
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir     // ::com::sun::star::rdf::XNode:
62*cdf0e10cSrcweir     virtual ::rtl::OUString SAL_CALL getStringValue() throw (css::uno::RuntimeException);
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir private:
65*cdf0e10cSrcweir     CBlankNode(const CBlankNode &); // not defined
66*cdf0e10cSrcweir     CBlankNode& operator=(const CBlankNode &); // not defined
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir     css::uno::Reference< css::uno::XComponentContext > m_xContext;
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     ::rtl::OUString m_NodeID;
71*cdf0e10cSrcweir };
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir CBlankNode::CBlankNode(css::uno::Reference< css::uno::XComponentContext > const & context) :
74*cdf0e10cSrcweir     m_xContext(context), m_NodeID()
75*cdf0e10cSrcweir {}
76*cdf0e10cSrcweir 
77*cdf0e10cSrcweir // com.sun.star.uno.XServiceInfo:
78*cdf0e10cSrcweir ::rtl::OUString SAL_CALL CBlankNode::getImplementationName() throw (css::uno::RuntimeException)
79*cdf0e10cSrcweir {
80*cdf0e10cSrcweir     return comp_CBlankNode::_getImplementationName();
81*cdf0e10cSrcweir }
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir ::sal_Bool SAL_CALL CBlankNode::supportsService(::rtl::OUString const & serviceName) throw (css::uno::RuntimeException)
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString > serviceNames = comp_CBlankNode::_getSupportedServiceNames();
86*cdf0e10cSrcweir     for (::sal_Int32 i = 0; i < serviceNames.getLength(); ++i) {
87*cdf0e10cSrcweir         if (serviceNames[i] == serviceName)
88*cdf0e10cSrcweir             return sal_True;
89*cdf0e10cSrcweir     }
90*cdf0e10cSrcweir     return sal_False;
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL CBlankNode::getSupportedServiceNames() throw (css::uno::RuntimeException)
94*cdf0e10cSrcweir {
95*cdf0e10cSrcweir     return comp_CBlankNode::_getSupportedServiceNames();
96*cdf0e10cSrcweir }
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir // ::com::sun::star::lang::XInitialization:
99*cdf0e10cSrcweir void SAL_CALL CBlankNode::initialize(const css::uno::Sequence< ::com::sun::star::uno::Any > & aArguments) throw (css::uno::RuntimeException, css::uno::Exception)
100*cdf0e10cSrcweir {
101*cdf0e10cSrcweir     if (aArguments.getLength() != 1) {
102*cdf0e10cSrcweir         throw css::lang::IllegalArgumentException(
103*cdf0e10cSrcweir             ::rtl::OUString::createFromAscii("CBlankNode::initialize: "
104*cdf0e10cSrcweir                 "must give exactly 1 argument"), *this, 1);
105*cdf0e10cSrcweir     }
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     ::rtl::OUString arg;
108*cdf0e10cSrcweir     if (!(aArguments[0] >>= arg)) {
109*cdf0e10cSrcweir         throw css::lang::IllegalArgumentException(
110*cdf0e10cSrcweir             ::rtl::OUString::createFromAscii("CBlankNode::initialize: "
111*cdf0e10cSrcweir                 "argument must be string"), *this, 0);
112*cdf0e10cSrcweir     }
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     //FIXME: what is legal?
115*cdf0e10cSrcweir     if (arg.getLength() > 0) {
116*cdf0e10cSrcweir         m_NodeID = arg;
117*cdf0e10cSrcweir     } else {
118*cdf0e10cSrcweir         throw css::lang::IllegalArgumentException(
119*cdf0e10cSrcweir             ::rtl::OUString::createFromAscii("CBlankNode::initialize: "
120*cdf0e10cSrcweir                 "argument is not valid blank node ID"), *this, 0);
121*cdf0e10cSrcweir     }
122*cdf0e10cSrcweir }
123*cdf0e10cSrcweir 
124*cdf0e10cSrcweir // ::com::sun::star::rdf::XNode:
125*cdf0e10cSrcweir ::rtl::OUString SAL_CALL CBlankNode::getStringValue() throw (css::uno::RuntimeException)
126*cdf0e10cSrcweir {
127*cdf0e10cSrcweir     return m_NodeID;
128*cdf0e10cSrcweir }
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir } // closing anonymous implementation namespace
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir // component helper namespace
135*cdf0e10cSrcweir namespace comp_CBlankNode {
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir ::rtl::OUString SAL_CALL _getImplementationName() {
138*cdf0e10cSrcweir     return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
139*cdf0e10cSrcweir         "CBlankNode"));
140*cdf0e10cSrcweir }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir css::uno::Sequence< ::rtl::OUString > SAL_CALL _getSupportedServiceNames()
143*cdf0e10cSrcweir {
144*cdf0e10cSrcweir     css::uno::Sequence< ::rtl::OUString > s(1);
145*cdf0e10cSrcweir     s[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(
146*cdf0e10cSrcweir         "com.sun.star.rdf.BlankNode"));
147*cdf0e10cSrcweir     return s;
148*cdf0e10cSrcweir }
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir css::uno::Reference< css::uno::XInterface > SAL_CALL _create(
151*cdf0e10cSrcweir     const css::uno::Reference< css::uno::XComponentContext > & context)
152*cdf0e10cSrcweir         SAL_THROW((css::uno::Exception))
153*cdf0e10cSrcweir {
154*cdf0e10cSrcweir     return static_cast< ::cppu::OWeakObject * >(new CBlankNode(context));
155*cdf0e10cSrcweir }
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir } // closing component helper namespace
158*cdf0e10cSrcweir 
159