KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > naming > directory > SchemaViolationException

javax.naming.directory
Class SchemaViolationException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by javax.naming.NamingException
              extended by javax.naming.directory.SchemaViolationException
All Implemented Interfaces:
Serializable
See Also:
Top Examples, Source Code, Context.bind(javax.naming.Name, java.lang.Object), DirContext.bind(javax.naming.Name, java.lang.Object, javax.naming.directory.Attributes), Context.rebind(javax.naming.Name, java.lang.Object), DirContext.rebind(javax.naming.Name, java.lang.Object, javax.naming.directory.Attributes), DirContext.createSubcontext(javax.naming.Name, javax.naming.directory.Attributes), Context.createSubcontext(javax.naming.Name), DirContext.modifyAttributes(javax.naming.Name, int, javax.naming.directory.Attributes)

public SchemaViolationException()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[376]Create factory, group, user in LDAP
By aurelio { dot } vahi { at } madrid { dot } sema { dot } slb { dot } com on 2003/09/01 11:31:04  Rate
public void CreateFactory ( Attributes myAttrs )  {  
                            
         myAttrs.put ( "ou", factory ) ; 
                  
     }  
  
  
     public void CreateGroup ( Attributes myAttrs )  {  
                            
         myAttrs.put ( "cn", office ) ; 
                  
     }  
  
  
     public void CreateUser ( Attributes myAttrs )  {  
                            
         myAttrs.put ( "cn", username ) ; 
         myAttrs.put ( "title", title ) ; 
         myAttrs.put ( "mail", mailAddress ) ; 
         myAttrs.put ( "uid", userKey ) ;         
                  
     }  
          
    public void AddRecord (  String adminUid, String adminPasswd, String adminDomain  )  {  
    
       try  {  
                      
            
           Attributes factAttrs = new BasicAttributes (  true  ) ; 
           Attribute objFact = new BasicAttribute ( "objectclass" ) ;           
           objFact.add ( "top" ) ; 
           objFact.add ( "organizationalunit" ) ; 
           factAttrs.put ( objFact ) ; 
            
           Attributes groupAttrs = new BasicAttributes (  true  ) ; 
           Attribute objGroup = new BasicAttribute ( "objectclass" ) ; 
           objGroup.add ( "top" ) ; 
           objGroup.add ( "groupofuniquenames" ) ; 
           groupAttrs.put ( objGroup ) ; 
  
  
           Attributes userAttrs = new BasicAttributes (  true  ) ; 
           Attribute objUser = new BasicAttribute ( "objectclass" ) ; 
           objUser.add ( "top" ) ; 
           objUser.add ( "person" ) ; 
           userAttrs.put ( objUser ) ; 
            
           String factoryDomain = new String (  ) ; 
           String groupDomain = new String (  ) ; 
           String userDomain = new String (  ) ; 
            
            //Hashtable for environmental information 
           Hashtable env = new Hashtable ( 11 ) ; 
           env.put ( Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory" ) ; 
           env.put ( Context.PROVIDER_URL, urlProvider  ) ; 
     env.put (  Context.SECURITY_AUTHENTICATION, "simple"  ) ; 
     env.put (  Context.SECURITY_PRINCIPAL, "uid=admin,ou=administrators,ou=topologymanagement,o=netscaperoot" ) ; 
     env.put (  Context.SECURITY_CREDENTIALS, "aimldap"  ) ; 
                  
            //Get a reference to a directory context 
            DirContext ctx = new InitialDirContext ( env ) ; 
  
  
     // Add Factory 
                  try {  
                 if (  factory != null  )  {  
                     myAttrs = factAttrs; 
                     CreateFactory ( myAttrs ) ; 
                     factoryDomain = "ou=" + factory + "," + domainCondition; 
                     //if ( ctx.getAttributes ( "ou" ) .get ( factory )  == null  )  
                         ctx.bind (  factoryDomain, this, myAttrs ) ; 
                  }  else  {  
                     ctx.close (  ) ; 
                     return; 
                  }  
                  }  catch ( javax.naming.NameAlreadyBoundException e  )  {  
                      System.out.println (  "javax.naming.NameAlreadyBoundException --- > " + e.getMessage (  )  ) ; 
                  }  
     // Add Group 
                 try  {  
                 if (  office != null  )  {  
                     myAttrs = groupAttrs; 
                     CreateGroup ( myAttrs ) ; 
                     groupDomain = "cn=" + office + "," + factoryDomain; 
                     //if ( ctx.getAttributes ( "cn" ) .get ( office )  == null  )  
                         ctx.bind (  groupDomain, this, myAttrs ) ;     
                  }  else  {  
                     ctx.close (  ) ; 
                     return; 
                  }  
                  }  catch ( javax.naming.NameAlreadyBoundException e  )  {  
                      System.out.println (  "javax.naming.NameAlreadyBoundException --- > " + e.getMessage (  )  ) ; 
                  }  
                   
     // Add user 
                 try  {  
                 if (  username != null  )  {  
                     myAttrs = userAttrs; 
                     CreateUser ( myAttrs ) ; 
                     userDomain = "cn=" + username + "," + groupDomain; 
                     //if ( ctx.getAttributes ( "cn" ) .get ( username )  == null  )  
                         /////////////////////////////////////////// 
                         // The exception is rised here with message 
 //javax.naming.directory.SchemaViolationException:  [ LDAP: error code //65 - Object Class Violation ] ; remaining name 'cn=Pepito,cn=Grupo de //Produccion,ou=Factory 100,dc=aim' 
                         /////////////////////////////////////////// 
  
  
                         ctx.bind (  userDomain, this, myAttrs ) ;     
                  }  else  {                          
                     ctx.close (  ) ; 
                     return; 
                  }  
                  }  catch ( javax.naming.NameAlreadyBoundException e  )  {  
                      System.out.println (  "javax.naming.NameAlreadyBoundException --- > " + e.getMessage (  )  ) ; 
                  }  
         
        } catch ( Exception e )  {        
          e.printStackTrace (  ) ; 
          return; 
        }  
      }  
 


public SchemaViolationException(String explanation)
See Also:
Throwable.getMessage()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags