I want to use an applet to change a repository. To do this I wrote the following code:
LoadOntology:
package owlapi.loader;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.io.*;
import org.semanticweb.owlapi.model.*;
import org.semanticweb.owlapi.util.DefaultPrefixManager;
import org.semanticweb.owlapi.util.OWLEntityRenamer;
import java.io.File;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class LoadOntology {
private static String ontologyDir = "./owlapi/loader/featurepool.owl";
private static OWLOntology localOntology;
private static OWLOntologyManager manager;
private static OWLDataFactory factory;
private static PrefixManager pm = new DefaultPrefixManager("http://wise.vub.ac.be/Members/lamia/variability/Feature_Assembly/FAM.owl#");
public LoadOntology() {
manager = OWLManager.createOWLOntologyManager();
File file = new File(ontologyDir);
try {
localOntology = manager.loadOntologyFromOntologyDocument(file);
System.out.println("Loaded ontology: " + localOntology);
factory = manager.getOWLDataFactory();
}
catch (UnparsableOntologyException e) {
System.out.println("Could not parse the ontology: " + e.getMessage());
Map<OWLParser, OWLParserException> exceptions = e.getExceptions();
for (OWLParser parser : exceptions.keySet()) {
System.out.println("Tried to parse the ontology with the " + parser.getClass().getSimpleName() + " parser");
System.out.println("Failed because: " + exceptions.get(parser).getMessage());
}
}
catch (UnloadableImportException e) {
System.out.println("Could not load import: " + e.getImportsDeclaration());
OWLOntologyCreationException cause = e.getOntologyCreationException();
System.out.println("Reason: " + cause.getMessage());
}
catch (OWLOntologyCreationException e) {
System.out.println("Could not load ontology: " + e.getMessage());
}
}
public void addInstance(String Class, String individual) {
OWLClass owlClass = factory.getOWLClass(Class, pm);
OWLClass superClass = factory.getOWLThing();
OWLIndividual instance = factory.getOWLNamedIndividual(individual, pm);
OWLClassAssertionAxiom classAssertion1 = factory.getOWLClassAssertionAxiom(superClass, instance);
manager.addAxiom(localOntology, classAssertion1);
OWLClassAssertionAxiom classAssertion2 = factory.getOWLClassAssertionAxiom(owlClass, instance);
manager.addAxiom(localOntology, classAssertion2);
System.out.println("Instance added");
}
}
InJava (applet loaded in javascript):
public class InJava extends Applet{
private static LoadOntology loadedOntology;
public void addInstance(String Class, String individual) {
Graphics g = getGraphics();
g.drawString("Test", 10, 10);
loadedOntology = new LoadOntology();
loadedOntology.addInstance(Class, individual);
}
}
When I load the applet, there is no error at all, but when I try to call the method addInstance:
<input type="button" value="call Java Applet method" onClick = 'document.owlapi.addInstance("Abstract_Feature", "New_Test")'>
<APPLET CODE="owlapi/InJava.class" NAME="owlapi" HEIGHT=100 WIDTH=100> </APPLET>
The browser throws the error Uncaught Error: Error calling method on NPObject. After reading some questions about this on stackoverflow, I came only to the conclusion that there has to be something wrong with the plugin.
I added some testing-code to the method (the drawString("Test", 10, 10)) which works, so I suggest that the constructing of the LoadOntology class gives some issues (this class was tested separately in works perfect on its own). Does anybody see what I am doing wrong?
update: I added the a part of the java class that is used by the applet: the repository loader. All the provided code should compile.
update: I didn't use MASCRIPT/SCRIPTABLE because the code is based on this example, which works in my current browser (chrome)
udpate: You have to include the owlapi jars to the buildpath, which can be downloaded here
MAYSCRIPT/SCRIPTABLEif it is interacting with JavaScript? What does the JS do?owlapi& it is in the compilation class-path. Neither of which is the case here. 2) If theowlapiis indeed required for the applet, it will need to be added to the run-time class-path of the applet. 3) What about that link? 4)File file = new File(ontologyDir);That won't work in a sand-boxed applet. If that resource is on your server, it would not even work for a trusted applet. In the latter case, access it by URL. 5) What is the structure of the server in terms of location of HTML, class and API Jars?