XSLT: Sum of products from multiple nodes

The XSL method sum(/foo) sums the value of all foo nodes in current context. If you, however, want to sum the product between two or more nodes the sum(/foo * /bar) is not sufficient as the product does not return a nodeset and thus sum() fails.
I found one way to sum products of multiple nodes and is to construct a temporary variable with the products, convert that variable to a nodeset and the sum all nodes in that temporary node set.
The function that converts a variable to a nodeset seems to be XSLT specific and the solution below is for Xalan since we are using it in our app. If you are using MSXML you will have to change the namespace but the name of the function is the same.

Continue reading “XSLT: Sum of products from multiple nodes”

Concurrent calls to the same session object not allowed

That is the error you get if you are trying to access the same instance of a stateful session bean (SSB) with more than one thread.
Our reference to the stateful session bean is stored in the HttpSession object and passed to a stateless session facade. In our scenario the error occurs because we are using framesets in the web tier and up to three threads may be trying to access our SSB at once.
When the header and middle part of a web page request information from the SSB via the session facade, the container will then make three instances of the session facade available to serve each call but each of these instances is trying to access the same instance of the stateful session bean.
A quick search on Google (as always) showed this is a common problem but I was not able to find a quick solution. One of my colleagues suggested that I should try “synchronization” which I did with what seems until now a success.
In my session facade bean, I surround all accesses to the stateful session bean with synchronization blocks, locking on the SSB. This will prevent more than one thread accessing the SSB; once a thread has entered the SSB any additional threads will be queued.

public void submitText(TextTo text, TextSessionLocal textLocal) {
        log.debug("ENTER submitText(TextTo text, TextSessionLocal textLocal): "+text);
        synchronized (textLocal) {
            //set message data in SSB
            textLocal.setMsgTitle(text.getMsgTitle());
            .... more code
        }
        log.debug("EXIT submitText(TextTo text, TextSessionLocal textLocal));
}

One might ask what impact this may have on the performance. Because it will only be one single user that will be accessing the same instance of a SSB I don’t think the performance will be detoriated by much but later stress testing will show more.
Stateful session beans should be avoided if possible. Especially if purpose of it is for storing some HttpSession data, like intermediate steps in a shopping process. It is recommended then to store the partial information in the HttpSession and as a last step to use a stateless session bean to perform the business logic. Well, maybe next time 😉
Update 05/11/03
This QA about EJBs article from Sun is very related

I think we’d better throw some water at it

fire_place Last night was very cozy, to start with at least.
I, being the man in the cave, started a fire. After a small celebration that included me dancing around with raised arms and emitting guttural sounds, we went back to the vice of watching TV. Chumbo had prepared an exquisite cheese fondue and it felt so right due to the cold and rainy weather outside.
The problem started when the candles on the side of the fireplace started melting from the heat. A pool of melted wax was building up under the cast iron fire place and slowly caught fire. We got suspicious when flames started coming out from the sides.
“I think we’d better throw some water at it”, Chumbo said.
The thing is that water thrown at burning wax just infuriated it and for a moment I thought this would escalate. Fortunately, throwing even more water at the fire killed it.
Then again, killing the fire produced some seriously thick smoke so I hurried of to get the BBQ from outside to move the logs over to it and then rushed out again. There is nothing like some everyday excitement… living on the edge you know… always pushing the envelope and stuff 🙂
Oh, and when listening to a lighter to find out whether any gas is coming, make sure to “click” it before putting it close to your ear or else you will end up, like me, with fried ear hair.

FOR SALE: Delonghi Rapido Oil Filled Radiator

DelonghiRapido.gif After installing central heating and re-opening the fireplace, we will not be needing this fella anymore. It is almost new, used less than 30 times.
This 3kW Delonghi oil-filled radiator offers you warmth quickly and effectively thanks to its large surface area. With 7 heat settings, thermostat and frost protection. For complete portability the radiator is on wheels. H64.5 x W68 x D24.5cm.
Features:

  • Large surface area to transfer heat
  • Low surface temperature
  • 24 hour timer
  • Extra fast warm up
  • High speed convection

New price £130 (eg JohnLewis), our price: £75
UPDATE: SOLD

Chilly in Lodon

pumpkin.gifI will probably not put it better than was done at theThe Hiding Place but it is getting chilly in London. It feels like yesterday when I was cycling to work in shorts and t-shirt (during weekend of course due to dress code). Now dressing in the morning is a longer ritual including multiple layers of garments, a scarf, a hat and some gloves. At least it’s sunny and crisp.
Holiday tickets to Sweden and Brasil are booked so that’s one less thing to worry about (obrigado chumbo). If you are in the vicinity of Copenhagen, Helsingborg or Sao Paulo in late December then let me know!
A Halloween party is being planned. I don’t quite remember why but the theme will be porn (yes I said porn). I will be downloading some “material” later this week to create the right atmosphere at the party.
… and I can’t stop whistling two tunes from Kill Bill, Vol 1. It’s the Twisted Nerve by Bernard Herrman and Woo Hoo by 5.6.7.8s and it’s driving my colleges crazy :-D. “Watch the movie and sing-along with me”, I tell them.

Kill Bill, Vol. 1

Well this must be the most violent movie in a very, VERY long time. It’s not one of those psychologically violent movies where the scary images are in your mind. It is instead a movie filled with blood, spraying blood and congealed blood. It is not a movie for the fainthearted.
Nevertheless, it is a very captivating film mostly due to its chic soundtrack and heavy Japanese influence. Is it just me or is everything Japanese bizarrely cool.
The movie has the standard Tarantino-style irregular time line in which you are thrown in at the middle of the movie and only later you are revealed details about how things started. This time it is bit easier to follow since we are shown chapters and the number of next victim to be killed.
Apparently, making a two part movie started of as a joke when the movie running time was closing in to 3 hours but later it was not so funny anymore and the decision was made. To me it just seems to follow this years trend of sequels and sequels to sequels.
Kill Bill at IMDB

Wildlife photography III

insect
Canon EOS-5, Sigma 300 mm macro, f/5.6, Fuji Superia 100
This photo was taken by Carla. It is of an indigenous insect as it was hanging leisurely of the beautiful flower. It is not so much wild life photo as it is stunning composition and colours. I only wish I had taken it my self!
(This series of wildlife photographs is to highlight the Wildlife Photographer of the Year 2003 Award and exhibition).

java.io.Reader issues

I have developed an XML converter that is based on the Castor framework. It is quite simple as it takes certain Java objects (beans, collections and maps) and returns an XML representation.
Actually I have implemented it so it returns an InputSource which goes well with the next step in the process, the Xalan transformation.
The problem I am having is that the InputSource can only be used once whereas we would like to use it multiple times. At least once to log the converted XML and second time for the XSLT. As soon as the input source has been used for logging purposes of the XML, the internal reader is empty and I have not found any way of resetting it.
I see two solutions. Either redesign the XMLConverter to store the XML content internally in a different way or write a utility that copies the content of one reader to another reader, while it outputs the content.

Wildlife photography II


Canon EOS-5, Sigma 300 mm, f/5.6, UV Filter, Fuji Superia 200.
We were on a half day cruise along a river in Lengkawi, Malaysia. With us was a very knowledgeable biologists that was explaining about everything around us; from plants to eagle habits.
The highlight of the trip was following around 15 eagles circling around our boat. I felt I really pushed the EOS by using eye focusing, tracking and shutter-priority mode. See more eagle photos.
(This series of wildlife photographs is to highlight the Wildlife Photographer of the Year 2003 Award and exhibition).

I Am David by Anne Holm

iamdavid.jpgIf you have come here looking for information about the book I Am David by Anne Holm unfortunately this web site is about me, David Kaspar.
You can buy “I am David” at Amazon.com or Amazon.co.uk.
Or take some time to read my blog which is about the Internet, photography, gadgets and my daily ponderings.
David Kaspar
Update
Due to comment abuse, the comments have been disabled. Please use the I Am David by Anne Holm forum for any discussions.