use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class GetHttpListener method execute.
@Override
public void execute(AdminCommandContext context) {
ActionReport report = context.getActionReport();
// Check that a configuration can be found
if (targetUtil.getConfig(target) == null) {
report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_CONFIG), target));
return;
}
Config config = targetUtil.getConfig(target);
// Check that a matching listener can be found
List<NetworkListener> listeners = config.getNetworkConfig().getNetworkListeners().getNetworkListener();
Optional<NetworkListener> optionalListener = listeners.stream().filter(listener -> listener.getName().equals(listenerName)).findFirst();
if (!optionalListener.isPresent()) {
report.failure(logger, MessageFormat.format(logger.getResourceBundle().getString(LogFacade.UNKNOWN_NETWORK_LISTENER), listenerName, target));
return;
}
NetworkListener listener = optionalListener.get();
// Write message body
report.appendMessage(String.format("Name: %s\n", listener.getName()));
report.appendMessage(String.format("Enabled: %s\n", listener.getEnabled()));
report.appendMessage(String.format("Port: %s\n", listener.getPort()));
if (listener.getPortRange() != null) {
report.appendMessage(String.format("Port Range: %s\n", listener.getPortRange()));
}
report.appendMessage(String.format("Address: %s\n", listener.getAddress()));
report.appendMessage(String.format("Protocol: %s\n", listener.getProtocol()));
if (verbose) {
report.appendMessage(String.format("Transport: %s\n", listener.getTransport()));
report.appendMessage(String.format("Type: %s\n", listener.getType()));
report.appendMessage(String.format("Thread Pool: %s\n", listener.getThreadPool()));
report.appendMessage(String.format("JK Enabled: %s\n", listener.getJkEnabled()));
report.appendMessage(String.format("JK Configuration File: %s\n", listener.getJkConfigurationFile()));
}
// Write the variables as properties
Properties properties = new Properties();
properties.put("name", listener.getName());
properties.put("enabled", listener.getEnabled());
properties.put("port", listener.getPort());
if (listener.getPortRange() != null) {
properties.put("portRange", listener.getPortRange());
}
properties.put("address", listener.getAddress());
properties.put("protocol", listener.getProtocol());
properties.put("transport", listener.getTransport());
properties.put("type", listener.getType());
properties.put("threadPool", listener.getThreadPool());
properties.put("jkEnabled", listener.getJkEnabled());
properties.put("jkConfigurationFile", listener.getJkConfigurationFile());
report.setExtraProperties(properties);
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class DomainXml method parseDomainXml.
/**
* Parses <tt>domain.xml</tt>
* @param parser
* @param domainXml
* @param serverName
*/
protected void parseDomainXml(ConfigParser parser, final URL domainXml, final String serverName) {
long startNano = System.nanoTime();
try {
ServerReaderFilter xsr = null;
// Set the resolver so that any external entity references, such
// as a reference to a DTD, return an empty file. The domain.xml
// file doesn't support entity references.
xif.setXMLResolver(new XMLResolver() {
@Override
public Object resolveEntity(String publicID, String systemID, String baseURI, String namespace) throws XMLStreamException {
return new ByteArrayInputStream(new byte[0]);
}
});
if (null == env.getRuntimeType()) {
throw new RuntimeException("Internal Error: Unknown server type: " + env.getRuntimeType());
} else {
switch(env.getRuntimeType()) {
case DAS:
case EMBEDDED:
case MICRO:
xsr = new DasReaderFilter(domainXml, xif);
break;
case INSTANCE:
xsr = new InstanceReaderFilter(env.getInstanceName(), domainXml, xif);
break;
default:
throw new RuntimeException("Internal Error: Unknown server type: " + env.getRuntimeType());
}
}
Lock lock = null;
try {
// lock the domain.xml for reading if not embedded
try {
lock = configAccess.accessRead();
} catch (Exception e) {
// ignore
}
parser.parse(xsr, getDomDocument());
xsr.close();
} finally {
if (lock != null) {
lock.unlock();
}
}
String errorMessage = xsr.configWasFound();
if (errorMessage != null) {
LogRecord lr = new LogRecord(Level.WARNING, errorMessage);
lr.setLoggerName(getClass().getName());
EarlyLogHandler.earlyMessages.add(lr);
}
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
throw new RuntimeException("Fatal Error. Unable to parse " + domainXml, e);
}
}
Long l = System.nanoTime() - startNano;
LogRecord lr = new LogRecord(Level.FINE, totalTimeToParseDomain + l.toString());
lr.setLoggerName(getClass().getName());
EarlyLogHandler.earlyMessages.add(lr);
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class GenericCrudCommand method elementName.
/**
* Returns the element name used by the parent to store instances of the child
*
* @param document the dom document this configuration element lives in.
* @param parent type of the parent
* @param child type of the child
* @return the element name holding child's instances in the parent
* @throws ClassNotFoundException when subclasses cannot be loaded
*/
public static String elementName(DomDocument document, Class<?> parent, Class<?> child) throws ClassNotFoundException {
ConfigModel cm = document.buildModel(parent);
for (String elementName : cm.getElementNames()) {
ConfigModel.Property prop = cm.getElement(elementName);
if (prop instanceof ConfigModel.Node) {
ConfigModel childCM = ((ConfigModel.Node) prop).getModel();
String childTypeName = childCM.targetTypeName;
if (childTypeName.equals(child.getName())) {
return childCM.getTagName();
}
// check the inheritance hierarchy
List<ConfigModel> subChildrenModels = document.getAllModelsImplementing(childCM.classLoaderHolder.loadClass(childTypeName));
if (subChildrenModels != null) {
for (ConfigModel subChildModel : subChildrenModels) {
if (subChildModel.targetTypeName.equals(child.getName())) {
return subChildModel.getTagName();
}
}
}
}
}
return null;
}
use of org.jvnet.hk2.config.Changed.TYPE in project Payara by payara.
the class TargetBasedResolver method getTarget.
private <T extends ConfigBeanProxy> T getTarget(Class<? extends ConfigBeanProxy> targetType, Class<T> type) throws ClassNotFoundException {
// when using the target based parameter, we look first for a configuration of that name,
// then we look for a cluster of that name and finally we look for a subelement of the right type
final String name = getName();
ConfigBeanProxy config = habitat.getService(targetType, target);
if (config != null) {
try {
return type.cast(config);
} catch (ClassCastException e) {
// ok we need to do more work to find which object is really requested.
}
Dom parentDom = Dom.unwrap(config);
String elementName = GenericCrudCommand.elementName(parentDom.document, targetType, type);
if (elementName == null) {
return null;
}
ConfigModel.Property property = parentDom.model.getElement(elementName);
if (property.isCollection()) {
Collection<Dom> collection;
synchronized (parentDom) {
collection = parentDom.nodeElements(elementName);
}
if (collection == null) {
return null;
}
for (Dom child : collection) {
if (name.equals(child.attribute("ref"))) {
return type.cast(child.<ConfigBeanProxy>createProxy());
}
}
}
}
return null;
}
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