org.ow2.wildcat.hierarchy
Class Path

java.lang.Object
  extended by org.ow2.wildcat.hierarchy.Path
All Implemented Interfaces:
Serializable

public class Path
extends Object
implements Serializable

A path in the wildcat hierarchy. Path have the form of url.

See Also:
Serialized Form

Field Summary
static Path NULL
          Constant Path for null://
static Path ROOT
          Constant Path for /.
 
Constructor Summary
Path(Path path)
          Deep copy constructor
Path(String path)
          Convenient constructors.
 
Method Summary
 Path append(Path suffix)
          Creates a new Path by appending suffix to 'this'.
 Path appendAttribute(String name)
          Creates a new path by appending 'name' as attribute name to current path assumes 'name' to be a valid attribute name
 Path appendResource(String name)
          Creates a new path by appending 'name' as resource to current path
 Path canonicalize()
          Canonicalize current path
 boolean equals(Object object)
           
 void expectAbsolute()
          Does nothing.
 void expectAttribute()
          Does nothing
 void expectCanonical()
          Does nothing.
 void expectFinite()
          Does nothing.
 void expectRelative()
          Does nothing.
 void expectResource()
          Does nothing.
 String getAttributeName()
           
 String getFirstResource()
           
 String getHostname()
           
 Path getParentPath()
           
 Path getRelativePart()
          Creates a new path by stripping host and starting '/'.
 boolean hasAttribute()
           
 boolean hasExplicitHost()
           
 int hashCode()
           
 boolean hasResource()
           
 boolean isAbsolute()
           
 boolean isCanonical()
          Tests if path is canonical.
 boolean isOnlyAttribute()
           
 boolean isOnlyResource()
           
 boolean isPattern()
          Tests if path contain pattern elements.
 boolean isPrefix(Path prefix)
          Test whether argument is a prefix of current path.
static boolean isValidAttributeName(String attributeName)
           
static boolean isValidHostname(String hostname)
           
static boolean isValidResourceName(String resourceName)
           
 Path replacePrefix(Path oprefix, Path nprefix)
          Partially rewrite current path, changing oprefix in 'this' to nprefix.
 void setHostName(String hostname)
           
 Path stripTop()
          Creates a new path by stripping the first resource as attribute name to current path.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

ROOT

public static final Path ROOT
Constant Path for /.


NULL

public static final Path NULL
Constant Path for null://

Constructor Detail

Path

public Path(String path)
     throws MalformedPathException
Convenient constructors. Constructs a path from its string representation

Parameters:
path -
Throws:
MalformedPathException - if the path is malformed

Path

public Path(Path path)
Deep copy constructor

Parameters:
path -
Method Detail

appendResource

public Path appendResource(String name)
Creates a new path by appending 'name' as resource to current path

Parameters:
name -
Returns:
a new path with 'name' as resource added at the end of current path

appendAttribute

public Path appendAttribute(String name)
Creates a new path by appending 'name' as attribute name to current path assumes 'name' to be a valid attribute name

Parameters:
name -
Returns:
a copy of this path with 'name' as attribute name.

append

public Path append(Path suffix)
Creates a new Path by appending suffix to 'this'.

Parameters:
suffix - suffix to append
Returns:
a new Path

replacePrefix

public Path replacePrefix(Path oprefix,
                          Path nprefix)
Partially rewrite current path, changing oprefix in 'this' to nprefix.

Parameters:
oprefix - the prefix of current path to delete
nprefix - the new prefix
Returns:
rewritten path

getParentPath

public Path getParentPath()
Returns:
the parent resource

canonicalize

public Path canonicalize()
Canonicalize current path

Returns:
a new Path canonicalized

stripTop

public Path stripTop()
Creates a new path by stripping the first resource as attribute name to current path. Only set absolute to false when the path is absolute.

Returns:
same as getRelativePart if path is absolute, else a copy of current path without the first resource

getRelativePart

public Path getRelativePart()
Creates a new path by stripping host and starting '/'.

Returns:
a copy of current path without host and starting '/'

getHostname

public String getHostname()
Returns:
the hostname, null if none is explicitly given

setHostName

public void setHostName(String hostname)

getAttributeName

public String getAttributeName()
Returns:
the attribute name, null if none

getFirstResource

public String getFirstResource()
Returns:
the first resource name of the path

isAbsolute

public boolean isAbsolute()
Returns:
true if path is absolute (it start with '/' or if hasExplicitHost. is true), false otherwise.

hasExplicitHost

public boolean hasExplicitHost()
Returns:
true if path has an explicitly reference an host ('self' or any other hostname) false otherwise.

hasAttribute

public boolean hasAttribute()
Returns:
true if path points an attribute, else false

hasResource

public boolean hasResource()
Returns:
true if path contains at least one resource

isOnlyAttribute

public boolean isOnlyAttribute()
Returns:
true if path only contains an attribute name, else false

isOnlyResource

public boolean isOnlyResource()
Returns:
true if path is only a resource name, else false

isCanonical

public boolean isCanonical()
Tests if path is canonical.

Returns:
true if no resource is a relative reference ("." or "..")

isPattern

public boolean isPattern()
Tests if path contain pattern elements.

Returns:
true if a resource or the attribute equal "*", else false

isPrefix

public boolean isPrefix(Path prefix)
Test whether argument is a prefix of current path.

Parameters:
prefix -
Returns:
trueif prefix is a prefix of current path, else false

isValidHostname

public static boolean isValidHostname(String hostname)
Parameters:
hostname -
Returns:
true if is valid host name, else false.

isValidResourceName

public static boolean isValidResourceName(String resourceName)
Parameters:
resourceName -
Returns:
true if is valid resource name, else false.

isValidAttributeName

public static boolean isValidAttributeName(String attributeName)
Parameters:
attributeName -
Returns:
true if is valid attribute name, else false.

expectCanonical

public void expectCanonical()
                     throws MalformedPathException
Does nothing.

Throws:
MalformedPathException - if path is not canonical

expectFinite

public void expectFinite()
                  throws MalformedPathException
Does nothing.

Throws:
MalformedPathException - if path is a pattern

expectAbsolute

public void expectAbsolute()
                    throws MalformedPathException
Does nothing.

Throws:
MalformedPathException - if path is not absolute

expectRelative

public void expectRelative()
                    throws MalformedPathException
Does nothing.

Throws:
MalformedPathException - if path is not relative

expectResource

public void expectResource()
                    throws MalformedPathException
Does nothing.

Throws:
MalformedPathException - if path denotes an attribute

expectAttribute

public void expectAttribute()
                     throws MalformedPathException
Does nothing

Throws:
MalformedPathException - if path not denotes an attribute

toString

public String toString()
Overrides:
toString in class Object

equals

public boolean equals(Object object)
Overrides:
equals in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object


Copyright © 2010 OW2 Consortium. All Rights Reserved.