XJC scope within XJB binding file - binding

I got XJB binding file where I want to replace ALL dates with java.util.Date and I would like one specific element (with name 'MyElementName') to extend my custom class:
My XJB file:
<jaxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
jaxb:version="2.0">
<!-- replace JAXBElement with real object where nillable="true" and minOccurs="0" -->
<jaxb:globalBindings generateElementProperty="false">
<!-- replace all dates with java.util.Date -->
<jaxb:javaType xmlType="xsd:dateTime" name="java.util.Date"
parseMethod="cz.i.sdp.nsessapi.util.DataTypeConverter.parseDateTime"
printMethod="cz.i.sdp.nsessapi.util.DataTypeConverter.printDateTime"/>
<jaxb:javaType xmlType="xsd:date" name="java.util.Date"
parseMethod="cz.i.sdp.nsessapi.util.DataTypeConverter.parseDateTime"
printMethod="cz.i.sdp.nsessapi.util.DataTypeConverter.printDateTime"/>
<jaxb:javaType xmlType="xsd:time" name="java.util.Date"
parseMethod="cz.i.sdp.nsessapi.util.DataTypeConverter.parseDateTime"
printMethod="cz.i.sdp.nsessapi.util.DataTypeConverter.printDateTime"/>
</jaxb:globalBindings>
<!-- Only element with name 'MyElementName' should extend
<jaxb:bindings schemaLocation="mySchema.xsd">
<jaxb:bindings node="//xs:element[#name='MyElementName']">
<xjc:superClass name="net.test.Whatever"/>
</jaxb:bindings>
</jaxb:bindings>
</jaxb:bindings>
The XJC enhancements will be silently ignored unless they are inside <globalBindings>. But then all generated classes will extend my custom class and I don't want that.
Is there a way to specify global bindings together with "scoped" bindings?
In here is mentioned "Global Scope", "Schema scope", "Definition Scope" and "Component scope" and they say "pecifically, declarations towards the top of the pyramid inherit and supersede declarations below them".

Related

Teiid User Defined Java Functions not visible

I am using teiid-wildfly servers. I followed the user defined functions example provided in teiid documentation. Below is my vdb file. Please let me know if I need to import any additional properties to view/access user defined functions. Metadata URL(http://localhost:8080/odata4/UDFTest/JavaCall/$metadata) does not list user defined function and no error in the server log. I created jar file which contains TempConv file implementation and completed the setup under module directory.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<vdb name="UDFTest" version="1">
<property name ="lib" value ="org.test"></property>
<model visible="true" name="JavaCall" type="VIRTUAL">
<metadata type="DDL">
<![CDATA[
CREATE VIRTUAL FUNCTION celsiusToFahrenheit(celsius double) RETURNS double OPTIONS (JAVA_CLASS 'org.test.TempConv', JAVA_METHOD 'celsiusToFahrenheit');
]]> </metadata>
</model>
</vdb>
OData has a known issue with exposing functions: see https://issues.redhat.com/browse/TEIID-5736
The workaround would be to use a procedure instead.

How do I get IDE code completion to work with JSF 2.2 non-composite component attributes?

Problem: I get code completion on the tags but not the attributes.
I am working on a new web application using
Java 8
JSF 2.2.14
PrimeFaces 6.1
Netbeans 8.2
We are using a library that is provided to us in JavaScript (generated from Typescript sources). I have written a non-composite component to wrap this library and keep all that JavaScript code hidden and in one place. It initializes the the library and provides attributes to pass JavaScript callback functions to the library (so we still have to write some JavaScript).
snippet from the JSF .xhtml file
<script type="text/javascript">
function jscallbackHandler() { alert("function called!");}
</script>
<myComponent:initialize callback1="jscallbackHandler" />
This tag invokes my class to write a lot of JavaScript into the page to setup and initialize the library.
I am using the #FacesComponent annotation to declare my classes as custom components.
snippet from 'InitMyComponent.java' file
#FacesComponent(createTag = true,
tagName = "initialize",
namespace = "https://com.my.project/myComponent",
value = InitMyComponent.FAMILY)
public class InitMyComponent extends UIComponentBase { ... }
This is working except for IDE code completion and I can't find documentation or examples for JSF 2.2 components that show how to declare attributes and hook them into the project. I have seen many examples of earlier JSF 2.x components that use a taglib.xml to define the attributes for code completion, but it seems to be 'at odds' with features of the JSF 2.2 style annotation. I have to remove most of the attributes of the annotation (basically revert to a JSF 2.0 style annotation) or I get "Expression Error: Named Object ... not found". I have also gotten Tag Library supports namespace, but no tag was defined for name. If I just provide a component name to the annotation that matches the one in the taglib file it works, but just no code completion.
I have a FACELETS_LIBRARIES name/value pair in a context-param tag in the web.xml to declare where my facelet-taglib file is located.
snippet from the 'web.xml' file
<!-- Enable IDE autocompletion on component attributes -->
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/myComponent.taglib.xml</param-value>
</context-param>
I have a facelet-taglib file named 'myComponent.taglib.xml' in my WEB-INF directory (same place as faces-config.xml and web.xml).
UPDATE: Responding to the comment by Kukeltje, I updated my facelet-taglib file to version 2.2, but I still get "No Suggestions" from my IDE... also updated the namespaces in my .xhtml JSF source file (even though this site said the older versions were still supported
https://jsflive.wordpress.com/2013/05/16/jsf22-namespaces/)
snippet from the 'myComponent.taglib.xml' file
<?xml version="1.0"?>
<facelet-taglib version="2.2"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facelettaglibrary_2_2.xsd">
<namespace>http://java.sun.com/jsf/composite/components</namespace>
<composite-library-name>myComposites</composite-library-name>
<namespace>https://com.my.project/myComponent</namespace>
<tag>
<tag-name>initialize</tag-name>
<component>
<component-type>InitMyComponent</component-type>
</component>
<attribute>
<name>callback1</name>
<required>false</required>
<type>java.lang.String</type>
</attribute>
</tag>
The faces-config.xml file - defines the javaee and schema namespaces, and version 2.2 but it is otherwise 'empty'.
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
</faces-config>
I am fine with having to type in all the attributes but I just can't seem to find the proper way to hook this feature into my project.
Note: I have experimented with using a composite component. The code completion for attributes worked, but then I lost code completion for the tags. I'm just writing out JavaScript to setup and call a JavaScript library's initialize function but also, I would really love to pass a JavaScript object back to a bean on the server when my callback function is invoked. I am currently using a BalusC provided solution that involves p:remoteCommand and updating hidden input fields. I would greatly prefer to provide reference to the bean using EL in an attribute of my custom component.

Ant xmlproperty task fails due to validation error

I want to extract an application version from a DITA map file. The ditamap file is valid and looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map id="user-manual">
<title><ph keyref="product"/> User Manual</title>
<topicmeta>
<prodinfo>
<prodname><keyword keyref="product"/></prodname>
<vrmlist>
<vrm version="4" release="3" modification="0"/>
</vrmlist>
</prodinfo>
</topicmeta>
<!--
[...]
-->
</map>
The information I want to get is in the <vrm> element.
"Easy peasy," I think to myself. So I use Ant's <xmlproperty> task to just load this XML file.
<project default="test">
<!-- notice #validate -->
<xmlproperty file="path/to/user-manual.ditamap" validate="false"/>
<target name="test">
<echo>${map.topicmeta.prodinfo.vrmlist.vrm(version)}</echo>
</target>
</project>
I don't want it to validate because Ant isn't going to find map.dtd.
Loading the file returns an error:
java.io.FileNotFoundException: /home/user/user-manual/map.dtd (No such file or directory)
If I remove the <!DOCTYPE> declaration or add a nested <xmlcatalog> with the path to the DTD, the file loads and I can use the properties from it.
I tested this with Ant 1.7.1 and 1.9.4. Is this a bug with Ant, or am I misunderstanding how Ant loads XML properties and the purpose of the validate attribute?
How can I make Ant obey my will?
I recommend to not use the <xmlproperty> for this. Please have a look at the docs:
For example, with semantic attribute processing enabled, this XML
property file:
<root>
<properties>
<foo location="bar"/>
<quux>${root.properties.foo}</quux>
</properties>
</root>
is roughly equivalent to the following fragments in a build.xml file:
<property name="root.properties.foo" location="bar"/>
<property name="root.properties.quux" value="${root.properties.foo}"/>
So the name of the properties you set is generated using their paths to the root element, so they rely on the structure of your DITA Map. But many elements in DITA may be set at different positions on your DITA Map. That means, if you move your metadata to another parent element, the property name changes and your build fails. This is probably not, what you want.
I'd recommend to grab those values via XSLT and than set the properties. That way, you could, for example, say, "give me the first occurance of that element with a simple //foo[1] XPath selector. Further on, you have the power of XSLT and XPath to slice values, format dates and so on before setting a property.
Update
You can use the oops consultancy Ant xmltask for that. It is very easy to set a property using <copy>:
<copy path="//critdates/created/#date"
property="document.date"
append="false"/>

attaching #Entity annotations to jaxb-generated classes from a wsdl

My goal is to add #Entity annotations to the classes that are generated from a wsdl. I'm using cxf-codegen-plugin's wsdl2java goal, and pointing at a local wsdl file. I can generate all the sources without any problem, but when I try to add a binding file, I'm running into problems.
Here's a segment of the wsdl (the file is CAAudit.wsdl and is in my resources directory):
<?xml version="1.0" encoding="UTF-8" ?>
<wsdl:definitions targetNamespace="http://www.ocse.gov/quick/wsdl/CAAudit.wsdl"
xmlns:audw="http://www.ocse.gov/quick/wsdl/CAAudit.wsdl"
xmlns:audx="http://www.ocse.gov/quick/wsdl/CAAudit.xsd"
xmlns:qikrsp="urn:us:gov:hhs:acf:qikrsp"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
name="CAAudit"
>
<wsdl:types>
<xsd:schema targetNamespace="http://www.ocse.gov/quick/wsdl/CAAudit.xsd"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<xsd:import namespace="urn:us:gov:hhs:acf:qikrsp"
schemaLocation="QuickResponse.xsd" />
<xsd:complexType name="NotifyCAAuditRequest" >
<xsd:sequence>
<xsd:element ref="qikrsp:QuickResponse" />
</xsd:sequence>
</xsd:complexType>
....
My first question is I'm really not certain what should go in the binding file. First, I'm pretty sure that I need jaxws bindings to work with the wsdl (the jaxb binding only has the schemaLocation attribute), although I don't need to generate web service classes.
Next, I'm not sure I'm not sure if the introduction of a new xmlns in the schema element will cause problems for an xpath search. I did have problems running it with notepad++'s xpath evaluation.
Also, I'm not sure if the fact that the QuickResponse element (which is the class I want to annotate) is defined by a reference is hindering my efforts. I'm not sure if or how (or where) I would include the referenced xsd file.
Here is one possible binding file (I was just trying to get an #Generated on the class to start with):
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<jaxb:bindings
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:annox="http://annox.dev.java.net"
jaxb:extensionBindingPrefixes="annox"
jaxb:version="2.1"
>
<jaxws:bindings wsdlLocation="CAAudit.wsdl"
node="/wsdl:definitions/wsdl:types">
<jaxb:bindings node=".//xsd:schema">
<annox:annotate>#javax.annotation.Generated({"JAXWS"})</annox:annotate>
</jaxb:bindings>
</jaxws:bindings>
</jaxb:bindings>
I did not manage to customize schema embedded in WSDL. This are my latest efforts:
https://github.com/highsource/jaxb2-annotate-plugin/blob/master/tests/jaxws/src/main/resources/wsdl-bindings.xjb
What works with WSDLs is attaching customizations via SCD. But SCD does not allow proprietary customization elements (like annotate:*). So that won't help with jaxb2-annotate-plugin.
So the only thing which would probably work is to extract schema from the WSDL into an own file.

JAXB bindings generic converter

In JAXB binding i can change type of element from int to string and so on.
But i want not only data type conversion. I want replace integer Id's with they string equivalent.
This means that for every field i need write method.
Is anyway to get field name from parse method?
<!-- Resolve ID's -->
<jaxb:bindings node="/xs:schema/xs:element/xs:complexType/xs:sequence/xs:element[#name='Classification']/xs:complexType/xs:attribute[#name='id']">
<jaxb:property>
<jaxb:baseType>
<jaxb:javaType name="java.lang.String" parseMethod="com.company.lookup.Resolver.resolve" />
</jaxb:baseType>
</jaxb:property>
</jaxb:bindings>
Instead of defining the javaType on a per property basis you can override the Java type for an XML schema type in the global bindings section of the external binding document.
<jxb:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
<jxb:bindings>
<jxb:globalBindings>
<jxb:javaType name="String" xmlType="xs:int"/>
</jxb:globalBindings>
</jxb:bindings>
</jxb:bindings>

Resources