Beispiel #1
0
 private Resource toResource(Object bean) {
   String uri = instanceURI(bean);
   Resource type = getRDFSClass(bean);
   if (jpa.isEmbedded(bean) || uri == null) return m.createResource(type);
   else {
     // added by saeed to differentiate between save and update
     Resource resource = m.createResource(uri);
     if (resource.getProperty(RDF.type) == null) {
       resource.addProperty(RDF.type, type);
     }
     return resource;
   }
 }
Beispiel #2
0
 /** Calls the release() method of all available tag handlers in this tag handler pool. */
 public synchronized void release() {
   for (int i = current; i >= 0; i--) {
     handlers[i].release();
     if (annotationProcessor != null) {
       try {
         AnnotationHelper.preDestroy(annotationProcessor, handlers[i]);
       } catch (Exception e) {
         log.warn(
             "Error processing preDestroy on tag instance of " + handlers[i].getClass().getName(),
             e);
       }
     }
   }
 }
  @Test
  public void testExtractValue() throws Exception {
    field = TestConfig.class.getDeclaredField("testField");

    PropertyValue propertyValue = field.getAnnotation(PropertyValue.class);
    CommandLineValue commandLineValue = field.getAnnotation(CommandLineValue.class);

    List<Annotation> orderList = Lists.newArrayList(propertyValue, commandLineValue);
    when(annotationHelper.getAnnotationsInOrder(
            Matchers.any(Field.class), Matchers.any(Class[].class)))
        .thenReturn(orderList);

    String result = (String) fieldValueExtractor.extractValue(field, builderConfiguration);
    verify(annotationHelper).getAnnotationsInOrder(field, order);
    assertEquals("propertyValue", result);
  }
Beispiel #4
0
 /**
  * Adds the given tag handler to this tag handler pool, unless this tag handler pool has already
  * reached its capacity, in which case the tag handler's release() method is called.
  *
  * @param handler Tag handler to add to this tag handler pool
  */
 public void reuse(Tag handler) {
   synchronized (this) {
     if (current < (handlers.length - 1)) {
       handlers[++current] = handler;
       return;
     }
   }
   // There is no need for other threads to wait for us to release
   handler.release();
   if (annotationProcessor != null) {
     try {
       AnnotationHelper.preDestroy(annotationProcessor, handler);
     } catch (Exception e) {
       log.warn(
           "Error processing preDestroy on tag instance of " + handler.getClass().getName(), e);
     }
   }
 }
Beispiel #5
0
  /**
   * Gets the next available tag handler from this tag handler pool, instantiating one if this tag
   * handler pool is empty.
   *
   * @param handlerClass Tag handler class
   * @return Reused or newly instantiated tag handler
   * @throws JspException if a tag handler cannot be instantiated
   */
  public Tag get(Class handlerClass) throws JspException {
    Tag handler = null;
    synchronized (this) {
      if (current >= 0) {
        handler = handlers[current--];
        return handler;
      }
    }

    // Out of sync block - there is no need for other threads to
    // wait for us to construct a tag for this thread.
    try {
      Tag instance = (Tag) handlerClass.newInstance();
      AnnotationHelper.postConstruct(annotationProcessor, instance);
      return instance;
    } catch (Exception e) {
      throw new JspException(e.getMessage(), e);
    }
  }
  @Test
  public void testExtractValueWithNullValue() throws Exception {
    field = TestConfig.class.getDeclaredField("testField");

    PropertyValue propertyValue = field.getAnnotation(PropertyValue.class);
    CommandLineValue commandLineValue = field.getAnnotation(CommandLineValue.class);
    List<Annotation> orderList = Lists.newArrayList(propertyValue, commandLineValue);
    when(annotationHelper.getAnnotationsInOrder(
            Matchers.any(Field.class), Matchers.any(Class[].class)))
        .thenReturn(orderList);

    when(propertyValueProcessor.getValue(
            Matchers.any(PropertyValue.class), Matchers.any(ConfigBuilderFactory.class)))
        .thenReturn(null);
    when(commandLineValueProcessor.getValue(
            Matchers.any(CommandLineValue.class), Matchers.any(ConfigBuilderFactory.class)))
        .thenReturn(null);

    Object result = fieldValueExtractor.extractValue(field, builderConfiguration);
    assertEquals(null, result);
  }
 /** Checks whether the Activity extends one of the ActionBarSherlock Activity types */
 public boolean usesActionBarSherlock(TypeElement typeElement) {
   TypeMirror superType;
   while (!((superType = typeElement.getSuperclass()) instanceof NoType)) {
     typeElement = (TypeElement) ((DeclaredType) superType).asElement();
     String qName = typeElement.getQualifiedName().toString();
     if (qName.startsWith("com.actionbarsherlock.app")) {
       return true;
     }
     if (qName.startsWith("org.holoeverywhere")) {
       // Since 2.0.0, HoloEverywhere no longer depends on ABS so we
       // had to find a way to to detect the version in classpath.
       // Since org.holoeverywhere.addon.AddonSherlock has been removed
       // during ABS to ABC migration, we're checking if this class is
       // in the classpath. If so, we're using HEW < 2.0
       // See issue #776
       return annotationHelper.typeElementFromQualifiedName(
               "org.holoeverywhere.addon.AddonSherlock")
           != null;
     }
   }
   return false;
 }
 /**
  * Attempts to get a key from <code>domainObject</code> by looking for a {@literal @RiakKey}
  * annotated member. If non-present it simply returns <code>null</code>
  *
  * @param <T> the type of <code>domainObject</code>
  * @param domainObject the object to search for a key
  * @return either the value found on <code>domainObject</code>;s {@literal @RiakKey} member or
  *     <code>null</code>
  */
 public static <T> BinaryValue getKey(T domainObject) {
   return AnnotationHelper.getInstance().getRiakKey(domainObject);
 }
 /**
  * Attempts to inject <code>key</code> as the value of the {@literal @RiakKey} annotated member of
  * <code>domainObject</code>
  *
  * @param <T> the type of <code>domainObject</code>
  * @param domainObject the object to inject the key into
  * @param key the key to inject
  * @return <code>domainObject</code> with {@literal @RiakKey} annotated member set to <code>key
  *     </code>
  * @throws ConversionException if there is a {@literal @RiakKey} annotated member but it cannot be
  *     set to the value of <code>key</code>
  */
 public static <T> T setKey(T domainObject, BinaryValue key) throws ConversionException {
   T obj = AnnotationHelper.getInstance().setRiakKey(domainObject, key);
   return obj;
 }
 public static <T> T setLastModified(T domainObject, Long lastModified) {
   return AnnotationHelper.getInstance().setRiakLastModified(domainObject, lastModified);
 }
 public static <T> T setVTag(T domainObject, String vtag) {
   return AnnotationHelper.getInstance().setRiakVTag(domainObject, vtag);
 }
 /**
  * Attempts to get a vector clock from <code>domainObject</code> by looking for a
  * {@literal @RiakVClock} annotated member. If non-present it simply returns <code>null</code>
  *
  * @param <T> the type of <code>domainObject</code>
  * @param domainObject the object to search for a key
  * @return either the value found on <code>domainObject</code>;s {@literal @RiakVClock} member or
  *     <code>null</code>
  */
 public static <T> VClock getVClock(T domainObject) {
   return AnnotationHelper.getInstance().getRiakVClock(domainObject);
 }
Beispiel #13
0
 public OJAnnotationValue findAnnotation(OJPathName path) {
   return AnnotationHelper.getAnnotation(this, path);
 }
 /**
  * Attempts to get the riak user metadata from a domain object by looking for a
  * {@literal @RiakUsermeta} annotated field or getter method.
  *
  * @param <T> the type of the domain object
  * @param metaContainer the RiakUserMetadata container
  * @param domainObject the domain object
  * @return a Map containing the user metadata.
  */
 public static <T> RiakUserMetadata getUsermetaData(
     RiakUserMetadata metaContainer, T domainObject) {
   return AnnotationHelper.getInstance().getUsermetaData(metaContainer, domainObject);
 }
 /**
  * Attempts to populate a domain object with riak links by looking for a {@literal @RiakLinks}
  * annotated member.
  *
  * @param <T> the type of the domain object
  * @param links a collection of RiakLink objects
  * @param domainObject the domain object
  * @return the domain object
  */
 public static <T> T populateLinks(RiakLinks links, T domainObject) {
   return AnnotationHelper.getInstance().setLinks(links, domainObject);
 }
 /**
  * Attempts to get the the Riak links from a domain object by looking for a {@literal @RiakLinks}
  * annotated member.
  *
  * @param <T> the domain object type
  * @param container the RiakLinks container
  * @param domainObject the domain object
  * @return a Collection of RiakLink objects.
  */
 public static <T> RiakLinks getLinks(RiakLinks container, T domainObject) {
   return AnnotationHelper.getInstance().getLinks(container, domainObject);
 }
 /**
  * Attempts to populate a domain object with the contents of the supplied RiakIndexes by looking
  * for a {@literal @RiakIndex} annotated member
  *
  * @param <T> the type of the domain object
  * @param indexes a populated RiakIndexes object.
  * @param domainObject the domain object
  * @return the domain object.
  */
 public static <T> T populateIndexes(RiakIndexes indexes, T domainObject) {
   return AnnotationHelper.getInstance().setIndexes(indexes, domainObject);
 }
 /**
  * Attempts to get boolean from <code>domainObject</code> by looking for a
  * {@literal @RiakTombstone} annotated member. If non-present it simply returns <code>null</code>
  *
  * @param <T> the type of <code>domainObject</code>
  * @param domainObject the object to search for a key
  * @return either the value found on <code>domainObject</code>'s {@literal @RiakTombstone} member
  *     or <code>null</code>
  */
 public static <T> Boolean getTombstone(T domainObject) {
   return AnnotationHelper.getInstance().getRiakTombstone(domainObject);
 }
 /**
  * Attempts to inject <code>isTombstone</code> as the value of the {@literal @RiakTombstone}
  * annotated member of <code>domainObject</code>
  *
  * @param <T> the type of <code>domainObject</code>
  * @param domainObject the object to inject the key into
  * @param isTombstone the boolean to inject
  * @return <code>domainObject</code> with {@literal @RiakTombstone} annotated member set to <code>
  *     isTombstone</code>
  * @throws ConversionException if there is a {@literal @RiakTombstone} annotated member but it
  *     cannot be set to the value of <code>isTombstone</code>
  */
 public static <T> T setTombstone(T domainObject, boolean isTombstone) throws ConversionException {
   T obj = AnnotationHelper.getInstance().setRiakTombstone(domainObject, isTombstone);
   return obj;
 }
 public static <T> BinaryValue getBucketName(T domainObject) {
   return AnnotationHelper.getInstance().getRiakBucketName(domainObject);
 }
 public static <T> T setBucketType(T domainObject, BinaryValue bucketType) {
   return AnnotationHelper.getInstance().setRiakBucketType(domainObject, bucketType);
 }
 /**
  * Attempts to populate a domain object with user metadata by looking for a
  * {@literal @RiakUsermeta} annotated member.
  *
  * @param <T> the type of the domain object
  * @param usermetaData a Map of user metadata.
  * @param domainObject the domain object.
  * @return the domain object.
  */
 public static <T> T populateUsermeta(RiakUserMetadata usermetaData, T domainObject) {
   return AnnotationHelper.getInstance().setUsermetaData(usermetaData, domainObject);
 }
 /** Checks whether the Activity extends one of the ActionBarSherlock Activity types */
 public boolean usesActionBarSherlock(EComponentHolder holder) {
   TypeElement typeElement =
       annotationHelper.typeElementFromQualifiedName(
           holder.getGeneratedClass()._extends().fullName());
   return usesActionBarSherlock(typeElement);
 }
 public static <T> boolean hasVClockAnnotation(T domainObject) {
   return AnnotationHelper.getInstance().hasRiakVClockAnnotation(domainObject);
 }
  @SuppressWarnings({"rawtypes", "unchecked"})
  private <T> T convert(
      MetaData md, String[] data, Class<T> type, T defaultValue, Annotation annotation) {
    Object out = data[md.index];

    if (out == null) {
      out = defaultValue == null ? md.defaultValue : defaultValue;
    }

    if (annotation == null) {
      initializeMetadataConversions(data, md);
      out = md.convert(out);

      if (out == null) {
        out = defaultValue == null ? md.defaultValue : defaultValue;
      }
    }

    if (type != null) {
      if (out != null && type.isAssignableFrom(out.getClass())) {
        return (T) out;
      }
      Conversion conversion;
      if (type != String.class) {
        if (annotation == null) {
          conversion = conversionByType.get(type);
          if (conversion == null) {
            conversion = AnnotationHelper.getDefaultConversion(type, null);
            conversionByType.put(type, conversion);
          }
        } else {
          Map<Annotation, Conversion> m = conversionsByAnnotation.get(type);
          if (m == null) {
            m = new HashMap<Annotation, Conversion>();
            conversionsByAnnotation.put(type, m);
          }
          conversion = m.get(annotation);
          if (conversion == null) {
            conversion = AnnotationHelper.getConversion(type, annotation);
            m.put(annotation, conversion);
          }
        }

        if (conversion == null) {
          String message = "";
          if (type == Date.class || type == Calendar.class) {
            message = ". Need to specify format for date";
          }
          DataProcessingException exception =
              new DataProcessingException(
                  "Cannot convert '{value}' to " + type.getName() + message);
          exception.setValue(out);
          exception.setErrorContentLength(context.errorContentLength());
          throw exception;
        }
        out = conversion.execute(out);
      }
    }
    if (type == null) {
      return (T) out;
    }
    try {
      return type.cast(out);
    } catch (ClassCastException e) {
      DataProcessingException exception =
          new DataProcessingException(
              "Cannot cast value '{value}' of type "
                  + out.getClass().toString()
                  + " to "
                  + type.getName());
      exception.setValue(out);
      exception.setErrorContentLength(context.errorContentLength());
      throw exception;
    }
  }
 /**
  * Attempts to inject <code>vclock</code> as the value of the {@literal @RiakVClock} annotated
  * member of <code>domainObject</code>
  *
  * @param <T> the type of <code>domainObject</code>
  * @param domainObject the object to inject the key into
  * @param vclock the vclock to inject
  * @return <code>domainObject</code> with {@literal @RiakVClock} annotated member set to <code>
  *     vclock</code>
  * @throws ConversionException if there is a {@literal @RiakVClock} annotated member but it cannot
  *     be set to the value of <code>vclock</code>
  */
 public static <T> T setVClock(T domainObject, VClock vclock) throws ConversionException {
   T obj = AnnotationHelper.getInstance().setRiakVClock(domainObject, vclock);
   return obj;
 }
 public static <T> String getContentType(T domainObject) {
   return AnnotationHelper.getInstance().getRiakContentType(domainObject);
 }
 public static <T> T setContentType(T domainObject, String contentType) {
   return AnnotationHelper.getInstance().setRiakContentType(domainObject, contentType);
 }