5 Replies Latest reply on Nov 16, 2006 11:16 AM by cpob

    Problems getting the type of a node

    lelaub

      Hi there!

      I've encountered a problem, when trying to find out what type a specific node is.
      token.getNode() returns always an object type org.jbpm.graph.def.Node. casting it to it's actual subclass (i.e. Fork, Decision, etc) does not work (or i missunderstood something)
      I've made several tests, and checked my hibernate configuration (which i took unmodified from the starters kit). I am using starters-kit 3.1.1

      Does anyone have the similar problem?

      Thank you very much for your help,

      kind regards
      phil.

        • 1. Re: Problems getting the type of a node
          cpob

          Yeah, I've been burned by this recently too.

          However, if you do a .toString() on the object, it displays the proper class name with the name of the node in parens: 'EndState(End)'

          My ghetto fix around this was to .toString() and then parse the text until the first parenthesis.

          The to string just does a getClass().getName(), but if I do that straight off the object, it returns Node, but .toString() displays the right value.

          • 2. Re: Problems getting the type of a node
            olivier_debels

            Isn't the reason for this that you get a hibernate proxy for the node instead of the real Node. The class hierarchy is not known by this proxy. you can retrieve the real object and try typing there...

            public static Object getProxiedObject(Object proxy) {
             if (proxy instanceof HibernateProxy) {
             LazyInitializer initializer = ((HibernateProxy) proxy)
             .getHibernateLazyInitializer();
             return initializer.getImplementation();
             }
            
             return proxy;
             }
            


            • 3. Re: Problems getting the type of a node
              cpob

              Thanks, I'll give that a shot. I figured it was something like that, but I didn't have the time to figure out a real solution (eep). Though my fix is a hack, it works! ;)

              • 4. Re: Problems getting the type of a node
                lelaub

                Thanks Olivier, that really helped me and solved my problem.
                I wasn't aware of that, seems that I have to go over the books again :)

                cpob: Thanks for your reply, actually i prefer instanceof instead of substring ;) - but thank you anyway.

                • 5. Re: Problems getting the type of a node
                  cpob

                  Olivier, I used your method, and it works like a charm, thanks.

                  I'm now using the instanceof like a proper developer should ;)