Example usage for org.springframework.beans.factory.config TypedStringValue getValue

List of usage examples for org.springframework.beans.factory.config TypedStringValue getValue

Introduction

In this page you can find the example usage for org.springframework.beans.factory.config TypedStringValue getValue.

Prototype

@Nullable
public String getValue() 

Source Link

Document

Return the String value.

Usage

From source file:me.springframework.di.spring.SpringConfigurationLoader.java

/**
 * Constructs a {@link MutableSource} from a source based on a literal
 * representation of a value./*from  ww w. j a  v  a 2  s .c om*/
 * 
 * @param sink
 *            The {@link Sink} configured to receive the value produced by
 *            the source.
 * @param value
 *            Spring's representation of that value.
 * @return The {@link Source} representation of the object producing that
 *         value.
 */
private static MutableSource load(Sink sink, TypedStringValue value) {
    return new MutableStringValueSource(sink, value.getValue(), value.getTargetTypeName());
}

From source file:com.jaspersoft.jasperserver.api.common.util.spring.BeanPropertyTextAppender.java

protected Object getProcessedPropertyValue(Object originalValue) {
    Object appendedValue;//from w ww.j  a  v a  2s.  c  om
    if (originalValue == null) {
        appendedValue = getAppended();
    } else {
        if (originalValue instanceof String) {
            appendedValue = originalValue + getAppended();
        } else if (originalValue instanceof TypedStringValue) {
            TypedStringValue newValue = (TypedStringValue) originalValue;
            newValue.setValue(newValue.getValue() + getAppended());

            appendedValue = newValue;
        } else {
            throw new JSException("jsexception.property.not.a.text",
                    new Object[] { getPropertyName(), getBeanName() });
        }
    }

    if (log.isInfoEnabled()) {
        log.info("Appending " + getBeanName() + "." + getPropertyName() + " with " + getAppended());
    }

    return appendedValue;
}

From source file:com.himanshu.spring.context.loader.sameconfigallcontext.bean.visitor.BeanVisitor.java

private TypedStringValue insertPrefixToProperty(TypedStringValue typedStringValue) {
    return new TypedStringValue(insertPrefixToProperty(typedStringValue.getValue()));

}

From source file:com.helpinput.spring.refresher.SessiontRefresher.java

@SuppressWarnings("unchecked")
ManagedList<Object> getManageList(DefaultListableBeanFactory dlbf, PropertyValue oldPropertyValue) {
    Set<String> oldClasses = null;

    if (oldPropertyValue != null) {
        Object value = oldPropertyValue.getValue();
        if (value != null && value instanceof ManagedList) {
            ManagedList<Object> real = (ManagedList<Object>) value;
            oldClasses = new HashSet<>(real.size() >>> 1);
            ClassLoader parentClassLoader = ClassUtils.getDefaultClassLoader();
            for (Object object : real) {
                TypedStringValue typedStringValue = (TypedStringValue) object;
                String className = typedStringValue.getValue();
                try {
                    parentClassLoader.loadClass(className);
                    oldClasses.add(className);
                } catch (ClassNotFoundException e) {
                }//w  w w  .j a  v a 2  s  . com
            }
        }
    }

    int oldClassSize = (Utils.hasLength(oldClasses) ? oldClasses.size() : 0);
    Map<String, Object> beans = dlbf.getBeansWithAnnotation(Entity.class);
    HashSet<String> totalClasses = new HashSet<>(beans.size() + oldClassSize);
    if (oldClassSize > 0) {
        totalClasses.addAll(oldClasses);
    }

    for (Object entity : beans.values()) {
        String clzName = entity.getClass().getName();
        if (!totalClasses.contains(clzName)) {
            totalClasses.add(clzName);
        }
    }

    ManagedList<Object> list = new ManagedList<>(totalClasses.size());
    for (String clzName : totalClasses) {
        TypedStringValue typedStringValue = new TypedStringValue(clzName);
        list.add(typedStringValue);
    }
    return list;
}

From source file:com.arondor.common.reflection.parser.spring.BeanPropertyParser.java

private boolean useSPEL(TypedStringValue stringValue) {
    if (!enableSPEL || stringValue == null || stringValue.getValue() == null) {
        return false;
    }//from w w w. ja va  2  s  .c o m
    String trimmedValue = stringValue.getValue().trim();
    return trimmedValue.startsWith("#{") && trimmedValue.endsWith("}");
}

From source file:net.nan21.dnet.core.presenter.descriptor.DsDefinitions.java

/**
 * Helper method to create the definition for a single given data-source.
 * /*www  .j a  v a 2s  . c  o m*/
 * @param name
 * @param factory
 * @return
 * @throws Exception
 */
private DsDefinition createDefinition(String name, ConfigurableListableBeanFactory factory) throws Exception {

    BeanDefinition beanDef = factory.getBeanDefinition(name);

    DsDefinition definition = new DsDefinition();
    definition.setName(name);

    String modelClass = null;
    String filterClass = null;
    String paramClass = null;

    String readOnly = null;

    MutablePropertyValues mpv = beanDef.getPropertyValues();

    // model class

    modelClass = ((TypedStringValue) mpv.getPropertyValue("modelClass").getValue()).getValue();
    definition.setModelClass(this.applicationContext.getClassLoader().loadClass(modelClass));

    // filter class

    if (mpv.getPropertyValue("filterClass") != null) {
        filterClass = ((TypedStringValue) mpv.getPropertyValue("filterClass").getValue()).getValue();
        definition.setFilterClass(this.applicationContext.getClassLoader().loadClass(filterClass));
    } else {
        definition.setFilterClass(this.applicationContext.getClassLoader().loadClass(modelClass));
    }

    // param-class
    if (mpv.getPropertyValue("paramClass") != null) {
        paramClass = ((TypedStringValue) mpv.getPropertyValue("paramClass").getValue()).getValue();
        definition.setParamClass(this.applicationContext.getClassLoader().loadClass(paramClass));
    }

    // other attributes

    if (mpv.contains("readOnly")) {
        readOnly = ((TypedStringValue) mpv.getPropertyValue("readOnly").getValue()).getValue();
        definition.setReadOnly(Boolean.getBoolean(readOnly));
    }

    // RPC methods

    if (mpv.contains("rpcData")) {
        @SuppressWarnings("unchecked")
        ManagedMap<TypedStringValue, Object> rpcData = (ManagedMap<TypedStringValue, Object>) mpv
                .getPropertyValue("rpcData").getValue();

        List<String> services = new ArrayList<String>();
        for (TypedStringValue tsv : rpcData.keySet()) {
            services.add(tsv.getValue());
        }
        definition.setServiceMethods(services);
    }

    if (mpv.contains("rpcFilter")) {
        @SuppressWarnings("unchecked")
        ManagedMap<TypedStringValue, Object> rpcFilter = (ManagedMap<TypedStringValue, Object>) mpv
                .getPropertyValue("rpcFilter").getValue();
        List<String> services = new ArrayList<String>();
        for (TypedStringValue tsv : rpcFilter.keySet()) {
            services.add(tsv.getValue());
        }
        definition.setServiceMethods(services);
    }
    return definition;
}

From source file:com.apporiented.spring.override.ListMergeProcessor.java

@SuppressWarnings({ "rawtypes", "unchecked" })
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    BeanDefinition bd = beanFactory.getBeanDefinition(ref);
    if (property == null) {
        //Assert.state(ListFactoryBean.class.getName().equals(bd.getBeanClassName()),
        //        "Bean [" + ref + "] must be a ListFactoryBean");

        property = "sourceList";
    }//from w  w w.j av a  2  s.  c  om

    log.debug("Adding " + values.size() + " items to " + ref + "." + property + ": " + values);

    PropertyValue pv = bd.getPropertyValues().getPropertyValue(property);
    if (pv == null) {
        // No list set on the target bean, create a new one ...
        ManagedList list = new ManagedList();
        list.addAll(values);
        bd.getPropertyValues().addPropertyValue(property, list);
    } else {
        Object value = pv.getValue();
        if (value instanceof RuntimeBeanReference) {
            RuntimeBeanReference ref = (RuntimeBeanReference) value;
            value = beanFactory.getBean(ref.getBeanName());
        } else if (value instanceof TypedStringValue) {
            TypedStringValue tsv = (TypedStringValue) value;
            ManagedList list = new ManagedList();
            list.addAll(values);
            list.add(tsv.getValue());
            bd.getPropertyValues().addPropertyValue(property, list);
            return;
        }
        Assert.isInstanceOf(List.class, value);
        List list = (List) value;
        if (append) {
            list.addAll(values);
        } else {
            for (int i = values.size() - 1; i >= 0; i--) {
                list.add(0, values.get(i));
            }
        }
    }
}

From source file:org.cloudfoundry.reconfiguration.util.StandardPropertyAugmenter.java

private Properties extractProperties(TypedStringValue value) {
    try {/*  ww w .  j a v  a 2 s  .c  om*/
        Properties properties = new Properties();
        properties.load(new StringReader(value.getValue()));
        return properties;
    } catch (IOException e) {
        throw new IllegalStateException(String.format("Error loading properties from '%s'", value), e);
    }
}

From source file:de.acosix.alfresco.mtsupport.repo.subsystems.TenantAwareSubsystemPlaceholderConfigurer.java

/**
 * {@inheritDoc}/*from   w  w w.j ava  2 s  .c  om*/
 */
@Override
protected void doProcessProperties(final ConfigurableListableBeanFactory beanFactoryToProcess,
        final StringValueResolver valueResolver) {
    final BeanDefinitionVisitor visitor = new BeanDefinitionVisitor(valueResolver) {

        /**
         * {@inheritDoc}
         */
        @Override
        protected Object resolveValue(final Object value) {
            Object result = value;

            // TODO Report bug with Spring
            // TypedStringValue may be reused as result of cloneBeanDefinition and thus should not be mutated

            if (value instanceof TypedStringValue) {
                final TypedStringValue typedStringValue = (TypedStringValue) value;
                final String stringValue = typedStringValue.getValue();
                if (stringValue != null) {
                    final String visitedString = this.resolveStringValue(stringValue);
                    if (!stringValue.equals(visitedString)) {
                        result = typedStringValue.hasTargetType()
                                ? new TypedStringValue(visitedString, typedStringValue.getTargetType())
                                : new TypedStringValue(visitedString);
                    }
                }
            } else {
                result = super.resolveValue(value);
            }

            return result;
        }
    };

    final String[] beanNames = beanFactoryToProcess.getBeanDefinitionNames();
    for (final String curName : beanNames) {
        // Check that we're not parsing our own bean definition,
        // to avoid failing on unresolvable placeholders in properties file locations.
        if (!(curName.equals(this.beanName) && beanFactoryToProcess.equals(this.beanFactory))) {
            final String tenantDomain;
            if (curName.contains(TenantBeanUtils.TENANT_BEAN_NAME_PATTERN)) {
                tenantDomain = curName.substring(curName.indexOf(TenantBeanUtils.TENANT_BEAN_NAME_PATTERN)
                        + TenantBeanUtils.TENANT_BEAN_NAME_PATTERN.length());
                LOGGER.debug("[{}] Processing bean {} for tenant domain {}", this.beanName, curName,
                        tenantDomain);
            } else {
                LOGGER.debug("[{}] Processing bean {} without tenant domain", this.beanName, curName);
                tenantDomain = null;
            }

            final BeanDefinition bd = beanFactoryToProcess.getBeanDefinition(curName);
            TENANT_CONTEXT.set(tenantDomain);
            try {
                visitor.visitBeanDefinition(bd);
            } catch (final Exception ex) {
                throw new BeanDefinitionStoreException(bd.getResourceDescription(), curName, ex.getMessage());
            } finally {
                TENANT_CONTEXT.remove();
            }
        }
    }
    LOGGER.debug("[{}] Completed processing all beans", this.beanName);

    // New in Spring 2.5: resolve placeholders in alias target names and aliases as well.
    beanFactoryToProcess.resolveAliases(valueResolver);

    // New in Spring 3.0: resolve placeholders in embedded values such as annotation attributes.
    beanFactoryToProcess.addEmbeddedValueResolver(valueResolver);

}

From source file:org.guicerecipes.spring.converter.SpringConverter.java

@SuppressWarnings("unchecked")
protected void generateBeanDefinition(ModuleGenerator generator, String name, BeanDefinition definition,
        String className) {/*from  ww w.  j a v  a 2s  .  com*/
    String shortClassName = addImport(className);
    ProduceMethod method = generator.startProvides(name, shortClassName);

    ConstructorArgumentValues constructors = definition.getConstructorArgumentValues();
    Map map = constructors.getIndexedArgumentValues();
    for (int i = 0, size = map.size(); i < size; i++) {
        ValueHolder valueHolder = (ValueHolder) map.get(i);
        if (valueHolder != null) {
            Object value = valueHolder.getValue();
            if (value instanceof TypedStringValue) {
                TypedStringValue stringValue = (TypedStringValue) value;
                String text = stringValue.getValue();
                System.out.printf("param %s=\"%s\"\n", i, text);
                String expression = null;
                String namedParameter = namedParameter(text);
                if (namedParameter != null) {
                    expression = addParameter(method, "String", namedParameter);
                } else {
                    expression = "\"" + text + "\"";
                }
                method.addConstructorExpression(expression);
            } else if (value instanceof BeanReference) {
                BeanReference reference = (BeanReference) value;
                String beanRef = reference.getBeanName();
                // TODO
                String typeName = "Object";
                String expression = addParameter(method, typeName, beanRef);
                method.addConstructorExpression(expression);
            }
        }
    }

    MutablePropertyValues propertyValues = definition.getPropertyValues();
    PropertyValue[] propertyArray = propertyValues.getPropertyValues();
    for (PropertyValue propertyValue : propertyArray) {
        String property = getSetterMethod(propertyValue);
        Object value = propertyValue.getConvertedValue();
        if (value == null) {
            value = propertyValue.getValue();
        }
        if (value instanceof BeanReference) {
            BeanReference reference = (BeanReference) value;
            String beanRef = reference.getBeanName();
            // TODO
            String typeName = "Object";
            String expression = addParameter(method, typeName, beanRef);
            method.addMethodCall("answer", getSetterMethod(propertyValue), expression);
        } else if (value instanceof BeanDefinitionHolder) {
            BeanDefinitionHolder beanDefinitionHolder = (BeanDefinitionHolder) value;
            addChildBeanDefinition(generator, method, name, propertyValue,
                    beanDefinitionHolder.getBeanDefinition());
        } else if (value instanceof ChildBeanDefinition) {
            ChildBeanDefinition childBeanDefinition = (ChildBeanDefinition) value;
            addChildBeanDefinition(generator, method, name, propertyValue, childBeanDefinition);
        } else {
            if (value instanceof TypedStringValue) {
                TypedStringValue stringValue = (TypedStringValue) value;
                value = stringValue.getValue();

            }
            String valueType = (value == null) ? null : value.getClass().getName();
            System.out.printf("property %s=%s of type %s\n", property, value, valueType);

            String expression;
            if (value instanceof String) {
                String text = (String) value;
                String namedParameter = namedParameter(text);
                if (namedParameter != null) {
                    expression = addParameter(method, "String", namedParameter);
                } else {
                    expression = "\"" + value + "\"";
                }
            } else if (value == null) {
                expression = "null";
            } else {
                expression = value.toString();
            }
            method.addMethodCall("answer", getSetterMethod(propertyValue), expression);
        }
    }
}