/** * Loads and registers roles listed in resource. * * @throws ObjectStoreConfigException */ public void loadRoles(ClassLoader cl) throws ObjectStoreConfigException { try { ClassLoader first = RoleClassLoader.class.getClassLoader(); Set<URL> loaded; loaded = load(new CheckForAnnotation(first), first, "annotations", ANNOTATIONS, true, new HashSet<URL>()); loaded = load(new CheckForAnnotation(cl), cl, "annotations", ANNOTATIONS, true, loaded); loaded = load(new CheckForConcept(first), first, "concepts", CONCEPTS, true, new HashSet<URL>()); loaded = load(new CheckForConcept(cl), cl, "concepts", CONCEPTS, true, loaded); loaded = load(new CheckForBehaviour(first), first, "behaviours", BEHAVIOURS, false, new HashSet<URL>()); loaded = load(new CheckForBehaviour(cl), cl, "behaviours", BEHAVIOURS, false, loaded); } catch (ObjectStoreConfigException e) { throw e; } catch (Exception e) { throw new ObjectStoreConfigException(e); } }
/** * Loads and registers roles listed in resource. * * @throws ObjectStoreConfigException */ public void loadRoles(ClassLoader cl) throws ObjectStoreConfigException { try { ClassLoader first = RoleClassLoader.class.getClassLoader(); Set<URL> loaded; loaded = load(new CheckForAnnotation(first), first, "annotations", ANNOTATIONS, true, new HashSet<URL>()); loaded = load(new CheckForAnnotation(cl), cl, "annotations", ANNOTATIONS, true, loaded); loaded = load(new CheckForConcept(first), first, "concepts", CONCEPTS, true, new HashSet<URL>()); loaded = load(new CheckForConcept(cl), cl, "concepts", CONCEPTS, true, loaded); loaded = load(new CheckForBehaviour(first), first, "behaviours", BEHAVIOURS, false, new HashSet<URL>()); loaded = load(new CheckForBehaviour(cl), cl, "behaviours", BEHAVIOURS, false, loaded); scanConceptsWithReflections(); Collection<Class<?>> concepts = roleMapper.getConceptClasses(); for(Class<?> conceptClass : concepts) { logger.debug("Registered concept class " + conceptClass.getCanonicalName()); } } catch (ObjectStoreConfigException e) { throw e; } catch (Exception e) { throw new ObjectStoreConfigException(e); } }
private Set<URL> load(CheckForConcept checker, ClassLoader cl, String forType, String roles, boolean concept, Set<URL> exclude) throws IOException, ClassNotFoundException, ObjectStoreConfigException { if (cl == null) return exclude; Scanner scanner = new Scanner(checker, roles); Enumeration<URL> resources = cl.getResources(roles); while (resources.hasMoreElements()) { URL url = resources.nextElement(); if (!exclude.contains(url)) { exclude.add(url); logger.debug("Reading roles from {}", url); try { Properties p = new Properties(); p.load(url.openStream()); if (p.isEmpty()) { load(scanner.scan(url, forType, null), cl, concept); } else { load(p, cl, concept); } } catch (IOException e) { String msg = e.getMessage() + " in: " + url; throw new ObjectStoreConfigException(msg, e); } catch (IllegalArgumentException e) { String msg = e.getMessage() + " in: " + url; throw new ObjectStoreConfigException(msg, e); } } } return exclude; }
private void scan(URL url, CheckForConcept checker, String role, ClassLoader cl) throws ObjectStoreConfigException { try { Scanner scanner = new Scanner(checker); load(scanner.scan(url, checker.getName(), role), cl, false); } catch (Exception e) { throw new ObjectStoreConfigException(e); } }
private void scan(URL url, CheckForConcept checker, String role, ClassLoader cl) throws ObjectStoreConfigException { try { Scanner scanner = new Scanner(checker); load(scanner.scan(url, checker.getName(), role), cl, false); } catch (Exception e) { throw new ObjectStoreConfigException(e); } }