directory-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ole Ersoy <ole.er...@gmail.com>
Subject [Configuration] Some More Concrete EMF Lines for Accessing pom.xml
Date Sun, 09 Mar 2008 04:13:16 GMT
Hey Guys,

Here are some snippets that give more concrete insight into how an EMF generated model can
be leveraged.  These show how the various parts of a pom.xml document are accessed.  Note
that interfaces like LicenseType were generated from the pom.xml schema:
http://maven.apache.org/maven-v4_0_0.xsd

The main point of what I'm showing below is to provide examples of what I mean by:
- Getting the root element of server.xml (pom.xml in this case)
- Retrieving configuration components by URI Fragment
- Navigating the Configuration Graph- 

//Load a pom.xml document:
//(The URI object is EMF Specific and just points to a pom.xml file)
Resource resource = resourceSet.getResource(pomURI, true);

//Get the document root
DocumentRoot documentRoot = (DocumentRoot) resource.getContents().get(0);

//Get the root element of the pom.xml document <project>
Model model = documentRoot.getProject();

//Get all the license element contained in the pom
LicensesType liceneType	=  model.getLicenses();

//Get the URI Fragment for licenseType and print it
String fr= resource.getURIFragment(liceneType);
System.out.println(fr);

//Get the list of plugins in the pom using a fragment path
EList plugins = (EList) resource.getEObject("//@project/@reporting/@plugins");

//Get the name of the second license in the list
License	license = (License) liceneType.getLicense().get(1);
System.out.println(license.getName());

Cheers,
- Ole



Mime
View raw message