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;
}
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;
}
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());
}
}
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());
}
}
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;
}
Aggregations