本文整理汇总了Java中javax.enterprise.inject.spi.Annotated类的典型用法代码示例。如果您正苦于以下问题:Java Annotated类的具体用法?Java Annotated怎么用?Java Annotated使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Annotated类属于javax.enterprise.inject.spi包,在下文中一共展示了Annotated类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldDeployDefaultCamelContext
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
private boolean shouldDeployDefaultCamelContext(Set<Bean<?>> beans) {
return beans.stream()
// Is there a Camel bean with the @Default qualifier?
// Excluding internal components...
.filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
.filter(hasType(CamelContextAware.class).or(hasType(Component.class))
.or(hasType(RouteContainer.class).or(hasType(RoutesBuilder.class))))
.map(Bean::getQualifiers)
.flatMap(Set::stream)
.filter(isEqual(DEFAULT))
.findAny()
.isPresent()
// Or a bean with Camel annotations?
|| concat(camelBeans.stream().map(AnnotatedType::getFields),
camelBeans.stream().map(AnnotatedType::getMethods))
.flatMap(Set::stream)
.map(Annotated::getAnnotations)
.flatMap(Set::stream)
.filter(isAnnotationType(Consume.class).and(a -> ((Consume) a).context().isEmpty())
.or(isAnnotationType(BeanInject.class).and(a -> ((BeanInject) a).context().isEmpty()))
.or(isAnnotationType(EndpointInject.class).and(a -> ((EndpointInject) a).context().isEmpty()))
.or(isAnnotationType(Produce.class).and(a -> ((Produce) a).context().isEmpty()))
.or(isAnnotationType(PropertyInject.class).and(a -> ((PropertyInject) a).context().isEmpty())))
.findAny()
.isPresent()
// Or an injection point for Camel primitives?
|| beans.stream()
// Excluding internal components...
.filter(bean -> !bean.getBeanClass().getPackage().equals(getClass().getPackage()))
.map(Bean::getInjectionPoints)
.flatMap(Set::stream)
.filter(ip -> getRawType(ip.getType()).getName().startsWith("org.apache.camel"))
.map(InjectionPoint::getQualifiers)
.flatMap(Set::stream)
.filter(isAnnotationType(Uri.class).or(isAnnotationType(Mock.class)).or(isEqual(DEFAULT)))
.findAny()
.isPresent();
}
示例2: getAppDataValueAsString
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
@Produces
@AppData("PRODUCER")
public String getAppDataValueAsString(InjectionPoint injectionPoint) {
Annotated annotated = injectionPoint.getAnnotated();
String key = null;
String value = null;
if (annotated.isAnnotationPresent(AppData.class)) {
AppData annotation = annotated.getAnnotation(AppData.class);
key = annotation.value();
value = properties.getProperty(key);
}
if (value == null) {
throw new IllegalArgumentException("No AppData value found for key " + key);
}
return value;
}
示例3: getUserSetting
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
@Produces
@CoreSetting("PRODUCER")
public String getUserSetting(InjectionPoint injectionPoint) {
Annotated annotated = injectionPoint.getAnnotated();
if (annotated.isAnnotationPresent(CoreSetting.class)) {
String settingPath = annotated.getAnnotation(CoreSetting.class).value();
Object object = yamlCoreSettings;
String[] split = settingPath.split("\\.");
int c = 0;
while (c < split.length) {
try {
object = PropertyUtils.getProperty(object, split[c]);
c++;
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
LogManager.getLogger(getClass()).error("Failed retrieving setting " + settingPath, e);
return null;
}
}
return String.valueOf(object);
}
return null;
}
示例4: createL10nMap
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
@Produces
public I18nMap createL10nMap(InjectionPoint injectionPoint) {
Annotated annotated = injectionPoint.getAnnotated();
String baseName;
if (annotated.isAnnotationPresent(I18nData.class)) {
baseName = annotated.getAnnotation(I18nData.class).value().getSimpleName();
} else {
baseName = injectionPoint.getBean().getBeanClass().getSimpleName();
}
File langFile = new File(langBase, baseName + ".properties");
I18NMapImpl l10NMap = new I18NMapImpl(commonLang);
try (InputStream stream = new FileInputStream(langFile)) {
l10NMap.load(stream);
} catch (IOException e) {
// I18n data will be injected in all components,
// but a component is not required to have a language definition
// This implementation will return an empty I18nMap containing only able to supply common strings
}
return l10NMap;
}
示例5: pathParam
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
@Test
public void pathParam() {
final InjectionPoint ip = mock(InjectionPoint.class);
final PathParser parser = new PathParser("/{there}");
final Message msg = mock(Message.class);
final DestinationChanged dc = mock(DestinationChanged.class);
final Frame frame = mock(Frame.class);
when(msg.frame()).thenReturn(frame);
when(frame.destination()).thenReturn(Optional.of("/here"));
final Annotated annotated = mock(Annotated.class);
when(ip.getAnnotated()).thenReturn(annotated);
when(annotated.getAnnotation(PathParam.class)).thenReturn(createPathParam("there"));
final String param = PathParamProducer.pathParam(ip, parser, msg, dc);
assertEquals("here", param);
verify(msg).frame();
verify(frame).destination();
verify(ip).getAnnotated();
verify(annotated).getAnnotation(PathParam.class);
verifyNoMoreInteractions(ip, msg, dc, frame, annotated);
}
示例6: pathParam_message
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
@Test
public void pathParam_message() {
final InjectionPoint ip = mock(InjectionPoint.class);
final PathParser parser = new PathParser("/{there}");
final Message msg = mock(Message.class);
final Frame frame = mock(Frame.class);
when(msg.frame()).thenReturn(frame);
when(frame.destination()).thenReturn(Optional.of("/here"));
final Annotated annotated = mock(Annotated.class);
when(ip.getAnnotated()).thenReturn(annotated);
when(annotated.getAnnotation(PathParam.class)).thenReturn(createPathParam("there"));
final String param = PathParamProducer.pathParam(ip, parser, msg, null);
assertEquals("here", param);
verify(msg).frame();
verify(frame).destination();
verify(ip).getAnnotated();
verify(annotated).getAnnotation(PathParam.class);
verifyNoMoreInteractions(ip, msg, frame, annotated);
}
示例7: pathParam_destination
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
@Test
public void pathParam_destination() {
final InjectionPoint ip = mock(InjectionPoint.class);
final PathParser parser = new PathParser("/{there}");
final DestinationChanged dc = mock(DestinationChanged.class);
when(dc.getDestination()).thenReturn("/here");
final Annotated annotated = mock(Annotated.class);
when(ip.getAnnotated()).thenReturn(annotated);
when(annotated.getAnnotation(PathParam.class)).thenReturn(createPathParam("there"));
final String param = PathParamProducer.pathParam(ip, parser, null, dc);
assertEquals("here", param);
verify(dc).getDestination();
verify(ip).getAnnotated();
verify(annotated).getAnnotation(PathParam.class);
verifyNoMoreInteractions(ip, dc, annotated);
}
示例8: exposeLegacyLink
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
@Produces
@LegacyLink
public String exposeLegacyLink(InjectionPoint ip) {
Annotated field = ip.getAnnotated();
LegacyLink link = field.getAnnotation(LegacyLink.class);
String linkName = link.name();
if (linkName.isEmpty()) {
linkName = ip.getMember().getName().toUpperCase();
}
int portNumber = link.portNumber();
String resource = link.path();
if (resource.isEmpty()) {
return URIProvider.computeURIWithEnvironmentEntries(linkName, portNumber);
} else {
return URIProvider.computeURIWithEnvironmentEntries(linkName, portNumber, resource);
}
}
示例9: expose
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
@Produces
@Link
public String expose(InjectionPoint ip) {
Annotated field = ip.getAnnotated();
Link link = field.getAnnotation(Link.class);
String linkName = link.name();
if (linkName.isEmpty()) {
linkName = ip.getMember().getName().toUpperCase();
}
int portNumber = link.portNumber();
String resource = link.path();
if (resource.isEmpty()) {
return URIProvider.computeUri(linkName, portNumber);
} else {
return URIProvider.computeUri(linkName, portNumber, resource);
}
}
示例10: getPropertyName
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
String getPropertyName(final InjectionPoint point, final String propertyName) {
if (!propertyName.isEmpty()) {
return propertyName;
}
Member member = point.getMember();
final String name;
if (member instanceof Executable) {
Annotated annotated = point.getAnnotated();
int p = ((AnnotatedParameter<?>) annotated).getPosition();
name = member.getName() + ".arg" + p;
} else {
name = member.getName();
}
return name;
}
示例11: nameStrategy
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
private static CamelContextNameStrategy nameStrategy(Annotated annotated) {
if (annotated.isAnnotationPresent(ContextName.class)) {
return new ExplicitCamelContextNameStrategy(annotated.getAnnotation(ContextName.class).value());
} else if (annotated.isAnnotationPresent(Named.class)) {
// TODO: support stereotype with empty @Named annotation
String name = annotated.getAnnotation(Named.class).value();
if (name.isEmpty()) {
if (annotated instanceof AnnotatedField) {
name = ((AnnotatedField) annotated).getJavaMember().getName();
} else if (annotated instanceof AnnotatedMethod) {
name = ((AnnotatedMethod) annotated).getJavaMember().getName();
if (name.startsWith("get")) {
name = decapitalize(name.substring(3));
}
} else {
name = decapitalize(getRawType(annotated.getBaseType()).getSimpleName());
}
}
return new ExplicitCamelContextNameStrategy(name);
} else {
// Use a specific naming strategy for Camel CDI as the default one increments the suffix for each CDI proxy created
return new CdiCamelContextNameStrategy();
}
}
示例12: testSendObjectToTopicNotAnnotated
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
/**
* Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
*
* @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
*/
@Test
public void testSendObjectToTopicNotAnnotated() throws JsonMarshallingException {
System.out.println("sendObjectToTopic");
EventMetadata metadata = mock(EventMetadata.class);
InjectionPoint injectionPoint = mock(InjectionPoint.class);
Annotated annotated = mock(Annotated.class);
when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
when(injectionPoint.getAnnotated()).thenReturn(annotated);
when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(null);
// no JsTopicEvent
instance.sendObjectToTopic(PAYLOAD, metadata);
verify(instance, never()).sendMessageToTopic(any(MessageToClient.class));
}
示例13: testSendObjectToTopicWithoutMarshaller
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
/**
* Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
*
* @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
*/
@Test
public void testSendObjectToTopicWithoutMarshaller() throws JsonMarshallingException {
System.out.println("sendObjectToTopic");
EventMetadata metadata = mock(EventMetadata.class);
InjectionPoint injectionPoint = mock(InjectionPoint.class);
Annotated annotated = mock(Annotated.class);
JsTopicEvent jte = mock(JsTopicEvent.class);
when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
when(injectionPoint.getAnnotated()).thenReturn(annotated);
when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(null);
when(jte.value()).thenReturn(TOPIC);
// JsTopicEvent, no marshaller
instance.sendObjectToTopic(PAYLOAD, metadata);
ArgumentCaptor<MessageToClient> captureMtC = ArgumentCaptor.forClass(MessageToClient.class);
ArgumentCaptor<Object> captureObject = ArgumentCaptor.forClass(Object.class);
verify(topicsMessagesBroadcaster).sendMessageToTopic(captureMtC.capture(), captureObject.capture());
assertThat(captureMtC.getValue().getResponse()).isEqualTo(PAYLOAD);
assertThat(captureObject.getValue()).isEqualTo(PAYLOAD);
}
示例14: testSendObjectToTopicJsonPayload
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
/**
* Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
*
* @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
*/
@Test
public void testSendObjectToTopicJsonPayload() throws JsonMarshallingException {
System.out.println("sendObjectToTopic");
EventMetadata metadata = mock(EventMetadata.class);
InjectionPoint injectionPoint = mock(InjectionPoint.class);
Annotated annotated = mock(Annotated.class);
JsTopicEvent jte = mock(JsTopicEvent.class);
when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
when(injectionPoint.getAnnotated()).thenReturn(annotated);
when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(null);
when(jte.value()).thenReturn(TOPIC);
when(jte.jsonPayload()).thenReturn(true);
// JsTopicEvent, jsonPayload <,no marshaller
instance.sendObjectToTopic(PAYLOAD, metadata);
ArgumentCaptor<MessageToClient> captureMtC = ArgumentCaptor.forClass(MessageToClient.class);
ArgumentCaptor<Object> captureObject = ArgumentCaptor.forClass(Object.class);
verify(topicsMessagesBroadcaster).sendMessageToTopic(captureMtC.capture(), captureObject.capture());
assertThat(captureMtC.getValue().getJson()).isEqualTo(PAYLOAD);
assertThat(captureObject.getValue()).isEqualTo(PAYLOAD);
}
示例15: testSendObjectToTopicJsonPayloadFailed
import javax.enterprise.inject.spi.Annotated; //导入依赖的package包/类
/**
* Test of sendObjectToTopic method, of class TopicsMessagesBroadcaster.
*
* @throws org.ocelotds.marshalling.exceptions.JsonMarshallingException
*/
@Test
public void testSendObjectToTopicJsonPayloadFailed() throws JsonMarshallingException {
System.out.println("sendObjectToTopic");
EventMetadata metadata = mock(EventMetadata.class);
InjectionPoint injectionPoint = mock(InjectionPoint.class);
Annotated annotated = mock(Annotated.class);
JsTopicEvent jte = mock(JsTopicEvent.class);
when(metadata.getInjectionPoint()).thenReturn(injectionPoint);
when(injectionPoint.getAnnotated()).thenReturn(annotated);
when(annotated.getAnnotation(JsTopicEvent.class)).thenReturn(jte);
when(annotated.getAnnotation(JsonMarshaller.class)).thenReturn(null);
when(jte.value()).thenReturn(TOPIC);
when(jte.jsonPayload()).thenReturn(true);
// JsTopicEvent, jsonPayload <,no marshaller
instance.sendObjectToTopic(new Long(5), metadata);
verify(topicsMessagesBroadcaster, never()).sendMessageToTopic(any(MessageToClient.class), anyObject());
}