QueryGenUtil { protected static Set<String> getClassNames(ObjectStore os, String clsName) throws ObjectStoreException { boolean useSubClasses = false; Set<String> clsNames = new LinkedHashSet<String>(); for (String part : clsName.split(",")) { if (part.indexOf('.') != -1) { QueryAndClass qac = createClassFindingQuery(os.getModel(), part); for (Object cls : os.executeSingleton(qac.getQuery(), 1000, false, false, false)) { Class<?> clazz = (Class<?>) cls; for (Class<?> classPart : Util.decomposeClass(clazz)) { if (qac.getClazz().isAssignableFrom(classPart)) { clsNames.add(TypeUtil.unqualifiedName(classPart.getName())); } } } } else { if (part.startsWith("+")) { part = part.substring(1); useSubClasses = true; } ClassDescriptor cld = os.getModel().getClassDescriptorByName(os.getModel() .getPackageName() + "." + part); if (cld == null) { throw new IllegalArgumentException("cannot find ClassDescriptor for " + part + " in argument \"" + clsName + "\""); } clsNames.add(part); if (useSubClasses) { for (ClassDescriptor nextCld : os.getModel().getAllSubs(cld)) { clsNames.add(TypeUtil.unqualifiedName(nextCld.getName())); } } } } return clsNames; } private  QueryGenUtil(); static void validatePath(String path, Model model); static Set<String> expandPath(ObjectStore os, String path); static Query constructQuery(Model model, String path);  }
@Test public void testGetClassNames() throws Exception { String clsName = "+Employee"; Set expected = new HashSet(Arrays.asList(new String[] {"Employee", "Manager", "CEO"})); Assert.assertEquals(expected, QueryGenUtil.getClassNames(os, clsName)); }
@Test public void testGetClassNames2() throws Exception { String clsName = "Employee,Department"; Set expected = new HashSet(Arrays.asList("Employee", "Department")); Assert.assertEquals(expected, QueryGenUtil.getClassNames(os, clsName)); }
@Test public void testGetClassNames3() throws Exception { String clsName = "+Employee,Department"; Set expected = new HashSet(Arrays.asList("Employee", "Manager", "CEO", "Department")); Assert.assertEquals(expected, QueryGenUtil.getClassNames(os, clsName)); }
@Test public void testGetClassNames4() throws Exception { String clsName = "Department.employees.class"; Set expected = new HashSet(Arrays.asList(new String[] {"Employee", "Manager", "CEO"})); Assert.assertEquals(expected, QueryGenUtil.getClassNames(os, clsName)); }