|
From: <php...@li...> - 2010-01-21 01:05:27
|
Hi,
As you adviced me, I have tried to catch a RuntimeException before the execSelect call, but I have no success.
Here is the Java Code I want to transform to PHP code with PHP/Java Bridge:
import de.fuberlin.wiwiss.d2rq.*;
import com.hp.hpl.jena.query.*;
class pruebaSPARQL{
public pruebaSPARQL()
{
super();
}
public static void main(String argv[])
{
// Load mapping file
ModelD2RQ m = new ModelD2RQ("D:/DOCUMENTOS/alejandro/Maestria/tesis/egresados/herramientas/d2r-server-0.7/mapvariasLapOnto.n3");
String sparql =
"PREFIX onto: <http://localhost/egresados/site/egresado.owl#>" +
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" +
"SELECT DISTINCT ?carrera WHERE {" +
" ?egresado onto:Carrera ?carrera . " +
"}";
Query q = QueryFactory.create(sparql);
ResultSet rs = QueryExecutionFactory.create(q, m).execSelect();
while (rs.hasNext()) {
QuerySolution row = rs.nextSolution();
System.out.println("Carrera: " + row.getLiteral("carrera").getString());
}
}
}
According to "http://jena.sourceforge.net/ARQ/javadoc/com/hp/hpl/jena/query/package-summary.html", QueryExecutionFactory.create(q, m) returns a QueryExecution Java interface and the execSelect() call should returns a ResultSet Java interface.
Is there (with PHP/Java Bridge) any special thing I have to consider when I work with Java interfaces rather than classes?.
Here is what I have tried with PHP/Java Bridge.
<?php
define ("JAVA_PREFER_VALUES", true);
require_once("http://localhost:8080/egresados/java/Java.inc");
class PRUEBA
{
public function execute()
{
$java_library_path = "D:\\DOCUMENTOS\\alejandro\\Maestria\\tesis\\egresados\\herramientas\\Jena-2.6.2\\lib\\;D:\\DOCUMENTOS\\alejandro\\Maestria\\tesis\\egresados\\herramientas\\d2r-server-0.7\\lib\\";
try {
java_require($java_library_path);
$modelD2RQ = new Java("de.fuberlin.wiwiss.d2rq.ModelD2RQ", "D:\\DOCUMENTOS\\alejandro\\Maestria\\tesis\\egresados\\herramientas\\d2r-server-0.7\\mapvariasLapOnto.n3");
$sparqlString = htmlentities("PREFIX onto: <http://localhost/egresados/site/egresado.owl#>" .
"PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>" .
"SELECT DISTINCT ?carrera WHERE {" .
" ?egresado onto:Carrera ?carrera . " .
"}");
echo $sparqlString;
$query = Java("com.hp.hpl.jena.query.QueryFactory")->create($sparqlString);
$rs = Java("com.hp.hpl.jena.query.QueryExecutionFactory")->create($query, $modelD2RQ)->execSelect();
/*while($rs.hasNext()){
//$row = new java("com.hp.hpl.jena.query.QuerySolution");
$row = $rs.nextSolution();
echo $row.getLiteral("carrera").getString();
}*/
}catch (JavaException $ex) {
$trace = new Java("java.io.ByteArrayOutputStream");
$ex->printStackTrace(new Java("java.io.PrintStream", $trace));
print "java stack trace: $trace\n";
}
}
}
?>
Sincerly, thank you very much.
> Date: Sun, 17 Jan 2010 20:18:14 +0100
> To: php...@li...
> From: php...@li...
> Subject: Re: [Php-java-bridge-users] Help
>
> Hi,
>
> like other containers (EJB for example), the PHP/Java Bridge container
> terminates the current transaction if a java.lang.RuntimeException or
> java.lang.Error crosses the container boundary. However, it does not
> terminate it immediately, to give you a chance to clear the error condition
> before the PHP script terminates.
>
> Please see
> http://php-java-bridge.sourceforge.net/pjb/docs/php-api/JavaBridge/_JavaProxy.inc.html#functionjava_last_exception_clear
> for details.
>
> Please see our FAQ entry "Why doesn't the bridge throw a
> java.lang.RuntimeException or Error as a PHP JavaException by default?"
>
>
> > [[o:Response$
> > UndeclaredThrowableErrorMarker]]->execSelect. Cause:
> > java.lang.NoSuchMethodException: execSelect(). Candidates: [] VM:
>
> please take a look at the error message again; your code:
>
> $query = Java("com.hp.hpl.jena.query.QueryFactory")->create($sparqlString);
> //---OK.
>
> has thrown a java.lang.Error or java.lang.RuntimeException, which is
> reported as a PHP warning. In the next step you ignore the warning, take the
> RuntimeException and try to invoke execSelect() on it, which fails, of
> course.
>
> If you want java.lang.Error and java.lang.RuntimeException to fail fast,
> define("JAVA_PREFER_VALUES", true) before including Java.inc.
>
>
> Regards,
> Jost Boekemeier
> ------------------------------------------------------------------------------
> Throughout its 18-year history, RSA Conference consistently attracts the
> world's best and brightest in the field, creating opportunities for Conference
> attendees to learn about information security's most important issues through
> interactions with peers, luminaries and emerging and established companies.
> http://p.sf.net/sfu/rsaconf-dev2dev
> _______________________________________________
> php-java-bridge-users mailing list
> php...@li...
> https://lists.sourceforge.net/lists/listinfo/php-java-bridge-users
_________________________________________________________________
Juega y gana con Samsung y Windows Live
http://www.equipatucasa.com.mx
|