use of com.sun.faces.application.ApplicationAssociate in project mojarra by eclipse-ee4j.
the class CdiUtils method createConverter.
/**
* Create a converter using the FacesConverter forClass attribute.
*
* @param beanManager the bean manager.
* @param forClass the for class.
* @return the converter, or null if we could not match one.
*/
public static Converter<?> createConverter(BeanManager beanManager, Class<?> forClass) {
Converter<?> managedConverter = null;
for (Class<?> forClassOrSuperclass = forClass; managedConverter == null && forClassOrSuperclass != null && forClassOrSuperclass != Object.class; forClassOrSuperclass = forClassOrSuperclass.getSuperclass()) {
managedConverter = createConverter(beanManager, FacesConverter.Literal.of("", forClassOrSuperclass, true));
}
if (managedConverter != null) {
ApplicationAssociate associate = ApplicationAssociate.getCurrentInstance();
// #4913
associate.getAnnotationManager().applyConverterAnnotations(FacesContext.getCurrentInstance(), managedConverter);
return new CdiConverter("", forClass, managedConverter);
}
return null;
}
use of com.sun.faces.application.ApplicationAssociate in project faces by jakartaee.
the class UserBean method init.
@PostConstruct
private void init() {
ApplicationAssociate appAss = ApplicationAssociate.getInstance(extContext);
firstName = "" + appAss.getFaceletFactory().getRefreshPeriod();
}
use of com.sun.faces.application.ApplicationAssociate in project faces by jakartaee.
the class UserBean method init.
@PostConstruct
private void init() {
ApplicationAssociate appAss = ApplicationAssociate.getInstance(extContext);
firstName = "" + appAss.getFaceletFactory().getRefreshPeriod();
}
use of com.sun.faces.application.ApplicationAssociate in project mojarra by eclipse-ee4j.
the class ConfigureListener method reload.
/**
* This method will be invoked {@link WebConfigResourceMonitor} when changes to any of the faces-config.xml files
* included in WEB-INF are modified.
*/
private void reload(ServletContext servletContext) {
LOGGER.log(INFO, () -> format("Reloading Faces configuration for context {0}", servletContext.getContextPath()));
// tear down the application
try {
// this will only be true in the automated test usage scenario
if (webAppListener != null) {
List<HttpSession> sessions = webAppListener.getActiveSessions();
if (sessions != null) {
for (HttpSession session : sessions) {
if (LOGGER.isLoggable(INFO)) {
LOGGER.log(INFO, "Invalidating Session {0}", session.getId());
}
session.invalidate();
}
}
}
// Release any allocated application resources
FactoryFinder.releaseFactories();
} catch (Exception e) {
e.printStackTrace();
} finally {
FacesContext initContext = new InitFacesContext(servletContext);
ApplicationAssociate.clearInstance(initContext.getExternalContext());
ApplicationAssociate.setCurrentInstance(null);
// Release the initialization mark on this web application
ConfigManager configManager = ConfigManager.getInstance(servletContext);
if (configManager != null) {
configManager.destroy(servletContext, initContext);
ConfigManager.removeInstance(servletContext);
} else {
LOGGER.log(SEVERE, "Unexpected state during reload: no ConfigManager instance in current ServletContext but one is expected to exist.");
}
initContext.release();
ReflectionUtils.clearCache(Thread.currentThread().getContextClassLoader());
WebConfiguration.clear(servletContext);
}
// Bring the application back up.
// No verification will be performed either to make this light weight.
// init a new WebAppLifecycleListener so that the cached ApplicationAssociate
// is removed.
webAppListener = new WebappLifecycleListener(servletContext);
InitFacesContext initContext = new InitFacesContext(servletContext);
ReflectionUtils.initCache(Thread.currentThread().getContextClassLoader());
try {
ConfigManager configManager = ConfigManager.createInstance(servletContext);
if (configManager != null) {
configManager.initialize(servletContext, initContext);
} else {
LOGGER.log(SEVERE, "Unexpected state during reload: no ConfigManager instance in current ServletContext but one is expected to exist.");
}
ApplicationAssociate associate = ApplicationAssociate.getInstance(servletContext);
if (associate != null) {
Boolean errorPagePresent = (Boolean) servletContext.getAttribute(ERROR_PAGE_PRESENT_KEY_NAME);
if (errorPagePresent != null) {
associate.setErrorPagePresent(errorPagePresent);
associate.setContextName(servletContext.getContextPath());
}
}
} catch (Exception e) {
e.printStackTrace();
} finally {
initContext.release();
}
LOGGER.log(INFO, () -> format("Reload complete. ({0})", servletContext.getContextPath()));
}
use of com.sun.faces.application.ApplicationAssociate in project mojarra by eclipse-ee4j.
the class WebConfiguration method discoverResourceLibraryContracts.
private void discoverResourceLibraryContracts() {
FacesContext context = FacesContext.getCurrentInstance();
ExternalContext extContex = context.getExternalContext();
Set<String> foundContracts = new HashSet<>();
Set<String> candidates;
// Scan for "contractMappings" in the web app root
String contractsDirName = getOptionValue(WebContextInitParameter.WebAppContractsDirectory);
assert null != contractsDirName;
candidates = extContex.getResourcePaths(contractsDirName);
if (null != candidates) {
int contractsDirNameLen = contractsDirName.length();
int end;
for (String cur : candidates) {
end = cur.length();
if (cur.endsWith("/")) {
end--;
}
foundContracts.add(cur.substring(contractsDirNameLen + 1, end));
}
}
// Scan for "META-INF" contractMappings in the classpath
try {
URL[] candidateURLs = Classpath.search(Util.getCurrentLoader(this), META_INF_CONTRACTS_DIR, RESOURCE_CONTRACT_SUFFIX, Classpath.SearchAdvice.AllMatches);
for (URL curURL : candidateURLs) {
String cur = curURL.toExternalForm();
int i = cur.indexOf(META_INF_CONTRACTS_DIR) + META_INF_CONTRACTS_DIR_LEN + 1;
int j = cur.indexOf(RESOURCE_CONTRACT_SUFFIX);
if (i < j) {
foundContracts.add(cur.substring(i, j));
}
}
} catch (IOException ioe) {
if (LOGGER.isLoggable(Level.FINEST)) {
LOGGER.log(Level.FINEST, "Unable to scan " + META_INF_CONTRACTS_DIR, ioe);
}
}
if (foundContracts.isEmpty()) {
return;
}
Map<String, List<String>> contractMappings = new HashMap<>();
ApplicationAssociate associate = ApplicationAssociate.getCurrentInstance();
Map<String, List<String>> contractsFromConfig = associate.getResourceLibraryContracts();
List<String> contractsToExpose;
if (null != contractsFromConfig && !contractsFromConfig.isEmpty()) {
List<String> contractsFromMapping;
for (Map.Entry<String, List<String>> cur : contractsFromConfig.entrySet()) {
// Verify that the contractsToExpose in this mapping actually exist
// in the application. If not, log a message.
contractsFromMapping = cur.getValue();
if (null == contractsFromMapping || contractsFromMapping.isEmpty()) {
if (LOGGER.isLoggable(Level.CONFIG)) {
LOGGER.log(Level.CONFIG, "resource library contract mapping for pattern {0} has no contracts.", cur.getKey());
}
} else {
contractsToExpose = new ArrayList<>();
for (String curContractFromMapping : contractsFromMapping) {
if (foundContracts.contains(curContractFromMapping)) {
contractsToExpose.add(curContractFromMapping);
} else {
if (LOGGER.isLoggable(Level.CONFIG)) {
LOGGER.log(Level.CONFIG, "resource library contract mapping for pattern {0} exposes contract {1}, but that contract is not available to the application.", new String[] { cur.getKey(), curContractFromMapping });
}
}
}
if (!contractsToExpose.isEmpty()) {
contractMappings.put(cur.getKey(), contractsToExpose);
}
}
}
} else {
contractsToExpose = new ArrayList<>();
contractsToExpose.addAll(foundContracts);
contractMappings.put("*", contractsToExpose);
}
extContex.getApplicationMap().put(FaceletViewHandlingStrategy.RESOURCE_LIBRARY_CONTRACT_DATA_STRUCTURE_KEY, contractMappings);
}
Aggregations