users@jaxb.java.net

Re: Plugin for EJB 3.0 annotations

From: <SAllan1000_at_aol.com>
Date: Fri, 12 Aug 2005 23:15:01 EDT

here's the schema:
 
<?xml version="1.0"?>
<xs:schema xmlns:xs="_http://www.w3.org/2001/XMLSchema_
(http://www.w3.org/2001/XMLSchema) "
xmlns:jaxb="_http://java.sun.com/xml/ns/jaxb_
(http://java.sun.com/xml/ns/jaxb) "
xmlns:xjc="_http://java.sun.com/xml/ns/jaxb/xjc_
(http://java.sun.com/xml/ns/jaxb/xjc) "
xmlns:ejb3="_http://jaxb.dev.java.net/plugin/ejb3-cmp_
(http://jaxb.dev.java.net/plugin/ejb3-cmp) "
jaxb:extensionBindingPrefixes="xjc ejb3"
jaxb:version="2.0">
 
<xs:element name="personDocument">
<xs:complexType>
<xs:sequence>
<xs:element name="person" type="personType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
 

<xs:complexType name="personType">
<xs:annotation><xs:appinfo>
<ejb3:annotate className="javax.ejb.Entity" param="myparam" value="myvalue"/>
<ejb3:annotate className="javax.ejb.Table" param="myparam" value="myvalue"/>
</xs:appinfo></xs:annotation>
<xs:sequence>
<xs:element name="name" type="xs:string">
<xs:annotation><xs:appinfo>
<ejb3:annotate className="javax.ejb.Entity" param="myparam" value="myvalue"/>
</xs:appinfo></xs:annotation>
</xs:element>
</xs:sequence>
<xs:attribute name="personID" type="xs:string" use="required"/>
</xs:complexType>
 
</xs:schema>

here's the plugin:
 
public class EJB3Test extends Plugin {
 
    public List<String> getCustomizationURIs() {
return Collections.singletonList(Const.NS);
}
 
    public boolean isCustomizationTagName(String nsUri, String localName) {
return nsUri.equals(Const.NS) && localName.equals("annotate");
}
 
    public String getOptionName() {
return "Xejb3-cmp";
}
 
    public String getUsage() {
return " -Xejb3-cmp : inject specified EJB3.0 Annotations into the
generated code";
}
 
    // meat of the processing
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {


// This doesn't work
Model m = outline.getModel();
for ( CElementInfo cei : m.getAllElements())
{
System.out.println("test3");
CCustomizations custList = cei.getCustomizations();
for (CPluginCustomization c : custList){
Element e = c.element;
System.out.println(e.getTagName());
c.markAsAcknowledged();
}

}


// This works
        for( ClassOutline co : outline.getClasses() ) {
CCustomizations cList = co.target.getCustomizations();
for (CPluginCustomization c : cList){
Element e = c.element;
System.out.println(e.getTagName());
c.markAsAcknowledged();
}
}
 

return true;
}
 
}

Here's the error:
 
      [xjc] Checking timestamp of C:\temp\test.xsd
[xjc] the last modified time of the inputs is 1123902497916
[xjc] the last modified time of the outputs is -9223372036854775808
[xjc] Compiling file:/C:/temp/test.xsd
[xjc] ejb3:annotate
[xjc] ejb3:annotate
[xjc] [ERROR] ejb3:annotate customization is attached to a place where it
is not allowed.
[xjc] line 26 of file:/C:/temp/test.xsd
 
      [xjc] [ERROR] (the above customization is attached to the following
locati
on in the schema)
[xjc] line 24 of file:/C:/temp/test.xsd
 
      [xjc] failure in the XJC task. Use the Ant -verbose switch for more
detail
s
 
BUILD FAILED
C:\oracle\jdevj2ee1013\jdev\mywork\DataWarehouse\Project\build.xml:40:
failed to
compile a schema
at com.sun.tools.xjc.XJC2Task._doXJC(XJC2Task.java:376)
at com.sun.tools.xjc.XJC2Task.doXJC(XJC2Task.java:316)
at com.sun.tools.xjc.XJC2Task.execute(XJC2Task.java:256)
at com.sun.tools.xjc.XJCTask.execute(XJCTask.java:65)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
at org.apache.tools.ant.Task.perform(Task.java:364)
at org.apache.tools.ant.Target.execute(Target.java:341)
at org.apache.tools.ant.Target.performTasks(Target.java:369)
at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
at org.apache.tools.ant.Main.runBuild(Main.java:673)
at org.apache.tools.ant.Main.startAnt(Main.java:188)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:196)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:55)