use of org.glassfish.admin.rest.provider.MethodMetaData 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.glassfish.admin.rest.provider.MethodMetaData 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.glassfish.admin.rest.provider.MethodMetaData in project Payara by payara.
the class CollectionLeafResource method buildActionReportResult.
protected ActionReportResult buildActionReportResult() {
RestActionReporter ar = new RestActionReporter();
final String typeKey = upperCaseFirstLetter((decode(getName())));
ar.setActionDescription(typeKey);
ar.getExtraProperties().put("leafList", getEntity());
OptionsResult optionsResult = new OptionsResult(Util.getResourceName(uriInfo));
Map<String, MethodMetaData> mmd = getMethodMetaData();
optionsResult.putMethodMetaData("GET", mmd.get("GET"));
optionsResult.putMethodMetaData("POST", mmd.get("POST"));
ResourceUtil.addMethodMetaData(ar, mmd);
return new ActionReportResult(ar, optionsResult);
}
use of org.glassfish.admin.rest.provider.MethodMetaData in project Payara by payara.
the class LeafResource method getMethodMetaData.
protected Map<String, MethodMetaData> getMethodMetaData() {
Map<String, MethodMetaData> mmd = new TreeMap<String, MethodMetaData>();
// GET meta data
mmd.put("GET", new MethodMetaData());
return mmd;
}
use of org.glassfish.admin.rest.provider.MethodMetaData in project Payara by payara.
the class LeafResource method buildActionReportResult.
protected ActionReportResult buildActionReportResult() {
RestActionReporter ar = new RestActionReporter();
final String typeKey = (decode(getName()));
ar.setActionDescription(typeKey);
ar.getExtraProperties().put("entityLeaf", getEntity());
OptionsResult optionsResult = new OptionsResult(Util.getResourceName(uriInfo));
Map<String, MethodMetaData> mmd = getMethodMetaData();
optionsResult.putMethodMetaData("GET", mmd.get("GET"));
optionsResult.putMethodMetaData("POST", mmd.get("POST"));
ResourceUtil.addMethodMetaData(ar, mmd);
ActionReportResult r = new ActionReportResult(ar, optionsResult);
r.setLeafContent(entity);
return r;
}
Aggregations