Here are the examples of the java api class javax.ws.rs.core.Context taken from open source projects.
1. ProviderMetadataCollector#parseAccessibleObject()
Project: wink
File: ProviderMetadataCollector.java
File: ProviderMetadataCollector.java
@Override protected Injectable parseAccessibleObject(AccessibleObject field, Type fieldType) { Context context = field.getAnnotation(Context.class); if (context != null) { return InjectableFactory.getInstance().createContextParam(GenericsUtils.getClassType(fieldType, ((Member) field).getDeclaringClass()), field.getAnnotations(), (Member) field); } return null; }
2. SessionHelperFactoryProvider#createValueFactory()
Project: commafeed
File: SessionHelperFactoryProvider.java
File: SessionHelperFactoryProvider.java
@Override protected Factory<?> createValueFactory(final Parameter parameter) { final Class<?> classType = parameter.getRawType(); Context context = parameter.getAnnotation(Context.class); if (context == null) return null; if (classType.isAssignableFrom(SessionHelper.class)) { return new SessionHelperFactory(); } else { return null; } }
3. InjectableFactory#create()
Project: wink
File: InjectableFactory.java
File: InjectableFactory.java
public Injectable create(Type genericType, Annotation[] annotations, Member member, boolean encoded, String defaultValue) { Class<?> classType = TypeFactory.type(genericType, member.getDeclaringClass()).getRawClass(); // Class<?> classType = GenericsUtils.getClassType(genericType); MatrixParam matrix = null; PathParam path = null; QueryParam query = null; HeaderParam header = null; CookieParam cookie = null; FormParam form = null; Context context = null; Injectable injectable = null; int annotationsCounter = 0; for (int i = 0; i < annotations.length; ++i) { if (annotations[i].annotationType().equals(MatrixParam.class)) { matrix = (MatrixParam) annotations[i]; ++annotationsCounter; } else if (annotations[i].annotationType().equals(PathParam.class)) { path = (PathParam) annotations[i]; ++annotationsCounter; } else if (annotations[i].annotationType().equals(QueryParam.class)) { query = (QueryParam) annotations[i]; ++annotationsCounter; } else if (annotations[i].annotationType().equals(HeaderParam.class)) { header = (HeaderParam) annotations[i]; ++annotationsCounter; } else if (annotations[i].annotationType().equals(CookieParam.class)) { cookie = (CookieParam) annotations[i]; ++annotationsCounter; } else if (annotations[i].annotationType().equals(FormParam.class)) { form = (FormParam) annotations[i]; ++annotationsCounter; } else if (annotations[i].annotationType().equals(Context.class)) { context = (Context) annotations[i]; ++annotationsCounter; } else if (annotations[i].annotationType().equals(Encoded.class)) { encoded = true; } else if (annotations[i].annotationType().equals(DefaultValue.class)) { defaultValue = ((DefaultValue) annotations[i]).value(); } } if (annotationsCounter > 1) { throw new IllegalStateException(Messages.getMessage("conflictingParameterAnnotations", //$NON-NLS-1$ member.getName())); } if (matrix != null) { injectable = createMatrixParam(matrix.value(), classType, genericType, annotations, member); } else if (path != null) { injectable = createPathParam(path.value(), classType, genericType, annotations, member); } else if (query != null) { injectable = createQueryParam(query.value(), classType, genericType, annotations, member); } else if (header != null) { injectable = createHeaderParam(header.value(), classType, genericType, annotations, member); } else if (cookie != null) { injectable = createCookieParam(cookie.value(), classType, genericType, annotations, member); } else if (form != null) { injectable = createFormParam(form.value(), classType, genericType, annotations, member); } else if (context != null) { injectable = createContextParam(classType, annotations, member); } else { injectable = createEntityParam(classType, genericType, annotations, member); } if (injectable instanceof BoundInjectable) { BoundInjectable binding = (BoundInjectable) injectable; binding.setEncoded(encoded); binding.setDefaultValue(defaultValue); } return injectable; }