Class SimpleJndiName

java.lang.Object
org.glassfish.api.naming.SimpleJndiName
All Implemented Interfaces:
Serializable, Comparable<SimpleJndiName>

public class SimpleJndiName extends Object implements Serializable, Comparable<SimpleJndiName>
Value object for JNDI names used in GlassFish.
Author:
David Matejcek
See Also:
  • Field Details

  • Constructor Details

    • SimpleJndiName

      public SimpleJndiName(String jndiName)
      Does simple validation and creates the instance.
      Parameters:
      jndiName - must not be null and if it is not a corbaname: jndi name, must not contain more than one colon.
  • Method Details

    • hasJavaPrefix

      public boolean hasJavaPrefix()
      Returns:
      true if the JNDI name starts with "java:"
    • hasCorbaPrefix

      public boolean hasCorbaPrefix()
      Returns:
      true if the JNDI name starts with "corbaname:"
    • isJavaGlobal

      public boolean isJavaGlobal()
      Returns:
      true if the JNDI name starts with "java:global".
    • isJavaApp

      public boolean isJavaApp()
      Returns:
      true if the JNDI name starts with "java:app".
    • isJavaModule

      public boolean isJavaModule()
      Returns:
      true if the JNDI name starts with "java:module".
    • isJavaComponent

      public boolean isJavaComponent()
      Returns:
      true if the JNDI name starts with "java:comp".
    • compareTo

      public int compareTo(SimpleJndiName other)
      Specified by:
      compareTo in interface Comparable<SimpleJndiName>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

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

      public boolean isEmpty()
      Returns:
      true if the JNDI name is an empty string
    • contains

      public boolean contains(String part)
      Parameters:
      part - must not be null.
      Returns:
      true if the JNDI name contains the parameter.
    • getPrefix

      public String getPrefix()
      Prefix in this case is understood as any string in the form a:b/ or a: or x://

      For JNDI names starting with "corbaname:" returns null.

      Returns:
      substring containing : and ending by /
    • hasPrefix

      public boolean hasPrefix(String prefix)
      Parameters:
      prefix - must not be null.
      Returns:
      true if the JNDI name starts with the parameter.
    • hasSuffix

      public boolean hasSuffix(String suffix)
      Parameters:
      suffix - must not be null.
      Returns:
      true if the JNDI name ends with the parameter.
    • removePrefix

      public SimpleJndiName removePrefix(String prefix)
      Parameters:
      prefix - can be null, then returns this instance unchanged.
      Returns:
      new instance with the prefix removed or this instance unchanged if the prefix was not present.
    • removePrefix

      public SimpleJndiName removePrefix()
      Returns the JNDI name without the prefix. If there is no prefix, returns this instance unchanged.

      Prefix in this case is understood as any string in the form a:b/ or a: or x://

      For JNDI names starting with "corbaname:" returns this instance unchanged.

      Returns:
      new instance with the prefix removed or this instance unchanged, never null.
    • changePrefix

      public SimpleJndiName changePrefix(String newPrefix) throws IllegalArgumentException
      Changes the simple JNDI name prefix.

      Prefix in this case is understood as any string in the form a:b/ or a: or x://

      For JNDI names starting with "corbaname:" returns this instance unchanged.

      If there is no prefix, just sets the new prefix. If the name is a Corba name doesn't do anything. If the name has java:ccc/ prefix or is an URL (protocol://xxx:8888/...), sets the new prefix instead of the java:ccc/ or the protocol://

      Parameters:
      newPrefix - must end with the colon or slash.
      Returns:
      new instance, never null.
      Throws:
      IllegalArgumentException - if it is not possible to create valid JNDI name with the new prefix
    • removeSuffix

      public SimpleJndiName removeSuffix(String suffix)
      Parameters:
      suffix - can be null, then returns this instance unchanged.
      Returns:
      new instance with the suffix removed or this instance unchanged if the suffix was not present.
    • toString

      public String toString()
      Returns the JNDI name.
      Overrides:
      toString in class Object
    • toName

      public Name toName() throws InvalidNameException
      Returns:
      CompositeName representing the same JNDI name.
      Throws:
      InvalidNameException - if the conversions was not possible.
    • isValidJndiName

      public static boolean isValidJndiName(String jndiName)
      Returns true if the parameter is not null and doesn't start with the "java:", or if it does, it must contain just one colon character.
      Parameters:
      jndiName - any string or null
      Returns:
      true if the jndiName can be used in the constructor.
    • of

      public static SimpleJndiName of(Name name)
      Parameters:
      name - can be null, then returns null.
      Returns:
      null or a new instance of SimpleJndiName.
    • of

      public static SimpleJndiName of(String name)
      Parameters:
      name - can be null, then returns null.
      Returns:
      null or a new instance of SimpleJndiName.