javax.naming.NameAlreadyBoundException Java Examples
The following examples show how to use
javax.naming.NameAlreadyBoundException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultInitialContext.java From piranha with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Bind the object to the given name. * * @param name the name. * @param object the object. * @throws NamingException when an naming error occurs. */ @Override public void bind(String name, Object object) throws NamingException { checkClosed(); if (name.contains("/")) { String[] names = name.split("/"); DefaultInitialContext contextMap = this; for (int i = 0; i < names.length - 1; i++) { try { contextMap = (DefaultInitialContext) contextMap.lookup(names[i]); } catch (NameNotFoundException ne) { contextMap = (DefaultInitialContext) contextMap.createSubcontext(names[i]); } } contextMap.bind(names[names.length - 1], object); } else if (!bindings.containsKey(name)) { bindings.put(name, object); } else { throw new NameAlreadyBoundException("Name '" + name + "' already bound"); } }
Example #2
Source File: VFSDirContext.java From olat with Apache License 2.0 | 6 votes |
/** * 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. * * @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 */ @Override public void rename(String oldName, String newName) throws NamingException { VFSItem oldFile = resolveFile(oldName); if (oldFile == null) throw new NamingException(smgr.getString("resources.notFound", oldName)); VFSItem newFile = resolveFile(newName); if (newFile != null) throw new NameAlreadyBoundException(); VFSStatus status = oldFile.rename(newName); if (status == VFSConstants.NO) throw new NameAlreadyBoundException(); }
Example #3
Source File: LocalContext.java From unitime with Apache License 2.0 | 6 votes |
@Override public Context createSubcontext(Name name) throws NamingException { if (name.isEmpty()) throw new InvalidNameException("Cannot bind empty name"); Name nm = getMyComponents(name); String atom = nm.get(0); Object inter = iBindings.get(atom); if (nm.size() == 1) { if (inter != null) throw new NameAlreadyBoundException("Use rebind to override"); Context child = createCtx(this, atom, iEnv); iBindings.put(atom, child); return child; } else { if (!(inter instanceof Context)) throw new NotContextException(atom + " does not name a context"); return ((Context) inter).createSubcontext(nm.getSuffix(1)); } }
Example #4
Source File: VFSDirContext.java From olat with Apache License 2.0 | 6 votes |
/** * 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(). * * @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 */ @Override public DirContext createSubcontext(String name, Attributes attrs) throws NamingException { VFSItem file = resolveFile(name); if (file != null) throw new NameAlreadyBoundException(smgr.getString("resources.alreadyBound", name)); int lastSlash = name.lastIndexOf('/'); if (lastSlash == -1) throw new NamingException(); String parent = name.substring(0, lastSlash); VFSItem folder = resolveFile(parent); if (folder == null || (!(folder instanceof VFSContainer))) throw new NamingException(smgr.getString("resources.bindFailed", name)); String newName = name.substring(lastSlash + 1); VFSItem childContainer = ((VFSContainer) folder).createChildContainer(newName); if (childContainer == null) throw new NamingException(smgr.getString("resources.bindFailed", name)); return (DirContext) lookup(name); }
Example #5
Source File: LocalContext.java From unitime with Apache License 2.0 | 6 votes |
@Override public void bind(Name name, Object obj) throws NamingException { if (name.isEmpty()) { throw new InvalidNameException("Cannot bind empty name"); } Name nm = getMyComponents(name); String atom = nm.get(0); Object inter = iBindings.get(atom); if (nm.size() == 1) { if (inter != null) throw new NameAlreadyBoundException("Use rebind to override"); obj = NamingManager.getStateToBind(obj, new CompositeName().add(atom), this, iEnv); iBindings.put(atom, obj); } else { if (!(inter instanceof Context)) throw new NotContextException(atom + " does not name a context"); ((Context) inter).bind(nm.getSuffix(1), obj); } }
Example #6
Source File: VFSDirContext.java From olat with Apache License 2.0 | 6 votes |
/** * 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. * * @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 */ @Override public void rename(String oldName, String newName) throws NamingException { VFSItem oldFile = resolveFile(oldName); if (oldFile == null) throw new NamingException(smgr.getString("resources.notFound", oldName)); VFSItem newFile = resolveFile(newName); if (newFile != null) throw new NameAlreadyBoundException(); VFSStatus status = oldFile.rename(newName); if (status == VFSConstants.NO) throw new NameAlreadyBoundException(); }
Example #7
Source File: VFSDirContext.java From olat with Apache License 2.0 | 6 votes |
/** * 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(). * * @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 */ @Override public DirContext createSubcontext(String name, Attributes attrs) throws NamingException { VFSItem file = resolveFile(name); if (file != null) throw new NameAlreadyBoundException(smgr.getString("resources.alreadyBound", name)); int lastSlash = name.lastIndexOf('/'); if (lastSlash == -1) throw new NamingException(); String parent = name.substring(0, lastSlash); VFSItem folder = resolveFile(parent); if (folder == null || (!(folder instanceof VFSContainer))) throw new NamingException(smgr.getString("resources.bindFailed", name)); String newName = name.substring(lastSlash + 1); VFSItem childContainer = ((VFSContainer) folder).createChildContainer(newName); if (childContainer == null) throw new NamingException(smgr.getString("resources.bindFailed", name)); return (DirContext) lookup(name); }
Example #8
Source File: WebSphereMQ.java From perf-harness with MIT License | 6 votes |
public DestinationWrapper<Topic> lookupTopic(String topic, JMSContext context) throws JMSException, NamingException { if (usingJNDI || context == null) { if (autoCreateTopics) { Topic t = configureMQTopic((MQTopic)context.createTopic(topic)); try { getInitialContext().bind(topic, t); Log.logger.fine( "Auto-created JNDI entry for: " + topic ); } catch ( NameAlreadyBoundException e ) { // No op - already exists } } // end if return lookupTopicFromJNDI(topic); } else { return new DestinationWrapper<Topic>(topic, configureMQTopic((MQTopic) context.createTopic(topic))); } }
Example #9
Source File: ObjectContext.java From oodt with Apache License 2.0 | 6 votes |
public synchronized void bind(String name, Object obj) throws NamingException { if (name == null) { throw new IllegalArgumentException("Name required"); } if (name.length() == 0) { throw new InvalidNameException("Cannot bind object named after context"); } // If it's an alias name, stop here. if (aliases.containsKey(name)) { throw new NameAlreadyBoundException("Name \"" + name + "\" already bound as an aliased name"); } // Make sure it isn't bound anywhere for (NamingEnumeration e = list(""); e.hasMore();) { NameClassPair nameClassPair = (NameClassPair) e.next(); if (name.equals(nameClassPair.getName())) { throw new NameAlreadyBoundException("Name \"" + name + "\" already bound by a managed subcontext"); } } doRebind(name, obj); }
Example #10
Source File: Assembler.java From tomee with Apache License 2.0 | 6 votes |
public void bindGlobals(final Map<String, Object> bindings) throws NamingException { final Context containerSystemContext = containerSystem.getJNDIContext(); for (final Entry<String, Object> value : bindings.entrySet()) { final String path = value.getKey(); // keep only global bindings if (path.startsWith("module/") || path.startsWith("app/") || path.startsWith("comp/") || path.equalsIgnoreCase("global/dummy")) { continue; } // a bit weird but just to be consistent if user doesn't lookup directly the resource final Context lastContext = Contexts.createSubcontexts(containerSystemContext, path); try { lastContext.rebind(path.substring(path.lastIndexOf('/') + 1, path.length()), value.getValue()); } catch (final NameAlreadyBoundException nabe) { nabe.printStackTrace(); } containerSystemContext.rebind(path, value.getValue()); } }
Example #11
Source File: WebSphereMQ.java From perf-harness with MIT License | 6 votes |
public void createQueue(String name) throws Exception { if ( usingJNDI ) { // Assumes use of ME01 SupportPac for WMQInitialContextFactory Queue queue = configureMQQueue( new MQQueue(name) ); try { getInitialContext().bind( name, queue ); } catch ( NameAlreadyBoundException e ) { // No op - already exists } } else { // "new" PCF style. PCFMessageAgent agent = new PCFMessageAgent( Config.parms.getString("jh"), Config.parms.getInt("jp"), "CLIENT" ); PCFMessage message = new PCFMessage( CMQCFC.MQCMD_CREATE_Q ); message.addParameter( CMQC.MQCA_Q_NAME, name); agent.send( message ); } }
Example #12
Source File: NameNode.java From tomee with Apache License 2.0 | 6 votes |
public void unbind(final ParsedName name) throws NameAlreadyBoundException { final int compareResult = name.compareTo(atomicHash); if (compareResult == ParsedName.IS_EQUAL && name.getComponent().equals(atomicName)) { if (name.next()) { if (subTree != null) { subTree.unbind(name); } } else { unbound = true; myObject = null; parentTree.unbind(this); } } else if (compareResult == ParsedName.IS_LESS) { if (lessTree != null) { lessTree.unbind(name); } } else {//ParsedName.IS_GREATER ... if (grtrTree != null) { grtrTree.unbind(name); } } }
Example #13
Source File: IvmContext.java From tomee with Apache License 2.0 | 6 votes |
public Context createSubcontext(String name) throws NamingException { if(checkReadOnly()) { //TODO: null is fine if there is a one time - 10 calls will log a single time - log line (warning?) return null; } final int indx = name.indexOf(':'); if (indx > -1) { /* The ':' character will be in the path if its an absolute path name starting with the schema 'java:'. We strip the schema off the path before passing it to the node.resolve method. */ name = name.substring(indx + 1); } if (fastCache.containsKey(name)) { throw new NameAlreadyBoundException(); } else { return mynode.createSubcontext(getParsedNameFor(name), readOnly); } }
Example #14
Source File: WebSphereMQ.java From perf-harness with MIT License | 6 votes |
public DestinationWrapper<Topic> lookupTopic( String topic, Session session ) throws JMSException, NamingException { if ( usingJNDI || session==null ) { if ( autoCreateTopics ) { Topic t = configureMQTopic( (MQTopic)session.createTopic( topic ) ); try { getInitialContext().bind( topic, t ); Log.logger.fine( "Auto-created JNDI entry for "+topic ); } catch ( NameAlreadyBoundException e ) { // No op - already exists } } // end if return lookupTopicFromJNDI( topic ); } else { return new DestinationWrapper<Topic>(topic, configureMQTopic((MQTopic) session.createTopic(topic))); } }
Example #15
Source File: IvmContext.java From tomee with Apache License 2.0 | 6 votes |
public void bind(String name, final Object obj) throws NamingException { if(checkReadOnly()) { return; } final int indx = name.indexOf(':'); if (indx > -1) { /* The ':' character will be in the path if its an absolute path name starting with the schema 'java:'. We strip the schema off the path before passing it to the node.resolve method. */ name = name.substring(indx + 1); } if (fastCache.containsKey(name)) { throw new NameAlreadyBoundException(); } else { final ParsedName parsedName = getParsedNameFor(name); mynode.bind(parsedName, obj); } }
Example #16
Source File: TContext.java From oodt with Apache License 2.0 | 5 votes |
public void rename(String oldName, String newName) throws NamingException { if (!bindings.containsKey(oldName)) throw new NameNotFoundException(oldName); if (bindings.containsKey(newName)) throw new NameAlreadyBoundException(newName); if (!newName.startsWith(prefix)) throw new InvalidNameException("Name doesn't start with " + prefix); bindings.put(newName, bindings.remove(oldName)); }
Example #17
Source File: right_LmiInitialContext_1.6.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
public void rename(String oldName, String newName) throws NamingException { if (TraceCarol.isDebugJndiCarol()) { TraceCarol.debugJndiCarol("LmiInitialContext.rename(\"" + oldName + "\",\"" + newName + "\")"); } if (oldName.equals("") || newName.equals("")) throw new InvalidNameException("Cannot rename empty name"); if (bindings.get(newName) != null) throw new NameAlreadyBoundException(newName + " is already bound"); Object oldb = bindings.remove(oldName); if (oldb == null) throw new NameNotFoundException(oldName + " not bound"); bindings.put(newName, oldb); }
Example #18
Source File: right_LmiInitialContext_1.6.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
public void bind(String name, Object obj) throws NamingException { if (TraceCarol.isDebugJndiCarol()) { TraceCarol.debugJndiCarol("LmiInitialContext.bind(\"" + name + "\"," + simpleClass(obj.getClass().getName()) + " object)"); } if (name.equals("")) { throw new InvalidNameException("Cannot bind empty name"); } if (bindings.get(name) != null) { throw new NameAlreadyBoundException("Use rebind to override"); } bindings.put(name, encodeObject(obj)); }
Example #19
Source File: left_LmiInitialContext_1.5.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
public void rename(String oldName, String newName) throws NamingException { if (TraceCarol.isDebugJndiCarol()) { TraceCarol.debugJndiCarol("LmiInitialContext.rename(\"" + oldName + "\",\"" + newName + "\")"); } if (oldName.equals("") || newName.equals("")) throw new InvalidNameException("Cannot rename empty name"); if (bindings.get(newName) != null) throw new NameAlreadyBoundException(newName + " is already bound"); Object oldb = bindings.remove(oldName); if (oldb == null) throw new NameNotFoundException(oldName + " not bound"); bindings.put(newName, oldb); }
Example #20
Source File: left_LmiInitialContext_1.5.java From gumtree-spoon-ast-diff with Apache License 2.0 | 5 votes |
public void bind(String name, Object obj) throws NamingException { if (TraceCarol.isDebugJndiCarol()) { TraceCarol.debugJndiCarol("LmiInitialContext.bind(\"" + name + "\"," + simpleClass(obj.getClass().getName()) + " object)"); } if (name.equals("")) { throw new InvalidNameException("Cannot bind empty name"); } if (bindings.get(name) != null) { throw new NameAlreadyBoundException("Use rebind to override"); } bindings.put(name, encodeObject(obj)); }
Example #21
Source File: NameNode.java From tomee with Apache License 2.0 | 5 votes |
public IvmContext createSubcontext(final ParsedName name, final boolean createReadOnlyContext) throws NameAlreadyBoundException { try { bind(name, null); name.reset(); return (IvmContext) resolve(name, createReadOnlyContext); } catch (final NameNotFoundException exception) { exception.printStackTrace(); throw new OpenEJBRuntimeException(exception); } }
Example #22
Source File: IvmContextTest.java From tomee with Apache License 2.0 | 5 votes |
public void testAlreadyBound() throws Exception { final IvmContext context = new IvmContext(); context.bind("number", 2); try { context.bind("number", 3); fail("A NameAlreadyBoundException should have been thrown"); } catch (final NameAlreadyBoundException e) { // pass } }
Example #23
Source File: Step4Test.java From learning with Apache License 2.0 | 5 votes |
private void bindDataSource(InitialContext context, String name, DataSource ds) throws Exception { try { context.bind(name, ds); } catch (NameAlreadyBoundException e) { e.getMessage(); // ignore } }
Example #24
Source File: TestUtil.java From apiman with Apache License 2.0 | 5 votes |
/** * Ensure that the given name is bound to a context. * @param ctx * @param name * @throws NamingException */ public static final Context ensureCtx(InitialContext ctx, String name) throws NamingException { try { return ctx.createSubcontext(name); } catch (NameAlreadyBoundException e) { // this is ok return (Context) ctx.lookup(name); } }
Example #25
Source File: InVMContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public Context createSubcontext(String name) throws NamingException { name = trimSlashes(name); if (map.get(name) != null) { throw new NameAlreadyBoundException(name); } InVMContext c = new InVMContext(getNameInNamespace()); map.put(name, c); return c; }
Example #26
Source File: InVMNamingContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void internalBind(String name, final Object obj, final boolean rebind) throws NamingException { UnitTestLogger.LOGGER.debug("Binding " + name + " obj " + obj + " rebind " + rebind); name = trimSlashes(name); int i = name.lastIndexOf("/"); InVMNamingContext c = this; if (i != -1) { String path = name.substring(0, i); c = (InVMNamingContext) lookup(path); } name = name.substring(i + 1); if (!rebind && c.map.get(name) != null) { throw new NameAlreadyBoundException(name); } c.map.put(name, obj); }
Example #27
Source File: InVMNamingContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Override public Context createSubcontext(String name) throws NamingException { name = trimSlashes(name); if (map.get(name) != null) { throw new NameAlreadyBoundException(name); } InVMNamingContext c = new InVMNamingContext(getNameInNamespace()); map.put(name, c); return c; }
Example #28
Source File: InVMContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void internalBind(String name, final Object obj, final boolean rebind) throws NamingException { UnitTestLogger.LOGGER.debug("Binding " + name + " obj " + obj + " rebind " + rebind); name = trimSlashes(name); int i = name.lastIndexOf("/"); InVMContext c = this; if (i != -1) { String path = name.substring(0, i); c = (InVMContext) lookup(path); } name = name.substring(i + 1); if (!rebind && c.map.get(name) != null) { throw new NameAlreadyBoundException(name); } c.map.put(name, obj); }
Example #29
Source File: InVMContext.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void internalBind(String name, final Object obj, final boolean rebind) throws NamingException { InVMContext.log.debug("Binding " + name + " obj " + obj + " rebind " + rebind); name = trimSlashes(name); int i = name.lastIndexOf("/"); InVMContext c = this; if (i != -1) { String path = name.substring(0, i); c = (InVMContext) lookup(path); } name = name.substring(i + 1); if (!rebind && c.map.get(name) != null) { throw new NameAlreadyBoundException(name); } c.map.put(name, obj); }
Example #30
Source File: DefaultInitialContext.java From piranha with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Rename the object. * * @param oldName the old name. * @param newName the new name. * @throws NamingException when a naming error occurs. */ @Override public void rename(String oldName, String newName) throws NamingException { checkClosed(); try { lookup(newName); throw new NameAlreadyBoundException(newName); } catch (NameNotFoundException nnfe) { // intentionally not caught. } Object object = lookup(oldName); bind(newName, object); unbind(oldName); }