use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.
the class MapInjectionResolver method getParamField.
/**
* Get the value of the field. This value is defined in the
* annotated Param declaration. For example:
* <code>
* @Param(optional=true)
* String name="server"
* </code>
* The Field, name's value, "server" is returned.
*
* @param component command class object
* @param annotated annotated element
* @return the annotated Field value
*/
// package-private, for testing
static Object getParamField(final Object component, final AnnotatedElement annotated) {
try {
if (annotated instanceof Field) {
final Field field = (Field) annotated;
AccessController.doPrivileged(new PrivilegedAction<Object>() {
@Override
public Object run() {
field.setAccessible(true);
return null;
}
});
return ((Field) annotated).get(component);
}
} catch (Exception e) {
// return null instead.
return null;
}
return null;
}
use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.
the class ApplicationProcessor method visitConsumes.
@Override
public void visitConsumes(AnnotationModel consumes, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel && context.getWorkingOperation() != null) {
RequestBody requestBody = context.getWorkingOperation().getRequestBody();
if (requestBody != null) {
// Find the wildcard return type
if (requestBody.getContent() != null && requestBody.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD) != null) {
MediaType wildcardMedia = requestBody.getContent().getMediaType(javax.ws.rs.core.MediaType.WILDCARD);
// Copy the wildcard return type to the valid request body types
List<String> mediaTypes = consumes.getValue("value", List.class);
for (String mediaType : mediaTypes) {
requestBody.getContent().addMediaType(getContentType(mediaType), wildcardMedia);
}
// If there is an @Consumes, remove the wildcard
requestBody.getContent().removeMediaType(javax.ws.rs.core.MediaType.WILDCARD);
}
}
}
}
use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.
the class ApplicationProcessor method visitSchemaFieldOrMethod.
private void visitSchemaFieldOrMethod(AnnotationModel schemaAnnotation, AnnotatedElement fieldOrMethod, ExtensibleType<?> declaringType, String typeName, ApiContext context) {
assert (fieldOrMethod instanceof FieldModel) || (fieldOrMethod instanceof MethodModel);
Boolean hidden = schemaAnnotation.getValue("hidden", Boolean.class);
if (hidden == null || !hidden) {
// Get the schema object name
String schemaName = ModelUtils.getSchemaName(context, fieldOrMethod);
SchemaImpl schema = SchemaImpl.createInstance(schemaAnnotation, context);
// Get the parent schema object name
String parentName = null;
AnnotationModel classSchemaAnnotation = context.getAnnotationInfo(declaringType).getAnnotation(org.eclipse.microprofile.openapi.annotations.media.Schema.class);
if (classSchemaAnnotation != null) {
parentName = classSchemaAnnotation.getValue("name", String.class);
}
if (parentName == null || parentName.isEmpty()) {
parentName = declaringType.getSimpleName();
}
// Get or create the parent schema object
final Components components = context.getApi().getComponents();
Schema parentSchema = components.getSchemas().getOrDefault(parentName, new SchemaImpl());
components.addSchema(parentName, parentSchema);
Schema property = parentSchema.getProperties().getOrDefault(schemaName, new SchemaImpl());
parentSchema.addProperty(schemaName, property);
if (schema.isRequired()) {
parentSchema.addRequired(schemaName);
}
if (property.getRef() == null) {
property.setType(ModelUtils.getSchemaType(typeName, context));
}
SchemaImpl.merge(schema, property, true, context);
}
}
use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.
the class ApplicationProcessor method visitServer.
@Override
public void visitServer(AnnotationModel server, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel) {
Server newServer = new ServerImpl();
context.getWorkingOperation().addServer(newServer);
ServerImpl.merge(ServerImpl.createInstance(server, context), newServer, true);
}
}
use of org.glassfish.hk2.classmodel.reflect.AnnotatedElement in project Payara by payara.
the class ApplicationProcessor method visitSecurityRequirement.
@Override
public void visitSecurityRequirement(AnnotationModel annotation, AnnotatedElement element, ApiContext context) {
if (element instanceof MethodModel) {
String securityRequirementName = annotation.getValue("name", String.class);
SecurityRequirement securityRequirement = SecurityRequirementImpl.createInstance(annotation, context);
if (securityRequirementName != null && !securityRequirementName.isEmpty()) {
SecurityRequirement model = new SecurityRequirementImpl();
SecurityRequirementImpl.merge(securityRequirement, model);
context.getWorkingOperation().addSecurityRequirement(model);
}
}
}
Aggregations