Skip to content

Instantly share code, notes, and snippets.

View tomasmalmsten's full-sized avatar

Tomas Malmsten tomasmalmsten

View GitHub Profile
@tomasmalmsten
tomasmalmsten / mvn-test-output-to-shell
Created October 31, 2013 11:02
Make maven print test output to the terminal
<profile>
<id>dev</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<disableXmlReport>true</disableXmlReport>
<useFile>false</useFile>
@tomasmalmsten
tomasmalmsten / DefaultStrategy.java
Last active December 27, 2015 01:49
How to create a factory for strategies without using if's - DefaultStrategy.java
package com.tomasmalmsten.examples.strategy;
public class DefaultStrategy implements Strategy {
DefaultStrategy() {}
public void execute() {
System.out.println("Default Strategy!");
}
}
@tomasmalmsten
tomasmalmsten / Strategy.java
Created October 31, 2013 11:33
How to create a factory for strategies without using if's - Strategy.java
package com.tomasmalmsten.examples.strategy;
public interface Strategy {
void execute();
}
@tomasmalmsten
tomasmalmsten / StrategyFactory.java
Created October 31, 2013 11:33
How to create a factory for strategies without using if's - StrategyFactory.java
package com.tomasmalmsten.examples.strategy;
import java.util.HashMap;
import java.util.Map;
public class StrategyFactory {
public static final String DEFAULT_STRATEGY_KEY = "default";
public static final String SPECIFIC_STRATEGY_KEY = "specific";
private static StrategyFactory instance = new StrategyFactory();
@tomasmalmsten
tomasmalmsten / SpecificStrategy.java
Created October 31, 2013 11:35
How to create a factory for strategies without using if's - SpecificStrategy.java
package com.tomasmalmsten.examples.strategy;
public class SpecificStrategy implements Strategy {
SpecificStrategy() {}
public void execute() {
System.out.println("Specific Strategy!");
}
}
@tomasmalmsten
tomasmalmsten / OSGiSafeJaxbRepresentation.java
Created October 31, 2013 12:44
Restlet's JAXB extension in OSGi
package com.tomasmalmsten.restlet.jaxb;
import org.restlet.ext.jaxb.JaxbRepresentation;
import org.restlet.representation.Representation;
public class OSGiSafeJaxbRepresentation<T> extends JaxbRepresentation<T> {
public OSGiSafeJaxbRepresentation(
final Representation xmlRepresentation, final String contextPath) {
super(xmlRepresentation, contextPath, null,
OSGiSafeJaxbRepresentation.class.getClassLoader());
@tomasmalmsten
tomasmalmsten / provider.xml
Created October 31, 2013 12:46
Mapping java.util.Map to XML using JAXB - provider.xml
<provider>
<name>Provider Name</name>
<properties>
<property>
<name>address</name>
<value>194.132.9.45</value>
</property>
<property>
<name>username</name>
<value>testuser</username>
@tomasmalmsten
tomasmalmsten / Provider.java
Created October 31, 2013 12:47
Mapping java.util.Map to XML using JAXB - Provider.java
package com.tomasmalmsten.example.jaxb;
import java.util.Map;
public class Provider {
private String name;
private Map<String, String> properties;
void setProperties(Map<String, String> properties) {
this.properties = properties;
@tomasmalmsten
tomasmalmsten / Property.java
Created October 31, 2013 12:48
Mapping java.util.Map to XML using JAXB - Property.java
package com.tomasmalmsten.example.jaxb;
import javax.xml.bind.annotation.XmlElement;
class Property {
@XmlElement(name = "name")
private String name;
@XmlElement(name = "value")
private String value;
@tomasmalmsten
tomasmalmsten / Properties.java
Last active December 27, 2015 01:59
Mapping java.util.Map to XML using JAXB - Properties.java
package com.tomasmalmsten.example.jaxb;
import javax.xml.bind.annotation.XmlElement;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
class Properties {
@XmlElement(name = "property")
private List<Property> entries = new ArrayList<>();