You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by mr...@apache.org on 2007/05/04 10:27:22 UTC
svn commit: r535127 -
/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/NameValue.java
Author: mreutegg
Date: Fri May 4 01:27:21 2007
New Revision: 535127
URL: http://svn.apache.org/viewvc?view=rev&rev=535127
Log:
JCR-896: Unnecessary parsing of Name value
- add factory method that takes QName and NamespaceResolver
Modified:
jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/NameValue.java
Modified: jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/NameValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/NameValue.java?view=diff&rev=535127&r1=535126&r2=535127
==============================================================================
--- jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/NameValue.java (original)
+++ jackrabbit/trunk/jackrabbit-jcr-commons/src/main/java/org/apache/jackrabbit/value/NameValue.java Fri May 4 01:27:21 2007
@@ -18,6 +18,9 @@
import org.apache.jackrabbit.name.NameFormat;
import org.apache.jackrabbit.name.IllegalNameException;
+import org.apache.jackrabbit.name.QName;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.name.NoPrefixDeclaredException;
import javax.jcr.PropertyType;
import javax.jcr.RepositoryException;
@@ -57,6 +60,28 @@
return new NameValue(s);
} else {
throw new ValueFormatException("not a valid name format");
+ }
+ }
+
+ /**
+ * Returns a new <code>NameValue</code> initialized to the value represented
+ * by the specified <code>QName</code> formatted to a string using the
+ * specified <code>resolver</code>.
+ *
+ * @param name the name to format.
+ * @param resolver a namespace resolver the resolve the URI in the name to a
+ * prefix.
+ * @return a newly constructed <code>NameValue</code> representing the the
+ * specified value.
+ * @throws ValueFormatException If the <code>QName</code> contains a URI
+ * that is not known to <code>resolver</code>.
+ */
+ public static NameValue valueOf(QName name, NamespaceResolver resolver)
+ throws ValueFormatException {
+ try {
+ return new NameValue(NameFormat.format(name, resolver));
+ } catch (NoPrefixDeclaredException e) {
+ throw new ValueFormatException(e.getMessage());
}
}