本文整理汇总了Java中javax.enterprise.inject.Instance类的典型用法代码示例。如果您正苦于以下问题:Java Instance类的具体用法?Java Instance怎么用?Java Instance使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Instance类属于javax.enterprise.inject包,在下文中一共展示了Instance类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mockEndpointFromUri
import javax.enterprise.inject.Instance; //导入依赖的package包/类
@Uri("")
@Produces
@Typed(MockEndpoint.class)
// Qualifiers are dynamically added in CdiCamelExtension
private static MockEndpoint mockEndpointFromUri(InjectionPoint ip, @Any Instance<CamelContext> instance, CdiCamelExtension extension) {
Uri uri = getQualifierByType(ip, Uri.class).get();
try {
CamelContext context = uri.context().isEmpty()
? selectContext(ip, instance, extension)
: selectContext(uri.context(), instance);
return context.getEndpoint(uri.value(), MockEndpoint.class);
} catch (Exception cause) {
throw new InjectionException("Error injecting mock endpoint annotated with " + uri
+ " into " + ip, cause);
}
}
示例2: filter
import javax.enterprise.inject.Instance; //导入依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
Instance<Object> instance = CDI.current();
User user = instance.select(User.class).get();
List<AccountRole> roles = user.getAccountRoles();
if (Arrays.stream(permissions.roles()).anyMatch(roles::contains)) {
return;
}
Permission permission = instance.select(permissions.value()).get();
if (permission.test(requestContext)) {
return;
}
throw new ForbiddenException();
}
示例3: prepare
import javax.enterprise.inject.Instance; //导入依赖的package包/类
@Before
public void prepare() {
ZonedDateTimeAdapter adapter = new ZonedDateTimeAdapter();
Instance<BoundStatement> getByIdStatement = mock(Instance.class);
when(getByIdStatement.get())
.thenReturn(new BoundStatement(session.prepare(BoundStatements.GET_BY_ID.getValue())));
Instance<BoundStatement> createStatement = mock(Instance.class);
when(createStatement.get())
.thenReturn(new BoundStatement(session.prepare(BoundStatements.CREATE.getValue())));
tokenService = new TokenService();
tokenService.session = session;
tokenService.zonedDateTimeAdapter = adapter;
tokenService.stmtGetById = getByIdStatement;
tokenService.stmtCreate = createStatement;
}
示例4: PreferenceStoreImpl
import javax.enterprise.inject.Instance; //导入依赖的package包/类
@Inject
public PreferenceStoreImpl(final PreferenceStorage storage,
final PreferenceScopeFactory scopeFactory,
@Customizable final PreferenceScopeResolutionStrategy defaultScopeResolutionStrategy,
final Instance<PreferenceScopeResolutionStrategy> preferenceScopeResolutionStrategy,
final InjectionPoint ip) {
this.storage = storage;
this.scopeFactory = scopeFactory;
if (preferenceScopeResolutionStrategy.isUnsatisfied()) {
if (ip != null) {
String componentKey = null;
Annotation annotation = ip.getAnnotated().getAnnotation(ComponentKey.class);
if (annotation != null) {
componentKey = ((ComponentKey) annotation).value();
}
this.defaultScopeResolutionStrategy = new DefaultPreferenceScopeResolutionStrategy(scopeFactory,
componentKey);
} else {
this.defaultScopeResolutionStrategy = defaultScopeResolutionStrategy;
}
} else {
this.defaultScopeResolutionStrategy = preferenceScopeResolutionStrategy.get();
}
}
示例5: Row
import javax.enterprise.inject.Instance; //导入依赖的package包/类
@Inject
public Row(View view,
Instance<ComponentColumn> columnInstance,
Instance<ColumnWithComponents> columnWithComponentsInstance,
DnDManager dndManager,
LayoutDragComponentHelper layoutDragComponentHelper,
Event<ComponentDropEvent> componentDropEvent,
Event<ComponentRemovedEvent> componentRemovedEvent,
Event<RowResizeEvent> rowResizeEvent) {
this.view = view;
this.columnInstance = columnInstance;
this.columnWithComponentsInstance = columnWithComponentsInstance;
this.dndManager = dndManager;
this.layoutDragComponentHelper = layoutDragComponentHelper;
this.componentDropEvent = componentDropEvent;
this.componentRemovedEvent = componentRemovedEvent;
this.rowResizeEvent = rowResizeEvent;
}
示例6: CopyServiceImpl
import javax.enterprise.inject.Instance; //导入依赖的package包/类
@Inject
public CopyServiceImpl(@Named("ioStrategy") IOService ioService,
User identity,
SessionInfo sessionInfo,
Instance<CopyHelper> helpers,
Event<ResourceCopiedEvent> resourceCopiedEvent,
Instance<CopyRestrictor> copyRestrictorBeans,
PathNamingService pathNamingService) {
this.ioService = ioService;
this.identity = identity;
this.sessionInfo = sessionInfo;
this.helpers = helpers;
this.resourceCopiedEvent = resourceCopiedEvent;
this.copyRestrictorBeans = copyRestrictorBeans;
this.pathNamingService = pathNamingService;
}
示例7: setup
import javax.enterprise.inject.Instance; //导入依赖的package包/类
@Before
public void setup() {
securityConstraints = mock(Instance.class);
event1 = generateEvent(new SocialUser("admin"));
event2 = generateEvent(new SocialUser("dora"));
events = new ArrayList<>();
events.add(event1);
events.add(event2);
constraint1 = mock(SocialSecurityConstraint.class);
constraint2 = mock(SocialSecurityConstraint.class);
when(securityConstraints.iterator()).thenReturn(createSecurityConstraintsIterator());
socialSecurityConstraintsManager = new SocialSecurityConstraintsManager() {
@Override
Instance<SocialSecurityConstraint> getSocialSecurityConstraints() {
Instance<SocialSecurityConstraint> mock = mock(Instance.class);
when(mock.iterator()).thenReturn(createSecurityConstraintsIterator());
return mock;
}
};
}
示例8: PanelManagerImpl
import javax.enterprise.inject.Instance; //导入依赖的package包/类
@Inject
public PanelManagerImpl(
Event<PlaceGainFocusEvent> placeGainFocusEvent,
Event<PlaceLostFocusEvent> placeLostFocusEvent,
Event<PanelFocusEvent> panelFocusEvent,
Event<SelectPlaceEvent> selectPlaceEvent,
Event<PlaceMaximizedEvent> placeMaximizedEvent,
Event<PlaceMinimizedEvent> placeMinimizedEventEvent,
Event<PlaceHiddenEvent> placeHiddenEvent,
SyncBeanManager iocManager,
Instance<PlaceManager> placeManager,
LayoutSelection layoutSelection,
BeanFactory beanFactory) {
this.placeGainFocusEvent = placeGainFocusEvent;
this.placeLostFocusEvent = placeLostFocusEvent;
this.panelFocusEvent = panelFocusEvent;
this.selectPlaceEvent = selectPlaceEvent;
this.placeMaximizedEvent = placeMaximizedEvent;
this.placeMinimizedEvent = placeMinimizedEventEvent;
this.placeHiddenEvent = placeHiddenEvent;
this.iocManager = iocManager;
this.placeManager = placeManager;
this.layoutSelection = layoutSelection;
this.beanFactory = beanFactory;
}
示例9: setupGuvnorM2Repository
import javax.enterprise.inject.Instance; //导入依赖的package包/类
@Before
public void setupGuvnorM2Repository() {
ArtifactRepositoryPreference pref = mock(ArtifactRepositoryPreference.class);
when(pref.getGlobalM2RepoDir()).thenReturn("repositories/kie");
when(pref.isGlobalM2RepoDirEnabled()).thenReturn(true);
when(pref.isDistributionManagementM2RepoDirEnabled()).thenReturn(true);
when(pref.isWorkspaceM2RepoDirEnabled()).thenReturn(false);
WorkspaceNameResolver resolver = mock(WorkspaceNameResolver.class);
when(resolver.getWorkspaceName()).thenReturn("global");
ArtifactRepositoryProducer producer = new ArtifactRepositoryProducer(pref,
resolver);
producer.initialize();
Instance<ArtifactRepository> repositories = new MockInstanceImpl<>(producer.produceLocalRepository(),
producer.produceGlobalRepository(),
producer.produceDistributionManagementRepository());
ArtifactRepositoryService factory = new ArtifactRepositoryService(repositories);
repository = new GuvnorM2Repository(factory);
repository.init();
}
示例10: getJsTopicMessageControllerFromJsTopicControlsTest
import javax.enterprise.inject.Instance; //导入依赖的package包/类
/**
* Test of getJsTopicMessageControllerFromJsTopicControls method, of class.
*/
@Test
public void getJsTopicMessageControllerFromJsTopicControlsTest() {
System.out.println("getJsTopicMessageControllerFromJsTopicControls");
JsTopicMessageController jtmc = mock(JsTopicMessageController.class);
Instance select = mock(Instance.class);
when(topicMessageController.select(any(JsTopicCtrlsAnnotationLiteral.class))).thenReturn(select);
when(select.isUnsatisfied()).thenReturn(Boolean.TRUE).thenReturn(Boolean.FALSE);
doReturn(jtmc).when(instance).getJsTopicMessageControllerFromIterable(eq(TOPIC), any(Instance.class));
JsTopicMessageController result = instance.getJsTopicMessageControllerFromJsTopicControls(TOPIC);
assertThat(result).isNull();
result = instance.getJsTopicMessageControllerFromJsTopicControls(TOPIC);
assertThat(result).isEqualTo(jtmc);
}
示例11: checkAccessTopicFromJsTopicControlsTest
import javax.enterprise.inject.Instance; //导入依赖的package包/类
/**
* Test of checkAccessTopicFromJsTopicAccessControllers method, of class.
* @throws java.lang.IllegalAccessException
*/
@Test(expected = IllegalAccessException.class)
public void checkAccessTopicFromJsTopicControlsTest() throws IllegalAccessException {
System.out.println("checkAccessTopicFromJsTopicControls");
UserContext userContext = mock(UserContext.class);
Instance instances = mock(Instance.class);
when(topicAccessController.select(eq(new JsTopicCtrlsAnnotationLiteral()))).thenReturn(instances);
when(instances.isUnsatisfied()).thenReturn(Boolean.TRUE).thenReturn(Boolean.FALSE);
doReturn(Boolean.TRUE).doReturn(Boolean.FALSE).doThrow(IllegalAccessException.class).when(instance).checkAccessTopicFromJsTopicAccessControllers(eq(userContext), eq(TOPIC1), eq(instances));
boolean result = instance.checkAccessTopicFromJsTopicControls(userContext, TOPIC1);
assertThat(result).isFalse();
result = instance.checkAccessTopicFromJsTopicControls(userContext, TOPIC1);
assertThat(result).isTrue();
result = instance.checkAccessTopicFromJsTopicControls(userContext, TOPIC1);
assertThat(result).isFalse();
instance.checkAccessTopicFromJsTopicControls(userContext, TOPIC1);
}
示例12: getTestServlet
import javax.enterprise.inject.Instance; //导入依赖的package包/类
protected AbstractLightblueProxyServlet getTestServlet(CloseableHttpClient httpClient,
LightblueClientConfiguration clientConfig, final String serviceUri,
ServletConfig servletConfig) throws ServletException {
Instance<LightblueClientConfiguration> instance = new StubInstance<>(clientConfig);
AbstractLightblueProxyServlet servlet;
servlet = new AbstractLightblueProxyServlet(httpClient, instance) {
@Override
protected String serviceUriForRequest(HttpServletRequest request) throws ServletException {
return serviceUri + servicePathForRequest(request);
}
;
};
if (servletConfig == null) {
servlet.init();
} else {
servlet.init(servletConfig);
}
return servlet;
}
示例13: asCodeGrant
import javax.enterprise.inject.Instance; //导入依赖的package包/类
public AuthorizationCodeGrant asCodeGrant(Instance<AbstractAuthorizationGrant> grantInstance) {
AuthorizationCodeGrant grant = grantInstance.select(AuthorizationCodeGrant.class).get();
grant.init(user, client, authenticationTime);
grant.setAuthorizationCode(new AuthorizationCode(authorizationCodeString, authorizationCodeCreationDate, authorizationCodeExpirationDate));
grant.setScopes(scopes);
grant.setGrantId(grantId);
grant.setSessionDn(sessionDn);
grant.setCodeChallenge(codeChallenge);
grant.setCodeChallengeMethod(codeChallengeMethod);
grant.setAcrValues(acrValues);
grant.setNonce(nonce);
grant.setClaims(claims);
return grant;
}
示例14: testByDir
import javax.enterprise.inject.Instance; //导入依赖的package包/类
@SuppressWarnings({ "unchecked" })
@Test
public void testByDir() throws TemplateProcessorException {
Instance<ProxiedParam<String>> templateDirectory = Mockito.mock(Instance.class);
ProxiedParam<String> pp = new ProxiedParam<>();
pp.setParam(Paths.get("src/test/resources/templates/").toAbsolutePath().toString());
Mockito.when(templateDirectory.isUnsatisfied()).thenReturn(Boolean.FALSE);
Mockito.when(templateDirectory.get()).thenReturn(pp);
TemplateConfigProducer producer = new TemplateConfigProducer(templateDirectory);
TemplateProcessor p = new TemplateProcessor(producer.produceConfiguration());
Assert.assertEquals("template val.", p.processTemplate("test2.ftl", null));
}
示例15: initModules
import javax.enterprise.inject.Instance; //导入依赖的package包/类
/**
* Initialise all statistics modules that are found in the system
* @param modules
*/
@Inject
protected void initModules(@Any Instance<StatisticsModule> modules) {
log.info("Apache Marmotta StatisticsService starting up ...");
this.modules = new LinkedHashMap<String,StatisticsModule>();
for(StatisticsModule module : modules) {
registerModule(module.getName(),module);
}
if(configurationService.getBooleanConfiguration("statistics.enabled",false)) {
enableAll();
} else {
disableAll();
}
}