Search in sources :

Example 1 with UpdatableLibrary

use of com.ibm.xsp.registry.UpdatableLibrary in project org.openntf.nsfodp by OpenNTF.

the class ODPCompiler method compileCustomControls.

// *******************************************************************************
// * XSP compilation methods
// *******************************************************************************
private Map<CustomControl, XSPCompilationResult> compileCustomControls(JavaSourceClassLoader classLoader) throws Exception {
    subTask(Messages.ODPCompiler_compilingCustomControls);
    ConfigParser configParser = ConfigParserFactory.getParserInstance();
    FacesClassLoader facesClassLoader = new DynamicFacesClassLoader(dynamicXPageBean, classLoader);
    Map<CustomControl, XSPCompilationResult> result = new LinkedHashMap<>();
    List<CustomControl> ccs = odp.getCustomControls();
    for (CustomControl cc : ccs) {
        Document xspConfig = cc.getXspConfig().get();
        // $NON-NLS-1$
        String namespace = StringUtil.trim(NSFODPDomUtil.node(xspConfig, "/faces-config/faces-config-extension/namespace-uri/text()").get().getTextContent());
        Path fileName = odp.getBaseDirectory().relativize(cc.getXspConfigFile());
        LibraryFragmentImpl fragment = (LibraryFragmentImpl) configParser.createFacesLibraryFragment(facesProject, facesClassLoader, fileName.toString(), xspConfig.getDocumentElement(), resourceBundleSource, iconUrlSource, namespace);
        UpdatableLibrary library = getLibrary(namespace);
        library.addLibraryFragment(fragment);
        // Load the definition to refresh its parent ref
        CompositeComponentDefinitionImpl def = (CompositeComponentDefinitionImpl) library.getDefinition(cc.getControlName());
        def.refreshReferences();
    }
    // Now that they're all defined, try to compile them in a queue
    for (CustomControl cc : ccs) {
        XSPCompilationResult compilationResult = compileXSP(cc, classLoader);
        result.put(cc, compilationResult);
    }
    return result;
}
Also used : Path(java.nio.file.Path) CompositeComponentDefinitionImpl(com.ibm.xsp.registry.CompositeComponentDefinitionImpl) DynamicFacesClassLoader(com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader) ConfigParser(com.ibm.xsp.registry.parse.ConfigParser) DynamicFacesClassLoader(com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader) FacesClassLoader(com.ibm.xsp.library.FacesClassLoader) UpdatableLibrary(com.ibm.xsp.registry.UpdatableLibrary) Document(org.w3c.dom.Document) LinkedHashMap(java.util.LinkedHashMap) CustomControl(org.openntf.nsfodp.commons.odp.CustomControl) LibraryFragmentImpl(com.ibm.xsp.registry.LibraryFragmentImpl) XSPCompilationResult(org.openntf.nsfodp.commons.odp.XSPCompilationResult)

Example 2 with UpdatableLibrary

use of com.ibm.xsp.registry.UpdatableLibrary in project org.openntf.nsfodp by OpenNTF.

the class AbstractCompilationEnvironment method getLibrary.

protected UpdatableLibrary getLibrary(String namespace) {
    SharableRegistryImpl facesRegistry = (SharableRegistryImpl) facesProject.getRegistry();
    UpdatableLibrary library = (UpdatableLibrary) facesRegistry.getLocalLibrary(namespace);
    if (library == null) {
        try {
            library = new FacesLibraryImpl(facesRegistry, namespace);
            // TODO this is probably properly done by creating a FacesProjectImpl
            // - it can then register the library fragments itself
            // Note: my first attempt at this ended with an infinite loop, so it's trickier than that
            // $NON-NLS-1$
            Field localLibsField = facesRegistry.getClass().getDeclaredField("_localLibs");
            localLibsField.setAccessible(true);
            @SuppressWarnings("unchecked") Map<String, UpdatableLibrary> localLibs = (Map<String, UpdatableLibrary>) localLibsField.get(facesRegistry);
            localLibs.put(namespace, library);
        } catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
            throw new RuntimeException(e);
        }
    }
    return library;
}
Also used : UpdatableLibrary(com.ibm.xsp.registry.UpdatableLibrary) SharableRegistryImpl(com.ibm.xsp.registry.SharableRegistryImpl) Field(java.lang.reflect.Field) FacesLibraryImpl(com.ibm.xsp.registry.FacesLibraryImpl) Map(java.util.Map)

Aggregations

UpdatableLibrary (com.ibm.xsp.registry.UpdatableLibrary)2 DynamicFacesClassLoader (com.ibm.xsp.extlib.interpreter.DynamicFacesClassLoader)1 FacesClassLoader (com.ibm.xsp.library.FacesClassLoader)1 CompositeComponentDefinitionImpl (com.ibm.xsp.registry.CompositeComponentDefinitionImpl)1 FacesLibraryImpl (com.ibm.xsp.registry.FacesLibraryImpl)1 LibraryFragmentImpl (com.ibm.xsp.registry.LibraryFragmentImpl)1 SharableRegistryImpl (com.ibm.xsp.registry.SharableRegistryImpl)1 ConfigParser (com.ibm.xsp.registry.parse.ConfigParser)1 Field (java.lang.reflect.Field)1 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CustomControl (org.openntf.nsfodp.commons.odp.CustomControl)1 XSPCompilationResult (org.openntf.nsfodp.commons.odp.XSPCompilationResult)1 Document (org.w3c.dom.Document)1