public interface WsLocationAdmin
Resources are associated with a group, where the group functions as a pseudo-filesystem: a collection of locations that comprise a search path to use when locating resources by name.
Modifier and Type | Method and Description |
---|---|
WsResource |
addLocation(java.lang.String fileName,
java.lang.String symbolicName)
Add location to the registry of locations.
|
WsResource |
asResource(java.io.File file,
boolean isFile)
Create a
WsResource for the provided file. |
java.io.File |
getBundleFile(java.lang.Object caller,
java.lang.String relativeBundlePath)
Return a File with the given name (which may or may not exist, and may or
may not be a directory) in the bundle's private working area.
|
WsResource |
getRuntimeResource(java.lang.String relativeRuntimePath)
Return an WsResource object with the given name in the runtime install directory
(wlp.install.dir).
|
java.util.UUID |
getServerId()
Returns a persistent unique identifier for the server.
|
java.lang.String |
getServerName()
Get a string representation of the configured server name.
|
WsResource |
getServerOutputResource(java.lang.String relativeServerPath)
Return an WsResource object with the given name in the active server's configuration directory
(server.output.dir).
|
WsResource |
getServerResource(java.lang.String relativeServerPath)
Return an WsResource object with the given name in the active server's configuration directory
(server.config.dir).
|
WsResource |
getServerWorkareaResource(java.lang.String relativeServerWorkareaPath)
Return an WsResource object with the given name (which may or may not
exist) in the active server's workarea.
|
java.util.Iterator<WsResource> |
matchResource(java.lang.String resourceGroupName,
java.lang.String resourceRegex,
int limit)
Find the resource(s) matching the provided regular expression.
|
java.lang.String |
printLocations(boolean useLineBreaks)
Print debug information about the configured locations for the current
server.
|
WsResource |
resolveResource(java.lang.String resourceURI)
Resolve the given resource URI (either an absolute URI, or a repository URI
containing symbolics), and return an
WsResource . |
WsResource |
resolveResource(java.net.URI resourceURI)
Resolve the given resource URI (either an absolute URI, or an liberty
repository URI containing symbolics), and return an
WsResource . |
java.lang.String |
resolveString(java.lang.String string)
Resolve all symbols in the given string URI.
|
java.lang.String printLocations(boolean useLineBreaks)
formatOutput
- If true, the output will be formatted and separated with line
breaks, otherwise, output will be a comma-separated list.java.util.UUID getServerId()
java.lang.String getServerName()
java.io.File getBundleFile(java.lang.Object caller, java.lang.String relativeBundlePath)
This is a convenience method. It will use OSGi FrameworkUtil
to
find the Bundle
used to load the caller's class, and then will
call BundleContext.getDataFile(String)
to create the
File.
Use forward slashes in the relative path.
caller
- Object (this, or static's class) requesting a file in the
bundle's private data area; can not be nullrelativeBundlePath
- Relative path for inside of the bundle's private data areaMalformedLocationException
- if relativeBundlePath is not relative (is an absolute path, a
file URI, or starts with a symbol)java.lang.NullPointerException
- if caller is nullWsResource getRuntimeResource(java.lang.String relativeRuntimePath)
Note: This method MUST not be used to resolve server resources since there is no relationship between the location of the runtime install and the location of server resources.
Use forward slashes in the relative path.
relativeServerPath
- Relative path for inside of the runtime install's directory, can not be
null.MalformedLocationException
- if relativeRuntimePath is not relative (is an absolute path, a
file URI, or starts with a symbol), or if the path attempts
to navigate to or above the parent (../).java.lang.IllegalArgumentException
- if resource to be created already exists as a different type:
i.e. if the resource uri indicates the resource should be a
directory and the resource exists as a file, or vice versa.WsResource getServerResource(java.lang.String relativeServerPath)
Note: Anything generated by the server should be created using getServerOutputResource(java.lang.String)
.
"Internal" data should be created using getServerWorkareaResource(String)
.
Use forward slashes in the relative path.
A File object for the base directory of the public server area can be obtained by calling this method with an empty string as filename.
relativeServerPath
- Relative path for inside of the server's directory, can not be
null.MalformedLocationException
- if relativeServerPath is not relative (is an absolute path, a
file URI, or starts with a symbol), or if the path attempts
to navigate to or above the parent (../).java.lang.IllegalArgumentException
- if resource to be created already exists as a different type:
i.e. if the resource uri indicates the resource should be a
directory and the resource exists as a file, or vice versa.WsResource getServerOutputResource(java.lang.String relativeServerPath)
Note: Server "working" data should be created/managed in either the bundle's data area, or the server's workarea. The server's root directory should contain only user-generated/controllable artifacts: Anything in the server dir should be treated as API.
Use forward slashes in the relative path.
A File object for the base directory of the public server area can be obtained by calling this method with an empty string as filename.
relativeServerPath
- Relative path for inside of the server's directory, can not be
null.MalformedLocationException
- if relativeServerPath is not relative (is an absolute path, a
file URI, or starts with a symbol), or if the path attempts
to navigate to or above the parent (../).java.lang.IllegalArgumentException
- if resource to be created already exists as a different type:
i.e. if the resource uri indicates the resource should be a
directory and the resource exists as a file, or vice versa.WsResource getServerWorkareaResource(java.lang.String relativeServerWorkareaPath)
Data in the server workarea will survive a refresh of the OSGi framework cache
Best Practice: use a subdirectory (e.g. using the bundle's PID, or the config group name) to consolidate data associated w/ a particular bundle or subsystem, and reduce the likelihood of name collisions.
Use forward slashes in the relative path.
A File object for the base directory of the public server area can be obtained by calling this method with an empty string as filename.
relativeServerWorkareaPath
- Relative path within the configured server's private workarea;
can not be nullMalformedLocationException
- if relativeServerWorkareaPath is not relative (is an absolute
path, a file URI, or starts with a symbol), or if the path
attempts to navigate to or above the parent (../).java.lang.IllegalArgumentException
- if resource to be created already exists as a different type:
i.e. if the resource uri indicates the resource should be a
directory and the resource exists as a file, or vice versa.WsResource resolveResource(java.lang.String resourceURI)
WsResource
.
Use forward slashes in the resource URI.
resourceURI
- Resource URI as a stringWsResource
representing the resource specified by the provided URI; may return null
if the resourceURI
contains an unknown/unresolvable symbol.MalformedLocationException
- if the resourceURI is malformedjava.lang.IllegalArgumentException
- if the URI points to an existing resource of the wrong type (i.e. you specified a
file, "a/b/c", but the resource already exists as a directory, "a/b/c/")WsResource resolveResource(java.net.URI resourceURI)
WsResource
.
Use forward slashes in the resource URI.
resourceURI
- Resource URIWsResource
representing the resource specified by the provided URI;
may return null if the resourceURI
contains an unknown/unresolvable
symbol.MalformedLocationException
- if the resourceURI is malformedjava.lang.IllegalArgumentException
- if the URI points to an existing resource of the wrong type (i.e. you specified a
file, "a/b/c", but the resource already exists as a directory, "a/b/c/")WsResource asResource(java.io.File file, boolean isFile)
WsResource
for the provided file.file
- The File object that should be converted to a WsResourceisFile
- If true, the file object should be treated as a file;
if false, the file object should be treated as a directory.WsResource
representing the provided file, or null if file argument is null.java.lang.IllegalArgumentException
- if the File points to an existing resource of the wrong type
(i.e. isFile is true, but the file object references a directory).java.lang.String resolveString(java.lang.String string)
file://blah | file://blah |
${shared.app.dir} | /path/to/usr/shared/apps |
${shared.resource.dir}/security | /path/to/usr/shared/resources/security |
${relativePathSymbol}/extra | relative/extra |
resourceURI
- Resource URI as a stringresourceURI
contains an unknown/unresolvable symbol.MalformedLocationException
- if the resourceURI is malformedjava.lang.IllegalArgumentException
- if the URI points to an existing resource of the wrong type
(i.e. you specified a file, "a/b/c", but the resource already
exists as a directory, "a/b/c/")java.util.Iterator<WsResource> matchResource(java.lang.String resourceGroupName, java.lang.String resourceRegex, int limit)
If a particular path is expected (e.g. a/b/c), include the path elements in the regular expression. Use forward slashes.
The iterator will present resources in the order they were matched. If no resources were found, the iterator will have no elements.
resourceGroupName
- Group of resources to resolve against: bundle, config, etc.resourceRegex
- Regular expression describing matching resource URIs to find
within the search path defined for the resourceGroup.limit
- Maximum number of resources to match (0 implies no limit, 1
will only return first match, etc.)java.lang.IllegalArgumentException
- if resource to be created already exists as a different type:
i.e. if the resource uri indicates the resource should be a
directory and the resource exists as a file, or vice versa. This
throw may not occur until the element is reached while
iterating.WsResource addLocation(java.lang.String fileName, java.lang.String symbolicName)
fileName
- The name of the file that is the root of the locationsymbolicName
- The symbolic name of this resource without the symbol decorations
(e.g. productextension.extension.dir)java.lang.NullPointerException
- if either the fileName or the symbolicName are nulljava.lang.IllegalArgumentException
- if the named location exits and is a file