4 Replies Latest reply: Jan 2, 2007 9:51 AM by 807607 RSS

    JAXB and SAML

    807607
      Hello,

      I am trying to use JAXB to unmarshal one of my xml files. The scheme I am using was provided to me (http://www.w3.org/TR/2002/REC-xmldsig-core-20020212/xmldsig-core-schema.xsd). However when I am going to unmarshal the xml file what type would I use here? I should not be using Object but I cannot find what type to use. If I can get past this little road bump I will be fine so any help would be great.
      private void unmarshal() throws JAXBException
      {
          Object  o = unmarshaler.unmarshal(xmlFile);
      }
        • 1. Re: JAXB and SAML
          807607
          I should not be using Object but I cannot find what type to use
          What type do you want it to be? Do you want to use the object?
          What type of object is unmarshaler?

          Please be more specific.
          • 2. Re: JAXB and SAML
            807607
            From the docs that I have read about unmarshalling you would use the generated class as the type. In the examples they show

            <item>
            <client>none</client>
            </item>

            and then the code would look like
            private void unmarshal() throws JAXBException
            {
            Item  i = (Item) unmarshaler.unmarshal(xmlFile);
            }
            and from there you can use the get methods to retrieve the data and such. However I cannot seem to take what I said above and use it with my signature file. I don't know what my "Item" would be. I have generated the classes, compiled, and included in classpath according to some jaxb docs. Everything stems back to I have a scheme (like in first post) what would my "Item" be?
            • 3. Re: JAXB and SAML
              807607
              Look here under the unmarshall methods. I don't know much about JAXB but this seems like it might have your answer.

              http://java.sun.com/webservices/docs/1.4/api/javax/xml/bind/Unmarshaller.html
              • 4. Re: JAXB and SAML
                807607
                The referenced document shows how to perform an unmarshal however I am just having an issue with identifying the "root" class that I should be using for the unmarshalled object. If i use the incorrect one I of course get a nice error like the one below. All the examples deal with plain ol' xml documents and I am using a SAML document. Pretty much an xml document with some added text like
                <ds:Signature> instead of the plain <Signature> and this is where I'm getting thrown. Something that is probably very easy to solve that I'm missing completely.

                Exception in thread "main" java.lang.ClassCastException: javax.xml.bind.JAXBElement