com.arch.cdi.GlobalInformation Maven / Gradle / Ivy
package com.arch.cdi;
import javax.enterprise.context.Dependent;
import javax.enterprise.inject.Instance;
import javax.inject.Inject;
import javax.inject.Named;
import java.io.Serializable;
@Named
@Dependent
public class GlobalInformation implements Serializable {
@Inject
private ApplicationInformation applicationInformation;
@Inject
private Instance sessionInformation;
public void set(String key, Serializable value) {
try {
sessionInformation.get().put(key, value);
} catch (Exception ex) {
applicationInformation.put(getKeyApplication(key), value);
}
}
public T get(String key) {
try {
return (T) sessionInformation.get().get(key);
} catch (Exception ex) {
return (T) applicationInformation.get(getKeyApplication(key));
}
}
public boolean exists(String key) {
try {
return !sessionInformation.isUnsatisfied()
&& sessionInformation.get().get(key) != null;
} catch (Exception ex) {
return applicationInformation.get(getKeyApplication(key)) != null;
}
}
private String getKeyApplication(String key) {
return Thread.currentThread().getName().concat("_").concat(key);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy