Interface PrefixMapping
-
- All Known Implementing Classes:
InfModelImpl
,ModelCom
,MonitorModel
,OntModelImpl
,PolyadicPrefixMappingImpl
,PrefixMappingImpl
public interface PrefixMapping
Methods for recording namespace prefix mappings and applying and unapplying them to URIs.Note that a Model *is* a PrefixMapping, so all the PrefixMapping operations apply to Models, and a Model can be used to supply the PrefixMapping argument to setNsPrefixes.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
PrefixMapping.Factory
Factory class to create an unspecified kind of PrefixMapping.static class
PrefixMapping.IllegalPrefixException
Exception to throw when the prefix argument to setNsPrefix is illegal for some reason.static class
PrefixMapping.JenaLockedException
Exception to throw when trying to update a locked PrefixMapping.
-
Field Summary
Fields Modifier and Type Field Description static PrefixMapping
Extended
A PrefixMapping built on Standard with some extrasstatic PrefixMapping
Standard
A PrefixMapping that contains the "standard" prefixes we know about, viz rdf, rdfs, dc, rss, vcard, and owl.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description PrefixMapping
clearNsPrefixMap()
Clear this prefix mapping of all mappingsjava.lang.String
expandPrefix(java.lang.String prefixed)
Expand the uri using the prefix mappings if possible.java.util.Map<java.lang.String,java.lang.String>
getNsPrefixMap()
Return a copy of the internal mapping from names to URI strings.java.lang.String
getNsPrefixURI(java.lang.String prefix)
Get the URI bound to a specific prefix, null if there isn't one.java.lang.String
getNsURIPrefix(java.lang.String uri)
Answer the prefix for the given URI, or null if there isn't one.default boolean
hasNoMappings()
Return whether the prefix mapping has any defined prefixes.PrefixMapping
lock()
Lock the PrefixMapping so that changes can no longer be made to it.int
numPrefixes()
Return the number of defined prefixes.java.lang.String
qnameFor(java.lang.String uri)
Answer a qname with the expansion of the given uri, or null if no such qname can be constructed using the mapping's prefixes.PrefixMapping
removeNsPrefix(java.lang.String prefix)
Remove any existing maplet with the given prefix name and answer this mapping.boolean
samePrefixMappingAs(PrefixMapping other)
Answer true iff this prefix-mappings are equal, that is, map the same prefixes to the same URIs; same as this.getNsPrefixMap().equals( other.getNsPrefixMap() ) except that it may avoid unnecessary Map creations.PrefixMapping
setNsPrefix(java.lang.String prefix, java.lang.String uri)
Specify the prefix name for a URI prefix string.PrefixMapping
setNsPrefixes(java.util.Map<java.lang.String,java.lang.String> map)
Copies the prefix mapping from other into this.PrefixMapping
setNsPrefixes(PrefixMapping other)
Copies the prefixes from other into this.java.lang.String
shortForm(java.lang.String uri)
Compress the URI using the prefix mappings if possible.PrefixMapping
withDefaultMappings(PrefixMapping map)
Update this PrefixMapping with the bindings inmap
, only adding those (p, u) pairs for which neither p nor u appears in this mapping.
-
-
-
Field Detail
-
Standard
static final PrefixMapping Standard
A PrefixMapping that contains the "standard" prefixes we know about, viz rdf, rdfs, dc, rss, vcard, and owl.
-
Extended
static final PrefixMapping Extended
A PrefixMapping built on Standard with some extras
-
-
Method Detail
-
setNsPrefix
PrefixMapping setNsPrefix(java.lang.String prefix, java.lang.String uri)
Specify the prefix name for a URI prefix string. Any existing use of that prefix name is overwritten. The result is this same prefixMapping. (The earlier restriction that adding second prefix for the same URI caused the earlier binding to be deleted has been withdrawn.)A prefix name must be a valid NCName, or the empty string. The empty string is reserved to mean "the default namespace".
Need not check the RFC2396 validity of the URI. Bad URIs are either silently ignored or behave as if they were good. The earlier restriction that the URI should end with a non-NCName character has been removed.
Note, in particular, that the prefix mapping can only be used if it includes the URI up to any '#' character because '#' is not legal in the local part of an NCName.
- Parameters:
prefix
- the string to be used for the prefix.uri
- the URI prefix to be named- Returns:
- this PrefixMapping
- Throws:
PrefixMapping.IllegalPrefixException
- if the prefix is not an XML NCName
-
removeNsPrefix
PrefixMapping removeNsPrefix(java.lang.String prefix)
Remove any existing maplet with the given prefix name and answer this mapping. If the prefix is the empty string, then this removes the default namespace. If the prefix is not a legal prefix string, or is not present in the mapping, nothing happens.The reverse URI-to-prefix mapping is updated, but if there are multiple prefixes for the removed URI it is unspecified which of them will be chosen.
- Parameters:
prefix
- the prefix string to remove- Returns:
- this PrefixMapping
-
clearNsPrefixMap
PrefixMapping clearNsPrefixMap()
Clear this prefix mapping of all mappings
-
setNsPrefixes
PrefixMapping setNsPrefixes(PrefixMapping other)
Copies the prefixes from other into this. Any existing binding of the same prefix is lost. The result is this same prefixMapping.- Parameters:
other
- the PrefixMapping to add- Returns:
- this PrefixMapping
-
setNsPrefixes
PrefixMapping setNsPrefixes(java.util.Map<java.lang.String,java.lang.String> map)
Copies the prefix mapping from other into this. Illegal prefix mappings are detected. Existing binds of the same prefix are lost. The result is this same prefixMapping.- Parameters:
map
- the Map whose maplets are to be added- Returns:
- this PrefixMapping
-
withDefaultMappings
PrefixMapping withDefaultMappings(PrefixMapping map)
Update this PrefixMapping with the bindings inmap
, only adding those (p, u) pairs for which neither p nor u appears in this mapping. Answer this PrefixMapping.
-
getNsPrefixURI
java.lang.String getNsPrefixURI(java.lang.String prefix)
Get the URI bound to a specific prefix, null if there isn't one.- Parameters:
prefix
- the prefix name to be looked up- Returns:
- the most recent URI bound to that prefix name, null if none
-
getNsURIPrefix
java.lang.String getNsURIPrefix(java.lang.String uri)
Answer the prefix for the given URI, or null if there isn't one. If there is more than one, one of them will be picked. If possible, it will be the most recently added prefix. (The cases where it's not possible is when a binding has been removed.)- Parameters:
uri
- the uri whose prefix is to be found- Returns:
- the prefix mapped to that uri, or null if there isn't one
-
getNsPrefixMap
java.util.Map<java.lang.String,java.lang.String> getNsPrefixMap()
Return a copy of the internal mapping from names to URI strings. Updating this copy will have no effect on the PrefixMap.- Returns:
- a copy of the internal String -> String mapping
-
expandPrefix
java.lang.String expandPrefix(java.lang.String prefixed)
Expand the uri using the prefix mappings if possible. If prefixed has the form Foo:Bar, and Foo is a prefix bound to FooURI, return FooURI+Bar. Otherwise return prefixed unchanged.- Parameters:
prefixed
- a QName or URI- Returns:
- the expanded string if possible, otherwise the original string
-
shortForm
java.lang.String shortForm(java.lang.String uri)
Compress the URI using the prefix mappings if possible. If there is a prefix mapping Name -> URIStart, and uri is URIStart+Tail, return Name:Tail; otherwise return uri unchanged. If there are multiple applicable mappings available, the "most recent" is chosen if that is possible, otherwise one is picked "at random".The result is primarily intended for human convenience: it is not necessarily a legal QName, as Tail need not be a legal NCName; and there's no way to tell a shortened name from a URI with an unusual scheme.
- Parameters:
uri
- the URI string to try and prefix-compress- Returns:
- the shortened form if possible, otherwise the unchanged argument
-
qnameFor
java.lang.String qnameFor(java.lang.String uri)
Answer a qname with the expansion of the given uri, or null if no such qname can be constructed using the mapping's prefixes.
-
lock
PrefixMapping lock()
Lock the PrefixMapping so that changes can no longer be made to it. Primarily intended to lock Standard against mutation.- Returns:
- this mapping, locked against changes
-
hasNoMappings
default boolean hasNoMappings()
Return whether the prefix mapping has any defined prefixes.
-
numPrefixes
int numPrefixes()
Return the number of defined prefixes.
-
samePrefixMappingAs
boolean samePrefixMappingAs(PrefixMapping other)
Answer true iff this prefix-mappings are equal, that is, map the same prefixes to the same URIs; same asthis.getNsPrefixMap().equals( other.getNsPrefixMap() )
except that it may avoid unnecessary Map creations.
-
-