Welcome to this Blog. I am Software Engineer and work for Zühlke Engineering AG in Bern. This is my private blog, in which I will post mainly about technical stuff like Software Engineering or IT related topics. The views expressed herein do not necessarily represent those of my employer.
Are you a real men (or women)? Because if you are one, Eclipse offers you the possiblity to “don’t click”
Try to use the simple shortcut CTRL + 3. What happens? Eclipse opens the Quick access window:
Now, type what you want, for example “new xml file”, and Eclipse searches for the command, which consists of these words:
Also very interesting is the access to the Preferences window. Try to search for “classpath variables” or “build path”, you get direct access to these settings. Also interesting is “Generate Getters”. If you don’t know a specific shortcut, just use CTRL + 3 from now on!
This is the last hint this week. While working with JiBX, I had the situation, that there were some null values in the Java class.
JiBXTestApplication Exception in thread "main" org.jibx.runtime.JiBXException: null value for element "{http://stefanjaeger.ch/CustomerSchema}city" from object of type ch.stefanjaeger.jibx.Customer at org.jibx.runtime.impl.MarshallingContext.element(MarshallingContext.java:713) at ch.admin.bit.edec.common.declaration.Versandvorgang.JiBX_binding_marshal_1_0(Unknown Source) at ch.admin.bit.edec.common.declaration.Deklaration.JiBX_binding_marshal_1_0(Unknown Source) at ch.admin.bit.edec.common.declaration.JiBX_bindingDeklaration_access.marshal() at ch.admin.bit.edec.common.declaration.Deklaration.marshal(Unknown Source) at org.jibx.runtime.impl.MarshallingContext.marshalRoot(MarshallingContext.java:1041) at org.jibx.runtime.impl.MarshallingContext.marshalDocument(MarshallingContext.java:1111) at ch.admin.bit.test.jibx.JiBXTestApplication.main(Unknown Source)
Per default, JiBX doesn’t allow null values. If there is a null value, it throws an JiBXException while marshalling.
To allow null values, you have to define explicit the attribute usage="optional" on a value or structure element in the binding file. If JiBX finds a null pointer on a member, JiBX does not fill an empty value to the xml element, JiBX will skip the element.
To define a constant value in an output mapping, just use the attribute constant:
<value constant="hello world" name="theAttribute" />The XML attribute theAttribute get now always the value hello world.
I like to validate the binding XML file against a schema, to prevent typos and other mistakes. In the folder docs of the JiBX zip archive, there is the XML schema binding.xsd. Just use it like following:
<binding xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nonamespaceschemalocation="binding.xsd">
JiBX offers the possibility to create separate input and output bindings. Just use the attribute direction in the root element of the binding file. To create a XML binding just for the marshalling objects, use <binding direction="output">. To create an XML binding just for unmarhshalling XML files, use <binding direction="input">.
With this possibility, you can define for example an input binding, which doesn’t map every element of a XML file. But in the output binding you can define some constants, which get’s mapped, if objects gets marshaled to XML files.
« Newer Posts — Older Posts »
