Package org.platformlayer

Examples of org.platformlayer.UntypedItemXml


  @Override
  public UntypedItem putItem(PlatformLayerKey key, String data, Format format) throws PlatformLayerClientException {
    MappedPlatformLayerKey mapped = mapToChildForPut(key);

    UntypedItemXml untypedItem = UntypedItemXml.build(data);
    untypedItem.setPlatformLayerKey(mapped.key);

    UntypedItem item = mapped.child.client.putItem(mapped.key, untypedItem.serialize(), format);

    return mapped.child.setHost(item);
  }
View Full Code Here


  @Override
  public UntypedItem putItemByTag(PlatformLayerKey key, Tag uniqueTag, String data, Format format)
      throws PlatformLayerClientException {
    MappedPlatformLayerKey mapped = mapToChildForPut(key);

    UntypedItemXml post = UntypedItemXml.build(data);
    post.setPlatformLayerKey(mapped.key);

    UntypedItem item = mapped.child.client.putItemByTag(mapped.key, uniqueTag, post.serialize(), format);
    return mapped.child.setHost(item);
  }
View Full Code Here

  public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();

    PlatformLayerKey resolved = path.resolve(getContext());

    UntypedItemXml item = (UntypedItemXml) client.getItemUntyped(resolved, Format.XML);

    Links links = item.getLinks();

    Link link = new Link();
    link.name = name;
    link.target = target.resolve(getContext());

    Link existing = links.findLink(name);
    List<Link> linkList = links.getLinks();
    if (existing != null) {
      linkList.remove(existing);
    }
    linkList.add(link);

    item.setLinks(links);

    String xml = item.serialize();

    UntypedItemXml updated = (UntypedItemXml) client.putItem(resolved, xml, Format.XML);

    return updated.getLinks().getLinks();
  }
View Full Code Here

  protected UntypedItemXml runCommand(ItemPath path) throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();

    PlatformLayerKey resolved = path.resolve(getContext());

    UntypedItemXml item = (UntypedItemXml) client.getItemUntyped(resolved, Format.XML);

    changeItem(item);

    String xml = item.serialize();

    UntypedItemXml updated = (UntypedItemXml) client.putItem(resolved, xml, Format.XML);

    return updated;
  }
View Full Code Here

  @Override
  public void formatRaw(Object o, PrintWriter writer) {

    String data;
    if (o instanceof UntypedItemXml) {
      UntypedItemXml item = (UntypedItemXml) o;

      Source src = new DOMSource(item.getRoot());
      String xml = DomUtils.toXml(src, 4);
      data = xml;
    } else if (o instanceof UntypedItemJson) {
      UntypedItemJson item = (UntypedItemJson) o;

      JSONObject root = item.getRoot();
      try {
        data = root.toString(2);
      } catch (JSONException e) {
        throw new IllegalStateException("Error formatting JSON", e);
      }
View Full Code Here

    super("add", "config");
  }

  @Override
  public Object runCommand() throws PlatformLayerClientException {
    UntypedItemXml item = runCommand(path);
    return item;
  }
View Full Code Here

    super();
    this.client = client;
  }

  public void visit(UntypedItem item) throws PlatformLayerClientException {
    UntypedItemXml untypedItem = (UntypedItemXml) item;

    ElementInfo rootElementInfo = untypedItem.getRootElementInfo();

    boolean consider = true;

    switch (untypedItem.getState()) {
    case DELETED:
    case DELETE_REQUESTED:
      consider = false;
      break;
    }

    Set<String> instanceTypes = Sets.newHashSet();
    instanceTypes.add("directInstance");
    instanceTypes.add("googleCloudInstance");

    if (!instanceTypes.contains(rootElementInfo.elementName)) {
      consider = false;
    }

    if (consider) {
      Tags itemTags = untypedItem.getTags();

      for (InetAddress address : Tag.NETWORK_ADDRESS.find(itemTags)) {
        found.add(address);
      }
    }

    boolean includeDeleted = false;

    for (UntypedItem child : client.listChildren(untypedItem.getKey(), includeDeleted).getItems()) {
      visit(child);
    }

  }
View Full Code Here

  public Object runCommand() throws PlatformLayerClientException {
    PlatformLayerClient client = getPlatformLayerClient();

    PlatformLayerKey resolved = path.resolve(getContext());

    UntypedItemXml item = (UntypedItemXml) client.getItemUntyped(resolved, Format.XML);

    Links links = item.getLinks();

    Link existing = links.findLink(name);
    List<Link> linkList = links.getLinks();
    if (existing != null) {
      linkList.remove(existing);

      item.setLinks(links);

      String xml = item.serialize();

      UntypedItemXml updated = (UntypedItemXml) client.putItem(resolved, xml, Format.XML);

      return updated.getLinks().getLinks();
    } else {
      return linkList;
    }
  }
View Full Code Here

          throw new IllegalStateException();
        }
        itemBase.setKey(changeHost(plk));
        // }
      } else if (item instanceof UntypedItemXml) {
        UntypedItemXml untypedItemXml = (UntypedItemXml) item;
        PlatformLayerKey plk = untypedItemXml.getKey();
        untypedItemXml.setPlatformLayerKey(changeHost(plk));
      } else {
        throw new UnsupportedOperationException();
      }
      // }
View Full Code Here

  public void visit(CliContext contextGeneric, UntypedItem o, OutputSink sink) throws IOException {
    PlatformLayerCliContext context = (PlatformLayerCliContext) contextGeneric;

    LinkedHashMap<String, Object> values = Maps.newLinkedHashMap();

    UntypedItemXml item = (UntypedItemXml) o;

    Element dataElement = item.getDataElement();

    // String xml = o.getModelData();
    //
    // Element documentElement;
    //
    // try {
    // Document dom = XmlHelper.parseXmlDocument(xml, false);
    // documentElement = dom.getDocumentElement();
    // } catch (Exception e) {
    // throw new IllegalArgumentException("Error parsing XML", e);
    // }

    values.put("key", Utils.formatUrl(context, item.getKey()));
    values.put("state", item.getState());

    Tags tags = item.getTags();
    values.put("tags", tagsToString(context, tags));

    NodeList childNodes = dataElement.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
      Node node = childNodes.item(i);
View Full Code Here

TOP

Related Classes of org.platformlayer.UntypedItemXml

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.