use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class SubstringAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
org.apache.stanbol.rules.manager.atoms.SubstringAtom tmp = (org.apache.stanbol.rules.manager.atoms.SubstringAtom) ruleAtom;
StringFunctionAtom stringFunctionAtom = tmp.getStringFunctionAtom();
NumericFunctionAtom startAtom = tmp.getStart();
NumericFunctionAtom lengthAtom = tmp.getLength();
try {
SPARQLObject stringSparqlAtom = adapter.adaptTo(stringFunctionAtom, SPARQLObject.class);
SPARQLObject startSparqlAtom = adapter.adaptTo(startAtom, SPARQLObject.class);
SPARQLObject lengthSparqlAtom = adapter.adaptTo(lengthAtom, SPARQLObject.class);
String uriResourceString = stringSparqlAtom.getObject();
String start = startSparqlAtom.getObject();
String length = lengthSparqlAtom.getObject();
String sparql = "<http://www.w3.org/2005/xpath-functions#substring> (" + uriResourceString + ", " + start + ", " + length + ")";
return (T) new SPARQLFunction(sparql);
} catch (UnsupportedTypeForExportException e) {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
} catch (UnavailableRuleObjectException e) {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class UpperCaseAtom method adapt.
@SuppressWarnings("unchecked")
@Override
public <T> T adapt(RuleAtom ruleAtom) throws RuleAtomCallExeption {
StringFunctionAtom argument = ((org.apache.stanbol.rules.manager.atoms.UpperCaseAtom) ruleAtom).getStringFunctionAtom();
try {
SPARQLObject sparqlArgument = adapter.adaptTo(argument, SPARQLObject.class);
String sparql = "<http://www.w3.org/2005/xpath-functions#upper-case> (" + sparqlArgument.getObject() + ")";
return (T) new SPARQLFunction(sparql);
} catch (UnsupportedTypeForExportException e) {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
} catch (UnavailableRuleObjectException e) {
throw new org.apache.stanbol.rules.base.api.RuleAtomCallExeption(getClass());
}
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class SPARQLAdapter method adaptRuleAtomTo.
@SuppressWarnings("unchecked")
protected <T> T adaptRuleAtomTo(RuleAtom ruleAtom, Class<T> type) throws UnsupportedTypeForExportException, UnavailableRuleObjectException {
if (type == SPARQLObject.class) {
String className = ruleAtom.getClass().getSimpleName();
String canonicalName = ARTIFACT + "." + className;
try {
Class<AdaptableAtom> sparqlAtomClass = (Class<AdaptableAtom>) Class.forName(canonicalName);
try {
AdaptableAtom sparqlAtom = sparqlAtomClass.newInstance();
sparqlAtom.setRuleAdapter(this);
return (T) sparqlAtom.adapt(ruleAtom);
} catch (InstantiationException e) {
log.error(e.getMessage(), e);
} catch (IllegalAccessException e) {
log.error(e.getMessage(), e);
} catch (RuleAtomCallExeption e) {
log.error(e.getMessage(), e);
}
} catch (ClassNotFoundException e) {
log.error(e.getMessage(), e);
} catch (SecurityException e) {
log.error(e.getMessage(), e);
}
}
return null;
}
use of org.apache.stanbol.rules.base.api.RuleAtomCallExeption in project stanbol by apache.
the class JenaAdpterTest 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.RuleAtomCallExeption in project stanbol by apache.
the class JenaAdpterTest method test.
@SuppressWarnings("unchecked")
@Test
public void test() {
try {
List<Rule> rules = (List<Rule>) ruleAdapter.adaptTo(recipeGood, Rule.class);
StringBuilder sb = new StringBuilder();
for (Rule rule : rules) {
sb.append(rule.toString());
}
Assert.assertNotSame(sb.toString(), "");
} catch (UnavailableRuleObjectException e) {
Assert.fail(e.getMessage());
} catch (UnsupportedTypeForExportException e) {
Assert.fail(e.getMessage());
} catch (RuleAtomCallExeption e) {
Assert.fail(e.getMessage());
}
}
Aggregations