2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.common;
10 import java.io.Serializable;
12 import java.net.URISyntaxException;
13 import java.util.Date;
15 import org.opendaylight.yangtools.concepts.Immutable;
16 import org.slf4j.Logger;
17 import org.slf4j.LoggerFactory;
19 public final class QNameModule implements Immutable, Serializable {
20 private static final Logger LOG = LoggerFactory.getLogger(QNameModule.class);
21 private static final long serialVersionUID = 1L;
24 private final URI namespace;
27 private final Date revision;
30 private String formattedRevision;
32 private QNameModule(final URI namespace, final Date revision) {
33 this.namespace = namespace;
34 this.revision = revision;
37 public static QNameModule create(final URI namespace, final Date revision) {
38 return new QNameModule(namespace, revision);
41 public String getFormattedRevision() {
42 if (revision == null) {
46 if (formattedRevision == null) {
48 if (formattedRevision == null) {
49 formattedRevision = SimpleDateFormatUtil.getRevisionFormat().format(revision);
54 return formattedRevision;
57 public URI getNamespace() {
61 public Date getRevision() {
66 public int hashCode() {
68 int result = (namespace == null) ? 0 : namespace.hashCode();
69 result = prime * result + ((revision == null) ? 0 : revision.hashCode());
74 public boolean equals(final Object obj) {
78 if (!(obj instanceof QNameModule)) {
81 final QNameModule other = (QNameModule) obj;
82 if (namespace == null) {
83 if (other.namespace != null) {
86 } else if (!namespace.equals(other.namespace)) {
89 if (revision == null) {
90 if (other.revision != null) {
93 } else if (!revision.equals(other.revision)) {
100 * Returns a namespace in form defined by section 5.6.4. of {@link https
101 * ://tools.ietf.org/html/rfc6020}, if namespace is not correctly defined,
102 * the method will return <code>null</code> <br>
103 * example "http://example.acme.com/system?revision=2008-04-01"
105 * @return namespace in form defined by section 5.6.4. of {@link https
106 * ://tools.ietf.org/html/rfc6020}, if namespace is not correctly
107 * defined, the method will return <code>null</code>
110 URI getRevisionNamespace() {
112 if (namespace == null) {
117 if (revision != null) {
118 query = "revision=" + getFormattedRevision();
121 URI compositeURI = null;
123 compositeURI = new URI(namespace.getScheme(), namespace.getUserInfo(), namespace.getHost(),
124 namespace.getPort(), namespace.getPath(), query, namespace.getFragment());
125 } catch (URISyntaxException e) {