本文整理了Java中org.jvnet.hk2.annotations.Inject
类的一些代码示例,展示了Inject
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Inject
类的具体详情如下:
包路径:org.jvnet.hk2.annotations.Inject
类名称:Inject
暂无
代码示例来源:origin: org.glassfish.admin/config-api
@Service
@Scoped(PerLookup.class)
public class CrDecorator implements CreationDecorator<SecureAdminInternalUser> {
@Param(optional=false, primary=true)
private String username;
@Param(optional=false)
private String passwordAlias;
@Inject
private SecureAdminHelper helper;
@Override
public void decorate(AdminCommandContext context, SecureAdminInternalUser instance) throws TransactionFailure, PropertyVetoException {
try {
helper.validateInternalUsernameAndPasswordAlias(
username, passwordAlias);
} catch (Exception ex) {
throw new TransactionFailure("create", ex);
}
instance.setUsername(username);
instance.setPasswordAlias(passwordAlias);
}
}
}
代码示例来源:origin: com.sun.enterprise/auto-depends
String getTargetName(AnnotatedElement target, Inject inject) {
Named named = target.getAnnotation(Named.class);
String name = inject.name();
if (named!=null && !inject.name().isEmpty()) {
throw new RuntimeException("Field or method [" + target.toString() + "] is annotated with both a @Named" +
" annotation as well as a @Inject.name() value, please choose");
}
if (named!=null) {
name = named.value();
}
return name;
}
}
代码示例来源:origin: org.glassfish.hk2/auto-depends
public boolean isOptional(AnnotatedElement element, Inject annotation) {
return annotation.optional();
}
代码示例来源:origin: org.glassfish.security/securitycommon
/**
*
* @author venu
* TODO: need to change this class, it needs to be similar to SecurityServicesUtil
*/
@Service
public class Util {
@Inject
static Habitat defaultHabitat;
public static Habitat getDefaultHabitat() {
return defaultHabitat;
}
}
代码示例来源:origin: org.glassfish.main.virtualization/virt-core
/**
* Start a stopped virtual machine.
* @author Jerome Dochez
*/
@Service(name="start-vm")
@Scoped(PerLookup.class)
public class StartVirtualMachine extends VirtualMachineMgt implements AdminCommand {
@Inject
VirtualMachineLifecycle vmLifecycle;
@Override
void doWork(VirtualMachine vm) throws VirtException {
vmLifecycle.start(vm);
}
}
代码示例来源:origin: org.glassfish.main.virtualization/virt-api
@Service
public class VirtResolver implements CrudResolver {
@Param
String virtualization;
@Inject
Virtualizations virtualizations;
@Override
@SuppressWarnings("unchecked")
public <T extends ConfigBeanProxy> T resolve(AdminCommandContext context, Class<T> type) {
return (T) virtualizations.byName(virtualization);
}
}
代码示例来源:origin: org.glassfish.main.virtualization/virt-core
public LocalServerPoolFactory(@Inject TemplateRepository templateRepository,
@Inject Domain domain,
@Inject ServerContext environment) {
this.templateRepository = templateRepository;
this.domain = domain;
this.environment = environment;
}
代码示例来源:origin: org.glassfish.admin/config-api
@Service
public static final class DefaultResolver implements CrudResolver {
@Inject(name="type", optional=true)
CrudResolver defaultResolver=null;
@Override
public <T extends ConfigBeanProxy> T resolve(AdminCommandContext context, Class<T> type) {
if (defaultResolver!=null) {
return defaultResolver.resolve(context, type);
}
return null;
}
}
}
代码示例来源:origin: org.glassfish.main/paas.orchestrator
@Service
@Scoped(PerLookup.class)
public class RemoteCommandExecutor {
@Inject
private SSHLauncher sshLauncher;
@Inject
private Logger logger;
代码示例来源:origin: org.glassfish.main.virtualization/virt-api
@Service
public class ServerPoolResolver implements CrudResolver {
@Param(name="serverPool")
String group;
@Param(optional = true)
String virtualization;
@Inject
Virtualizations virts;
@Override
public <T extends ConfigBeanProxy> T resolve(AdminCommandContext context, Class<T> type) {
Virtualization virt = virtualization==null?virts.getVirtualizations().get(0):virts.byName(virtualization);
ServerPoolConfig config = virt.serverPoolByName(group);
if (config!=null) {
return (T) config;
}
context.getActionReport().failure(context.getLogger(), "Cannot find a serverPool by the name of " + group);
return null;
}
}
代码示例来源:origin: org.glassfish.main.virtualization/virt-core
public GroupsAccessImpl(@Inject Injector injector, @Inject IAAS groupMgt) {
this.injector = injector;
this.groupMgt = groupMgt;
}
代码示例来源:origin: org.glassfish.admin/config-api
@Service
@Scoped(PerLookup.class)
public static class CrDecorator implements CreationDecorator<SecureAdminPrincipal> {
@Inject(/*name=CREATION_DECORATOR_NAME*/)
private SecureAdminHelper helper;
@Param(optional=false, name="value", primary=true)
private String value;
@Param(optional=true, name="alias", defaultValue="false")
private boolean isAlias = true;
代码示例来源:origin: org.glassfish.main.virtualization/virt-core
/**
* Provides environmental methods for the virtualization feature.
* @author Jerome Dochez
*/
@Service
public class VirtualizationEnvImpl implements VirtualizationEnv {
@Inject
Domain domain;
@Override
public boolean isPaasEnabled() {
Virtualizations virtualizations = domain.getExtensionByType(Virtualizations.class);
return (virtualizations!=null && virtualizations.getVirtualizations().size()>0);
}
}
代码示例来源:origin: org.glassfish.admin/config-api
@Service
@Scoped(PerLookup.class)
class DeleteDecorator implements DeletionDecorator<LbConfigs, LbConfig> {
@Inject
private Domain domain;
@Override
public void decorate(AdminCommandContext context, LbConfigs parent, LbConfig child)
throws PropertyVetoException, TransactionFailure {
Logger logger = LogDomains.getLogger(LbConfig.class, LogDomains.ADMIN_LOGGER);
LocalStringManagerImpl localStrings = new LocalStringManagerImpl(LbConfig.class);
String lbConfigName = child.getName();
LbConfig lbConfig = domain.getLbConfigs().getLbConfig(lbConfigName);
//Ensure there are no refs
if ( (lbConfig.getClusterRefOrServerRef().size() != 0 ) ) {
String msg = localStrings.getLocalString("LbConfigNotEmpty", lbConfigName);
throw new TransactionFailure(msg);
}
logger.info(localStrings.getLocalString("http_lb_admin.LbConfigDeleted", lbConfigName));
}
}
}
代码示例来源:origin: org.glassfish.admin/config-api
/**
* Resolver based on type + name.
*
* @author Jerome Dochez
*/
@Service
public class TypeAndNameResolver implements CrudResolver {
@Param(primary = true)
String name;
@Inject
Habitat habitat;
final protected static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(GenericCrudCommand.class);
@Override
public <T extends ConfigBeanProxy> T resolve(AdminCommandContext context, Class<T> type) {
T proxy = habitat.getComponent(type, name);
if (proxy==null) {
String msg = localStrings.getLocalString(TypeAndNameResolver.class,
"TypeAndNameResolver.target_object_not_found",
"Cannot find a {0} with a name {1}", type.getSimpleName(), name);
throw new RuntimeException(msg);
}
return proxy;
}
}
代码示例来源:origin: org.glassfish.main.virtualization/virt-core
public VirtualClusters(@Inject IAAS iaas, @Inject Domain domain) {
this.iaas = iaas;
this.domain = domain;
}
代码示例来源:origin: org.glassfish.hk2/auto-depends
static String injection_failed_msg(Object t, Annotation inject, Throwable cause) {
String name = (Inject.class.isInstance(inject)) ? Inject.class.cast(inject).name() : null;
name = (null == name || name.isEmpty()) ? null : name;
String msg;
if (Field.class.isInstance(t)) {
Field target = Field.class.cast(t);
msg = "injection failed on " + target.getDeclaringClass().getName() + "." +
target.getName() + " with " + target.getGenericType() + (null == name ? "" : " and name '" + name + "'");
} else {
msg = "injection failed on " + t + (null == name ? "" : " with name '" + name + "'");
}
return msg;
}
代码示例来源:origin: com.sun.enterprise/auto-depends
public boolean isOptional(AnnotatedElement element, Inject annotation) {
return annotation.optional();
}
代码示例来源:origin: org.glassfish.admin/admin-util
/**
*
* @author PRASHANTH ABBAGANI
*
* Factory class which returns the appropriate ResourceManager
*/
@Service(name="resource-factory")
@Scoped(PerLookup.class)
@I18n("add.resources")
public class ResourceFactory {
@Inject
private Habitat habitat;
public ResourceManager getResourceManager(Resource resource) {
String resourceType = resource.getType();
ResourceManager resourceManager = null;
for (ResourceManager rm : habitat.getAllByContract(ResourceManager.class)) {
if ((rm.getResourceType()).equals(resourceType)) {
resourceManager = rm;
break;
}
}
return resourceManager;
}
}
代码示例来源:origin: org.glassfish.common/internal-api
/**
* So far, the admin container does not require much configuration but we
* could imagine that it will eventually support configuring wether or not
* to start the AminGUI.
*
* @author Jerome Dochez
*/
@Service
public class AdminInfo implements ContainerBuilder<EmbeddedAdminContainer> {
@Inject
EmbeddedAdminContainer ctr;
public EmbeddedAdminContainer create(Server server) {
return ctr;
}
}
内容来源于网络,如有侵权,请联系作者删除!