Some time ago, I showed how to create DSLs with statements to manage JCR nodes and properties. If you correctly lay out the code, it resembles an ASCII drawing for the actual content tree. Next Scala code
root ¦- "movies" -+ { n: Node => n ¦= ("title", "Night on Earth") n ¦= ("length", 123L) n ¦= ("ratings", 9L::8L::5L::Nil) n ¦= ("languages", "en"::"it"::"fi"::"fr"::Nil) n ¦- "cast" -+ { n: Node => n ¦= ("Gena Rowlands", "Victoria Snelling") n ¦= ("Winona Ryder", "Corky") n ¦= ("Roberto Benigni", "Taxi Driver") }}
equivalent to this version in Java:
Node movies = root.addNode("movies"); movies.setProperty("title", "Night on Earth"); movies.setProperty("length", 123L); movies.setProperty("ratings", new String[]{"9", "8", "5"}, PropertyType.LONG); movies.setProperty("languages", new String[]{"en", "it", "fi", "fr"}, PropertyType.STRING); Node cast = movies.addNode("cast"); cast.setProperty("Gena Rowlands", "Victoria Snelling"); cast.setProperty("Winona Ryder", "Corky"); cast.setProperty("Roberto Benigni", "Taxi Driver");
Despite the fact that it is not always useful, it may deserve attention for creativity.
michid
source share