Package com.hp.gloze.www_w3_org_2001_XMLSchema

Examples of com.hp.gloze.www_w3_org_2001_XMLSchema.schema


 
  public static schema loadSchema(URL url) throws Exception {
    // look up a schema by its URL
    // dump it if it gets too large
    if (schemaCache.size()>SCHEMA_CACHE_MAX) clearCache();
    schema xs = GlozeURL.schemaCache.get(url);
    if (!GlozeURL.schemaCache.containsKey(url)) {
      // otherwise parse the input
      if ("true".equals(System.getProperty("gloze.verbose"))) logger.info("reading " + url);
      Document doc = XMLUtility.read(input(url, null));
      if (doc!=null) {
        xs = (schema) XMLBean.newShallowInstance(doc.getDocumentElement());
        // add to the cache before continuing with imports
        GlozeURL.schemaCache.put(url, xs);
        // required to break loops in mutually imported schema
        xs.set_url(url);
        xs.set_location(parent(url));
        xs.populate();
      }
    }
    return xs;
  }
View Full Code Here


   * @return schema instance
   */
 
  public static schema getCachedSchema(String namespace) {
    for (Iterator<schema> i = GlozeURL.schemaCache.values().iterator(); i.hasNext(); ) {
      schema xs = i.next();
      if (namespace.equals(xs.getTargetNamespace())) return xs;
    }
    return null;
  }
View Full Code Here

   * @param schemaMap : Maps schema location to schema instance
   * @throws Exception
   */
 
  public static schema initSchema(URI namespace, URL url, Map<URL,schema> schemaMap) throws Exception {
    schema xs = null;
    if (!url.getProtocol().equals("file")) {
      xs = getCachedSchema(namespace.toString());
      if (xs!=null) return xs;
    }
    xs = loadSchema(url);
    if (xs!=null) {
      String tns = xs.getTargetNamespace();
      if (namespace!=null && tns!=null && !tns.equals(namespace.toString()))
        logger.warn("target namespace mismatch: " + namespace + " " + tns);
      schemaMap.put(url,xs);
    }
    return xs;
View Full Code Here

    Element e = doc.getDocumentElement();
    StringBuffer loc = null;
    StringBuffer noNSloc = null;
    Set<String> added = new HashSet<String>();
    for (URL l : schemaMap.keySet()) {
      schema xsd = schemaMap.get(l);
      for (URL url : schemaCache.keySet()) {
        if (schemaCache.get(url).equals(xsd)) {
          String uri = XMLBean.relativize(base, url.toURI()).toString();
          if (uri.startsWith(base.toString()))
            uri = uri.substring(base.toString().length());
          if (xsd.getTargetNamespace()==null && !added.contains(uri)) {
            if (noNSloc==null) noNSloc = new StringBuffer();
            else noNSloc = noNSloc.append(" ");
            noNSloc.append(uri);
            added.add(uri);
          }
          else if (!added.contains(uri)) {
            if (loc==null) loc = new StringBuffer();
            else loc.append(" ");
            loc.append(xsd.getTargetNamespace());
            loc.append(" ");
            loc.append(uri);
            added.add(uri);
          }
        }
View Full Code Here

   * @param base of the ontology
   * @return ontology
   */
 
  public OntModel xsd_to_owl( URL source, String base) throws Exception {
    schema xs = loadSchema(source);
    if (xs==null) return null;
   
    schemaMap.put(source, xs);
    String suffix = "owl";
    String name = XMLBean.changeSuffix(source.getFile(),suffix);

    // derive target
    File t = this.target!=null?new File(this.target):null, target = t;
    if (t!=null && (t.isDirectory() || t.getName().indexOf('.')<0)) {
      if (!t.exists()) t.mkdirs();
      target = new File(t, name);
    }

    // derive base
    if (base!=null && base.endsWith("/") && name!=null) base += name;
    URI b = null;
    if (base!=null) b = new URI(base);
    else if (target!=null) b = target.toURI();
    else b = source.toURI();

    // create a context gathering global definitions
    Context ctx = new Context(b,xmlns,ModelFactory.createDefaultModel(),schemaMap,this);
    String ns = xs.getTargetNamespace();
    if (ns==null) ns = ctx.getDefaultNS();
    initSchema(new URI(ns),source, schemaMap);

    // load rules and initialise reasoner
    InputStream rules = GlozeURL.class.getResourceAsStream(RULES);
    BufferedReader br = new BufferedReader(new InputStreamReader(rules));
    List<Rule> l = Rule.parseRules(Rule.rulesParserFromReader(br));
    GenericRuleReasoner r = new GenericRuleReasoner(l);
    r.setTraceOn(trace!=null && trace.equals("true"));
    ctx.setReasoner(r);
   
    OntModel m = xs.toOWL(target, name, false, ctx);
//    ctx.getModel().write(System.out,"RDF/XML-ABBREV");
    return m;
  }
View Full Code Here

 
  public static schema loadSchema(URL url) throws Exception {
    // look up a schema by its URL
    // dump it if it gets too large
    if (schemaCache.size()>SCHEMA_CACHE_MAX) clearCache();
    schema xs = (schema) Gloze.schemaCache.get(url);
    if (!Gloze.schemaCache.containsKey(url)) {
      // otherwise parse the input
      if ("true".equals(System.getProperty("gloze.verbose"))) logger.info("reading " + url);
      Document doc = XMLUtility.read(input(url, null));
      if (doc!=null) {
        xs = (schema) XMLBean.newShallowInstance(doc.getDocumentElement());
        // add to the cache before continuing with imports
        Gloze.schemaCache.put(url, xs);
        // required to break loops in mutually imported schema
        xs.set_url(url);
        xs.set_location(parent(url));
        xs.populate();
      }
    }
    return xs;
  }
View Full Code Here

   * @return schema instance
   */
 
  public static schema getCachedSchema(String namespace) {
    for (Iterator i = Gloze.schemaCache.values().iterator(); i.hasNext(); ) {
      schema xs = (schema) i.next();
      if (namespace.equals(xs.getTargetNamespace())) return xs;
    }
    return null;
  }
View Full Code Here

   * @param schemaMap : Maps schema location to schema instance
   * @throws Exception
   */
 
  public static schema initSchema(URI namespace, URL url, Map<URL,schema> schemaMap) throws Exception {
    schema xs = null;
    if (!url.getProtocol().equals("file")) {
      xs = getCachedSchema(namespace.toString());
      if (xs!=null) return xs;
    }
    xs = loadSchema(url);
    if (xs!=null) {
      String tns = xs.getTargetNamespace();
      if (namespace!=null && tns!=null && !tns.equals(namespace.toString()))
        logger.warn("target namespace mismatch: " + namespace + " " + tns);
      schemaMap.put(url,xs);
    }
    return xs;
View Full Code Here

    Element e = doc.getDocumentElement();
    StringBuffer loc = null;
    StringBuffer noNSloc = null;
    Set<String> added = new HashSet<String>();
    for (URL l : schemaMap.keySet()) {
      schema xsd = schemaMap.get(l);
      for (URL url : schemaCache.keySet()) {
        if (schemaCache.get(url).equals(xsd)) {
          String uri = XMLBean.relativize(base, url.toURI()).toString();
          if (uri.startsWith(base.toString()))
            uri = uri.substring(base.toString().length());
          if (xsd.getTargetNamespace()==null && !added.contains(uri)) {
            if (noNSloc==null) noNSloc = new StringBuffer();
            else noNSloc = noNSloc.append(" ");
            noNSloc.append(uri);
            added.add(uri);
          }
          else if (!added.contains(uri)) {
            if (loc==null) loc = new StringBuffer();
            else loc.append(" ");
            loc.append(xsd.getTargetNamespace());
            loc.append(" ");
            loc.append(uri);
            added.add(uri);
          }
        }
View Full Code Here

   * @param base of the ontology
   * @return ontology
   */
 
  public OntModel xsd_to_owl(File source, String base) throws Exception {
    schema xs = loadSchema(source.toURL());
    if (xs==null) return null;
   
    schemaMap.put(source.toURL(),xs);
    String suffix = "owl";
    String name = XMLBean.changeSuffix(source.getName(),suffix);

    // derive target
    File t = this.target!=null?new File(this.target):null, target = t;
    if (t!=null && (t.isDirectory() || t.getName().indexOf('.')<0)) {
      if (!t.exists()) t.mkdirs();
      target = new File(t, name);
    }

    // derive base
    if (base!=null && base.endsWith("/") && name!=null) base += name;
    URI b = null;
    if (base!=null) b = new URI(base);
    else if (target!=null) b = target.toURI();
    else b = source.toURI();

    // create a context gathering global definitions
    Context ctx = new Context(b,xmlns,ModelFactory.createDefaultModel(),schemaMap,this);
    String ns = xs.getTargetNamespace();
    if (ns==null) ns = ctx.getDefaultNS();
    initSchema(new URI(ns),source.toURL(),schemaMap);

    // load rules and initialise reasoner
    InputStream rules = Gloze.class.getResourceAsStream(RULES);
    BufferedReader br = new BufferedReader(new InputStreamReader(rules));
    List l = Rule.parseRules(Rule.rulesParserFromReader(br));
    GenericRuleReasoner r = new GenericRuleReasoner(l);
    r.setTraceOn(trace!=null && trace.equals("true"));
    ctx.setReasoner(r);
   
    OntModel m = xs.toOWL(target, name, false, ctx);
//    ctx.getModel().write(System.out,"RDF/XML-ABBREV");
    return m;
  }
View Full Code Here

TOP

Related Classes of com.hp.gloze.www_w3_org_2001_XMLSchema.schema

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.