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