Search in sources :

Example 6 with TranslationException

use of com.onespatial.jrc.tns.oml_to_rif.api.TranslationException in project hale by halestudio.

the class AlignmentToModelAlignmentDigester method createAttributePath.

/**
 * Create an attribute path from an {@link IDetailedAbout}
 *
 * @param about the about
 * @param elements the available elements
 * @return the attribute path
 * @throws TranslationException if the attribute path cannot be resolved
 */
private static GmlAttributePath createAttributePath(IDetailedAbout about, Map<String, SchemaElement> elements) throws TranslationException {
    GmlAttributePath binding = new GmlAttributePath();
    // get the parent class for the entity
    // $NON-NLS-1$
    SchemaElement entityParent = elements.get(about.getNamespace() + "/" + about.getFeatureClass());
    if (entityParent == null) {
        // $NON-NLS-1$ //$NON-NLS-2$
        throw new TranslationException("Element " + about.getFeatureClass() + " not found");
    }
    TypeDefinition type = entityParent.getType();
    List<String> nestedParts = about.getProperties();
    for (String attributeName : nestedParts) {
        AttributeDefinition attDef = type.getAttribute(attributeName);
        if (attDef == null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new TranslationException("Attribute " + attributeName + " not found");
        }
        GmlAttribute attribute = new GmlAttribute(attDef);
        binding.add(attribute);
        type = attDef.getAttributeType();
    }
    return binding;
}
Also used : GmlAttributePath(com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttributePath) AttributeDefinition(eu.esdihumboldt.hale.schemaprovider.model.AttributeDefinition) SchemaElement(eu.esdihumboldt.hale.schemaprovider.model.SchemaElement) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) GmlAttribute(com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttribute) TypeDefinition(eu.esdihumboldt.hale.schemaprovider.model.TypeDefinition)

Example 7 with TranslationException

use of com.onespatial.jrc.tns.oml_to_rif.api.TranslationException in project hale by halestudio.

the class RifBindingToDomTranslator method translate.

/**
 * Translates a RIF {@link org.w3._2007.rif.Document} to a DOM
 * {@link Document}.
 *
 * @param rifDoc
 *            {@link org.w3._2007.rif.Document}
 * @return {@link Document}
 * @throws TranslationException
 *             if anything goes wrong during the translation
 */
@Override
public Document translate(org.w3._2007.rif.Document rifDoc) throws TranslationException {
    try {
        Document domDoc = documentBuilder.newDocument();
        marshaller.marshal(rifDoc, domDoc);
        return domDoc;
    } catch (JAXBException e) {
        throw new TranslationException(e);
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) Document(org.w3c.dom.Document)

Example 8 with TranslationException

use of com.onespatial.jrc.tns.oml_to_rif.api.TranslationException in project hale by halestudio.

the class RifMappingExportProvider method export.

/**
 * @see MappingExportProvider#export(Alignment, String, Collection, Collection)
 */
@Override
public MappingExportReport export(Alignment al, String path, Collection<SchemaElement> sourceSchema, Collection<SchemaElement> targetSchema) throws MappingExportException {
    MappingExportReport report = new MappingExportReport();
    try {
        HaleAlignment hal = new HaleAlignment(al, sourceSchema, targetSchema);
        Document document = AlignmentToRifTranslator.getInstance(report).translate(hal);
        DOMSource source = new DOMSource(document);
        File newFile = new File(path);
        OutputStream stream = new FileOutputStream(newFile);
        StreamResult result = new StreamResult(stream);
        TransformerFactory tFactory = TransformerFactory.newInstance();
        Transformer transformer = tFactory.newTransformer();
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        // $NON-NLS-1$ //$NON-NLS-2$
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
        transformer.transform(source, result);
    } catch (TranslationException e) {
        throw new MappingExportException(e.getMessage(), e);
    } catch (FileNotFoundException e) {
        throw new MappingExportException(e.getMessage(), e);
    } catch (TransformerException e) {
        throw new MappingExportException(e.getMessage(), e);
    }
    return report;
}
Also used : HaleAlignment(com.onespatial.jrc.tns.oml_to_rif.HaleAlignment) DOMSource(javax.xml.transform.dom.DOMSource) TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) TranslationException(com.onespatial.jrc.tns.oml_to_rif.api.TranslationException) Document(org.w3c.dom.Document) MappingExportReport(eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportReport) MappingExportException(eu.esdihumboldt.hale.ui.io.legacy.mappingexport.MappingExportException) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Aggregations

TranslationException (com.onespatial.jrc.tns.oml_to_rif.api.TranslationException)8 HaleAlignment (com.onespatial.jrc.tns.oml_to_rif.HaleAlignment)3 ModelAttributeMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAttributeMappingCell)2 ModelStaticAssignmentCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelStaticAssignmentCell)2 Alignment (eu.esdihumboldt.commons.goml.align.Alignment)2 ComposedProperty (eu.esdihumboldt.commons.goml.omwg.ComposedProperty)2 FeatureClass (eu.esdihumboldt.commons.goml.omwg.FeatureClass)2 IDetailedAbout (eu.esdihumboldt.commons.goml.rdf.IDetailedAbout)2 SchemaElement (eu.esdihumboldt.hale.schemaprovider.model.SchemaElement)2 ArrayList (java.util.ArrayList)2 Document (org.w3c.dom.Document)2 ModelAlignment (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelAlignment)1 ModelClassMappingCell (com.onespatial.jrc.tns.oml_to_rif.model.alignment.ModelClassMappingCell)1 GmlAttribute (com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttribute)1 GmlAttributePath (com.onespatial.jrc.tns.oml_to_rif.schema.GmlAttributePath)1 OmlRdfReader (eu.esdihumboldt.commons.goml.oml.io.OmlRdfReader)1 Property (eu.esdihumboldt.commons.goml.omwg.Property)1 Restriction (eu.esdihumboldt.commons.goml.omwg.Restriction)1 DetailedAbout (eu.esdihumboldt.commons.goml.rdf.DetailedAbout)1 ConstantValueFunction (eu.esdihumboldt.cst.corefunctions.ConstantValueFunction)1