Package nux.xom.pool

Examples of nux.xom.pool.BuilderFactory


    PoolConfig config = new PoolConfig();
    if (noBuilderPool) config.setMaxEntries(0);
    final BuilderPool builderPool;
   
    if (filter == null) {
      builderPool = new BuilderPool(config, new BuilderFactory());
    } else {
      BuilderFactory builderFactory = new BuilderFactory() {
        protected Builder newBuilder(XMLReader parser, boolean validate) {
          StreamingTransform myTransform = new StreamingTransform() {
            public Nodes transform(Element subtree) {
              return XQueryUtil.xquery(subtree, filterQuery);
            }
          };
          return new Builder(parser, validate, filter.createNodeFactory(null, myTransform));    
        }
      };
      builderPool = new BuilderPool(config, builderFactory);
    }

    // prepare DocumentFactory and DocumentPool
    DocumentFactory docFactory = new DocumentFactory() {
      public Document createDocument(InputStream input, URI baseURI)
          throws ParsingException, IOException {
        long start = System.currentTimeMillis();
        Document doc;
        if (baseURI != null && baseURI.getPath().endsWith(".bnux")) {
          if (filter == null) {
            doc = getBinaryXMLFactory().createDocument(input, baseURI);
          } else {
            StreamingTransform myTransform = new StreamingTransform() {
              public Nodes transform(Element subtree) {
                return XQueryUtil.xquery(subtree, filterQuery);
              }
            };
 
            if (input == null && baseURI == null)
              throw new IllegalArgumentException("input and baseURI must not both be null");
            if (input == null) input = baseURI.toURL().openStream();
            try {
              doc = new BinaryXMLCodec().deserialize(input, filter.createNodeFactory(null, myTransform));
              if (baseURI != null) doc.setBaseURI(baseURI.toASCIIString());
            } finally {
              input.close(); // do what SAX XML parsers do
            }
          }
        } else {
          doc = super.createDocument(input, baseURI);
        }
        if (xinclude) {
          try {
            XIncluder.resolveInPlace(doc, newBuilder());
          } catch (XIncludeException e) {
            throw new ParsingException(e.getMessage(), e);
          }
        }
        if (stripWhitespace) XOMUtil.Normalizer.STRIP.normalize(doc);
        long end = System.currentTimeMillis();
        if (isBench || explain) System.out.println(baseURI + " parse [ms]=" + (end-start));
        return doc;
      }
     
      protected Builder newBuilder() {
        if (validate.equals("wf")) {
          return builderPool.getBuilder(false);
        } else if (validate.equals("dtd")) {
          if (schema == null) return builderPool.getBuilder(true);
          EntityResolver resolver;
          try {
            resolver = new BuilderFactory().createResolver(
                  new FileInputStream(schema));
          } catch (IOException e) {
            throw new UsageException(e);
          }
          return builderPool.getDTDBuilder(resolver);
View Full Code Here


    }
   
    if (mode.equals("xom-V")) {
      builder = new Builder(new NodeFactory() {});
    } else if (mode.equals("xom-V-pool")) {
      builder = new BuilderFactory() {
        protected Builder newBuilder(XMLReader parser, boolean validate) {
          return new Builder(parser, false, new NodeFactory() {});    
        }
      }.createBuilder(false);
    }
   
    if (mode.equals("xom-NNF")) {
      builder = new Builder(XOMUtil.getNullNodeFactory());
    } else if (mode.equals("xom-NNF-pool")) {
      builder = new BuilderFactory() {
        protected Builder newBuilder(XMLReader parser, boolean validate) {
          return new Builder(parser, false, XOMUtil.getNullNodeFactory());    
        }
      }.createBuilder(false);
    }
View Full Code Here

    byte[] b = new byte[0];
    if (memory && !fileName.equals("nofile")) b = FileUtil.toByteArray(new FileInputStream(fileName));
    final byte[] bytes = b;
   
    final BuilderPool pool = !nullNodeFactory ? BuilderPool.GLOBAL_POOL : new BuilderPool(new PoolConfig(),
        new BuilderFactory() {
          protected NodeFactory createNodeFactory() {
            return XOMUtil.getNullNodeFactory();
          }
        }
      );
View Full Code Here

    }
  }
 
  private static Builder getW3CBuilder() {
    if (USE_SCHEMA_VALIDATING_BUILDER) {
      return new BuilderFactory().createW3CBuilder(null);
    }
    return new Builder();
  }
View Full Code Here

TOP

Related Classes of nux.xom.pool.BuilderFactory

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.