Search in sources :

Example 1 with SimpleNamespaceHandlerSet

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;
}
Also used : SimpleNamespaceHandlerSet(org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet) Namespaces(org.apache.aries.blueprint.Namespaces) NamespaceHandler(org.apache.aries.blueprint.NamespaceHandler) IOException(java.io.IOException)

Example 2 with SimpleNamespaceHandlerSet

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);
}
Also used : SimpleNamespaceHandlerSet(org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet) MilliLittersPropertyEditor(org.apache.xbean.blueprint.example.MilliLittersPropertyEditor) HashMap(java.util.HashMap) InputStream(java.io.InputStream) Properties(java.util.Properties) URL(java.net.URL) XBeanNamespaceHandler(org.apache.xbean.blueprint.context.impl.XBeanNamespaceHandler) QNameNamespaceHandler(org.apache.xbean.blueprint.context.impl.QNameNamespaceHandler) PropertyEditor(java.beans.PropertyEditor) MilliLittersPropertyEditor(org.apache.xbean.blueprint.example.MilliLittersPropertyEditor) QNameNamespaceHandler(org.apache.xbean.blueprint.context.impl.QNameNamespaceHandler) NamespaceHandler(org.apache.aries.blueprint.NamespaceHandler) XBeanNamespaceHandler(org.apache.xbean.blueprint.context.impl.XBeanNamespaceHandler) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

NamespaceHandler (org.apache.aries.blueprint.NamespaceHandler)2 SimpleNamespaceHandlerSet (org.apache.aries.blueprint.container.SimpleNamespaceHandlerSet)2 PropertyEditor (java.beans.PropertyEditor)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Properties (java.util.Properties)1 Namespaces (org.apache.aries.blueprint.Namespaces)1 QNameNamespaceHandler (org.apache.xbean.blueprint.context.impl.QNameNamespaceHandler)1 XBeanNamespaceHandler (org.apache.xbean.blueprint.context.impl.XBeanNamespaceHandler)1 MilliLittersPropertyEditor (org.apache.xbean.blueprint.example.MilliLittersPropertyEditor)1