July 2006 Archives
Greenbox: Consuming Metamodel as XML
Posted by edgars on July 13, 2006 at 11:37 AM | Permalink
| Comments (1)
As Alexandre Gomes told on JavaOne2006 "Greenbox is a lot of ideas", besides ideas, it have a lot of very easy instruments to generate source really easy.
Creating a Metamoldel serializer for XML
To do that is quite easy, you have a interface available since 2002 on framework, its name is IXmlMetamodel. Then I did an implementation using XStream tool, which you can see in the following code:
public class MetamodelMarshaller implements IXmlMetamodel {
protected XStream xml;
private static MetamodelMarshaller me;
private MetamodelMarshaller() {
// setting the alias for classes and attributes
xml = new XStream();
xml.alias("class", net.java.dev.greenbox.base.Clazz.class);
xml.alias("attribute", net.java.dev.greenbox.base.Attribute.class);
xml.alias("method", net.java.dev.greenbox.base.Method.class);
xml.aliasField("package", net.java.dev.greenbox.base.Clazz.class,"packageName");
xml.aliasField("name", net.java.dev.greenbox.base.Clazz.class,"className");
}
public static MetamodelMarshaller getInstance() {
if (null == me) {
me = new MetamodelMarshaller();
}
return me;
}
public String getMetamodelAsXml(Object objeto) {
return xml.toXML(objeto);
}
public Object loadMetamodel(String xmlString) {
return xml.fromXML(xmlString);
}
}
Now, we will build a simple main method on Java Class to use it and generate a ValueObject pattern:
public static void main(String[] args) {
StringBuffer xml = loadXMLFromFile();
Clazz clazz = (Clazz) MetamodelMarshaller.getInstance ().loadMetamodel(xml.toString());
clazz.setMethods(decorateMethods(clazz));
GreenboxContext ctx = new GreenboxContext();
ctx.declareVariable("class",clazz);
try {
System.out.println(ClassGeneratorBase.getInstance().generateSourceByTemplateName(clazz,"vo",ctx));
} catch (Exception e) {
e.printStackTrace();
}
This will print a complete Java Value Object pattern implementation source.
Look that we have some errors on source, this I know, is just to call your atention to GreenboxContext usage, when you declare it on the object ctx, this will be generated in output too.
If you want this example, feel you free to send an email to edgarsilva (nospam) gmail.com
cya
XML Databinding really simple
Posted by edgars on July 13, 2006 at 09:03 AM | Permalink
| Comments (6)
XStream is the kind of project which is so easy and so great, that if somebody try give a presenation about that could be hard spend more than five minutes.
I've used XStream on some new supports for Greebox in order to allow Eclipse Developers use it.
Here I will take a piece of tests of my evaluations:
xml = new XStream();
xml.alias("class",net.java.dev.greenbox.base.Clazz.class);
xml.alias("attribute",net.java.dev.greenbox.base.Attribute.class);
xml.aliasField("package",net.java.dev.greenbox.base.Clazz.class,"packageName");
xml.aliasField("name",net.java.dev.greenbox.base.Clazz.class,"className");
classe = new Clazz();
classe.setPackageName("br.com.summatech.greenboxsamplexml.contact");
classe.setClassName("Contact");
Attribute nameContact = new Attribute();
nameContact.setName("name");
nameContact.setDataType("String");
nameContact.setAcessor("private");
Attribute email = new Attribute();
email.setName("email");
email.setDataType("String");
email.setAcessor("private");
ArrayList attrs = new ArrayList();
attrs.add(nameContact);
attrs.add(email);
classe.setAttributes(attrs);
System.out.println(xml.toXML(classe));
And the Result:
<class>
<package>br.com.summatech.greenboxsamplexml.contact</package>
<name>Contact</name>
<attributes>
<attribute>
<acessor>private</acessor>
<dataType>String</dataType>
<name>name</name>
</attribute>
<attribute>
<acessor>private</acessor>
<dataType>String</dataType>
<name>email</name>
</attribute>
</attributes>
</class>
So now, I can marshall and unmarchall object really easy! thanks codehaus :D and XStream team. Solutions like that could be part of JSE.
Javax.Ide ???
Posted by edgars on July 07, 2006 at 03:53 PM | Permalink
| Comments (6)
Right now I am developing plugins-module for Greenbox Framework, and I spent so many times to discover how NetBeans works internally, its details, and a lot of related issues.
Ofcouse, I lot of users and customers asked me for an Eclipse Version, and I am trying to do almost the same, but NetBeans and Eclipse are completelly different platforms. Then all work I spend on NetBeans, anybody else will spend porting to Eclipse the same things I did.
However, there are a JSR which describes how plugins, extensions, modules, wizards, menus and so on...Should work, this JSR 198.
Unfortunally I can't say if NetBeans, JBuilder, Eclipse, IDEA, JDeveloper (big players) are at least really tryng to finish and use this JSR... Would be awesome see the WORA concept working for Addon tools.
|