Search in sources :

Example 6 with UnsupportedTypeForExportException

use of org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException in project stanbol by apache.

the class JenaAdapter method adaptRuleAtomTo.

@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRuleAtomTo(RuleAtom ruleAtom, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    if (type == com.hp.hpl.jena.reasoner.rulesys.Rule.class) {
        String className = ruleAtom.getClass().getSimpleName();
        String canonicalName = ARTIFACT + "." + className;
        try {
            Class<AdaptableAtom> jenaAtomClass = (Class<AdaptableAtom>) Class.forName(canonicalName);
            try {
                AdaptableAtom jenaAtom = jenaAtomClass.newInstance();
                if (jenaAtom instanceof VariableAtom) {
                    System.out.println("Class equals");
                }
                jenaAtom.setRuleAdapter(this);
                return (T) jenaAtom.adapt(ruleAtom);
            } catch (InstantiationException e) {
                log.error(e.getMessage(), e);
            } catch (IllegalAccessException e) {
                log.error(e.getMessage(), e);
            }
        } catch (ClassNotFoundException e) {
            log.error(e.getMessage(), e);
        } catch (SecurityException e) {
            log.error(e.getMessage(), e);
        }
    } else {
        throw new UnsupportedTypeForExportException("The adapter " + getClass() + " does not support type : " + type.getCanonicalName());
    }
    return null;
}
Also used : VariableAtom(org.apache.stanbol.rules.adapters.jena.atoms.VariableAtom) AdaptableAtom(org.apache.stanbol.rules.adapters.AdaptableAtom) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)

Example 7 with UnsupportedTypeForExportException

use of org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException in project stanbol by apache.

the class ClerezzaAdapter method adaptRecipeTo.

@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRecipeTo(Recipe recipe, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    List<ConstructQuery> constructQueries = null;
    if (type == ConstructQuery.class) {
        constructQueries = new ArrayList<ConstructQuery>();
        RuleList ruleList = recipe.getRuleList();
        Iterator<Rule> ruleIterator = ruleList.iterator();
        for (int i = 0; ruleIterator.hasNext(); i++) {
            constructQueries.add((ConstructQuery) adaptRuleTo(ruleIterator.next(), type));
        }
    } else {
        throw new UnsupportedTypeForExportException("The adapter for Clerezza does not support the selected serialization : " + type.getCanonicalName());
    }
    return (T) constructQueries;
}
Also used : RuleList(org.apache.stanbol.rules.base.api.util.RuleList) UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) Rule(org.apache.stanbol.rules.base.api.Rule) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) SimpleConstructQuery(org.apache.clerezza.rdf.core.sparql.query.impl.SimpleConstructQuery)

Example 8 with UnsupportedTypeForExportException

use of org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException in project stanbol by apache.

the class SWRLAdpterTest method wrongAdaptabeClassTest.

@SuppressWarnings("unchecked")
@Test
public void wrongAdaptabeClassTest() {
    try {
        List<ConstructQuery> constructQueries = (List<ConstructQuery>) ruleAdapter.adaptTo(recipeGood, ConstructQuery.class);
        for (ConstructQuery constructQuery : constructQueries) {
            log.debug(constructQuery.toString());
            Assert.fail("The adapter for Jena should not accept " + ConstructQuery.class.getCanonicalName() + " objects.");
        }
    } catch (UnavailableRuleObjectException e) {
        Assert.fail(e.getMessage());
    } catch (UnsupportedTypeForExportException e) {
        log.debug(e.getMessage());
    } catch (RuleAtomCallExeption e) {
        Assert.fail(e.getMessage());
    }
}
Also used : UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) List(java.util.List) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) ConstructQuery(org.apache.clerezza.rdf.core.sparql.query.ConstructQuery) Test(org.junit.Test)

Example 9 with UnsupportedTypeForExportException

use of org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException in project stanbol by apache.

the class SPARQLAdpterTest method test.

@SuppressWarnings("unchecked")
@Test
public void test() {
    try {
        List<SPARQLObject> sparqlObjects = (List<SPARQLObject>) ruleAdapter.adaptTo(recipeGood, SPARQLObject.class);
        for (SPARQLObject sparqlObject : sparqlObjects) {
            log.debug(sparqlObject.getObject());
        }
        Assert.assertTrue(true);
    } catch (UnavailableRuleObjectException e) {
        Assert.fail(e.getMessage());
    } catch (UnsupportedTypeForExportException e) {
        Assert.fail(e.getMessage());
    } catch (RuleAtomCallExeption e) {
        Assert.fail(e.getMessage());
    }
}
Also used : UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) SPARQLObject(org.apache.stanbol.rules.base.api.SPARQLObject) UnavailableRuleObjectException(org.apache.stanbol.rules.base.api.UnavailableRuleObjectException) List(java.util.List) RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) Test(org.junit.Test)

Example 10 with UnsupportedTypeForExportException

use of org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException in project stanbol by apache.

the class SWRLAdapter method adaptRuleAtomTo.

@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRuleAtomTo(RuleAtom ruleAtom, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
    if (type == SWRLRule.class) {
        String className = ruleAtom.getClass().getSimpleName();
        String canonicalName = ARTIFACT + "." + className;
        try {
            Class<AdaptableAtom> swrlAtomClass = (Class<AdaptableAtom>) Class.forName(canonicalName);
            try {
                AdaptableAtom swrlAtom = swrlAtomClass.newInstance();
                swrlAtom.setRuleAdapter(this);
                return (T) swrlAtom.adapt(ruleAtom);
            } catch (InstantiationException e) {
                log.error(e.getMessage(), e);
            } catch (IllegalAccessException e) {
                log.error(e.getMessage(), e);
            }
        } catch (ClassNotFoundException e) {
            log.error(e.getMessage(), e);
        } catch (SecurityException e) {
            log.error(e.getMessage(), e);
        }
    } else {
        throw new UnsupportedTypeForExportException("The adapter " + getClass() + " does not support type : " + type.getCanonicalName());
    }
    return null;
}
Also used : UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) AdaptableAtom(org.apache.stanbol.rules.adapters.AdaptableAtom)

Aggregations

UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)29 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)21 UnavailableRuleObjectException (org.apache.stanbol.rules.base.api.UnavailableRuleObjectException)21 SPARQLObject (org.apache.stanbol.rules.base.api.SPARQLObject)11 List (java.util.List)10 Test (org.junit.Test)7 ConstructQuery (org.apache.clerezza.rdf.core.sparql.query.ConstructQuery)6 SPARQLComparison (org.apache.stanbol.rules.adapters.sparql.SPARQLComparison)5 Rule (org.apache.stanbol.rules.base.api.Rule)5 RuleAdapter (org.apache.stanbol.rules.base.api.RuleAdapter)5 RuleList (org.apache.stanbol.rules.base.api.util.RuleList)5 SPARQLFunction (org.apache.stanbol.rules.adapters.sparql.SPARQLFunction)4 Recipe (org.apache.stanbol.rules.base.api.Recipe)4 StringFunctionAtom (org.apache.stanbol.rules.manager.atoms.StringFunctionAtom)4 Rule (com.hp.hpl.jena.reasoner.rulesys.Rule)3 IRI (org.apache.clerezza.commons.rdf.IRI)3 NoSuchRecipeException (org.apache.stanbol.rules.base.api.NoSuchRecipeException)3 RecipeConstructionException (org.apache.stanbol.rules.base.api.RecipeConstructionException)3 RuleAtom (org.apache.stanbol.rules.base.api.RuleAtom)3 NumericFunctionAtom (org.apache.stanbol.rules.manager.atoms.NumericFunctionAtom)3