1 /*
2 * Licensed to The Apereo Foundation under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work for additional
4 * information regarding copyright ownership.
5 *
6 *
7 * The Apereo Foundation licenses this file to you under the Educational
8 * Community License, Version 2.0 (the "License"); you may not use this file
9 * except in compliance with the License. You may obtain a copy of the License
10 * at:
11 *
12 * http://opensource.org/licenses/ecl2.txt
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 * License for the specific language governing permissions and limitations under
18 * the License.
19 *
20 */
21
22 package org.opencastproject.util;
23
24 import static org.opencastproject.util.EqualsUtil.eq;
25 import static org.opencastproject.util.EqualsUtil.hash;
26
27 import java.io.Serializable;
28
29 /**
30 * Declaration of an XML namespace binding which is the association of a prefix to a namespace URI (namespace name).
31 * <p>
32 * See <a href="http://www.w3.org/TR/xml-names11/#sec-namespaces">W3C specification</a> for details.
33 */
34 public final class XmlNamespaceBinding implements Serializable {
35 private static final long serialVersionUID = -3189348197739705012L;
36
37 private final String prefix;
38 private final String namespaceURI;
39
40 /**
41 * Bind a prefix to a namespace URI (namespace name).
42 *
43 * @param prefix a prefix or the empty string ({@link javax.xml.XMLConstants#DEFAULT_NS_PREFIX}) to bind
44 * the default namespace
45 * @param namespaceURI Either a URI or the empty string ({@link javax.xml.XMLConstants#NULL_NS_URI}).
46 * See <a href="http://www.w3.org/TR/REC-xml-names/#ns-decl">Declaring Namespaces</a>
47 * for details about namespace declarations.
48 */
49 public XmlNamespaceBinding(String prefix, String namespaceURI) {
50 this.prefix = RequireUtil.notNull(prefix, "prefix");
51 this.namespaceURI = RequireUtil.notNull(namespaceURI, "namespaceURI");
52 }
53
54 /**
55 * Constructor method.
56 *
57 * @see org.opencastproject.util.XmlNamespaceBinding#XmlNamespaceBinding(String, String)
58 */
59 public static XmlNamespaceBinding mk(String prefix, String namespaceURI) {
60 return new XmlNamespaceBinding(prefix, namespaceURI);
61 }
62
63 public String getPrefix() {
64 return prefix;
65 }
66
67 public String getNamespaceURI() {
68 return namespaceURI;
69 }
70
71 @Override public int hashCode() {
72 return hash(prefix, namespaceURI);
73 }
74
75 @Override public boolean equals(Object that) {
76 return (this == that) || (that instanceof XmlNamespaceBinding && eqFields((XmlNamespaceBinding) that));
77 }
78
79 private boolean eqFields(XmlNamespaceBinding that) {
80 return eq(prefix, that.prefix) && eq(namespaceURI, that.namespaceURI);
81 }
82 }