Hybris: Cannot create ProductBundle Item Type that extends ProductModel - sap-commerce-cloud

I wanted to implement custom dynamic attribute handler class for ProductBundle class, but it expects AbstractItemModel type instead of my ProductBundle:
public class BundlePriceAttributeHandler extends AbstractDynamicAttributeHandler<Double, ProductModel> {
It gives error: type argument ProductModel is not within bounds of type-variable MODEL hybris
Then I tried
<itemtype code="ProductBundle" autocreate="true" generate="true" extends="ProductModel">
<attributes>
<attribute qualifier="bundlePrice" type="java.lang.Double">
<persistence type="dynamic" attributeHandler="bundlePriceAttributeHandler"/>
</attribute>
</attributes>
</itemtype>
but, there is error YComposedType due to missing super type 'ProductModel' (even using de.hybris.platform.core.model.product.ProductModel)
if I try extend just "Product" my ProductBundle will extend just Product jalo class not ProductModel, and it will cause error: type argument ProductModel is not within bounds of type-variable MODEL hybris again.

As per this error
YComposedType due to missing super type 'ProductModel' (even using de.hybris.platform.core.model.product.ProductModel)
It is saying that type ProductModel is not available, and that's correct. This platform's default itemtype name is "product," not "ProductModel".
Naming convention follows as below:
so correct entry should be as below.
<itemtype code="ProductBundle" autocreate="true" generate="true" extends="Product">
<attributes>
<attribute qualifier="bundlePrice" type="java.lang.Double">
<persistence type="dynamic" attributeHandler="bundlePriceAttributeHandler"/>
</attribute>
</attributes>
</itemtype>
and attribute handler class :
package com.customer.attributeHandler;
import com.core.model.ProductBundleModel;
import de.hybris.platform.servicelayer.model.attribute.DynamicAttributeHandler;
public class BundlePriceAttributeHandler implements DynamicAttributeHandler<Double, ProductBundleModel> {
#Override
public Double get(ProductBundleModel model) {
//Random return
return model.getAverageRating();
}
#Override
public void set(ProductBundleModel model, Double aDouble) {
}
}
Bean entry as below:
<alias name="bundlePriceAttributeHandler" alias="bundlePriceAttributeHandler"/>
<bean class="com.customer.attributeHandler.BundlePriceAttributeHandler" id="bundlePriceAttributeHandler"/>

Related

Hybris: How to get the name of an enum from context?

this is my code:
public void onValidate(final Object o, final InterceptorContext ctx) throws InterceptorException
{
if (o instanceof ProductModel)
{
final ProductModel product = (ProductModel) o;
if (!ctx.isNew(product))
{
if (StringUtils.isEmpty(product.getCode()))
{
throw new InterceptorException("The Code must not be empty!");
}
if (StringUtils.isEmpty(product.getManufacturerName().toString()))
{
throw new InterceptorException("The ManufacturerName must not be empty!");
}
if (ctx.isModified(product, ProductModel.MANUFACTURERPRODUCTID)
|| ctx.isModified(product, ProductModel.MANUFACTURERNAME))
{
final boolean b = ProductLookupService.getProductforManufacturerName(product.getManufacturerName().toString());
...
}
I need the name of enum ManufacturerName to compare it with another String, but my genereted getManufacturerName returns me just the code.What are my options? Here are the -item.xml and my generated get method:
<enumtype code="ManufacturerName" generate="true" autocreate="true" dynamic="true"/>
<itemtype code="Product" generate="false" autocreate="false">
<attributes>
<attribute type="ManufacturerName" qualifier="manufacturerName" generate="true">
<description> </description>
<persistence type="property" />
</attribute>
...
</attributes>
and
/**
* <i>Generated method</i> - Getter of the <code>Product.ManufacturerName</code> attribute defined at extension <code>myextension</code>.
* #return the manufacturerName
*/
#Accessor(qualifier = "manufacturerName", type = Accessor.Type.GETTER)
public ManufacturerName getManufacturerName()
{
return getPersistenceContext().getPropertyValue(MANUFACTURERNAME);
}
Thanks again!
Use EnumerationService's getEnumerationName() method.
import de.hybris.platform.enumeration.EnumerationService;
...
private EnumerationService enumerationService;
...
// Returns current session language name
String name = enumerationService.getEnumerationName(product.getManufacturerName());
// Returns name for a given locale
String englishName = getEnumerationName(product.getManufacturerName(), Locale.ENGLISH);
...
#Required
public void setEnumerationService(EnumerationService enumerationService) {
this.enumerationService = enumerationService;
}
Spring declaration
<bean id="myClass" ...>
<property name="enumerationService" ref="enumerationService" />
</bean>

How to pass variable from xml to java class in mule?

I have a variable in the mule config xml, which I want to access in the Java file. How do I do that?
I find below ways:
use component
use transformer
use scripting such as groovy
I want to send that variable to java file, and I import it to database in java file.
my config is:
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns:cxf="http://www.mulesoft.org/schema/mule/cxf" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans" version="CE-3.3.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/cxf http://www.mulesoft.org/schema/mule/cxf/current/mule-cxf.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd ">
<set-variable variableName="remoteClientAddress"
value="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" />
<message-properties-transformer name="setProperty"
scope="session" doc:name="Message Properties">
<add-message-property key="remoteClientAddress"
value="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" />
</message-properties-transformer>
<flow name="service-cxf-wsdlfirstFlow1" doc:name="service-cxf-wsdlfirstFlow1">
<http:inbound-endpoint host="localhost" port="8085"
path="Weather/Service" exchange-pattern="request-response" doc:name="HTTP">
</http:inbound-endpoint>
<set-variable variableName="remoteClientAddress"
value="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" />
<message-properties-transformer doc:name="myproperty"
scope="session">
<add-message-property key="remoteClientAddress"
value="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" />
</message-properties-transformer>
<component doc:name="classTest" class="org.mule.example.scripting.IpClient" />
<logger
message="#[groovy:message.getInboundProperty('MULE_REMOTE_CLIENT_ADDRESS')]"
level="INFO" doc:name="Logger" />
<cxf:proxy-service payload="envelope" service="Weather"
wsdlLocation="http://wsf.cdyne.com/WeatherWS/Weather.asmx?wsdl"
namespace="http://ws.cdyne.com/WeatherWS/" validationEnabled="true"
doc:name="SOAP">
</cxf:proxy-service>
<copy-properties propertyName="SOAPAction" doc:name="Property" />
<cxf:proxy-client payload="body"
enableMuleSoapHeaders="true" doc:name="SOAP" />
<outbound-endpoint address="http://wsf.cdyne.com/WeatherWS/Weather.asmx"
exchange-pattern="request-response" doc:name="Generic">
</outbound-endpoint>
</flow>
My mule version is CE 3.3.0. I use component for define location of java class, but after running my project I have some error:
ERROR 2013-02-27 11:15:20,129 [[mule-sample_].connector.http.mule.default.receiver.02] org.mule.exception.DefaultMessagingExceptionStrategy:
Message : Failed to find entry point for component, the following resolvers tried but failed: [
CallableEntryPointResolver: Object "IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]}" does not implement required interface "interface org.mule.api.lifecycle.Callable"
ReflectionEntryPointResolver: Found too many possible methods on object "org.mule.example.scripting.IpClient" that accept parameters "{class java.lang.String}", Methods matched are "[public void org.mule.transformer.AbstractTransformer.setMimeType(java.lang.String) throws javax.activation.MimeTypeParseException, public final java.lang.Object org.mule.transformer.AbstractTransformer.transform(java.lang.Object) throws org.mule.api.transformer.TransformerException, public void org.mule.transformer.AbstractTransformer.setName(java.lang.String), public void org.mule.transformer.AbstractTransformer.setEncoding(java.lang.String)]"
AnnotatedEntryPointResolver: Component: IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]} doesn't have any annotated methods, skipping.
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
]
Code : MULE_ERROR-321
--------------------------------------------------------------------------------
Exception stack is:
1. Failed to find entry point for component, the following resolvers tried but failed: [
CallableEntryPointResolver: Object "IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]}" does not implement required interface "interface org.mule.api.lifecycle.Callable"
ReflectionEntryPointResolver: Found too many possible methods on object "org.mule.example.scripting.IpClient" that accept parameters "{class java.lang.String}", Methods matched are "[public void org.mule.transformer.AbstractTransformer.setMimeType(java.lang.String) throws javax.activation.MimeTypeParseException, public final java.lang.Object org.mule.transformer.AbstractTransformer.transform(java.lang.Object) throws org.mule.api.transformer.TransformerException, public void org.mule.transformer.AbstractTransformer.setName(java.lang.String), public void org.mule.transformer.AbstractTransformer.setEncoding(java.lang.String)]"
AnnotatedEntryPointResolver: Component: IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]} doesn't have any annotated methods, skipping.
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
] (org.mule.model.resolvers.EntryPointNotFoundException)
org.mule.model.resolvers.DefaultEntryPointResolverSet:52 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/model/resolvers/EntryPointNotFoundException.html)
--------------------------------------------------------------------------------
Root Exception stack trace:
org.mule.model.resolvers.EntryPointNotFoundException: Failed to find entry point for component, the following resolvers tried but failed: [
CallableEntryPointResolver: Object "IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]}" does not implement required interface "interface org.mule.api.lifecycle.Callable"
ReflectionEntryPointResolver: Found too many possible methods on object "org.mule.example.scripting.IpClient" that accept parameters "{class java.lang.String}", Methods matched are "[public void org.mule.transformer.AbstractTransformer.setMimeType(java.lang.String) throws javax.activation.MimeTypeParseException, public final java.lang.Object org.mule.transformer.AbstractTransformer.transform(java.lang.Object) throws org.mule.api.transformer.TransformerException, public void org.mule.transformer.AbstractTransformer.setName(java.lang.String), public void org.mule.transformer.AbstractTransformer.setEncoding(java.lang.String)]"
AnnotatedEntryPointResolver: Component: IpClient{this=1e68a2b, name='null', ignoreBadInput=false, returnClass=SimpleDataType{type=java.lang.Object, mimeType='*/*'}, sourceTypes=[]} doesn't have any annotated methods, skipping.
MethodHeaderPropertyEntryPointResolver: The required property "method" is not set on the event
]
at org.mule.model.resolvers.DefaultEntryPointResolverSet.invoke(DefaultEntryPointResolverSet.java:52)
at org.mule.component.DefaultComponentLifecycleAdapter.invoke(DefaultComponentLifecycleAdapter.java:343)
at org.mule.component.AbstractJavaComponent.invokeComponentInstance(AbstractJavaComponent.java:86)
+ 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)
As per the cod eoyu have given to add the property
<set-variable variableName="remoteClientAddress" value ="#[message.inboundProperties ['MULE_REMOTE_CLIENT_ADDRESS']]"/>
This sets the property into the mulemessage in the INVOCATION scope.
You can access the property in your IpClient component with the following line of code
msg.getProperty("remoteClientAddress", PropertyScope.INVOCATION);
EX:
#Override
public Object onCall(MuleEventContext eventContext) throws Exception {
MuleMessage msg = eventContext.getMessage();
String remClient = msg.getProperty("remoteClientAddress", PropertyScope.INVOCATION);
Hope this helps.
<message-properties-transformer name="myScope" scope="session">
<add-message-property key="remoteClientAddress"
value ="#[message.inboundProperties['MULE_REMOTE_CLIENT_ADDRESS']]" />
</message-properties-transformer>

test if JAXB generated field is required

I have a JAXB generated class PersonType with the properties name, phone, address. In the XSD I define that "phone" minoccurs="1".
How can I test programatically(i.e. via reflection, etc), in Java code, if the property "phone" is required or not in the XSD?
Later edit:
The JAXB generator creates a class without any "required", etc. attributes. So there's no annotation on the class or it's fields to indicate if it's required or not. However, there's the #XmlElement annotation on the field specifying the XSD equivalent element. So I guess the only solution is to inspect this annotation and then make an XPath or something against the XSD?
Thank you!
The #XmlElement annotation has a required property (false by default) that is used to indicate that an XML element is required (minOccurs > 0). You could use the java.lang.reflect APIs to get this value from the class.
XML Schema
In the XML schema below the foo element is required and the bar element is not.
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/schema"
xmlns:tns="http://www.example.org/schema"
elementFormDefault="qualified">
<complexType name="root">
<sequence>
<element name="foo" type="string"/>
<element name="bar" type="string" minOccurs="0"/>
</sequence>
</complexType>
</schema>
Generated Class
Below is the class that was generated from the XML schema. We see that the foo field is annotated with #XmlElement(required=true) anf the bar field is not.
#XmlAccessorType(XmlAccessType.FIELD)
#XmlType(name = "root", propOrder = {
"foo",
"bar"
})
public class Root {
#XmlElement(required = true)
protected String foo;
protected String bar;
}

JAXB (Moxy) XML Metadata mapping issue

I am trying to map the below interface using Moxy's XML Metadata extension. But when I try to load it, I am getting the below error. I can't add a public constructor to the AddressType as it is an enum.
My question is: Why is Moxy impl looking at AddressType even though I didn't specify in the xml metadata?
public interface TokenizedUnitedStatesAddress
{
class AddressType extends Enum
{
public static final AddressType STREET = new AddressType("street");
public static final AddressType PO_BOX = new AddressType("poBox");
public static final AddressType RURAL_ROUTE = new AddressType("ruralRoute");
public static AddressType getEnum(final String type)
{
return (AddressType) getEnum(AddressType.class, type);
}
protected AddressType(final String name)
{
super(name);
}
}
String getApartmentNumber();
//removed other getters for brevity
}
<xml-bindings xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.eclipse.org/eclipselink/xsds/persistence/oxm http://www.eclipse.org/eclipselink/xsds/eclipselink_oxm_2_4.xsd"
version="2.4" package-name="com.abc.ic.domain.country.us">
<java-types>
<java-type name="TokenizedUnitedStatesAddress">
<xml-root-element />
<xml-type
prop-order="StreetPreDirection StreetNumber StreetName StreetType StreetPostDirection UnitDesignator UnitNumber AddressLine1 AddressLine2 City State PostalCode CarrierRoute LengthAtAddress OwnershipStatus" />
<java-attributes>
<xml-element name="StreetPreDirection" java-attribute="preDirectional" />
<xml-element name="StreetNumber" java-attribute="houseNumber" />
<xml-element name="StreetName" java-attribute="streetName" />
<xml-element name="StreetType" java-attribute="streetType" />
<xml-element name="StreetPostDirection" java-attribute="postDirection" />
<xml-element name="UnitNumber" java-attribute="apartmentNumber" />
<xml-element name="AddressLine1" java-attribute="primaryAddress" />
<xml-element name="AddressLine2" java-attribute="secondaryAddress" />
<xml-element name="City" java-attribute="cityName" />
<xml-element name="State" java-attribute="stateAbbreviation" />
<xml-element name="PostalCode" java-attribute="zipCode" />
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
javax.xml.bind.JAXBException:
Exception Description: The class com.abc.ic.domain.country.us.TokenizedUnitedStatesAddress$AddressType requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported.
- with linked exception:
[Exception [EclipseLink-50001] (Eclipse Persistence Services - 2.4.0.v20120608-r11652): org.eclipse.persistence.exceptions.JAXBException
Exception Description: The class com.abc.ic.domain.country.us.TokenizedUnitedStatesAddress$AddressType requires a zero argument constructor or a specified factory method. Note that non-static inner classes do not have zero argument constructors and are not supported.]
at org.eclipse.persistence.jaxb.JAXBContext$TypeMappingInfoInput.createContextState(JAXBContext.java:908)
at org.eclipse.persistence.jaxb.JAXBContext.<init>(JAXBContext.java:157)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:170)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:157)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:117)
at org.eclipse.persistence.jaxb.JAXBContextFactory.createContext(JAXBContextFactory.java:107)
Mxoy impl still introspects the class even though XML is used to provide metadata. This is because, by design, the external mapping file is used to augment metadata supplied by annotations.
The issue however is that the commons-land Enum abstraction requires us to have a non-public single argument constructor for the enums. I fixed this issue by adding a public no-arg constructor that initializes a default enum. This is sufficient for my application. I've however created a bug which can be followed here.
Note: I also looked at the foctory-method option of Moxy but it requires an empty arg method as the factory method which is not the case in case of Enum.
I am a developer on the EclipseLink MOXy team, and I've been looking at this issue. You are correct as to why the AddressType class was introspected, and I see that you have a workaround.
Another solution would be to create an XmlAdapter that can convert between Apache Enum classes and their XML (string) representation, as follows:
import javax.xml.bind.annotation.adapters.XmlAdapter;
import org.apache.commons.lang.enums.Enum;
import enumbindings.TokenizedUnitedStatesAddress.AddressType;
public class ApacheEnumAdapter extends XmlAdapter<String, Enum> {
public ApacheEnumAdapter() {
}
#Override
public Enum unmarshal(String s) throws Exception {
return AddressType.getEnum(s);
}
#Override
public String marshal(Enum e) throws Exception {
if (null == e) {
return null;
}
return e.getName();
}
}
And then hook up the adapter in your bindings file like this:
...
<xml-element name="StreetType" java-attribute="streetType">
<xml-java-type-adapter value="enumbindings.ApacheEnumAdapter" />
</xml-element>
...
As far as the bug you entered, EclipseLink is actually behaving correctly in this situation, we do not do any special handling of Apache Commons classes and so a default no-arg constructor (or some other handling mechanism) is still required. However I will update your bug and change it to an enhancement request to support Apache Enums out of the box, and we will evaluate it.
Thanks,
Rick

JAXB-Eclipselink: Mapping abstract "getter" to XML

I am using the EclipseLink implementation (2.3) of JAXB to map POJOs to XML and encountering a problem with following usecase:
public abstract class A {
public abstract Set<X> getX();
// There is no setter
}
public class B extends A {
// Set via constructor
private Set<X> x;
#Override
public Set<X> getX();
}
I am defining the mapping itself completely in an external bindings-file, i set class A to be transient like so:
<java-type name="foo.A" xml-transient="true"/>
and for class B:
<java-type name="bar.B" xml-accessor-type="PROPERTY">
<xml-root-element name="B" />
<java-attributes>
<xml-element java-attribute="x" xml-path="..."/>
</java-attributes>
</java-type>
Now, upon marshalling i am getting the exception: "Duplicate Property named [x] found on class [bar.B]"
which in my opinion is coming from the abstract declaration in A, being inherited by B.
Setting the accessor-type for B to FIELD, gets rid of this error, unfortunately this is not an option because i do have an extra property in B to marshal which does not return a field but a calculated value, so i am stuck with PROPERTY (following works: setting accessor-type for B to FIELD and mapping the extra property with an #XmlPath annotation - but i dont want annotations in my code).
Being stuck with accessor-type PROPERTY for class B, my next attempt was:
<java-type name="foo.A" xml-accessor-type="NONE"/>
to prevent the abstract property from being inherited by B, which gets me:
Ignoring attribute [x] on class [bar.B] as no Property was generated for it.
Same is happening using this mapping:
<java-type name="foo.A" xml-accessor-type="PROPERTY">
<java-attributes>
<xml-transient java-attribute="x"/>
</java-attributes>
</java-type>
In both cases property 'x' is ignored.
I have really spent quite some time on this now - i cant imagine that its not possible to get this to work??
My workaround at the moment:
Leaving foo.A to be transient, specifying accessor-type FIELD for bar.B (which gets me property 'x' without problems) and mapping the extra property in B using an annotation in code.
But as mentioned before: I would like to solve this completely without annotations - anybody any idea? Blaise? :)
regards,
--qu
Note: I'm the EclipseLink JAXB (MOXy) lead and a member of the JAXB 2 (JSR-222) expert group.
You appear to have hit a bug. You can track our progress on this issue at the following link. I have provided additional details on this issue below:
https://bugs.eclipse.org/367886
Using Annotations
If you were going to map this use case with JAXB/MOXy annotations you could set #XmlAccessorType(XmlAccessType.NONE) on the A class and do something like:
A
package forum8727402;
import javax.xml.bind.annotation.*;
#XmlAccessorType(XmlAccessType.NONE)
public abstract class A {
public abstract String getX();
}
B
package forum8727402;
import javax.xml.bind.annotation.*;
import org.eclipse.persistence.oxm.annotations.XmlPath;
#XmlRootElement
public class B extends A {
#XmlPath("a/b/c/text()")
private String x;
public B() {
x = "Hello World";
}
#Override
public String getX() {
return x;
}
#XmlElement
public String getCalculatedValue() {
return "Calculated Value";
}
}
Demo
package forum8727402;
import javax.xml.bind.*;
public class Demo {
public static void main(String[] args) throws Exception {
JAXBContext jc = JAXBContext.newInstance(B.class);
B b = new B();
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(b, System.out);
}
}
Output
<?xml version="1.0" encoding="UTF-8"?>
<b>
<a>
<b>
<c>Hello World</c>
</b>
</a>
<calculatedValue>Calculated Value</calculatedValue>
</b>
Using MOXy's External Mapping File
oxm.xml
Below is a MOXy external mapping file that represents the equivalent of the previously shown annotations:
<?xml version="1.0" encoding="UTF-8"?>
<xml-bindings
xmlns="http://www.eclipse.org/eclipselink/xsds/persistence/oxm"
package-name="forum8727402">
<java-types>
<java-type name="A" xml-accessor-type="NONE"/>
<java-type name="B">
<xml-root-element/>
<java-attributes>
<xml-element java-attribute="x" xml-path="a/b/c/text()"/>
<xml-element java-attribute="calculatedValue"/>
</java-attributes>
</java-type>
</java-types>
</xml-bindings>
Demo
The code below demonstrates how to reference the mapping file:
package forum8727402;
import java.util.*;
import javax.xml.bind.*;
import org.eclipse.persistence.jaxb.JAXBContextFactory;
public class Demo {
public static void main(String[] args) throws Exception {
Map<String, Object> properties = new HashMap<String, Object>(1);
properties.put(JAXBContextFactory.ECLIPSELINK_OXM_XML_KEY, "forum8727402/oxm.xml");
JAXBContext jc = JAXBContext.newInstance(new Class[] {A.class, B.class}, properties);
B b = new B();
Marshaller marshaller = jc.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
marshaller.marshal(b, System.out);
}
}
Output
[EL Warning]: 2012-01-04 14:45:46.366--Ignoring attribute [x] on class [forum8727402.xml.B] as no Property was generated for it.
<?xml version="1.0" encoding="UTF-8"?>
<b>
<calculatedValue>Calculated Value</calculatedValue>
</b>

Resources