modules/databinding-axiom/src/main/java/org/apache/tuscany/sca/databinding/axiom/AxiomHelper.java [40:131]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class AxiomHelper {
    private static final String DEFAULT_PREFIX = "_ns_";

    private AxiomHelper() {
    }

    /**
     * See http://issues.apache.org/jira/browse/WSCOMMONS-240
     * @param om
     */
    public static void completeAndClose(OMElement om) {
        // Get the builder associated with the om element
        OMXMLParserWrapper builder = om.getBuilder();
        if (builder != null) {
            if (builder instanceof StAXBuilder) {
                ((StAXBuilder)builder).releaseParserOnClose(true);
            }
            OMElement document = builder.getDocumentElement();
            if (document != null) {
                document.build();
            }
        }
        if (builder instanceof StAXBuilder) {
            ((StAXBuilder)builder).close();
        }
    }

    /**
     * This method will close the builder immediately.  Any subsequent Axiom objects won't 
     * be built or accessible.
     */
    public static void closeImmediately(OMElement om) {
        // Get the builder associated with the om element
        OMXMLParserWrapper builder = om.getBuilder();
        if (builder != null) {
            if (builder instanceof StAXBuilder) {
                ((StAXBuilder)builder).releaseParserOnClose(true);
                ((StAXBuilder)builder).close();
            }
            // builder.close();
        }
    }

    /**
     * @param context
     * @param element
     */
    public static void adjustElementName(TransformationContext context, OMElement element) {
        if (context != null) {
            DataType dataType = context.getTargetDataType();
            Object logical = dataType == null ? null : dataType.getLogical();
            if (!(logical instanceof XMLType)) {
                return;
            }
            XMLType xmlType = (XMLType)logical;
            if (xmlType.isElement() && !xmlType.getElementName().equals(element.getQName())) {
                // FIXME:: Throw exception or switch to the new Element?
                OMFactory factory = OMAbstractFactory.getOMFactory();
                QName name = xmlType.getElementName();
                OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix());
                element.setNamespace(namespace);
                element.setLocalName(name.getLocalPart());
            }
        }
    }

    public static OMElement createOMElement(OMFactory factory, QName element) {
        String localName = element.getLocalPart();
        OMNamespace ns = createOMNamespace(factory, element);

        return factory.createOMElement(localName, ns);

    }

    public static OMElement createOMElement(OMFactory factory, QName element, OMDataSource dataSource) {
        String localName = element.getLocalPart();
        OMNamespace ns = createOMNamespace(factory, element);

        return factory.createOMElement(dataSource, localName, ns);

    }

    /**
     * @param factory
     * @param name
     * @return
     */
    public static OMNamespace createOMNamespace(OMFactory factory, QName name) {
        String namespaceURI = name.getNamespaceURI();
        String prefix = name.getPrefix();

        OMNamespace ns = null;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



modules/databinding-sdo-axiom/src/main/java/org/apache/tuscany/sca/databinding/sdo2om/AxiomHelper.java [40:131]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
public class AxiomHelper {
    private static final String DEFAULT_PREFIX = "_ns_";

    private AxiomHelper() {
    }

    /**
     * See http://issues.apache.org/jira/browse/WSCOMMONS-240
     * @param om
     */
    public static void completeAndClose(OMElement om) {
        // Get the builder associated with the om element
        OMXMLParserWrapper builder = om.getBuilder();
        if (builder != null) {
            if (builder instanceof StAXBuilder) {
                ((StAXBuilder)builder).releaseParserOnClose(true);
            }
            OMElement document = builder.getDocumentElement();
            if (document != null) {
                document.build();
            }
        }
        if (builder instanceof StAXBuilder) {
            ((StAXBuilder)builder).close();
        }
    }

    /**
     * This method will close the builder immediately.  Any subsequent Axiom objects won't 
     * be built or accessible.
     */
    public static void closeImmediately(OMElement om) {
        // Get the builder associated with the om element
        OMXMLParserWrapper builder = om.getBuilder();
        if (builder != null) {
            if (builder instanceof StAXBuilder) {
                ((StAXBuilder)builder).releaseParserOnClose(true);
                ((StAXBuilder)builder).close();
            }
            // builder.close();
        }
    }

    /**
     * @param context
     * @param element
     */
    public static void adjustElementName(TransformationContext context, OMElement element) {
        if (context != null) {
            DataType dataType = context.getTargetDataType();
            Object logical = dataType == null ? null : dataType.getLogical();
            if (!(logical instanceof XMLType)) {
                return;
            }
            XMLType xmlType = (XMLType)logical;
            if (xmlType.isElement() && !xmlType.getElementName().equals(element.getQName())) {
                // FIXME:: Throw exception or switch to the new Element?
                OMFactory factory = OMAbstractFactory.getOMFactory();
                QName name = xmlType.getElementName();
                OMNamespace namespace = factory.createOMNamespace(name.getNamespaceURI(), name.getPrefix());
                element.setNamespace(namespace);
                element.setLocalName(name.getLocalPart());
            }
        }
    }

    public static OMElement createOMElement(OMFactory factory, QName element) {
        String localName = element.getLocalPart();
        OMNamespace ns = createOMNamespace(factory, element);

        return factory.createOMElement(localName, ns);

    }

    public static OMElement createOMElement(OMFactory factory, QName element, OMDataSource dataSource) {
        String localName = element.getLocalPart();
        OMNamespace ns = createOMNamespace(factory, element);

        return factory.createOMElement(dataSource, localName, ns);

    }

    /**
     * @param factory
     * @param name
     * @return
     */
    public static OMNamespace createOMNamespace(OMFactory factory, QName name) {
        String namespaceURI = name.getNamespaceURI();
        String prefix = name.getPrefix();

        OMNamespace ns = null;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



