Example usage for org.springframework.beans MutablePropertyValues MutablePropertyValues

List of usage examples for org.springframework.beans MutablePropertyValues MutablePropertyValues

Introduction

In this page you can find the example usage for org.springframework.beans MutablePropertyValues MutablePropertyValues.

Prototype

public MutablePropertyValues() 

Source Link

Document

Creates a new empty MutablePropertyValues object.

Usage

From source file:com.athena.peacock.agent.scheduler.quartz.BaseJob.java

/**
 * <pre>// w w w.ja  v  a  2 s.  c  o m
 *   ? ?? {@link JobExecutionContext}?  .
 * </pre>
 * @param context
 * @throws JobExecutionException
 */
public void initializingContext(JobExecutionContext context) throws JobExecutionException {
    try {
        this.context = (ApplicationContext) context.getScheduler().getContext().get(APPLICAITON_CONTEXT_KEY);

        BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(this);
        MutablePropertyValues pvs = new MutablePropertyValues();
        pvs.addPropertyValues(context.getScheduler().getContext());
        pvs.addPropertyValues(context.getMergedJobDataMap());

        resolveDependenciesOfJobObject(context, pvs);

        bw.setPropertyValues(pvs, true);
    } catch (SchedulerException ex) {
        throw new JobExecutionException(ex);
    }
}

From source file:com.seovic.validation.config.ValidationBeanDefinitionParser.java

@SuppressWarnings("unchecked")
private BeanDefinition parseValidator(Element element, ParserContext parserContext) {
    String parent = element.getAttribute("parent");
    if ("".equals(parent)) {
        parent = null;/* w w w. j  av  a 2  s.  co  m*/
    }
    String test = element.getAttribute("test");
    String when = element.getAttribute("when");
    String validateAll = element.getAttribute("validate-all");
    String context = element.getAttribute("context");
    String includeElementsErrors = element.getAttribute("include-element-errors");

    MutablePropertyValues properties = new MutablePropertyValues();
    if (StringUtils.hasText(test)) {
        properties.addPropertyValue("test", test);
    }
    if (StringUtils.hasText(when)) {
        properties.addPropertyValue("when", when);
    }
    if (StringUtils.hasText(validateAll)) {
        properties.addPropertyValue("validateAll", validateAll);
    }
    if (StringUtils.hasText(context)) {
        properties.addPropertyValue("context", context);
    }
    if (StringUtils.hasText(includeElementsErrors)) {
        properties.addPropertyValue("includeElementsErrors", includeElementsErrors);
    }
    ManagedList nestedValidators = new ManagedList();
    ManagedList actions = new ManagedList();
    for (int i = 0; i < element.getChildNodes().getLength(); i++) {
        Node child = element.getChildNodes().item(i);
        if (child != null && child instanceof Element) {
            Element childElement = (Element) child;
            if ("message".equals(childElement.getLocalName())) {
                actions.add(parseErrorMessageAction(childElement, parserContext));
            } else {
                nestedValidators.add(parseAndRegisterValidator2(childElement, parserContext));
            }
        }
    }
    if (nestedValidators.size() > 0) {
        properties.addPropertyValue("validators", nestedValidators);
    }
    if (actions.size() > 0) {
        properties.addPropertyValue("actions", actions);
    }
    String className;
    if ("required".equals(element.getLocalName())) {
        className = RequiredValidator.class.getName();
    } else if ("condition".equals(element.getLocalName())) {
        className = ConditionValidator.class.getName();
    } else if ("validator".equals(element.getLocalName())) {
        className = element.getAttribute("type");
    } else {
        className = ValidatorGroup.class.getName();
    }
    AbstractBeanDefinition validatorDefinition;
    try {
        validatorDefinition = BeanDefinitionReaderUtils.createBeanDefinition(parent, className,
                parserContext.getReaderContext().getBeanClassLoader());
    } catch (ClassNotFoundException e) {
        throw new BeanCreationException("Error occured during creation of bean definition", e);
    }
    validatorDefinition.setResource(parserContext.getReaderContext().getResource());
    validatorDefinition.setSource(parserContext.extractSource(element));
    validatorDefinition.setPropertyValues(properties);
    validatorDefinition.setLazyInit(true);
    validatorDefinition.setScope("singleton");
    return validatorDefinition;
}

From source file:org.springmodules.cache.config.AbstractMetadataAttributesParser.java

private void registerCachingInterceptor(BeanDefinitionRegistry registry,
        CacheSetupStrategyPropertySource propertySource) {

    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.addPropertyValue(propertySource.getCacheKeyGeneratorProperty());
    propertyValues.addPropertyValue(propertySource.getCacheProviderFacadeProperty());
    propertyValues.addPropertyValue(propertySource.getCachingListenersProperty());
    propertyValues.addPropertyValue(propertySource.getCachingModelsProperty());

    RootBeanDefinition cachingInterceptor = new RootBeanDefinition(MetadataCachingInterceptor.class,
            propertyValues);//  w  ww  .j av a 2s  . c o  m

    configureCachingInterceptor(propertyValues, registry);

    String beanName = BeanName.CACHING_INTERCEPTOR;
    registry.registerBeanDefinition(beanName, cachingInterceptor);
}

From source file:com.gzj.tulip.load.context.RoseWebAppContext.java

/** ?messageSourceRose? */
public static void registerMessageSourceIfNecessary(BeanDefinitionRegistry registry,
        String[] messageBaseNames) {
    if (!registry.containsBeanDefinition(MESSAGE_SOURCE_BEAN_NAME)) {
        GenericBeanDefinition messageSource = new GenericBeanDefinition();
        messageSource.setBeanClass(ReloadableResourceBundleMessageSource.class);
        MutablePropertyValues propertyValues = new MutablePropertyValues();
        propertyValues.addPropertyValue("useCodeAsDefaultMessage", true);
        propertyValues.addPropertyValue("defaultEncoding", "UTF-8"); // propertiesUTF-8?ISO-9959-1
        propertyValues.addPropertyValue("cacheSeconds", 60); // hardcode! seconds
        propertyValues.addPropertyValue("basenames", messageBaseNames);

        messageSource.setPropertyValues(propertyValues);
        registry.registerBeanDefinition(MESSAGE_SOURCE_BEAN_NAME, messageSource);
    }//from  w ww .  j ava2 s.com
}

From source file:org.springmodules.cache.config.CacheManagerAndProviderFacadeParserTests.java

protected void setUp() throws Exception {
    configElementBuilder = new ConfigElementBuilder();
    cacheManagerClass = AbstractCacheManagerFactoryBean.class;

    Class targetClass = AbstractCacheManagerAndProviderFacadeParser.class;

    Method getCacheManagerClassMethod = targetClass.getDeclaredMethod("getCacheManagerClass", new Class[0]);

    Method[] methodsToMock = { getCacheManagerClassMethod };

    parserControl = MockClassControl.createControl(targetClass, null, null, methodsToMock);
    parser = (AbstractCacheManagerAndProviderFacadeParser) parserControl.getMock();
    registry = new DefaultListableBeanFactory();

    cacheProviderFacade = new RootBeanDefinition(CacheProviderFacade.class);
    cacheProviderFacade.setPropertyValues(new MutablePropertyValues());
    registry.registerBeanDefinition(BeanName.CACHE_PROVIDER_FACADE, cacheProviderFacade);
}

From source file:com.laxser.blitz.web.impl.view.ViewDispatcherImpl.java

protected ViewResolver getJspViewResolver() throws IOException {
    if (this.jspViewResolver != null) {
        return this.jspViewResolver;
    }//from  w  ww .jav  a  2 s  .co m
    String beanName = "jspViewResolver";
    this.jspViewResolver = (ViewResolver) SpringUtils.getBean(getApplicationContext(), beanName);
    if (jspViewResolver == null) {
        GenericBeanDefinition beanDefinition = new GenericBeanDefinition();
        beanDefinition.setBeanClass(InternalResourceViewResolver.class);
        MutablePropertyValues propertyValues = new MutablePropertyValues();
        propertyValues.addPropertyValue(new PropertyValue("viewClass", JstlView.class));
        beanDefinition.setPropertyValues(propertyValues);
        ((BeanDefinitionRegistry) getApplicationContext().getBeanFactory()).registerBeanDefinition(beanName,
                beanDefinition);
        logger.info("registered bean definition named " + beanName + ": "
                + InternalResourceViewResolver.class.getName());
        jspViewResolver = (ViewResolver) SpringUtils.getBean(getApplicationContext(), beanName);
    }
    return this.jspViewResolver;
}

From source file:org.anodyneos.jse.cron.CronDaemon.java

public CronDaemon(InputSource source) throws JseException {

    Schedule schedule;//from w  w w  . j a  va  2 s  .  c  o  m

    // parse source
    try {

        JAXBContext jc = JAXBContext.newInstance("org.anodyneos.jse.cron.config");
        Unmarshaller u = jc.createUnmarshaller();
        //Schedule
        Source schemaSource = new StreamSource(Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("org/anodyneos/jse/cron/cron.xsd"));

        SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = sf.newSchema(schemaSource);
        u.setSchema(schema);
        ValidationEventCollector vec = new ValidationEventCollector();
        u.setEventHandler(vec);

        JAXBElement<?> rootElement;
        try {
            rootElement = ((JAXBElement<?>) u.unmarshal(source));
        } catch (UnmarshalException ex) {
            if (!vec.hasEvents()) {
                throw ex;
            } else {
                for (ValidationEvent ve : vec.getEvents()) {
                    ValidationEventLocator vel = ve.getLocator();
                    log.error("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + "]:"
                            + ve.getMessage());
                }
                throw new JseException("Validation failed for source publicId='" + source.getPublicId()
                        + "'; systemId='" + source.getSystemId() + "';");
            }
        }

        schedule = (Schedule) rootElement.getValue();

        if (vec.hasEvents()) {
            for (ValidationEvent ve : vec.getEvents()) {
                ValidationEventLocator vel = ve.getLocator();
                log.warn("Line:Col[" + vel.getLineNumber() + ":" + vel.getColumnNumber() + "]:"
                        + ve.getMessage());
            }
        }

    } catch (JseException e) {
        throw e;
    } catch (Exception e) {
        throw new JseException("Cannot parse " + source + ".", e);
    }

    SpringHelper springHelper = new SpringHelper();

    ////////////////
    //
    // Configure Spring and Create Beans
    //
    ////////////////

    TimeZone defaultTimeZone;

    if (schedule.isSetTimeZone()) {
        defaultTimeZone = getTimeZone(schedule.getTimeZone());
    } else {
        defaultTimeZone = TimeZone.getDefault();
    }

    if (schedule.isSetSpringContext() && schedule.getSpringContext().isSetConfig()) {
        for (Config config : schedule.getSpringContext().getConfig()) {
            springHelper.addXmlClassPathConfigLocation(config.getClassPathResource());
        }
    }

    for (org.anodyneos.jse.cron.config.JobGroup jobGroup : schedule.getJobGroup()) {
        for (Job job : jobGroup.getJob()) {
            if (job.isSetBeanRef()) {
                if (job.isSetBean() || job.isSetClassName()) {
                    throw new JseException("Cannot set bean or class attribute for job when beanRef is set.");
                } // else config ok
            } else {
                if (!job.isSetClassName()) {
                    throw new JseException("must set either class or beanRef for job.");
                }
                GenericBeanDefinition beanDef = new GenericBeanDefinition();
                MutablePropertyValues propertyValues = new MutablePropertyValues();

                if (!job.isSetBean()) {
                    job.setBean(UUID.randomUUID().toString());
                }

                if (springHelper.containsBean(job.getBean())) {
                    throw new JseException(
                            "Bean name already used; overriding not allowed here: " + job.getBean());
                }

                beanDef.setBeanClassName(job.getClassName());

                for (Property prop : job.getProperty()) {
                    String value = null;
                    if (prop.isSetSystemProperty()) {
                        value = System.getProperty(prop.getSystemProperty());
                    }
                    if (null == value) {
                        value = prop.getValue();
                    }

                    propertyValues.addPropertyValue(prop.getName(), value);
                }

                beanDef.setPropertyValues(propertyValues);
                springHelper.registerBean(job.getBean(), beanDef);
                job.setBeanRef(job.getBean());
            }
        }
    }

    springHelper.init();

    ////////////////
    //
    // Configure Timer Services
    //
    ////////////////

    for (org.anodyneos.jse.cron.config.JobGroup jobGroup : schedule.getJobGroup()) {

        String jobGroupName;
        JseTimerService service = new JseTimerService();

        timerServices.add(service);

        if (jobGroup.isSetName()) {
            jobGroupName = jobGroup.getName();
        } else {
            jobGroupName = UUID.randomUUID().toString();
        }

        if (jobGroup.isSetMaxConcurrent()) {
            service.setMaxConcurrent(jobGroup.getMaxConcurrent());
        }

        for (Job job : jobGroup.getJob()) {

            TimeZone jobTimeZone = defaultTimeZone;

            if (job.isSetTimeZone()) {
                jobTimeZone = getTimeZone(job.getTimeZone());
            } else {
                jobTimeZone = defaultTimeZone;
            }

            Object obj;

            Date notBefore = null;
            Date notAfter = null;

            if (job.isSetNotBefore()) {
                notBefore = job.getNotBefore().toGregorianCalendar(jobTimeZone, null, null).getTime();
            }
            if (job.isSetNotAfter()) {
                notAfter = job.getNotAfter().toGregorianCalendar(jobTimeZone, null, null).getTime();
            }

            CronSchedule cs = new CronSchedule(job.getSchedule(), jobTimeZone, job.getMaxIterations(),
                    job.getMaxQueue(), notBefore, notAfter);

            obj = springHelper.getBean(job.getBeanRef());
            log.info("Adding job " + jobGroup.getName() + "/" + job.getName() + " using bean "
                    + job.getBeanRef());
            if (obj instanceof CronJob) {
                ((CronJob) obj).setCronContext(new CronContext(jobGroupName, job.getName(), cs));
            }
            if (obj instanceof JseDateAwareJob) {
                service.createTimer((JseDateAwareJob) obj, cs);
            } else if (obj instanceof Runnable) {
                service.createTimer((Runnable) obj, cs);
            } else {
                throw new JseException("Job must implement Runnable or JseDateAwareJob");
            }
        }
    }
}

From source file:com.alibaba.dubbo.config.spring.context.annotation.DubboConfigBindingRegistrar.java

private MutablePropertyValues resolveBeanPropertyValues(String beanName, boolean multiple,
        Map<String, String> properties) {

    MutablePropertyValues propertyValues = new MutablePropertyValues();

    if (multiple) { // For Multiple Beans

        MutablePropertySources propertySources = new MutablePropertySources();
        propertySources.addFirst(new MapPropertySource(beanName, new TreeMap<String, Object>(properties)));

        Map<String, String> subProperties = getSubProperties(propertySources, beanName);

        propertyValues.addPropertyValues(subProperties);

    } else { // For Single Bean

        for (Map.Entry<String, String> entry : properties.entrySet()) {
            String propertyName = entry.getKey();
            if (!propertyName.contains(".")) { // ignore property name with "."
                propertyValues.addPropertyValue(propertyName, entry.getValue());
            }/*from  ww  w.  j  ava2  s  .c om*/
        }

    }

    return propertyValues;

}

From source file:org.atomserver.utils.test.TestingAtomServer.java

/**
 * add a new workspace to the testing server with the given name and localization flag.
 *
 * @param name      the name of the workspace
 * @param localized true iff the workspace is localized
 * @return a TestWorkspaceConfigurer to further configure the workspace
 *//*from  w  ww.  j av a 2s  .  c o  m*/
public TestWorkspaceConfigurer addWorkspace(String name, boolean localized) {
    // create a bean definition for the workspace and add it to the managed set.
    final RootBeanDefinition workspace = new RootBeanDefinition(WorkspaceOptions.class);

    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.addPropertyValue("name", name);
    propertyValues.addPropertyValue("defaultLocalized", localized);
    propertyValues.addPropertyValue("defaultProducingEntryCategoriesFeedElement", true);
    propertyValues.addPropertyValue("defaultContentStorage",
            new RuntimeBeanReference("org.atomserver-contentStorage"));
    propertyValues.addPropertyValue("defaultContentValidator",
            new RuntimeBeanReference("org.atomserver-simpleXMLContentValidator"));
    propertyValues.addPropertyValue("defaultCategoriesHandler",
            new RuntimeBeanReference("org.atomserver-entryCategoriesHandler"));
    propertyValues.addPropertyValue("defaultEntryIdGenerator",
            new RuntimeBeanReference("org.atomserver-entryIdGenerator"));

    workspace.setPropertyValues(propertyValues);

    workspaceSet.add(workspace);

    return new TestWorkspaceConfigurer() {
        // if given a RNC location, we spin up a RelaxNGValidator to validate with it
        public TestWorkspaceConfigurer setRncLocation(String rncLocation) {
            RootBeanDefinition autotagger = new RootBeanDefinition(RelaxNGValidator.class);
            MutablePropertyValues propertyValues = new MutablePropertyValues();
            propertyValues.addPropertyValue("schemaLocation", rncLocation);
            autotagger.setPropertyValues(propertyValues);
            workspace.getPropertyValues().addPropertyValue("defaultContentValidator", autotagger);
            return this;
        }

        // if given an XPathAutoTagger script, set up a tagger to use it
        public TestWorkspaceConfigurer setXPathAutotaggerRules(String rules) {
            RootBeanDefinition autotagger = new RootBeanDefinition(XPathAutoTagger.class);
            MutablePropertyValues propertyValues = new MutablePropertyValues();
            propertyValues.addPropertyValue("categoriesHandler",
                    new RuntimeBeanReference("org.atomserver-entryCategoriesHandler"));
            propertyValues.addPropertyValue("script", rules);
            autotagger.setPropertyValues(propertyValues);
            workspace.getPropertyValues().addPropertyValue("defaultAutoTagger", autotagger);
            return this;
        }

        // allow for arbitrary property setting on the workspace bean -- requires knowledge
        // of the Spring bean factory APIs
        public TestWorkspaceConfigurer addPropertyValue(String name, Object value) {
            workspace.getPropertyValues().addPropertyValue(name, value);
            return this;
        }
    };
}