Posts

Generating XML from JavaScript

Image
Generating XML from JavaScript: When to use these functions: In some Javascript-based environments there are no XML libraries available, sometimes external libraries are not allowed or you just want fine control over your xml generation process. They are easy to implement and easy to use too. About the image: well, I just liked it. // Create an XML element. function createXMLElement(parent, name, data) {     var node = new Object();     node["parent"] = parent;     node["name"] = name;     node["data"] = data;     node["children"] = new Array();     node["attributes"] = new Array();     return node; } //Add child function addXMLChild(parent, child) {     child["parent"] = parent;     parent["children"].push(child); } // XML library: add a child function addXMLChildAtPos(parent, child,pos) {     child["parent"] = parent;     par...

Getting Access To Private Fields in JAVA using Reflection:

Image
Getting Access To Private Fields in JAVA using Reflection: Private fields are... ehem, private, that means that they cannot (should not) be known, inspected or changed... now that inversion of control is common around us, what if a class is keeping a field private to protect it from 'abuse' but I want to access it just to abuse it softly (??? I should check my semantics when talking about code). What if I want Inversion of Control and I do not have an IOC Container? Ok, lets do it the hard (O_O ???) way. For example, a Business Object is keeping a Data Object in private for it not to be directly used out of the Business Tier, but a Manager class wants to be made responsible for Business Tier's persistence. So the manager takes the Business Object, takes its DataObject, and persists it... but, it cannot! the Data Object was set to... private. Ok, here is how to change that field access permissions during runtime: Obtain a private field and play with it:...

Google Web Toolkit GWT with NetBeans 7 (and 8) Tutorial

Image
Installing GWT plugin on Netbeans: Open Tools Menu/Plugins, go to Available Plugins tab and type GWT in the search field and proceed by clicking the Install button on the bottom left corner. Accept the plugin even if it is signed but not trusted and restart Netbeans. GWT framework will be available now while creating a new web project. Starting a GWT Project: To create a GWT project with Netbeans the GWT framework should be selected.  Unfortunately or not the generated code is a simple client-only module. Lets see what it has created for us: Notice that: WEB-INF: web.xml No servlets have been added. This is due to being just a client-only gwt example page. The starting page is pointing at welcomeGWT.html. Most probably you will want to change this as it is quite a funny name for a serious application. Source Packages A package and a subpackage have been created: com.ramon.talavera containing a Main.gwt...