Why doesn't JAXB handle namespaced child elements properly? - java

I'm using JAXB with a CXF Web Service. When I pass:
<?xml version="1.0" ?><ns2:Optionen xmlns:ns2="http://test.at/ezustellung/global/20090501#">
<ns2:PdfAKonvertierung>true</ns2:PdfAKonvertierung><ns2:SignaturTyp>Adobe</ns2:SignaturTyp>
</ns2:Optionen>
to the Unmarshaller, the properties pdfAKonvertierung und signaturTyp are both null in my Object. But if I pass:
<?xml version="1.0" ?><ns2:Optionen xmlns:ns2="http://test.at/ezustellung/global/20090501#">
<PdfAKonvertierung>true</PdfAKonvertierung><SignaturTyp>Adobe</SignaturTyp>
</ns2:Optionen>
which is invalid, according to the CXF Validator and wikipedia (translation, haven't found that in english):
Child elements of an element with a namespace prefix do not automatically have the same namespace, they have to be prefixed with a namespace as well.
The properties are set accordingly. Can someone spot an error in my code, or have I found a bug in the JAXB implementation from Java 1.6?
For reference, here is my code:
public class JaxbTests {
#Test
public void testOptionen() throws JAXBException, SAXException, IOException {
JAXBContext context = JAXBContext.newInstance(Optionen.class);
Unmarshaller unmarshaller = context.createUnmarshaller();
ByteArrayInputStream is = new ByteArrayInputStream(
// Does not work
("<?xml version=\"1.0\" ?><ns2:Optionen xmlns:ns2=\"http://test.at/ezustellung/global/20090501#\">" +
"<ns2:PdfAKonvertierung>true</ns2:PdfAKonvertierung><ns2:SignaturTyp>Adobe</ns2:SignaturTyp>" +
"</ns2:Optionen>").getBytes());
// Works
// ("<?xml version=\"1.0\" ?><ns2:Optionen xmlns:ns2=\"http://test.at/ezustellung/global/20090501#\">" +
// "<PdfAKonvertierung>true</PdfAKonvertierung><SignaturTyp>Adobe</SignaturTyp>" +
// "</ns2:Optionen>").getBytes());
Optionen opts = ((Optionen) unmarshaller.unmarshal(is));
Assert.assertTrue(opts.isPdfAKonvertierung() == true);
Assert.assertEquals(SignaturTypType.ADOBE, opts.getSignaturTyp());
}
}
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "", propOrder = {
"pdfAKonvertierung",
"signaturTyp"
})
#XmlRootElement(name = "Optionen")
public class Optionen {
#XmlElement(name = "PdfAKonvertierung", defaultValue = "true")
protected Boolean pdfAKonvertierung;
#XmlElement(name = "SignaturTyp", defaultValue = "Adobe")
protected SignaturTypType signaturTyp;
public Optionen() {
System.out.println("Optionen created");
}
public Boolean isPdfAKonvertierung() {
return pdfAKonvertierung;
}
public void setPdfAKonvertierung(Boolean value) {
this.pdfAKonvertierung = value;
}
public SignaturTypType getSignaturTyp() {
return signaturTyp;
}
public void setSignaturTyp(SignaturTypType value) {
this.signaturTyp = value;
}
}
#XmlType(name = "SignaturTypType")
#XmlEnum
public enum SignaturTypType {
#XmlEnumValue("Adobe")
ADOBE("Adobe"), #XmlEnumValue("PDF-AS")
PDF_AS("PDF-AS");
private final String value;
SignaturTypType(String v) {
this.value = v;
}
public String value() {
return this.value;
}
public static SignaturTypType fromValue(String v) {
for (SignaturTypType c : SignaturTypType.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}
}
package-info.java:
#javax.xml.bind.annotation.XmlSchema(namespace = "http://test.at/ezustellung/global/20090501#")
package at.test.ezustellung.global._20090501_;

The solution (without modifying the generated classes) to the problem was to make sure that the
<xs:schema elementFormDefault="qualified">
attribute is present and to regenerate the jaxb mapping, so
that
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED
ends up in the package-info.java

It's a little bit difficult to read your incorrectly formatted code, but wouldn't it fix your problem if you declare your elements with the correct namespace, e.g. #XmlElement(namespace = "http://test.at/ezustellung/global/20090501#", name = "SignaturTyp", defaultValue = "Adobe")?

Related

How to parse whole XML document using SAX parser in Java

So Im pretty new to Java coming from C#! They are pretty similar programming languages, so im getting a hang of it quickly, but there is a problem I have been battling with for a while, that I hope you can help me solve!
So Im using my SAX parser to parse the XML document, and it works fine, but Im having problems parsing the whole xml document, and don't know how to parse the attribute value in the top element.
My xml document is as follows:
This is the code snippet where I believe the problem lies! This code works for parsing all of tecaj elements and their attributes/content values, but not "datum" attribute:
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
{
this.elementStack.push(qName);
CurrencyModel model = new CurrencyModel();
if("tecajnica".equals(qName))
{
if(attributes != null)
{
model.setDatum(attributes.getValue(0));
}
}
else if("tecaj".equals(qName))
{
if(attributes != null)
{
model.setOznaka(attributes.getValue(0));
model.setSifra(attributes.getValue(1));
}
}
this.objectStack.push(model);
}
So I have a model class that looks like this:
public class CurrencyModel
{
public String getDatum() {
return datum;
}
public void setDatum(String datum) {
this.datum = datum;
}
public String getOznaka() {
return oznaka;
}
public void setOznaka(String oznaka) {
this.oznaka = oznaka;
}
public String getSifra() {
return sifra;
}
public void setSifra(String sifra) {
this.sifra = sifra;
}
public double getValue() {
return value;
}
public void setValue(double value) {
this.value = value;
}
String datum;
String oznaka;
String sifra;
double value;
#Override
public String toString() {
return "CurrencyModel{" +
"datum=" + datum +
", oznaka='" + oznaka + '\'' +
", sifra='" + sifra + '\'' +
", value=" + value +
'}';
}
}
So each object of type CurrencyModel has its date property that is supposed to get the value of the attribute from its respected "tecajnica" element. It works for all of the other properties but "Datum". At first I was parsing it as Date type, but as that didn't work I tried parsing it as a String. Now it works without any errors, but always sets the object "Datum" property to null...
Output looks as follows:
Any help and suggestions will be much appreciated!!! Thank you in advance!
You can use JAXB parser instead of SAX, It converts each element tag into a Java objects and easily configurable too. But we need to create classes for each element tag in the XML file as mentioned in this article https://www.javatpoint.com/jaxb-tutorial
As per your data your root class will be like below:
package com.a.b.c;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
#XmlRootElement(name="DtecBs")
public class DtecBs {
private String datum;
private List<tecjnica> tecjnicaList;
#XmlAttribute
public String getDatum() {
return datum;
}
public void setDatum(String datum) {
this.datum = datum;
}
#XmlElement(name="tecjnica")
public List<tecjnica> getTecjnicaList() {
return tecjnicaList;
}
public void setTecjnicaList(List<tecjnica> tecjnicaList) {
this.tecjnicaList = tecjnicaList;
}
}
Following method helps to convert XML into JavaObject:
Required parameters are:
InputStream (Inputstream of the XML file)
Class (Class name of the root element in the XML com.a.b.c.DtecBs)
DtecBs dtecbsObj = (DtecBs)convertXmltoJavaObject(is,className);
public Object convertXmltoJavaObject(InputStream is, Class className) throws JAXBException, ParserConfigurationException, SAXException {
//Disable XXE
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
//Do unmarshall operation
Source xmlSource = new SAXSource(spf.newSAXParser().getXMLReader(),new InputSource(is));
JAXBContext jaxbContext = JAXBContext.newInstance(className);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
JAXBIntrospector ji = jaxbContext.createJAXBIntrospector();
return ji.getValue(jaxbUnmarshaller.unmarshal(xmlSource));
}

How do I get JAXB to choose enum?

I'm trying to convert the XML text to a Java object, but there is a number in the prQueryStatus XML attribute. The type of the Java field is an enum. Is there a way for JAXB to choose my enum?
Strxml:
<custom prQueryStatus="1" ></custom>
faulty row:
CustAttrPrQuery custom = (CustAttrPrQuery)XmlOperations.deserializeFromXML(CustAttrPrQuery.class, strXmlCustom);
XmlOperations.deserializeFromXML():
public static Object deserializeFromXML(Class obj, String strXml) {
Object result = null;
JAXBContext jaxbContext;
try {
jaxbContext = JAXBContext.newInstance(obj);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
StringReader reader = new StringReader(strXml);
result = unmarshaller.unmarshal(reader);
return result;
} catch (JAXBException e) {
return new String("-3 JAXB deSerialize Error");
}
}
CustAttrPrQuery:
#XmlAccessorType(javax.xml.bind.annotation.XmlAccessType.FIELD)
#XmlRootElement(name = CustAttrPrQuery.RootElement)
public class CustAttrPrQuery {
public final static String RootElement = "custom";
#javax.xml.bind.annotation.XmlAttribute
private PrQueryStatus prQueryStatus = PrQueryStatus.NONE;
public PrQueryStatus getPrQueryStatus() {
return prQueryStatus;
}
public void setPrQueryStatus(PrQueryStatus prQueryStatus) {
this.prQueryStatus = prQueryStatus;
}
}
enum:
public enum PrQueryStatus {
NONE,
ACIK,
TUMU
}
You need to annotate your enum type with #XmlEnum
and its constants with #XmlEnumValue,
so that JAXB will know how to map from XML attributes ("0", "1", "2") to the enum constants (NONE, ACIK, TUMU):
#XmlEnum
public enum PrQueryStatus {
#XmlEnumValue("0") NONE,
#XmlEnumValue("1") ACIK,
#XmlEnumValue("2") TUMU
}

JAXB generate nillable = "true" from java

it this a bug?
I need nillable = "true" in my xsd schema. The only way to generate such an element from my java code is to use #XmlElement(nillable = true), right? But in this case, I will not be able to take advantage of this definition, I will not be able to check if the element is set to nil. The method isNil() is in the JAXBElement wrapper class.
So, what are my options here - I want to generate nillable = "true" in my xsd schema AND be able to check if it is set from my java code.
I need nillable = "true" in my xsd schema. The only way to generate
such an element from my java code is to use #XmlElement(nillable =
true), right?
Yes.
But in this case, I will not be able to take advantage of this
definition, I will not be able to check if the element is set to nil.
The method isNil() is in the JAXBElement wrapper class.
You can do getFoo() == null to determine if it was null. If you are trying to determine if the null corresponds to an absent element or xsi:nil="true" then you will have to do more. A set won't be done for absent nodes so you can put logic in your setter to track if a set to null was done because of an element with xsi:nil="true.
#XmlElement(nillable=true)
public String getFooString() {
return fooString;
}
public void setFooString(String foo) {
this.fooString = foo;
this.setFoo = true;
}
If you don't want to have this extra logic (which doesn't help for marshalling anyways you need to leverage JAXBElement.
#XmlElementRef(name="fooJAXBElement")
public JAXBElement<String> getFooJAXBElement() {
return fooJAXBElement;
}
public void setFooJAXBElement(JAXBElement<String> fooJAXBElement) {
this.fooJAXBElement = fooJAXBElement;
}
Java Model
Root
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.*;
#XmlRootElement
#XmlType(propOrder={"fooString", "barString", "fooJAXBElement", "barJAXBElement"})
public class Root {
private String fooString;
private String barString;
private JAXBElement<String> fooJAXBElement;
private JAXBElement<String> barJAXBElement;
private boolean setFoo;
private boolean setBar;
#XmlElement(nillable=true)
public String getFooString() {
return fooString;
}
public void setFooString(String foo) {
this.fooString = foo;
this.setFoo = true;
}
public boolean isSetFooString() {
return setFoo;
}
#XmlElement(nillable=true)
public String getBarString() {
return barString;
}
public void setBarString(String bar) {
this.barString = bar;
this.setBar = true;
}
public boolean isSetBarString() {
return setBar;
}
#XmlElementRef(name="fooJAXBElement")
public JAXBElement<String> getFooJAXBElement() {
return fooJAXBElement;
}
public void setFooJAXBElement(JAXBElement<String> fooJAXBElement) {
this.fooJAXBElement = fooJAXBElement;
}
#XmlElementRef(name="barJAXBElement")
public JAXBElement<String> getBarJAXBElement() {
return barJAXBElement;
}
public void setBarJAXBElement(JAXBElement<String> barJAXBElement) {
this.barJAXBElement = barJAXBElement;
}
}
ObjectFactory
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.*;
import javax.xml.namespace.QName;
#XmlRegistry
public class ObjectFactory {
#XmlElementDecl(name="fooJAXBElement")
public JAXBElement<String> createFooJAXBElement(String string) {
return new JAXBElement<String>(new QName("fooJAXBElement"), String.class, string);
}
#XmlElementDecl(name="barJAXBElement")
public JAXBElement<String> createBarJAXBElement(String string) {
return new JAXBElement<String>(new QName("barJAXBElement"), String.class, string);
}
}
Demo
Below is a full example to demonstrate the concepts discussed above.
input.xml
This document contains 2 elements explicitly marked with xsi:nil="true" and 2 other mapped elements that are absent.
<?xml version="1.0" encoding="UTF-8"?>
<root>
<barString xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
<barJAXBElement xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
</root>
Demo
This demo code will read in the above XML and check whether the properties have been set as a result of the unmarshal.
import java.io.File;
import javax.xml.bind.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Root.class, ObjectFactory.class);
Unmarshaller unmarshaller = jc.createUnmarshaller();
File xml = new File("src/forum20076018/input.xml");
Root root = (Root) unmarshaller.unmarshal(xml);
System.out.println("Was fooString set? " + root.isSetFooString());
System.out.println("Was barString set? " + root.isSetBarString());
System.out.println("Was fooJAXBElement set? " + (root.getFooJAXBElement() != null));
System.out.println("Was barJAXBElement set? " + (root.getBarJAXBElement() != null));
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(root, System.out);
}
}
Output
Below is the output from running the demo code. We see that all the is set checks are correct, but that the output only fully matches the input for the JAXBElement properties.
Was fooString set? false
Was barString set? true
Was fooJAXBElement set? false
Was barJAXBElement set? true
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<fooString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<barString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
<barJAXBElement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>
</root>

xml:base in JAXB

I have some XML like this:
<root xml:base="http://www.example.com/foo">
<childElement someAttribute="bar/blort.html"/>
<childElement someAttribute="bar/baz/foo.html"/>
</root>
The schema for my XML defines someAttribute as being of type xs:anyURI
I want to use JAXB to unmarshall the XML into an object model a bit like this:
#XmlRootElement(name="root")
class Root {
#XmlElement(name="childElement")
private List<Child> _children;
}
class Child {
#XmlAttribute(name="someAttribute")
private URI _someAttribute;
}
I would like values of someAttribute to be resolved according to XML base, i.e. when I unmarshall the XML given above, I want the childrens' attributes to be resolved to java.net.URI instances with values http://www.example.com/foo/bar/blort.html and so on.
I was hoping a custom XmlAdapter would allow me to achieve the right result, but the XmlAdapter has no access to the surrounding context, in particular, the value of xml:base in effect at that point (note that this is not as simple as the most recent enclosing value of xml:base as xml:base can appear anywhere in the tree, and relative xml:bases must be resolved against their ancestors).
I'm using EclipseLink's MOXY implementation of JAXB, if it matters.
You can leverage an XMLStreamReader and an XmlAdapter to implement this use case:
UriAdapter
The UriAdapter is both an XmlAdapter for handling the URI property, and a StreamFilter that we will use to detect the xml:base attribute.
package forum9906642;
import java.net.URI;
import javax.xml.bind.annotation.adapters.*;
import javax.xml.stream.*;
public class UriAdapter extends XmlAdapter<String, URI> implements StreamFilter {
private String base = "";
public UriAdapter() {
}
public UriAdapter(String base) {
this.base = base;
}
public URI unmarshal(String string) throws Exception {
return new URI(base + '/' + string);
}
public String marshal(URI uri) throws Exception {
if("".equals(base)) {
return uri.toString();
} else {
URI baseURI = new URI(base);
return baseURI.relativize(uri).toString();
}
}
public boolean accept(XMLStreamReader reader) {
if(reader.isStartElement()) {
String newBase = reader.getAttributeValue("http://www.w3.org/XML/1998/namespace", "base");
if(null != newBase) {
base = newBase;
}
}
return true;
}
}
Demo
The code below demonstrates how to use all the pieces together:
package forum9906642;
import java.io.*;
import javax.xml.bind.*;
import javax.xml.stream.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Root.class);
UriAdapter uriAdapter = new UriAdapter();
XMLInputFactory xif = XMLInputFactory.newFactory();
XMLStreamReader xsr = xif.createXMLStreamReader(new FileReader("src/forum9906642/input.xml"));
xsr = xif.createFilteredReader(xsr, uriAdapter);
Unmarshaller unmarshaller = jc.createUnmarshaller();
unmarshaller.setAdapter(uriAdapter);
Root root = (Root) unmarshaller.unmarshal(xsr);
for(Child child : root.getChildren()) {
System.out.println(child.getSomeAttribute().toString());
}
Marshaller marshaller = jc.createMarshaller();
marshaller.setAdapter(uriAdapter);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(root, System.out);
}
}
Child
package forum9906642;
import java.net.URI;
import javax.xml.bind.annotation.*;
import javax.xml.bind.annotation.adapters.*;
#XmlAccessorType(XmlAccessType.FIELD)
class Child {
#XmlAttribute(name="someAttribute")
#XmlJavaTypeAdapter(UriAdapter.class)
private URI _someAttribute;
public URI getSomeAttribute() {
return _someAttribute;
}
public void setSomeAttribute(URI _someAttribute) {
this._someAttribute = _someAttribute;
}
}
Output
http://www.example.com/foo/bar/blort.html
http://www.example.com/foo/bar/baz/foo.html
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<root>
<childElement someAttribute="bar/blort.html"/>
<childElement someAttribute="bar/baz/foo.html"/>
</root>
I had a similar problem, but with nested xml:base (because of XInclude), so I ended up having to do this:
public class URIFixingUnmarshaller {
private final JAXBContext jaxb;
public URIFixingUnmarshaller(JAXBContext jaxb) {
this.jaxb = jaxb;
}
public <T> JAXBElement<T> unmarshal(SAXSource in, Class<T> as)
throws JAXBException {
CurrLocation curr = new CurrLocation(in.getXMLReader());
Unmarshaller u = jaxb.createUnmarshaller();
u.setListener(new URIUpdater(curr));
return u.unmarshal(new SAXSource(curr, in.getInputSource()), as);
}
private static class CurrLocation extends XMLFilterImpl {
private Locator curr;
public CurrLocation(XMLReader actual) {
setParent(actual);
}
#Override
public void setDocumentLocator(Locator to) {
super.setDocumentLocator(to);
this.curr = to;
}
String resolve(String uri) {
try {
URL base = new URL(curr.getSystemId());
URL absolute = new URL(base, uri);
return absolute.toString();
} catch (MalformedURLException probablyAlreadyAbsolute) {
return uri;
}
}
}
private static class URIUpdater extends Unmarshaller.Listener {
private final CurrLocation curr;
URIUpdater(CurrLocation curr) {
this.curr = curr;
}
#Override
public void afterUnmarshal(Object target, Object parent) {
if (target instanceof SomethingWithRelativeURI) {
SomethingWithRelativeURI casted = (SomethingWithRelativeURI) target;
casted.setPath(curr.resolve(casted.getPath()));
}
}
}
}

JAXB Avoid saving default values

Is there any way to make JAXB not save fields which values are the default values specified in the #Element annotations, and then make set the value to it when loading elements from XML that are null or empties? An example:
class Example
{
#XmlElement(defaultValue="default1")
String prop1;
}
Example example = new Example();
example.setProp1("default1");
jaxbMarshaller.marshal(example, aFile);
Should generate:
<example/>
And when loading
Example example = (Example) jaxbUnMarshaller.unmarshal(aFile);
assertTrue(example.getProp1().equals("default1"));
I am trying to do this in order to generate a clean XML configuration file, and make it better readable and smaller size.
Regars and thanks in advance.
You could do something like the following by leveraging XmlAccessorType(XmlAccessType.FIELD) and putting logic in the get/set methods:
Example
package forum8885011;
import javax.xml.bind.annotation.*;
#XmlRootElement
#XmlAccessorType(XmlAccessType.FIELD)
class Example {
private static final String PROP1_DEFAULT = "default1";
private static final String PROP2_DEFAULT = "123";
#XmlElement(defaultValue=PROP1_DEFAULT)
String prop1;
#XmlElement(defaultValue=PROP2_DEFAULT)
Integer prop2;
public String getProp1() {
if(null == prop1) {
return PROP1_DEFAULT;
}
return prop1;
}
public void setProp1(String value) {
if(PROP1_DEFAULT.equals(value)) {
prop1 = null;
} else {
prop1 = value;
}
}
public int getProp2() {
if(null == prop2) {
return Integer.valueOf(PROP2_DEFAULT);
}
return prop2;
}
public void setProp2(int value) {
if(PROP2_DEFAULT.equals(String.valueOf(value))) {
prop2 = null;
} else {
prop2 = value;
}
}
}
Demo
package forum8885011;
import javax.xml.bind.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(Example.class);
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
Example example = new Example();
example.setProp1("default1");
example.setProp2(123);
System.out.println(example.getProp1());
System.out.println(example.getProp2());
marshaller.marshal(example, System.out);
example.setProp1("FOO");
example.setProp2(456);
System.out.println(example.getProp1());
System.out.println(example.getProp2());
marshaller.marshal(example, System.out);
}
}
Output
default1
123
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<example/>
FOO
456
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<example>
<prop1>FOO</prop1>
<prop2>456</prop2>
</example>
For More Information
http://blog.bdoughan.com/2011/06/using-jaxbs-xmlaccessortype-to.html
For a programmatic solution, there's also good old Apache commons XmlSchema and you can check against the default value with XmlSchemaElement.getDefaultValue()
So with something like
XmlSchemaElement elem = schema.getElementByName(ELEMENT_QNAME);
String defval = elem.getDefaultValue();
you should be able to do what you need. Haven't tried it out in the end, because I needed a more direct solution, but I hope that helps.

Categories

Resources