Package org.eclipse.persistence.internal.oxm

Examples of org.eclipse.persistence.internal.oxm.NamespaceResolver


            }
            if(next != null){
                NamespaceInfo info = getNamespaceInfoForURI(namespaceUri);

          if(info != null) {
            NamespaceResolver resolver = info.getNamespaceResolverForDescriptor();
           
            String prefix = null;
            if(namespaceUri != Constants.EMPTY_STRING){
                prefix = resolver.resolveNamespaceURI(namespaceUri);
                if(prefix == null){
                  prefix = getPrefixForNamespace(namespaceUri, resolver);             
                }
            }
            desc.setNamespaceResolver(resolver);
            if(nextElement.isXmlRootElement()) {
                desc.setDefaultRootElement(getQualifiedString(prefix, next.getLocalPart()));
            } else {
                desc.setDefaultRootElement("");
                desc.addRootElement(getQualifiedString(prefix, next.getLocalPart()));
                desc.setResultAlwaysXMLRoot(true);
            }
                } else {
                    if(namespaceUri.equals("")) {
                        desc.setDefaultRootElement(next.getLocalPart());
                    } else {
                        NamespaceResolver resolver = new org.eclipse.persistence.oxm.NamespaceResolver();
                        String prefix = getPrefixForNamespace(namespaceUri, resolver);

                        desc.setNamespaceResolver(resolver);
                          if(nextElement.isXmlRootElement()) {
                              desc.setDefaultRootElement(getQualifiedString(prefix, next.getLocalPart()));
View Full Code Here


            sourceElement = ((Document)sourceNode).getDocumentElement();
        }else if(sourceNode.getNodeType() == Node.ELEMENT_NODE){
            sourceElement = (Element)sourceNode;
        }
       
        NamespaceResolver sourceNR = new NamespaceResolver();
        sourceNR.setDOM(sourceElement);
       
        NamespaceResolver targetNR = new NamespaceResolver();
        targetNR.setDOM(targetNode);
              
        String prefix = getPrefix(namespace, sourceNR, sourceElement);
        if(prefix != null && prefix.length() >0){
            xmlRootQualifiedName = prefix + ':' + name;           
        }
       
        if(null == xmlRootQualifiedName && null != sourceElement) {
            namespace = sourceElement.getNamespaceURI();
            xmlRootQualifiedName = sourceElement.getNodeName();
        }
        if(xmlRootQualifiedName != null) {
            Element newElement = null;
            if(null == namespace) {
                newElement = targetDoc.createElement(xmlRootQualifiedName);
                if(null != targetNR.getDefaultNamespaceURI()) {
                    newElement.setAttributeNS(XMLConstants.XMLNS_ATTRIBUTE_NS_URI, XMLConstants.XMLNS_ATTRIBUTE, Constants.EMPTY_STRING);
                }
            } else {
                newElement = targetDoc.createElementNS(namespace, xmlRootQualifiedName);
                if(null == prefix) {
                    prefix = newElement.getPrefix();
                }
            }
            if(prefix != null && prefix.length() >0 && targetNR.resolveNamespaceURI(namespace) == null){
                newElement.setAttributeNS(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI, javax.xml.XMLConstants.XMLNS_ATTRIBUTE + ':' + prefix, namespace);
            }
            targetNode.appendChild(newElement);
   
            copyAttributes(sourceElement.getAttributes(),sourceElement, newElement, sourceNR, targetNR);
View Full Code Here

        Descriptor schemaDescriptor = (Descriptor)proj.getDescriptor(Schema.class);
        int schemaCount = 0;
        for (Entry<String, Schema> entry : schemas.entrySet()) {
            Schema schema = entry.getValue();
            try {
                NamespaceResolver schemaNamespaces = schema.getNamespaceResolver();
                schemaNamespaces.put(Constants.SCHEMA_PREFIX, "http://www.w3.org/2001/XMLSchema");
                schemaDescriptor.setNamespaceResolver(schemaNamespaces);
                javax.xml.transform.Result target = outputResolver.createOutput(schema.getTargetNamespace(), schema.getName());
                marshaller.marshal(schema, target);
                schemaCount++;
            } catch (IOException ex) {
View Full Code Here

     */
    protected QName getDefaultRootElementAsQName(Descriptor desc, String qualifiedTableName) {
        QName qName = null;
        int idx = qualifiedTableName.indexOf(Constants.COLON);
        String localName = qualifiedTableName.substring(idx + 1);
        NamespaceResolver nsResolver = desc.getNamespaceResolver();
        if (nsResolver == null) {
            qName = new QName(localName);
        } else if (idx > -1) {
            String prefix = qualifiedTableName.substring(0, idx);
            String uri = nsResolver.resolveNamespacePrefix(prefix);
            qName = new QName(uri, localName);
        } else {
            if (nsResolver.getDefaultNamespaceURI() != null) {
                qName = new QName(nsResolver.getDefaultNamespaceURI(), localName);
            } else {
                qName = new QName(localName);
            }
        }
        return qName;
View Full Code Here

    @Override
    public boolean addXsiTypeAndClassIndicatorIfRequired(
            Descriptor xmlDescriptor, Descriptor referenceDescriptor,
            Field xmlField, Object originalObject, Object obj,
            boolean wasXMLRoot, boolean isRootElement) {
        validatingRecord.setNamespaceResolver(new NamespaceResolver(marshalRecord.getNamespaceResolver()));
        validatingRecord.addXsiTypeAndClassIndicatorIfRequired(xmlDescriptor, referenceDescriptor, xmlField, originalObject, obj, wasXMLRoot, isRootElement);
        return marshalRecord.addXsiTypeAndClassIndicatorIfRequired(xmlDescriptor, referenceDescriptor, xmlField, originalObject, obj, wasXMLRoot, isRootElement);
    }
View Full Code Here

        if(newName != null){
            namespace = newNamespace;
            localName = newName;
            nodeName = newName;
            if(newNamespace != null && newNamespace.length() > 0) {
                NamespaceResolver tempNR = new NamespaceResolver();
                tempNR.setDOM(elem);               
                prefix = tempNR.resolveNamespaceURI(namespace);
               
                if(prefix == null || prefix.length() == 0){
                    String defaultNamespace = elem.getAttributeNS(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI, javax.xml.XMLConstants.XMLNS_ATTRIBUTE);
                    if(defaultNamespace == null){
                        prefix = tempNR.generatePrefix();   
                    }else if(defaultNamespace != namespace){
                        prefix = tempNR.generatePrefix();
                    }else{
                        prefix = Constants.EMPTY_STRING;
                    }     
                }   
            }
View Full Code Here

    protected static final String TRUE = "true";
   
   
    public MarshalRecord() {
        super(null);
        namespaceResolver = new NamespaceResolver();
    }
View Full Code Here

                //need to add a default namespace declaration.               
                defaultNamespaceDeclaration(namespaceURI);
            }
            return qName.getLocalPart();
        } else {
            NamespaceResolver namespaceResolver = getNamespaceResolver();
            if(namespaceResolver == null){
                throw XMLMarshalException.namespaceResolverNotSpecified(namespaceURI);
            }
            if(namespaceURI.equals(namespaceResolver.getDefaultNamespaceURI())) {
                return qName.getLocalPart();
            }
            String prefix = namespaceResolver.resolveNamespaceURI(namespaceURI);
            if(null == prefix) {
                prefix = namespaceResolver.generatePrefix();               
                namespaceDeclaration(prefix, namespaceURI);
            }
            if(Constants.EMPTY_STRING.equals(prefix)){
              return qName.getLocalPart();
            }
View Full Code Here

    protected String processNamespaceResolverForXSIPrefix(NamespaceResolver namespaceResolver) {
        String xsiPrefix;
        if (null == namespaceResolver) {
            // add new xsi entry into the properties map
            xsiPrefix = Constants.SCHEMA_INSTANCE_PREFIX;
            namespaceResolver = new NamespaceResolver();
            namespaceResolver.put(xsiPrefix, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);           
            namespaceDeclaration(xsiPrefix, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
        } else {
            // find an existing xsi entry in the map
            xsiPrefix = namespaceResolver.resolveNamespaceURI(javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
View Full Code Here

     * @param value
     */
    protected void handleXMLNSPrefixedAttribute(Element elem, Attr attr) {
        String uri = resolveNamespacePrefix(elem.getPrefix());
        if (uri == null || !uri.equals(attr.getLocalName())) {
            NamespaceResolver tmpresolver = getTempResolver(elem);
            tmpresolver.put(attr.getLocalName(), attr.getValue());
            if (!nsresolverList.contains(tmpresolver)) {
                nsresolverList.add(tmpresolver);
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.eclipse.persistence.internal.oxm.NamespaceResolver

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.