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
Related
I am having trouble finding faked Thread.Sleep in mscorlib.fakes library.
I am following direction at http://www.codewrecks.com/blog/index.php/2012/04/27/using-shims-in-visual-studio-11-to-test-untestable-code/
http://msdn.microsoft.com/en-us/library/d00bd51t(v=vs.100).aspx shows Thread.Sleep is in mscorlib so I added its fake but System.Threading.Fakes namespace doesn't contain ShimThread nor StubThread.
Thread is a sealed class but VS fake framework should be able to fake static method in sealed class.
This is very much possible. By default Fakes framework doesn't generate shims for most types (including types in System.Threading namespace) of mscorlib because Fakes framework itself makes use of mscorlib. So only a few of the types are shimmed,
However, you can configure this behavior by changing the mscorlib.fakes file added in your project.
<Fakes xmlns="http://schemas.microsoft.com/fakes/2011/">
<Assembly Name="mscorlib" Version="4.0.0.0"/>
<ShimGeneration>
<Add Namespace="System.Threading!"/>
</ShimGeneration>
</Fakes>
Now build the test project and you can see shims for types in the System.Threading namespace, including ShimThread.SleepInt32.
Read more about the .fakes xml file on this page
This is because the Shim framework cannot fake all .Net BCL classes in mscrolib and System, see: MSDN.
Unfortunately I couldn't find a list of types that aren't supported. But it seems, primarily types that are not pure CLR classes or need OS functionality (Thread, FileSystemWatcher, ...) are not supported at this time.
I am new to GWT. i have below line of code.
SomeClientServiceAsync someService = GWT.create(SomeClientService.class);
what does above line means and why cannot i use any other alternatives to instantiate it?
Please help me!
Thanks.
GWT.create is used for deferred binding. This allows you to supply different implementations of the same service based on the user's browser. See the following question:
Why use GWT.create() instead of new?
If you do not need to have multiple implementations of your service, just create it via new!
GWT works by creating a service just like RMI does. Here you are creating the service SomeClientService which resides in the client package. It contains all the functions that can be called server-side.
GWT.create works in different ways:
It tries to see if in the gwt.xml files there is no declaration of which implementation to use depending on a GWT property. This GWT property can be the well known user agent which in this case will have the effect of selecting different implementations for each browser, but it can also be used for other things, for example to disable logging (the fact that logging is enabled or not has nothing to do with in which browser it runs)
Example:
<replace-with class="com.x.app.client.ui.base.button.CustomSlicedButtonCellAppearance">
<when-type-is class="com.x.app.client.ui.base.button.CustomButtonCellAppearance" />
<when-property-is name="gxt.css3.enabled" value="false"/>
<when-property-is name="gxt.theme" value="themeName" />
</replace-with>
In this case it will use CustomSlicedButtonCellAppearance for a call to GWT.create(CustomButtonCellAppearance.class) only if css3 is not supported and for the given theme. Notice that "when-property-is" is optional, and if not supplied it will always use that implementation for the given interface.
It also looks for generators, in which case a new class is generated during GWT compilation (or in devmode) usually based on annotation that are present in the interface passed to the create method.
Example:
<generate-with class="org.fusesource.restygwt.rebind.RestServiceGenerator">
<when-type-assignable class="org.fusesource.restygwt.client.RestService" />
</generate-with>
In this case the RestServiceGenerator will generate code to submit the request.
Another example is how UIBinder works: besides using the annotations in the interface it also generates code based on what is inside the ui.xml file.
If no declaration matches the class/interface passed to the GWT.create method, then it will try to do a new on that class (in case of an interface it will fail).
Declarations in gwt.xml files can be overwritten by other declarations that are processed afterwards, so if you are using a module which declares a rule you can change that rule by declaring a new rule after the inherits declaration of the module containing the original declaration.
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?
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.
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".