List of usage examples for javax.naming.ldap LdapName addAll
public Name addAll(List<Rdn> suffixRdns)
From source file:Main.java
public static void main(String args[]) { try {/* w w w . ja va2 s.c o m*/ LdapName dn = new LdapName("ou=Fruits,o=Food"); LdapName dn2 = new LdapName("ou=Summer"); System.out.println(dn.addAll(dn2)); System.out.println(dn.add(0, "o=Resources")); System.out.println(dn.add("cn=WaterMelon")); System.out.println(dn.remove(1)); System.out.println(dn); } catch (InvalidNameException e) { e.printStackTrace(); } }
From source file:ModifyLdapName.java
public static void main(String args[]) { try {/*from w ww. j a v a 2s .c om*/ LdapName dn = new LdapName("ou=Fruits,o=Food"); LdapName dn2 = new LdapName("ou=Summer"); System.out.println(dn.addAll(dn2)); // ou=Summer,ou=Fruits,o=Food System.out.println(dn.add(0, "o=Resources")); // ou=Summer,ou=Fruits,o=Food,o=Resources System.out.println(dn.add("cn=WaterMelon")); // cn=WaterMelon,ou=Summer,ou=Fruits,o=Food,o=Resources System.out.println(dn.remove(1)); // o=Food System.out.println(dn); // cn=WaterMelon,ou=Summer,ou=Fruits,o=Resources } catch (InvalidNameException e) { e.printStackTrace(); } }
From source file:org.springframework.ldap.odm.test.TestSchemaToJava.java
@Test public void generate() throws Exception { final String className = "Person"; final String packageName = "org.springframework.ldap.odm.testclasses"; File tempFile = File.createTempFile("test-odm-syntax-to-class-map", ".txt"); FileUtils.copyInputStreamToFile(new ClassPathResource("/syntax-to-class-map.txt").getInputStream(), tempFile);/*from w ww .ja v a 2s . co m*/ // Add classes dir to class path - needed for compilation System.setProperty("java.class.path", System.getProperty("java.class.path") + File.pathSeparator + "target/classes"); String[] flags = new String[] { "--url", "ldap://127.0.0.1:" + port, "--objectclasses", "organizationalperson", "--syntaxmap", tempFile.getAbsolutePath(), "--class", className, "--package", packageName, "--outputdir", tempDir }; // Generate the code using SchemaToJava SchemaToJava.main(flags); tempFile.delete(); // Java 5 - we'll use the Java 6 Compiler API once we can drop support for Java 5. String javaDir = calculateOutputDirectory(tempDir, packageName); CompilerInterface.compile(javaDir, className + ".java"); // Java 5 // OK it compiles so lets load our new class URL[] urls = new URL[] { new File(tempDir).toURI().toURL() }; URLClassLoader ucl = new URLClassLoader(urls, getClass().getClassLoader()); Class<?> clazz = ucl.loadClass(packageName + "." + className); // Create our OdmManager using our new class OdmManagerImpl odmManager = new OdmManagerImpl(converterManager, contextSource); odmManager.addManagedClass(clazz); // And try reading from the directory using it LdapName testDn = LdapUtils.newLdapName(baseName); testDn.addAll(LdapUtils.newLdapName("cn=William Hartnell,ou=Doctors")); Object fromDirectory = odmManager.read(clazz, testDn); LOG.debug(String.format("Read - %1$s", fromDirectory)); // Check some returned values Method getDnMethod = clazz.getMethod("getDn"); Object dn = getDnMethod.invoke(fromDirectory); assertEquals(testDn, dn); Method getCnIteratorMethod = clazz.getMethod("getCnIterator"); @SuppressWarnings("unchecked") Iterator<String> cnIterator = (Iterator<String>) getCnIteratorMethod.invoke(fromDirectory); int cnCount = 0; while (cnIterator.hasNext()) { cnCount++; assertEquals("William Hartnell", cnIterator.next()); } assertEquals(1, cnCount); Method telephoneNumberIteratorMethod = clazz.getMethod("getTelephoneNumberIterator"); @SuppressWarnings("unchecked") Iterator<Integer> telephoneNumberIterator = (Iterator<Integer>) telephoneNumberIteratorMethod .invoke(fromDirectory); int telephoneNumberCount = 0; while (telephoneNumberIterator.hasNext()) { telephoneNumberCount++; assertEquals(Integer.valueOf(1), telephoneNumberIterator.next()); } assertEquals(1, telephoneNumberCount); // Reread and check whether equals and hashCode are at least sane Object fromDirectory2 = odmManager.read(clazz, testDn); assertEquals(fromDirectory, fromDirectory2); assertEquals(fromDirectory.hashCode(), fromDirectory2.hashCode()); }