Exemplo n.º 1
0
  private void configureDescriptions(BusAttachment busAttachment, Class<?> busInterface)
      throws AnnotationBusException {
    BusInterface ifcNote = busInterface.getAnnotation(BusInterface.class);
    if (null == ifcNote) return;

    boolean hasDescriptions = false;

    if (!ifcNote.description().equals("")) {
      setDescription(ifcNote.description());
      hasDescriptions = true;
    }

    for (Method method : busInterface.getMethods()) {
      String name = getName(method);

      BusMethod methodNote = method.getAnnotation(BusMethod.class);
      if (null != methodNote && (methodNote.description().length() > 0)) {
        setMemberDescription(name, methodNote.description(), false);
        hasDescriptions = true;
      }

      BusSignal signalNote = method.getAnnotation(BusSignal.class);
      if (null != signalNote && (signalNote.description().length() > 0)) {
        setMemberDescription(name, signalNote.description(), signalNote.sessionless());
        hasDescriptions = true;
      }

      BusProperty propNote = method.getAnnotation(BusProperty.class);
      if (null != propNote && (propNote.description().length() > 0)) {
        setPropertyDescription(name, propNote.description());
        hasDescriptions = true;
      }
    }

    if (hasDescriptions) {
      setDescriptionLanguage(ifcNote.descriptionLanguage());
    }

    try {
      if (ifcNote.descriptionTranslator().length() > 0) {
        // We store these so as not to create a separate instance each time it is used.
        // Although this means we'll be holding on to each instance forever this is probably
        // not a problem since most Translators will need to live forever anyway
        Translator dt = translatorCache.get(ifcNote.descriptionTranslator());
        if (null == dt) {
          Class<?> c = Class.forName(ifcNote.descriptionTranslator());
          dt = (Translator) c.newInstance();
          translatorCache.put(ifcNote.descriptionTranslator(), dt);
        }
        setDescriptionTranslator(busAttachment, dt);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 2
0
 /**
  * Get the DBus property signature.
  *
  * @param method the method
  */
 public static String getPropertySig(Method method) throws AnnotationBusException {
   Type type = null;
   if (method.getName().startsWith("get")) {
     type = method.getGenericReturnType();
   } else if (method.getName().startsWith("set")) {
     type = method.getGenericParameterTypes()[0];
   }
   BusProperty busProperty = method.getAnnotation(BusProperty.class);
   if (busProperty != null && busProperty.signature().length() > 0) {
     return Signature.typeSig(type, busProperty.signature());
   }
   return Signature.typeSig(type, null);
 }
Exemplo n.º 3
0
 /**
  * Get the DBus member or property name.
  *
  * @param method The method.
  */
 public static String getName(Method method) {
   BusMethod busMethod = method.getAnnotation(BusMethod.class);
   if (busMethod != null && busMethod.name().length() > 0) {
     return busMethod.name();
   }
   BusSignal busSignal = method.getAnnotation(BusSignal.class);
   if (busSignal != null && busSignal.name().length() > 0) {
     return busSignal.name();
   }
   BusProperty busProperty = method.getAnnotation(BusProperty.class);
   if (busProperty != null) {
     if (busProperty.name().length() > 0) {
       return busProperty.name();
     } else {
       /* The rest of the method name following the "get" or "set" prefix. */
       return method.getName().substring(3);
     }
   }
   return method.getName();
 }