package org.glassfish.examples.extension.greeter.config;
import org.glassfish.api.admin.AdminCommand;
import org.glassfish.api.admin.AdminCommandContext;
import org.glassfish.api.Param;
import org.jvnet.hk2.annotations.Service;
import org.jvnet.hk2.annotations.Inject;
import org.jvnet.hk2.config.Transactions;
import org.jvnet.hk2.config.ConfigSupport;
import org.jvnet.hk2.config.SingleConfigCode;
import org.jvnet.hk2.config.TransactionFailure;
import java.beans.PropertyVetoException;
@Service(name = "configure-greeter-container")
public class ConfigureGreeterContainerCommand implements AdminCommand {
@Param(acceptableValues = "1,2,3,4,5,6,7,8,9,10", defaultValue = "5")
String instances;
@Param(acceptableValues = "english,norsk,francais", defaultValue = "norsk",
optional = true)
String language;
@Param(acceptableValues = "formal,casual,expansive", defaultValue = "formal",
optional = true)
String style;
@Inject
GreeterContainerConfig config;
public void execute(AdminCommandContext adminCommandContext) {
try {
ConfigSupport.apply(new SingleConfigCode<GreeterContainerConfig>() {
public Object run(GreeterContainerConfig greeterContainerConfig)
throws PropertyVetoException, TransactionFailure {
greeterContainerConfig.setNumberOfInstances(instances);
greeterContainerConfig.setLanguage(language);
greeterContainerConfig.setStyle(style);
return null;
}
}, config);
} catch (TransactionFailure e) {
}
}
}