Package org.platformlayer.xml

Examples of org.platformlayer.xml.JaxbHelper


          case XML:
            if (debug != null) {
              debug.println("Data: [XML Content]");
            }

            JaxbHelper jaxbHelper = JaxbHelper.get(sendData.getClass());
            String xml = jaxbHelper.marshal(sendData, false);
            httpRequest.setRequestContent(new Utf8StringByteSource(xml));
            // jaxbHelper.marshal(sendData, false, getOutputStream());
            break;
          case JSON:
            if (debug != null) {
View Full Code Here


  }

  protected abstract <T> Class<T> mapToJavaClass(ElementInfo elementInfo) throws OpsException;

  public <T> T promoteToTyped(UntypedItem untypedItem, Class<T> itemClass) throws OpsException {
    JaxbHelper jaxbHelper = JaxbHelper.get(itemClass);
    T typedItem;
    try {
      Element element = ((UntypedItemXml) untypedItem).getDataElement();

      String xmlElementName = jaxbHelper.getXmlElementName();
      String nodeName = element.getLocalName();
      if (!Objects.equal(xmlElementName, nodeName)) {
        String type = element.getAttribute("xsi:type");

        if (type != null && type.endsWith(":" + xmlElementName)) {
          // OK
        } else {
          throw new OpsException("Incorrect element type: " + xmlElementName + " vs " + nodeName);
        }
      }

      T object = jaxbHelper.unmarshal(element, itemClass);

      if (!(object.getClass().isAssignableFrom(itemClass))) {
        System.out.println("XML = " + ((UntypedItemXml) untypedItem).serialize());
      }
View Full Code Here

  public static <T extends ItemBase> ModelClass<T> publicModel(ServiceProvider serviceProvider, Class<T> clazz) {
    return build(serviceProvider, clazz);
  }

  public static <T extends ItemBase> ModelClass<T> build(ServiceProvider serviceProvider, Class<T> clazz) {
    JaxbHelper jaxbHelper = JaxbHelper.get(clazz);
    ItemType itemType = new ItemType(JaxbHelper.getXmlElementName(clazz));
    return new ModelClass<T>(serviceProvider, clazz, itemType);
  }
View Full Code Here

  }

  public static <T> T cloneViaJaxb(T o) {
    try {
      Class<T> objectClass = (Class<T>) o.getClass();
      JaxbHelper jaxbHelper = JaxbHelper.get(objectClass);

      String xml = JaxbHelper.toXml(o, false);
      return jaxbHelper.deserialize(new StringReader(xml), objectClass);
    } catch (UnmarshalException e) {
      throw new IllegalStateException("Error while cloning object", e);
    } catch (JAXBException e) {
      throw new IllegalStateException("Error while cloning object", e);
    }
View Full Code Here

      }

      ServiceType serviceType = db.getServiceType(entity.service);
      ItemType itemType = db.getItemType(entity.model);

      JaxbHelper jaxbHelper = getJaxbHelper(db, serviceType, itemType);
      T item = mapToModel(project, serviceType, itemType, entity, jaxbHelper, secretProvider);

      int itemId = entity.id;
      Collection<Tag> tags = itemTags.get(itemId);
      item.getTags().addAll(tags);
View Full Code Here

    ModelClass<?> modelClass = serviceProvider.getModelClass(itemType);
    if (modelClass == null) {
      throw new IllegalStateException();
    }

    JaxbHelper jaxbHelper = JaxbHelper.get(modelClass.getJavaClass());
    return jaxbHelper;
  }
View Full Code Here

    mutableItem.tags = null;
    mutableItem.key = null;
    mutableItem.version = 0;
    mutableItem.state = null;

    JaxbHelper jaxbHelper = JaxbHelper.get(item.getClass());

    StringWriter writer = new StringWriter();
    try {
      Marshaller marshaller = jaxbHelper.createMarshaller();

      // OpsSecretEncryptionStrategy strategy = new OpsSecretEncryptionStrategy(itemSecret);
      // strategy.setAdapter(marshaller);

      marshaller.marshal(mutableItem, writer);
View Full Code Here

    return doListConcatenationUntyped(getChildClients(path), AddHostUntyped.wrap(new ListItemsUntyped(path)));
  }

  @Override
  public <T> List<T> listItems(final Class<T> clazz) throws PlatformLayerClientException {
    JaxbHelper jaxbHelper = PlatformLayerClientBase.toJaxbHelper(clazz, ManagedItemCollection.class);
    PlatformLayerKey path = PlatformLayerClientBase.toKey(jaxbHelper, null, listServices(true));

    return doListConcatenationTyped(getChildClients(path), AddHostTyped.wrap(new ListItemsTyped<T>(clazz)));
  }
View Full Code Here

      throw new UnsupportedOperationException();
    }
  }

  protected PlatformLayerKey toKey(Class<?> c) throws PlatformLayerClientException {
    JaxbHelper jaxbHelper = toJaxbHelper(c, new Class[0]);
    return toKey(jaxbHelper);
  }
View Full Code Here

    if (format == null) {
      throw new IllegalStateException("Could not determine format");
    }

    if (format == Format.XML) {
      JaxbHelper jaxb = JaxbHelper.get(c);
      try {
        return jaxb.deserialize(new StringReader(data), c);
      } catch (UnmarshalException e) {
        throw new OpsException("Error deserializing item", e);
      }
    } else {
      throw new UnsupportedOperationException();
View Full Code Here

TOP

Related Classes of org.platformlayer.xml.JaxbHelper

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.