Package org.springframework.context

Examples of org.springframework.context.ConfigurableApplicationContext


            return;
        }

        String[] beanNames = beanFactory.getBeanNamesForType(type);

        ConfigurableApplicationContext ctxt = (ConfigurableApplicationContext)beanFactory;

        // Take any bean name or alias that has a web service annotation
        for (int i = 0; i < beanNames.length; i++) {

            BeanDefinition def = ctxt.getBeanFactory().getBeanDefinition(beanNames[i]);

            if (!beanFactory.isSingleton(beanNames[i]) || def.isAbstract()) {
                continue;
            }

            try {
                Collection<?> ids = null;
                PropertyValue pv = def.getPropertyValues().getPropertyValue(idsProperty);
               
                if (pv != null) {
                    Object value = pv.getValue();
                    if (!(value instanceof Collection)) {
                        throw new RuntimeException("The property " + idsProperty + " must be a collection!");
                    }

                    if (value instanceof Mergeable) {
                        if (!((Mergeable)value).isMergeEnabled()) {
                            ids = (Collection<?>)value;
                        }
                    } else {
                        ids = (Collection<?>)value;
                    }
                }
                if (ids == null && staticFieldName != null) {
                    Class<?> cls = context.getType(beanNames[i]);
                    try {
                        Field f = cls.getDeclaredField(staticFieldName);
                        f.setAccessible(true);
                        Collection<QName> sids = CastUtils.cast((Collection<?>)f.get(null));
                        if (sids != null) {
                            ids = new ArrayList<QName>(sids);
                        }
                    } catch (Exception ex) {
                        //ignore, fall through
                    }
                }

                // if values are not legal keys (for lazy-init bean definitions id values may be
                // BeanDefinitionHolders), load the bean and get its id values instead
                // for BeanReference type values, simply resolve reference
                // 
                if (null != ids) {
                    Collection<Object> checked = new ArrayList<Object>(ids.size());
                    for (Object id : ids) {
                        if (id instanceof QName) {
                            checked.add(id);
                        } else if (id instanceof BeanReference) {
                            BeanReference br = (BeanReference)id;
                            Object refId = context.getBean(br.getBeanName());
                            checked.add(refId);
                        } else if (id instanceof BeanDefinitionHolder) {
                            BeanDefinitionHolder bdh = (BeanDefinitionHolder)id;
                            if (QName.class.getName().equals(bdh.getBeanDefinition().getBeanClassName())) {
                                try {
                                    java.util.List l = bdh.getBeanDefinition().getConstructorArgumentValues()
                                        .getGenericArgumentValues();
                                   
                                    ConstructorArgumentValues.ValueHolder v
                                        = (ConstructorArgumentValues.ValueHolder)l.get(0);
                                   
                                    TypedStringValue nss = (TypedStringValue)v.getValue();
                                    v = (ConstructorArgumentValues.ValueHolder)l.get(1);
                                    TypedStringValue ln = (TypedStringValue)v.getValue();
                                    checked.add(new QName(nss.getValue(), ln.getValue()));
                                } catch (Exception ex) {
                                    //ignore
                                    break;
                                }
                            } else {
                                break;
                            }
                        } else {
                           
                            break;
                        }
                    }
                    if (checked.size() < ids.size()) {
                        ids = null;
                    } else {
                        ids = checked;
                    }
                }
                if (ids == null) {
                    ids = getIds(ctxt.getBean(beanNames[i]));
                    if (ids == null) {
                        continue;
                    }
                }
               
                for (Object id : ids) {
                    QName key = (QName)id;
                    getBeanListForId(key).add(beanNames[i]);
                }
            } catch (BeanIsAbstractException e) {
                // The bean is abstract, we won't be doing anything with it.
                continue;
            }
        }

        processBeans(ctxt.getParent());
    }
View Full Code Here


            return;
        }

        String[] beanNames = beanFactory.getBeanNamesForType(type);

        ConfigurableApplicationContext ctxt = (ConfigurableApplicationContext)beanFactory;

        // Take any bean name or alias that has a web service annotation
        for (int i = 0; i < beanNames.length; i++) {
            BeanDefinition def = ctxt.getBeanFactory().getBeanDefinition(beanNames[i]);

            if (!beanFactory.isSingleton(beanNames[i]) || def.isAbstract()) {
                continue;
            }

            try {
                Collection<?> ids = null;
                PropertyValue pv = def.getPropertyValues().getPropertyValue(idsProperty);
               
                if (pv != null) {
                    Object value = pv.getValue();
                    if (!(value instanceof Collection)) {
                        throw new RuntimeException("The property " + idsProperty + " must be a collection!");
                    }

                    if (value instanceof Mergeable) {
                        if (!((Mergeable)value).isMergeEnabled()) {
                            ids = (Collection<?>)value;
                        }
                    } else {
                        ids = (Collection<?>)value;
                    }
                }
               
                if (ids == null) {
                    ids = getIds(ctxt.getBean(beanNames[i]));
                    if (ids == null) {
                        continue;
                    }
                }
               
                if (ids instanceof ManagedSet || ids instanceof ManagedList) {
                    List<String> newIds = new ArrayList<String>();
                    for (Iterator itr = ids.iterator(); itr.hasNext();) {
                        Object o = itr.next();
                        if (o instanceof TypedStringValue) {
                            newIds.add(((TypedStringValue) o).getValue());
                        } else {
                            newIds.add((String) o);
                        }
                    }
                    ids = newIds;
                }
                for (Object id : ids) {
                    getBeanListForId(id.toString()).add(beanNames[i]);
                }
            } catch (BeanIsAbstractException e) {
                // The bean is abstract, we won't be doing anything with it.
                continue;
            }
        }

        processBeans(ctxt.getParent());
    }
View Full Code Here

        Configurer conf = bus.getExtension(Configurer.class);
        if (conf instanceof ConfigurerImpl) {
            ((ConfigurerImpl)conf).addApplicationContext(ctx);
        }
        if (ctx instanceof ConfigurableApplicationContext) {
            ConfigurableApplicationContext cctx = (ConfigurableApplicationContext)ctx;
            new BusWiringBeanFactoryPostProcessor(bus).postProcessBeanFactory(cctx.getBeanFactory());
        }
    }
View Full Code Here

        return connObjectTO;
    }

    public void retrieveVirAttrValues(final AbstractAttributable owner) {
        final ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();
        final ConnInstanceLoader connInstanceLoader = context.getBean(ConnInstanceLoader.class);

        final Map<SchemaMappingUtil.SchemaMappingsWrapper, ConnectorObject> remoteObjects =
                new HashMap<SchemaMappingUtil.SchemaMappingsWrapper, ConnectorObject>();

        for (ExternalResource resource : owner.getResources()) {
View Full Code Here

    @Autowired
    private ResourceDataBinder resourceDataBinder;

    private DefaultListableBeanFactory getBeanFactory() {
        ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();

        return (DefaultListableBeanFactory) context.getBeanFactory();
    }
View Full Code Here

    @Autowired
    private ReportDAO reportDAO;

    private DefaultListableBeanFactory getBeanFactory() {
        ConfigurableApplicationContext context = ApplicationContextProvider.getApplicationContext();

        return (DefaultListableBeanFactory) context.getBeanFactory();
    }
View Full Code Here

        camelRemotingInvocation();
        tearDownServer();
    }
   
    protected void camelClientInvocation() {
        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");

        // get the camel template for Spring template style sending of messages (= producer)
        ProducerTemplate camelTemplate = (ProducerTemplate) context.getBean("camelTemplate");
       
        // as opposed to the CamelClientRemoting example we need to define the service URI in this java code
        int response = (Integer)camelTemplate.sendBody("jms:queue:numbers", ExchangePattern.InOut, 22);
       
        assertEquals("Get a wrong response", 66, response);
       
        context.stop();
       
    }
View Full Code Here

       
    }
   
    protected void camelEndpointInvocation() throws Exception {
       
        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
        CamelContext camel = (CamelContext) context.getBean("camel");

        // get the endpoint from the camel context
        Endpoint endpoint = camel.getEndpoint("jms:queue:numbers");

        // create the exchange used for the communication
        // we use the in out pattern for a synchronized exchange where we expect a response
        Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
        // set the input on the in body
        // must you correct type to match the expected type of an Integer object
        exchange.getIn().setBody(11);

        // to send the exchange we need an producer to do it for us
        Producer producer = endpoint.createProducer();
        // start the producer so it can operate
        producer.start();

        // let the producer process the exchange where it does all the work in this oneline of code
       
        producer.process(exchange);

        // get the response from the out body and cast it to an integer
        int response = exchange.getOut().getBody(Integer.class);
       
        assertEquals("Get a wrong response.", 33, response);

        // stop and exit the client
        producer.stop();
        context.stop();
       
    }
View Full Code Here

       
    }
   
    protected void camelRemotingInvocation() {

        ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("camel-client-remoting.xml");
        // just get the proxy to the service and we as the client can use the "proxy" as it was
        // a local object we are invoking. Camel will under the covers do the remote communication
        // to the remote ActiveMQ server and fetch the response.
        Multiplier multiplier = (Multiplier)context.getBean("multiplierProxy");
      
        int response = multiplier.multiply(33);
       
        assertEquals("Get a wrong response", 99, response);
       
        context.stop();
       
    }
View Full Code Here

        context = ctx;
        orig = bus.getExtension(ConfiguredBeanLocator.class);
        if (orig instanceof ExtensionManagerImpl) {
            List<String> names = new ArrayList<String>();
            for (String s : ctx.getBeanDefinitionNames()) {
                ConfigurableApplicationContext ctxt = (ConfigurableApplicationContext)context;
                BeanDefinition def = ctxt.getBeanFactory().getBeanDefinition(s);
                String cn =  def.getBeanClassName();
                if (OldSpringSupport.class.getName().equals(cn)) {
                    passThroughs.add(s);
                    for (String s2 : ctx.getAliases(s)) {
                        passThroughs.add(s2);
View Full Code Here

TOP

Related Classes of org.springframework.context.ConfigurableApplicationContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.