[jboss-cvs] JBossAS SVN: r91494 - in projects/jboss-osgi: projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal and 6 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jul 21 06:05:54 EDT 2009


Author: thomas.diesler at jboss.com
Date: 2009-07-21 06:05:53 -0400 (Tue, 21 Jul 2009)
New Revision: 91494

Added:
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/CompanyType.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/ContactType.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/CourseBooking.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/JAXBTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/ObjectFactory.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/StudentType.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/booking.xml
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/booking.xsd
   projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/example-xml-jaxb.bnd
Modified:
   projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/JAXBService.java
   projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceImpl.java
   projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/DOMParserTestCase.java
   projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/SAXParserTestCase.java
Log:
[JBOSGI-95] Provide JAXB example

Modified: projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/JAXBService.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/JAXBService.java	2009-07-21 09:58:10 UTC (rev 91493)
+++ projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/JAXBService.java	2009-07-21 10:05:53 UTC (rev 91494)
@@ -41,26 +41,26 @@
     * 
     * @see {@link JAXBContext#newInstance(String)}
     */
-   JAXBContext newInstance(String contextPath) throws JAXBException;
+   JAXBContext newJAXBContext(String contextPath) throws JAXBException;
    
    /**
     * Obtain a new instance of a JAXBContext class. 
     * 
     * @see {@link JAXBContext#newInstance(String,ClassLoader,Map)}
     */
-   JAXBContext newInstance(String contextPath, Map<String,?> props) throws JAXBException;
+   JAXBContext newJAXBContext(String contextPath, Map<String,?> props) throws JAXBException;
    
    /**
     * Obtain a new instance of a JAXBContext class. 
     * 
     * @see {@link JAXBContext#newInstance(Class...)}
     */
-   JAXBContext newInstance(Class<?> ... classesToBeBound) throws JAXBException;
+   JAXBContext newJAXBContext(Class<?> ... classesToBeBound) throws JAXBException;
    
    /**
     * Obtain a new instance of a JAXBContext class. 
     * 
     * @see {@link JAXBContext#newInstance(Class[], Map)}
     */
-   JAXBContext newInstance(Class<?>[] classesToBeBound, Map<String,?> props) throws JAXBException;
+   JAXBContext newJAXBContext(Class<?>[] classesToBeBound, Map<String,?> props) throws JAXBException;
 }
\ No newline at end of file

Modified: projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceImpl.java
===================================================================
--- projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceImpl.java	2009-07-21 09:58:10 UTC (rev 91493)
+++ projects/jboss-osgi/projects/bundles/jaxb/trunk/src/main/java/org/jboss/osgi/jaxb/internal/JAXBServiceImpl.java	2009-07-21 10:05:53 UTC (rev 91494)
@@ -47,23 +47,23 @@
       this.bundle = bundle;
    }
 
-   public JAXBContext newInstance(String contextPath) throws JAXBException
+   public JAXBContext newJAXBContext(String contextPath) throws JAXBException
    {
-      return newInstance(contextPath, null);
+      return newJAXBContext(contextPath, null);
    }
 
-   public JAXBContext newInstance(String contextPath, Map<String, ?> props) throws JAXBException
+   public JAXBContext newJAXBContext(String contextPath, Map<String, ?> props) throws JAXBException
    {
       ClassLoader classLoader = BundleClassLoader.createClassLoader(bundle);
       return JAXBContext.newInstance(contextPath, classLoader, props);
    }
 
-   public JAXBContext newInstance(Class<?>... classesToBeBound) throws JAXBException
+   public JAXBContext newJAXBContext(Class<?>... classesToBeBound) throws JAXBException
    {
       return JAXBContext.newInstance(classesToBeBound);
    }
 
-   public JAXBContext newInstance(Class<?>[] classesToBeBound, Map<String, ?> props) throws JAXBException
+   public JAXBContext newJAXBContext(Class<?>[] classesToBeBound, Map<String, ?> props) throws JAXBException
    {
       return JAXBContext.newInstance(classesToBeBound, props);
    }

Modified: projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml	2009-07-21 09:58:10 UTC (rev 91493)
+++ projects/jboss-osgi/trunk/testsuite/example/scripts/antrun-test-jars.xml	2009-07-21 10:05:53 UTC (rev 91494)
@@ -62,6 +62,9 @@
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-simple.jar" files="${tests.resources.dir}/simple/example-simple.bnd" />
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-simple-husky.jar" files="${tests.resources.dir}/simple/example-simple-husky.bnd" />
     
+    <!-- xml/jaxb -->
+    <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-xml-jaxb.jar" files="${tests.resources.dir}/xml/jaxb/example-xml-jaxb.bnd" />
+    
     <!-- xml/parser -->
     <bnd classpath="${tests.classes.dir}" output="${tests.output.dir}/test-libs/example-xml-parser.jar" files="${tests.resources.dir}/xml/parser/example-xml-parser.bnd" />
     

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/CompanyType.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/CompanyType.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/CompanyType.java	2009-07-21 10:05:53 UTC (rev 91494)
@@ -0,0 +1,125 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2009.07.21 at 10:48:55 AM CEST 
+//
+
+
+package org.jboss.test.osgi.example.xml.jaxb;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for companyType complex type.
+ * 
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ * 
+ * <pre>
+ * &lt;complexType name="companyType">
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       &lt;sequence>
+ *         &lt;element name="address" type="{http://www.w3.org/2001/XMLSchema}anyType"/>
+ *         &lt;element ref="{}contact"/>
+ *       &lt;/sequence>
+ *       &lt;attribute name="name" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
+ * </pre>
+ * 
+ * 
+ */
+ at XmlAccessorType(XmlAccessType.FIELD)
+ at XmlType(name = "companyType", propOrder = {
+    "address",
+    "contact"
+})
+public class CompanyType {
+
+    @XmlElement(required = true)
+    protected Object address;
+    @XmlElement(required = true)
+    protected ContactType contact;
+    @XmlAttribute
+    protected String name;
+
+    /**
+     * Gets the value of the address property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link Object }
+     *     
+     */
+    public Object getAddress() {
+        return address;
+    }
+
+    /**
+     * Sets the value of the address property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link Object }
+     *     
+     */
+    public void setAddress(Object value) {
+        this.address = value;
+    }
+
+    /**
+     * Gets the value of the contact property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link ContactType }
+     *     
+     */
+    public ContactType getContact() {
+        return contact;
+    }
+
+    /**
+     * Sets the value of the contact property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link ContactType }
+     *     
+     */
+    public void setContact(ContactType value) {
+        this.contact = value;
+    }
+
+    /**
+     * Gets the value of the name property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Sets the value of the name property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setName(String value) {
+        this.name = value;
+    }
+
+}

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/ContactType.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/ContactType.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/ContactType.java	2009-07-21 10:05:53 UTC (rev 91494)
@@ -0,0 +1,119 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2009.07.21 at 10:48:55 AM CEST 
+//
+
+
+package org.jboss.test.osgi.example.xml.jaxb;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for contactType complex type.
+ * 
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ * 
+ * <pre>
+ * &lt;complexType name="contactType">
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       &lt;attribute name="name" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       &lt;attribute name="telephone" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       &lt;attribute name="email" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
+ * </pre>
+ * 
+ * 
+ */
+ at XmlAccessorType(XmlAccessType.FIELD)
+ at XmlType(name = "contactType")
+public class ContactType {
+
+    @XmlAttribute(required = true)
+    protected String name;
+    @XmlAttribute(required = true)
+    protected String telephone;
+    @XmlAttribute(required = true)
+    protected String email;
+
+    /**
+     * Gets the value of the name property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * Sets the value of the name property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setName(String value) {
+        this.name = value;
+    }
+
+    /**
+     * Gets the value of the telephone property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getTelephone() {
+        return telephone;
+    }
+
+    /**
+     * Sets the value of the telephone property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setTelephone(String value) {
+        this.telephone = value;
+    }
+
+    /**
+     * Gets the value of the email property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getEmail() {
+        return email;
+    }
+
+    /**
+     * Sets the value of the email property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setEmail(String value) {
+        this.email = value;
+    }
+
+}

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/CourseBooking.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/CourseBooking.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/CourseBooking.java	2009-07-21 10:05:53 UTC (rev 91494)
@@ -0,0 +1,217 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2009.07.21 at 10:48:55 AM CEST 
+//
+
+
+package org.jboss.test.osgi.example.xml.jaxb;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlSchemaType;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.datatype.XMLGregorianCalendar;
+
+
+/**
+ * <p>Java class for courseBooking complex type.
+ * 
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ * 
+ * <pre>
+ * &lt;complexType name="courseBooking">
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       &lt;sequence>
+ *         &lt;element ref="{}company"/>
+ *         &lt;element ref="{}student" maxOccurs="unbounded"/>
+ *       &lt;/sequence>
+ *       &lt;attribute name="courseReference" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       &lt;attribute name="courseDate" use="required" type="{http://www.w3.org/2001/XMLSchema}date" />
+ *       &lt;attribute name="invoiceReference" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       &lt;attribute name="totalPrice" use="required" type="{http://www.w3.org/2001/XMLSchema}decimal" />
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
+ * </pre>
+ * 
+ * 
+ */
+ at XmlAccessorType(XmlAccessType.FIELD)
+ at XmlType(name = "courseBooking", propOrder = {
+    "company",
+    "student"
+})
+public class CourseBooking {
+
+    @XmlElement(required = true)
+    protected CompanyType company;
+    @XmlElement(required = true)
+    protected List<StudentType> student;
+    @XmlAttribute(required = true)
+    protected String courseReference;
+    @XmlAttribute(required = true)
+    @XmlSchemaType(name = "date")
+    protected XMLGregorianCalendar courseDate;
+    @XmlAttribute(required = true)
+    protected String invoiceReference;
+    @XmlAttribute(required = true)
+    protected BigDecimal totalPrice;
+
+    /**
+     * Gets the value of the company property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link CompanyType }
+     *     
+     */
+    public CompanyType getCompany() {
+        return company;
+    }
+
+    /**
+     * Sets the value of the company property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link CompanyType }
+     *     
+     */
+    public void setCompany(CompanyType value) {
+        this.company = value;
+    }
+
+    /**
+     * Gets the value of the student property.
+     * 
+     * <p>
+     * This accessor method returns a reference to the live list,
+     * not a snapshot. Therefore any modification you make to the
+     * returned list will be present inside the JAXB object.
+     * This is why there is not a <CODE>set</CODE> method for the student property.
+     * 
+     * <p>
+     * For example, to add a new item, do as follows:
+     * <pre>
+     *    getStudent().add(newItem);
+     * </pre>
+     * 
+     * 
+     * <p>
+     * Objects of the following type(s) are allowed in the list
+     * {@link StudentType }
+     * 
+     * 
+     */
+    public List<StudentType> getStudent() {
+        if (student == null) {
+            student = new ArrayList<StudentType>();
+        }
+        return this.student;
+    }
+
+    /**
+     * Gets the value of the courseReference property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getCourseReference() {
+        return courseReference;
+    }
+
+    /**
+     * Sets the value of the courseReference property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setCourseReference(String value) {
+        this.courseReference = value;
+    }
+
+    /**
+     * Gets the value of the courseDate property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link XMLGregorianCalendar }
+     *     
+     */
+    public XMLGregorianCalendar getCourseDate() {
+        return courseDate;
+    }
+
+    /**
+     * Sets the value of the courseDate property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link XMLGregorianCalendar }
+     *     
+     */
+    public void setCourseDate(XMLGregorianCalendar value) {
+        this.courseDate = value;
+    }
+
+    /**
+     * Gets the value of the invoiceReference property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getInvoiceReference() {
+        return invoiceReference;
+    }
+
+    /**
+     * Sets the value of the invoiceReference property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setInvoiceReference(String value) {
+        this.invoiceReference = value;
+    }
+
+    /**
+     * Gets the value of the totalPrice property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link BigDecimal }
+     *     
+     */
+    public BigDecimal getTotalPrice() {
+        return totalPrice;
+    }
+
+    /**
+     * Sets the value of the totalPrice property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link BigDecimal }
+     *     
+     */
+    public void setTotalPrice(BigDecimal value) {
+        this.totalPrice = value;
+    }
+
+}

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/JAXBTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/JAXBTestCase.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/JAXBTestCase.java	2009-07-21 10:05:53 UTC (rev 91494)
@@ -0,0 +1,122 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.osgi.example.xml.jaxb;
+
+//$Id: DOMParserTestCase.java 91490 2009-07-21 08:39:45Z thomas.diesler at jboss.com $
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assume.assumeNotNull;
+
+import java.net.URL;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.jboss.osgi.husky.BridgeFactory;
+import org.jboss.osgi.husky.HuskyCapability;
+import org.jboss.osgi.husky.annotation.ProvideContext;
+import org.jboss.osgi.jaxb.JAXBCapability;
+import org.jboss.osgi.jaxb.JAXBService;
+import org.jboss.osgi.spi.testing.OSGiBundle;
+import org.jboss.osgi.spi.testing.OSGiRuntime;
+import org.jboss.osgi.spi.testing.OSGiTestHelper;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+
+/**
+ * A test that uses JAXB to read an XML document.
+ * 
+ * @author thomas.diesler at jboss.com
+ * @since 21-Jul-2009
+ */
+public class JAXBTestCase
+{
+   @ProvideContext
+   public static BundleContext context;
+   private static OSGiRuntime runtime;
+
+   @Before
+   public void beforeClass() throws Exception
+   {
+      // Only do this if we are not within the OSGi Runtime
+      if (context == null)
+      {
+         runtime = new OSGiTestHelper().getDefaultRuntime();
+         runtime.addCapability(new JAXBCapability());
+         runtime.addCapability(new HuskyCapability());
+
+         OSGiBundle bundle = runtime.installBundle("example-xml-jaxb.jar");
+         bundle.start();
+      }
+   }
+
+   @After
+   public void afterClass() throws Exception
+   {
+      // Only do this if we are not within the OSGi Runtime
+      if (context == null)
+         runtime.shutdown();
+   }
+
+   @Test
+   @SuppressWarnings("unchecked")
+   public void testUnmarshaller() throws Exception
+   {
+      // Tell Husky to run this test method within the OSGi Runtime
+      if (context == null)
+         BridgeFactory.getBridge().run();
+      
+      // Stop here if the context is not injected
+      assumeNotNull(context);
+
+      JAXBContext jaxbContext = getJAXBContext();
+      Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+      URL resURL = context.getBundle().getResource("booking.xml");
+      JAXBElement<CourseBooking> rootElement = (JAXBElement<CourseBooking>)unmarshaller.unmarshal(resURL.openStream());
+      assertNotNull("root element not null", rootElement);
+      
+      CourseBooking booking = rootElement.getValue();
+      assertNotNull("booking not null", booking);
+      
+      CompanyType company = booking.getCompany();
+      assertNotNull("company not null", company);
+      assertEquals("ACME Consulting", company.getName());
+   }
+
+   private JAXBContext getJAXBContext() throws JAXBException 
+   {
+      // This service gets registerd by the jboss-osgi-apache-xerces service
+      ServiceReference sref = context.getServiceReference(JAXBService.class.getName());
+      if (sref == null)
+         throw new IllegalStateException("JAXBService not available");
+      
+      JAXBService service = (JAXBService)context.getService(sref);
+      JAXBContext jaxbContext = service.newJAXBContext(getClass().getPackage().getName());
+      return jaxbContext;
+   }
+}
\ No newline at end of file

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/ObjectFactory.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/ObjectFactory.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/ObjectFactory.java	2009-07-21 10:05:53 UTC (rev 91494)
@@ -0,0 +1,114 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2009.07.21 at 10:48:55 AM CEST 
+//
+
+
+package org.jboss.test.osgi.example.xml.jaxb;
+
+import javax.xml.bind.JAXBElement;
+import javax.xml.bind.annotation.XmlElementDecl;
+import javax.xml.bind.annotation.XmlRegistry;
+import javax.xml.namespace.QName;
+
+
+/**
+ * This object contains factory methods for each 
+ * Java content interface and Java element interface 
+ * generated in the org.jboss.test.osgi.example.xml.jaxb package. 
+ * <p>An ObjectFactory allows you to programatically 
+ * construct new instances of the Java representation 
+ * for XML content. The Java representation of XML 
+ * content can consist of schema derived interfaces 
+ * and classes representing the binding of schema 
+ * type definitions, element declarations and model 
+ * groups.  Factory methods for each of these are 
+ * provided in this class.
+ * 
+ */
+ at XmlRegistry
+public class ObjectFactory {
+
+    private final static QName _Booking_QNAME = new QName("", "booking");
+    private final static QName _Student_QNAME = new QName("", "student");
+    private final static QName _Company_QNAME = new QName("", "company");
+    private final static QName _Contact_QNAME = new QName("", "contact");
+
+    /**
+     * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: org.jboss.test.osgi.example.xml.jaxb
+     * 
+     */
+    public ObjectFactory() {
+    }
+
+    /**
+     * Create an instance of {@link StudentType }
+     * 
+     */
+    public StudentType createStudentType() {
+        return new StudentType();
+    }
+
+    /**
+     * Create an instance of {@link CompanyType }
+     * 
+     */
+    public CompanyType createCompanyType() {
+        return new CompanyType();
+    }
+
+    /**
+     * Create an instance of {@link CourseBooking }
+     * 
+     */
+    public CourseBooking createCourseBooking() {
+        return new CourseBooking();
+    }
+
+    /**
+     * Create an instance of {@link ContactType }
+     * 
+     */
+    public ContactType createContactType() {
+        return new ContactType();
+    }
+
+    /**
+     * Create an instance of {@link JAXBElement }{@code <}{@link CourseBooking }{@code >}}
+     * 
+     */
+    @XmlElementDecl(namespace = "", name = "booking")
+    public JAXBElement<CourseBooking> createBooking(CourseBooking value) {
+        return new JAXBElement<CourseBooking>(_Booking_QNAME, CourseBooking.class, null, value);
+    }
+
+    /**
+     * Create an instance of {@link JAXBElement }{@code <}{@link StudentType }{@code >}}
+     * 
+     */
+    @XmlElementDecl(namespace = "", name = "student")
+    public JAXBElement<StudentType> createStudent(StudentType value) {
+        return new JAXBElement<StudentType>(_Student_QNAME, StudentType.class, null, value);
+    }
+
+    /**
+     * Create an instance of {@link JAXBElement }{@code <}{@link CompanyType }{@code >}}
+     * 
+     */
+    @XmlElementDecl(namespace = "", name = "company")
+    public JAXBElement<CompanyType> createCompany(CompanyType value) {
+        return new JAXBElement<CompanyType>(_Company_QNAME, CompanyType.class, null, value);
+    }
+
+    /**
+     * Create an instance of {@link JAXBElement }{@code <}{@link ContactType }{@code >}}
+     * 
+     */
+    @XmlElementDecl(namespace = "", name = "contact")
+    public JAXBElement<ContactType> createContact(ContactType value) {
+        return new JAXBElement<ContactType>(_Contact_QNAME, ContactType.class, null, value);
+    }
+
+}

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/StudentType.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/StudentType.java	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/jaxb/StudentType.java	2009-07-21 10:05:53 UTC (rev 91494)
@@ -0,0 +1,92 @@
+//
+// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, vJAXB 2.1.10 in JDK 6 
+// See <a href="http://java.sun.com/xml/jaxb">http://java.sun.com/xml/jaxb</a> 
+// Any modifications to this file will be lost upon recompilation of the source schema. 
+// Generated on: 2009.07.21 at 10:48:55 AM CEST 
+//
+
+
+package org.jboss.test.osgi.example.xml.jaxb;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * <p>Java class for studentType complex type.
+ * 
+ * <p>The following schema fragment specifies the expected content contained within this class.
+ * 
+ * <pre>
+ * &lt;complexType name="studentType">
+ *   &lt;complexContent>
+ *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
+ *       &lt;attribute name="firstName" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *       &lt;attribute name="surname" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
+ *     &lt;/restriction>
+ *   &lt;/complexContent>
+ * &lt;/complexType>
+ * </pre>
+ * 
+ * 
+ */
+ at XmlAccessorType(XmlAccessType.FIELD)
+ at XmlType(name = "studentType")
+public class StudentType {
+
+    @XmlAttribute(required = true)
+    protected String firstName;
+    @XmlAttribute(required = true)
+    protected String surname;
+
+    /**
+     * Gets the value of the firstName property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getFirstName() {
+        return firstName;
+    }
+
+    /**
+     * Sets the value of the firstName property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setFirstName(String value) {
+        this.firstName = value;
+    }
+
+    /**
+     * Gets the value of the surname property.
+     * 
+     * @return
+     *     possible object is
+     *     {@link String }
+     *     
+     */
+    public String getSurname() {
+        return surname;
+    }
+
+    /**
+     * Sets the value of the surname property.
+     * 
+     * @param value
+     *     allowed object is
+     *     {@link String }
+     *     
+     */
+    public void setSurname(String value) {
+        this.surname = value;
+    }
+
+}

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/DOMParserTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/DOMParserTestCase.java	2009-07-21 09:58:10 UTC (rev 91493)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/DOMParserTestCase.java	2009-07-21 10:05:53 UTC (rev 91494)
@@ -50,12 +50,12 @@
 import org.w3c.dom.Node;
 
 /**
- * A test that parses XML ducuments
+ * A test that uses a SAX parser to read an XML document.
  * 
  * @see http://www.osgi.org/javadoc/r4v41/org/osgi/util/xml/XMLParserActivator.html
  * 
  * @author thomas.diesler at jboss.com
- * @since 12-Feb-2009
+ * @since 21-Jul-2009
  */
 public class DOMParserTestCase
 {

Modified: projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/SAXParserTestCase.java
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/SAXParserTestCase.java	2009-07-21 09:58:10 UTC (rev 91493)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/java/org/jboss/test/osgi/example/xml/parser/SAXParserTestCase.java	2009-07-21 10:05:53 UTC (rev 91494)
@@ -48,12 +48,12 @@
 import org.xml.sax.helpers.DefaultHandler;
 
 /**
- * A test that parses XML ducuments
+ * A test that uses a SAX parser to read an XML document.
  * 
  * @see http://www.osgi.org/javadoc/r4v41/org/osgi/util/xml/XMLParserActivator.html
  * 
  * @author thomas.diesler at jboss.com
- * @since 12-Feb-2009
+ * @since 21-Jul-2009
  */
 public class SAXParserTestCase
 {

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/booking.xml
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/booking.xml	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/booking.xml	2009-07-21 10:05:53 UTC (rev 91494)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<booking xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <company name="ACME Consulting">
+    <address>10 Coyote Avenue, Arizona, USA</address>
+    <contact name="Duke" email="duke at acme.com" telephone="1234567890" />
+  </company>
+  <student firstName="Jane" surname="Dow" />
+  <student firstName="John" surname="Doe" />
+</booking>  

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/booking.xsd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/booking.xsd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/booking.xsd	2009-07-21 10:05:53 UTC (rev 91494)
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  This is taken from 
+  
+  "Java-XML mapping made easy with JAXB 2.0"
+  http://www.javaworld.com/javaworld/jw-06-2006/jw-0626-jaxb.html
+  
+  $ xjc src/test/resources/xml/jaxb/booking.xsd -p org.jboss.test.osgi.example.xml.jaxb -d src/test/java
+ 
+-->
+<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+  <xsd:element name="booking" type="courseBooking" />
+  <xsd:complexType name="courseBooking">
+    <xsd:sequence>
+      <xsd:element ref="company" />
+      <xsd:element ref="student" minOccurs="1" maxOccurs="unbounded" />
+    </xsd:sequence>
+    <xsd:attribute name="courseReference" type="xsd:string" use="required" />
+    <xsd:attribute name="courseDate" type="xsd:date" use="required" />
+    <xsd:attribute name="invoiceReference" type="xsd:string" use="required" />
+    <xsd:attribute name="totalPrice" type="xsd:decimal" use="required" />
+  </xsd:complexType>
+  <xsd:element name="student" type="studentType" />
+  <xsd:complexType name="studentType">
+    <xsd:attribute name="firstName" type="xsd:string" use="required" />
+    <xsd:attribute name="surname" type="xsd:string" use="required" />
+  </xsd:complexType>
+  <xsd:element name="company" type="companyType" />
+  <xsd:complexType name="companyType">
+    <xsd:sequence>
+      <xsd:element name="address" />
+      <xsd:element ref="contact" />
+    </xsd:sequence>
+    <xsd:attribute name="name" type="xsd:string" />
+  </xsd:complexType>
+  <xsd:element name="contact" type="contactType" />
+  <xsd:complexType name="contactType">
+    <xsd:attribute name="name" type="xsd:string" use="required" />
+    <xsd:attribute name="telephone" type="xsd:string" use="required" />
+    <xsd:attribute name="email" type="xsd:string" use="required" />
+  </xsd:complexType>
+</xsd:schema>  
\ No newline at end of file

Added: projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/example-xml-jaxb.bnd
===================================================================
--- projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/example-xml-jaxb.bnd	                        (rev 0)
+++ projects/jboss-osgi/trunk/testsuite/example/src/test/resources/xml/jaxb/example-xml-jaxb.bnd	2009-07-21 10:05:53 UTC (rev 91494)
@@ -0,0 +1,14 @@
+# bnd build -classpath target/test-classes -output target/test-libs/example-xml-jaxb.jar src/test/resources/xml/jaxb/example-xml-jaxb.bnd
+
+Bundle-SymbolicName: example-xml-jaxb
+
+# Export the package that contains the test case
+Export-Package: org.jboss.test.osgi.example.xml.jaxb
+
+Import-Package: com.sun.xml.bind.v2, javax.xml.bind*, javax.xml.datatype, javax.xml.namespace, \
+   org.jboss.osgi.husky*, org.jboss.osgi.jaxb, org.jboss.osgi.spi*, org.junit, org.osgi.framework
+
+Include-Resource: booking.xml, booking.xsd
+
+# Tell Husky that there are test cases in this package
+Test-Package: org.jboss.test.osgi.example.xml.jaxb




More information about the jboss-cvs-commits mailing list