From: <jen...@us...> - 2008-02-17 10:50:18
|
Revision: 588 http://dl-learner.svn.sourceforge.net/dl-learner/?rev=588&view=rev Author: jenslehmann Date: 2008-02-17 02:50:06 -0800 (Sun, 17 Feb 2008) Log Message: ----------- - created ComponentInitException (thrown when exceptions occur during component initialisation) - abstract init method in Component now throws ComponentInitException - @developers: please update your code accordingingly (currently I only added default try-catch-blocks) Modified Paths: -------------- trunk/src/dl-learner/org/dllearner/cli/Start.java trunk/src/dl-learner/org/dllearner/core/Component.java trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java trunk/src/dl-learner/org/dllearner/test/ComponentTest.java trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java Added Paths: ----------- trunk/src/dl-learner/org/dllearner/core/ComponentInitException.java Modified: trunk/src/dl-learner/org/dllearner/cli/Start.java =================================================================== --- trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/cli/Start.java 2008-02-17 10:50:06 UTC (rev 588) @@ -44,6 +44,7 @@ import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; @@ -119,15 +120,22 @@ logger.addAppender(consoleAppender); logger.setLevel(Level.INFO); - Start start = new Start(file); + Start start = null; + try { + start = new Start(file); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } start.start(inQueryMode); } /** * Initialise all components based on conf file. * @param file Conf file to read. + * @throws ComponentInitException */ - public Start(File file) { + public Start(File file) throws ComponentInitException { String baseDir = file.getParentFile().getPath(); // create component manager instance @@ -542,7 +550,7 @@ } } - private static void initComponent(ComponentManager cm, Component component) { + private static void initComponent(ComponentManager cm, Component component) throws ComponentInitException { String startMessage = "initialising component \"" + cm.getComponentName(component.getClass()) + "\" ... "; long initStartTime = System.nanoTime(); Modified: trunk/src/dl-learner/org/dllearner/core/Component.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/Component.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/core/Component.java 2008-02-17 10:50:06 UTC (rev 588) @@ -52,7 +52,7 @@ /** * Method to be called after the component has been configured. */ - public abstract void init(); + public abstract void init() throws ComponentInitException; /** * Applies a configuration option to this component. Added: trunk/src/dl-learner/org/dllearner/core/ComponentInitException.java =================================================================== --- trunk/src/dl-learner/org/dllearner/core/ComponentInitException.java (rev 0) +++ trunk/src/dl-learner/org/dllearner/core/ComponentInitException.java 2008-02-17 10:50:06 UTC (rev 588) @@ -0,0 +1,46 @@ +/** + * Copyright (C) 2007-2008, Jens Lehmann + * + * This file is part of DL-Learner. + * + * DL-Learner is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * DL-Learner is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ +package org.dllearner.core; + +/** + * Exception which is thrown when a component cannot be intialised, + * e.g. due to bad configuration parameteres or unforeseen + * circumstances unreachable web files. It can encapsulate arbitrary + * exceptions occuring during initialisation. + * + * @author Jens Lehmann + * + */ +public class ComponentInitException extends Exception { + + private static final long serialVersionUID = -3550079897929658317L; + + public ComponentInitException(String message) { + super(message); + } + + public ComponentInitException(Exception exception) { + super(exception); + } + + public ComponentInitException(String message, Exception exception) { + super(message, exception); + } +} Modified: trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/gui/KnowledgeSourcePanel.java 2008-02-17 10:50:06 UTC (rev 588) @@ -26,6 +26,8 @@ import java.awt.Color; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; + +import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; /** @@ -116,7 +118,12 @@ */ public void init() { if (config.getKnowledgeSource() != null && config.getURI() != null) { - config.getKnowledgeSource().init(); + try { + config.getKnowledgeSource().init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } config.setInitKnowledgeSource(true); System.out.println("init KnowledgeSource"); startGUI.updateTabColors(); Modified: trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/gui/LearningAlgorithmPanel.java 2008-02-17 10:50:06 UTC (rev 588) @@ -27,6 +27,7 @@ import java.awt.event.ActionListener; import java.util.List; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblemUnsupportedException; @@ -127,7 +128,12 @@ public void init() { setLearningAlgorithm(); if (config.getLearningProblem() != null) { - config.getLearningAlgorithm().init(); + try { + config.getLearningAlgorithm().init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } config.setInitLearningAlgorithm(true); System.out.println("init LearningAlgorithm"); startGUI.updateTabColors(); Modified: trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/gui/LearningProblemPanel.java 2008-02-17 10:50:06 UTC (rev 588) @@ -26,6 +26,8 @@ import java.awt.event.ActionListener; import java.util.List; import javax.swing.*; + +import org.dllearner.core.ComponentInitException; import org.dllearner.core.LearningProblem; /** @@ -121,7 +123,12 @@ private void init() { setLearningProblem(); if (config.getReasoner() != null && config.getLearningProblem() != null) { - config.getLearningProblem().init(); + try { + config.getLearningProblem().init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } config.setInitLearningProblem(true); System.out.println("init LearningProblem"); startGUI.updateTabColors(); Modified: trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/gui/MiniGUI.java 2008-02-17 10:50:06 UTC (rev 588) @@ -39,6 +39,7 @@ import javax.swing.JTextField; import org.dllearner.algorithms.refinement.ROLearner; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; @@ -134,12 +135,22 @@ // (everything else will cause an exception) KnowledgeSource source = cm.knowledgeSource(OWLFile.class); cm.applyConfigEntry(source, "url", selectedFile.toURI().toString()); - source.init(); + try { + source.init(); + } catch (ComponentInitException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } // use a reasoner to find out which instances exist // in the background knowledge ReasonerComponent reasoner = cm.reasoner(DIGReasoner.class, source); - reasoner.init(); + try { + reasoner.init(); + } catch (ComponentInitException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } rs = cm.reasoningService(reasoner); Set<Individual> individualsSet = rs.getIndividuals(); individuals = new LinkedList<Individual>(individualsSet); @@ -160,7 +171,12 @@ // create a positive only learning problem LearningProblem lp = cm.learningProblem(PosOnlyDefinitionLP.class, rs); cm.applyConfigEntry(lp, "positiveExamples", exampleSet); - lp.init(); + try { + lp.init(); + } catch (ComponentInitException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } // try the refinement operator based learning algorithm to solve // the problem @@ -171,7 +187,12 @@ // TODO Auto-generated catch block e1.printStackTrace(); } - la.init(); + try { + la.init(); + } catch (ComponentInitException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } la.start(); // wait for a solution (note that not all learning problems have a Modified: trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java =================================================================== --- trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/gui/ReasonerPanel.java 2008-02-17 10:50:06 UTC (rev 588) @@ -28,6 +28,7 @@ import javax.swing.*; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.ReasonerComponent; /** @@ -127,7 +128,12 @@ public void init() { setReasoner(); if (config.getKnowledgeSource() != null && config.getReasoner() != null) { - config.getReasoner().init(); + try { + config.getReasoner().init(); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } System.out.println("init Reasoner"); // set ReasoningService config.setReasoningService(config.getComponentManager() Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGHTTPConnector.java 2008-02-17 10:50:06 UTC (rev 588) @@ -67,7 +67,13 @@ public URI newKB() { NewKBDocument newKB = NewKBDocument.Factory.newInstance(); newKB.addNewNewKB(); - String answer = sendAndReceive(newKB.toString()); + String answer = ""; + try { + answer = sendAndReceive(newKB.toString()); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } ResponseDocument rd = parse(answer); IdRespType rt = rd.getResponse(); @@ -89,15 +95,22 @@ public boolean releaseKB(URI kbURI) { ReleaseKBDocument releaseKB = ReleaseKBDocument.Factory.newInstance(); releaseKB.addNewReleaseKB().setUri(kbURI.toString()); - String answer = sendAndReceive(releaseKB.toString()); + String answer = ""; + try { + answer = sendAndReceive(releaseKB.toString()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } ResponseDocument rd = parse(answer); return rd.getResponse().isSetOk(); } - public String getIdentifier() { + public String getIdentifier() throws IOException { GetIdentifierDocument gid = GetIdentifierDocument.Factory.newInstance(); gid.addNewGetIdentifier(); - String answer = sendAndReceive(gid.toString()); + String answer = ""; + answer = sendAndReceive(gid.toString()); IdentifierDocument id = null; try { id = IdentifierDocument.Factory.parse(answer); @@ -111,7 +124,7 @@ } // tell-Anfrage als XML-String schicken - public ResponseDocument tells(String tells) { + public ResponseDocument tells(String tells) throws IOException { return parse(sendAndReceive(tells)); } @@ -121,7 +134,13 @@ public ResponsesDocument asks(String asks) { askCounter++; - String answer = sendAndReceive(asks); + String answer = ""; + try { + answer = sendAndReceive(asks); + } catch (IOException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } ResponsesDocument rd = null; try { rd = ResponsesDocument.Factory.parse(answer); @@ -142,13 +161,13 @@ return rd; } - private String sendAndReceive(String send) { + private String sendAndReceive(String send) throws IOException { StringBuilder answer = new StringBuilder(); // String an DIG-Reasoner schicken HttpURLConnection connection; - try { +// try { connection = (HttpURLConnection) url.openConnection(); connection.setDoOutput(true); @@ -174,10 +193,10 @@ br.close(); - } catch (IOException e) { - System.out.println("Communication problem with DIG Reasoner. Please make sure there is a DIG reasoner running at " + url + " and try again."); - System.exit(0); - } +// } catch (IOException e) { +// System.out.println("Communication problem with DIG Reasoner. Please make sure there is a DIG reasoner running at " + url + " and try again."); +// System.exit(0); +// } if(protocolFile != null) Files.appendFile(protocolFile, "DIG code received from reasoner:\n\n"+answer+"\n\n"); Modified: trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/reasoning/DIGReasoner.java 2008-02-17 10:50:06 UTC (rev 588) @@ -20,6 +20,7 @@ package org.dllearner.reasoning; import java.io.File; +import java.io.IOException; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; @@ -36,6 +37,7 @@ import javax.xml.namespace.QName; import org.apache.xmlbeans.XmlCursor; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.OntologyFormat; import org.dllearner.core.ReasonerComponent; @@ -112,7 +114,7 @@ } @Override - public void init() { + public void init() throws ComponentInitException { // if a DIG protocol is written clear the file first if(writeDIGProtocol) { if(digProtocolFile == null) @@ -123,7 +125,11 @@ connector = new DIGHTTPConnector(reasonerURL); } - identifier = connector.getIdentifier(); + try { + identifier = connector.getIdentifier(); + } catch (IOException e1) { + throw new ComponentInitException("Communication problem with DIG Reasoner. Please make sure there is a DIG reasoner running at " + reasonerURL + " and try again.", e1); + } kbURI = connector.newKB(); // asks-Prefix entsprechend der KB-URI initialisieren @@ -144,7 +150,13 @@ for (KnowledgeSource source : sources) { sb.append(source.toDIG(kbURI)); - ResponseDocument rd = connector.tells(sb.toString()); + ResponseDocument rd = null; + try { + rd = connector.tells(sb.toString()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } if (!rd.getResponse().isSetOk()) { System.err.println("DIG-Reasoner cannot read knowledgebase."); System.exit(0); Modified: trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java =================================================================== --- trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/reasoning/FastRetrievalReasoner.java 2008-02-17 10:50:06 UTC (rev 588) @@ -5,6 +5,7 @@ import java.util.SortedSet; import java.util.TreeSet; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.ReasonerComponent; import org.dllearner.core.ReasoningMethodUnsupportedException; @@ -36,7 +37,12 @@ public FastRetrievalReasoner(Set<KnowledgeSource> sources) { rc = new DIGReasoner(sources); - rc.init(); + try { + rc.init(); + } catch (ComponentInitException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } atomicConcepts = rc.getAtomicConcepts(); atomicRoles = rc.getAtomicRoles(); individuals = rc.getIndividuals(); Modified: trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java =================================================================== --- trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/server/DLLearnerWS.java 2008-02-17 10:50:06 UTC (rev 588) @@ -41,6 +41,7 @@ import org.dllearner.algorithms.refexamples.ExampleBasedROLComponent; import org.dllearner.algorithms.refinement.ROLearner; import org.dllearner.core.Component; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; @@ -262,9 +263,10 @@ /** * Initialise all components. * @param id Session ID. + * @throws ComponentInitException */ @WebMethod - public void initAll(int id) throws ClientNotKnownException { + public void initAll(int id) throws ClientNotKnownException, ComponentInitException { ClientState state = getState(id); for(KnowledgeSource ks : state.getKnowledgeSources()) ks.init(); @@ -279,9 +281,10 @@ * @param componentID Component-ID. * @throws ClientNotKnownException Thrown if the client ID is nor registered. * @throws UnknownComponentException Thrown if the component is unknown. + * @throws ComponentInitException */ @WebMethod - public void init(int id, int componentID) throws ClientNotKnownException, UnknownComponentException { + public void init(int id, int componentID) throws ClientNotKnownException, UnknownComponentException, ComponentInitException { ClientState state = getState(id); Component component = state.getComponent(componentID); component.init(); Modified: trunk/src/dl-learner/org/dllearner/test/ComponentTest.java =================================================================== --- trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/test/ComponentTest.java 2008-02-17 10:50:06 UTC (rev 588) @@ -24,6 +24,7 @@ import java.util.TreeSet; import org.dllearner.algorithms.RandomGuesser; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.KnowledgeSource; import org.dllearner.core.LearningAlgorithm; @@ -45,8 +46,9 @@ /** * @param args + * @throws ComponentInitException */ - public static void main(String[] args) { + public static void main(String[] args) throws ComponentInitException { // get singleton instance of component manager ComponentManager cm = ComponentManager.getInstance(); Modified: trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java =================================================================== --- trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java 2008-02-17 10:11:48 UTC (rev 587) +++ trunk/src/dl-learner/org/dllearner/utilities/CrossValidation.java 2008-02-17 10:50:06 UTC (rev 588) @@ -31,6 +31,7 @@ import org.apache.log4j.Logger; import org.apache.log4j.SimpleLayout; import org.dllearner.cli.Start; +import org.dllearner.core.ComponentInitException; import org.dllearner.core.ComponentManager; import org.dllearner.core.LearningAlgorithm; import org.dllearner.core.LearningProblem; @@ -84,7 +85,13 @@ // the first read of the file is used to detect the examples // and set up the splits correctly according to our validation // method - Start start = new Start(file); + Start start = null; + try { + start = new Start(file); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } LearningProblem lp = start.getLearningProblem(); ReasoningService rs = start.getReasoningService(); @@ -162,7 +169,12 @@ for(int currFold=0; currFold<folds; currFold++) { // we always perform a full initialisation to make sure that // no objects are reused - start = new Start(file); + try { + start = new Start(file); + } catch (ComponentInitException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } lp = start.getLearningProblem(); Set<String> pos = Datastructures.individualSetToStringSet(trainingSetsPos.get(currFold)); Set<String> neg = Datastructures.individualSetToStringSet(trainingSetsNeg.get(currFold)); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |