Package com.clarkparsia.empire

Examples of com.clarkparsia.empire.SupportsRdfId


    }

    NamedGraph aAnnotation = theObj.getClass().getAnnotation(NamedGraph.class);

    if (aAnnotation.type() == NamedGraph.NamedGraphType.Instance) {
      SupportsRdfId aId = asSupportsRdfId(theObj);

      try {
        return asURI(aId);
      }
      catch (URISyntaxException e) {
View Full Code Here


  }
 
  @SuppressWarnings("unchecked")
    private static <T> Class<T> determineClass(Class<T> theOrigClass, T theObj, DataSource theSource) throws InvalidRdfException, DataSourceException {
    Class aResult = theOrigClass;
    final SupportsRdfId aTmpSupportsRdfId = asSupportsRdfId(theObj);
  
//    ExtGraph aGraph = new ExtGraph(DataSourceUtil.describe(theSource, theObj));
    final Collection<Value> aTypes = DataSourceUtil.getValues(theSource, EmpireUtil.asResource(EmpireUtil.asSupportsRdfId(theObj)), RDF.TYPE);
   
    // right now, our best match is the original class (we will refine later)
View Full Code Here

   * @throws InvalidRdfException thrown if the object does not support the RDF JPA API.
   * @throws DataSourceException thrown if there is an error retrieving data from the database
   */
  @SuppressWarnings("unchecked")
  private synchronized static <T> T fromRdf(T theObj, DataSource theSource) throws InvalidRdfException, DataSourceException {
    final SupportsRdfId aTmpSupportsRdfId = asSupportsRdfId(theObj);
    final SupportsRdfId.RdfKey theKeyObj = aTmpSupportsRdfId.getRdfId();

    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Converting {} to RDF.", theObj);
    }
   
    if (OBJECT_M.containsKey(theKeyObj)) {
      // TODO: this is probably a safe cast, i dont see how something w/ the same URI, which should be the same
      // object would change types
      return (T) OBJECT_M.get(theKeyObj);
    }

    try {

      OBJECT_M.put(theKeyObj, theObj);

      Graph aGraph = DataSourceUtil.describe(theSource, theObj);

      if (aGraph.size() == 0) {
        return theObj;
      }

      final Resource aTmpRes = EmpireUtil.asResource(aTmpSupportsRdfId);
      Set<URI> aProps = new HashSet<URI>();
     
      Iterator<Statement> sIter = aGraph.match(aTmpRes, null, null);

      while (sIter.hasNext()) {
        Statement aStmt = sIter.next();
        aProps.add(aStmt.getPredicate());
      }
     
     
      final SupportsRdfId aSupportsRdfId = asSupportsRdfId(theObj);
     
      final EmpireGenerated aEmpireGenerated = asEmpireGenerated(theObj);
     
      aEmpireGenerated.setAllTriples(aGraph);   
     
View Full Code Here

   * @return the object's rdf:Id
   * @throws InvalidRdfException thrown if the object does not support the minimum to create or retrieve an rdf:ID
   * @see SupportsRdfId
   */
  public static Resource id(Object theObj) throws InvalidRdfException {
    SupportsRdfId aSupport = asSupportsRdfId(theObj);

    if (aSupport.getRdfId() != null) {
      return EmpireUtil.asResource(aSupport);
    }

    Field aIdField = BeanReflectUtil.getIdField(theObj.getClass());

    String aValue = hash(Strings2.getRandomString(10));
    String aNS = RdfId.DEFAULT;

    URI aURI = FACTORY.createURI(aNS + aValue);

    if (aIdField != null && !aIdField.getAnnotation(RdfId.class).namespace().equals("")) {
      aNS = aIdField.getAnnotation(RdfId.class).namespace();
    }

    if (aIdField != null) {
      boolean aOldAccess = aIdField.isAccessible();
      aIdField.setAccessible(true);

      try {
        if (aIdField.get(theObj) == null) {
          throw new InvalidRdfException("id field must have a value");
        }

        Object aValObj = aIdField.get(theObj);

        aValue = Strings2.urlEncode(aValObj.toString());

        if (aValObj instanceof java.net.URI || NetUtils.isURI(aValObj.toString())) {
          try {
            aURI = FACTORY.createURI(aValObj.toString());
          }
          catch (IllegalArgumentException e) {
            // sometimes sesame disagrees w/ Java about what a valid URI is.  so we'll have to try
            // and construct a URI from the possible fragment
            aURI = FACTORY.createURI(aNS + aValue);
          }
        }
        else {
          //aValue = hash(aValObj);
          aURI = FACTORY.createURI(aNS + aValue);
        }
      }
      catch (IllegalAccessException ex) {
        throw new InvalidRdfException(ex);
      }

      aIdField.setAccessible(aOldAccess);
    }

    aSupport.setRdfId(new SupportsRdfId.URIKey(java.net.URI.create(aURI.toString())));

    return aURI;
  }
View Full Code Here

TOP

Related Classes of com.clarkparsia.empire.SupportsRdfId

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.