use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.
the class ParseConfigResourceToDOMTask method call.
// ----------------------------------------------- Methods from Callable
/**
* @return the result of the parse operation (a DOM)
* @throws Exception if an error occurs during the parsing process
*/
@Override
public DocumentInfo call() throws Exception {
try {
Timer timer = Timer.getInstance();
if (timer != null) {
timer.startTiming();
}
Document document = getDocument();
if (timer != null) {
timer.stopTiming();
timer.logResult("Parse " + documentURI.toURL().toExternalForm());
}
return new DocumentInfo(document, documentURI);
} catch (Exception e) {
throw new ConfigurationException(format("Unable to parse document ''{0}'': {1}", documentURI.toURL().toExternalForm(), e.getMessage()), e);
}
}
use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.
the class ApplicationConfigProcessor method addSystemEventListener.
private void addSystemEventListener(ServletContext servletContext, FacesContext facesContext, Application application, Node systemEventListener) {
NodeList children = systemEventListener.getChildNodes();
String listenerClass = null;
String eventClass = null;
String sourceClass = null;
for (int j = 0, len = children.getLength(); j < len; j++) {
Node n = children.item(j);
if (n.getNodeType() == Node.ELEMENT_NODE) {
switch(n.getLocalName()) {
case SYSTEM_EVENT_LISTENER_CLASS:
listenerClass = getNodeText(n);
break;
case SYSTEM_EVENT_CLASS:
eventClass = getNodeText(n);
break;
case SOURCE_CLASS:
sourceClass = getNodeText(n);
break;
}
}
}
if (listenerClass != null) {
SystemEventListener systemEventListenerInstance = (SystemEventListener) createInstance(servletContext, facesContext, listenerClass, SystemEventListener.class, null, systemEventListener);
if (systemEventListenerInstance != null) {
systemEventListeners.add(systemEventListenerInstance);
try {
// If there is an eventClass, use it, otherwise use
// SystemEvent.class
// noinspection unchecked
Class<? extends SystemEvent> eventClazz;
if (eventClass != null) {
eventClazz = (Class<? extends SystemEvent>) loadClass(servletContext, facesContext, eventClass, this, null);
} else {
eventClazz = SystemEvent.class;
}
// If there is a sourceClass, use it, otherwise use null
Class<?> sourceClazz = sourceClass != null && sourceClass.length() != 0 ? Util.loadClass(sourceClass, this.getClass()) : null;
application.subscribeToEvent(eventClazz, sourceClazz, systemEventListenerInstance);
if (LOGGER.isLoggable(Level.FINE)) {
LOGGER.log(Level.FINE, "Subscribing for event {0} and source {1} using listener {2}", new Object[] { eventClazz.getName(), sourceClazz != null ? sourceClazz.getName() : "ANY", systemEventListenerInstance.getClass().getName() });
}
} catch (ClassNotFoundException cnfe) {
throw new ConfigurationException(cnfe);
}
}
}
}
use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.
the class ConverterConfigProcessor method addConverters.
// --------------------------------------------------------- Private Methods
private void addConverters(NodeList converters, String namespace) {
Application application = getApplication();
Verifier verifier = Verifier.getCurrentInstance();
for (int i = 0, size = converters.getLength(); i < size; i++) {
Node converter = converters.item(i);
NodeList children = ((Element) converter).getElementsByTagNameNS(namespace, "*");
String converterId = null;
String converterClass = null;
String converterForClass = null;
for (int c = 0, csize = children.getLength(); c < csize; c++) {
Node n = children.item(c);
switch(n.getLocalName()) {
case CONVERTER_ID:
converterId = getNodeText(n);
break;
case CONVERTER_CLASS:
converterClass = getNodeText(n);
break;
case CONVERTER_FOR_CLASS:
converterForClass = getNodeText(n);
break;
}
}
if (converterId != null && converterClass != null) {
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, format("[Converter by ID] Calling Application.addConverter({0}, {1}", converterId, converterClass));
}
if (verifier != null) {
verifier.validateObject(Verifier.ObjectType.CONVERTER, converterClass, Converter.class);
}
application.addConverter(converterId, converterClass);
} else if (converterClass != null && converterForClass != null) {
try {
Class<?> cfcClass = Util.loadClass(converterForClass, this.getClass());
if (LOGGER.isLoggable(FINE)) {
LOGGER.log(FINE, format("[Converter for Class] Calling Application.addConverter({0}, {1}", converterForClass, converterClass));
}
if (verifier != null) {
verifier.validateObject(Verifier.ObjectType.CONVERTER, converterClass, Converter.class);
}
application.addConverter(cfcClass, converterClass);
} catch (ClassNotFoundException cnfe) {
throw new ConfigurationException(cnfe);
}
}
}
}
use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.
the class Documents method getXMLDocuments.
/**
* <p>
* Obtains an array of <code>Document</code>s to be processed
* </p>
*
* @param servletContext the <code>ServletContext</code> for the application to be processed
* @param providers <code>List</code> of <code>ConfigurationResourceProvider</code> instances that provide the URL of
* the documents to parse.
* @param executor the <code>ExecutorService</code> used to dispatch parse request to
* @param validating flag indicating whether or not the documents should be validated
* @return an array of <code>DocumentInfo</code>s
*/
public static DocumentInfo[] getXMLDocuments(ServletContext servletContext, List<ConfigurationResourceProvider> providers, ExecutorService executor, boolean validating) {
// Query all configuration providers to give us a URL to the configuration they are providing
List<FutureTask<Collection<URI>>> uriTasks = new ArrayList<>(providers.size());
for (ConfigurationResourceProvider provider : providers) {
FutureTask<Collection<URI>> uriTask = new FutureTask<>(new FindConfigResourceURIsTask(provider, servletContext));
uriTasks.add(uriTask);
if (executor != null) {
executor.execute(uriTask);
} else {
uriTask.run();
}
}
// Load and XML parse all documents to which the URLs that we collected above point to
List<FutureTask<DocumentInfo>> docTasks = new ArrayList<>(providers.size() << 1);
for (FutureTask<Collection<URI>> uriTask : uriTasks) {
try {
for (URI uri : uriTask.get()) {
FutureTask<DocumentInfo> docTask = new FutureTask<>(new ParseConfigResourceToDOMTask(servletContext, validating, uri));
docTasks.add(docTask);
if (executor != null) {
executor.execute(docTask);
} else {
docTask.run();
}
}
} catch (InterruptedException ignored) {
} catch (Exception e) {
throw new ConfigurationException(e);
}
}
// Collect the results of the documents we parsed above
List<DocumentInfo> docs = new ArrayList<>(docTasks.size());
for (FutureTask<DocumentInfo> docTask : docTasks) {
try {
docs.add(docTask.get());
} catch (ExecutionException e) {
throw new ConfigurationException(e);
} catch (InterruptedException ignored) {
}
}
return docs.toArray(new DocumentInfo[docs.size()]);
}
use of com.sun.faces.config.ConfigurationException in project mojarra by eclipse-ee4j.
the class ValidatorConfigProcessor method processDefaultValidatorIds.
// --------------------------------------------------------- Private Methods
private void processDefaultValidatorIds() {
Application app = getApplication();
Map<String, String> defaultValidatorInfo = app.getDefaultValidatorInfo();
for (Map.Entry<String, String> info : defaultValidatorInfo.entrySet()) {
String defaultValidatorId = info.getKey();
boolean found = false;
for (Iterator<String> registered = app.getValidatorIds(); registered.hasNext(); ) {
if (defaultValidatorId.equals(registered.next())) {
found = true;
break;
}
}
if (!found) {
throw new ConfigurationException(format("Default validator ''{0}'' does not reference a registered validator.", defaultValidatorId));
}
}
}
Aggregations