Search in sources :

Example 1 with AdaptableAtom

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;
}
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 2 with AdaptableAtom

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;
}
Also used : UnsupportedTypeForExportException(org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException) AdaptableAtom(org.apache.stanbol.rules.adapters.AdaptableAtom)

Example 3 with AdaptableAtom

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;
}
Also used : AdaptableAtom(org.apache.stanbol.rules.adapters.AdaptableAtom)

Example 4 with AdaptableAtom

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;
}
Also used : RuleAtomCallExeption(org.apache.stanbol.rules.base.api.RuleAtomCallExeption) AdaptableAtom(org.apache.stanbol.rules.adapters.AdaptableAtom)

Aggregations

AdaptableAtom (org.apache.stanbol.rules.adapters.AdaptableAtom)4 UnsupportedTypeForExportException (org.apache.stanbol.rules.base.api.UnsupportedTypeForExportException)2 VariableAtom (org.apache.stanbol.rules.adapters.jena.atoms.VariableAtom)1 RuleAtomCallExeption (org.apache.stanbol.rules.base.api.RuleAtomCallExeption)1