Comments (3)
Hi, it's always better to give a concrete example of what you're trying to achieve. As far as I understand, you want to start from an XSD schema that contains <xs:annotation>
tags, and then generate Java source code classes which contain the corresponding @Annotation
annotations.
Java classes can currently only be generated from WSDL files which contain embedded XML Schemas, using the utility script bin/wsimport.sh
. Create a bare minimum WSDL file with your schema as follows. Replace the MySchemaType
complex type definition with your own type definition(s) and store the file as /tmp/tmpservice.wsdl
.
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com/service/TestService" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" name="TestService" targetNamespace="http://example.com/service/TestService">
<wsdl:types>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://example.com/service/TestService" elementFormDefault="unqualified" targetNamespace="http://example.com/service/TestService" version="1.0">
<xs:element name="testIn" type="xs:anyType"/>
<xs:element name="testOut" type="xs:anyType"/>
<xs:complexType name="MySchemaType">
<xs:annotation>
<xs:documentation>Your documentation goes here...!</xs:documentation>
</xs:annotation>
<xs:sequence/>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="testOut">
<wsdl:part element="tns:testOut" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="testIn">
<wsdl:part element="tns:testIn" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="TestService">
<wsdl:operation name="test">
<wsdl:input message="tns:testIn" name="testIn">
</wsdl:input>
<wsdl:output message="tns:testOut" name="testOut">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="TestServiceSoapBinding" type="tns:TestService">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="test">
<soap:operation soapAction="" style="document"/>
<wsdl:input name="testIn">
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output name="testOut">
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="TestService">
<wsdl:port binding="tns:TestServiceSoapBinding" name="TestServiceImplPort">
<soap:address location="http://localhost:9001/TestService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Next, run these commands (from the directory where you cloned the jaxb-facets repository). I'm assuming that you are running a Unix operating system (e.g., Mac OS, Linux) and that you have Apache Maven (mvn
) installed.
mvn install # to compile and install the code in this repo
mkdir /tmp/tmpservice
./bin/wsimport.sh -keep -B-jaxb-facets -d /tmp/tmpservice /tmp/tmpservice.wsdl
This will generate (among other files, which you can ignore), the following file:
/tmp/tmpservice/com/example/service/testservice/MySchemaType.java
Take a look at the file and you will find the desired XSD annotations:
@XmlType(name = "MySchemaType")
@Annotation(documentation = @Documentation("Your documentation goes here...!"))
public class MySchemaType {
}
Good luck, and let me know how it goes... :)
from jaxb-facets.
Hi,
thanks for your answer. What I would like is to be able to add any type of annotation to a field of a class when generating the .java files from the xsd. The schema files are actually generated from a proprietary description of a binary format, which should then be parsed and serialized with preon (https://github.com/preon/preon).
So, for example, the original class with annotations would look like:
public class FooTest {
@BoundNumber(size="16", byteOrder = BigEndian)
public int foo;
@BoundString
public String world = "Hello World!";
}
The schema, including the annotations, could then be something along these lines:
<xs:complexType name="fooTest">
<xs:sequence>
<xs:element name="foo" type="xs:int">
<xs:annotation>
<xs:jannotation type=BoundNumber>
<param name="size" type="xs:string" value="16"/>
<param name="byteOrder" value="java:org.codehaus.preon.buffer.ByteOrder.BigEndian"/>
<xs:jannotation/>
</xs:annotation>
</xs:element>
<xs:element name="world" type="xs:string" minOccurs="0">
<xs:annotation>
<xs:jannotation type=BoundString/>
</xs:annotation>
</xs:sequence>
</xs:complexType>
Additionally, I would also like to add annotations for JPA mappings for each field of a class. As there is no webservice involved, a WSDL would not make much sense it that case.
In the meantime, I think I found what i was looking for: https://github.com/highsource/jaxb2-annotate-plugin
It seems this xjc plugin allows to define arbitrary annotations on Classe/Types and Fields/Elements, by using the xsd:appinfo tag. I will try it and report back on success.
Thank you a lot for your answer so far :)
from jaxb-facets.
Thanks for your detailed answer. jaxb2-annotate-plugin seems to provide what you're looking for. Feel free to come back here if it doesn't, then we can try to work something out... Closing this for now.
from jaxb-facets.
Related Issues (20)
- AnnotationLocation missing HOT 2
- compilation fails because of testutils pom HOT 1
- wsimport issue HOT 6
- Adding support for assertions HOT 3
- Support for JavaEE annotations HOT 8
- Using @Documentation annotation at field level causes @XmlSchemaType to be ignored HOT 2
- @Pattern annotation does not work nicely with @XmlID and @XmlIDREF HOT 6
- WARNING: Unable to get @MinOccurs annotation from type com.sun.xml.bind.v2.model.impl.TypeRefImpl@667de82c HOT 1
- Issue with @Facets and @XmlJavaTypeAdapter HOT 2
- mvn clean install with empty repository HOT 3
- Jaxb-Facets @MaxOccurs generated XML Schema validation not working HOT 2
- Which license HOT 4
- Spring boot 1.3.1 + jaxb-facets HOT 2
- Annotation generation HOT 4
- Any plans into getting facets into JDK's JAXB? HOT 5
- Working example with cxf-xjc-plugin
- appear NullPointerException HOT 1
- java.lang.NoClassDefFoundError: com/sun/tools/javac/code/Type$ClassType HOT 3
- Pushing facets support upstream HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jaxb-facets.