users@jaxb.java.net

Re: changing package names in a Plugin

From: Sekhar Vajjhala <Sekhar.Vajjhala_at_Sun.COM>
Date: Thu, 23 Mar 2006 12:08:51 -0500

Malachi de Ælfweald wrote:

> Perhaps I am missing something. Why don't you just specify the package
> name in the binding file, in the schema, or on the command line? Why
> do you need a plugin for this?

<schemaBindings> JAXB customization can be used like:

<jaxb:schemaBindings>
     <jaxb:package name = "org.example.po" />
</jaxb:schemaBindings>

You will need a <schemaBindings> for each distinct
targetNamespace.

See Section 7.6, "<schemaBindings> Declaration" of the
JAXB 2.0 Proposed Final Draft.

Sekhar

>
> Malachi
>
>
> On 3/23/06, *Andreas Pakulat* <pakulat_at_rostock.zgdv.de
> <mailto:pakulat_at_rostock.zgdv.de>> wrote:
>
> Hi,
>
> I'm struggling a bit here with writing a Plugin for xjc. My goal is to
> prefix all generated package names (created from the targetNamespace)
> with my own package, so that I end up with a structure like
>
> my.company.some.namespace
>
> I started with the Camelcase Plugin as this one changes the class name
> and changed the NameConverter.Standard subclass to return some
> arbitrary
> string for toPackageName(). However it seems like my plugin isn't used
> at all.
>
> I call xjc via:
>
> C:\_users\pakulat\jaxb_md_generation>java
> -Dcom.sun.tools.xjc.Options.findServices=true -jar
> ..\jaxb-ri\lib\jaxb- xjc.jar -classpath plugins\addpackageprefix.jar
> -verbose -d java-src schema\iso19119.xsd -addpackageprefix
>
> My Plugin class and NameConverter.Standard subclass are shown below.
> jaxb tells me that he tries to create an instance of the class but
> nothing else happens. I added a file-write to the NameConverter
> but the
> file is not created...
>
> Andreas
>
>
> /* Plugin class */
> import org.xml.sax.ErrorHandler;
> import com.sun.tools.xjc.BadCommandLineException ;
> import com.sun.tools.xjc.Options;
> import com.sun.tools.xjc.Plugin;
> import com.sun.tools.xjc.outline.Outline;
>
> public class AddPackagePrefixPlugin extends Plugin
> {
> protected final String OPTION_NAME = "addpackageprefix";
>
> public String getOptionName() {
> return OPTION_NAME;
> }
>
> public String getUsage() {
> return " -" + OPTION_NAME +
> " : prefixes every package with de.zgdv.geo.metadata";
> }
>
> public void onActivated(Options opts) throws
> BadCommandLineException {
> opts.setNameConverter( new
> AddPackagePrefixNameConverter(), this );
> }
>
> public boolean run( Outline model, Options opts, ErrorHandler
> errorHandler ) {
> return true;
> }
>
> }
>
> /* NameConverter.Standard subclass */
> import java.io.FileWriter;
> import java.io.IOException;
> import com.sun.tools.xjc.ConsoleErrorReporter;
> import com.sun.xml.bind.api.impl.NameConverter;
>
> public class AddPackagePrefixNameConverter extends
> NameConverter.Standard
> {
>
> public String toPackageName(String s) {
> try{
> FileWriter fw = new
> FileWriter("C:\\\\temp\\\\testfile");
> fw.write(s);
> fw.close();
> }catch(IOException ioe){
> ioe.printStackTrace();
> }
> String str = super.toPackageName(s);
> return "de.zgdv.geo.metadata."+str;
> }
>
> }
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> <mailto:users-unsubscribe_at_jaxb.dev.java.net>
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
> <mailto:users-help_at_jaxb.dev.java.net>
>
>