use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class ConfigDomainParser method parseIDEntry.
private void parseIDEntry(ProviderConfig pConfig, Map<String, GFServerConfigProvider.InterceptEntry> newConfig, String intercept) throws IOException {
String id = pConfig.getProviderId();
String type = pConfig.getProviderType();
String moduleClass = pConfig.getClassName();
MessagePolicy requestPolicy = parsePolicy((RequestPolicy) pConfig.getRequestPolicy());
MessagePolicy responsePolicy = parsePolicy((ResponsePolicy) pConfig.getResponsePolicy());
// get the module options
Map<String, Object> options = new HashMap<>();
List<Property> pList = pConfig.getProperty();
if (pList != null) {
Iterator<Property> pit = pList.iterator();
while (pit.hasNext()) {
Property property = pit.next();
try {
options.put(property.getName(), PropertyExpander.expand(property.getValue(), false));
} catch (ExpandException ee) {
// interpret value itself.
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "jmac.unexpandedproperty");
}
options.put(property.getName(), property.getValue());
}
}
}
if (_logger.isLoggable(FINE)) {
_logger.fine("ID Entry: " + "\n module class: " + moduleClass + "\n id: " + id + "\n type: " + type + "\n request policy: " + requestPolicy + "\n response policy: " + responsePolicy + "\n options: " + options);
}
// create ID entry
GFServerConfigProvider.IDEntry idEntry = new GFServerConfigProvider.IDEntry(type, moduleClass, requestPolicy, responsePolicy, options);
GFServerConfigProvider.InterceptEntry intEntry = newConfig.get(intercept);
if (intEntry == null) {
throw new IOException("intercept entry for " + intercept + " must be specified before ID entries");
}
if (intEntry.idMap == null) {
intEntry.idMap = new HashMap<>();
}
// map id to Intercept
intEntry.idMap.put(id, idEntry);
}
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;
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class ExtensionPatternInvocationImpl method handleExtension.
@Override
public ConfigBeanProxy handleExtension(Object owner, Class ownerType, Object[] params) {
if (((Class) params[0]).getName().equals("com.sun.enterprise.config.serverbeans.SystemProperty"))
return null;
ConfigBeanProxy configExtension = null;
List<ConfigBeanProxy> extensions = configModularityUtils.getExtensions(((ConfigBean) owner).createProxy(ownerType));
for (ConfigBeanProxy extension : extensions) {
try {
configExtension = (ConfigBeanProxy) ((Class) params[0]).cast(extension);
return configExtension;
} catch (Exception e) {
// ignore, not the right type.
}
}
try {
ConfigBeanProxy pr = ((ConfigBean) owner).createProxy(ownerType);
ConfigBeanProxy returnValue = moduleConfigurationLoader.createConfigBeanForType((Class) params[0], pr);
return returnValue;
} catch (TransactionFailure transactionFailure) {
LogHelper.log(LOG, Level.INFO, "Cannot get extension type {0} for {1}.", transactionFailure, new Object[] { owner.getClass().getName(), ownerType.getName() });
return null;
}
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class ActionReportResultHtmlProvider method getContent.
@Override
public String getContent(ActionReportResult proxy) {
RestActionReporter ar = (RestActionReporter) proxy.getActionReport();
StringBuilder result = new StringBuilder(ProviderUtil.getHtmlHeader(getBaseUri()));
final String message = ResourceUtil.encodeString(ar.getCombinedMessage());
if (!message.isEmpty()) {
result.append("<h3>").append(message).append(HEADING_END);
}
if (proxy.isError()) {
result.append("<h2>").append(ar.getActionDescription()).append(" Error:</h2>").append(proxy.getErrorMessage());
} else {
final Map<String, String> childResources = (Map<String, String>) ar.getExtraProperties().get("childResources");
final List<Map<String, String>> commands = (List<Map<String, String>>) ar.getExtraProperties().get("commands");
final MethodMetaData postMetaData = proxy.getMetaData().getMethodMetaData("POST");
final MethodMetaData deleteMetaData = proxy.getMetaData().getMethodMetaData(DELETE);
final MethodMetaData getMetaData = proxy.getMetaData().getMethodMetaData("GET");
final ConfigBean entity = proxy.getEntity();
if ((proxy.getCommandDisplayName() != null) && (getMetaData != null)) {
// for commands, we want the output of the command before the form
if (entity == null) {
// show extra properties only for non entity pages
result.append(processReport(ar));
}
}
if ((postMetaData != null) && (entity == null)) {
String postCommand = getHtmlRespresentationsForCommand(postMetaData, "POST", (proxy.getCommandDisplayName() == null) ? "Create" : proxy.getCommandDisplayName(), uriInfo.get());
result.append(getHtmlForComponent(postCommand, "Create " + ar.getActionDescription(), ""));
}
if ((deleteMetaData != null) && (entity == null)) {
String deleteCommand = getHtmlRespresentationsForCommand(deleteMetaData, DELETE, (proxy.getCommandDisplayName() == null) ? "Delete" : proxy.getCommandDisplayName(), uriInfo.get());
result.append(getHtmlForComponent(deleteCommand, "Delete " + ar.getActionDescription(), ""));
}
if ((getMetaData != null) && (entity == null) && (proxy.getCommandDisplayName() != null)) {
String getCommand = getHtmlRespresentationsForCommand(getMetaData, "GET", (proxy.getCommandDisplayName() == null) ? "Get" : proxy.getCommandDisplayName(), uriInfo.get());
result.append(getHtmlForComponent(getCommand, "Get " + ar.getActionDescription(), ""));
}
if (entity != null) {
String attributes = ProviderUtil.getHtmlRepresentationForAttributes(proxy.getEntity(), uriInfo.get());
result.append(ProviderUtil.getHtmlForComponent(attributes, ar.getActionDescription() + " Attributes", ""));
String deleteCommand = ProviderUtil.getHtmlRespresentationsForCommand(proxy.getMetaData().getMethodMetaData(DELETE), DELETE, (proxy.getCommandDisplayName() == null) ? "Delete" : proxy.getCommandDisplayName(), uriInfo.get());
result.append(ProviderUtil.getHtmlForComponent(deleteCommand, "Delete " + entity.model.getTagName(), ""));
} else if (proxy.getLeafContent() != null) {
// it is a single leaf @Element
String content = "<form action=\"" + uriInfo.get().getAbsolutePath().toString() + "\" method=\"post\">" + "<dl><dt>" + "<label for=\"" + proxy.getLeafContent().name + "\">" + proxy.getLeafContent().name + ": </label>" + "</dt><dd>" + "<input name=\"" + proxy.getLeafContent().name + "\" value =\"" + proxy.getLeafContent().value + "\" type=\"text\" >" + "</dd><dt class=\"button\"></dt><dd class=\"button\"><input value=\"Update\" type=\"submit\"></dd></dl>" + "</form><br><hr class=\"separator\"/";
result.append(content);
} else {
// This is a monitoring result!!!
final Map vals = (Map) ar.getExtraProperties().get("entity");
if ((vals != null) && (!vals.isEmpty())) {
result.append("<ul>");
for (Map.Entry entry : (Set<Map.Entry>) vals.entrySet()) {
Object object = entry.getValue();
if (object == null) {
// do nothing
} else if (object instanceof Collection) {
if (!((Collection) object).isEmpty()) {
Collection c = ((Collection) object);
Iterator i = c.iterator();
result.append("<li>").append(entry.getKey());
result.append("<ul>");
while (i.hasNext()) {
result.append("<li>").append(getHtmlRepresentation(i.next())).append(LIST_ITEM_END);
}
result.append(LIST_END);
result.append(LIST_ITEM_END);
}
} else if (object instanceof Map) {
if (!((Map) object).isEmpty()) {
Map m = (Map) object;
if (vals.size() != 1) {
// add a link if more than 1 child
result.append("<li>").append(ANCHOR_OPEN).append(uriInfo.get().getAbsolutePath().toString()).append("/").append(entry.getKey()).append("\">").append(entry.getKey()).append("</a>");
} else {
result.append("<li>").append(entry.getKey());
}
result.append("<ul>");
for (Map.Entry anEntry : (Set<Map.Entry>) m.entrySet()) {
final String htmlRepresentation = getHtmlRepresentation(anEntry.getValue());
if (htmlRepresentation != null) {
result.append("<li>").append(anEntry.getKey()).append(" : ").append(htmlRepresentation).append(LIST_ITEM_END);
}
}
result.append(LIST_END);
result.append(LIST_ITEM_END);
}
} else {
result.append("<li>").append(entry.getKey()).append(" : ").append(object.toString()).append(LIST_ITEM_END);
}
}
result.append(LIST_END);
} else {
// no values to show... give an hint
if ((childResources == null) || (childResources.isEmpty())) {
if ((uriInfo != null) && (uriInfo.get().getPath().equalsIgnoreCase("domain"))) {
result.append(getHint(uriInfo.get(), MediaType.TEXT_HTML));
}
}
}
}
if ((childResources != null) && (!childResources.isEmpty())) {
String childResourceLinks = getResourcesLinks(childResources);
result.append(ProviderUtil.getHtmlForComponent(childResourceLinks, "Child Resources", ""));
}
if ((commands != null) && (!commands.isEmpty())) {
String commandLinks = getCommandLinks(commands);
result.append(ProviderUtil.getHtmlForComponent(commandLinks, "Commands", ""));
}
}
return result.append("</div></body></html>").toString();
}
use of org.jvnet.hk2.config.Changed.TYPE 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;
}
Aggregations