Skip to content

Instantly share code, notes, and snippets.

View nschlimm's full-sized avatar
🏠
Working from home

Niklas Schlimm nschlimm

🏠
Working from home
  • TIMOCOM GmbH
  • Cologne, Germany
View GitHub Profile
@nschlimm
nschlimm / Complete script
Created July 2, 2011 15:55
Ant build file to run Arquillian test
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
Any modifications will be overwritten.
To include a user specific buildfile here, simply create one in the same
directory with the processing instruction <?eclipse.ant.import?>
as the first entry and export the buildfile again. -->
<project basedir="." default="runtests" name="testng_tests">
<property environment="env" />
<property name="M2_REPO" value="C:/Users/nschlimm/.m2/repository" />
<property name="ECLIPSE_HOME" value="../../../../eclipse-3.6" />
@nschlimm
nschlimm / gist:1060914
Created July 2, 2011 15:52
Ant build file to run Arquillian test
<project basedir="." default="runtests" name="testng_tests">
<property environment="env" />
<property name="M2_REPO" value="C:/Users/nschlimm/.m2/repository" />
<property name="ECLIPSE_HOME" value="../../../../eclipse-3.6" />
<property name="debuglevel" value="source,lines,vars" />
<property name="target" value="1.6" />
<property name="source" value="1.6" />
<target name="runtests">
<junit printsummary="yes" haltonfailure="yes">
<classpath>
@nschlimm
nschlimm / gist:1109076
Created July 27, 2011 10:12
Receive delegate for decorator
public String getRegisteredDelegate(ConfigurableListableBeanFactory beanFactory, DecoratorInfo decoratorInfo) {
DelegateField arbitraryDelegateField = decoratorInfo.getDelegateFields().get(0);
DependencyDescriptor delegateDependencyDescriptor = DecoratorModuleUtils.createRuleBasedDescriptor(arbitraryDelegateField.getDeclaredField(), new Class[] { IgnoreDecoratorAutowiringLogic.class });
List<String> registeredDelegates = new ArrayList<String>();
String[] candidateNames = BeanFactoryUtils.beanNamesForTypeIncludingAncestors(beanFactory, arbitraryDelegateField.getDeclaredField().getType(), true, false);
for (String candidate : candidateNames) {
BeanDefinition bd = beanFactory.getBeanDefinition(candidate);
// Annotated Bean scanned in the classpath
if (bd instanceof AnnotatedBeanDefinition) {
AnnotatedBeanDefinition abd = (AnnotatedBeanDefinition) bd;
@nschlimm
nschlimm / gist:1115465
Created July 30, 2011 12:14
Spring-CDI decorator application context
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
default-autowire="byName">
<context:component-scan base-package="com.mycompany.springapp.springcdi" scoped-proxy="targetClass">
@nschlimm
nschlimm / gist:1115494
Created July 30, 2011 12:55
DecoratorBeanFactoryPostProcessor main
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
Map<String, Class> decorators = decoratorResolutionStrategy.getRegisteredDecorators(beanFactory);
List<QualifiedDecoratorChain> chains = buildQualifiedDecoratorChains(beanFactory, decorators);
registerAutowireCandidateResolver(beanFactory, chains);
registerDecoratorMetadataBean(beanFactory, chains);
if (PROCESSOR.equals(getMode())) {
((DefaultListableBeanFactory) beanFactory).registerBeanDefinition(DECORATOR_POSTPROCESSOR_NAME, BeanDefinitionBuilder.rootBeanDefinition(DecoratorAwareBeanPostProcessor.class).getBeanDefinition());
if (beanFactory.getBeanNamesForType(DecoratorAwareBeanPostProcessor.class) == null) {
@nschlimm
nschlimm / gist:1115496
Created July 30, 2011 12:57
DecoratorPostProcessor main
@Override
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (metaData.isDecoratedBean(beanName)) {
return buildDelegateProxy(bean, beanName);
} else {
return bean;
}
}
@nschlimm
nschlimm / gist:1127871
Created August 5, 2011 16:07
Decorator example 4
package com.mycompany.springapp.springcdi;
import javax.decorator.Decorator;
import javax.decorator.Delegate;
@Decorator
public class MyServiceTransactionDecorator implements MyService{
@Delegate
private MyService delegate;
@nschlimm
nschlimm / gist:1127882
Created August 5, 2011 16:12
User Credentials example
import org.springframework.context.annotation.Scope;
@Scope("session")
public class UserCredentials {
...
}
import org.springframework.context.annotation.Scope;
@Scope("singleton")
@nschlimm
nschlimm / gist:1127888
Created August 5, 2011 16:14
Scopes web.xml
<web-app>
...
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
...
</web-app>
@nschlimm
nschlimm / gist:1127885
Created August 5, 2011 16:13
User Credentials example CDI scopes
import javax.enterprise.context.SessionScoped;
@SessionScoped
public class UserCredentials implements Serializable {
/**
* Unique ID
*/
private static final long serialVersionUID = 8825296584100263935L;