List of usage examples for javax.naming NameAlreadyBoundException NameAlreadyBoundException
public NameAlreadyBoundException(String explanation)
From source file:com.dattack.naming.AbstractContext.java
@Override public void bind(final Name name, final Object object) throws NamingException { ensureContextNotClosed();//w ww . j a v a 2 s .c om 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:NonSerializableFactory.java
/** Place an object into the NonSerializableFactory namespace for subsequent access by getObject. There cannot be an already existing binding for key. /*from w w w .ja v a2 s. co m*/ @param key the name to bind target under. This should typically be the name that will be used to bind target in the JNDI namespace, but it does not have to be. @param target the non-Serializable object to bind. @throws NameAlreadyBoundException thrown if key already exists in the NonSerializableFactory map */ public static synchronized void bind(String key, Object target) throws NameAlreadyBoundException { if (wrapperMap.containsKey(key) == true) throw new NameAlreadyBoundException(key + " already exists in the NonSerializableFactory map"); wrapperMap.put(key, target); }
From source file:de.fiz.ddb.aas.auxiliaryoperations.ThreadOrganisationCreate.java
/** * /*from ww w . j a v a 2s . c o m*/ * @return Organisation * @throws AASUnauthorizedException * @throws NamingException * @throws IOException * @throws CloneNotSupportedException * @throws IllegalAccessException * @throws Exception */ @PreAuthorize(privileges = { PrivilegeEnum.DEFAULT }, scope = Scope.ORGANIZATION) public Organisation call() throws AASUnauthorizedException, ExecutionException, NameAlreadyBoundException { Organisation vResult = this._orgObj; // -- Fr eine Prfung, ob bereits existent: // but only if that is not a copy in the export directory if (!this.isAddToLicensedOrgs() && organizationExists(this._orgObj.getOIDs().getOrgName())) { throw new NameAlreadyBoundException( "Error: A organization with ID: '" + this._orgObj.getOIDs().getOrgName() + "' already exists!"); } try { // -- Ist ein Parent bekannt, muss auch die komplette RDN aufgebaut // werden: if (!this.isAddToLicensedOrgs()) { if ((this._orgObj.getOrgRDN() == null) && (this._orgObj.getOrgParent() != null) && (!this._orgObj.getOrgParent().isEmpty())) { ThreadOIDsRDNComplement threadOIDsRDNComplement = new ThreadOIDsRDNComplement( new OIDs(this._orgObj.getOrgParent(), false), getPerformer()); this._orgParentOIDs = threadOIDsRDNComplement.call(); if (this._orgParentOIDs != null) { LOG.info("OrgParent = " + this._orgParentOIDs); this._orgObj.setOrgRDN(new StringBuilder(this._orgObj.getId()).append(",") .append(this._orgParentOIDs.getOrgRDN()).toString()); } else { throw new IllegalArgumentException("Error: A parent organization with ID: '" + this._orgObj.getOrgParent() + "' not found!"); } } else { this._orgObj.setOrgRDN(this._orgObj.getId()); } } // -- Ask about Geo coordinates but only if that is not a copy in the export directory or Licensed directory if (!this.isAddToLicensedOrgs() && !this.isIngestingOperation()) { boolean vQueryRequestForGeocoding = ((Math.abs(this._orgObj.getAddress().getLatitude()) <= 1e-6) || (Math.abs(this._orgObj.getAddress().getLongitude()) <= 1e-6)); if (vQueryRequestForGeocoding) { try { GeoRequest vGeoRequest = new GeoRequest(new GeoAdresse(this._orgObj.getAddress()), LDAPConnector.getSingletonInstance().getHttpProxy()); vGeoRequest.setAskForLocation(true); // -- should be set by Properties... change it! vGeoRequest.addAcceptLocationType(GeoLocationType.ROOFTOP, GeoLocationType.RANGE_INTERPOLATED, GeoLocationType.GEOMETRIC_CENTER, GeoLocationType.APPROXIMATE); _submit = LDAPConnector.getSingletonInstance().getExecutorServiceOne().submit(vGeoRequest); } catch (IllegalAccessException ex) { LOG.log(Level.SEVERE, "Error bei Adresse: " + this._orgObj.getAddress(), ex); } } } this.createOrg(); vResult = this._orgObj; // -- The performer gets automatically a member of this organization // X but only if that is not a copy in the export or licensed directory if ((!this.isAddToLicensedOrgs()) && (this._performer != null)) { //if ((this._performer != null)) { Map<OIDs, Set<PrivilegeEnum>> privileges = new HashMap<OIDs, Set<PrivilegeEnum>>(); privileges.put(this._orgObj.getOIDs(), new HashSet<PrivilegeEnum>()); privileges.get(this._orgObj.getOIDs()).add(PrivilegeEnum.ADMIN_ORG); ThreadUserOrgPrivilegsOperations threadUserOrgPrivilegsOperations = new ThreadUserOrgPrivilegsOperations( _performer.getUid(), privileges, Action.ADD, this._performer); threadUserOrgPrivilegsOperations.call(); } } catch (ExecutionException ex) { LOG.log(Level.WARNING, ex.getMessage(), ex.getCause()); throw ex; } catch (NameNotFoundException ex) { LOG.log(Level.SEVERE, ex.getMessage()); throw new ExecutionException(ex.getMessage(), ex); } catch (AssertionError ex) { LOG.log(Level.SEVERE, ex.getMessage()); throw new ExecutionException(ex.getMessage(), ex); } finally { if (this._ready != null) { this._ready.countDown(); } if ((_submit != null) && (!_submit.isDone()) && (!_submit.isCancelled())) { _submit.cancel(true); } } return vResult; }
From source file:com.dattack.naming.AbstractContext.java
@Override public void rename(final Name oldName, final Name newName) throws NamingException { ensureContextNotClosed();/* www.jav a2 s . c o m*/ if (newName.isEmpty()) { throw new InvalidNameException("Cannot bind to empty name"); } final Object oldValue = lookup(oldName); if (oldValue == null) { throw new NamingException(String.format("Cannot rename object: name not found (%s)", oldName)); } if (lookup(newName) != null) { throw new NameAlreadyBoundException( String.format("Cannot rename object: name already bound (%s)", newName)); } unbind(oldName); unbind(newName); bind(newName, oldValue); }
From source file:org.apache.directory.studio.connection.core.io.api.DirectoryApiConnectionWrapper.java
/** * Checks the given response./*from w w w . ja va2s.co m*/ * * @param response * the response * @throws Exception * if the LDAP result associated with the response is not a success */ private void checkResponse(ResultResponse response) throws Exception { if (response != null) { LdapResult ldapResult = response.getLdapResult(); if (ldapResult != null) { // NOT_ALLOWED_ON_NON_LEAF error (thrown when deleting an entry with children) if (ResultCodeEnum.NOT_ALLOWED_ON_NON_LEAF.equals(ldapResult.getResultCode())) { throw new ContextNotEmptyException(ldapResult.getDiagnosticMessage()); } // ENTRY_ALREADY_EXISTS error // (We need this conversion in the case where this error is thrown during an LDIF // import with the "Update existing entries" flag turned on) else if (ResultCodeEnum.ENTRY_ALREADY_EXISTS.equals(ldapResult.getResultCode())) { throw new NameAlreadyBoundException(ldapResult.getDiagnosticMessage()); } // Different from SUCCESS, we throw a generic exception else if (!ResultCodeEnum.SUCCESS.equals(ldapResult.getResultCode())) { int code = ldapResult.getResultCode().getResultCode(); String message = ldapResult.getDiagnosticMessage(); // Checking if we got a message from the LDAP result if (StringUtils.isEmpty(message)) { // Assigning the generic result code description message = Utils.getResultCodeDescription(code); } throw new Exception(NLS.bind("[LDAP: error code {0} - {1}]", new String[] //$NON-NLS-1$ { Integer.toString(code), message })); //$NON-NLS-1$ } } } }
From source file:org.apache.naming.modules.fs.FileDirContext.java
/** * Binds a name to an object, along with associated attributes. If attrs * is null, the resulting binding will have the attributes associated * with obj if obj is a DirContext, and no attributes otherwise. If attrs * is non-null, the resulting binding will have attrs as its attributes; * any attributes associated with obj are ignored. * /*from www . j a v a 2 s . co 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 NameAlreadyBoundException if name is already bound * @exception InvalidAttributesException if some "mandatory" attributes * of the binding are not supplied * @exception NamingException if a naming exception is encountered */ public void bind(Name nameN, Object obj, Attributes attrs) throws NamingException { String name = nameN.toString(); // Note: No custom attributes allowed File file = new File(base, name); if (file.exists()) throw new NameAlreadyBoundException(sm.getString("resources.alreadyBound", name)); rebind(name, obj, attrs); }
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()./* w w w. 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.olat.core.util.servlets.VFSDirContext.java
/** * Binds a name to an object, along with associated attributes. If attrs is null, the resulting binding will have the attributes associated with obj if obj is a * DirContext, and no attributes otherwise. If attrs is non-null, the resulting binding will have attrs as its attributes; any attributes associated with obj are * ignored.//from w w w. j av a 2 s .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 NameAlreadyBoundException if name is already bound * @exception InvalidAttributesException if some "mandatory" attributes of the binding are not supplied * @exception NamingException if a naming exception is encountered */ @Override public void bind(String name, Object obj, Attributes attrs) throws NamingException { // Note: No custom attributes allowed 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); VFSLeaf childLeaf = ((VFSContainer) folder).createChildLeaf(newName); if (childLeaf == null) throw new NamingException(smgr.getString("resources.bindFailed", name)); copyVFS(childLeaf, name, obj, attrs); VFSSecurityCallback callback = folder.getLocalSecurityCallback(); if (callback != null && callback.getSubscriptionContext() != null) { SubscriptionContext subContext = callback.getSubscriptionContext(); NotificationsManager.getInstance().markPublisherNews(subContext, null); } if (childLeaf instanceof MetaTagged) { MetaInfo infos = ((MetaTagged) childLeaf).getMetaInfo(); if (infos != null && infos.getAuthorIdentity() == null) { infos.setAuthor(userSession.getIdentity().getName()); infos.clearThumbnails(); infos.write(); } } // used by move operations if (obj instanceof VFSResource) { VFSResource vfsResource = (VFSResource) obj; if (vfsResource.vfsItem instanceof Versionable && ((Versionable) vfsResource.vfsItem).getVersions().isVersioned()) { Versionable currentVersion = (Versionable) vfsResource.vfsItem; VersionsManager.getInstance().move(currentVersion, childLeaf.getParentContainer()); } } }
From source file:org.olat.core.util.servlets.VFSDirContext.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(). * // w ww . j ava2 s . c om * @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); }