Package com.caucho.jaxb.mapping

Examples of com.caucho.jaxb.mapping.XmlMapping


    // Necessary for situations in which the read object has an XmlValue,
    // but also has XmlAttributes.
    if (attributed != null) {
      for (int i = 0; i < in.getAttributeCount(); i++) {
        QName attributeName = in.getAttributeName(i);
        XmlMapping mapping = attributed.getAttributeMapping(attributeName);

        if (mapping == null)
          throw new UnmarshalException(L.l("Attribute {0} not found in {1}",
                                           attributeName,
                                           attributed.getType()));

        mapping.readAttribute(in, i, parent);
      }
    }

    // Now read the actual value of the CData
    in.next();
View Full Code Here


   * mapping or field.
   **/
  private void processAccessor(Accessor accessor)
    throws JAXBException
  {
    XmlMapping mapping = XmlMapping.newInstance(_context, accessor);

    if (mapping instanceof XmlValueMapping) {
      if (_value != null)
        throw new JAXBException(L.l("Cannot have two @XmlValue annotated fields or properties"));

      if (_elementMappings.size() > 0) {
        // in case of propOrder & XmlValue
        if (_elementMappings.size() != 1 || _elementMappings.get(0) != null)
          throw new JAXBException(L.l("Cannot have both @XmlValue and elements in a JAXB element (e.g. {0})", _elementMappings.get(0)));

        _elementMappings.clear();
      }

      _value = (XmlValueMapping) mapping;
    }
    else if (mapping instanceof AttributeMapping) {
      mapping.putQNames(_attributeQNameToMappingMap);
      _attributeMappings.add((AttributeMapping) mapping);
    }
    else if (mapping instanceof AnyAttributeMapping) {
      if (_anyAttributeMapping != null)
        throw new JAXBException(L.l("Cannot have two fields or properties with @XmlAnyAttribute annotation"));

      _anyAttributeMapping = (AnyAttributeMapping) mapping;
      _attributeMappings.add(mapping);
    }
    else if ((mapping instanceof ElementMapping) ||
             (mapping instanceof ElementRefMapping) ||
             (mapping instanceof ElementsMapping)) {
      if (_value != null)
        throw new JAXBException(L.l("{0}: Cannot have both @XmlValue and elements in a JAXB element", _class.getName()));

      if (mapping.getAccessor().getOrder() >= 0)
        _elementMappings.set(mapping.getAccessor().getOrder(), mapping);
      else
        _elementMappings.add(mapping);
    }
    else if (mapping instanceof AnyElementMapping) {
      if (_anyElementMapping != null)
        throw new JAXBException(L.l("{0}: Cannot have two @XmlAnyElement annotations in a single class", _class.getName()));

      _anyElementMapping = (AnyElementMapping) mapping;
    }
    else {
      throw new RuntimeException(L.l("Unknown mapping type {0}", mapping.getClass()));
    }
  }
View Full Code Here

  }

  private XmlMapping getElementMapping(QName q)
    throws JAXBException
  {
    XmlMapping mapping = _elementQNameToMappingMap.get(q);

    if (mapping != null)
      return mapping;

    if (_anyElementMapping != null)
View Full Code Here

  }

  public XmlMapping getAttributeMapping(QName q)
    throws JAXBException
  {
    XmlMapping mapping = _attributeQNameToMappingMap.get(q);

    if (mapping != null)
      return mapping;

    if (_anyAttributeMapping != null)
View Full Code Here

      }
      else {
        // process the attributes
        for (int i = 0; i < in.getAttributeCount(); i++) {
          QName attributeName = in.getAttributeName(i);
          XmlMapping mapping = getAttributeMapping(attributeName);

          if (mapping == null)
            throw new UnmarshalException(L.l("Attribute {0} not found in {1}",
                                             attributeName, getType()));

          mapping.readAttribute(in, i, ret);
        }

        int i = 0;
        in.nextTag();

        while (in.getEventType() == in.START_ELEMENT) {
          XmlMapping mapping = getElementMapping(in.getName());

          if (mapping == null) {
            throw new UnmarshalException(L.l("Child <{0}> not found in {1}",
                                             in.getName(), getType()));
          }

          if (! mapping.getAccessor().checkOrder(i++, u.getEventHandler())) {
            throw new UnmarshalException(L.l("Child <{0}> misordered in {1}",
                                             in.getName(), getType()));
          }

          mapping.read(u, in, ret);
        }

        // essentially a nextTag() that handles end of document gracefully
        while (in.hasNext()) {
          in.next();
View Full Code Here

      while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
          QName name = JAXBUtil.qnameFromNode(child);

          XmlMapping mapping = getElementMapping(name);

          if (mapping == null)
            throw new UnmarshalException(L.l("Child <{0}> not found", name));

          if (! mapping.getAccessor().checkOrder(i++, binder.getEventHandler()))
            throw new UnmarshalException(L.l("Child <{0}> misordered", name));

          mapping.bindFrom(binder, node, ret);
        }

        child = node.nextSibling();
      }
    }
View Full Code Here

    // Necessary for situations in which the read object has an XmlValue,
    // but also has XmlAttributes.
    if (attributed != null) {
      for (int i = 0; i < in.getAttributeCount(); i++) {
        QName attributeName = in.getAttributeName(i);
        XmlMapping mapping = attributed.getAttributeMapping(attributeName);

        if (mapping == null)
          throw new UnmarshalException(L.l("Attribute {0} not found in {1}",
                                           attributeName,
                                           attributed.getType()));

        mapping.readAttribute(in, i, parent);
      }
    }

    // Now read the actual value of the CData
    in.next();
View Full Code Here

   * mapping or field.
   **/
  private void processAccessor(Accessor accessor)
    throws JAXBException
  {
    XmlMapping mapping = XmlMapping.newInstance(_context, accessor);

    if (mapping instanceof XmlValueMapping) {
      if (_value != null)
        throw new JAXBException(L.l("Cannot have two @XmlValue annotated fields or properties"));

      if (_elementMappings.size() > 0) {
        // in case of propOrder & XmlValue
        if (_elementMappings.size() != 1 || _elementMappings.get(0) != null)
          throw new JAXBException(L.l("Cannot have both @XmlValue and elements in a JAXB element (e.g. {0})", _elementMappings.get(0)));

        _elementMappings.clear();
      }

      _value = (XmlValueMapping) mapping;
    }
    else if (mapping instanceof AttributeMapping) {
      mapping.putQNames(_attributeQNameToMappingMap);
      _attributeMappings.add((AttributeMapping) mapping);
    }
    else if (mapping instanceof AnyAttributeMapping) {
      if (_anyAttributeMapping != null)
        throw new JAXBException(L.l("Cannot have two fields or properties with @XmlAnyAttribute annotation"));

      _anyAttributeMapping = (AnyAttributeMapping) mapping;
      _attributeMappings.add(mapping);
    }
    else if ((mapping instanceof ElementMapping) ||
             (mapping instanceof ElementRefMapping) ||
             (mapping instanceof ElementsMapping)) {
      if (_value != null)
        throw new JAXBException(L.l("{0}: Cannot have both @XmlValue and elements in a JAXB element", _class.getName()));

      if (mapping.getAccessor().getOrder() >= 0)
        _elementMappings.set(mapping.getAccessor().getOrder(), mapping);
      else
        _elementMappings.add(mapping);
    }
    else if (mapping instanceof AnyElementMapping) {
      if (_anyElementMapping != null)
        throw new JAXBException(L.l("{0}: Cannot have two @XmlAnyElement annotations in a single class", _class.getName()));

      _anyElementMapping = (AnyElementMapping) mapping;
    }
    else {
      throw new RuntimeException(L.l("Unknown mapping type {0}", mapping.getClass()));
    }
  }
View Full Code Here

  }

  private XmlMapping getElementMapping(QName q)
    throws JAXBException
  {
    XmlMapping mapping = _elementQNameToMappingMap.get(q);

    if (mapping != null)
      return mapping;

    if (_anyElementMapping != null)
View Full Code Here

  }

  public XmlMapping getAttributeMapping(QName q)
    throws JAXBException
  {
    XmlMapping mapping = _attributeQNameToMappingMap.get(q);

    if (mapping != null)
      return mapping;

    if (_anyAttributeMapping != null)
View Full Code Here

TOP

Related Classes of com.caucho.jaxb.mapping.XmlMapping

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.