Ejemplo n.º 1
0
 public Attribute unmarshal(Object value) {
   if (value instanceof org.w3c.dom.Element) {
     org.w3c.dom.Element el = (org.w3c.dom.Element) value;
     String prefix = el.getPrefix();
     String namespace = el.getNamespaceURI();
     String local = el.getLocalName();
     String child = el.getTextContent();
     String typeAsString = el.getAttributeNS(NamespacePrefixMapper.XSI_NS, "type");
     String lang = el.getAttributeNS(NamespacePrefixMapper.XML_NS, "lang");
     QName type =
         ((typeAsString == null) || (typeAsString.equals("")))
             ? null
             : stringToQName(typeAsString, el);
     if (type == null) type = ValueConverter.QNAME_XSD_STRING;
     if (type.equals(ValueConverter.QNAME_XSD_QNAME)) {
       QName qn = stringToQName(child, el); // TODO: not robust to prefix not predeclared
       return pFactory.newAttribute(namespace, local, prefix, qn, type);
     } else if ((lang == null) || (lang.equals(""))) {
       return pFactory.newAttribute(
           namespace, local, prefix, vconv.convertToJava(type, child), type);
     } else {
       return pFactory.newAttribute(
           namespace, local, prefix, pFactory.newInternationalizedString(child, lang), type);
     }
   }
   if (value instanceof JAXBElement) {
     JAXBElement<?> je = (JAXBElement<?>) value;
     return pFactory.newAttribute(je.getName(), je.getValue(), vconv);
   }
   return null;
 }
Ejemplo n.º 2
0
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "Key", namespace = "http://www.w3.org/ns/prov#")
@javax.persistence.Entity(name = "Key")
@Table(name = "KEY")
public class Key extends TypedValue
    implements Equals,
        HashCode,
        ToString,
        org.openprovenance.prov.model.Key,
        org.openprovenance.prov.model.Attribute {

  private static final AttributeKind PROV_KEY_KIND =
      org.openprovenance.prov.model.Attribute.AttributeKind.PROV_KEY;
  private static final QualifiedName PROV_KEY_QNAME = ProvFactory.getFactory().getName().PROV_KEY;

  @Transient
  public QualifiedName getElementName() {
    return PROV_KEY_QNAME;
  }

  @Transient
  public AttributeKind getKind() {
    return PROV_KEY_KIND;
  }

  public String toNotationString() {
    return DOMProcessing.qualifiedNameToString(getElementName())
        + " = "
        + ProvUtilities.valueToNotationString(getValue(), getType());
  }
}
Ejemplo n.º 3
0
  public Object marshal(Attribute attribute) {
    // System.out.println("AnyAdapter2 marshalling for " + attribute);
    // System.out.println("AnyAdapter2 marshalling for " + attribute
    //                .getClass());
    // TODO: this call creates a DOM but does not encode the type as xsi:type
    Object value = attribute.getValue();
    if (value instanceof InternationalizedString) {
      InternationalizedString istring = ((InternationalizedString) value);
      return pFactory.newElement(
          attribute.getElementName(),
          istring.getValue(),
          attribute.getXsdType(),
          istring.getLang());
    } else if (value instanceof QName) {
      return pFactory.newElement(attribute.getElementName(), (QName) value);

    } else {
      return pFactory.newElement(
          attribute.getElementName(), value.toString(), attribute.getXsdType());
    }
    // JAXBElement<?> je=new
    // JAXBElement(value.getElementName(),value.getValue().getClass(),value.getValue());
    // return je;
  }