use of javax.naming.NameParser in project ACS by ACS-Community.
the class ManagerImpl method rebind.
/**
* @param remoteDirectory parent context of parentContext.
* @param parent name of context to bind.
* @param parentContext context to bind.
* @throws NamingException
*
private void generateHiearchyContexts(Context remoteDirectory, String parent, Context parentContext) throws NamingException
{
/// @todo CORBA specific
if (remoteDirectory instanceof com.sun.jndi.cosnaming.CNCtx)
{
boolean isParentDomain = remoteDirectory.getNameInNamespace().length() == 0 ||
remoteDirectory.getNameInNamespace().endsWith(".D");
org.omg.CORBA.Object parentRepresentation = ((com.sun.jndi.cosnaming.CNCtx)remoteDirectory)._nc;
if (parent.endsWith(".D"))
{
// domain binding
parentContext.rebind("Parent.D", parentRepresentation);
}
else if (parent.endsWith(".F"))
{
// hierarchical component binding
if (isParentDomain)
parentContext.rebind("Domain.D", parentRepresentation);
else
parentContext.rebind("Domain.D", remoteDirectory.lookup("Domain.D"));
parentContext.rebind("Parent.F", parentRepresentation);
}
}
else if (remoteDirectory instanceof InitialContext)
generateHiearchyContexts((Context)((InitialContext)remoteDirectory).lookup(""), parent, parentContext);
else
new MessageLogEntry(this, "generateHiearchyContexts", "Unsupported remote directory, class '" + remoteDirectory.getClass().getName() + "'.", Level.WARNING).dispatch();
}*/
/**
* Rebind object to the root of remote directory.
*
* Use INS syntax specified in the INS specification.
* In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
* The id and kind of each component are separated by the period character ('.').
* NOTE: Does not support hierarchical names.
*
* @param name name of the object, code non-<code>null</code>
* @param type type of the object
* @param object object to be binded
*
private void rebind(String name, String type, Object object)
{
rebind(remoteDirectory, name, type, object);
}*/
/**
* Rebind object to remote directory.
*
* Use INS syntax specified in the INS specification.
* In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
* The id and kind of each component are separated by the period character ('.').
* NOTE: Does not support hierarchical names.
*
* @param remoteDirectory remote directory context to be used.
* @param name name of the object, code non-<code>null</code>
* @param type type of the object
* @param object object to be binded
*/
private void rebind(Context remoteDirectory, String name, String type, Object object) {
assert (name != null);
// do not bind interdomain names
if (name.startsWith(CURL_URI_SCHEMA))
return;
if (remoteDirectory != null) {
try {
NameParser parser = remoteDirectory.getNameParser("");
Name n;
if (type != null)
n = parser.parse(name + "." + type);
else
n = parser.parse(name);
remoteDirectory.rebind(n, object);
} catch (NamingException ne) {
CoreException ce = new CoreException("Failed to rebind name '" + name + "' to the remote directory.", ne);
logger.log(Level.FINE, ce.getMessage(), ce);
}
}
}
use of javax.naming.NameParser in project ACS by ACS-Community.
the class ManagerImpl method unbind.
/**
* Unbind object to remote directory.
*
* Use INS syntax specified in the INS specification.
* In short, the syntax is that components are left-to-right slash ('/') separated and case-sensitive.
* The id and kind of each component are separated by the period character ('.').
*
* @param remoteDirectory remote directory context to be used.
* @param name name of the object, code non-<code>null</code>
* @param type type of the object
*/
private void unbind(Context remoteDirectory, String name, String type) {
assert (name != null);
// do not unbind interdomain names
if (name.startsWith(CURL_URI_SCHEMA))
return;
if (remoteDirectory != null) {
try {
NameParser parser = remoteDirectory.getNameParser("");
Name n;
if (type != null)
n = parser.parse(name + "." + type);
else
n = parser.parse(name);
remoteDirectory.unbind(n);
// NOTE: cleaning up the empty context nodes is not implemented
// since access NS cannot provide quantum actions (transactions)
// cleanup only empty ".F" contexts - only local manager
// should modify local NS
cleanupEmptyFContext(remoteDirectory, name);
} catch (NamingException ne) {
CoreException ce = new CoreException("Failed to unbind name '" + name + "' from the remote directory.", ne);
logger.log(Level.FINE, ce.getMessage(), ce);
}
}
}
use of javax.naming.NameParser in project deltaspike by apache.
the class JndiUtils method list.
/**
* Resolves an instances for the given naming context.
*
* @param name context name
* @param type target type
* @param <T> type
* @return the found instances, null otherwise
*/
public static <T> Map<String, T> list(String name, Class<T> type) {
Map<String, T> result = new HashMap<String, T>();
try {
NameParser nameParser = initialContext.getNameParser(name);
NamingEnumeration<NameClassPair> enumeration = initialContext.list(name);
while (enumeration.hasMoreElements()) {
try {
NameClassPair binding = enumeration.nextElement();
Name bindingName = nameParser.parse(name).add(binding.getName());
result.put(binding.getName(), lookup(bindingName, type));
} catch (NamingException e) {
if (LOG.isLoggable(Level.FINEST)) {
// this is expected if there is no entry in JNDI for the requested name or type
// so finest level is ok, if devs want to see it they can enable this logger level.
LOG.log(Level.FINEST, "InitialContext#list failed!", e);
}
}
}
} catch (NamingException e) {
// this is fine at this point, since the individual lines will be caught currently.
LOG.log(Level.WARNING, "Problem reading the name of the JNDI location " + name + " or failuring listing pairs.", e);
}
return result;
}
Aggregations