コード例 #1
0
 public UnmappedContentHandlerWrapper(
     UnmarshalRecord parentRecord, UnmappedContentHandler unmappedContentHandler) {
   super(null);
   this.depth = 0;
   this.unmappedContentHandler = unmappedContentHandler;
   setParentRecord(parentRecord);
   setUnmarshaller(parentRecord.getUnmarshaller());
   setXMLReader(parentRecord.getXMLReader());
   setUnmarshalNamespaceResolver(parentRecord.getUnmarshalNamespaceResolver());
   unmappedContentHandler.setUnmarshalRecord(this);
 }
コード例 #2
0
  public void attribute(
      UnmarshalRecord unmarshalRecord, String namespaceURI, String localName, String value) {
    DirectMapContainerPolicy cp =
        (DirectMapContainerPolicy) xmlAnyAttributeMapping.getContainerPolicy();
    Object containerInstance = unmarshalRecord.getContainerInstance(this);

    boolean includeAttribute = true;
    if (!xmlAnyAttributeMapping.isNamespaceDeclarationIncluded()
        && XMLConstants.XMLNS_URL.equals(namespaceURI)) {
      includeAttribute = false;
    } else if (!xmlAnyAttributeMapping.isSchemaInstanceIncluded()
        && XMLConstants.SCHEMA_INSTANCE_URL.equals(namespaceURI)) {
      includeAttribute = false;
    }

    if (includeAttribute) {
      QName key = new QName(namespaceURI, localName);
      cp.addInto(key, value, containerInstance, unmarshalRecord.getSession());
    }
  }
コード例 #3
0
  /**
   * INTERNAL: Create (if necessary) and populate a reference object that will be used during the
   * mapping reference resolution phase after unmarshalling is complete.
   *
   * @param record
   * @param xmlField
   * @param object
   * @param session
   * @return
   */
  public void buildReference(
      UnmarshalRecord record, XMLField xmlField, Object object, AbstractSession session) {
    ReferenceResolver resolver = ReferenceResolver.getInstance(session);
    if (resolver == null) {
      return;
    }

    Object srcObject = record.getCurrentObject();
    Reference reference = resolver.getReference(this, srcObject);
    // if reference is null, create a new instance and set it on the resolver
    if (reference == null) {
      reference = new Reference(this, srcObject, getReferenceClass(), new HashMap());
      resolver.addReference(reference);
    }

    XMLField tgtFld = (XMLField) getSourceToTargetKeyFieldAssociations().get(xmlField);
    String tgtXPath = tgtFld.getXPath();
    Vector pks;
    HashMap primaryKeyMap = reference.getPrimaryKeyMap();
    if (primaryKeyMap.containsKey(tgtXPath)) {
      pks = (Vector) primaryKeyMap.get(tgtXPath);
    } else {
      pks = new Vector();
      primaryKeyMap.put(tgtXPath, pks);
    }

    ClassDescriptor descriptor = session.getClassDescriptor(getReferenceClass());
    Class type = descriptor.getTypedField(tgtFld).getType();
    XMLConversionManager xmlConversionManager =
        (XMLConversionManager) session.getDatasourcePlatform().getConversionManager();
    for (StringTokenizer stok = new StringTokenizer((String) object); stok.hasMoreTokens(); ) {
      Object value = xmlConversionManager.convertObject(stok.nextToken(), type);
      if (value != null) {
        pks.add(value);
      }
    }
  }
 public void endElement(XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord) {
   unmarshalRecord.getStringBuffer().reset();
 }
 public boolean startElement(
     XPathFragment xPathFragment, UnmarshalRecord unmarshalRecord, Attributes atts) {
   try {
     XMLField xmlField = (XMLField) xmlBinaryDataCollectionMapping.getField();
     XPathFragment lastFragment = xmlField.getLastXPathFragment();
     if (!lastFragment.isAttribute()) {
       // set a new content handler to deal with the Include element's event.
       BinaryMappingContentHandler handler =
           new BinaryMappingContentHandler(
               unmarshalRecord, this, this.xmlBinaryDataCollectionMapping);
       String qnameString = xPathFragment.getLocalName();
       if (xPathFragment.getPrefix() != null) {
         qnameString = xPathFragment.getPrefix() + XMLConstants.COLON + qnameString;
       }
       handler.startElement(
           xPathFragment.getNamespaceURI(), xPathFragment.getLocalName(), qnameString, atts);
       unmarshalRecord.getXMLReader().setContentHandler(handler);
     } else if (lastFragment.isAttribute()) {
       // handle swaRef and inline attribute cases here:
       String value = atts.getValue(lastFragment.getNamespaceURI(), lastFragment.getLocalName());
       Object fieldValue = null;
       if (xmlBinaryDataCollectionMapping.isSwaRef()) {
         if (unmarshalRecord.getUnmarshaller().getAttachmentUnmarshaller() != null) {
           if (xmlBinaryDataCollectionMapping.getAttributeClassification()
               == XMLBinaryDataHelper.getXMLBinaryDataHelper().DATA_HANDLER) {
             fieldValue =
                 unmarshalRecord
                     .getUnmarshaller()
                     .getAttachmentUnmarshaller()
                     .getAttachmentAsDataHandler(value);
           } else {
             fieldValue =
                 unmarshalRecord
                     .getUnmarshaller()
                     .getAttachmentUnmarshaller()
                     .getAttachmentAsByteArray(value);
           }
           xmlBinaryDataCollectionMapping.setAttributeValueInObject(
               unmarshalRecord.getCurrentObject(),
               XMLBinaryDataHelper.getXMLBinaryDataHelper()
                   .convertObject(
                       fieldValue,
                       xmlBinaryDataCollectionMapping.getAttributeClassification(),
                       unmarshalRecord.getSession()));
         }
       } else {
         // value should be base64 binary string
         fieldValue =
             ((XMLConversionManager)
                     unmarshalRecord.getSession().getDatasourcePlatform().getConversionManager())
                 .convertSchemaBase64ToByteArray(value);
         xmlBinaryDataCollectionMapping.setAttributeValueInObject(
             unmarshalRecord.getCurrentObject(),
             XMLBinaryDataHelper.getXMLBinaryDataHelper()
                 .convertObject(
                     fieldValue,
                     xmlBinaryDataCollectionMapping.getAttributeClassification(),
                     unmarshalRecord.getSession()));
       }
     }
     return true;
   } catch (SAXException ex) {
     throw XMLMarshalException.unmarshalException(ex);
   }
 }
コード例 #6
0
 public void processEvent(UnmarshalRecord unmarshalRecord) throws SAXException {
   unmarshalRecord.startDTD(name, publicId, systemId);
 }
コード例 #7
0
 public void processEvent(UnmarshalRecord unmarshalRecord) throws SAXException {
   unmarshalRecord.comment(characters, start, end);
 }
コード例 #8
0
 public void processEvent(UnmarshalRecord unmarshalRecord) throws SAXException {
   unmarshalRecord.setDocumentLocator(locator);
 }