List of usage examples for javax.naming NamingException NamingException
public NamingException(String explanation)
From source file:org.apache.juddi.v3.auth.LdapSimpleAuthenticator.java
public LdapSimpleAuthenticator() throws NamingException, ConfigurationException { String authURL = null;//from w w w . j a va2s . com try { authURL = AppConfig.getConfiguration().getString(Property.JUDDI_AUTHENTICATOR_URL, DEFAULT_URL); } catch (ConfigurationException ce) { logger.error("Configuration exception occurred retrieving: " + Property.JUDDI_AUTHENTICATOR_URL); throw new NamingException( Property.JUDDI_AUTHENTICATOR_URL + " missing from config or config is not available."); } init(authURL); }
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 ava 2 s. co m * * @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.// w ww . j a va2s . 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 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.modules.fs.FileDirContext.java
/** * Binds a new name to the object bound to an old name, and unbinds the * old name. Both names are relative to this context. Any attributes * associated with the old name become associated with the new name. * Intermediate contexts of the old name are not changed. * //from ww w . ja v a 2s. c om * @param oldName the name of the existing binding; may not be empty * @param newName the name of the new binding; may not be empty * @exception NameAlreadyBoundException if newName is already bound * @exception NamingException if a naming exception is encountered */ public void rename(Name oldNameO, Name newNameO) throws NamingException { String oldName = oldNameO.toString(); String newName = newNameO.toString(); File file = file(oldName); if (file == null) throw new NamingException(sm.getString("resources.notFound", oldName)); File newFile = new File(base, newName); file.renameTo(newFile); }
From source file:org.apache.naming.modules.fs.FileDirContext.java
/** * Enumerates the names bound in the named context, along with the class * names of objects bound to them. The contents of any subcontexts are * not included.//from ww w . j av a2 s . co m * <p> * If a binding is added to or removed from this context, its effect on * an enumeration previously returned is undefined. * * @param name the name of the context to list * @return an enumeration of the names and class names of the bindings in * this context. Each element of the enumeration is of type NameClassPair. * @exception NamingException if a naming exception is encountered */ public NamingEnumeration list(Name nameN) throws NamingException { String name = nameN.toString(); if (log.isDebugEnabled()) log.debug("list " + name); File file = file(name); if (file == null) throw new NamingException(sm.getString("resources.notFound", name)); Vector entries = list(file); return new NamingContextEnumeration(entries.elements(), this, false); }
From source file:org.apache.naming.modules.fs.FileDirContext.java
/** * Enumerates the names bound in the named context, along with the * objects bound to them. The contents of any subcontexts are not * included.//from w ww .j av a 2 s . c o m * <p> * If a binding is added to or removed from this context, its effect on * an enumeration previously returned is undefined. * * @param name the name of the context to list * @return an enumeration of the bindings in this context. * Each element of the enumeration is of type Binding. * @exception NamingException if a naming exception is encountered */ public NamingEnumeration listBindings(Name nameN) throws NamingException { String name = nameN.toString(); if (log.isDebugEnabled()) log.debug("listBindings " + name); File file = file(name); if (file == null) throw new NamingException(sm.getString("resources.notFound", name)); Vector entries = list(file); return new NamingContextEnumeration(entries.elements(), this, true); }
From source file:org.apache.naming.modules.fs.FileDirContext.java
/** * Retrieves selected attributes associated with a named object. * See the class description regarding attribute models, attribute type * names, and operational attributes.//from w w w . j av a 2 s . c om * * @return the requested attributes; never null * @param name the name of the object from which to retrieve attributes * @param attrIds the identifiers of the attributes to retrieve. null * indicates that all attributes should be retrieved; an empty array * indicates that none should be retrieved * @exception NamingException if a naming exception is encountered */ public Attributes getAttributes(Name nameN, String[] attrIds) throws NamingException { String name = nameN.toString(); if (log.isDebugEnabled()) log.debug("getAttributes " + name); // Building attribute list File file = file(name); if (file == null) throw new NamingException(sm.getString("resources.notFound", name)); return new FileAttributes(file); }
From source file:org.apache.naming.modules.fs.FileDirContext.java
/** * Binds a name to an object, along with associated attributes, * overwriting any existing binding. If attrs is null and obj is a * DirContext, the attributes from obj are used. If attrs is null and obj * is not a DirContext, any existing attributes associated with the object * already bound in the directory remain unchanged. If attrs is non-null, * any existing attributes associated with the object already bound in * the directory are removed and attrs is associated with the named * object. If obj is a DirContext and attrs is non-null, the attributes * of obj are ignored./*from w w w . j ava 2s. c o m*/ * * @param name the name to bind; may not be empty * @param obj the object to bind; possibly null * @param attrs the attributes to associate with the binding * @exception InvalidAttributesException if some "mandatory" attributes * of the binding are not supplied * @exception NamingException if a naming exception is encountered */ public void rebind(Name nameN, Object obj, Attributes attrs) throws NamingException { String name = nameN.toString(); // Note: No custom attributes allowed // Check obj type File file = new File(base, name); InputStream is = null; // if (obj instanceof Resource) { // try { // is = ((Resource) obj).streamContent(); // } catch (IOException e) { // } // } else // TODO support File, byte[], String if (obj instanceof InputStream) { is = (InputStream) obj; } else if (obj instanceof DirContext) { if (file.exists()) { if (!file.delete()) throw new NamingException(sm.getString("resources.bindFailed", name)); } if (!file.mkdir()) throw new NamingException(sm.getString("resources.bindFailed", name)); } if (is == null) throw new NamingException(sm.getString("resources.bindFailed", name)); // Open os try { FileOutputStream os = null; byte buffer[] = new byte[BUFFER_SIZE]; int len = -1; try { os = new FileOutputStream(file); while (true) { len = is.read(buffer); if (len == -1) break; os.write(buffer, 0, len); } } finally { if (os != null) os.close(); is.close(); } } catch (IOException e) { throw new NamingException(sm.getString("resources.bindFailed", e)); } }
From source file:org.apache.naming.modules.fs.FileDirContext.java
/** * Creates and binds a new context, along with associated attributes. * This method creates a new subcontext with the given name, binds it in * the target context (that named by all but terminal atomic component of * the name), and associates the supplied attributes with the newly * created object. All intermediate and target contexts must already * exist. If attrs is null, this method is equivalent to * Context.createSubcontext()./*from w ww . j a v a 2 s.c o m*/ * * @param name the name of the context to create; may not be empty * @param attrs the attributes to associate with the newly created context * @return the newly created context * @exception NameAlreadyBoundException if the name is already bound * @exception InvalidAttributesException if attrs does not contain all * the mandatory attributes required for creation * @exception NamingException if a naming exception is encountered */ public DirContext createSubcontext(Name nameN, Attributes attrs) throws NamingException { String name = nameN.toString(); File file = new File(base, name); if (file.exists()) throw new NameAlreadyBoundException(sm.getString("resources.alreadyBound", name)); if (!file.mkdir()) throw new NamingException(sm.getString("resources.bindFailed", name)); return (DirContext) lookup(name); }
From source file:org.apache.naming.modules.java.ContextBindings.java
/** * Binds a naming context to a thread.// ww w . java2s .c om * * @param name Name of the context * @param token Security token */ public static void bindThread(Object name, Object token) throws NamingException { // log.info( "BIND: " + name + " " + token ); if (ContextAccessController.checkSecurityToken(name, token)) { Context context = (Context) contextNameBindings.get(name); if (context == null) throw new NamingException(sm.getString("contextBindings.unknownContext", name)); threadBindings.put(Thread.currentThread(), context); threadNameBindings.put(Thread.currentThread(), name); } }