[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] [MOXy] additional xpath support
|
Great! Thanks!
--Polly
Blaise Doughan wrote:
>
> Hi Polly,
>
> In general we recommend the SAXPlatform for performance reasons. The
> SAXPlatform is used by default in OXM including our JAXB and SDO
> implementations
>
> The DOMPlatform represents the approach taken to implement the first
> version of our object-to-XML runtime. Originally an XPath library was
> used to get all of the data from XML. As we worked on improving
> performance we added our own XPath engine, and eventually added event
> based processing represented by the SAXPlatform.
>
> Some reasons you may want to consider the DOMPlatform:
>
> * Advanced XPath support (unmarshalling only) for mappings. The
> javax.xml.xpath library (included since Java SE 5) is used to
> execute any XPaths not natively handled by EclipseLink MOXy.
> * Full access to DOM tree in XMLTransformationMapping, when the
> SAXPlatform is used you only have access to a sub-tree.
>
> -Blaise
>
> polly.c.chang wrote:
>> cool! Do you have any documentation that describes when users should
>> choose
>> SAXPlatform vs. DOMPlatform? I was using SAX because I thought the
>> DOMPlatform would be slower. Is that a concern or do you recommend that
>> everyone uses DOMPlatform?
>>
>> Thanks,
>> Polly
>>
>>
>> Blaise Doughan wrote:
>>
>>> Hi Polly,
>>>
>>> There is actually already unmarshal support for these types of XPaths if
>>> you use our DOMPlatform. I have attached an example, in this example
>>> one of the mappings has the following XPath:
>>>
>>>
>>> addressMapping.setXPath("//ns:customer/ns:phone-number/preceding-sibling::*[1]");
>>>
>>> Note you will need the fix for bug #298114, this fix will be available
>>> in the 2.0.1 and 2.1 nightly builds starting tomorrow (Dec 18).
>>>
>>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=298114
>>>
>>> -Blaise
>>>
>>> polly.c.chang wrote:
>>>
>>>> Hi,
>>>>
>>>> I don't believe that MOXy currently supports these two features:
>>>>
>>>> 1. Support for preceding-sibling and following-sibling axis. This is
>>>> necessary so that we can check for a following-sibling of an ID with
>>>> the
>>>> name VersionID.
>>>>
>>>> 2. Support for position() and false() functions.
>>>>
>>>> Would it be possible to add these?
>>>>
>>>> Thanks!
>>>> --Polly
>>>>
>>>>
>>>>
>>>>
>>>>
>>> /*******************************************************************************
>>> * Copyright (c) 1998, 2009 Oracle. All rights reserved.
>>> * This program and the accompanying materials are made available under
>>> the
>>> * terms of the Eclipse Public License v1.0 and Eclipse Distribution
>>> License v. 1.0
>>> * which accompanies this distribution.
>>> * The Eclipse Public License is available at
>>> http://www.eclipse.org/legal/epl-v10.html
>>> * and the Eclipse Distribution License is available at
>>> * http://www.eclipse.org/org/documents/edl-v10.php.
>>> *
>>> * Contributors:
>>> * bdoughan - December 17/2009 - 2.0.1 - Initial implementation
>>> ******************************************************************************/
>>> package org.eclipse.persistence.testing.oxm.mappings.advancedxpath;
>>>
>>> import org.eclipse.persistence.oxm.NamespaceResolver;
>>> import org.eclipse.persistence.oxm.XMLDescriptor;
>>> import org.eclipse.persistence.oxm.XMLLogin;
>>> import org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping;
>>> import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
>>> import org.eclipse.persistence.oxm.platform.DOMPlatform;
>>> import org.eclipse.persistence.sessions.Project;
>>>
>>> public class CustomerProject extends Project {
>>>
>>> public CustomerProject() {
>>> XMLLogin xmlLogin = new XMLLogin();
>>> xmlLogin.setDatasourcePlatform(new DOMPlatform());
>>> this.setDatasourceLogin(xmlLogin);
>>>
>>> this.addDescriptor(getCustomerDescriptor());
>>> this.addDescriptor(getAddressDescriptor());
>>> }
>>>
>>> private XMLDescriptor getCustomerDescriptor() {
>>> XMLDescriptor xmlDescriptor = new XMLDescriptor();
>>> xmlDescriptor.setJavaClass(Customer.class);
>>> xmlDescriptor.setDefaultRootElement("ns:customer");
>>>
>>> NamespaceResolver nsResolver = new NamespaceResolver();
>>> nsResolver.put("ns", "urn:example");
>>> xmlDescriptor.setNamespaceResolver(nsResolver);
>>>
>>> XMLCompositeObjectMapping addressMapping = new
>>> XMLCompositeObjectMapping();
>>> addressMapping.setAttributeName("address");
>>>
>>> addressMapping.setXPath("//ns:customer/ns:phone-number/preceding-sibling::*[1]");
>>> addressMapping.setReferenceClass(Address.class);
>>> xmlDescriptor.addMapping(addressMapping);
>>>
>>> return xmlDescriptor;
>>> }
>>>
>>> private XMLDescriptor getAddressDescriptor() {
>>> XMLDescriptor xmlDescriptor = new XMLDescriptor();
>>> xmlDescriptor.setJavaClass(Address.class);
>>>
>>> NamespaceResolver nsResolver = new NamespaceResolver();
>>> nsResolver.put("ns", "urn:example");
>>> xmlDescriptor.setNamespaceResolver(nsResolver);
>>>
>>> XMLDirectMapping streetMapping = new XMLDirectMapping();
>>> streetMapping.setAttributeName("street");
>>> streetMapping.setXPath("text()");
>>> xmlDescriptor.addMapping(streetMapping);
>>>
>>> return xmlDescriptor;
>>> }
>>>
>>> }
>>> /*******************************************************************************
>>> * Copyright (c) 1998, 2009 Oracle. All rights reserved.
>>> * This program and the accompanying materials are made available under
>>> the
>>> * terms of the Eclipse Public License v1.0 and Eclipse Distribution
>>> License v. 1.0
>>> * which accompanies this distribution.
>>> * The Eclipse Public License is available at
>>> http://www.eclipse.org/legal/epl-v10.html
>>> * and the Eclipse Distribution License is available at
>>> * http://www.eclipse.org/org/documents/edl-v10.php.
>>> *
>>> * Contributors:
>>> * bdoughan - December 17/2009 - 2.0.1 - Initial implementation
>>> ******************************************************************************/
>>> package org.eclipse.persistence.testing.oxm.mappings.advancedxpath;
>>>
>>> public class Address {
>>>
>>> private String street;
>>>
>>> public String getStreet() {
>>> return street;
>>> }
>>>
>>> public void setStreet(String street) {
>>> this.street = street;
>>> }
>>>
>>> public boolean equals(Object object) {
>>> try {
>>> if(null == object) {
>>> return false;
>>> }
>>> Address testAddress = (Address) object;
>>> if(null == street) {
>>> return null == testAddress.getStreet();
>>> } else {
>>> return street.equals(testAddress.getStreet());
>>> }
>>> } catch(ClassCastException e) {
>>> return false;
>>> }
>>> }
>>>
>>> public String toString() {
>>> String string = "Address(street=";
>>> if(null == street) {
>>> string += null;
>>> } else {
>>> string += "'" + street + "'";
>>> }
>>> return string += ")";
>>> }
>>>
>>> }
>>> /*******************************************************************************
>>> * Copyright (c) 1998, 2009 Oracle. All rights reserved.
>>> * This program and the accompanying materials are made available under
>>> the
>>> * terms of the Eclipse Public License v1.0 and Eclipse Distribution
>>> License v. 1.0
>>> * which accompanies this distribution.
>>> * The Eclipse Public License is available at
>>> http://www.eclipse.org/legal/epl-v10.html
>>> * and the Eclipse Distribution License is available at
>>> * http://www.eclipse.org/org/documents/edl-v10.php.
>>> *
>>> * Contributors:
>>> * bdoughan - December 17/2009 - 2.0.1 - Initial implementation
>>> ******************************************************************************/
>>> package org.eclipse.persistence.testing.oxm.mappings.advancedxpath;
>>>
>>> public class Customer {
>>>
>>> private Address address;
>>>
>>> public Address getAddress() {
>>> return address;
>>> }
>>>
>>> public void setAddress(Address address) {
>>> this.address = address;
>>> }
>>>
>>> public boolean equals(Object object) {
>>> try {
>>> if(null == object) {
>>> return false;
>>> }
>>> Customer testCustomer = (Customer) object;
>>> if(null == address) {
>>> return null == testCustomer.getAddress();
>>> } else {
>>> return address.equals(testCustomer.getAddress());
>>> }
>>> } catch(ClassCastException e) {
>>> return false;
>>> }
>>> }
>>>
>>> public String toString() {
>>> String string = "Customer(address=";
>>> if(null == address) {
>>> string += null;
>>> } else {
>>> string += address.toString();
>>> }
>>> return string += ")";
>>> }
>>>
>>> }
>>> <ns:customer xmlns:ns="urn:example">
>>> <ns:address>Wrong Street</ns:address>
>>> <ns:address>Right Street</ns:address>
>>> <ns:phone-number/>
>>> <ns:address>Wrong Street</ns:address>
>>> </ns:customer>
>>> _______________________________________________
>>> eclipselink-users mailing list
>>> eclipselink-users@xxxxxxxxxxx
>>> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>>>
>>>
>>>
>>
>>
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
>
--
View this message in context: http://old.nabble.com/-MOXy--additional-xpath-support-tp26822783p26848593.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.