diff --git a/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java b/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java index e73a8131d..08d81108c 100644 --- a/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java +++ b/processor/src/main/java/org/mapstruct/ap/prism/PrismGenerator.java @@ -18,6 +18,7 @@ */ package org.mapstruct.ap.prism; +import javax.xml.bind.annotation.XmlElementDecl; import net.java.dev.hickory.prism.GeneratePrism; import net.java.dev.hickory.prism.GeneratePrisms; @@ -39,7 +40,10 @@ import org.mapstruct.Mappings; @GeneratePrism(value = Mappings.class, publicAccess = true), @GeneratePrism(value = IterableMapping.class, publicAccess = true), @GeneratePrism(value = MapMapping.class, publicAccess = true), - @GeneratePrism(value = MappingTarget.class, publicAccess = true) + @GeneratePrism(value = MappingTarget.class, publicAccess = true), + + // external types + @GeneratePrism(value = XmlElementDecl.class, publicAccess = true) }) public class PrismGenerator { diff --git a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java index 60f22b2ab..f69526f95 100644 --- a/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java +++ b/processor/src/main/java/org/mapstruct/ap/processor/MapperCreationProcessor.java @@ -65,6 +65,7 @@ import org.mapstruct.ap.model.source.builtin.BuiltInMethod; import org.mapstruct.ap.option.Options; import org.mapstruct.ap.option.ReportingPolicy; import org.mapstruct.ap.prism.MapperPrism; +import org.mapstruct.ap.prism.XmlElementDeclPrism; import org.mapstruct.ap.util.Executables; import org.mapstruct.ap.util.Filters; import org.mapstruct.ap.util.Strings; @@ -583,9 +584,7 @@ public class MapperCreationProcessor implements ModelElementProcessor mapperReferences, - List methods, Type sourceType, Type targetType, + List methods, + Type sourceType, + Type targetType, + String targetPropertyName, String dateFormat) { // first try to find a matching source method - SourceMethod matchingSourceMethod = getBestMatch( method, mappedElement, methods, sourceType, targetType ); + SourceMethod matchingSourceMethod = getBestMatch( + method, + mappedElement, + methods, + sourceType, + targetType, + targetPropertyName + ); if ( matchingSourceMethod != null ) { return getMappingMethodReference( matchingSourceMethod, mapperReferences ); @@ -924,16 +940,20 @@ public class MapperCreationProcessor implements ModelElementProcessor T getBestMatch(SourceMethod mappingMethod, String mappedElement, - Iterable methods, Type parameterType, - Type returnType) { + private T getBestMatch(SourceMethod mappingMethod, + String mappedElement, + Iterable methods, + Type parameterType, + Type returnType, + String targetPropertyName) { List candidatesWithMathingTargetType = new ArrayList(); for ( T method : methods ) { @@ -965,6 +985,17 @@ public class MapperCreationProcessor implements ModelElementProcessor 1 ) { + + // OK, we have more candidats. Lets see if we can use additional criteria to determine which is better + T result = getBestMatchBasedOnXmlElementDecl( + candidatesWithMathingTargetType, + mappingMethod, + targetPropertyName + ); + if (result != null) { + return result; + } + messager.printMessage( Kind.ERROR, String.format( @@ -1177,4 +1208,39 @@ public class MapperCreationProcessor implements ModelElementProcessor can be SourceMethod or BuildInType. Only SourceMethods qualify + * @param candidates list with potential matches + * @param mapperMethod mapper method for which this is analyzed + * @param targetPropertyName the property name of the target + * @return a method (always SourceMethod) when there's a scope that matches + */ + private T getBestMatchBasedOnXmlElementDecl( + List candidates, + SourceMethod mapperMethod, + String targetPropertyName) { + for (T candidate : candidates ) { + if (candidate instanceof SourceMethod) { + SourceMethod candiateMethod = (SourceMethod) candidate; + XmlElementDeclPrism xmlElememtDecl = + XmlElementDeclPrism.getInstanceOn( candiateMethod.getExecutable() ); + if ( xmlElememtDecl != null ) { + String name = xmlElememtDecl.name(); + TypeMirror scope = xmlElememtDecl.scope(); + TypeMirror target = mapperMethod.getExecutable().getReturnType(); + if ( scope != null && typeUtils.isSameType( scope, target ) ) { + if ( ( name != null ) && ( name.equals( targetPropertyName ) ) ) { + return candidate; + } + } + } + } + } + return null; + } + } diff --git a/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/JaxbFactoryMethodSelectionTest.java b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/JaxbFactoryMethodSelectionTest.java new file mode 100644 index 000000000..032a184c5 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/JaxbFactoryMethodSelectionTest.java @@ -0,0 +1,78 @@ +/** + * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.jaxb.selection; + +import org.mapstruct.ap.test.jaxb.selection.test1.OrderType; +import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType; +import org.mapstruct.ap.test.jaxb.selection.test2.ObjectFactory; +import org.mapstruct.ap.testutil.IssueKey; +import org.mapstruct.ap.testutil.MapperTestBase; +import org.mapstruct.ap.testutil.WithClasses; + +import org.testng.annotations.Test; +import static org.fest.assertions.Assertions.assertThat; + +/** + * @author Sjaak Derksen + */ +@IssueKey("135") +@WithClasses({ org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.class, ObjectFactory.class, + OrderDto.class, OrderShippingDetailsDto.class, OrderType.class, OrderShippingDetailsType.class, + SourceTargetMapper.class +}) +public class JaxbFactoryMethodSelectionTest extends MapperTestBase { + + + @Test + public void shouldMatchOnNameAndOrScope() { + OrderType target = SourceTargetMapper.INSTANCE.targetToSource( createSource() ); + + // qname and value should match for orderNumbers (distinct 1, 2) + assertThat( target.getOrderNumber1().getValue() ).isEqualTo( 15L ); + assertThat( target.getOrderNumber1().getName() ).isEqualTo( + org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.ORDER_TYPE_ORDER_NUMBER1_QNAME ); + assertThat( target.getOrderNumber2().getValue() ).isEqualTo( 31L ); + assertThat( target.getOrderNumber2().getName() ).isEqualTo( + org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.ORDER_TYPE_ORDER_NUMBER2_QNAME ); + + // qname should match for shipping details + assertThat( target.getShippingDetails().getName() ).isEqualTo( + org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory.ORDER_TYPE_SHIPPING_DETAILS_QNAME ); + + OrderShippingDetailsType shippingDetals = target.getShippingDetails().getValue(); + + // qname and value should match (ObjectFactory = test2.ObjectFactory) + assertThat( shippingDetals.getOrderShippedFrom().getValue() ).isEqualTo( "from" ); + assertThat( shippingDetals.getOrderShippedFrom().getName() ).isEqualTo( + ObjectFactory.ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME ); + assertThat( shippingDetals.getOrderShippedTo().getValue() ).isEqualTo( "to" ); + assertThat( shippingDetals.getOrderShippedTo().getName() ).isEqualTo( + ObjectFactory.ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME ); + } + + private OrderDto createSource() { + OrderDto order = new OrderDto(); + order.setShippingDetails( new OrderShippingDetailsDto() ); + order.setOrderNumber1( 15L ); + order.setOrderNumber2( 31L ); + order.getShippingDetails().setOrderShippedFrom( "from" ); + order.getShippingDetails().setOrderShippedTo( "to" ); + return order; + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/OrderDto.java b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/OrderDto.java new file mode 100644 index 000000000..12af94779 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/OrderDto.java @@ -0,0 +1,56 @@ +/** + * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.jaxb.selection; + +/** + * + * @author Sjaak Derksen + */ +public class OrderDto { + + private Long orderNumber1; + private Long orderNumber2; + private OrderShippingDetailsDto shippingDetails; + + public Long getOrderNumber1() { + return orderNumber1; + } + + public void setOrderNumber1( Long orderNumber1 ) { + this.orderNumber1 = orderNumber1; + } + + public Long getOrderNumber2() { + return orderNumber2; + } + + public void setOrderNumber2( Long orderNumber2 ) { + this.orderNumber2 = orderNumber2; + } + + public OrderShippingDetailsDto getShippingDetails() { + return shippingDetails; + } + + public void setShippingDetails( OrderShippingDetailsDto shippingDetails ) { + this.shippingDetails = shippingDetails; + } + + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/OrderShippingDetailsDto.java b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/OrderShippingDetailsDto.java new file mode 100644 index 000000000..ea3e18111 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/OrderShippingDetailsDto.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.jaxb.selection; + +/** + * + * @author Sjaak Derksen + */ +public class OrderShippingDetailsDto { + + private String orderShippedFrom; + private String orderShippedTo; + + public String getOrderShippedFrom() { + return orderShippedFrom; + } + + public void setOrderShippedFrom( String orderShippedFrom ) { + this.orderShippedFrom = orderShippedFrom; + } + + public String getOrderShippedTo() { + return orderShippedTo; + } + + public void setOrderShippedTo( String orderShippedTo ) { + this.orderShippedTo = orderShippedTo; + } + + + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/SourceTargetMapper.java b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/SourceTargetMapper.java new file mode 100644 index 000000000..60ff5712d --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/SourceTargetMapper.java @@ -0,0 +1,48 @@ +/** + * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.mapstruct.ap.test.jaxb.selection; + +import javax.xml.bind.JAXBElement; +import org.mapstruct.Mapper; +import org.mapstruct.ap.test.jaxb.selection.test1.ObjectFactory; +import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType; +import org.mapstruct.ap.test.jaxb.selection.test1.OrderType; +import org.mapstruct.factory.Mappers; + +/** + * + * @author Sjaak Derksen + */ +@Mapper(uses = { ObjectFactory.class, + org.mapstruct.ap.test.jaxb.selection.test2.ObjectFactory.class } ) +public abstract class SourceTargetMapper { + + public static final SourceTargetMapper INSTANCE = Mappers.getMapper( SourceTargetMapper.class ); + + // target 2 source methods + public abstract OrderType targetToSource(OrderDto target); + public abstract OrderShippingDetailsType dtoToOrderShippingDetailsType(OrderShippingDetailsDto target); + + // TODO, remove this method when #134 is fixed + public JAXBElement dtoToOrderShippingDetailsTypeJB(OrderShippingDetailsDto target) { + ObjectFactory of1 = new ObjectFactory(); + return of1.createOrderTypeShippingDetails( INSTANCE.dtoToOrderShippingDetailsType( target ) ); + } +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test1/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test1/ObjectFactory.java new file mode 100644 index 000000000..6dcf30807 --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test1/ObjectFactory.java @@ -0,0 +1,71 @@ +/** + * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.jaxb.selection.test1; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; +import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType; + +@XmlRegistry +public class ObjectFactory { + + public static final QName ORDER_QNAME = + new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test1", "Order"); + public static final QName ORDER_TYPE_ORDER_NUMBER1_QNAME = + new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test1", "orderNumber1"); + public static final QName ORDER_TYPE_ORDER_NUMBER2_QNAME = + new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test1", "orderNumber2"); + public static final QName ORDER_TYPE_SHIPPING_DETAILS_QNAME = + new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test1", "shippingDetails"); + + + public ObjectFactory() { + } + + public OrderType createOrderType() { + return new OrderType(); + } + + @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", name = "Order") + public JAXBElement createOrder(OrderType value) { + return new JAXBElement(ORDER_QNAME, OrderType.class, null, value); + } + + @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", + name = "orderNumber1", scope = OrderType.class) + public JAXBElement createOrderTypeOrderNumber1(Long value) { + return new JAXBElement(ORDER_TYPE_ORDER_NUMBER1_QNAME, Long.class, OrderType.class, value); + } + + @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", + name = "orderNumber2", scope = OrderType.class) + public JAXBElement createOrderTypeOrderNumber2(Long value) { + return new JAXBElement(ORDER_TYPE_ORDER_NUMBER2_QNAME, Long.class, OrderType.class, value); + } + + @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", + name = "shippingDetails", scope = OrderType.class) + public JAXBElement createOrderTypeShippingDetails(OrderShippingDetailsType value) { + return new JAXBElement(ORDER_TYPE_SHIPPING_DETAILS_QNAME, + OrderShippingDetailsType.class, OrderType.class, value); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test1/OrderType.java b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test1/OrderType.java new file mode 100644 index 000000000..c9ba66f1e --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test1/OrderType.java @@ -0,0 +1,72 @@ +/** + * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.mapstruct.ap.test.jaxb.selection.test1; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlType; +import org.mapstruct.ap.test.jaxb.selection.test2.OrderShippingDetailsType; + + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "OrderType", propOrder = { + "orderNumber1", + "orderNumber2", + "shippingDetails" +}) +public class OrderType { + + @XmlElementRef(name = "orderNumber1", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", + type = JAXBElement.class) + private JAXBElement orderNumber1; + @XmlElementRef(name = "orderNumber2", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", + type = JAXBElement.class) + private JAXBElement orderNumber2; + @XmlElementRef(name = "shippingDetails", namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test1", + type = JAXBElement.class) + private JAXBElement shippingDetails; + + public JAXBElement getOrderNumber1() { + return orderNumber1; + } + + public void setOrderNumber1(JAXBElement value) { + this.orderNumber1 = value; + } + + public JAXBElement getOrderNumber2() { + return orderNumber2; + } + + public void setOrderNumber2(JAXBElement value) { + this.orderNumber2 = value; + } + + public JAXBElement getShippingDetails() { + return shippingDetails; + } + + public void setShippingDetails(JAXBElement value) { + this.shippingDetails = value; + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test2/ObjectFactory.java b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test2/ObjectFactory.java new file mode 100644 index 000000000..c6764037a --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test2/ObjectFactory.java @@ -0,0 +1,64 @@ +/** + * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.mapstruct.ap.test.jaxb.selection.test2; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; + +@XmlRegistry +public class ObjectFactory { + + public static final QName ORDER_SHIPPING_DETAILS_QNAME = + new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test2", "OrderShippingDetails"); + public static final QName ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME = + new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test2", "orderShippedFrom"); + public static final QName ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME = + new QName("http://www.mapstruct.org/ap/test/jaxb/selection/test2", "orderShippedTo"); + + public ObjectFactory() { + } + + public OrderShippingDetailsType createOrderShippingDetailsType() { + return new OrderShippingDetailsType(); + } + + + @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "OrderShippingDetails") + public JAXBElement createOrderShippingDetails(OrderShippingDetailsType value) { + return new JAXBElement(ORDER_SHIPPING_DETAILS_QNAME, + OrderShippingDetailsType.class, null, value); + } + + @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "orderShippedFrom", + scope = OrderShippingDetailsType.class) + public JAXBElement createOrderShippingDetailsTypeOrderShippedFrom(String value) { + return new JAXBElement(ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_FROM_QNAME, String.class, + OrderShippingDetailsType.class, value); + } + + @XmlElementDecl(namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", name = "orderShippedTo", + scope = OrderShippingDetailsType.class) + public JAXBElement createOrderShippingDetailsTypeOrderShippedTo(String value) { + return new JAXBElement(ORDER_SHIPPING_DETAILS_TYPE_ORDER_SHIPPED_TO_QNAME, String.class, + OrderShippingDetailsType.class, value); + } + +} diff --git a/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test2/OrderShippingDetailsType.java b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test2/OrderShippingDetailsType.java new file mode 100644 index 000000000..b696b238b --- /dev/null +++ b/processor/src/test/java/org/mapstruct/ap/test/jaxb/selection/test2/OrderShippingDetailsType.java @@ -0,0 +1,59 @@ +/** + * Copyright 2012-2014 Gunnar Morling (http://www.gunnarmorling.de/) + * and/or other contributors as indicated by the @authors tag. See the + * copyright.txt file in the distribution for a full listing of all + * contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.mapstruct.ap.test.jaxb.selection.test2; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlElementRef; +import javax.xml.bind.annotation.XmlType; + + +@XmlAccessorType(XmlAccessType.FIELD) +@XmlType(name = "OrderShippingDetailsType", propOrder = { + "orderShippedFrom", + "orderShippedTo" +}) +public class OrderShippingDetailsType { + + @XmlElementRef(name = "orderShippedFrom", + namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", type = JAXBElement.class) + private JAXBElement orderShippedFrom; + @XmlElementRef(name = "orderShippedTo", + namespace = "http://www.mapstruct.org/ap/test/jaxb/selection/test2", type = JAXBElement.class) + private JAXBElement orderShippedTo; + + public JAXBElement getOrderShippedFrom() { + return orderShippedFrom; + } + + public void setOrderShippedFrom(JAXBElement value) { + this.orderShippedFrom = value; + } + + public JAXBElement getOrderShippedTo() { + return orderShippedTo; + } + + public void setOrderShippedTo(JAXBElement value) { + this.orderShippedTo = value; + } + +}