If you need to access the metadata of a class or be a bit less type safe than Java is by itself, you will have to get involved with the Java Reflection API. At that the question may arise, how to check whether one class object is the super class of another. If you are working with objects, you may use the java keyword instanceof
. But this won’t work as expected for class objects, since all class objects are instances of Class<?>
. So Class<?>
owns the method cls1.isAssignableFrom(cls2)
, checking whether cls1
is a super class/interface or the same as cls2
. So it works just like instanceof
on objects, but the order of the parameters is switched.
Category: Knowledge
Problem using SQL keywords as field names in entities
If you’re using an JPA implementation in your application like hibernate you might try to name a field of an entity just as SQL keywords (e.g. ‘order’ or ‘key’). But beware of the nasty persistence provider.
Read More
Bug in JDK Javadoc for class java.util.regex.Pattern
The Javadoc for class java.util.regex.Pattern contains a bug. It says that a back reference (Pattern (Java Platform SE 6)) to a capturing group is depicted by \n
whereas n denotes the number of the capturing group. Unfortunately this won’t work. Use $n
instead.
Read More
Transaction Propagation for Remote calls
I didn’t find a clear statement whether transactions are propagated for remote calls in Java EE 5. So I tested it by creating two enterprise applications being deployed in different ears to the same JBoss-5.1.0-GA. In short: YES, the transaction is propagated and a rollback on a calling method initiates a rollback on the remote transaction, too. The willing reader might read on in order to get to know the test setup. Read More
Virtualization for VPN on Shared Systems
If you are using a machine being shared between several persons it is not advisable to open a VPN connection, because the tunnel would be accessible for all users of the computer. This is often the case in environments with thin clients. Instead of using a notebook or some other dedicated system, there is another possibility. Stephan Windmüller pointed me at the following solution. Simply install a virtualizer like VirtualBox with an operating system emulating its own network hardware. You can use a VPN tunnel from inside the virtualized OS without sharing the connection with other users on the host machine.
Preventing a bad color representation in acroread for LaTeX documents
Using pdftex to generate a PDF document from LaTeX source shows up to look ugly in acroread due to color model and transparency settings. The following LaTeX commando hacks this behavior:
\pdfpageattr {/Group << /S /Transparency /I true /CS /DeviceRGB>>}
Using JAAS login modules from jBoss in Tomcat
A jboss login module (like the LdapExtLoginModule
in jbosssx.jar shipped with jboss-5.0.1.GA) returns a
Group
array with one SimpleGroup
named “Roles” as its role set.
The parent class AbstractServerLoginModule
combines this with the Principal
object representing the user. So the set of principals consists of two entries acting as the
user and his roles. These are added to the principals of the Subject
instance, which
has been given to the login module when LoginModule#initialize(Subject, javax.security.auth.callback.CallbackHandler, java.util.Map, java.util.Map)
is called.