Search in sources :

Example 21 with Resource

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);
            }
        }
    }
}
Also used : Field(java.lang.reflect.Field) Resource(javax.annotation.Resource) ContextResource(org.apache.catalina.deploy.ContextResource)

Example 22 with Resource

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);
        }
    }
}
Also used : Resource(javax.annotation.Resource) ContextResource(org.apache.catalina.deploy.ContextResource) DeclareRoles(javax.annotation.security.DeclareRoles) Resources(javax.annotation.Resources)

Example 23 with Resource

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);
    }
}
Also used : BeanUtil(org.codelibs.core.beans.util.BeanUtil) EntityRowHandler(org.dbflute.bhv.readable.EntityRowHandler) Constants(org.codelibs.fess.Constants) ElevateWordPager(org.codelibs.fess.app.pager.ElevateWordPager) SearchEngineClient(org.codelibs.fess.es.client.SearchEngineClient) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) LabelType(org.codelibs.fess.es.config.exentity.LabelType) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) StreamUtil.split(org.codelibs.core.stream.StreamUtil.split) PagingResultBean(org.dbflute.cbean.result.PagingResultBean) LabelTypeBhv(org.codelibs.fess.es.config.exbhv.LabelTypeBhv) ElevateWordBhv(org.codelibs.fess.es.config.exbhv.ElevateWordBhv) ElevateWordCB(org.codelibs.fess.es.config.cbean.ElevateWordCB) ElevateWordToLabel(org.codelibs.fess.es.config.exentity.ElevateWordToLabel) StreamUtil.stream(org.codelibs.core.stream.StreamUtil.stream) OptionalEntity(org.dbflute.optional.OptionalEntity) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) CsvWriter(com.orangesignal.csv.CsvWriter) IOException(java.io.IOException) Reader(java.io.Reader) Collectors(java.util.stream.Collectors) CsvConfig(com.orangesignal.csv.CsvConfig) List(java.util.List) Logger(org.apache.logging.log4j.Logger) ComponentUtil(org.codelibs.fess.util.ComponentUtil) ElevateWordToLabelBhv(org.codelibs.fess.es.config.exbhv.ElevateWordToLabelBhv) Writer(java.io.Writer) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) LogManager(org.apache.logging.log4j.LogManager) CsvReader(com.orangesignal.csv.CsvReader) CsvWriter(com.orangesignal.csv.CsvWriter) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ElevateWord(org.codelibs.fess.es.config.exentity.ElevateWord) PermissionHelper(org.codelibs.fess.helper.PermissionHelper) ArrayList(java.util.ArrayList) List(java.util.List) CsvConfig(com.orangesignal.csv.CsvConfig) StringUtil(org.codelibs.core.lang.StringUtil)

Example 24 with Resource

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);
    }
}
Also used : CsvReader(com.orangesignal.csv.CsvReader) CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) BeanUtil(org.codelibs.core.beans.util.BeanUtil) EntityRowHandler(org.dbflute.bhv.readable.EntityRowHandler) Constants(org.codelibs.fess.Constants) FessSystemException(org.codelibs.fess.exception.FessSystemException) CrawlingInfoBhv(org.codelibs.fess.es.config.exbhv.CrawlingInfoBhv) ListResultBean(org.dbflute.cbean.result.ListResultBean) LocalDateTime(java.time.LocalDateTime) SimpleDateFormat(java.text.SimpleDateFormat) ArrayList(java.util.ArrayList) FessConfig(org.codelibs.fess.mylasta.direction.FessConfig) CrawlingInfoParam(org.codelibs.fess.es.config.exentity.CrawlingInfoParam) PagingResultBean(org.dbflute.cbean.result.PagingResultBean) DateFormat(java.text.DateFormat) CrawlingInfoPager(org.codelibs.fess.app.pager.CrawlingInfoPager) OptionalEntity(org.dbflute.optional.OptionalEntity) CrawlingInfoParamBhv(org.codelibs.fess.es.config.exbhv.CrawlingInfoParamBhv) Resource(javax.annotation.Resource) StringUtil(org.codelibs.core.lang.StringUtil) CsvWriter(com.orangesignal.csv.CsvWriter) Set(java.util.Set) IOException(java.io.IOException) Reader(java.io.Reader) CoreLibConstants(org.codelibs.core.CoreLibConstants) Collectors(java.util.stream.Collectors) CrawlingInfoCB(org.codelibs.fess.es.config.cbean.CrawlingInfoCB) CsvConfig(com.orangesignal.csv.CsvConfig) List(java.util.List) Logger(org.apache.logging.log4j.Logger) CrawlingInfo(org.codelibs.fess.es.config.exentity.CrawlingInfo) ComponentUtil(org.codelibs.fess.util.ComponentUtil) DateTimeFormatter(java.time.format.DateTimeFormatter) Writer(java.io.Writer) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) CsvReader(com.orangesignal.csv.CsvReader) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) CsvConfig(com.orangesignal.csv.CsvConfig) IOException(java.io.IOException) SimpleDateFormat(java.text.SimpleDateFormat) CrawlingInfoParam(org.codelibs.fess.es.config.exentity.CrawlingInfoParam) FessSystemException(org.codelibs.fess.exception.FessSystemException) IOException(java.io.IOException)

Example 25 with Resource

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);
}
Also used : Resource(javax.annotation.Resource)

Aggregations

Resource (javax.annotation.Resource)56 Collectors (java.util.stream.Collectors)22 Set (java.util.Set)20 List (java.util.List)18 Subject (alien4cloud.security.Subject)17 Sets (com.google.common.collect.Sets)17 Arrays (java.util.Arrays)17 ArrayUtils (org.apache.commons.lang3.ArrayUtils)15 IGenericSearchDAO (alien4cloud.dao.IGenericSearchDAO)14 ApplicationEnvironmentService (alien4cloud.application.ApplicationEnvironmentService)12 ApplicationEnvironment (alien4cloud.model.application.ApplicationEnvironment)12 Audit (alien4cloud.audit.annotation.Audit)11 ResourcePermissionService (alien4cloud.authorization.ResourcePermissionService)11 RestResponse (alien4cloud.rest.model.RestResponse)11 RestResponseBuilder (alien4cloud.rest.model.RestResponseBuilder)11 ApplicationEnvironmentAuthorizationUpdateRequest (alien4cloud.rest.orchestrator.model.ApplicationEnvironmentAuthorizationUpdateRequest)11 ApiOperation (io.swagger.annotations.ApiOperation)11 IOException (java.io.IOException)11 MediaType (org.springframework.http.MediaType)11 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)11