public class PersistenceURI extends URI
URI
wrapper that creates specific resource URI
s from a File
descriptor or an existing
URI
. All methods are delegated to the internal URI
.
The created URI
are used to register PersistenceBackendFactory
in
PersistenceBackendFactoryRegistry
and configure the protocol to factory
map of an existing
ResourceSet
with a PersistentResourceFactory
.
URI.Fragment, URI.Hierarchical, URI.Opaque, URI.URIPool
Modifier and Type | Field and Description |
---|---|
protected static String |
FILE_SCHEME
The
URI scheme corresponding to a file. |
ALPHA_HI, ALPHA_LO, ALPHANUM_HI, ALPHANUM_LO, ARCHIVE_IDENTIFIER, ARCHIVE_SCHEMES, ARCHIVE_SEPARATOR, AUTHORITY_SEPARATOR, AUTHORITY_SEPARATOR_HASH_CODE, DEBUG, DEVICE_IDENTIFIER, DIGIT_HI, DIGIT_LO, ENCODE_PLATFORM_RESOURCE_URIS, ESCAPE, FILE_EXTENSION_SEPARATOR, FRAGMENT_FIRST_SEPARATOR, FRAGMENT_LAST_SEPARATOR, FRAGMENT_NONE, FRAGMENT_SEPARATOR, hashCode, HEX_DIGITS, HEX_HI, HEX_LO, MAJOR_SEPARATOR_HI, MAJOR_SEPARATOR_LO, NO_SEGMENTS, ONE_EMPTY_SEGMENT, ONE_SELF_SEGMENT, PATH_CHAR_HI, PATH_CHAR_LO, PLATFORM_SEGMENT_RESERVED_HI, PLATFORM_SEGMENT_RESERVED_LO, POOL, PORT_SEPARATOR, QUERY_SEPARATOR, RESERVED_HI, RESERVED_LO, SCHEME_ARCHIVE, SCHEME_ARCHIVE_HASH_CODE, SCHEME_FILE, SCHEME_FILE_HASH_CODE, SCHEME_HTTP, SCHEME_HTTP_HASH_CODE, SCHEME_JAR, SCHEME_JAR_HASH_CODE, SCHEME_PLATFORM, SCHEME_PLATFORM_HASH_CODE, SCHEME_SEPARATOR, SCHEME_ZIP, SCHEME_ZIP_HASH_CODE, SEGMENT_CHAR_HI, SEGMENT_CHAR_LO, SEGMENT_EMPTY, SEGMENT_END_HI, SEGMENT_END_LO, SEGMENT_PARENT, SEGMENT_PLUGIN, SEGMENT_RESOURCE, SEGMENT_SELF, SEGMENT_SEPARATOR, UNRESERVED_HI, UNRESERVED_LO, URIC_HI, URIC_LO, USER_INFO_SEPARATOR
Modifier | Constructor and Description |
---|---|
protected |
PersistenceURI(URI internalUri)
Constructs a new
PersistenceURI from the given internalURI . |
Modifier and Type | Method and Description |
---|---|
URI |
appendFileExtension(String fileExtension)
Returns the URI formed by appending a period (".") followed by the
specified file extension to the last path segment of this URI, if it is
hierarchical with a non-empty path ending in a non-empty segment;
otherwise, this URI is returned unchanged.
|
URI |
appendFragment(String fragment)
Returns the URI formed from this URI and the given fragment.
|
URI |
appendQuery(String query)
Returns the URI formed from this URI and the given query.
|
URI |
appendSegment(String segment)
Returns the URI formed by appending the specified segment on to the end
of the path of this URI, if hierarchical; this URI unchanged,
otherwise.
|
URI |
appendSegments(String[] segments)
Returns the URI formed by appending the specified segments on to the
end of the path of this URI, if hierarchical; this URI unchanged,
otherwise.
|
String |
authority()
If this is a hierarchical URI with an authority component, returns it;
null otherwise. |
static URI |
createFileURI(File file,
String scheme)
Creates a new
PersistenceURI from the given file descriptor. |
static URI |
createFileURI(URI uri,
String scheme)
Creates a new
PersistenceURI from the given uri by checking the referenced file exists on the
file system. |
static URI |
createURI(URI uri)
Creates a new
PersistenceURI from the given uri . |
URI |
deresolve(URI base)
Finds the shortest relative or, if necessary, the absolute URI that,
when resolved against the given
base absolute hierarchical
URI using resolve , will yield this absolute URI. |
URI |
deresolve(URI base,
boolean preserveRootParents,
boolean anyRelPath,
boolean shorterRelPath)
Finds an absolute URI that, when resolved against the given
base absolute hierarchical URI using resolve , will yield this absolute URI. |
String |
device()
If this is a hierarchical URI with a device component, returns it;
null otherwise. |
String |
devicePath()
If this is a hierarchical URI with a path, returns a string
representation of the path, including the authority and the
device component;
null otherwise. |
String |
fileExtension()
If this is a hierarchical URI whose path includes a file extension,
that file extension is returned; null otherwise.
|
String |
fragment()
If this URI has a fragment component, returns it;
null otherwise. |
boolean |
hasAbsolutePath()
Returns
true if this is a hierarchical URI with an
absolute path, or false if it is non-hierarchical, has no
path, or has a relative path. |
boolean |
hasAuthority()
Returns
true if this is a hierarchical URI with an authority
component; false otherwise. |
boolean |
hasDevice()
Returns
true if this is a hierarchical URI with a device
component; false otherwise. |
boolean |
hasEmptyPath()
Returns
true if this is a hierarchical URI with an empty
relative path; false otherwise. |
boolean |
hasFragment()
Returns
true if this URI has a fragment component;
false otherwise. |
int |
hashCode()
Returns the hash code.
|
boolean |
hasOpaquePart()
Returns
true if this is a non-hierarchical URI with an
opaque part component; false otherwise. |
boolean |
hasPath()
Returns
true if this is a hierarchical URI with an
absolute or relative path; false otherwise. |
boolean |
hasQuery()
Returns
true if this is a hierarchical URI with a query
component; false otherwise. |
boolean |
hasRelativePath()
Returns
true if this is a hierarchical URI with a relative
path, or false if it is non-hierarchical, has no path, or
has an absolute path. |
boolean |
hasTrailingPathSeparator()
Returns
true if this is a hierarchical URI that has a path
that ends with a trailing separator; false otherwise. |
String |
host()
If this is a hierarchical URI with an authority component that has a
host portion, returns it;
null otherwise. |
boolean |
isArchive()
Returns
true if this is an archive URI. |
boolean |
isCurrentDocumentReference()
Returns
true if this is a current document reference; that
is, if it is a relative hierarchical URI with no authority, device or
query components, and no path segments; false is returned
otherwise. |
boolean |
isEmpty()
|
boolean |
isFile()
Returns
true if this is a hierarchical URI that may refer
directly to a locally accessible file. |
boolean |
isHierarchical()
Returns
true if this a a hierarchical URI, or
false if it is of the generic form. |
boolean |
isPlatform()
Returns
true if this is a platform URI, that is, an absolute,
hierarchical URI, with "platform" scheme, no authority, and at least two
segments; false is returned otherwise. |
boolean |
isPlatformPlugin()
Returns
true if this is a platform plug-in URI, that is,
a platform URI whose first segment is "plugin";
false is returned otherwise. |
boolean |
isPlatformResource()
Returns
true if this is a platform resource URI, that is,
a platform URI whose first segment is "resource";
false is returned otherwise. |
boolean |
isPrefix()
Returns
true if this is a hierarchical URI that ends in a
slash; that is, it has a trailing path separator or is the root
absolute path, and has no query and no fragment; false
is returned otherwise. |
boolean |
isRelative()
Returns
true if this is a relative URI, or
false if it is an absolute URI. |
String |
lastSegment()
Returns the last segment in the segment array, or
null . |
String |
opaquePart()
If this is a non-hierarchical URI, returns the opaque part component;
null otherwise. |
String |
path()
If this is a hierarchical URI with a path, returns a string
representation of the path;
null otherwise. |
String |
port()
If this is a hierarchical URI with an authority component that has a
port portion, returns it;
null otherwise. |
String |
query()
If this is a hierarchical URI with a query component, returns it;
null otherwise. |
URI |
replacePrefix(URI oldPrefix,
URI newPrefix)
If this is a hierarchical URI reference and
oldPrefix is a
prefix of it, this returns the URI formed by replacing it by
newPrefix ; null otherwise. |
URI |
resolve(URI base)
Resolves this URI reference against a
base absolute
hierarchical URI, returning the resulting absolute URI. |
URI |
resolve(URI base,
boolean preserveRootParents)
Resolves this URI reference against a
base absolute
hierarchical URI, returning the resulting absolute URI. |
String |
scheme()
If this is an absolute URI, returns the scheme component;
null otherwise. |
String |
segment(int i)
Provides fast, indexed access to individual segments in the path
segment array.
|
int |
segmentCount()
Returns the number of elements in the segment array that would be
returned by
segments . |
String[] |
segments()
If this is a hierarchical URI with a path, returns an array containing
the segments of the path; an empty array otherwise.
|
List<String> |
segmentsList()
Returns an unmodifiable list containing the same segments as the array
returned by
segments . |
String |
toFileString()
|
String |
toPlatformString(boolean decode)
If this is a platform URI, as determined by
URI.isPlatform() , returns
the workspace-relative or plug-in-based path to the resource, optionally
decoding the segments in the process. |
String |
toString() |
URI |
trimFileExtension()
If this URI has a non-null
fileExtension ,
returns the URI formed by removing it; this URI unchanged, otherwise. |
URI |
trimFragment()
If this URI has a non-null
fragment , returns the URI
formed by removing it; this URI unchanged, otherwise. |
URI |
trimQuery()
If this URI has a non-null
query , returns the URI
formed by removing it; this URI unchanged, otherwise. |
URI |
trimSegments(int i)
Returns the URI formed by trimming the specified number of segments
(including empty segments, such as one representing a trailing
separator) from the end of the path of this URI, if hierarchical;
otherwise, this URI is returned unchanged.
|
String |
userInfo()
If this is a hierarchical URI with an authority component that has a
user info portion, returns it;
null otherwise. |
appendEscaped, cacheString, collapseSegments, contains, createDeviceURI, createFileURI, createGenericURI, createHierarchicalURI, createHierarchicalURI, createHierarchicalURI, createPlatformPluginURI, createPlatformResourceURI, createPlatformResourceURI, createURI, createURI, createURI, createURIWithCache, decode, encode, encodeAuthority, encodeFragment, encodeOpaquePart, encodeQuery, encodeSegment, encodeURI, equals, firstInvalidSegment, flushCachedString, getCachedString, hasDeviceOrPath, highBitmask, highBitmask, highBitmask, isArchiveScheme, isBase, isEscaped, lowBitmask, lowBitmask, lowBitmask, matches, matches, matches, matches, rawAppendFragment, rawSegments, segmentsEqual, splitInternFragment, unescape, validArchiveAuthority, validateURI, validAuthority, validDevice, validFragment, validJarAuthority, validOpaquePart, validQuery, validScheme, validSegment, validSegments, valueOf
@Nonnull protected static final String FILE_SCHEME
URI
scheme corresponding to a file.protected PersistenceURI(@Nonnull URI internalUri)
PersistenceURI
from the given internalURI
.
This constructor is protected to avoid wrong URI
instantiations. Use createURI(URI)
, createFileURI(File, String)
, or createFileURI(URI, String)
instead.
internalUri
- the base URI
@Nonnull public static URI createURI(@Nonnull URI uri)
PersistenceURI
from the given uri
.
This method checks that the scheme of the provided uri
can be used to create a new PersistenceURI
. Its scheme must be registered in the PersistenceBackendFactoryRegistry
.
uri
- the base URI
URI
NullPointerException
- if the uri
is null
IllegalArgumentException
- if the scheme of the provided uri
is not registered in the PersistenceBackendFactoryRegistry
or if it is FILE_SCHEME
createFileURI(File, String)
,
createFileURI(URI, String)
@Nonnull public static URI createFileURI(@Nonnull File file, @Nullable String scheme)
PersistenceURI
from the given file
descriptor.file
- the File
to build a URI
fromscheme
- the scheme to identify the PersistenceBackendFactory
to useURI
NullPointerException
- if the file
is null
@Nonnull public static URI createFileURI(@Nonnull URI uri, @Nullable String scheme)
PersistenceURI
from the given uri
by checking the referenced file exists on the
file system.uri
- the base URI
scheme
- the scheme to identify the PersistenceBackendFactory
to useURI
NullPointerException
- if the uri
is null
public boolean isRelative()
org.eclipse.emf.common.util.URI
true
if this is a relative URI, or
false
if it is an absolute URI.isRelative
in class URI
public boolean isHierarchical()
org.eclipse.emf.common.util.URI
true
if this a a hierarchical URI, or
false
if it is of the generic form.isHierarchical
in class URI
public boolean hasAuthority()
org.eclipse.emf.common.util.URI
true
if this is a hierarchical URI with an authority
component; false
otherwise.hasAuthority
in class URI
public boolean hasOpaquePart()
org.eclipse.emf.common.util.URI
true
if this is a non-hierarchical URI with an
opaque part component; false
otherwise.hasOpaquePart
in class URI
public boolean hasDevice()
org.eclipse.emf.common.util.URI
true
if this is a hierarchical URI with a device
component; false
otherwise.public boolean hasPath()
org.eclipse.emf.common.util.URI
true
if this is a hierarchical URI with an
absolute or relative path; false
otherwise.public boolean hasAbsolutePath()
org.eclipse.emf.common.util.URI
true
if this is a hierarchical URI with an
absolute path, or false
if it is non-hierarchical, has no
path, or has a relative path.hasAbsolutePath
in class URI
public boolean hasRelativePath()
org.eclipse.emf.common.util.URI
true
if this is a hierarchical URI with a relative
path, or false
if it is non-hierarchical, has no path, or
has an absolute path.hasRelativePath
in class URI
public boolean hasEmptyPath()
org.eclipse.emf.common.util.URI
true
if this is a hierarchical URI with an empty
relative path; false
otherwise.
Note that !hasEmpty()
does not imply that this
URI has any path segments; however, hasRelativePath &&
!hasEmptyPath()
does.
hasEmptyPath
in class URI
public boolean hasQuery()
org.eclipse.emf.common.util.URI
true
if this is a hierarchical URI with a query
component; false
otherwise.public boolean hasFragment()
org.eclipse.emf.common.util.URI
true
if this URI has a fragment component;
false
otherwise.hasFragment
in class URI
public boolean isCurrentDocumentReference()
org.eclipse.emf.common.util.URI
true
if this is a current document reference; that
is, if it is a relative hierarchical URI with no authority, device or
query components, and no path segments; false
is returned
otherwise.isCurrentDocumentReference
in class URI
public boolean isEmpty()
org.eclipse.emf.common.util.URI
isEmpty
in class URI
URI.isCurrentDocumentReference()
public boolean isFile()
org.eclipse.emf.common.util.URI
true
if this is a hierarchical URI that may refer
directly to a locally accessible file. This is considered to be the
case for a file-scheme absolute URI, or for a relative URI with no query;
false
is returned otherwise.public boolean isPlatform()
org.eclipse.emf.common.util.URI
true
if this is a platform URI, that is, an absolute,
hierarchical URI, with "platform" scheme, no authority, and at least two
segments; false
is returned otherwise.isPlatform
in class URI
public boolean isPlatformResource()
org.eclipse.emf.common.util.URI
true
if this is a platform resource URI, that is,
a platform URI
whose first segment is "resource";
false
is returned otherwise.isPlatformResource
in class URI
URI.isPlatform()
public boolean isPlatformPlugin()
org.eclipse.emf.common.util.URI
true
if this is a platform plug-in URI, that is,
a platform URI
whose first segment is "plugin";
false
is returned otherwise.isPlatformPlugin
in class URI
URI.isPlatform()
public boolean isArchive()
org.eclipse.emf.common.util.URI
true
if this is an archive URI. If so, it is also
hierarchical, with an authority (consisting of an absolute URI followed
by "!"), no device, and an absolute path.public int hashCode()
org.eclipse.emf.common.util.URI
public String scheme()
org.eclipse.emf.common.util.URI
null
otherwise.public String opaquePart()
org.eclipse.emf.common.util.URI
null
otherwise.opaquePart
in class URI
public String authority()
org.eclipse.emf.common.util.URI
null
otherwise.public String userInfo()
org.eclipse.emf.common.util.URI
null
otherwise.public String host()
org.eclipse.emf.common.util.URI
null
otherwise.public String port()
org.eclipse.emf.common.util.URI
null
otherwise.public String device()
org.eclipse.emf.common.util.URI
null
otherwise.public String[] segments()
org.eclipse.emf.common.util.URI
public List<String> segmentsList()
org.eclipse.emf.common.util.URI
segments
.segmentsList
in class URI
public int segmentCount()
org.eclipse.emf.common.util.URI
segments
.segmentCount
in class URI
public String segment(int i)
org.eclipse.emf.common.util.URI
public String lastSegment()
org.eclipse.emf.common.util.URI
null
.lastSegment
in class URI
public String path()
org.eclipse.emf.common.util.URI
null
otherwise. The path
consists of a leading segment separator character (a slash), if the
path is absolute, followed by the slash-separated path segments. If
this URI has a separate device
component, it is not included in the path.public String devicePath()
org.eclipse.emf.common.util.URI
null
otherwise.
If there is no authority, the format of this string is:
device/pathSegment1/pathSegment2...
If there is an authority, it is:
//authority/device/pathSegment1/pathSegment2...
For an archive URI, it's just:
authority/pathSegment1/pathSegment2...
devicePath
in class URI
public String query()
org.eclipse.emf.common.util.URI
null
otherwise.public URI appendQuery(String query)
org.eclipse.emf.common.util.URI
appendQuery
in class URI
public URI trimQuery()
org.eclipse.emf.common.util.URI
query
, returns the URI
formed by removing it; this URI unchanged, otherwise.public String fragment()
org.eclipse.emf.common.util.URI
null
otherwise.public URI appendFragment(String fragment)
org.eclipse.emf.common.util.URI
appendFragment
in class URI
public URI trimFragment()
org.eclipse.emf.common.util.URI
fragment
, returns the URI
formed by removing it; this URI unchanged, otherwise.trimFragment
in class URI
public URI resolve(URI base)
org.eclipse.emf.common.util.URI
base
absolute
hierarchical URI, returning the resulting absolute URI. If already
absolute, the URI itself is returned. URI resolution is described in
detail in section 5.2 of RFC
2396, "Resolving Relative References to Absolute Form."
During resolution, empty segments, self references ("."), and parent
references ("..") are interpreted, so that they can be removed from the
path. Step 6(g) gives a choice of how to handle the case where parent
references point to a path above the root: the offending segments can
be preserved or discarded. This method preserves them. To have them
discarded, please use the two-parameter form of resolve
.
public URI resolve(URI base, boolean preserveRootParents)
org.eclipse.emf.common.util.URI
base
absolute
hierarchical URI, returning the resulting absolute URI. If already
absolute, the URI itself is returned. URI resolution is described in
detail in section 5.2 of RFC
2396, "Resolving Relative References to Absolute Form."
During resolution, empty segments, self references ("."), and parent references ("..") are interpreted, so that they can be removed from the path. Step 6(g) gives a choice of how to handle the case where parent references point to a path above the root: the offending segments can be preserved or discarded. This method can do either.
public URI deresolve(URI base)
org.eclipse.emf.common.util.URI
base
absolute hierarchical
URI using resolve
, will yield this absolute URI.
If base
is non-hierarchical or is relative,
or this
is non-hierarchical or is relative,
this
will be returned.public URI deresolve(URI base, boolean preserveRootParents, boolean anyRelPath, boolean shorterRelPath)
org.eclipse.emf.common.util.URI
base
absolute hierarchical URI using resolve
, will yield this absolute URI.
If base
is non-hierarchical or is relative,
or this
is non-hierarchical or is relative,
this
will be returned.deresolve
in class URI
preserveRootParents
- the boolean argument to resolve(URI,
boolean)
for which the returned URI should resolve to this URI.anyRelPath
- if true
, the returned URI's path (if
any) will be relative, if possible. If false
, the form of
the result's path will depend upon the next parameter.shorterRelPath
- if anyRelPath
is false
and this parameter is true
, the returned URI's path (if
any) will be relative, if one can be found that is no longer (by number
of segments) than the absolute path. If both anyRelPath
and this parameter are false
, it will be absolute.public String toFileString()
org.eclipse.emf.common.util.URI
isFile
, decodes
and formats
the URI as a pathname to that file; returns null otherwise.
If there is no authority, the format of this string is:
device/pathSegment1/pathSegment2...
If there is an authority, it is:
//authority/device/pathSegment1/pathSegment2...
However, the character used as a separator is system-dependent and
obtained from File.separatorChar
.
toFileString
in class URI
public String toPlatformString(boolean decode)
org.eclipse.emf.common.util.URI
URI.isPlatform()
, returns
the workspace-relative or plug-in-based path to the resource, optionally
decoding
the segments in the process.toPlatformString
in class URI
URI.createPlatformResourceURI(String, boolean)
,
URI.createPlatformPluginURI(java.lang.String, boolean)
public URI appendSegment(String segment)
org.eclipse.emf.common.util.URI
appendSegment
in class URI
public URI appendSegments(String[] segments)
org.eclipse.emf.common.util.URI
appendSegments
in class URI
segments
- an array of non-null strings, each representing one
segment of the path. If desired, a trailing separator should be
represented by an empty-string segment as the last element of the
array.public URI trimSegments(int i)
org.eclipse.emf.common.util.URI
Note that if all segments are trimmed from an absolute path, the root absolute path remains.
trimSegments
in class URI
i
- the number of segments to be trimmed in the returned URI. If
less than 1, this URI is returned unchanged; if equal to or greater
than the number of segments in this URI's path, all segments are
trimmed.public boolean hasTrailingPathSeparator()
org.eclipse.emf.common.util.URI
true
if this is a hierarchical URI that has a path
that ends with a trailing separator; false
otherwise.
A trailing separator is represented as an empty segment as the last segment in the path; note that this definition does not include the lone separator in the root absolute path.
hasTrailingPathSeparator
in class URI
public String fileExtension()
org.eclipse.emf.common.util.URI
fileExtension
in class URI
public URI appendFileExtension(String fileExtension)
org.eclipse.emf.common.util.URI
The extension is appended regardless of whether the segment already contains an extension.
appendFileExtension
in class URI
public URI trimFileExtension()
org.eclipse.emf.common.util.URI
fileExtension
,
returns the URI formed by removing it; this URI unchanged, otherwise.trimFileExtension
in class URI
public boolean isPrefix()
org.eclipse.emf.common.util.URI
true
if this is a hierarchical URI that ends in a
slash; that is, it has a trailing path separator or is the root
absolute path, and has no query and no fragment; false
is returned otherwise.public URI replacePrefix(URI oldPrefix, URI newPrefix)
org.eclipse.emf.common.util.URI
oldPrefix
is a
prefix of it, this returns the URI formed by replacing it by
newPrefix
; null
otherwise.
In order to be a prefix, the oldPrefix
's
isPrefix
must return true
, and it must
match this URI's scheme, authority, and device. Also, the paths must
match, up to prefix's end.
replacePrefix
in class URI
Copyright © 2013–2017 Atlanmod INRIA LINA Mines Nantes. All rights reserved.