use of org.apache.stanbol.rules.adapters.AdaptableAtom 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.adapters.AdaptableAtom 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;
}
use of org.apache.stanbol.rules.adapters.AdaptableAtom in project stanbol by apache.
the class ClerezzaAdapter method adaptRuleAtomTo.
@SuppressWarnings("unchecked")
@Override
protected <T> T adaptRuleAtomTo(RuleAtom ruleAtom, Class<T> type) throws RuleAtomCallExeption, UnsupportedTypeForExportException, UnavailableRuleObjectException {
if (type == ConstructQuery.class) {
//ClassLoader loader = Thread.currentThread().getContextClassLoader();
//log.info("loader : " + loader);
String className = ruleAtom.getClass().getSimpleName();
String canonicalName = ARTIFACT + "." + className;
try {
Class<AdaptableAtom> clerezzaAtomClass = (Class<AdaptableAtom>) Class.forName(canonicalName);
try {
AdaptableAtom clerezzaAtom = clerezzaAtomClass.newInstance();
clerezzaAtom.setRuleAdapter(this);
return (T) clerezzaAtom.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);
}
}
return null;
}
use of org.apache.stanbol.rules.adapters.AdaptableAtom 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;
}
Aggregations