- Java name naming javax
- Field Summary
- Method Summary
- Field Detail
- serialVersionUID
- Method Detail
- clone
- compareTo
- size
- isEmpty
- getAll
- get
- getPrefix
- getSuffix
- startsWith
- endsWith
- addAll
- addAll
- add
- add
- remove
- Package javax.naming
- Context
- Names
- Bindings
- References
- The Initial Context
- Exceptions
- Package javax.naming
- Context
- Names
- Bindings
- References
- The Initial Context
- Exceptions
Java name naming javax
The Name interface represents a generic name — an ordered sequence of components. It can be a composite name (names that span multiple namespaces), or a compound name (names that are used within individual hierarchical naming systems). There can be different implementations of Name; for example, composite names, URLs, or namespace-specific compound names. The components of a name are numbered. The indexes of a name with N components range from 0 up to, but not including, N. This range may be written as [0,N). The most significant component is at index 0. An empty name has no components. None of the methods in this interface accept null as a valid value for a parameter that is a name or a name component. Likewise, methods that return a name or name component never return null. An instance of a Name may not be synchronized against concurrent multithreaded access if that access is not read-only.
Field Summary
The class fingerprint that is set to indicate serialization compatibility with a previous version of the class.
Method Summary
Field Detail
serialVersionUID
static final long serialVersionUID
The class fingerprint that is set to indicate serialization compatibility with a previous version of the class.
Method Detail
clone
Generates a new copy of this name. Subsequent changes to the components of this name will not affect the new copy, and vice versa.
compareTo
Compares this name with another name for order. Returns a negative integer, zero, or a positive integer as this name is less than, equal to, or greater than the given name. As with Object.equals(), the notion of ordering for names depends on the class that implements this interface. For example, the ordering may be based on lexicographical ordering of the name components. Specific attributes of the name, such as how it treats case, may affect the ordering. In general, two names of different classes may not be compared.
size
isEmpty
getAll
Retrieves the components of this name as an enumeration of strings. The effect on the enumeration of updates to this name is undefined. If the name has zero components, an empty (non-null) enumeration is returned.
get
getPrefix
Creates a name whose components consist of a prefix of the components of this name. Subsequent changes to this name will not affect the name that is returned and vice versa.
getSuffix
Creates a name whose components consist of a suffix of the components in this name. Subsequent changes to this name do not affect the name that is returned and vice versa.
startsWith
Determines whether this name starts with a specified prefix. A name n is a prefix if it is equal to getPrefix(n.size()).
endsWith
Determines whether this name ends with a specified suffix. A name n is a suffix if it is equal to getSuffix(size()-n.size()).
addAll
Name addAll(Name suffix) throws InvalidNameException
addAll
Name addAll(int posn, Name n) throws InvalidNameException
Adds the components of a name — in order — at a specified position within this name. Components of this name at or after the index of the first new component are shifted up (away from 0) to accommodate the new components.
add
Name add(String comp) throws InvalidNameException
add
Name add(int posn, String comp) throws InvalidNameException
Adds a single component at a specified position within this name. Components of this name at or after the index of the new component are shifted up by one (away from index 0) to accommodate the new component.
remove
Object remove(int posn) throws InvalidNameException
Removes a component from this name. The component of this name at the specified position is removed. Components with indexes greater than this position are shifted down (toward index 0) by one.
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2023, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
Package javax.naming
This package defines the naming operations of the Java Naming and Directory Interface (JNDI). JNDI provides naming and directory functionality to applications written in the Java programming language. It is designed to be independent of any specific naming or directory service implementation. Thus a variety of services—new, emerging, and already deployed ones—can be accessed in a common way.
Context
This package defines the notion of a context, represented by the Context interface. A context consists of a set of name-to-object bindings. Context is the core interface for looking up, binding, unbinding, and renaming objects, and for creating and destroying subcontexts.
lookup() is the most commonly used operation. You supply lookup() the name of the object you want to look up, and it returns the object bound to that name. For example, the following code fragment looks up a printer and sends a document to the printer object to be printed:
Printer printer = (Printer)ctx.lookup("treekiller"); printer.print(report);
Names
Every naming method in the Context interface has two overloads: one that accepts a Name argument and one that accepts a string name. Name is an interface that represents a generic name—an ordered sequence of zero of more components. For these methods, Name can be used to represent a composite name ( CompositeName ) so that you can name an object using a name which spans multiple namespaces.
The overloads that accept Name are useful for applications that need to manipulate names: composing them, comparing components, and so on. The overloads that accept string names are likely to be more useful for simple applications, such as those that simply read in a name and look up the corresponding object.
Bindings
The Binding class represents a name-to-object binding. It is a tuple containing the name of the bound object, the name of the object’s class, and the object itself.
The Binding class is actually a subclass of NameClassPair , which consists simply of the object’s name and the object’s class name. The NameClassPair is useful when you only want information about the object’s class and do not want to pay the extra cost of getting the object.
References
Objects are stored in naming and directory services in different ways. If an object store supports storing Java objects, it might support storing an object in its serialized form. However, some naming and directory services do not support the storing of Java objects. Furthermore, for some objects in the directory, Java programs are but one group of applications that access them. In this case, a serialized Java object might not be the most appropriate representation. JNDI defines a reference, represented by the Reference class, which contains information on how to construct a copy of the object. JNDI will attempt to turn references looked up from the directory into the Java objects they represent, so that JNDI clients have the illusion that what is stored in the directory are Java objects.
The Initial Context
In JNDI, all naming and directory operations are performed relative to a context. There are no absolute roots. Therefore JNDI defines an initial context, InitialContext , which provides a starting point for naming and directory operations. Once you have an initial context, you can use it to look up other contexts and objects.
Exceptions
JNDI defines a class hierarchy for exceptions that can be thrown in the course of performing naming and directory operations. The root of this class hierarchy is NamingException . Programs interested in dealing with a particular exception can catch the corresponding subclass of the exception. Otherwise, programs should catch NamingException .
Package javax.naming
This package defines the naming operations of the Java Naming and Directory Interface (JNDI). JNDI provides naming and directory functionality to applications written in the Java programming language. It is designed to be independent of any specific naming or directory service implementation. Thus a variety of services—new, emerging, and already deployed ones—can be accessed in a common way.
Context
This package defines the notion of a context, represented by the Context interface. A context consists of a set of name-to-object bindings. Context is the core interface for looking up, binding, unbinding, and renaming objects, and for creating and destroying subcontexts.
lookup() is the most commonly used operation. You supply lookup() the name of the object you want to look up, and it returns the object bound to that name. For example, the following code fragment looks up a printer and sends a document to the printer object to be printed:
Printer printer = (Printer)ctx.lookup("treekiller"); printer.print(report);
Names
Every naming method in the Context interface has two overloads: one that accepts a Name argument and one that accepts a string name. Name is an interface that represents a generic name—an ordered sequence of zero of more components. For these methods, Name can be used to represent a composite name ( CompositeName ) so that you can name an object using a name which spans multiple namespaces.
The overloads that accept Name are useful for applications that need to manipulate names: composing them, comparing components, and so on. The overloads that accept string names are likely to be more useful for simple applications, such as those that simply read in a name and look up the corresponding object.
Bindings
The Binding class represents a name-to-object binding. It is a tuple containing the name of the bound object, the name of the object’s class, and the object itself.
The Binding class is actually a subclass of NameClassPair , which consists simply of the object’s name and the object’s class name. The NameClassPair is useful when you only want information about the object’s class and do not want to pay the extra cost of getting the object.
References
Objects are stored in naming and directory services in different ways. If an object store supports storing Java objects, it might support storing an object in its serialized form. However, some naming and directory services do not support the storing of Java objects. Furthermore, for some objects in the directory, Java programs are but one group of applications that access them. In this case, a serialized Java object might not be the most appropriate representation. JNDI defines a reference, represented by the Reference class, which contains information on how to construct a copy of the object. JNDI will attempt to turn references looked up from the directory into the Java objects they represent, so that JNDI clients have the illusion that what is stored in the directory are Java objects.
The Initial Context
In JNDI, all naming and directory operations are performed relative to a context. There are no absolute roots. Therefore JNDI defines an initial context, InitialContext , which provides a starting point for naming and directory operations. Once you have an initial context, you can use it to look up other contexts and objects.
Exceptions
JNDI defines a class hierarchy for exceptions that can be thrown in the course of performing naming and directory operations. The root of this class hierarchy is NamingException . Programs interested in dealing with a particular exception can catch the corresponding subclass of the exception. Otherwise, programs should catch NamingException .