import java.util.regex.Pattern;
import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.objcache.ObjectCache;
+import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
/**
* The QName from XML consists of local name of element and XML namespace, but
*
*/
public final class QName implements Immutable, Serializable, Comparable<QName> {
+ private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(QName.class);
private static final long serialVersionUID = 5398411242927766414L;
static final String QNAME_REVISION_DELIMITER = "?revision=";
+ "(.+)\\)(.+)$");
private static final Pattern QNAME_PATTERN_NO_REVISION = Pattern.compile("^\\((.+)\\)(.+)$");
private static final Pattern QNAME_PATTERN_NO_NAMESPACE_NO_REVISION = Pattern.compile("^(.+)$");
-
private static final char[] ILLEGAL_CHARACTERS = new char[] { '?', '(', ')', '&' };
// Mandatory
this.module = module;
}
+ /**
+ * Look up specified QName in the global cache and return a shared reference.
+ *
+ * @param module QName instance
+ * @return Cached instance, according to {@link ObjectCache} policy.
+ */
+ public static QName cachedReference(final QName qname) {
+ return CACHE.getReference(qname);
+ }
+
/**
* QName Constructor.
*
}
public static QName create(final QName base, final String localName) {
- return new QName(base.getModule(), base.getPrefix(), localName);
+ return create(base.getModule(), base.getPrefix(), localName);
}
/**
* @return Instance of QName
*/
public static QName create(final QNameModule qnameModule, final String localName) {
- return new QName(qnameModule, null, localName);
+ return create(qnameModule, null, localName);
}
/**
* @return Instance of QName
*/
public static QName create(final URI namespace, final Date revision, final String localName) {
- return new QName(QNameModule.create(namespace, revision), null, localName);
+ return create(QNameModule.create(namespace, revision), null, localName);
}
/**
* @return copy of this QName with revision and prefix unset.
*/
public QName withoutRevision() {
- return QName.create(getNamespace(), null, localName);
+ return create(getNamespace(), null, localName);
}
public static Date parseRevision(final String formatedDate) {
import java.util.Date;
import org.opendaylight.yangtools.concepts.Immutable;
+import org.opendaylight.yangtools.objcache.ObjectCache;
+import org.opendaylight.yangtools.objcache.ObjectCacheFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public final class QNameModule implements Immutable, Serializable {
+ private static final ObjectCache CACHE = ObjectCacheFactory.getObjectCache(QNameModule.class);
private static final Logger LOG = LoggerFactory.getLogger(QNameModule.class);
private static final QNameModule NULL_INSTANCE = new QNameModule(null, null);
private static final long serialVersionUID = 1L;
this.revision = revision;
}
+ /**
+ * Look up specified module in the global cache and return a shared reference.
+ *
+ * @param module Module instance
+ * @return Cached instance, according to {@link ObjectCache} policy.
+ */
+ public static QNameModule cachedReference(final QNameModule module) {
+ return CACHE.getReference(module);
+ }
+
+ /**
+ * Create a new QName module instance with specified namespace/revision.
+ *
+ * @param namespace Module namespace
+ * @param revision Module revision
+ * @return A new, potentially shared, QNameModule instance
+ */
public static QNameModule create(final URI namespace, final Date revision) {
if (namespace == null && revision == null) {
return NULL_INSTANCE;