1 31 32 package com.hp.hpl.jena.rdf.model.impl; 33 34 import com.hp.hpl.jena.rdf.model.*; 35 import com.hp.hpl.jena.vocabulary.RDF; 36 import com.hp.hpl.jena.graph.*; 37 import com.hp.hpl.jena.enhanced.*; 38 import com.hp.hpl.jena.shared.*; 39 40 import org.apache.commons.logging.Log; 41 import org.apache.commons.logging.LogFactory; 42 43 48 49 public class PropertyImpl extends ResourceImpl implements Property { 50 51 final static public Implementation factory = new Implementation() { 52 public boolean canWrap( Node n, EnhGraph eg ) 53 { return n.isURI(); } 54 public EnhNode wrap(Node n,EnhGraph eg) { 55 return new PropertyImpl(n,eg); 56 } 57 }; 58 protected static Log logger = LogFactory.getLog( PropertyImpl.class ); 59 60 protected int ordinal = 0; 61 62 63 public PropertyImpl(String uri) { 64 super( uri ); 65 checkLocalName(); 66 checkOrdinal(); 67 } 68 69 public RDFNode inModel( Model m ) 70 { return getModel() == m ? this : m.createProperty( getURI() ); } 71 72 private void checkLocalName() 73 { 74 String localName = getLocalName(); 75 if (localName == null || localName.equals( "" )) 76 throw new InvalidPropertyURIException( getURI() ); 77 } 78 79 public PropertyImpl(String nameSpace, String localName) 80 { 81 super(nameSpace, localName); 82 checkLocalName(); 83 checkOrdinal(); 84 } 85 86 public PropertyImpl(String uri, ModelCom m) { 87 super(uri, m); 88 checkOrdinal(); 89 } 90 91 public PropertyImpl(String nameSpace, String localName, ModelCom m) 92 { 93 super(nameSpace, localName, m); 94 checkOrdinal(); 95 } 96 97 public PropertyImpl(Node n, EnhGraph m) 98 { 99 super(n, m); 100 checkOrdinal(); 101 } 102 103 public PropertyImpl(String nameSpace, 104 String localName, 105 int ordinal, 106 ModelCom m) { 107 super(nameSpace, localName, m); 108 checkLocalName(); 109 this.ordinal = ordinal; 110 } 111 112 public boolean isProperty() { 113 return true; 114 } 115 116 public int getOrdinal() { 117 return ordinal; 118 } 119 120 protected void checkOrdinal() 121 { 122 char c; 123 String nameSpace = getNameSpace(); 124 String localName = getLocalName(); 125 if (localName.length() > 0) 127 { 128 if (localName.charAt(0) == '_' && nameSpace.equals(RDF.getURI()) 129 && nameSpace.equals(RDF.getURI()) 130 && localName.length() > 1 131 ) 132 { 133 for (int i=1; i<localName.length(); i++) { 134 c = localName.charAt(i); 135 if (c < '0' || c > '9') return; 136 } 137 try { 138 ordinal = Integer.parseInt(localName.substring(1)); 139 } catch (NumberFormatException e) { 140 logger.error( "checkOrdinal fails on " + localName, e ); 141 } 142 } 143 } 144 } 145 146 } 147 | Popular Tags |