dev-blog

Sunday, January 23, 2005

Hibernate enums deprecated

One charachteristic of enumerations is that they are static. They possible enumerated values cannot be changed at run time. If the allowed values should be changeable it's problably not an enumeration but more a separate entity.
Enumerations are that static that their values are known when coding against them.

Hibernate does provide a method to persist enumerations. Nevertheless the Java Interface PersistentEnum is depricated
I found some suggestions for how to persist enumerations with hibernate:

  1. UserType per EnumType

  2. Extend PersistenEnum usertype

  3. A Forum Article


  4. Go for the non type save way and just use public static final int or String values

I'll check the first option by trying to map jakarta-commons-lang enums with hibernate. (I'll also have to check how this will behave in future with Java 5 enums)
Results will be posted here as soon as possible

Wednesday, January 19, 2005

Conainer Managed Auth. vs Application Managed Auth. in J2EE web applications

Authentication and Authorisation (Auth.) is part of the J2EE standard.

One design question that arises in each J2ee web application project is the wheter to use Conatiner Managed Auth. (CMA) or to impement own Application Managed Auth. (AMA).

CMA in pure web applications:
  • standard way for application to query if the user has given role
  • standard way to define how the user is authenticated (Basic authengication, Form-based authentication..)
on the other hand CMA
  • does not define how an application server stores and retrieves the authentication/authorsisation information (username/password, roles). This is left to the application server provider or to the application developer.
  • does not define how one plug in code into an application server to extend the authentication with more advanced authentication strategies (Captcha etc.)
  • does not define how to maintain the Authentication/Authorisation information (e.g. how a user could change his password or how an administrator can add/remove roles)
AMA :
  • is portable across application servers
  • can be customized to any extend (e.g. authentication based on dynamic information)
on the other Hand AMA:
  • introduces a security risk due to buggy implementation
  • is not standardized

Definitly - if all use cases can be implemented with CMA one shold use it. But how often is that the case in real world web applications?

References:

Sunday, January 16, 2005

UML 2.0: semantical difference between composition and aggregation

Associations are describing a set of tuples of typed instances.

In general there is no semantic difference between the instances paricipating in such a tuple. Very often though one of the instances is playing the special role of a whole whereous the others represent the parts of that whole. As an example take the association between companies and departments. Departments are part of a company. Such forms of whole-part associations are Aggregations and Compositions.

An Aggregation is adding semantic information to a general Association by defining which end is the whole and which is the part.
A Composition is an even stronger kind of aggregation. The instance that is composing the parts is responsible for the life-cycle of the parts i.e. a part can not live without the whole and a part can at a given time only be owned by one whole. (Nevertheless is it possible that the part can be passed to an other owner)

Aggregation and Composition are not represented sub types of a general Association in UML 2.0 as one could think at the first glance. Instead an attribute of an associations member properties of the type AggerationKind is controlling this aspect.

AggregationKind is an Enumeration with the following literals:
  • none
  • shared
  • composite

Saturday, January 15, 2005

UML 2.0: who owns properties

In UML 2.0 properties can be owned by ether a class or an association.

In case the property is owned by a class it is called attribute i.e. attribute is a role a property can take. There are two notations for attributes:
  1. as attribute inside a class
  2. as assiociation end (at the navigable end). The role name is the name of the attribute
Both notations are equivalent.

In case an association has an association end that is not navigable the property is not owned by the class at the association end but the association itself.

The navigability of an association end therefore detirmins the ownership of the property:










navigable property is owned by the class at opposite end (attribute)
not navigable property is owned by assiciation

Firefox ldif file processor for importing int windows address book

Firefox correctly encodes special characters like German "Umlaut" characters according to the LDIF RFC 2849.

In order to successfully import such ldif file into the windows address book the character encoding has to be changed from UTF-8 to iso-8859-1 (found by experiment):

  1. filter for lines with properties separated by double colon (instead of single colon)
  2. decode the value using Base64 decoder
  3. convert the byte stream into a character stream using a UTF-8 decoder
  4. convert the character stream into a byte stream using a ISO-8859-1 encoder
  5. encode the byte stream with a Base64 encoder

After this conversion the file can be succesfully imported into the windows address book.

Tuesday, January 11, 2005

Can Hibernate map one class to more than one table?

One restriction with Hibernate seems to be that one java class can be mapped to maximum one table.

Example:

Imagine a catalog of product objects which are cloned before they are assigned to an order.
This scenario can not be implemented with hibernate provided the ordered products should be persited into a separate table i.e. not the product-catalog table.

One solution for this might be to copy the catalog product objects into objects of an other class (maybe called LineItem). Objects of this class can then be mapped into an other table.

An other question is how to implement the different characteristics of different product-types:

Option 1: Each product-type is modelled as a sub-class (extension) of a base Product. Properties specific to a product-type are added to the sub class. Hibernate is supporting this model by allowing to map all sub-classes to one database table.
One specific sub-class of the product and therefore also a product-type is modelled as container for other products. This (bundle-) product can contain any type of other product object as child products.

Option 2: We have only one generic product class and the product-type is modelled as an enumerated value. Properties specific to a product-type are modelled as generic containers (e.g. one string value and one numeric value) which are to be interpreted diffently depending on the product-type. This generic product can also contain other product objects as child products (i.e. each type of a product can be a bundle product).

Conclusions:
Option 1 can be considered as "cleaner" object oriented design but probably also the more complicated solution. Especially when considering the above mentioned restriction of Hibernate (a class can not be mapped to more than one table). This would result in a duplicating the complete class hierarchy. Option 2 is a more generic but less strongly typed. As long as we can live with it's restrictions I consider this solution the one with lower implementation effert.

Monday, January 10, 2005

Howto extend xml schema types

Learned today how to extend XML schema types




<xs:complextype name="Payment">
<xs:sequence>
<xs:element name="paymentType" type="PaymentType">
</xs:element>
</xs:sequence>

<xs:complextype name="CardPayment">
<xs:complexcontent>
<xs:extension base="Payment">
</xs:extension>
</xs:complexcontent>
</xs:complextype>


Sunday, January 09, 2005

Moments in the year 2004

I was working for quite a while on a page Moments in the year 2004
Technically I tried to use css to the extend I know it at the moment.
I could not get around Javascript due to the 2 following reasons:
  1. Opening a new browser window without menu and toolbar
  2. hover effect when moving the mouse over the images
Optically I like it...


Windows Address Book import from ldif file

Still no solution found for importing the ldif file exported by Thunderbird into the Windows Address Book. Special characters (non-ASCII) are not imported correctly.
Searched a lot on the web today - without success.
Attributes starting with :: seem to be correctly encoded as UTF-8 byte stream and then base64-encoded. The Windows Adress Book can not read those entries correctly. Very annoying...