use of javax.annotation.Resource in project tomcat70 by apache.
the class WebAnnotationSet method loadFieldsAnnotation.
protected static void loadFieldsAnnotation(Context context, Class<?> clazz) {
// Initialize the annotations
Field[] fields = Introspection.getDeclaredFields(clazz);
if (fields != null && fields.length > 0) {
for (Field field : fields) {
Resource annotation = field.getAnnotation(Resource.class);
if (annotation != null) {
String defaultName = clazz.getName() + SEPARATOR + field.getName();
Class<?> defaultType = field.getType();
addResource(context, annotation, defaultName, defaultType);
}
}
}
}
use of javax.annotation.Resource in project tomcat70 by apache.
the class WebAnnotationSet method loadClassAnnotation.
/**
* Process the annotations on a context for a given className.
*
* @param context The context which will have its annotations processed
* @param clazz The class to examine for Servlet annotations
*/
protected static void loadClassAnnotation(Context context, Class<?> clazz) {
/* Process Resource annotation.
* Ref JSR 250
*/
Resource resourceAnnotation = clazz.getAnnotation(Resource.class);
if (resourceAnnotation != null) {
addResource(context, resourceAnnotation);
}
/* Process Resources annotation.
* Ref JSR 250
*/
Resources resourcesAnnotation = clazz.getAnnotation(Resources.class);
if (resourcesAnnotation != null && resourcesAnnotation.value() != null) {
for (Resource resource : resourcesAnnotation.value()) {
addResource(context, resource);
}
}
/* Process EJB annotation.
* Ref JSR 224, equivalent to the ejb-ref or ejb-local-ref
* element in the deployment descriptor.
{
EJB annotation = clazz.getAnnotation(EJB.class);
if (annotation != null) {
if ((annotation.mappedName().length() == 0)
|| annotation.mappedName().equals("Local")) {
ContextLocalEjb ejb = new ContextLocalEjb();
ejb.setName(annotation.name());
ejb.setType(annotation.beanInterface().getCanonicalName());
ejb.setDescription(annotation.description());
ejb.setHome(annotation.beanName());
context.getNamingResources().addLocalEjb(ejb);
} else if (annotation.mappedName().equals("Remote")) {
ContextEjb ejb = new ContextEjb();
ejb.setName(annotation.name());
ejb.setType(annotation.beanInterface().getCanonicalName());
ejb.setDescription(annotation.description());
ejb.setHome(annotation.beanName());
context.getNamingResources().addEjb(ejb);
}
}
}
*/
/* Process WebServiceRef annotation.
* Ref JSR 224, equivalent to the service-ref element in
* the deployment descriptor.
* The service-ref registration is not implemented
{
WebServiceRef annotation = clazz
.getAnnotation(WebServiceRef.class);
if (annotation != null) {
ContextService service = new ContextService();
service.setName(annotation.name());
service.setWsdlfile(annotation.wsdlLocation());
service.setType(annotation.type().getCanonicalName());
if (annotation.value() == null)
service.setServiceinterface(annotation.type()
.getCanonicalName());
if (annotation.type().getCanonicalName().equals("Service"))
service.setServiceinterface(annotation.type()
.getCanonicalName());
if (annotation.value().getCanonicalName().equals("Endpoint"))
service.setServiceendpoint(annotation.type()
.getCanonicalName());
service.setPortlink(annotation.type().getCanonicalName());
context.getNamingResources().addService(service);
}
}
*/
/* Process DeclareRoles annotation.
* Ref JSR 250, equivalent to the security-role element in
* the deployment descriptor
*/
DeclareRoles declareRolesAnnotation = clazz.getAnnotation(DeclareRoles.class);
if (declareRolesAnnotation != null && declareRolesAnnotation.value() != null) {
for (String role : declareRolesAnnotation.value()) {
context.addSecurityRole(role);
}
}
}
use of javax.annotation.Resource in project fess by codelibs.
the class ElevateWordService method exportCsv.
public void exportCsv(final Writer writer) {
final PermissionHelper permissionHelper = ComponentUtil.getPermissionHelper();
final CsvConfig cfg = new CsvConfig(',', '"', '"');
cfg.setEscapeDisabled(false);
cfg.setQuoteDisabled(false);
@SuppressWarnings("resource") final CsvWriter csvWriter = new CsvWriter(writer, cfg);
try {
final List<String> list = new ArrayList<>();
list.add("SuggestWord");
list.add("Reading");
list.add("Permissions");
list.add("Labels");
list.add("Boost");
csvWriter.writeValues(list);
elevateWordBhv.selectCursor(cb -> cb.query().matchAll(), new EntityRowHandler<ElevateWord>() {
@Override
public void handle(final ElevateWord entity) {
final List<String> list = new ArrayList<>();
final String permissions = stream(entity.getPermissions()).get(stream -> stream.map(s -> permissionHelper.decode(s)).filter(StringUtil::isNotBlank).distinct().collect(Collectors.joining(",")));
final String labels = elevateWordToLabelBhv.selectList(cb -> cb.query().setElevateWordId_Equal(entity.getId())).stream().map(e -> labelTypeBhv.selectByPK(e.getLabelTypeId()).map(LabelType::getValue).filter(StringUtil::isNotBlank).orElse(null)).distinct().sorted().collect(Collectors.joining(","));
addToList(list, entity.getSuggestWord());
addToList(list, entity.getReading());
addToList(list, permissions);
addToList(list, labels);
addToList(list, entity.getBoost());
try {
csvWriter.writeValues(list);
} catch (final IOException e) {
logger.warn("Failed to write a sugget elevate word: {}", entity, e);
}
}
private void addToList(final List<String> list, final Object value) {
if (value == null) {
list.add(StringUtil.EMPTY);
} else {
list.add(value.toString());
}
}
});
csvWriter.flush();
} catch (final IOException e) {
logger.warn("Failed to write a sugget elevate word.", e);
}
}
use of javax.annotation.Resource in project fess by codelibs.
the class CrawlingInfoService method importCsv.
public void importCsv(final Reader reader) {
@SuppressWarnings("resource") final CsvReader csvReader = new CsvReader(reader, new CsvConfig());
final DateFormat formatter = new SimpleDateFormat(CoreLibConstants.DATE_FORMAT_ISO_8601_EXTEND);
try {
List<String> list;
// ignore header
csvReader.readValues();
while ((list = csvReader.readValues()) != null) {
try {
final String sessionId = list.get(0);
CrawlingInfo crawlingInfo = crawlingInfoBhv.selectEntity(cb -> {
cb.query().setSessionId_Equal(sessionId);
cb.specify().columnSessionId();
}).orElse(// TODO
null);
if (crawlingInfo == null) {
crawlingInfo = new CrawlingInfo();
crawlingInfo.setSessionId(list.get(0));
crawlingInfo.setCreatedTime(formatter.parse(list.get(1)).getTime());
crawlingInfoBhv.insert(crawlingInfo, op -> op.setRefreshPolicy(Constants.TRUE));
}
final CrawlingInfoParam entity = new CrawlingInfoParam();
entity.setCrawlingInfoId(crawlingInfo.getId());
entity.setKey(list.get(2));
entity.setValue(list.get(3));
entity.setCreatedTime(formatter.parse(list.get(4)).getTime());
crawlingInfoParamBhv.insert(entity, op -> op.setRefreshPolicy(Constants.TRUE));
} catch (final Exception e) {
logger.warn("Failed to read a click log: {}", list, e);
}
}
} catch (final IOException e) {
logger.warn("Failed to read a click log.", e);
}
}
use of javax.annotation.Resource in project wildfly by wildfly.
the class WeldResourceInjectionServices method getResourceName.
protected String getResourceName(InjectionPoint injectionPoint) {
Resource resource = getResourceAnnotated(injectionPoint).getAnnotation(Resource.class);
String mappedName = resource.mappedName();
String lookup = resource.lookup();
if (!lookup.isEmpty()) {
return propertyReplacer.replaceProperties(lookup);
}
if (!mappedName.isEmpty()) {
return propertyReplacer.replaceProperties(mappedName);
}
String proposedName = ResourceInjectionUtilities.getResourceName(injectionPoint, propertyReplacer);
return getEJBResourceName(injectionPoint, proposedName);
}
Aggregations