All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cyc.xml.query.FormulaTemplateUnmarshaller Maven / Gradle / Ivy

Go to download

Query API implementation for requesting and handling answers to arbitrarily complex questions posed to a Cyc server.

There is a newer version: 1.2.2
Show newest version
package com.cyc.xml.query;

/*
 * #%L
 * File: FormulaTemplateUnmarshaller.java
 * Project: Query Client
 * %%
 * Copyright (C) 2013 - 2017 Cycorp, Inc.
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

import java.io.InputStream;
import java.net.URL;
import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.validation.SchemaFactory;
import com.cyc.baseclient.xml.cycml.CycmlDecoder;

import com.cyc.baseclient.xml.Constants;

/**
 *
 * @author baxter
 */
public class FormulaTemplateUnmarshaller {

  private final javax.xml.bind.Unmarshaller unmarshaller;
  public static final String XSD_URI = Constants.XSD_HOME + "/formulatemplate.xsd";
  private boolean shouldValidate = true;

  public FormulaTemplateUnmarshaller() throws JAXBException {
    final String packages = CycmlDecoder.class.getPackage().getName()
            + ":" + CyclQueryUnmarshaller.class.getPackage().getName() + ":" 
            + this.getClass().getPackage().getName();
    this.unmarshaller = JAXBContext.newInstance(packages).createUnmarshaller();
    if (shouldValidate) {
      try {
        unmarshaller.setSchema(SchemaFactory.newInstance(
                XMLConstants.W3C_XML_SCHEMA_NS_URI).newSchema(
                new URL(XSD_URI)));
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }

  public Object unmarshal(final InputStream stream) throws JAXBException {
    return unmarshaller.unmarshal(stream);
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy