Tuesday, August 14, 2012

Binding with JAXB


1) Get a xsd from an xml.
http://www.freeformatter.com/xsd-generator.html#ad-output


2) Generate the Java Objects
xjc.sh -p com.package.name books.xsd -d workfolder


3) Process it in Java

        JAXBContext jc = JAXBContext.newInstance("com.package.name");
   
 Unmarshaller unmarshaller = jc.createUnmarshaller();
   
 Collection collection = (Collection) unmarshaller.unmarshal(new File("src/books.xml"));



Wednesday, August 8, 2012

Git Bare Repo - Concept Summary

Do you get the below error: on GIT PUSH ?????

remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error: 
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error: 
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.


Understand the concept: : )



Notice 1, 2, 3, 4

2 - is the bare repo

To update the source of truth repo, you have to pull

To update the shared repo from the working , you have to push to it.

Sunday, August 5, 2012

Groovy Patterns - I just forget!


 http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html



def thePattern = /foo/
def theString = "boo foo";
def theMatcher = theString=~thePattern


//1.
//it's "true" if it has at least one match,
if( theString =~ thePattern){
println "true";
}else{
println "false"
}


//2.
//print the the matcher to see
println theMatcher;
//note theMatcher is an array
println theMatcher[0];


//3
def stringToMatch = '''abc quick brownfox ? blah blah'''

def myPattern = /blah/

def m = stringToMatch=~myPattern
println m[0] + m.size()