Ignoring some elements/classes in JAXB binding - jpa

I use Hyperjaxb to generate some classes with JPA annotations from XML schemas. I'd like to specify which elements from given schema xjc should generate. I can't change xsd file. I can modify only bindings.xjb. I tried to use hj:ignored, but without success.

Well, hj:ignored is the answer. It allows you to make Hyperjaxb ignore certain classes.
Here's an example:
<jaxb:bindings
node="xsd:complexType[#name='issue121Type']//xsd:element[#name='simpleCollection']">
<hj:ignored/>
</jaxb:bindings>
Customizations work in schema as well as via xjb files.
See this project for instance.
How does "without success" reveal itself?

Related

Passing input to optaplanner

I'm using MySql database for Passing input to optaplanner, im creating file similar to nurserostering in optaplanner. How many tables do i need to create if i need to pass the similar data in long01.xml
Am struck on this please do give me some ideas, its my school project.
Also why is this pattern used for
<Pattern ID="0" weight="1">
<PatternEntries>
<PatternEntry index="0">
<ShiftType>L</ShiftType>
<Day>Any</Day>
</PatternEntry>
<PatternEntry index="1">
<ShiftType>D</ShiftType>
<Day>Any</Day>
</PatternEntry>
</PatternEntries>
</Pattern>
The nurse rostering example has 2 XML formats:
import dir XML: defined by the research challenge. Converted to domain objects by the mapping code in the NurseRosteringImporter
unsolved dir XML: XStream serialized of the domain objects. So no explicit mapping code needed (beyond the #XStreamAlias annotations on the domain classes).
I believe you mention the import dir XML, but the system of the unsolved XML is far more interesting because it has minimal mapping code. NurseRosteringDAO reads/writes from unsolved XML. Following the same design, you can also read/write to a database, by using Hibernate-JPA instead of XStream:
Go to hibernate.org to learn Hibernate with JPA annotations. Basically, you'll add some JPA annotations (such as #Entity and #ManyToOne) on your domain objects and use an EntityManager(Factory) to read/write those from the database.

JAXB auto generated classes hierarchy

I'm generating java code based on various WSDL's. We have a different WSDL for every new version of the WebService that we release, each with its own namespace.
The thing is that normally the changes are minimal from one release to another, but I want to keep classes divided by namespace.
Is there a way to configure JAXB so that the auto generated classes implement a single interface/extend a single class, so I can refer to either of them without changing my code?
Dummy example:
WebService method: listScripts(ResultSize size);
Auto generated classes:
com.test.ws1.ResultSize
com.test.ws2.ResultSize
Both classes are exactly the same. Is there a way to arrange them in a class hierarchy so my code is isolated from changes in version numbers? i.e. a com.test.ResultSize interface implemented by both classes?
XJC has an extension for this purpose
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
jaxb:extensionBindingPrefixes="xjc"
jaxb:version="2.0">
<xs:annotation>
<xs:appinfo>
<jaxb:globalBindings>
<xjc:superClass name="com.mycompany.xml.UserRootObject"/>
</jaxb:globalBindings>
</xs:appinfo>
</xs:annotation>
.
.
.
</xs:schema>
For more information see:
http://jaxb.java.net/nonav/2.0.2/docs/vendorCustomizations.html
The schema annotations can also be supplied via an external bindings file. For an example see:
How do you customize how JAXB generates plural method names?
It turned out that I can use a plugin provided in the JAXB2 Basics package:
Inheritance plugin
With this plugin I can specify different super classes for my generated ones, although I couldn't make the auto generated enums to implement a given interface.
To use it in Maven it was a pain (I'm generating classes from a WSDL, not using JAXB directly), so I switched to an external Ant task as specified in this blog

How to define javax.validation.constraints.Size.List in my binding file using jaxb annotate and annox plugins?

I want to use JSR 303 Bean validation on my classes. My problem is that these classes are generated from schema. I am using the jaxb annotate plugin on my bindings file and was able to define simple validation annotations like #NotNull. My problem comes when I have to define multiple annotations of same type for different groups. javax.validation offers a solution for this using annotations like #Size.List{#Size...). How can I use jaxb-annotate and annox plugin to define annotations like those.
You can define nested annotations with Annox, it's no problem. In your case it will be something like:
In *.xjb file:
<annox:annotate>
<annox:annotate annox:class="javax.validation.constraints.Size$List">
<annox:annotate annox:field="value">
<annox:annotate annox:class="javax.validation.constraints.Size" .../>
</annox:annotate>
</annox:annotate>
</annox:annotate>
In schema:
<annox:annotate>
<c:Size$List xmlns:c="http://annox.dev.java.net/javax.validation.constraints">
<c:value>
<c:Size ... />
</c:value>
</c:Size$List>
</annox:annotate>
I haven't tested it, so the syntax may be a bit different.
See the Annox user guide an the Annotate plugin docs.

IBM Eclipse WSDL Editor: How do I include an external wsdl/schema?

I am trying to create Web Services from the Top-Down approach. I downloaded Eclipse and am using the WSDL gui editor in it to build my WSDL files.
I am splitting up my Services based on "modules". The Types I am adding to the WSDLs all need to reference common stuff, such as PersonEntity, AddressEntity, States enumeration (simple type), Countries enumeration (simple type), and AbstractEntity. Since those items are all common I created a seperate WSDL file (named Commons.wsdl) that contains the type information for those types.
I want to "import" that WSDL into my other WSDL files to use:
For example, I have an entity named RegistrationEntity which inherits from AbstractEntity and contains a PersonEntity as well as an AddressEntity. I'm not sure how to do this... I saw that the WSDL spec has "import" and "include" and am not sure which one to use. Also, how do I actually import (or include) the Commons.wsdl file so that I can use the Types defined within it?
Thanks!
Oh, and I'm not sure if I'm supposed to stick this stuff in a seperate WSDL but another type of file such as an xsd or something. I really wanna follow best practices so if that's the proper way to do it then I'd rather do that.
I found out that the problem I had was I was creating a WSDL file for my commons and using an inline scheme for that, rather than creating an XSD file to be imported by my other WSDLs.
So instead I just created an Commons.XSD as my "Common Schema".

XACML2 Schema Generation Error for .NET - Cannot use wildcards at the top level of a schema

Has anyone been able to successfully generate C# entity classes from XACML2 schema files? I am getting "Cannot use wildcards at the top level of a schema." I think this has something to do with xs:any elements. I have tried change the processContents="skip" (from "lax") but to no avail. I get this using WSCF Blue as well as xsd.exe.
Works perfectly for me using the version of xsd.exe that ships w/ VS 2010.
I have no problems running the Xacml3 schema through VS2010 XSD.exe, but I do see this "Cannot use wildcards at the top level of a schema" error when trying to process the Xacml2 schema with XSD.
XSD processes the Xacml2 Policy schema with no errors.
XSD reports this wildcard error when processing the Xacml2 Context schema.
The issue appears to be the combination of ##any and mixed="true" in the xacml-context:AttributeValueType schema definition. Other definitions of AttributeValueType in Xacml2 Policy schema and Xacml3 use an xs:complexContent wrapper around an ExpressionType extension, which in turn contains xs:any and xs:anyAttribute definitions. The Xacml2 context:AttributeValueType does not contain this wrapper.
Solution: Remove mixed="true" from the Xacml2 xacml-context:AttributeValueType definition and XSD will generate the correct class types for the schema. The generated AttributeValueType class will have properties for a list of elements and a list of attributes, which covers all the bases.