Package org.apache.ws.jaxme.generator.impl

Examples of org.apache.ws.jaxme.generator.impl.GeneratorImpl


    isource.setSystemId(pSystemId);
    return r.parse(isource);
  }

  protected JAXBSchemaReader getSchemaReader() {
      Generator generator = new GeneratorImpl();
      JAXBSchemaReader r = new JAXBSchemaReader();
      generator.setSchemaReader(r);
      r.setGenerator(generator);
      return r;
  }
View Full Code Here


          producesFilesSet.add(f);
        }
      }
     
 
      Generator generator = new GeneratorImpl();
      generator.setEntityResolver(xmlCatalog);
      generator.setForcingOverwrite(isForce());
      generator.setSettingReadOnly(isReadOnly());
      generator.setValidating(isValidating());
      for (int i = 0;  i < bindingFiles.length;  i++) {
        try {
          String systemId = bindingFiles[i].toURL().toExternalForm();
          generator.addBindings(new InputSource(systemId));
        } catch (Exception e) {
          throw new BuildException("Failed to read external binding file "
              + bindingFiles[i] + ": " + e.getMessage(), e,
              getLocation());
        }
      }

      if (getPackage() != null) {
        generator.setProperty("jaxme.package.name", getPackage());
      }
      Dtd myDtd = getDtd();
      if (myDtd != null) {
        generator.setProperty("jaxme.dtd.input", "true");
        if (myDtd.getTargetNamespace() != null) {
          generator.setProperty("jaxme.dtd.targetNamespace", myDtd.getTargetNamespace());
        }
      }
      Property[] myProperties = getProperties();
      for (int i = 0;  i < myProperties.length;  i++) {
        Property ot = myProperties[i];
        log("Option " + ot.getName() + "=" + ot.getValue(), Project.MSG_VERBOSE);
        generator.setProperty(ot.getName(), ot.getValue());
      }

      SchemaReader reader = getSchemaReader();
      if (reader instanceof JAXBSchemaReader) {
        ((JAXBSchemaReader) reader).setSupportingExtensions(isExtension());
      }
      generator.setSchemaReader(reader);
      reader.setGenerator(generator);
      generator.setTargetDirectory(getTarget());
      generator.setResourceTargetDirectory(getResourceTarget());

      ClassType[] mySgFactoryChains = getSGFactoryChains();
      if (mySgFactoryChains.length > 0) {
        if (!(reader instanceof JAXBSchemaReader)) {
          throw new BuildException("The nested child element 'sgFactoryChain' is valid only, if the schema reader is an instance of "
                                    + JAXBSchemaReader.class.getName(), getLocation());
        }
        for (int i = 0;  i < mySgFactoryChains.length;  i++) {
          ClassType ct = mySgFactoryChains[i];
          Class c;
          try {
            c = cl.loadClass(ct.getClassName());
          } catch (ClassNotFoundException e) {
            throw new BuildException("Failed to load SGFactoryChain implementation class " + ct.getClassName(),
                                      getLocation());
          }
          if (!SGFactoryChain.class.isAssignableFrom(c)) {
            throw new BuildException("The SGFactoryChain class " + c.getName() +
                                      " is not implementing " + SGFactoryChain.class.getName(),
                                      getLocation());
          }
          reader.addSGFactoryChain(c);
        }
      }

      for (int i = 0;  i < schemaFiles.length;  i++) {
        log("Reading schema file " + schemaFiles[i], Project.MSG_VERBOSE);
        try {
      SchemaSG schemaSG = generator.generate(schemaFiles[i]);
          if (producesFilesSet != null) {
            JavaSourceFactory jsf = schemaSG.getJavaSourceFactory();
            File targetDirectory = getTarget();
            for (Iterator iter = jsf.getJavaSources();  iter.hasNext()) {
              JavaSource js = (JavaSource) iter.next();
View Full Code Here

  /**
   * @param args the command line arguments
   */
  public static void main (String args[]) throws Exception {
    java.io.File schemaFile = null;
    Generator g = new GeneratorImpl();
    String schemaReaderClass = JAXBSchemaReader.class.getName();
    String target = null;
    String logFile = null;
    String logLevel = null;
    String packageName = null;
    List sgFactoryChains = new ArrayList();

    for (int i = 0;  i < args.length;  i++) {
      String arg = args[i];
      if (arg.equals("--")) {
        for (int j = i;  j < args.length;  j++) {
          if (schemaFile != null) {
            Usage("Only one input file may be specified.");
          }
          schemaFile = new java.io.File(args[j]);
        }
        break;
      }
      if (arg.startsWith("--")) {
        arg = arg.substring(1);
      }
      if (arg.startsWith("-")) {
        arg = arg.substring(1);
        int optIndex = arg.indexOf('=');
        String opt = null;
        if (optIndex > 0) {
          opt = arg.substring(optIndex+1);
          arg = arg.substring(0, optIndex);
        }
        if (arg.equalsIgnoreCase("schemaReader")) {
          if (logLevel != null) {
            Usage("The option " + arg + " may be used only once.");
          }
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          schemaReaderClass = opt;
        } else if (arg.equalsIgnoreCase("logFile")) {
          if (logFile != null) {
            Usage("The option " + arg + " may be used only once.");
          }
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          logFile = opt;
        } else if (arg.equalsIgnoreCase("package")) {
          if (packageName != null) {
            Usage("The option " + arg + " may be used only once.");
          }
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          packageName = opt;
          g.setProperty("jaxme.package.name", packageName);
        } else if (arg.equalsIgnoreCase("logLevel")) {
          if (logLevel != null) {
            Usage("The option " + arg + " may be used only once.");
          }
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          logLevel = opt;
        } else if (arg.equalsIgnoreCase("target")) {
          if (target != null) {
            Usage("The option " + arg + " may be used only once.");
          }
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          target = opt;
        } else if (arg.equalsIgnoreCase("option")) {
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          int offset = opt.indexOf('=');
          if (offset < 1) {
            System.err.println("Failed to parse option definition " + opt);
            System.err.println("Must be like --option=name=value or");
            System.err.println("--option=name=target=value");
            System.err.println();
            Usage(null);
          }
          String optName = opt.substring(0, offset);
          String optValue = opt.substring(offset+1);
          g.setProperty(optName, optValue);
        } else if (arg.equalsIgnoreCase("validating")) {
          g.setValidating(true);
        } else if ("sgFactoryChain".equals(arg)) {
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          Class c = null;
          try {
            c = Class.forName(opt);
          } catch (ClassNotFoundException e) {
            try {
              c = Thread.currentThread().getContextClassLoader().loadClass(opt);
            } catch (ClassNotFoundException f) {
              System.err.println("Failed to load class " + opt);
              System.exit(1);
            }
          }
          if (!SGFactoryChain.class.isAssignableFrom(c)) {
            System.err.println("The SGFactoryChain implementation " + c.getName() +
                               " is not implementing " + SGFactoryChain.class.getName());
          }
          sgFactoryChains.add(c);
        } else if (arg.equalsIgnoreCase("h"||  arg.equalsIgnoreCase("help"||
                   arg.equalsIgnoreCase("?")) {
          Usage(null);
        } else {
          Usage("Unknown option name: " + arg);
        }
      } else if (schemaFile != null) {
        Usage("Only one input file may be specified.");
       } else {
         schemaFile = new java.io.File(args[i]);
       }
    }

    if (schemaFile == null) {
      Usage("A Schema file must be specified");
    }

    SchemaReader sr = null;
    try {
      Class c = Class.forName(schemaReaderClass);
      sr = (SchemaReader) c.newInstance();
      g.setSchemaReader(sr);
      sr.setGenerator(g);
    } catch (ClassNotFoundException e) {
      System.err.println("Could not find SchemaReader class " + schemaReaderClass);
      System.exit(1);
    } catch (ClassCastException e) {
      System.err.println("Class " + schemaReaderClass +
                         " is not implementing " + SchemaReader.class.getName());
      System.exit(1);
    } catch (InstantiationException e) {
      System.err.println("Failed to instantiate SchemaReader class " + schemaReaderClass);
      System.exit(1);
    } catch (IllegalAccessException e) {
      System.err.println("Illegal access to SchemaReader class " + schemaReaderClass);
      System.exit(1);
    }

    if (sgFactoryChains.size() > 0) {
      if (!(sr instanceof JAXBSchemaReader)) {
        System.err.println("Additional instances of " + SGFactoryChain.class.getName()
                           + " may be specified only, if the schema reader is an instance of "
                           + JAXBSchemaReader.class.getName());
        System.exit(1);
      }
      JAXBSchemaReader jsr = (JAXBSchemaReader) sr;
      for (int i = 0;  i < sgFactoryChains.size();  i++) {
        jsr.addSGFactoryChain((Class) sgFactoryChains.get(i));
      }
    }

    if (target != null) {
      g.setTargetDirectory(new File(target));
    }

    try {
      g.generate(schemaFile);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }

View Full Code Here

          producesFilesSet.add(f);
        }
      }
     
 
      Generator generator = new GeneratorImpl();
      generator.setForcingOverwrite(isForce());
      generator.setSettingReadOnly(isReadOnly());
      generator.setValidating(isValidating());
      if (getPackageName() != null) {
        generator.setProperty("jaxme.package.name", getPackageName());
      }
      Property[] myProperties = getProperties();
      for (int i = 0;  i < myProperties.length;  i++) {
        Property ot = myProperties[i];
        log("Option " + ot.getName() + "=" + ot.getValue(), Project.MSG_VERBOSE);
        generator.setProperty(ot.getName(), ot.getValue());
      }

      SchemaReader reader = getSchemaReader();
      generator.setSchemaReader(reader);
      reader.setGenerator(generator);
      generator.setTargetDirectory(getTarget());

      ClassType[] mySgFactoryChains = getSGFactoryChains();
      if (mySgFactoryChains.length > 0) {
        if (!(reader instanceof JAXBSchemaReader)) {
          throw new BuildException("The nested child element 'sgFactoryChain' is valid only, if the schema reader is an instance of "
                                    + JAXBSchemaReader.class.getName(), getLocation());
        }
        for (int i = 0;  i < mySgFactoryChains.length;  i++) {
          ClassType ct = mySgFactoryChains[i];
          Class c;
          try {
            c = cl.loadClass(ct.getClassName());
          } catch (ClassNotFoundException e) {
            throw new BuildException("Failed to load SGFactoryChain implementation class " + ct.getClassName(),
                                      getLocation());
          }
          if (!SGFactoryChain.class.isAssignableFrom(c)) {
            throw new BuildException("The SGFactoryChain class " + c.getName() +
                                      " is not implementing " + SGFactoryChain.class.getName(),
                                      getLocation());
          }
          reader.addSGFactoryChain(c);
        }
      }

      for (int i = 0;  i < schemaFiles.length;  i++) {
        try {
          SchemaSG schemaSG = generator.generate(schemaFiles[i]);
          if (producesFilesSet != null) {
            JavaSourceFactory jsf = schemaSG.getJavaSourceFactory();
            File targetDirectory = getTarget();
            for (Iterator iter = jsf.getJavaSources();  iter.hasNext()) {
              JavaSource js = (JavaSource) iter.next();
View Full Code Here

*/
public class ParserTest extends BaseTestCase {
  public ParserTest(String arg) { super(arg); }

  protected SchemaSG parse(String pSchema, String pSystemId) throws Exception {
    Generator generator = new GeneratorImpl();
    JAXBSchemaReader r = new JAXBSchemaReader();
    generator.setSchemaReader(r);
    r.setGenerator(generator);
    InputSource isource = new InputSource(new StringReader(pSchema));
    isource.setSystemId(pSystemId);
    return r.parse(isource);
  }
View Full Code Here

          producesFilesSet.add(f);
        }
      }
     
 
      Generator generator = new GeneratorImpl();
      generator.setForcingOverwrite(isForce());
      generator.setSettingReadOnly(isReadOnly());
      generator.setValidating(isValidating());
      if (getPackage() != null) {
        generator.setProperty("jaxme.package.name", getPackage());
      }
      Property[] myProperties = getProperties();
      for (int i = 0;  i < myProperties.length;  i++) {
        Property ot = myProperties[i];
        log("Option " + ot.getName() + "=" + ot.getValue(), Project.MSG_VERBOSE);
        generator.setProperty(ot.getName(), ot.getValue());
      }

      SchemaReader reader = getSchemaReader();
      if (reader instanceof JAXBSchemaReader) {
        ((JAXBSchemaReader) reader).setSupportingExtensions(true);
      }
      generator.setSchemaReader(reader);
      reader.setGenerator(generator);
      generator.setTargetDirectory(getTarget());

      ClassType[] mySgFactoryChains = getSGFactoryChains();
      if (mySgFactoryChains.length > 0) {
        if (!(reader instanceof JAXBSchemaReader)) {
          throw new BuildException("The nested child element 'sgFactoryChain' is valid only, if the schema reader is an instance of "
                                    + JAXBSchemaReader.class.getName(), getLocation());
        }
        for (int i = 0;  i < mySgFactoryChains.length;  i++) {
          ClassType ct = mySgFactoryChains[i];
          Class c;
          try {
            c = cl.loadClass(ct.getClassName());
          } catch (ClassNotFoundException e) {
            throw new BuildException("Failed to load SGFactoryChain implementation class " + ct.getClassName(),
                                      getLocation());
          }
          if (!SGFactoryChain.class.isAssignableFrom(c)) {
            throw new BuildException("The SGFactoryChain class " + c.getName() +
                                      " is not implementing " + SGFactoryChain.class.getName(),
                                      getLocation());
          }
          reader.addSGFactoryChain(c);
        }
      }

      for (int i = 0;  i < schemaFiles.length;  i++) {
        try {
          SchemaSG schemaSG = generator.generate(schemaFiles[i]);
          if (producesFilesSet != null) {
            JavaSourceFactory jsf = schemaSG.getJavaSourceFactory();
            File targetDirectory = getTarget();
            for (Iterator iter = jsf.getJavaSources();  iter.hasNext()) {
              JavaSource js = (JavaSource) iter.next();
View Full Code Here

*/
public class ParserTest extends BaseTestCase {
  public ParserTest(String arg) { super(arg); }

  protected SchemaSG parse(String pSchema, String pSystemId) throws Exception {
    Generator generator = new GeneratorImpl();
    JAXBSchemaReader r = new JAXBSchemaReader();
    generator.setSchemaReader(r);
    r.setGenerator(generator);
    InputSource isource = new InputSource(new StringReader(pSchema));
    isource.setSystemId(pSystemId);
    return r.parse(isource);
  }
View Full Code Here

  /**
   * @param args the command line arguments
   */
  public static void main (String args[]) throws Exception {
    java.io.File schemaFile = null;
    Generator g = new GeneratorImpl();
    String schemaReaderClass = JAXBSchemaReader.class.getName();
    String target = null;
    String logFile = null;
    String logLevel = null;
    String packageName = null;
    List sgFactoryChains = new ArrayList();

    for (int i = 0;  i < args.length;  i++) {
      String arg = args[i];
      if (arg.equals("--")) {
        for (int j = i;  j < args.length;  j++) {
          if (schemaFile != null) {
            Usage("Only one input file may be specified.");
          }
          schemaFile = new java.io.File(args[j]);
        }
        break;
      }
      if (arg.startsWith("--")) {
        arg = arg.substring(1);
      }
      if (arg.startsWith("-")) {
        arg = arg.substring(1);
        int optIndex = arg.indexOf('=');
        String opt = null;
        if (optIndex > 0) {
          opt = arg.substring(optIndex+1);
          arg = arg.substring(0, optIndex);
        }
        if (arg.equalsIgnoreCase("force")) {
          g.setForcingOverwrite(true);
        } else if (arg.equalsIgnoreCase("schemaReader")) {
          if (logLevel != null) {
            Usage("The option " + arg + " may be used only once.");
          }
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          schemaReaderClass = opt;
        } else if (arg.equalsIgnoreCase("logFile")) {
          if (logFile != null) {
            Usage("The option " + arg + " may be used only once.");
          }
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          logFile = opt;
        } else if (arg.equalsIgnoreCase("package")) {
          if (packageName != null) {
            Usage("The option " + arg + " may be used only once.");
          }
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          packageName = opt;
          g.setProperty("jaxme.package.name", packageName);
        } else if (arg.equalsIgnoreCase("logLevel")) {
          if (logLevel != null) {
            Usage("The option " + arg + " may be used only once.");
          }
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          logLevel = opt;
        } else if (arg.equalsIgnoreCase("target")) {
          if (target != null) {
            Usage("The option " + arg + " may be used only once.");
          }
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          target = opt;
        } else if (arg.equalsIgnoreCase("option")) {
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          int offset = opt.indexOf('=');
          if (offset < 1) {
            System.err.println("Failed to parse option definition " + opt);
            System.err.println("Must be like --option=name=value or");
            System.err.println("--option=name=target=value");
            System.err.println();
            Usage(null);
          }
          String optName = opt.substring(0, offset);
          String optValue = opt.substring(offset+1);
          g.setProperty(optName, optValue);
        } else if (arg.equalsIgnoreCase("validating")) {
          g.setValidating(true);
        } else if ("sgFactoryChain".equals(arg)) {
          if (opt == null) {
            if (i == args.length) {
              Usage("Missing argument for option " + arg);
            }
            opt = args[++i];
          }
          Class c = null;
          try {
            c = Class.forName(opt);
          } catch (ClassNotFoundException e) {
            try {
              c = Thread.currentThread().getContextClassLoader().loadClass(opt);
            } catch (ClassNotFoundException f) {
              System.err.println("Failed to load class " + opt);
              System.exit(1);
            }
          }
          if (!SGFactoryChain.class.isAssignableFrom(c)) {
            System.err.println("The SGFactoryChain implementation " + c.getName() +
                               " is not implementing " + SGFactoryChain.class.getName());
          }
          sgFactoryChains.add(c);
        } else if (arg.equalsIgnoreCase("h"||  arg.equalsIgnoreCase("help"||
                   arg.equalsIgnoreCase("?")) {
          Usage(null);
        } else {
          Usage("Unknown option name: " + arg);
        }
      } else if (schemaFile != null) {
        Usage("Only one input file may be specified.");
       } else {
         schemaFile = new java.io.File(args[i]);
       }
    }

    if (schemaFile == null) {
      Usage("A Schema file must be specified");
    }

    SchemaReader sr = null;
    try {
      Class c = Class.forName(schemaReaderClass);
      sr = (SchemaReader) c.newInstance();
      g.setSchemaReader(sr);
      sr.setGenerator(g);
    } catch (ClassNotFoundException e) {
      System.err.println("Could not find SchemaReader class " + schemaReaderClass);
      System.exit(1);
    } catch (ClassCastException e) {
      System.err.println("Class " + schemaReaderClass +
                         " is not implementing " + SchemaReader.class.getName());
      System.exit(1);
    } catch (InstantiationException e) {
      System.err.println("Failed to instantiate SchemaReader class " + schemaReaderClass);
      System.exit(1);
    } catch (IllegalAccessException e) {
      System.err.println("Illegal access to SchemaReader class " + schemaReaderClass);
      System.exit(1);
    }

    if (sgFactoryChains.size() > 0) {
      if (!(sr instanceof JAXBSchemaReader)) {
        System.err.println("Additional instances of " + SGFactoryChain.class.getName()
                           + " may be specified only, if the schema reader is an instance of "
                           + JAXBSchemaReader.class.getName());
        System.exit(1);
      }
      JAXBSchemaReader jsr = (JAXBSchemaReader) sr;
      for (int i = 0;  i < sgFactoryChains.size();  i++) {
        jsr.addSGFactoryChain((Class) sgFactoryChains.get(i));
      }
    }

    if (target != null) {
      g.setTargetDirectory(new File(target));
    }

    try {
      g.generate(schemaFile);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }

View Full Code Here

                    new File(configuration.getOutputLocation(), configuration.getSourceLocation());

            JAXBSchemaReader reader = new JAXBSchemaReader();
            reader.setSupportingExtensions(true);

            GeneratorImpl generator = new GeneratorImpl();
            generator.setTargetDirectory(outputDir);
            generator.setForcingOverwrite(false);
            generator.setSchemaReader(reader);

            for (int i = 0; i < xmlObjectsVector.size(); i++) {
                SchemaSG sg = generator.generate((InputSource)xmlObjectsVector.elementAt(i));
                ObjectSG[] elements = sg.getElements();
                for (int j = 0; j < elements.length; j++) {
                    XsQName qName = elements[j].getName();
                    JavaQName name = elements[j].getClassContext().getXMLInterfaceName();
                    mapper.addTypeMappingName(
View Full Code Here

      + "        <xs:element name='element_1' type='xs:string'/>\n"
      + "      </xs:all>\n"
      + "    </xs:complexType>\n"
      + "  </xs:element>\n"
      + "</xs:schema>\n";
    Generator g = new GeneratorImpl();
    SchemaReader sr = new JAXBSchemaReader();
    g.setSchemaReader(sr);
    sr.setGenerator(g);
    SchemaSG schema = g.getSchemaReader().parse(new InputSource(new StringReader(xsSchema)));
    assertEquals("Element1", JavaNamer.convert("element1", schema));
    assertEquals("Element_1", JavaNamer.convert("element_1", schema));
  }
View Full Code Here

TOP

Related Classes of org.apache.ws.jaxme.generator.impl.GeneratorImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.