예제 #1
0
  private Status getProperties(Class<?> busInterface) throws AnnotationBusException {
    for (Method method : busInterface.getMethods()) {
      if (method.getAnnotation(BusProperty.class) != null) {
        String name = getName(method);
        Property property = properties.get(name);

        BusAnnotations propertyAnnotations = method.getAnnotation(BusAnnotations.class);
        TreeMap<String, String> annotations = new TreeMap<String, String>();
        if (propertyAnnotations != null) {
          for (BusAnnotation propertyAnnotation : propertyAnnotations.value()) {
            annotations.put(propertyAnnotation.name(), propertyAnnotation.value());
          }
        }

        if (property == null) {
          property = new Property(name, getPropertySig(method), annotations);
        } else if (!property.signature.equals(getPropertySig(method))) {
          return Status.BAD_ANNOTATION;
        }

        if (method.getName().startsWith("get")) {
          property.get = method;
        } else if (method.getName().startsWith("set")
            && (method.getGenericReturnType().equals(void.class))) {
          property.set = method;
        } else {
          return Status.BAD_ANNOTATION;
        }
        properties.put(name, property);
      }
    }
    return Status.OK;
  }
예제 #2
0
  /**
   * Create the native interface description for the busInterface.
   *
   * @param busAttachment the connection the interface is on
   * @param busInterface the interface
   */
  public Status create(BusAttachment busAttachment, Class<?> busInterface)
      throws AnnotationBusException {
    Status status = getProperties(busInterface);
    if (status != Status.OK) {
      return status;
    }
    status = getMembers(busInterface);
    if (status != Status.OK) {
      return status;
    }

    int securePolicy = AJ_IFC_SECURITY_INHERIT;
    Secure secureAnnotation = busInterface.getAnnotation(Secure.class);
    if (secureAnnotation != null) {
      if (secureAnnotation.value().equals("required")) {
        securePolicy = AJ_IFC_SECURITY_REQUIRED;
      } else if (secureAnnotation.value().equals("off")) {
        securePolicy = AJ_IFC_SECURITY_OFF;
      } else {
        /*
         * In C++ if an interface provides an unknown security annotation
         * it automatically defaults to the inherit for security. For
         * that reason the Java code will do the same.
         */
        securePolicy = AJ_IFC_SECURITY_INHERIT;
      }
    } else {
      securePolicy = AJ_IFC_SECURITY_INHERIT;
    }
    status =
        create(
            busAttachment, getName(busInterface), securePolicy, properties.size(), members.size());
    if (status != Status.OK) {
      return status;
    }
    status = addProperties(busInterface);
    if (status != Status.OK) {
      return status;
    }
    status = addMembers(busInterface);
    if (status != Status.OK) {
      return status;
    }

    // now we need to add the DBus annotations for the interface;
    // this must be done *before* calling create
    BusAnnotations busAnnotations = busInterface.getAnnotation(BusAnnotations.class);
    if (busAnnotations != null) {
      for (BusAnnotation annotation : busAnnotations.value()) {
        addAnnotation(annotation.name(), annotation.value());
      }
    }

    configureDescriptions(busAttachment, busInterface);

    activate();
    return Status.OK;
  }
예제 #3
0
  private Status addMembers(Class<?> busInterface) throws AnnotationBusException {
    for (Method member : members) {
      int type = INVALID;
      int annotation = 0;
      String accessPerm = null;
      BusMethod m = member.getAnnotation(BusMethod.class);
      BusSignal s = member.getAnnotation(BusSignal.class);
      AccessPermission ap = member.getAnnotation(AccessPermission.class);

      if (m != null) {
        type = METHOD_CALL;
        annotation = m.annotation();
      } else if (s != null) {
        type = SIGNAL;
        annotation = s.annotation();
      }
      if (type != INVALID) {
        if (ap != null) {
          accessPerm = ap.value();
        }

        String memberName = getName(member);
        Status status =
            addMember(
                type, memberName, getInputSig(member), getOutSig(member), annotation, accessPerm);
        if (status != Status.OK) {
          return status;
        }

        // pull out the DBus annotations
        BusAnnotations dbusAnnotations = member.getAnnotation(BusAnnotations.class);
        if (dbusAnnotations != null) {
          for (BusAnnotation busAnnotation : dbusAnnotations.value()) {
            addMemberAnnotation(memberName, busAnnotation.name(), busAnnotation.value());
          }
        }
      }
    }
    return Status.OK;
  }