Hello,

some additional remarks.
1. The code is incomplete: as I was typing it, I saw that the methods of
model weren't suggested, as if Java compiler does not recognize the imported
package. This does not happen when the same code is used as a Java
Application. It compiles and runs without problems.
2. I am not an expert in Java or even JavaBeans.

Cheers

HJdM



2011/6/29 Herli Joaquim de Menezes <[email protected]>

> Hello, friends
>
> Sorry for the long post. I am into a java web project using Jena. The
> architecture is MVC, and in de Model I am trying to use some javabeans to
> access and perform some processing on a OWL and a RDF file. The logic is
> somewhat simple, I have to extract a path from a simple ontology in OWL. So
> I am using the findShortestPath from OntTools (Comments are in Portuguese,
> and are just for debugging). However there is a weird thing. I got an error
> if I write something as:
> ++++++++++++
> package composicao.model;
>
> import java.util.HashSet;
> import java.util.Iterator;
> import java.util.LinkedList;
> import java.util.List;
> import java.util.Set;
> import java.util.*;
>
> import com.hp.hpl.jena.ontology.OntModel;
> import com.hp.hpl.jena.ontology.OntClass;
> import com.hp.hpl.jena.ontology.OntModelSpec;
> import com.hp.hpl.jena.ontology.OntTools.Path;
> import com.hp.hpl.jena.ontology.OntTools.PredicatesFilter;
> import com.hp.hpl.jena.rdf.model.*;
> import com.hp.hpl.jena.rdf.model.Model;
> import com.hp.hpl.jena.rdf.model.ModelFactory;
> import com.hp.hpl.jena.rdf.model.RDFNode;
> import com.hp.hpl.jena.rdf.model.Resource;
> import com.hp.hpl.jena.rdf.model.Statement;
> import com.hp.hpl.jena.util.iterator.Filter;
> import com.hp.hpl.jena.vocabulary.OWL;
>
> public class GeraSequenciaBean {
>     /*
>      * A Sequencia é definida aqui como o conjunto de de conceitos
>      * retirados da ontologia, a partir o inicial e do final.
>      *
>      */
>
>     String filename;
>
>     OntModel m = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
>     m.read(filename);
>
>
>     final Filter<Statement> ANY = Filter.any();
>
>
>     public Path SequenciaBean( Model m, Resource start, RDFNode end,
> Filter<Statement> onPath ) {
>         List<Path> bfs = new LinkedList<Path>();
>         Set<Resource> seen = new HashSet<Resource>();
>
>         // initialize the paths
>         for (Iterator<Statement> i = m.listStatements( start, null,
> (RDFNode) null ).filterKeep( onPath ); i.hasNext(); ) {
>             bfs.add( new Path().append( i.next() ) );
>         }
>
>         // search
>         Path solution = null;
>         while (solution == null && !bfs.isEmpty()) {
>             Path candidate = bfs.remove( 0 );
>
>             if (candidate.hasTerminus( end ) ) {
>                 solution = candidate;
>                 System.out.println("Solucao :"+ solution); //never
> printed...
>             }
>             else {
>                 Resource terminus = candidate.getTerminalResource();
>                 if (terminus != null) {
>                     seen.add( terminus );
>
>                     // breadth-first expansion
>                     for (Iterator<Statement> i =
> terminus.listProperties().filterKeep( onPath ); i.hasNext(); ) {
>                         Statement link = i.next();
>
>                         // no looping allowed, so we skip this link if it
> takes us to a node we've seen
>                         if (!seen.contains( link.getObject() )) {
>                             bfs.add( candidate.append( link ) );
>                             //System.out.println("Passou aqui!");
>                            // System.out.println("Caminho canditato :" +
> candidate);
>                         }
>                     }
>                 }
>             }
>         }
>
>         return solution;
>     }
> }
> ++++++++++++++++++
>
>
>
> java.lang.reflect.InvocationTargetException
>     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native
> Method)
>     at
> sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
>     at
> sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
>     at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
>     at
> org.eclipse.ve.internal.java.vce.launcher.remotevm.JavaBeansLauncher.main(JavaBeansLauncher.java:86)
> Caused by: java.lang.Error: Unresolved compilation problems:
>     Syntax error on token(s), misplaced construct(s)
>     Syntax error on token "filename", VariableDeclaratorId expected after
> this token
>
>     at composicao.model.GeraSequenciaBean.<init>(GeraSequenciaBean.java:34)
>     ... 5 more
> IWAV0048I Java Bean composicao.model.GeraSequenciaBean started with null
> constructor
> IWAV0052E Invocation Target Exception creating
> composicao.model.GeraSequenciaBean
>
> --
> Herli Menezes
> *Per Astra ad aspera.*
>
>
>


-- 
Herli Menezes
*Per Astra ad aspera.*

Reply via email to