Exemplo n.º 1
0
  /**
   * Generates views based on annotations found in a repository class. If the repository class
   * extends org.ektorp.support.CouchDbRepositorySupport its handled type will also examined for
   * annotations eligible for view generation.
   *
   * @param repository
   * @return a Map with generated views.
   */
  public Map<String, DesignDocument.View> generateViews(final Object repository) {
    final Map<String, DesignDocument.View> views = new HashMap<String, DesignDocument.View>();
    final Class<?> repositoryClass = repository.getClass();

    final Class<?> handledType =
        repository instanceof CouchDbRepositorySupport<?>
            ? ((CouchDbRepositorySupport<?>) repository).getHandledType()
            : null;

    createDeclaredViews(views, repositoryClass);

    eachMethod(
        repositoryClass,
        new Predicate<Method>() {
          public boolean apply(Method input) {
            if (hasAnnotation(input, GenerateView.class)) {
              generateView(views, input, handledType);
            }
            return false;
          }
        });

    if (handledType != null) {
      views.putAll(generateViewsFromPersistentType(handledType));
    }
    return views;
  }
Exemplo n.º 2
0
  /** @return matching bloc B bloc -> A bloc */
  public static Map<Integer, Integer> diff(FileDesc a, FileDesc b) {
    Map<Integer, List<IndexedHash>> blocA = new HashMap<Integer, List<IndexedHash>>();
    int i = 0;
    for (Bloc bloc : a.blocs) {
      List<IndexedHash> l = blocA.get(bloc.roll);
      if (l == null) {
        l = new ArrayList<IndexedHash>();
        blocA.put(bloc.roll, l);
      }
      l.add(new IndexedHash(i++, bloc.hash));
    }

    Map<Integer, Integer> map = new HashMap<Integer, Integer>();
    loop:
    for (i = 0; i < b.blocs.length; i++) {
      Bloc blocB = b.blocs[i];
      List<IndexedHash> list = blocA.get(blocB.roll);
      if (list != null) {
        for (IndexedHash bloc : list) {
          if (blocB.hash.equals(bloc.h)) {
            map.put(i, bloc.i);
            continue loop;
          }
        }
      }
    }
    return map;
  }
Exemplo n.º 3
0
  private void generateView(
      Map<String, DesignDocument.View> views, Method me, Class<?> handledType) {
    String name = me.getName();
    if (!name.startsWith("findBy") && !name.equals("getAll")) {
      throw new ViewGenerationException(
          String.format(
              "The method: %s in %s annotated with GenerateView does not conform to the naming convention of 'findByXxxx'",
              name, me.getDeclaringClass()));
    }

    Class<?> type = resolveReturnType(me);
    if (type == null) {
      if (handledType != null) {
        type = handledType;
      } else {
        throw new ViewGenerationException(
            "Could not resolve return type for method: %s in %s",
            me.getName(), me.getDeclaringClass());
      }
    }

    String typeDiscriminator = resolveTypeDiscriminator(type);

    if (name.equals("getAll")) {
      if (typeDiscriminator.length() < 1) {
        throw new ViewGenerationException(
            String.format(
                "Cannot generate 'all' view for %s. No type discriminator could be resolved. Try annotate unique field(s) with @TypeDiscriminator",
                type.getDeclaringClass()));
      }
      views.put("all", generateAllView(typeDiscriminator));
      return;
    }

    String finderName = name.substring(6);
    String fieldName = resolveFieldName(me, finderName);
    Method getter = findMethod(type, "get" + fieldName);
    if (getter == null) {
      // try pluralis
      fieldName += "s";
      getter = findMethod(type, "get" + fieldName);
    }
    if (getter == null) {
      throw new ViewGenerationException(
          "Could not generate view for method %s. No get method found for property %s in %s",
          name, name.substring(6), type);
    }

    fieldName = firstCharToLowerCase(fieldName);

    DesignDocument.View view;
    if (isIterable(getter.getReturnType())) {
      view = generateFindByIterableView(fieldName, typeDiscriminator);
    } else {
      view = generateFindByView(fieldName, typeDiscriminator);
    }

    views.put("by_" + firstCharToLowerCase(finderName), view);
  }
Exemplo n.º 4
0
 private void addView(
     Map<String, DesignDocument.View> views, View input, Class<?> repositoryClass) {
   if (input.file().length() > 0) {
     views.put(input.name(), loadViewFromFile(views, input, repositoryClass));
   } else {
     views.put(input.name(), DesignDocument.View.of(input));
   }
 }
Exemplo n.º 5
0
  @Override
  public boolean loadLibrary(String libname, boolean ignoreError, ClassLoader cl) {
    try {
      for (Entry<String, String> nativeEntry : platformNativeIndex.entrySet()) {
        if (nativeEntry.getKey().contains(libname)) {
          if (log.isDebugEnabled()) {
            log.debug(
                "Loading mapped entry: [{}] [{}] [{}]",
                libname,
                nativeEntry.getKey(),
                nativeEntry.getValue());
          }
          File nativeLibCopy =
              extractJarEntry(
                  nativeEntry.getValue(),
                  nativeEntry.getKey(),
                  System.getProperty(JAVA_TMP_DIR),
                  String.format("%s.jni", libname));
          System.load(nativeLibCopy.getAbsolutePath());
          return true;
        }
      }
    } catch (Exception e) {
      log.error("Unable to load native library [{}] - {}", libname, e);
    }

    if (log.isDebugEnabled()) {
      log.debug("No mapped library match for [{}]", libname);
    }
    return false;
  }
Exemplo n.º 6
0
  public GLBootstrap() throws Exception {

    System.setProperty("jogamp.gluegen.UseTempJarCache", "false");

    log.info(
        "Initializing native JOGL jar dependencies for platform [{}]. Temp jar cache disabled.",
        PlatformPropsImpl.os_and_arch);

    String nativeJarName = String.format("%s-%s", NATIVES, PlatformPropsImpl.os_and_arch);
    String[] classpathEntries =
        System.getProperty(JAVA_CLASSPATH).split(System.getProperty(JAVA_SEPARATOR));

    for (String jarPath : classpathEntries) {

      if (jarPath.contains(nativeJarName)) {

        if (log.isDebugEnabled()) {
          log.debug("Applicable platform jar: [{}]", jarPath);
        }

        JarFile jf = new JarFile(jarPath);

        try {
          Enumeration<JarEntry> jarEntries = jf.entries();

          while (jarEntries.hasMoreElements()) {

            JarEntry je = jarEntries.nextElement();

            if (!je.isDirectory() && !je.getName().contains(JAVA_META_INF)) {
              if (log.isDebugEnabled()) {
                log.debug("Mapping jar entry [{}] -> [{}]", je.getName(), jarPath);
              }
              if (log.isDebugEnabled() && platformNativeIndex.containsKey(je.getName())) {
                log.debug("Duplicate jar entry: [{}]", je.getName());
                log.debug("Mapped at: [{}]", platformNativeIndex.get(je.getName()));
                log.debug("Also at: [{}]", jarPath);
              }
              platformNativeIndex.put(je.getName(), jarPath);
            }
          }
        } finally {
          closeJar(jf);
        }
      }
    }
  }
Exemplo n.º 7
0
  private void generateSetBasedDocRefView(
      Map<String, org.ektorp.support.DesignDocument.View> views,
      Member me,
      DocumentReferences referenceMetaData) {
    String fieldName = firstCharToLowerCase(me.getName());
    String orderBy = referenceMetaData.orderBy();
    String backRef = referenceMetaData.backReference();
    if (backRef.length() == 0) {
      throw new ViewGenerationException(
          String.format(
              "The DocumentReferences annotation in %s must specify a backReference",
              me.getDeclaringClass()));
    }
    String viewName = NameConventions.backReferenceViewName(fieldName);
    String typeDiscriminator = resolveTypeDiscriminatorForBackReference(me);
    if (orderBy.length() > 0) {

      views.put(
          viewName,
          generateDocRefsAsSetWithOrderByView(backRef, fieldName, orderBy, typeDiscriminator));
    } else {
      views.put(viewName, generateDocRefsAsSetView(backRef, fieldName, typeDiscriminator));
    }
  }
 @Override
 public void unpairDevice(String deviceId) {
   pairedDevices.remove(deviceId);
 }
 @Override
 public void pairDevice(String deviceId, String deviceName) {
   pairedDevices.put(deviceId, deviceName);
 }
 @Override
 public String getDeviceName(String deviceId) {
   return isReceptionFromAnyDevice() ? null : pairedDevices.get(deviceId);
 }
 @Override
 public boolean isAllowedDeviceId(String deviceId) {
   return isReceptionFromAnyDevice() || pairedDevices.containsKey(deviceId);
 }
 @Override
 public Collection<String> getPairedDeviceIds() {
   return pairedDevices.keySet();
 }