use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class ConfigInstanceListener method lifecycleEvent.
/* (non-Javadoc)
* @see org.glassfish.hk2.api.InstanceLifecycleListener#lifecycleEvent(org.glassfish.hk2.api.InstanceLifecycleEvent)
*/
@Override
public void lifecycleEvent(InstanceLifecycleEvent lifecycleEvent) {
if (!lifecycleEvent.getEventType().equals(InstanceLifecycleEventType.POST_PRODUCTION)) {
return;
}
Map<Injectee, Object> injectees = lifecycleEvent.getKnownInjectees();
if (injectees == null)
return;
ConfigListener listener = (ConfigListener) lifecycleEvent.getLifecycleObject();
for (Object injectee : injectees.values()) {
if (!(injectee instanceof ConfigBeanProxy))
continue;
ConfigBeanProxy configBeanProxy = (ConfigBeanProxy) injectee;
Object impl = ConfigSupport.getImpl(configBeanProxy);
if (!(impl instanceof ObservableBean))
continue;
ObservableBean ob = (ObservableBean) impl;
ob.addListener(listener);
}
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class CommandSecurityChecker method resourceNameFromRestEndpoint.
private static String resourceNameFromRestEndpoint(Class<? extends ConfigBeanProxy> c, final String path, final ServiceLocator locator) {
ConfigBeanProxy b = locator.getService(c);
String name = (b != null ? AccessRequired.Util.resourceNameFromConfigBeanProxy(b) : "?");
if (path != null) {
name += '/' + path;
}
return name;
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class DomainXmlVerifier method checkDuplicate.
private void checkDuplicate(Collection<? extends Dom> beans) {
if (beans == null || beans.size() <= 1) {
return;
}
WeakHashMap keyBeanMap = new WeakHashMap();
ArrayList<String> keys = new ArrayList<String>(beans.size());
for (Dom b : beans) {
String key = b.getKey();
keyBeanMap.put(key, b);
keys.add(key);
}
WeakHashMap<String, Class<ConfigBeanProxy>> errorKeyBeanMap = new WeakHashMap<String, Class<ConfigBeanProxy>>();
String[] strKeys = keys.toArray(new String[beans.size()]);
for (int i = 0; i < strKeys.length; i++) {
boolean foundDuplicate = false;
for (int j = i + 1; j < strKeys.length; j++) {
// we have a duplicate. So output that error
if ((strKeys[i].equals(strKeys[j]))) {
foundDuplicate = true;
errorKeyBeanMap.put(strKeys[i], ((Dom) keyBeanMap.get(strKeys[i])).getProxyType());
error = true;
break;
}
}
}
for (Map.Entry e : errorKeyBeanMap.entrySet()) {
Result result = new Result(strings.get("VerifyDupKey", e.getKey(), e.getValue()));
output(result);
}
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class TemplateListOfResource method getPostCommand.
/**
* allows for remote files to be put in a tmp area and we pass the
* local location of this file to the corresponding command instead of the content of the file
* * Yu need to add enctype="multipart/form-data" in the form
* for ex: <form action="http://localhost:4848/management/domain/applications/application" method="post" enctype="multipart/form-data">
* then any param of type="file" will be uploaded, stored locally and the param will use the local location
* on the server side (ie. just the path)
*/
public String getPostCommand() {
ConfigModel.Property p = parent.model.getElement(tagName);
if (p == null) {
// "*"
ConfigModel.Property childElement = parent.model.getElement("*");
if (childElement != null) {
ConfigModel.Node node = (ConfigModel.Node) childElement;
ConfigModel childModel = node.getModel();
List<ConfigModel> subChildConfigModels = ResourceUtil.getRealChildConfigModels(childModel, parent.document);
for (ConfigModel subChildConfigModel : subChildConfigModels) {
if (subChildConfigModel.getTagName().equals(tagName)) {
return ResourceUtil.getCommand(RestRedirect.OpType.POST, subChildConfigModel);
}
}
}
} else {
ConfigModel.Node n = (ConfigModel.Node) p;
String command = ResourceUtil.getCommand(RestRedirect.OpType.POST, n.getModel());
if (command != null) {
return command;
}
// last possible case...the @Create annotation on a parent method
Class<? extends ConfigBeanProxy> cbp = null;
try {
cbp = (Class<? extends ConfigBeanProxy>) parent.model.classLoaderHolder.loadClass(parent.model.targetTypeName);
} catch (MultiException e) {
//
return null;
}
Create create = null;
for (Method m : cbp.getMethods()) {
ConfigModel.Property pp = parent.model.toProperty(m);
if ((pp != null) && (pp.xmlName.equals(tagName)) && (m.isAnnotationPresent(Create.class))) {
create = m.getAnnotation(Create.class);
break;
}
}
if (create != null) {
return create.value();
}
}
return null;
}
use of org.jvnet.hk2.config.ConfigBeanProxy in project Payara by payara.
the class TemplateRestResource method getDeleteCommand.
protected String getDeleteCommand() {
if (entity == null) {
return null;
}
String result = ResourceUtil.getCommand(RestRedirect.OpType.DELETE, getEntity().model);
if ((result == null) && (entity.parent() != null)) {
// trying @Delete annotation that as a generic CRUD delete command, possibly...
Class<? extends ConfigBeanProxy> cbp = null;
try {
cbp = (Class<? extends ConfigBeanProxy>) entity.parent().model.classLoaderHolder.loadClass(entity.parent().model.targetTypeName);
} catch (MultiException e) {
//
return null;
}
Delete del = null;
for (Method m : cbp.getMethods()) {
ConfigModel.Property pp = entity.parent().model.toProperty(m);
if ((pp != null) && (pp.xmlName.equals(tagName)) && m.isAnnotationPresent(Delete.class)) {
del = m.getAnnotation(Delete.class);
break;
}
}
if (del != null) {
return del.value();
}
}
return result;
}
Aggregations