Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@etluchs
etluchs / DbProfile.java
Created December 19, 2012 20:49
CDI profile enum
public enum DbProfile {
IN_MEMORY_DB, JEE_DATASOURCE;
public AnnotationLiteral<InProfile> literal(){
return new InProfileLiteral();
}
class InProfileLiteral extends AnnotationLiteral<InProfile> implements InProfile {
@Override
@etluchs
etluchs / SampleModuleConfigurationSelector.java
Created December 19, 2012 20:47
CDI configuration selector
@Produces
public SampleSvc sampleSvc(@Any Instance<SampleSvc> candidates) {
return candidates.select( activeProfile.literal() ).get();
}
@etluchs
etluchs / InProfile.java
Created December 19, 2012 20:50
profile annotation example
@Retention(RetentionPolicy.RUNTIME)
@Qualifier
@Target({ElementType.TYPE})
public @interface InProfile {
DbProfile value();
}
@etluchs
etluchs / App.scala
Created April 7, 2012 18:30
simple interactive test for completing parser
object CompletingParserTestApp extends TestParser with App {
println( "Type something and hit enter" );
var input = ""
do {
input = readLine();
parseAll( propertyPath, input ) match {
case s : Success[Any] => println ( "valid, parsed as "+ s.get)
case MissingCompletionOrFailure( completions, msg, in)
=> if ( completions.isEmpty )
@etluchs
etluchs / TestParser.scala
Created April 7, 2012 18:31
Trivial test-parser
class TestParser extends JavaTokenParsers with CompletingParser {
def propertyPath: Parser[Any] = "name" | ( "child"~opt("."~childProperties) ) | "chunk"
def childProperties: Parser[Any] = "name" | "toys" | "tolerance"
}
@etluchs
etluchs / CompletingParser.scala
Created April 6, 2012 21:15
Completing Parser Trait
import util.parsing.combinator.RegexParsers
/**
* A trait to make parsers for string literals return a nice list of possible completions if
* we're at the end of the input.
*
* @author Marcus Schulte
*/