List of usage examples for javax.naming Name getSuffix
public Name getSuffix(int posn);
From source file:com.dattack.naming.AbstractContext.java
@Override public void destroySubcontext(final Name name) throws NamingException { if (name.size() > 1) { if (subContexts.containsKey(name.getPrefix(1))) { final Context subContext = subContexts.get(name.getPrefix(1)); subContext.destroySubcontext(name.getSuffix(1)); return; }/*from ww w .j av a 2 s. c o m*/ throw new NameNotFoundException(); } if (objectTable.containsKey(name) || !subContexts.containsKey(name)) { throw new NameNotFoundException(String.format("Context not found: %s", name)); } final Context subContext = subContexts.get(name); final NamingEnumeration<NameClassPair> names = subContext.list(""); if (names.hasMore()) { throw new ContextNotEmptyException(); } subContexts.get(name).close(); subContexts.remove(name); }
From source file:com.dattack.naming.AbstractContext.java
@Override public NameParser getNameParser(final Name name) throws NamingException { if (name == null || name.isEmpty() || (name.size() == 1 && name.toString().equals(getNameInNamespace()))) { return nameParser; }//from w ww. j a v a2s . co m final Name subName = name.getPrefix(1); if (subContexts.containsKey(subName)) { return subContexts.get(subName).getNameParser(name.getSuffix(1)); } throw new NotContextException(); }
From source file:com.dattack.naming.AbstractContext.java
@Override public void bind(final Name name, final Object object) throws NamingException { ensureContextNotClosed();//from w w w.jav a2 s . co m if (object == null) { return; } if (name.isEmpty()) { throw new InvalidNameException("Cannot bind to an empty name"); } final Name prefix = name.getPrefix(1); if (subContexts.containsKey(prefix)) { subContexts.get(prefix).bind(name.getSuffix(1), object); return; } if (objectTable.containsKey(name) || subContexts.containsKey(name) || env.containsKey(name.toString())) { throw new NameAlreadyBoundException( String.format("Name %s already bound. Use rebind() to override", name.toString())); } if (object instanceof Context) { subContexts.put(name, (Context) object); } else { objectTable.put(name, object); } }
From source file:com.dattack.naming.AbstractContext.java
@Override public void unbind(final Name name) throws NamingException { ensureContextNotClosed();//from w w w . java 2 s . co m if (name.isEmpty()) { throw new InvalidNameException("Cannot unbind to empty name"); } if (name.size() == 1) { if (objectTable.containsKey(name)) { objectTable.remove(name); } return; } final Context parentContext = getParentContext(name); parentContext.unbind(name.getSuffix(name.size() - 1)); }
From source file:com.dattack.naming.AbstractContext.java
@Override public NamingEnumeration<Binding> listBindings(final Name name) throws NamingException { ensureContextNotClosed();//from www.j a va 2 s .co m if (name == null || name.isEmpty()) { final Map<Name, Object> enumStore = new HashMap<Name, Object>(); enumStore.putAll(objectTable); enumStore.putAll(subContexts); return new BindingNamingEnumeration(enumStore); } final Name subName = name.getPrefix(1); if (objectTable.containsKey(subName)) { throw new NotContextException(String.format("%s cannot be listed", name)); } if (subContexts.containsKey(subName)) { return subContexts.get(subName).listBindings(name.getSuffix(1)); } throw new NamingException(String.format("The named context '%s' can't be found", name)); }
From source file:com.dattack.naming.AbstractContext.java
@Override public NamingEnumeration<NameClassPair> list(final Name name) throws NamingException { ensureContextNotClosed();/*ww w.jav a2s .c om*/ if (name == null || name.isEmpty()) { // list all elements final Map<Name, Object> enumStore = new HashMap<Name, Object>(); enumStore.putAll(objectTable); enumStore.putAll(subContexts); return new NameClassPairNamingEnumeration(enumStore); } final Name prefixName = name.getPrefix(1); if (objectTable.containsKey(prefixName)) { throw new NotContextException(String.format("%s cannot be listed", name)); } if (subContexts.containsKey(prefixName)) { return subContexts.get(prefixName).list(name.getSuffix(1)); } throw new NamingException(String.format("The context '%s' can't be found", name)); }
From source file:com.dattack.naming.AbstractContext.java
@Override public Object lookup(final Name name) throws NamingException { ensureContextNotClosed();/*from w w w .j ava 2s . c o m*/ /* * Extract from Context Javadoc: If name is empty, returns a new instance of this context (which represents the * same naming context as this context, but its environment may be modified independently and it may be accessed * concurrently). */ if (name.isEmpty()) { try { return this.clone(); } catch (final CloneNotSupportedException e) { // this shouldn't happen, since we are Cloneable throw (NamingException) new OperationNotSupportedException(e.getMessage()).initCause(e); } } if (name.size() > 1) { if (subContexts.containsKey(name.getPrefix(1))) { return subContexts.get(name.getPrefix(1)).lookup(name.getSuffix(1)); } throw new NamingException( String.format("Invalid subcontext '%s' in context '%s'", name.getPrefix(1).toString(), StringUtils.isBlank(getNameInNamespace()) ? "/" : getNameInNamespace())); } Object result = null; // not found if (objectTable.containsKey(name)) { result = objectTable.get(name); } else if (subContexts.containsKey(name)) { result = subContexts.get(name); } else if (env.containsKey(name.toString())) { result = env.get(name.toString()); } return result; }
From source file:org.apache.naming.modules.fs.FileDirContext.java
/** * Retrieves the named object. The result is a File relative to the docBase * or a FileDirContext for directories.//from www . j av a 2 s . c om * * @param name the name of the object to look up * @return the object bound to name * @exception NamingException if a naming exception is encountered */ public Object lookup(Name nameObj, boolean resolveLinkx) throws NamingException { if (log.isDebugEnabled()) log.debug("lookup " + nameObj); System.out.println("XXX " + nameObj.get(0)); if ("fs:".equals(nameObj.get(0).toString())) nameObj = nameObj.getSuffix(1); String name = nameObj.toString(); // we need to convert anyway, for File constructor Object result = null; File file = file(name); if (file == null) throw new NamingException(sm.getString("resources.notFound", name)); if (file.isDirectory()) { FileDirContext tempContext = new FileDirContext(env); tempContext.setDocBase(file.getPath()); result = tempContext; } else { // TODO: based on the name, return various 'styles' of // content // TODO: use lazy streams, cacheable result = file; //new FileResource(file); } return result; }
From source file:org.apache.naming.modules.fs.FileDirContext.java
/** * Unbinds the named object. Removes the terminal atomic name in name * from the target context--that named by all but the terminal atomic * part of name./*from w ww .j av a2 s .c om*/ * <p> * This method is idempotent. It succeeds even if the terminal atomic * name is not bound in the target context, but throws * NameNotFoundException if any of the intermediate contexts do not exist. * * @param name the name to bind; may not be empty * @exception NameNotFoundException if an intermediate context does not * exist * @exception NamingException if a naming exception is encountered */ public void unbind(Name nameObj) throws NamingException { if ("fs:".equals(nameObj.get(0).toString())) nameObj = nameObj.getSuffix(1); String name = nameObj.toString(); if (log.isDebugEnabled()) log.debug("unbind " + name); File file = file(name); if (file == null) throw new NamingException(sm.getString("resources.notFound", name)); if (!file.delete()) throw new NamingException(sm.getString("resources.unbindFailed", name)); }
From source file:org.apache.naming.NamingContext.java
/** * Unbinds the named object. Removes the terminal atomic name in name * from the target context--that named by all but the terminal atomic * part of name.// w ww . ja v a 2 s .c o m * <p> * This method is idempotent. It succeeds even if the terminal atomic * name is not bound in the target context, but throws * NameNotFoundException if any of the intermediate contexts do not exist. * * @param name the name to bind; may not be empty * @exception NameNotFoundException if an intermediate context does not * exist * @exception NamingException if a naming exception is encountered */ public void unbind(Name name) throws NamingException { checkWritable(); while ((!name.isEmpty()) && (name.get(0).length() == 0)) name = name.getSuffix(1); if (name.isEmpty()) throw new NamingException(sm.getString("namingContext.invalidName")); NamingEntry entry = (NamingEntry) bindings.get(name.get(0)); if (entry == null) { throw new NameNotFoundException(sm.getString("namingContext.nameNotBound", name.get(0))); } if (name.size() > 1) { if (entry.type == NamingEntry.CONTEXT) { ((Context) entry.value).unbind(name.getSuffix(1)); } else { throw new NamingException(sm.getString("namingContext.contextExpected")); } } else { bindings.remove(name.get(0)); } }