This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Address address = new AddressBuilder() | |
| .forStreetNumber(...).ofStreet(...) | |
| .inCity(...).withZipCode(...) | |
| .lyingInState(...).ofCountry(...) | |
| .build(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Address address = new AddressBuilder() | |
| .setStreet(...) | |
| .setStreetNumer(...) | |
| .setZipCode(...) | |
| .setCity(...) | |
| .setState(...) | |
| .setCountry(...) | |
| .build(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| AddressBuilder builder = new AddressBuilder(); | |
| builder.setStreet(...); | |
| builder.setStreetNumer(...); | |
| builder.setZipCode(...); | |
| builder.setCity(...); | |
| builder.setState(...); | |
| builder.setCountry(...); | |
| Address address = builder.build(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Address { | |
| public Address(String street, | |
| String streetNumber, | |
| String zipCode, | |
| String city, | |
| String state, | |
| String country) { | |
| ... | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void marry(String newLastName) { | |
| lastName = notBlank(newLastName); | |
| married = true; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void connectCdiAndSpring(@Observes AfterBeanDiscovery event, BeanManager manager) | |
| throws ClassNotFoundException { | |
| ConfigurableApplicationContext springContext | |
| = new ClassPathXmlApplicationContext(new String[] { "classpath:application-context.xml"}, false); | |
| springContext.addBeanFactoryPostProcessor(new DependencyRegisteringPostProcessor(manager, cdiBeans)); | |
| springContext.refresh(); | |
| for (String beanName: springContext.getBeanDefinitionNames()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private BeanDefinition createBeanDefinition(Bean bean) { | |
| GenericBeanDefinition beanDefinition = new GenericBeanDefinition(); | |
| beanDefinition.setBeanClass(bean.getBeanClass()); | |
| beanDefinition.setScope(CdiScope.class.getName()); | |
| beanDefinition.setLazyInit(true); | |
| return beanDefinition; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class DependencyRegisteringPostProcessor | |
| implements BeanFactoryPostProcessor { | |
| private BeanManager beanManager; | |
| private List<Bean<Object>> cdiBeans; | |
| public DependencyRegisteringPostProcessor(BeanManager beanManager, List<bean><object>>cdiBeans) { | |
| this.beanManager = beanManager; | |
| this.cdiBeans = cdiBeans; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class SpringCdiExtension implements Extension { | |
| private List<Bean<Object>> cdiBeans = new ArrayList<Bean<Object>>(); | |
| public void addBean(@Observes ProcessBean<Object> bean) { | |
| cdiBeans.add(bean.getBean()); | |
| } | |
| public void connectCdiAndSpring(@Observes AfterBeanDiscovery event, | |
| BeanManager manager) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class CdiScope implements Scope { | |
| private BeanManager beanManager; | |
| private Map<string,><object>>beans; | |
| public CdiScope(BeanManager beanManager, | |
| Map<string,><object>>beans) { | |
| this.beanManager = beanManager; | |
| this.beans = beans; | |
| } |