use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.
the class FaceletTaglibConfigProcessor method processHandlerClass.
private void processHandlerClass(ServletContext sc, FacesContext facesContext, Node handlerClass, TagLibraryImpl taglibrary, String name) {
String className = getNodeText(handlerClass);
if (className == null) {
throw new ConfigurationException("The tag named " + name + " from namespace " + taglibrary.getNamespace() + " has a null handler-class defined");
}
try {
Class<?> clazz;
try {
clazz = loadClass(sc, facesContext, className, this, null);
taglibrary.putTagHandler(name, clazz);
} catch (NoClassDefFoundError defNotFound) {
String message = defNotFound.toString();
if (message.contains("com/sun/facelets/") || message.contains("com.sun.facelets.")) {
if (LOGGER.isLoggable(WARNING)) {
LOGGER.log(WARNING, "faces.config.legacy.facelet.warning", new Object[] { handlerClass });
}
} else {
throw defNotFound;
}
}
} catch (ClassNotFoundException cnfe) {
throw new ConfigurationException(cnfe);
}
}
use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.
the class FaceletTaglibConfigProcessor method processFunctions.
private void processFunctions(ServletContext sc, FacesContext facesContext, NodeList functions, TagLibraryImpl taglibrary) {
if (functions != null && functions.getLength() > 0) {
for (int i = 0, ilen = functions.getLength(); i < ilen; i++) {
NodeList children = functions.item(i).getChildNodes();
String functionName = null;
String functionClass = null;
String functionSignature = null;
for (int j = 0, jlen = children.getLength(); j < jlen; j++) {
Node n = children.item(j);
if (n.getLocalName() != null) {
switch(n.getLocalName()) {
case FUNCTION_NAME:
functionName = getNodeText(n);
break;
case FUNCTION_CLASS:
functionClass = getNodeText(n);
break;
case FUNCTION_SIGNATURE:
functionSignature = getNodeText(n);
break;
}
}
}
try {
Class<?> clazz = loadClass(sc, facesContext, functionClass, this, null);
Method m = createMethod(clazz, functionSignature);
taglibrary.putFunction(functionName, m);
} catch (Exception e) {
throw new ConfigurationException(e);
}
}
}
}
use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.
the class RenderKitConfigProcessor method process.
// -------------------------------------------- Methods from ConfigProcessor
@Override
public void process(ServletContext servletContext, FacesContext facesContext, DocumentInfo[] documentInfos) throws Exception {
Map<String, Map<Document, List<Node>>> renderers = new LinkedHashMap<>();
Map<String, Map<Document, List<Node>>> behaviorRenderers = new LinkedHashMap<>();
RenderKitFactory renderKitFactory = (RenderKitFactory) FactoryFinder.getFactory(FactoryFinder.RENDER_KIT_FACTORY);
for (int i = 0; i < documentInfos.length; i++) {
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, format("Processing render-kit elements for document: ''{0}''", documentInfos[i].getSourceURI()));
}
Document document = documentInfos[i].getDocument();
String namespace = document.getDocumentElement().getNamespaceURI();
NodeList renderkits = document.getDocumentElement().getElementsByTagNameNS(namespace, RENDERKIT);
if (renderkits != null && renderkits.getLength() > 0) {
addRenderKits(servletContext, facesContext, renderkits, document, renderers, behaviorRenderers, renderKitFactory);
}
}
// Process annotated Renderers, ClientBehaviorRenderers first as Renderers configured
// via config files take precedence
processAnnotations(facesContext, FacesRenderer.class);
processAnnotations(facesContext, FacesBehaviorRenderer.class);
// Now add the accumulated renderers to the RenderKits
for (Map.Entry<String, Map<Document, List<Node>>> entry : renderers.entrySet()) {
RenderKit renderKit = renderKitFactory.getRenderKit(null, entry.getKey());
if (renderKit == null) {
throw new ConfigurationException(getExceptionMessageString(RENDERER_CANNOT_BE_REGISTERED_ID, entry.getKey()));
}
for (Map.Entry<Document, List<Node>> renderEntry : entry.getValue().entrySet()) {
addRenderers(servletContext, facesContext, renderKit, renderEntry.getKey(), renderEntry.getValue());
}
}
// Now add the accumulated behavior renderers to the RenderKits
for (Map.Entry<String, Map<Document, List<Node>>> entry : behaviorRenderers.entrySet()) {
RenderKit renderKit = renderKitFactory.getRenderKit(null, entry.getKey());
if (renderKit == null) {
throw new ConfigurationException(getExceptionMessageString(RENDERER_CANNOT_BE_REGISTERED_ID, entry.getKey()));
}
for (Map.Entry<Document, List<Node>> renderEntry : entry.getValue().entrySet()) {
addClientBehaviorRenderers(servletContext, facesContext, renderKit, renderEntry.getKey(), renderEntry.getValue());
}
}
}
use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.
the class AbstractConfigProcessor method createInstance.
protected Object createInstance(ServletContext sc, FacesContext facesContext, String className, Class<?> rootType, Object root, Node source, boolean performInjection, boolean[] didPerformInjection) {
Class<?> clazz;
Object returnObject = null;
if (className != null) {
try {
clazz = loadClass(sc, facesContext, className, returnObject, null);
if (clazz != null) {
if (returnObject == null) {
// an object to adapt
if (rootType != null && root != null) {
Constructor<?> construct = lookupConstructor(clazz, rootType);
if (construct != null) {
returnObject = construct.newInstance(root);
}
}
}
if (clazz != null && returnObject == null) {
returnObject = clazz.newInstance();
}
ApplicationInstanceFactoryMetadataMap<String, Object> classMetadataMap = getClassMetadataMap(sc);
if (classMetadataMap.hasAnnotations(className) && performInjection) {
InjectionProvider injectionProvider = (InjectionProvider) facesContext.getAttributes().get(INJECTION_PROVIDER_KEY);
try {
injectionProvider.inject(returnObject);
} catch (InjectionProviderException ex) {
LOGGER.log(SEVERE, "Unable to inject instance" + className, ex);
throw new FacesException(ex);
}
try {
injectionProvider.invokePostConstruct(returnObject);
} catch (InjectionProviderException ex) {
LOGGER.log(SEVERE, "Unable to invoke @PostConstruct annotated method on instance " + className, ex);
throw new FacesException(ex);
}
didPerformInjection[0] = true;
}
}
} catch (ClassNotFoundException cnfe) {
throw new ConfigurationException(buildMessage(format("Unable to find class ''{0}''", className), source), cnfe);
} catch (NoClassDefFoundError ncdfe) {
throw new ConfigurationException(buildMessage(format("Class ''{0}'' is missing a runtime dependency: {1}", className, ncdfe.toString()), source), ncdfe);
} catch (ClassCastException cce) {
throw new ConfigurationException(buildMessage(format("Class ''{0}'' is not an instance of ''{1}''", className, rootType), source), cce);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | FacesException e) {
throw new ConfigurationException(buildMessage(format("Unable to create a new instance of ''{0}'': {1}", className, e.toString()), source), e);
}
}
return returnObject;
}
use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.
the class FaceletTaglibConfigProcessor method processValidator.
private void processValidator(ServletContext sc, FacesContext facesContext, NodeList validator, TagLibraryImpl taglibrary, String name) {
if (validator != null && validator.getLength() > 0) {
String validatorId = null;
String handlerClass = null;
for (int i = 0, ilen = validator.getLength(); i < ilen; i++) {
Node n = validator.item(i);
if (n.getLocalName() != null) {
switch(n.getLocalName()) {
case VALIDATOR_ID:
validatorId = getNodeText(n);
break;
case HANDLER_CLASS:
handlerClass = getNodeText(n);
break;
}
}
}
if (handlerClass != null) {
try {
Class<?> clazz = loadClass(sc, facesContext, handlerClass, this, null);
taglibrary.putValidator(name, validatorId, clazz);
} catch (NoClassDefFoundError defNotFound) {
String message = defNotFound.toString();
if (message.contains("com/sun/facelets/") || message.contains("com.sun.facelets.")) {
if (LOGGER.isLoggable(Level.WARNING)) {
LOGGER.log(Level.WARNING, "faces.config.legacy.facelet.warning", new Object[] { handlerClass });
}
} else {
throw defNotFound;
}
} catch (ClassNotFoundException e) {
throw new ConfigurationException(e);
}
} else {
taglibrary.putValidator(name, validatorId);
}
}
}
Aggregations