1 /*
2 * Copyright 2007-2010 The Kuali Foundation
3 *
4 * Licensed under the Educational Community License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/ecl2.php
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.kuali.rice.core.util.jaxb;
17
18 import javax.xml.bind.annotation.adapters.XmlAdapter;
19 import javax.xml.namespace.QName;
20
21 /**
22 * Marshall/unmarshall {@link QName} to and from a String value. If you do
23 * not use this adapter then you might end up with xml like the following:
24 *
25 * <p>{@code
26 * <serviceName xmlns:ns2="TEST">ns2:myService</serviceName>
27 * }
28 *
29 * <p>Instead of:
30 *
31 * <p>{@code
32 * <serviceName>{TEST}myService</serviceName>
33 * }
34 *
35 * @author Kuali Rice Team (rice.collab@kuali.org)
36 *
37 */
38 public class QNameAsStringAdapter extends XmlAdapter<String, QName> {
39
40 @Override
41 public String marshal(QName qName) throws Exception {
42 return qName == null ? null : qName.toString();
43 }
44
45 @Override
46 public QName unmarshal(String qNameValue) throws Exception {
47 return qNameValue == null ? null : QName.valueOf(qNameValue);
48 }
49 }