|
From: Elmer G. <ega...@us...> - 2004-08-21 00:23:13
|
Update of /cvsroot/javaowl/JavaOWL/src/org/javaowl/editor In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6871/src/org/javaowl/editor Modified Files: ResourceEditorBean.java ModelEditor.java ModelEditorBean.java Log Message: Moe work on refactoring Index: ModelEditorBean.java =================================================================== RCS file: /cvsroot/javaowl/JavaOWL/src/org/javaowl/editor/ModelEditorBean.java,v retrieving revision 1.14 retrieving revision 1.15 diff -C2 -d -r1.14 -r1.15 *** ModelEditorBean.java 20 Aug 2004 18:16:43 -0000 1.14 --- ModelEditorBean.java 21 Aug 2004 00:22:49 -0000 1.15 *************** *** 47,51 **** import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.vocabulary.RDF; - import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.XSD; --- 47,50 ---- *************** *** 139,145 **** } ! public OntProperty[] getApplicableProperties(Resource resource) { Set props = new HashSet(); ! InstanceClassification ic = getInstanceClassification(resource); for (Iterator iter = ic.possibleIterator(); iter.hasNext(); ) { String uri = (String) iter.next(); --- 138,144 ---- } ! public OntProperty[] getApplicableProperties(ResourceEditorBean resource) { Set props = new HashSet(); ! InstanceClassification ic = getInstanceClassification(resource.resource); for (Iterator iter = ic.possibleIterator(); iter.hasNext(); ) { String uri = (String) iter.next(); *************** *** 158,164 **** } ! public Statement[] getDeclaredProperties(Resource resource) { List resources = new ArrayList(); ! for (Iterator it = resource.listProperties(); it.hasNext();) { Statement stmt = (Statement) it.next(); if (stmt.getPredicate().getNameSpace().equals(prefix)) --- 157,163 ---- } ! public Statement[] getDeclaredProperties(ResourceEditorBean resource) { List resources = new ArrayList(); ! for (Iterator it = resource.resource.listProperties(); it.hasNext();) { Statement stmt = (Statement) it.next(); if (stmt.getPredicate().getNameSpace().equals(prefix)) *************** *** 168,172 **** } ! public OntProperty[] getProperties(Resource clazz, boolean all) { Set props = getPropertiesURIs(clazz, all); OntProperty[] result = new OntProperty[props.size()]; --- 167,171 ---- } ! public OntProperty[] getProperties(OntClass clazz, boolean all) { Set props = getPropertiesURIs(clazz, all); OntProperty[] result = new OntProperty[props.size()]; *************** *** 187,191 **** } ! public Resource[] getInstances(Resource clazz, boolean all) { List resources = new ArrayList(); if (all) { --- 186,190 ---- } ! public ResourceEditorBean[] getInstances(OntClass clazz, boolean all) { List resources = new ArrayList(); if (all) { *************** *** 203,213 **** Resource resource = it.nextResource(); if (reasoner.isType(resource, clazz)) ! resources.add(resource); } } else { for (Iterator it = data.listSubjectsWithProperty(RDF.type, clazz); it.hasNext();) ! resources.add(it.next()); } ! return (Resource[]) resources.toArray(new Resource[0]); } --- 202,212 ---- Resource resource = it.nextResource(); if (reasoner.isType(resource, clazz)) ! resources.add(new ResourceEditorBean(resource, this)); } } else { for (Iterator it = data.listSubjectsWithProperty(RDF.type, clazz); it.hasNext();) ! resources.add(new ResourceEditorBean((Resource) it.next(), this)); } ! return (ResourceEditorBean[]) resources.toArray(new ResourceEditorBean[0]); } *************** *** 221,235 **** } ! public Statement addObjectValue(Resource resource, Property property, Resource value) { ! resource.addProperty(property, value); ! return resource.getProperty(property); // TODO: This is a BUG! } ! public Statement addDataValue(Resource resource, Property property, Literal value) { ! resource.addProperty(property, value); ! return resource.getProperty(property); // TODO: This is a BUG! } ! public InstanceClassification getInstanceClassification(Resource instance) { EditorReasoner reasoner = new EditorReasoner(); Model model = ModelFactory.createDefaultModel(); --- 220,238 ---- } ! public Statement addObjectValue(ResourceEditorBean resource, Property property, Resource value) { ! resource.resource.addProperty(property, value); ! return resource.resource.getProperty(property); // TODO: This is a BUG! } ! public Statement addDataValue(ResourceEditorBean resource, Property property, Literal value) { ! resource.resource.addProperty(property, value); ! return resource.resource.getProperty(property); // TODO: This is a BUG! ! } ! ! public void addPropertyValue(ResourceEditorBean resource, Property property, String value) { ! resource.resource.addProperty(property, value); } ! private InstanceClassification getInstanceClassification(Resource instance) { EditorReasoner reasoner = new EditorReasoner(); Model model = ModelFactory.createDefaultModel(); *************** *** 276,289 **** //TODO: remove where resource is object ! public void removeResource(Resource resource) { List stmts = new ArrayList(); ! for(Iterator it = resource.listProperties(); it.hasNext(); ) stmts.add(it.next()); data.remove(stmts); } ! public OntClass[] getSubClasses(OntClass resourceClass) { List classes = new ArrayList(); ! Vector v = ontologyReasoner.getSubClasses(resourceClass, false); for (Iterator iter = v.iterator(); iter.hasNext(); ) { String uri = iter.next().toString(); --- 279,292 ---- //TODO: remove where resource is object ! public void removeResource(ResourceEditorBean resource) { List stmts = new ArrayList(); ! for(Iterator it = resource.resource.listProperties(); it.hasNext(); ) stmts.add(it.next()); data.remove(stmts); } ! public OntClass[] getSubClasses(OntClass clazz) { List classes = new ArrayList(); ! Vector v = ontologyReasoner.getSubClasses(clazz, false); for (Iterator iter = v.iterator(); iter.hasNext(); ) { String uri = iter.next().toString(); *************** *** 294,334 **** } ! public Resource createResource(Resource classResource) { Resource r = data.createResource(); ! r.addProperty(RDF.type, classResource); ! return r; } ! public Resource createResource(String uri, Resource classResource) { ! Resource r = data.createResource(uri); ! r.addProperty(RDF.type, classResource); ! return r; } ! ! public String getLabel(Resource resource) { ! Statement s = resource.getProperty(RDFS.label); ! return s == null ? "" : s.getString(); } - public void setLabel(Resource resource, String label) { - if (testEmpty(label)) - return; - resource.addProperty(RDFS.label, label); - } - public String getComment(Resource resource) { - Statement s = resource.getProperty(RDFS.comment); - return s == null ? "" : s.getString(); - } ! public void setComment(Resource resource, String comment) { ! if (testEmpty(comment)) ! return; ! resource.addProperty(RDFS.comment, comment); } ! ! private boolean testEmpty(String test) { ! return test == null || test.length() == 0; } --- 297,330 ---- } ! public ResourceEditorBean createResourceEditor(OntClass clazz) { Resource r = data.createResource(); ! r.addProperty(RDF.type, clazz); ! return new ResourceEditorBean(r, this); } ! public static ResourceEditorBean getResourceEditor(Resource r, ModelEditor editor) { ! return new ResourceEditorBean(r, editor); } ! public ResourceEditorBean createResourceEditor(String uri, OntClass clazz) { ! Resource r = data.createResource(uri); ! r.addProperty(RDF.type, clazz); ! return new ResourceEditorBean(r, this); } ! public String getPropertyValue(ResourceEditorBean resource, Property p, boolean showUri) { ! Statement s = resource.resource.getProperty(p); ! if (s != null) ! return s.getString(); ! return showUri ? resource.toString() : null; } ! ! public String getPropertyValue(OntClass clazz, Property p, boolean showUri) { ! Statement s = clazz.getProperty(p); ! if (s != null) ! return s.getString(); ! return showUri ? clazz.toString() : null; } Index: ModelEditor.java =================================================================== RCS file: /cvsroot/javaowl/JavaOWL/src/org/javaowl/editor/ModelEditor.java,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** ModelEditor.java 20 Aug 2004 18:16:43 -0000 1.27 --- ModelEditor.java 21 Aug 2004 00:22:49 -0000 1.28 *************** *** 32,42 **** public interface ModelEditor { ! public Statement addDataValue(Resource resource, Property currentProperty, Literal typedLiteral); ! public Statement addObjectValue(Resource resource, Property currentProperty, Resource value); ! public Resource createResource(Resource classResource); ! public Resource createResource(String uri, Resource classResource); public OntClass[] getAllClasses(); --- 32,44 ---- public interface ModelEditor { ! public Statement addDataValue(ResourceEditorBean resource, Property currentProperty, Literal typedLiteral); ! public Statement addObjectValue(ResourceEditorBean resource, Property currentProperty, Resource value); ! ! public void addPropertyValue(ResourceEditorBean bean, Property label, String value); ! public ResourceEditorBean createResourceEditor(OntClass clazz); ! public ResourceEditorBean createResourceEditor(String uri, OntClass clazz); public OntClass[] getAllClasses(); *************** *** 44,56 **** public OntProperty[] getAllDatatypeProperties(); ! public OntProperty[] getApplicableProperties(Resource resource); ! ! public String getComment(Resource resource); ! ! public Statement[] getDeclaredProperties(Resource resource); ! public Resource[] getInstances(Resource clazz, boolean all); ! public String getLabel(Resource resource); public OntClass getOntClass(Resource resource); --- 46,54 ---- public OntProperty[] getAllDatatypeProperties(); ! public OntProperty[] getApplicableProperties(ResourceEditorBean resource); ! public Statement[] getDeclaredProperties(ResourceEditorBean resource); ! public ResourceEditorBean[] getInstances(OntClass clazz, boolean all); public OntClass getOntClass(Resource resource); *************** *** 58,64 **** public OntProperty getOntProperty(Property property); ! public OntProperty[] getProperties(Resource clazz, boolean all); ! public OntClass[] getSubClasses(OntClass resourceClass); public Literal getTypedLiteral(Object value, OntResource type); --- 56,66 ---- public OntProperty getOntProperty(Property property); ! public OntProperty[] getProperties(OntClass clazz, boolean all); ! ! public String getPropertyValue(OntClass clazz, Property label, boolean b); ! ! public String getPropertyValue(ResourceEditorBean bean, Property p, boolean uri); ! public OntClass[] getSubClasses(OntClass clazz); public Literal getTypedLiteral(Object value, OntResource type); *************** *** 66,77 **** public OntClass getValidLeafClass(Property currentProperty); ! public Individual[] getValidObjects(OntClass ontClass); ! public void removeResource(Resource resource); public void removeStatement(Statement statement); - - public void setComment(Resource resource, String comment); - - public void setLabel(Resource resource, String label); } --- 68,75 ---- public OntClass getValidLeafClass(Property currentProperty); ! public Individual[] getValidObjects(OntClass clazz); ! public void removeResource(ResourceEditorBean resource); public void removeStatement(Statement statement); } Index: ResourceEditorBean.java =================================================================== RCS file: /cvsroot/javaowl/JavaOWL/src/org/javaowl/editor/ResourceEditorBean.java,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** ResourceEditorBean.java 19 Aug 2004 21:27:54 -0000 1.9 --- ResourceEditorBean.java 21 Aug 2004 00:22:49 -0000 1.10 *************** *** 20,40 **** package org.javaowl.editor; - import com.hp.hpl.jena.ontology.OntModel; - import com.hp.hpl.jena.ontology.OntProperty; import com.hp.hpl.jena.rdf.model.Resource; ! public class ResourceEditorBean { ! public ResourceEditorBean(Resource resource, String prefix, OntModel ontModel) { ! /*InstanceClassification ic = getInstanceClassification(resource); ! for (Iterator it = ic.possibleIterator(); it.hasNext(); ) { ! String uri = (String) it.next(); ! System.out.print(ic.isDeclaredClass(uri) ? "D" : "-"); ! System.out.print(ic.isInferredClass(uri) ? "I" : "-"); ! System.out.println(" " + uri); ! }*/ } ! public boolean isRequiredProperty(OntProperty property) { return false; } --- 20,77 ---- package org.javaowl.editor; import com.hp.hpl.jena.rdf.model.Resource; + import com.hp.hpl.jena.vocabulary.RDFS; ! public final class ResourceEditorBean { ! final Resource resource; ! private final ModelEditor editor; ! ! ResourceEditorBean(Resource resource, ModelEditor editor) { ! this.resource = resource; ! this.editor = editor; } ! public String getURI() { ! return resource.getURI(); ! } ! ! public String getLabel(boolean uri) { ! String s = editor.getPropertyValue(this, RDFS.label, uri); ! return s == null ? "" : s; ! } ! ! public void setLabel(String label) { ! if (testEmpty(label)) ! return; ! editor.addPropertyValue(this, RDFS.label, label); ! } ! ! public String getComment(boolean uri) { ! String s = editor.getPropertyValue(this, RDFS.label, uri); ! return s == null ? "" : s; ! } ! ! public void setComment(String comment) { ! if (testEmpty(comment)) ! return; ! editor.addPropertyValue(this, RDFS.comment, comment); ! } ! ! ! private boolean testEmpty(String test) { ! return test == null || test.length() == 0; ! } ! /*InstanceClassification ic = getInstanceClassification(resource); ! for (Iterator it = ic.possibleIterator(); it.hasNext(); ) { ! String uri = (String) it.next(); ! System.out.print(ic.isDeclaredClass(uri) ? "D" : "-"); ! System.out.print(ic.isInferredClass(uri) ? "I" : "-"); ! System.out.println(" " + uri); ! }*/ ! ! ! ! /*public boolean isRequiredProperty(OntProperty property) { return false; } *************** *** 42,46 **** public boolean isValidDataValue(OntProperty property, String value) { return false; ! } } --- 79,83 ---- public boolean isValidDataValue(OntProperty property, String value) { return false; ! }*/ } |