Example #1
0
  public static String asKey(ModelNode address, boolean fq) {

    List<Property> tuples = address.asPropertyList();
    StringBuilder sb = new StringBuilder();

    int i = 0;
    for (final Property tuple : tuples) {
      if (i > 0) sb.append("/");

      sb.append(tuple.getName());
      sb.append("=");

      if (i == tuples.size() - 1)
        if (fq) sb.append(escapeValue(tuple.getValue().asString()));
        else sb.append("*");
      else sb.append(escapeValue(tuple.getValue().asString()));

      i++;
    }

    // if(tuples.isEmpty())
    //    sb.append("ROOT"); // better then empty string

    return sb.toString();
  }
Example #2
0
  public static ModelNode toFqAddress(ModelNode address, String resourceName) {
    ModelNode fqAddress = new ModelNode();
    List<Property> tuples = address.asPropertyList();
    for (Property tuple : tuples) {
      String key = tuple.getName();
      String value = tuple.getValue().asString();

      fqAddress.add(key, value.equals("*") ? resourceName : value);
    }

    return fqAddress;
  }
Example #3
0
  public static ModelNode fromFqAddress(ModelNode address) {
    ModelNode wildcardAddress = new ModelNode();
    List<Property> tuples = address.asPropertyList();
    int i = 0;
    for (Property tuple : tuples) {
      String key = tuple.getName();
      String value = tuple.getValue().asString();

      if (i == tuples.size() - 1) wildcardAddress.add(key, "*");
      else wildcardAddress.add(key, value);

      i++;
    }

    return wildcardAddress;
  }
Example #4
0
  public void setChildren(
      ModelNode address,
      List<ModelNode> modelNodes,
      ModelBrowserView.ChildInformation childInformation) {

    this.currentAddress = address;
    this.childInformation = childInformation;

    String denominatorType = AddressUtils.getDenominatorType(address.asPropertyList());
    boolean isSingleton =
        denominatorType != null ? childInformation.isSingleton(denominatorType) : false;

    String text = isSingleton ? "Singleton Child Resources" : "Child Resources";
    header.setHTML(
        "<h2 class='homepage-secondary-header'>" + text + " (" + modelNodes.size() + ")</h2>");
    dataProvider.setList(modelNodes);
  }
Example #5
0
  private void _showAddDialog(
      final ModelNode address,
      boolean isSingleton,
      SecurityContext securityContext,
      ModelNode description) {
    List<Property> tuples = address.asPropertyList();
    String type = "";
    if (tuples.size() > 0) {
      type = tuples.get(tuples.size() - 1).getName();
    }

    ModelNodeFormBuilder builder =
        new ModelNodeFormBuilder()
            .setCreateMode(true)
            .setSingleton(isSingleton)
            .setResourceDescription(description)
            .setSecurityContext(securityContext);

    ModelNodeFormBuilder.FormAssets assets = builder.build();

    final ModelNodeForm form = assets.getForm();
    form.setEnabled(true);

    if (form.hasWritableAttributes()) {
      final DefaultWindow window = new DefaultWindow(Console.MESSAGES.createResource(type));
      window.addStyleName("browser-view");

      DialogueOptions options =
          new DialogueOptions(
              new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                  // save
                  FormValidation validation = form.validate();
                  if (!validation.hasErrors()) {
                    presenter.onAddChildResource(address, form.getUpdatedEntity());
                    window.hide();
                  }
                }
              },
              new ClickHandler() {
                @Override
                public void onClick(ClickEvent event) {
                  // cancel
                  window.hide();
                }
              });

      VerticalPanel layout = new VerticalPanel();
      layout.setStyleName("fill-layout-width");
      ModelNode opDescription = description.get("operations").get("add").get("description");
      ContentDescription text = new ContentDescription(opDescription.asString());
      layout.add(text);
      layout.add(assets.asWidget());

      WindowContentBuilder content = new WindowContentBuilder(layout, options);
      window.trapWidget(content.build());
      window.setGlassEnabled(true);
      window.setWidth(480);
      window.setHeight(360);
      window.center();
    } else {
      // no writable attributes
      Feedback.alert(
          Console.CONSTANTS.cannotCreateChildResource(),
          Console.MESSAGES.noConfigurableAttributes(address.toString()));
    }
  }
Example #6
0
  public static Object downCast(ModelNode value, ModelNode metadata) {
    Object result = null;
    ModelType targetType = resolveTypeFromMetaData(metadata);
    switch (targetType) {
      case STRING:
        result = value.asString();
        break;
      case INT:
        result = value.asInt();
        break;
      case LONG:
        result = value.asLong();
        break;
      case BOOLEAN:
        result = value.asBoolean();
        break;
      case BIG_DECIMAL:
        result = value.asBigDecimal();
        break;
      case BIG_INTEGER:
        result = value.asBigInteger();
        break;
      case DOUBLE:
        result = value.asDouble();
        break;
      case LIST:
        {
          try {

            List<ModelNode> items = value.asList();
            List<String> list = new ArrayList<String>(items.size());
            for (ModelNode item : items) list.add(item.asString());
            result = list;

          } catch (Throwable t) {
            t.printStackTrace();
            result = new ArrayList<>(); // syntax errors
          }
          break;
        }
      case PROPERTY:
        { // it's actually interpreted as a property list, but that ttype doesn'ty really exist
          // (yet)
          try {

            List<Property> properties = value.asPropertyList();
            Map<String, String> map = new HashMap<>();
            for (Property item : properties) map.put(item.getName(), item.getValue().asString());
            result = map;

          } catch (Throwable t) {
            t.printStackTrace();
            result = new HashMap(); // syntax errors
          }
          break;
        }
      case UNDEFINED:
        break;
      default:
        throw new RuntimeException("Unexpected targetType " + targetType);
    }
    return result;
  }