Ejemplo n.º 1
0
  /**
   * This <code>register</code> method is used to register a label based on its name and path.
   * Registration like this is done to ensure that the label can be resolved based on a parameter
   * name or path.
   *
   * <p>Registration here ensures a parameter can be resolved on both name and path. However,
   * because we want these mappings to be unique we do not allow multiple names to be mapped to the
   * same label. For example, say we have 'x/@a' and 'y/@a', these both have the same name 'a' even
   * though the point/put( to different things. Here we would not allow a mapping from 'a' and keep
   * only mappings based on the full path. This means that any parameters specified must declare the
   * full path also.
   *
   * @param label this is the label that is to be registered
   * @param map this is the map that the label is registered with
   */
  private void register(Label label, LabelMap map) throws Exception {
    String name = label.getName();
    String path = label.getPath();

    if (map.containsKey(name)) {
      Label current = map.get(name);
      String key = current.getPath();

      if (!key.equals(name)) {
        map.remove(name);
      }
    } else {
      map.put(name, label);
    }
    map.put(path, label);
  }
 /**
  * Constructor for the <code>CacheLabel</code> object. This is used to create a <code>Label</code>
  * that acquires details from another label in such a way that any logic involved in acquiring
  * details is performed only once.
  *
  * @param label this is the label to acquire the details from
  */
 public CacheLabel(Label label) throws Exception {
   this.annotation = label.getAnnotation();
   this.decorator = label.getDecorator();
   this.attribute = label.isAttribute();
   this.collection = label.isCollection();
   this.contact = label.getContact();
   this.depend = label.getDependent();
   this.required = label.isRequired();
   this.override = label.getOverride();
   this.inline = label.isInline();
   this.path = label.getPath();
   this.type = label.getType();
   this.name = label.getName();
   this.entry = label.getEntry();
   this.data = label.isData();
   this.label = label;
 }
Ejemplo n.º 3
0
  public static void main(String[] args) throws IOException {
    // Build a new authorized API client service.
    Gmail service = getGmailService();

    // Print the labels in the user's account.
    String user = "******";
    ListLabelsResponse listResponse = service.users().labels().list(user).execute();
    List<Label> labels = listResponse.getLabels();
    if (labels.size() == 0) {
      System.out.println("No labels found.");
    } else {
      System.out.println("Labels:");
      for (Label label : labels) {
        System.out.printf("- %s\n", label.getName());
      }
    }
  }
Ejemplo n.º 4
0
  /**
   * This is used to validate the names associated with the parameters. Validation is performed by
   * checking that the parameter name is present in the list of names the label is known by. This is
   * used to ensure that the if the label is a union the parameter is one of the names declared
   * within the union.
   *
   * @param label this is the label to validate the parameter against
   * @param parameter this is the parameter that is to be validated
   */
  private void validateNames(Label label, Parameter parameter) throws Exception {
    String[] options = label.getNames();
    String name = parameter.getName();

    if (!contains(options, name)) {
      String require = label.getName();

      if (name != require) {
        if (name == null || require == null) {
          throw new ConstructorException(
              "Annotation does not match %s for '%s' in %s", label, name, parameter);
        }
        if (!name.equals(require)) {
          throw new ConstructorException(
              "Annotation does not match %s for '%s' in %s", label, name, parameter);
        }
      }
    }
  }
Ejemplo n.º 5
0
    @Override
    public String getWhy() {
      Hudson hudson = Hudson.getInstance();
      if (hudson.isQuietingDown()) return Messages.Queue_HudsonIsAboutToShutDown();

      Label label = task.getAssignedLabel();
      if (hudson.getNodes().isEmpty())
        label = null; // no master/slave. pointless to talk about nodes

      String name = null;
      if (label != null) {
        name = label.getName();
        if (label.isOffline()) {
          if (label.getNodes().size() > 1) return Messages.Queue_AllNodesOffline(name);
          else return Messages.Queue_NodeOffline(name);
        }
      }

      if (name == null) return Messages.Queue_WaitingForNextAvailableExecutor();
      else return Messages.Queue_WaitingForNextAvailableExecutorOn(name);
    }