use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class WebConfigListener method changed.
/**
* Handles HttpService change events
* @param events the PropertyChangeEvent
*/
@Override
public synchronized UnprocessedChangeEvents changed(PropertyChangeEvent[] events) {
return ConfigSupport.sortAndDispatch(events, new Changed() {
@Override
public <T extends ConfigBeanProxy> NotProcessed changed(TYPE type, Class<T> tClass, T t) {
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.FINE, LogFacade.CHANGE_INVOKED, new Object[] { type, tClass, t });
}
try {
if (tClass == HttpService.class) {
container.updateHttpService((HttpService) t);
} else if (tClass == NetworkListener.class) {
if (type == TYPE.ADD) {
container.addConnector((NetworkListener) t, httpService, true);
} else if (type == TYPE.REMOVE) {
container.deleteConnector((NetworkListener) t);
} else if (type == TYPE.CHANGE) {
container.updateConnector((NetworkListener) t, httpService);
}
} else if (tClass == VirtualServer.class) {
if (type == TYPE.ADD) {
container.createHost((VirtualServer) t, httpService, null);
container.loadDefaultWebModule((VirtualServer) t);
} else if (type == TYPE.REMOVE) {
container.deleteHost(httpService);
} else if (type == TYPE.CHANGE) {
container.updateHost((VirtualServer) t);
}
} else if (tClass == AccessLog.class) {
container.updateAccessLog(httpService);
} else if (tClass == ManagerProperties.class) {
return new NotProcessed("ManagerProperties requires restart");
} else if (tClass == WebContainerAvailability.class || tClass == AvailabilityService.class) {
// container.updateHttpService handles SingleSignOn valve configuration
container.updateHttpService(httpService);
} else if (tClass == NetworkListeners.class) {
// skip updates
} else if (tClass == Property.class) {
ConfigBeanProxy config = ((Property) t).getParent();
if (config instanceof HttpService) {
container.updateHttpService((HttpService) config);
} else if (config instanceof VirtualServer) {
container.updateHost((VirtualServer) config);
} else if (config instanceof NetworkListener) {
container.updateConnector((NetworkListener) config, httpService);
} else {
container.updateHttpService(httpService);
}
} else if (tClass == SystemProperty.class) {
if (((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (listener.getPort().equals(((SystemProperty) t).getValue())) {
container.updateConnector(listener, httpService);
}
}
}
} else if (tClass == JavaConfig.class) {
JavaConfig jc = (JavaConfig) t;
final List<String> jvmOptions = new ArrayList<String>(jc.getJvmOptions());
for (String jvmOption : jvmOptions) {
if (jvmOption.startsWith("-DjvmRoute=")) {
container.updateJvmRoute(httpService, jvmOption);
}
}
} else {
// Ignore other unrelated events
}
} catch (LifecycleException le) {
logger.log(Level.SEVERE, LogFacade.EXCEPTION_WEB_CONFIG, le);
}
return null;
}
}, logger);
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class DeleteSsl method execute.
/**
* Executes the command with the command parameters passed as Properties
* where the keys are the parameter names and the values the parameter values
*
* @param context information
*/
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
Target targetUtil = habitat.getService(Target.class);
Config newConfig = targetUtil.getConfig(target);
if (newConfig != null) {
config = newConfig;
}
if ((!type.equals("iiop-service")) && (listenerId == null)) {
report.setMessage(LOCAL_STRINGS.getLocalString("create.ssl.listenerid.missing", "Listener id needs to be specified"));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
try {
SslConfigHandler sslConfigHandler = habitat.getService(SslConfigHandler.class, type);
if (sslConfigHandler != null) {
sslConfigHandler.delete(this, report);
} else if ("jmx-connector".equals(type)) {
JmxConnector jmxConnector = null;
for (JmxConnector listener : config.getAdminService().getJmxConnector()) {
if (listener.getName().equals(listenerId)) {
jmxConnector = listener;
}
}
if (jmxConnector == null) {
report.setMessage(LOCAL_STRINGS.getLocalString("delete.ssl.jmx.connector.notfound", "Iiop Listener named {0} not found", listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
if (jmxConnector.getSsl() == null) {
report.setMessage(LOCAL_STRINGS.getLocalString("delete.ssl.element.doesnotexist", "Ssl element does " + "not exist for Listener named {0}", listenerId));
report.setActionExitCode(ActionReport.ExitCode.FAILURE);
return;
}
ConfigSupport.apply(new SingleConfigCode<JmxConnector>() {
@Override
public Object run(JmxConnector param) throws PropertyVetoException {
param.setSsl(null);
return null;
}
}, jmxConnector);
report.setActionExitCode(ActionReport.ExitCode.SUCCESS);
}
} catch (TransactionFailure e) {
reportError(report, e);
}
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class CompositeUtil method analyzeInterface.
private void analyzeInterface(Class<?> iface, Map<String, Map<String, Object>> properties) throws SecurityException {
// find class level bean reference
String defaultBean = null;
if (iface.isAnnotationPresent(DefaultBeanReference.class)) {
DefaultBeanReference beanRef = iface.getAnnotation(DefaultBeanReference.class);
defaultBean = beanRef.bean();
}
for (Method method : iface.getMethods()) {
String name = method.getName();
final boolean isGetter = name.startsWith("get");
if (isGetter || name.startsWith("set")) {
name = name.substring(3);
Map<String, Object> property = properties.get(name);
if (property == null) {
property = new HashMap<String, Object>();
properties.put(name, property);
}
String bean = null;
String attribute = null;
AttributeReference ar = method.getAnnotation(AttributeReference.class);
if (ar != null) {
bean = ar.bean();
attribute = ar.attribute();
}
if (!StringUtil.notEmpty(bean)) {
bean = defaultBean;
}
if (!StringUtil.notEmpty(attribute)) {
attribute = name;
}
if (StringUtil.notEmpty(bean) && StringUtil.notEmpty(attribute)) {
property.put("annotations", gatherReferencedAttributes(bean, attribute));
}
Attribute attr = method.getAnnotation(Attribute.class);
if (attr != null) {
property.put("defaultValue", attr.defaultValue());
}
Class<?> type = isGetter ? method.getReturnType() : method.getParameterTypes()[0];
property.put("type", type);
}
}
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class ClientGenerator method processAttributes.
protected void processAttributes(ClientClassWriter writer, ConfigModel model, Set<String> processed) {
Class clazz = model.getProxyType();
for (Method method : clazz.getMethods()) {
String methodName = method.getName();
Attribute a = method.getAnnotation(Attribute.class);
Param p = method.getAnnotation(Param.class);
if ((a != null) || (p != null)) {
String type = "String";
if (a != null) {
type = a.dataType().getName();
}
if (methodName.startsWith("get") || methodName.startsWith("set")) {
methodName = methodName.substring(3);
}
String fieldName = Util.lowerCaseFirstLetter(methodName);
if (processed.contains(fieldName)) {
continue;
}
processed.add(fieldName);
writer.generateGettersAndSetters(type, methodName, fieldName);
}
}
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class ConfigModularityUtils method setConfigBean.
public <T extends ConfigBeanProxy> T setConfigBean(T finalConfigBean, ConfigBeanDefaultValue configBeanDefaultValue, ConfigBeanProxy parent) {
Class owningClassForLocation = getOwningClassForLocation(configBeanDefaultValue.getLocation());
Class configBeanClass = getClassForFullName(configBeanDefaultValue.getConfigBeanClassName());
try {
ConfigBeanProxy configBeanInstance = null;
if (getNameForConfigBean(finalConfigBean, configBeanClass) == null) {
List<ConfigBeanProxy> extensions = getExtensions(parent);
for (ConfigBeanProxy extension : extensions) {
try {
configBeanInstance = (ConfigBeanProxy) configBeanClass.cast(extension);
break;
} catch (Exception e) {
// ignore, not the right type.
}
}
if (!configBeanDefaultValue.replaceCurrentIfExists() || !stackPositionHigher(finalConfigBean, configBeanInstance)) {
if (configBeanInstance != null)
return (T) configBeanInstance;
}
if (configBeanInstance != null) {
extensions.remove(configBeanInstance);
}
}
} catch (InvocationTargetException e) {
LOG.log(Level.INFO, cannotSetConfigBean, e);
} catch (IllegalAccessException e) {
LOG.log(Level.INFO, cannotSetConfigBean, e);
}
Method m = getMatchingSetterMethod(owningClassForLocation, configBeanClass);
if (m != null) {
try {
if (configBeanClass.getAnnotation(HasCustomizationTokens.class) != null) {
applyCustomTokens(configBeanDefaultValue, finalConfigBean, parent);
}
m.invoke(parent, finalConfigBean);
} catch (Exception e) {
LogHelper.log(LOG, Level.INFO, cannotSetConfigBeanFor, e, finalConfigBean.getClass().getName());
}
return finalConfigBean;
}
m = findSuitableCollectionGetter(owningClassForLocation, configBeanClass);
if (m != null) {
try {
Collection col = (Collection) m.invoke(parent);
String name = getNameForConfigBean(finalConfigBean, configBeanClass);
ConfigBeanProxy itemToRemove = getNamedConfigBeanFromCollection(col, name, configBeanClass);
if (configBeanDefaultValue.replaceCurrentIfExists()) {
try {
if (itemToRemove != null) {
if (stackPositionHigher(finalConfigBean, itemToRemove)) {
col.remove(itemToRemove);
}
}
} catch (Exception ex) {
LogHelper.log(LOG, Level.INFO, cannotRemoveConfigBean, ex, finalConfigBean.getClass().getName());
}
}
if (configBeanClass.getAnnotation(HasCustomizationTokens.class) != null) {
applyCustomTokens(configBeanDefaultValue, finalConfigBean, parent);
}
if (itemToRemove != null && !configBeanDefaultValue.replaceCurrentIfExists()) {
// Check for duplication here.
if (((ConfigView) Proxy.getInvocationHandler(itemToRemove)).getProxyType().isAssignableFrom(configBeanClass)) {
return finalConfigBean;
}
}
col.add(finalConfigBean);
return finalConfigBean;
} catch (Exception e) {
LogHelper.log(LOG, Level.INFO, cannotSetConfigBeanFor, e, finalConfigBean.getClass().getName());
}
}
return null;
}
Aggregations