use of org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet in project aries by apache.
the class BlueprintContextListener method getNamespaceHandlerSetFromClassNames.
protected NamespaceHandlerSet getNamespaceHandlerSetFromClassNames(ServletContext servletContext, ClassLoader tccl, List<String> handlerClassNames) {
SimpleNamespaceHandlerSet nsSet = new SimpleNamespaceHandlerSet();
for (String name : handlerClassNames) {
String trimmedName = name.trim();
Object instance = null;
try {
instance = tccl.loadClass(trimmedName).newInstance();
} catch (Exception ex) {
throw new RuntimeException("Failed to load NamespaceHandler: " + trimmedName, ex);
}
if (!(instance instanceof NamespaceHandler)) {
throw new RuntimeException("Invalid NamespaceHandler: " + trimmedName);
}
NamespaceHandler nsHandler = (NamespaceHandler) instance;
Namespaces namespaces = nsHandler.getClass().getAnnotation(Namespaces.class);
if (namespaces != null) {
for (String ns : namespaces.value()) {
nsSet.addNamespace(URI.create(ns), nsHandler.getSchemaLocation(ns), nsHandler);
}
}
}
return nsSet;
}
use of org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet in project geronimo-xbean by apache.
the class BlueprintTestSupport method parse.
protected static BlueprintContainerImpl parse(String plan, String schema) throws Exception {
Properties properties = new Properties();
URL propUrl = BlueprintTestSupport.class.getClassLoader().getResource(schema);
InputStream in = propUrl.openStream();
try {
properties.load(in);
} finally {
in.close();
}
Set<Class> classes = new HashSet<Class>();
ClassLoader cl = BlueprintTestSupport.class.getClassLoader();
for (Map.Entry entry : properties.entrySet()) {
String key = (String) entry.getKey();
if (!key.contains(".")) {
String className = (String) entry.getValue();
Class clazz = cl.loadClass(className);
classes.add(clazz);
}
}
classes.add(QName.class);
Map<String, Class<? extends PropertyEditor>> propertyEditors = new HashMap<String, Class<? extends PropertyEditor>>();
propertyEditors.put(MilliLittersPropertyEditor.class.getName(), MilliLittersPropertyEditor.class);
final NamespaceHandler xbeanHandler = new XBeanNamespaceHandler(NAMESPACE_URI.toString(), BlueprintTestSupport.class.getClassLoader().getResource("restaurant.xsd"), classes, propertyEditors, properties);
final NamespaceHandler qnameHandler = new QNameNamespaceHandler();
SimpleNamespaceHandlerSet handlers = new SimpleNamespaceHandlerSet();
handlers.addNamespace(NAMESPACE_URI, xbeanHandler.getSchemaLocation(NAMESPACE_URI.toString()), xbeanHandler);
handlers.addNamespace(QNAME_URI, xbeanHandler.getSchemaLocation(NAMESPACE_URI.toString()), qnameHandler);
return parse(plan, handlers);
}
Aggregations