use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class ResourceUtil method getMethodMetaData2.
public static MethodMetaData getMethodMetaData2(Dom parent, ConfigModel childModel, int parameterType) {
MethodMetaData methodMetaData = new MethodMetaData();
List<Class<?>> interfaces = new ArrayList<Class<?>>();
Map<String, ParameterMetaData> params = new HashMap<String, ParameterMetaData>();
try {
Class<? extends ConfigBeanProxy> configBeanProxy = (Class<? extends ConfigBeanProxy>) childModel.classLoaderHolder.loadClass(childModel.targetTypeName);
getInterfaces(configBeanProxy, interfaces);
Set<String> attributeNames = childModel.getAttributeNames();
for (String attributeName : attributeNames) {
String methodName = ResourceUtil.getAttributeMethodName(attributeName);
// camelCase the attributeName before passing out
attributeName = Util.eleminateHypen(attributeName);
ParameterMetaData parameterMetaData = params.get(attributeName);
if (parameterMetaData == null) {
parameterMetaData = new ParameterMetaData();
params.put(attributeName, parameterMetaData);
}
// Check parent interfaces
for (int i = interfaces.size() - 1; i >= 0; i--) {
Class<?> intf = interfaces.get(i);
try {
Method method = intf.getMethod(methodName);
Attribute attribute = method.getAnnotation(Attribute.class);
if (attribute != null) {
ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
}
} catch (NoSuchMethodException e) {
}
}
// Check ConfigBean
try {
Method method = configBeanProxy.getMethod(methodName);
Attribute attribute = method.getAnnotation(Attribute.class);
if (attribute != null) {
ParameterMetaData localParam = ResourceUtil.getParameterMetaData(attribute);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.DEFAULT_VALUE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.KEY);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.TYPE);
copyParameterMetaDataAttribute(localParam, parameterMetaData, Constants.OPTIONAL);
}
} catch (NoSuchMethodException e) {
}
methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
}
} catch (MultiException cnfe) {
throw new RuntimeException(cnfe);
}
return methodMetaData;
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class ResourceUtil method getMethodMetaData.
/**
* Constructs and returns the resource method meta-data. This method is
* called to get meta-data in case of update method (POST).
*
* @param configBeanModel the config bean associated with the resource.
* @return MethodMetaData the meta-data store for the resource method.
*/
public static MethodMetaData getMethodMetaData(ConfigModel configBeanModel) {
MethodMetaData methodMetaData = new MethodMetaData();
Class<? extends ConfigBeanProxy> configBeanProxy = null;
try {
configBeanProxy = (Class<? extends ConfigBeanProxy>) configBeanModel.classLoaderHolder.loadClass(configBeanModel.targetTypeName);
Set<String> attributeNames = configBeanModel.getAttributeNames();
for (String attributeName : attributeNames) {
String methodName = getAttributeMethodName(attributeName);
Method method = null;
try {
method = configBeanProxy.getMethod(methodName);
} catch (NoSuchMethodException e) {
// Method not found, so let's try a brute force method if the method
// can't be found via the method above. For example: for
// Ssl.getSSLInactivityTimeout(), we calculate getSslInactivityTimeout,
// which doesn't match due to case.
String booleanMethodName = getAttributeBooleanMethodName(attributeName);
for (Method m : configBeanProxy.getMethods()) {
if (m.getName().equalsIgnoreCase(methodName) || m.getName().equalsIgnoreCase(booleanMethodName)) {
method = m;
}
}
}
Attribute attribute = method.getAnnotation(Attribute.class);
if (attribute != null) {
ParameterMetaData parameterMetaData = getParameterMetaData(attribute);
if (method.getAnnotation(Deprecated.class) != null) {
parameterMetaData.putAttribute(Constants.DEPRECATED, "true");
}
// camelCase the attributeName before passing out
attributeName = eleminateHypen(attributeName);
methodMetaData.putParameterMetaData(attributeName, parameterMetaData);
}
}
} catch (MultiException e) {
e.printStackTrace();
}
return methodMetaData;
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class ConfigBeanJMXSupport method getTypeString.
public String getTypeString(final Class<? extends ConfigBeanProxy> intf) {
String type = null;
final Configured configuredAnnotation = intf.getAnnotation(Configured.class);
if (configuredAnnotation != null && configuredAnnotation.name().length() != 0) {
type = configuredAnnotation.name();
if (type == null || type.length() == 0) {
throw new IllegalArgumentException("ConfigBeanJMXSupport.getTypeString(): Malformed @Configured annotation on " + intf.getName());
}
} else {
final Package pkg = intf.getPackage();
String simple = intf.getName().substring(pkg.getName().length() + 1, intf.getName().length());
type = Util.typeFromName(simple);
if (type == null || type.length() == 0) {
throw new IllegalArgumentException("ConfigBeanJMXSupport.getTypeString(): Malformed type generated from " + intf.getName());
}
}
return type;
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class ConfigBeanJMXSupport method findStuff.
private void findStuff(final Class<? extends ConfigBeanProxy> intf, final List<AttributeMethodInfo> attrs, final List<ElementMethodInfo> elements, final List<DuckTypedInfo> duckTyped) {
for (final Method m : intf.getMethods()) {
AttributeMethodInfo a;
// debug( "Method: " + m.getName() + " on " + m.getDeclaringClass() );
if ((a = AttributeMethodInfo.get(m)) != null) {
attrs.add(a);
if (a.returnType() != String.class) {
AMXLoggerInfo.getLogger().log(Level.INFO, AMXLoggerInfo.illegalNonstring, new Object[] { intf.getName(), m.getName(), a.returnType().getName() });
}
continue;
}
ElementMethodInfo e;
if ((e = ElementMethodInfo.get(m)) != null) {
elements.add(e);
continue;
}
final DuckTyped dt = m.getAnnotation(DuckTyped.class);
if (dt != null && isRemoteableDuckTyped(m, dt)) {
duckTyped.add(new DuckTypedInfo(m, dt));
}
}
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class DynamicConfigListener method changed.
@Override
public synchronized UnprocessedChangeEvents changed(final 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, "NetworkConfig changed {0} {1} {2}", new Object[] { type, tClass, t });
}
if (tClass == NetworkListener.class && t instanceof NetworkListener) {
return processNetworkListener(type, (NetworkListener) t, events);
} else if (tClass == Http.class && t instanceof Http) {
return processProtocol(type, (Protocol) t.getParent(), events);
} else if (tClass == FileCache.class && t instanceof FileCache) {
return processProtocol(type, (Protocol) t.getParent().getParent(), null);
} else if (tClass == Ssl.class && t instanceof Ssl) {
/*
* Make sure the SSL parent is in fact a protocol. It could
* be a jmx-connector.
*/
final ConfigBeanProxy parent = t.getParent();
if (parent instanceof Protocol) {
return processProtocol(type, (Protocol) parent, null);
}
} else if (tClass == Protocol.class && t instanceof Protocol) {
return processProtocol(type, (Protocol) t, null);
} else if (tClass == ThreadPool.class && t instanceof ThreadPool) {
NotProcessed notProcessed = null;
ThreadPool threadPool = (ThreadPool) t;
for (NetworkListener listener : threadPool.findNetworkListeners()) {
notProcessed = processNetworkListener(type, listener, null);
}
// Throw an unprocessed event change if one hasn't already if HTTP or ThreadPool monitoring is enabled.
MonitoringService ms = config.getMonitoringService();
String threadPoolLevel = ms.getModuleMonitoringLevels().getThreadPool();
String httpServiceLevel = ms.getModuleMonitoringLevels().getHttpService();
if (((threadPoolLevel != null && !threadPoolLevel.equals(OFF)) || (httpServiceLevel != null && !httpServiceLevel.equals(OFF))) && notProcessed == null) {
notProcessed = new NotProcessed("Monitoring statistics will be incorrect for " + threadPool.getName() + " until restart due to changed attribute(s).");
}
return notProcessed;
} else if (tClass == Transport.class && t instanceof Transport) {
NotProcessed notProcessed = null;
for (NetworkListener listener : ((Transport) t).findNetworkListeners()) {
notProcessed = processNetworkListener(type, listener, null);
}
return notProcessed;
} else if (tClass == VirtualServer.class && t instanceof VirtualServer && !grizzlyService.hasMapperUpdateListener()) {
return processVirtualServer(type, (VirtualServer) t);
} else if (tClass == SystemProperty.class && t instanceof SystemProperty) {
NetworkConfig networkConfig = config.getNetworkConfig();
if ((networkConfig != null) && ((SystemProperty) t).getName().endsWith("LISTENER_PORT")) {
for (NetworkListener listener : networkConfig.getNetworkListeners().getNetworkListener()) {
if (listener.getPort().equals(((SystemProperty) t).getValue())) {
return processNetworkListener(Changed.TYPE.CHANGE, listener, events);
}
}
}
return null;
}
return null;
}
}, logger);
}
Aggregations