1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the
7  * "License"); you may not use this file except in compliance
8  * with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing,
13  * software distributed under the License is distributed on an
14  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15  * KIND, either express or implied. See the License for the
16  * specific language governing permissions and limitations
17  * under the License.
18  */
19 
20 /*
21  * XSEC
22  *
23  * XKMSRecoverKeyBindingImpl := Implementation for RecoverKeyBinding
24  *
25  * $Id$
26  *
27  */
28 
29 // XSEC Includes
30 
31 #include <xsec/framework/XSECDefs.hpp>
32 #include <xsec/framework/XSECError.hpp>
33 #include <xsec/framework/XSECEnv.hpp>
34 
35 
36 #ifdef XSEC_XKMS_ENABLED
37 
38 #include "../../utils/XSECDOMUtils.hpp"
39 
40 #include "XKMSRecoverKeyBindingImpl.hpp"
41 #include "XKMSStatusImpl.hpp"
42 
43 #include <xsec/xkms/XKMSConstants.hpp>
44 
45 #include <xercesc/dom/DOM.hpp>
46 
47 XERCES_CPP_NAMESPACE_USE
48 
49 // --------------------------------------------------------------------------------
50 //           Construct/Destruct
51 // --------------------------------------------------------------------------------
52 
XKMSRecoverKeyBindingImpl(const XSECEnv * env)53 XKMSRecoverKeyBindingImpl::XKMSRecoverKeyBindingImpl(
54 		const XSECEnv * env
55 		) :
56 XKMSKeyBindingAbstractTypeImpl(env) {
57 	mp_status = NULL;
58 }
59 
XKMSRecoverKeyBindingImpl(const XSECEnv * env,XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * node)60 XKMSRecoverKeyBindingImpl::XKMSRecoverKeyBindingImpl(
61 		const XSECEnv * env,
62 		XERCES_CPP_NAMESPACE_QUALIFIER DOMElement * node
63 		) :
64 XKMSKeyBindingAbstractTypeImpl(env, node) {
65 
66 	mp_status = NULL;
67 }
68 
~XKMSRecoverKeyBindingImpl()69 XKMSRecoverKeyBindingImpl::~XKMSRecoverKeyBindingImpl() {
70 
71 	if (mp_status != NULL)
72 		delete mp_status;
73 
74 }
75 
76 // --------------------------------------------------------------------------------
77 //           Load from DOM
78 // --------------------------------------------------------------------------------
79 
load(void)80 void XKMSRecoverKeyBindingImpl::load(void) {
81 
82 	if (mp_keyBindingAbstractTypeElement == NULL) {
83 		throw XSECException(XSECException::ExpectedXKMSChildNotFound,
84 			"XKMSRecoverKeyBindingImpl::load - called on empty DOM");
85 	}
86 
87 	XKMSKeyBindingAbstractTypeImpl::load();
88 
89 	/* Find the status element */
90 	DOMNodeList * nl = mp_keyBindingAbstractTypeElement->getElementsByTagNameNS(
91 		XKMSConstants::s_unicodeStrURIXKMS,
92 		XKMSConstants::s_tagStatus);
93 
94 	if (nl == NULL || nl->getLength() != 1) {
95 		throw XSECException(XSECException::ExpectedXKMSChildNotFound,
96 			"XKMSRecoverKeyBinding::load - Status value not found");
97 	}
98 
99 	XSECnew(mp_status, XKMSStatusImpl(mp_env, (DOMElement*) nl->item(0)));
100 	mp_status->load();
101 
102 }
103 
104 // --------------------------------------------------------------------------------
105 //           Create
106 // --------------------------------------------------------------------------------
107 
createBlankRecoverKeyBinding(XKMSStatus::StatusValue status)108 DOMElement * XKMSRecoverKeyBindingImpl::createBlankRecoverKeyBinding(XKMSStatus::StatusValue status) {
109 
110 	DOMElement * ret = XKMSKeyBindingAbstractTypeImpl::
111 				createBlankKeyBindingAbstractType(XKMSConstants::s_tagRecoverKeyBinding);
112 
113 	mp_env->doPrettyPrint(ret);
114 
115 	// Create the status element
116 	XSECnew(mp_status, XKMSStatusImpl(mp_env));
117 	ret->appendChild(mp_status->createBlankStatus(status));
118 	mp_env->doPrettyPrint(ret);
119 
120 	// Must have an Id
121 	XKMSKeyBindingAbstractTypeImpl::setId();
122 
123 	return ret;
124 
125 }
126 
127 // --------------------------------------------------------------------------------
128 //           Status handling
129 // --------------------------------------------------------------------------------
130 
getStatus(void) const131 XKMSStatus * XKMSRecoverKeyBindingImpl::getStatus(void) const {
132 
133 	return mp_status;
134 
135 }
136 
137 #endif /* XSEC_XKMS_ENABLED */
138