Java 类org.springframework.core.Conventions 实例源码

项目:JRediClients    文件:RedissonGenericObjectDefinitionParser.java   
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    bd.setFactoryBeanName(element.getAttribute(
            RedissonNamespaceParserSupport.REDISSON_REF_ATTRIBUTE));
    String typeName
            = Conventions.attributeNameToPropertyName(element.getLocalName());
    bd.setFactoryMethodName("get" + StringUtils.capitalize(typeName));

    helper.addConstructorArgs(element, KEY_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, TOPIC_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, PATTERN_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, SERVICE_ATTRIBUTE,
            String.class, builder);
    helper.addConstructorArgs(element, CODEC_REF_ATTRIBUTE,
            Codec.class, builder);
    if (RDestroyable.class.isAssignableFrom(getBeanClass(element))) {
        ((AbstractBeanDefinition) bd).setDestroyMethodName("destroy");
    }
}
项目:JRediClients    文件:LocalCachedMapOptionsDecorator.java   
private void invokeTimeUnitOptions(Element element, String id, ParserContext parserContext, RedissonNamespaceParserSupport helper, String timeAttrubute, String timeUnitAttribute) {
    if (helper.hasAttribute(element, timeUnitAttribute)) {
        Assert.state(
                helper.hasAttribute(element, timeAttrubute),
                "Missing \"" + timeAttrubute + "\" attribute in \""
                + RedissonNamespaceParserSupport.LOCAL_CACHED_MAP_OPTIONS_ELEMENT
                + "\" element.");
        helper.invoker(id,
                Conventions.attributeNameToPropertyName(timeAttrubute),
                new Object[]{
                    Integer.parseInt(
                            helper.getAttribute(element, timeAttrubute)),
                    helper.getAttribute(element, timeUnitAttribute)},
                parserContext);
    }
}
项目:JRediClients    文件:RedissonDefinitionParser.java   
private void parseChildElements(Element element, String parentId, String redissonRef, BeanDefinitionBuilder redissonDef, ParserContext parserContext) {
    if (element.hasChildNodes()) {
        CompositeComponentDefinition compositeDef
                = new CompositeComponentDefinition(parentId,
                        parserContext.extractSource(element));
        parserContext.pushContainingComponent(compositeDef);
        List<Element> childElts = DomUtils.getChildElements(element);
        for (Element elt : childElts) {
            if(BeanDefinitionParserDelegate
                    .QUALIFIER_ELEMENT.equals(elt.getLocalName())) {
                continue;//parsed elsewhere
            }
            String localName = parserContext.getDelegate().getLocalName(elt);
            localName = Conventions.attributeNameToPropertyName(localName);
            if (ConfigType.contains(localName)) {
                parseConfigTypes(elt, localName, redissonDef, parserContext);
            } else if (AddressType.contains(localName)) {
                parseAddressTypes(elt, localName, redissonDef, parserContext);
            } else if (helper.isRedissonNS(elt)) {
                elt.setAttribute(REDISSON_REF, redissonRef);
                parserContext.getDelegate().parseCustomElement(elt);
            }
        }
        parserContext.popContainingComponent();
    }
}
项目:JRediClients    文件:RedissonNamespaceParserSupport.java   
public void parseAttributes(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    NamedNodeMap attributes = element.getAttributes();
    for (int x = 0; x < attributes.getLength(); x++) {
        Attr attribute = (Attr) attributes.item(x);
        if (isEligibleAttribute(attribute)) {
            String propertyName
                    = attribute.getLocalName().endsWith(REF_SUFFIX)
                            ? attribute.getLocalName()
                                    .substring(0, attribute.getLocalName()
                                            .length() - REF_SUFFIX.length())
                            : attribute.getLocalName();
            propertyName = Conventions
                    .attributeNameToPropertyName(propertyName);
            Assert.state(StringUtils.hasText(propertyName),
                    "Illegal property name returned from"
                            + " 'extractPropertyName(String)': cannot be"
                            + " null or empty.");
            if (attribute.getLocalName().endsWith(REF_SUFFIX)) {
                builder.addPropertyReference(propertyName,
                        attribute.getValue());
            } else {
                builder.addPropertyValue(propertyName, attribute.getValue());
            }
        }
    }
}
项目:gemini.blueprint    文件:ServiceParsingUtils.java   
public static boolean parseServiceProperties(Element parent, Element element, ParserContext parserContext,
        BeanDefinitionBuilder builder) {
    String name = element.getLocalName();

    if (PROPS_ID.equals(name)) {
        if (DomUtils.getChildElementsByTagName(element, BeanDefinitionParserDelegate.ENTRY_ELEMENT).size() > 0) {
            Object props = parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition());
            builder.addPropertyValue(Conventions.attributeNameToPropertyName(PROPS_ID), props);
        }
        else {
            parserContext.getReaderContext().error("Invalid service property type", element);
        }
        return true;
    }
    return false;
}
项目:lams    文件:HandlerMethodInvoker.java   
private WebDataBinder resolveModelAttribute(String attrName, MethodParameter methodParam,
        ExtendedModelMap implicitModel, NativeWebRequest webRequest, Object handler) throws Exception {

    // Bind request parameter onto object...
    String name = attrName;
    if ("".equals(name)) {
        name = Conventions.getVariableNameForParameter(methodParam);
    }
    Class<?> paramType = methodParam.getParameterType();
    Object bindObject;
    if (implicitModel.containsKey(name)) {
        bindObject = implicitModel.get(name);
    }
    else if (this.methodResolver.isSessionAttribute(name, paramType)) {
        bindObject = this.sessionAttributeStore.retrieveAttribute(webRequest, name);
        if (bindObject == null) {
            raiseSessionRequiredException("Session attribute '" + name + "' required - not found in session");
        }
    }
    else {
        bindObject = BeanUtils.instantiateClass(paramType);
    }
    WebDataBinder binder = createBinder(webRequest, bindObject, name);
    initBinder(handler, name, binder, webRequest);
    return binder;
}
项目:lams    文件:SimplePropertyNamespaceHandler.java   
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    if (node instanceof Attr) {
        Attr attr = (Attr) node;
        String propertyName = parserContext.getDelegate().getLocalName(attr);
        String propertyValue = attr.getValue();
        MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues();
        if (pvs.contains(propertyName)) {
            parserContext.getReaderContext().error("Property '" + propertyName + "' is already defined using " +
                    "both <property> and inline syntax. Only one approach may be used per property.", attr);
        }
        if (propertyName.endsWith(REF_SUFFIX)) {
            propertyName = propertyName.substring(0, propertyName.length() - REF_SUFFIX.length());
            pvs.add(Conventions.attributeNameToPropertyName(propertyName), new RuntimeBeanReference(propertyValue));
        }
        else {
            pvs.add(Conventions.attributeNameToPropertyName(propertyName), propertyValue);
        }
    }
    return definition;
}
项目:spring4-understanding    文件:RequestResponseBodyMethodProcessor.java   
/**
 * Throws MethodArgumentNotValidException if validation fails.
 * @throws HttpMessageNotReadableException if {@link RequestBody#required()}
 * is {@code true} and there is no body content or if there is no suitable
 * converter to read the content with.
 */
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    Object arg = readWithMessageConverters(webRequest, parameter, parameter.getGenericParameterType());
    String name = Conventions.getVariableNameForParameter(parameter);

    WebDataBinder binder = binderFactory.createBinder(webRequest, arg, name);
    if (arg != null) {
        validateIfApplicable(binder, parameter);
        if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) {
            throw new MethodArgumentNotValidException(parameter, binder.getBindingResult());
        }
    }
    mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());

    return arg;
}
项目:spring4-understanding    文件:AbstractDispatcherServletInitializer.java   
/**
 * Add the given filter to the ServletContext and map it to the
 * {@code DispatcherServlet} as follows:
 * <ul>
 * <li>a default filter name is chosen based on its concrete type
 * <li>the {@code asyncSupported} flag is set depending on the
 * return value of {@link #isAsyncSupported() asyncSupported}
 * <li>a filter mapping is created with dispatcher types {@code REQUEST},
 * {@code FORWARD}, {@code INCLUDE}, and conditionally {@code ASYNC} depending
 * on the return value of {@link #isAsyncSupported() asyncSupported}
 * </ul>
 * <p>If the above defaults are not suitable or insufficient, override this
 * method and register filters directly with the {@code ServletContext}.
 * @param servletContext the servlet context to register filters with
 * @param filter the filter to be registered
 * @return the filter registration
 */
protected FilterRegistration.Dynamic registerServletFilter(ServletContext servletContext, Filter filter) {
    String filterName = Conventions.getVariableName(filter);
    Dynamic registration = servletContext.addFilter(filterName, filter);
    if (registration == null) {
        int counter = -1;
        while (counter == -1 || registration == null) {
            counter++;
            registration = servletContext.addFilter(filterName + "#" + counter, filter);
            Assert.isTrue(counter < 100,
                    "Failed to register filter '" + filter + "'." +
                    "Could the same Filter instance have been registered already?");
        }
    }
    registration.setAsyncSupported(isAsyncSupported());
    registration.addMappingForServletNames(getDispatcherTypes(), false, getServletName());
    return registration;
}
项目:spring4-understanding    文件:HandlerMethodInvoker.java   
private WebDataBinder resolveModelAttribute(String attrName, MethodParameter methodParam,
        ExtendedModelMap implicitModel, NativeWebRequest webRequest, Object handler) throws Exception {

    // Bind request parameter onto object...
    String name = attrName;
    if ("".equals(name)) {
        name = Conventions.getVariableNameForParameter(methodParam);
    }
    Class<?> paramType = methodParam.getParameterType();
    Object bindObject;
    if (implicitModel.containsKey(name)) {
        bindObject = implicitModel.get(name);
    }
    else if (this.methodResolver.isSessionAttribute(name, paramType)) {
        bindObject = this.sessionAttributeStore.retrieveAttribute(webRequest, name);
        if (bindObject == null) {
            raiseSessionRequiredException("Session attribute '" + name + "' required - not found in session");
        }
    }
    else {
        bindObject = BeanUtils.instantiateClass(paramType);
    }
    WebDataBinder binder = createBinder(webRequest, bindObject, name);
    initBinder(handler, name, binder, webRequest);
    return binder;
}
项目:spring4-understanding    文件:SimplePropertyNamespaceHandler.java   
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    if (node instanceof Attr) {
        Attr attr = (Attr) node;
        String propertyName = parserContext.getDelegate().getLocalName(attr);
        String propertyValue = attr.getValue();
        MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues();
        if (pvs.contains(propertyName)) {
            parserContext.getReaderContext().error("Property '" + propertyName + "' is already defined using " +
                    "both <property> and inline syntax. Only one approach may be used per property.", attr);
        }
        if (propertyName.endsWith(REF_SUFFIX)) {
            propertyName = propertyName.substring(0, propertyName.length() - REF_SUFFIX.length());
            pvs.add(Conventions.attributeNameToPropertyName(propertyName), new RuntimeBeanReference(propertyValue));
        }
        else {
            pvs.add(Conventions.attributeNameToPropertyName(propertyName), propertyValue);
        }
    }
    return definition;
}
项目:spring    文件:SimplePropertyNamespaceHandler.java   
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    if (node instanceof Attr) {
        Attr attr = (Attr) node;
        String propertyName = parserContext.getDelegate().getLocalName(attr);
        String propertyValue = attr.getValue();
        MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues();
        if (pvs.contains(propertyName)) {
            parserContext.getReaderContext().error("Property '" + propertyName + "' is already defined using " +
                    "both <property> and inline syntax. Only one approach may be used per property.", attr);
        }
        if (propertyName.endsWith(REF_SUFFIX)) {
            propertyName = propertyName.substring(0, propertyName.length() - REF_SUFFIX.length());
            pvs.add(Conventions.attributeNameToPropertyName(propertyName), new RuntimeBeanReference(propertyValue));
        }
        else {
            pvs.add(Conventions.attributeNameToPropertyName(propertyName), propertyValue);
        }
    }
    return definition;
}
项目:class-guard    文件:RequestResponseBodyMethodProcessor.java   
/**
 * {@inheritDoc}
 * @throws MethodArgumentNotValidException if validation fails
 * @throws HttpMessageNotReadableException if {@link RequestBody#required()}
 *  is {@code true} and there is no body content or if there is no suitable
 *  converter to read the content with.
 */
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    Object argument = readWithMessageConverters(webRequest, parameter, parameter.getGenericParameterType());

    String name = Conventions.getVariableNameForParameter(parameter);
    WebDataBinder binder = binderFactory.createBinder(webRequest, argument, name);

    if (argument != null) {
        validate(binder, parameter);
    }

    mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());

    return argument;
}
项目:class-guard    文件:HandlerMethodInvoker.java   
private WebDataBinder resolveModelAttribute(String attrName, MethodParameter methodParam,
        ExtendedModelMap implicitModel, NativeWebRequest webRequest, Object handler) throws Exception {

    // Bind request parameter onto object...
    String name = attrName;
    if ("".equals(name)) {
        name = Conventions.getVariableNameForParameter(methodParam);
    }
    Class<?> paramType = methodParam.getParameterType();
    Object bindObject;
    if (implicitModel.containsKey(name)) {
        bindObject = implicitModel.get(name);
    }
    else if (this.methodResolver.isSessionAttribute(name, paramType)) {
        bindObject = this.sessionAttributeStore.retrieveAttribute(webRequest, name);
        if (bindObject == null) {
            raiseSessionRequiredException("Session attribute '" + name + "' required - not found in session");
        }
    }
    else {
        bindObject = BeanUtils.instantiateClass(paramType);
    }
    WebDataBinder binder = createBinder(webRequest, bindObject, name);
    initBinder(handler, name, binder, webRequest);
    return binder;
}
项目:class-guard    文件:SimplePropertyNamespaceHandler.java   
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    if (node instanceof Attr) {
        Attr attr = (Attr) node;
        String propertyName = parserContext.getDelegate().getLocalName(attr);
        String propertyValue = attr.getValue();
        MutablePropertyValues pvs = definition.getBeanDefinition().getPropertyValues();
        if (pvs.contains(propertyName)) {
            parserContext.getReaderContext().error("Property '" + propertyName + "' is already defined using " +
                    "both <property> and inline syntax. Only one approach may be used per property.", attr);
        }
        if (propertyName.endsWith(REF_SUFFIX)) {
            propertyName = propertyName.substring(0, propertyName.length() - REF_SUFFIX.length());
            pvs.add(Conventions.attributeNameToPropertyName(propertyName), new RuntimeBeanReference(propertyValue));
        }
        else {
            pvs.add(Conventions.attributeNameToPropertyName(propertyName), propertyValue);
        }
    }
    return definition;
}
项目:spring-osgi    文件:ServiceParsingUtils.java   
public static boolean parseServiceProperties(Element parent, Element element, ParserContext parserContext,
        BeanDefinitionBuilder builder) {
    String name = element.getLocalName();

    if (PROPS_ID.equals(name)) {
        if (DomUtils.getChildElementsByTagName(element, BeanDefinitionParserDelegate.ENTRY_ELEMENT).size() > 0) {
            Object props = parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition());
            builder.addPropertyValue(Conventions.attributeNameToPropertyName(PROPS_ID), props);
        }
        else {
            parserContext.getReaderContext().error("Invalid service property type", element);
        }
        return true;
    }
    return false;
}
项目:JRediClients    文件:RedissonMultiLockDefinitionParser.java   
@Override
protected String getBeanClassName(Element element) {
    String elementName
            = Conventions.attributeNameToPropertyName(
                    element.getLocalName());
    return RedissonNamespaceParserSupport.IMPL_CLASS_PATH_PREFIX
            + StringUtils.capitalize(elementName);
}
项目:JRediClients    文件:RedissonGenericObjectDefinitionParser.java   
@Override
protected Class<?> getBeanClass(Element element) {
    String elementName
            = Conventions.attributeNameToPropertyName(
                    element.getLocalName());
    try {
        return Class.forName(RedissonNamespaceParserSupport.API_CLASS_PATH_PREFIX
                + (StringUtils.capitalize(FAIL_LOCK.equals(elementName)
                        ? "lock"
                        : elementName)));
    } catch (ClassNotFoundException ex) {
        throw new IllegalArgumentException(ex);
    }
}
项目:JRediClients    文件:RedissonReadAndWriteLockDefinitionParser.java   
@Override
protected void parseNested(Element element, ParserContext parserContext, BeanDefinitionBuilder builder, BeanDefinition bd) {
    bd.setFactoryBeanName(element.getAttribute(
            RedissonNamespaceParserSupport.READ_WRITE_LOCK_REF_ATTRIBUTE));
    String typeName
            = Conventions.attributeNameToPropertyName(element.getLocalName());
    bd.setFactoryMethodName(typeName);
}
项目:lams    文件:HandlerMethodInvoker.java   
protected final void addReturnValueAsModelAttribute(Method handlerMethod, Class<?> handlerType,
        Object returnValue, ExtendedModelMap implicitModel) {

    ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
    String attrName = (attr != null ? attr.value() : "");
    if ("".equals(attrName)) {
        Class<?> resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
        attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue);
    }
    implicitModel.addAttribute(attrName, returnValue);
}
项目:spring4-understanding    文件:ModelFactory.java   
/**
 * Derive the model attribute name for the given return value using one of:
 * <ol>
 *  <li>The method {@code ModelAttribute} annotation value
 *  <li>The declared return type if it is more specific than {@code Object}
 *  <li>The actual return value type
 * </ol>
 * @param returnValue the value returned from a method invocation
 * @param returnType the return type of the method
 * @return the model name, never {@code null} nor empty
 */
public static String getNameForReturnValue(Object returnValue, MethodParameter returnType) {
    ModelAttribute annotation = returnType.getMethodAnnotation(ModelAttribute.class);
    if (annotation != null && StringUtils.hasText(annotation.value())) {
        return annotation.value();
    }
    else {
        Method method = returnType.getMethod();
        Class<?> resolvedType = GenericTypeResolver.resolveReturnType(method, returnType.getContainingClass());
        return Conventions.getVariableNameForReturnType(method, resolvedType, returnValue);
    }
}
项目:spring4-understanding    文件:HandlerMethodInvoker.java   
protected final void addReturnValueAsModelAttribute(Method handlerMethod, Class<?> handlerType,
        Object returnValue, ExtendedModelMap implicitModel) {

    ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
    String attrName = (attr != null ? attr.value() : "");
    if ("".equals(attrName)) {
        Class<?> resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
        attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue);
    }
    implicitModel.addAttribute(attrName, returnValue);
}
项目:example-restful-project    文件:TeapotMappingHandler.java   
/**
 * Converts {@link TeapotMapping} to {@link Teapot} domain object. Apply
 * binding on {@link Teapot}.
 */
@Override
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    /* Read mapping from request */
    TeapotMapping mapping = (TeapotMapping) readWithMessageConverters(
            webRequest, parameter, TeapotMapping.class);
    String name = Conventions.getVariableNameForParameter(parameter);

    /* Convert mapping to domain object */
    Teapot teapot = mapper.fromMapping(mapping);

    WebDataBinder binder = binderFactory
            .createBinder(webRequest, teapot, name);

    if (teapot != null) {
        validateIfApplicable(binder, parameter);
        if (binder.getBindingResult().hasErrors() && isBindExceptionRequired(binder, parameter)) {
            throw new MethodArgumentNotValidException(parameter, binder.getBindingResult());
        }
    }

    mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());

    return teapot;
}
项目:spring-session    文件:AbstractHttpSessionApplicationInitializer.java   
/**
 * Registers the provided {@link Filter}s using default generated names,
 * {@link #getSessionDispatcherTypes()}, and {@link #isAsyncSessionSupported()}.
 *
 * @param servletContext the {@link ServletContext} to use
 * @param insertBeforeOtherFilters if true, will insert the provided {@link Filter}s
 * before other {@link Filter}s. Otherwise, will insert the {@link Filter}s after
 * other {@link Filter}s.
 * @param filters the {@link Filter}s to register
 */
private void registerFilters(ServletContext servletContext,
        boolean insertBeforeOtherFilters, Filter... filters) {
    Assert.notEmpty(filters, "filters cannot be null or empty");

    for (Filter filter : filters) {
        if (filter == null) {
            throw new IllegalArgumentException(
                    "filters cannot contain null values. Got "
                            + Arrays.asList(filters));
        }
        String filterName = Conventions.getVariableName(filter);
        registerFilter(servletContext, insertBeforeOtherFilters, filterName, filter);
    }
}
项目:class-guard    文件:HandlerMethodInvoker.java   
protected final void addReturnValueAsModelAttribute(Method handlerMethod, Class handlerType,
        Object returnValue, ExtendedModelMap implicitModel) {

    ModelAttribute attr = AnnotationUtils.findAnnotation(handlerMethod, ModelAttribute.class);
    String attrName = (attr != null ? attr.value() : "");
    if ("".equals(attrName)) {
        Class resolvedType = GenericTypeResolver.resolveReturnType(handlerMethod, handlerType);
        attrName = Conventions.getVariableNameForReturnType(handlerMethod, resolvedType, returnValue);
    }
    implicitModel.addAttribute(attrName, returnValue);
}
项目:spring-cloud-aws    文件:AmazonRdsDataSourceBeanDefinitionParser.java   
@Override
protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder datasourceBuilder = getBeanDefinitionBuilderForDataSource(element);

    //Constructor (mandatory) args
    String amazonRdsClientBeanName = getCustomClientOrDefaultClientBeanName(element, parserContext, "amazon-rds", AMAZON_RDS_CLIENT_CLASS_NAME);
    datasourceBuilder.addConstructorArgReference(amazonRdsClientBeanName);
    datasourceBuilder.addConstructorArgValue(element.getAttribute(DB_INSTANCE_IDENTIFIER));
    datasourceBuilder.addConstructorArgValue(element.getAttribute(PASSWORD));

    //optional args
    if (StringUtils.hasText(element.getAttribute(USERNAME))) {
        datasourceBuilder.addPropertyValue(USERNAME, element.getAttribute(USERNAME));
    }

    if (StringUtils.hasText(element.getAttribute(DATABASE_NAME))) {
        datasourceBuilder.addPropertyValue(Conventions.attributeNameToPropertyName(DATABASE_NAME), element.getAttribute(DATABASE_NAME));
    }

    datasourceBuilder.addPropertyValue("dataSourceFactory", createDataSourceFactoryBeanDefinition(element));

    //Register registry to enable cloud formation support
    String resourceResolverBeanName = GlobalBeanDefinitionUtils.retrieveResourceIdResolverBeanName(parserContext.getRegistry());
    datasourceBuilder.addPropertyReference("resourceIdResolver", resourceResolverBeanName);

    registerUserTagsMapIfNecessary(element, parserContext, amazonRdsClientBeanName);

    return datasourceBuilder.getBeanDefinition();
}
项目:spring-cloud-aws    文件:AmazonRdsRetryInterceptorBeanDefinitionParser.java   
/**
 * Builds the RetryOperation {@link BeanDefinition} with its collaborators
 *
 * @param element
 *         - <code>retry-interceptor Element</code>
 * @param parserContext
 *         - ParserContext used to query the {@link org.springframework.beans.factory.support.BeanDefinitionRegistry}
 * @return Configured but non registered bean definition
 */
private static BeanDefinition buildRetryOperationDefinition(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(RETRY_OPERATIONS_CLASS_NAME);
    builder.addPropertyValue("retryPolicy", buildRetryPolicyDefinition(element, parserContext));

    if (StringUtils.hasText(element.getAttribute(BACK_OFF_POLICY))) {
        String backOffPolicyBeanName = element.getAttribute(BACK_OFF_POLICY);
        builder.addPropertyReference(Conventions.attributeNameToPropertyName(BACK_OFF_POLICY), backOffPolicyBeanName);
    }

    return builder.getBeanDefinition();
}
项目:spring-cloud-aws    文件:AmazonRdsRetryInterceptorBeanDefinitionParser.java   
private static BeanDefinition buildSQLRetryPolicy(Element element) {
    BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(SqlRetryPolicy.class);
    if (StringUtils.hasText(element.getAttribute(MAX_NUMBER_OF_RETRIES))) {
        beanDefinitionBuilder.addPropertyValue(Conventions.attributeNameToPropertyName(MAX_NUMBER_OF_RETRIES), element.getAttribute(MAX_NUMBER_OF_RETRIES));
    }
    return beanDefinitionBuilder.getBeanDefinition();
}
项目:spring-cloud-aws    文件:ContextResourceLoaderBeanDefinitionParser.java   
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    builder.addConstructorArgReference(getCustomClientOrDefaultClientBeanName(element, parserContext, "amazon-s3", AMAZON_S3_CLIENT_CLASS_NAME));

    if (StringUtils.hasText(element.getAttribute("task-executor"))) {
        builder.addPropertyReference(Conventions.attributeNameToPropertyName("task-executor"),
                element.getAttribute("task-executor"));
    }
}
项目:JRediClients    文件:RedissonNamespaceParserSupport.java   
public String getName(Node node) {
    return Conventions.attributeNameToPropertyName(node.getLocalName());
}
项目:gemini.blueprint    文件:ServiceBeanDefinitionParser.java   
protected BeanDefinition parseListener(ParserContext context, Element element, BeanDefinitionBuilder builder) {

        // filter elements
        NodeList nl = element.getChildNodes();

        // wrapped object
        Object target = null;
        // target bean name (used for cycles)
        String targetName = null;

        // discover if we have listener with ref and nested bean declaration
        for (int i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (node instanceof Element) {
                Element nestedDefinition = (Element) node;
                // check shortcut on the parent
                if (element.hasAttribute(REF))
                    context.getReaderContext().error(
                            "nested bean declaration is not allowed if 'ref' attribute has been specified",
                            nestedDefinition);

                target = parsePropertySubElement(context, nestedDefinition, builder.getBeanDefinition());
                // if this is a bean reference (nested <ref>), extract the name
                if (target instanceof RuntimeBeanReference) {
                    targetName = ((RuntimeBeanReference) target).getBeanName();
                }
            }
        }

        // extract registration/unregistration attributes from
        // <osgi:registration-listener>
        MutablePropertyValues vals = new MutablePropertyValues();

        NamedNodeMap attrs = element.getAttributes();
        for (int x = 0; x < attrs.getLength(); x++) {
            Attr attribute = (Attr) attrs.item(x);
            String name = attribute.getLocalName();

            if (REF.equals(name))
                targetName = attribute.getValue();
            else {
                vals.addPropertyValue(Conventions.attributeNameToPropertyName(name), attribute.getValue());
            }

        }

        // create serviceListener wrapper
        RootBeanDefinition wrapperDef = new RootBeanDefinition(OsgiServiceRegistrationListenerAdapter.class);

        // set the target name (if we have one)
        if (targetName != null) {
            vals.addPropertyValue(TARGET_BEAN_NAME_PROP, targetName);
        }
        // else set the actual target
        else {
            vals.addPropertyValue(TARGET_PROP, target);
        }

        wrapperDef.setPropertyValues(vals);

        return wrapperDef;

    }
项目:gemini.blueprint    文件:ConventionsCallback.java   
public boolean process(Element parent, Attr attribute, BeanDefinitionBuilder builder) {
    String name = attribute.getLocalName();
    String propertyName = Conventions.attributeNameToPropertyName(name);
    builder.addPropertyValue(propertyName, attribute.getValue());
    return true;
}
项目:gemini.blueprint    文件:ServiceParsingUtils.java   
public static BeanDefinition parseListener(ParserContext context, Element element, BeanDefinitionBuilder builder) {

        // filter elements
        NodeList nl = element.getChildNodes();

        // wrapped object
        Object target = null;
        // target bean name (used for cycles)
        String targetName = null;

        // discover if we have listener with ref and nested bean declaration
        for (int i = 0; i < nl.getLength(); i++) {
            Node node = nl.item(i);
            if (node instanceof Element) {
                Element nestedDefinition = (Element) node;
                // check shortcut on the parent
                if (element.hasAttribute(REF))
                    context.getReaderContext().error(
                        "nested bean declaration is not allowed if 'ref' attribute has been specified",
                        nestedDefinition);

                target = context.getDelegate().parsePropertySubElement(nestedDefinition, builder.getBeanDefinition());
                // if this is a bean reference (nested <ref>), extract the name
                if (target instanceof RuntimeBeanReference) {
                    targetName = ((RuntimeBeanReference) target).getBeanName();
                }
            }
        }

        // extract registration/unregistration attributes from
        // <osgi:registration-listener>
        BeanDefinitionBuilder localBuilder = BeanDefinitionBuilder.rootBeanDefinition(OsgiServiceRegistrationListenerAdapter.class);
        localBuilder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

        NamedNodeMap attrs = element.getAttributes();
        for (int x = 0; x < attrs.getLength(); x++) {
            Attr attribute = (Attr) attrs.item(x);
            String name = attribute.getLocalName();

            if (REF.equals(name))
                targetName = attribute.getValue();
            else
                localBuilder.addPropertyValue(Conventions.attributeNameToPropertyName(name), attribute.getValue());
        }

        // set the target name (if we have one)
        if (targetName != null)
            localBuilder.addPropertyValue(TARGET_BEAN_NAME_PROP, targetName);
        // else set the actual target
        else
            localBuilder.addPropertyValue(TARGET_PROP, target);

        return localBuilder.getBeanDefinition();
    }
项目:lams    文件:SimpleConstructorNamespaceHandler.java   
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    if (node instanceof Attr) {
        Attr attr = (Attr) node;
        String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr));
        String argValue = StringUtils.trimWhitespace(attr.getValue());

        ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues();
        boolean ref = false;

        // handle -ref arguments
        if (argName.endsWith(REF_SUFFIX)) {
            ref = true;
            argName = argName.substring(0, argName.length() - REF_SUFFIX.length());
        }

        ValueHolder valueHolder = new ValueHolder(ref ? new RuntimeBeanReference(argValue) : argValue);
        valueHolder.setSource(parserContext.getReaderContext().extractSource(attr));

        // handle "escaped"/"_" arguments
        if (argName.startsWith(DELIMITER_PREFIX)) {
            String arg = argName.substring(1).trim();

            // fast default check
            if (!StringUtils.hasText(arg)) {
                cvs.addGenericArgumentValue(valueHolder);
            }
            // assume an index otherwise
            else {
                int index = -1;
                try {
                    index = Integer.parseInt(arg);
                } catch (NumberFormatException ex) {
                    parserContext.getReaderContext().error(
                            "Constructor argument '" + argName + "' specifies an invalid integer", attr);
                }
                if (index < 0) {
                    parserContext.getReaderContext().error(
                            "Constructor argument '" + argName + "' specifies a negative index", attr);
                }

                if (cvs.hasIndexedArgumentValue(index)){
                    parserContext.getReaderContext().error(
                            "Constructor argument '" + argName + "' with index "+ index+" already defined using <constructor-arg>." +
                            " Only one approach may be used per argument.", attr);
                }

                cvs.addIndexedArgumentValue(index, valueHolder);
            }
        }
        // no escaping -> ctr name
        else {
            String name = Conventions.attributeNameToPropertyName(argName);
            if (containsArgWithName(name, cvs)){
                parserContext.getReaderContext().error(
                        "Constructor argument '" + argName + "' already defined using <constructor-arg>." +
                        " Only one approach may be used per argument.", attr);
            }
            valueHolder.setName(Conventions.attributeNameToPropertyName(argName));
            cvs.addGenericArgumentValue(valueHolder);
        }
    }
    return definition;
}
项目:spring4-understanding    文件:StatusResultMatchersTests.java   
private Method getMethodForHttpStatus(HttpStatus status) throws NoSuchMethodException {
    String name = status.name().toLowerCase().replace("_", "-");
    name = "is" + StringUtils.capitalize(Conventions.attributeNameToPropertyName(name));
    return StatusResultMatchers.class.getMethod(name);
}
项目:spring4-understanding    文件:SimpleConstructorNamespaceHandler.java   
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    if (node instanceof Attr) {
        Attr attr = (Attr) node;
        String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr));
        String argValue = StringUtils.trimWhitespace(attr.getValue());

        ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues();
        boolean ref = false;

        // handle -ref arguments
        if (argName.endsWith(REF_SUFFIX)) {
            ref = true;
            argName = argName.substring(0, argName.length() - REF_SUFFIX.length());
        }

        ValueHolder valueHolder = new ValueHolder(ref ? new RuntimeBeanReference(argValue) : argValue);
        valueHolder.setSource(parserContext.getReaderContext().extractSource(attr));

        // handle "escaped"/"_" arguments
        if (argName.startsWith(DELIMITER_PREFIX)) {
            String arg = argName.substring(1).trim();

            // fast default check
            if (!StringUtils.hasText(arg)) {
                cvs.addGenericArgumentValue(valueHolder);
            }
            // assume an index otherwise
            else {
                int index = -1;
                try {
                    index = Integer.parseInt(arg);
                }
                catch (NumberFormatException ex) {
                    parserContext.getReaderContext().error(
                            "Constructor argument '" + argName + "' specifies an invalid integer", attr);
                }
                if (index < 0) {
                    parserContext.getReaderContext().error(
                            "Constructor argument '" + argName + "' specifies a negative index", attr);
                }

                if (cvs.hasIndexedArgumentValue(index)){
                    parserContext.getReaderContext().error(
                            "Constructor argument '" + argName + "' with index "+ index+" already defined using <constructor-arg>." +
                            " Only one approach may be used per argument.", attr);
                }

                cvs.addIndexedArgumentValue(index, valueHolder);
            }
        }
        // no escaping -> ctr name
        else {
            String name = Conventions.attributeNameToPropertyName(argName);
            if (containsArgWithName(name, cvs)){
                parserContext.getReaderContext().error(
                        "Constructor argument '" + argName + "' already defined using <constructor-arg>." +
                        " Only one approach may be used per argument.", attr);
            }
            valueHolder.setName(Conventions.attributeNameToPropertyName(argName));
            cvs.addGenericArgumentValue(valueHolder);
        }
    }
    return definition;
}
项目:nbone    文件:JsonRequestBodyMethodProcessor.java   
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer,
        NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {

    Object argument = readWithMessageConverters(webRequest, parameter, parameter.getGenericParameterType());

    String name = Conventions.getVariableNameForParameter(parameter);
    WebDataBinder binder = binderFactory.createBinder(webRequest, argument, name);

    if (argument != null) {
        validate(binder, parameter);
    }

    mavContainer.addAttribute(BindingResult.MODEL_KEY_PREFIX + name, binder.getBindingResult());

    return argument;
}
项目:spring    文件:SimpleConstructorNamespaceHandler.java   
@Override
public BeanDefinitionHolder decorate(Node node, BeanDefinitionHolder definition, ParserContext parserContext) {
    if (node instanceof Attr) {
        Attr attr = (Attr) node;
        String argName = StringUtils.trimWhitespace(parserContext.getDelegate().getLocalName(attr));
        String argValue = StringUtils.trimWhitespace(attr.getValue());

        ConstructorArgumentValues cvs = definition.getBeanDefinition().getConstructorArgumentValues();
        boolean ref = false;

        // handle -ref arguments
        if (argName.endsWith(REF_SUFFIX)) {
            ref = true;
            argName = argName.substring(0, argName.length() - REF_SUFFIX.length());
        }

        ValueHolder valueHolder = new ValueHolder(ref ? new RuntimeBeanReference(argValue) : argValue);
        valueHolder.setSource(parserContext.getReaderContext().extractSource(attr));

        // handle "escaped"/"_" arguments
        if (argName.startsWith(DELIMITER_PREFIX)) {
            String arg = argName.substring(1).trim();

            // fast default check
            if (!StringUtils.hasText(arg)) {
                cvs.addGenericArgumentValue(valueHolder);
            }
            // assume an index otherwise
            else {
                int index = -1;
                try {
                    index = Integer.parseInt(arg);
                }
                catch (NumberFormatException ex) {
                    parserContext.getReaderContext().error(
                            "Constructor argument '" + argName + "' specifies an invalid integer", attr);
                }
                if (index < 0) {
                    parserContext.getReaderContext().error(
                            "Constructor argument '" + argName + "' specifies a negative index", attr);
                }

                if (cvs.hasIndexedArgumentValue(index)){
                    parserContext.getReaderContext().error(
                            "Constructor argument '" + argName + "' with index "+ index+" already defined using <constructor-arg>." +
                            " Only one approach may be used per argument.", attr);
                }

                cvs.addIndexedArgumentValue(index, valueHolder);
            }
        }
        // no escaping -> ctr name
        else {
            String name = Conventions.attributeNameToPropertyName(argName);
            if (containsArgWithName(name, cvs)){
                parserContext.getReaderContext().error(
                        "Constructor argument '" + argName + "' already defined using <constructor-arg>." +
                        " Only one approach may be used per argument.", attr);
            }
            valueHolder.setName(Conventions.attributeNameToPropertyName(argName));
            cvs.addGenericArgumentValue(valueHolder);
        }
    }
    return definition;
}
项目:xap-openspaces    文件:GigaMapBeanDefinitionParser.java   
protected String extractPropertyName(String attributeName) {
    return Conventions.attributeNameToPropertyName(attributeName);
}
项目:xap-openspaces    文件:DistributedTxManagerBeanDefinitionParser.java   
protected String extractPropertyName(String attributeName) {
    return Conventions.attributeNameToPropertyName(attributeName);
}