Example usage for javax.xml.namespace QName QName

List of usage examples for javax.xml.namespace QName QName

Introduction

In this page you can find the example usage for javax.xml.namespace QName QName.

Prototype

public QName(final String namespaceURI, final String localPart) 

Source Link

Document

QName constructor specifying the Namespace URI and local part.

If the Namespace URI is null, it is set to javax.xml.XMLConstants#NULL_NS_URI XMLConstants.NULL_NS_URI .

Usage

From source file:Main.java

public static QName getQName(String namespaceURI, String localPart) {
    QName name = new QName(namespaceURI, localPart);
    return name;//  w w w  .j av  a 2  s  .  c  o  m
}

From source file:Main.java

/**
 * Registers a global variable. Global variables are added to the list of
 * variable of a webtest at the webtest start.
 * @param namespaceURI the namespace URI of the function to be registered (<code>null</code>
 *            if none)./*from w w w .j a va2  s  . co  m*/
 * @param localName the non-prefixed local portion of the function name to
 *            be registered
 * @param value the variable to be registered
 */
public static void registerGlobalVariable(final String namespaceURI, final String localName,
        final Object value) {
    sGlobalVariables.put(new QName(namespaceURI, localName), value);
}

From source file:Main.java

/**
 * @param the//from   w  ww .  j a v  a2  s.c  o m
 *            node to create the name from, never <code>null</code>
 * @return the node of the name as qualified name, never <code>null</code>
 */
public static QName buildQName(Node node) {
    String localPart;
    String nsName;
    String name = node.getTextContent();
    int indexOfColon = name.indexOf(':');
    if (indexOfColon > 0) {
        localPart = name.substring(indexOfColon + 1);
        nsName = node.lookupNamespaceURI(name.substring(0, indexOfColon));
    } else {
        localPart = name;
        // return default namespace URI if any
        nsName = node.lookupNamespaceURI(null);
    }
    return new QName(nsName, localPart);
}

From source file:Main.java

/**
 * Generic method to Validate XML file while marshalling against their schema.
 * //from   ww w  .j  ava 2 s . co  m
 * @param context
 * @param schemaFile
 * @param object
 * @return
 * @throws SAXException
 * @throws JAXBException
 */
public static String validateAndMarshallXML(JAXBContext context, String schemaFile, Object object)
        throws SAXException, JAXBException {
    String xmlFormOfBean = null;

    //      if (context != null && (schemaFile != null && schemaFile.trim().length() > 0)) {
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    QName qname = new QName("www.genpact.com", "CobCmData");
    marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "www.genpact.com cob_cm.xsd ");
    //         SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);   // thread- safe 
    //         marshaller.setSchema(sf.newSchema(new File(schemaFile)));   // validate jaxb context against schema 
    ByteArrayOutputStream sos = new ByteArrayOutputStream(); // for XML output into string

    //         JAXBElement<CobCmData> rootElement = new JAXBElement<CobCmData>(qname,CobCmData.class,(CobCmData)object);
    //         marshaller.marshal(rootElement, sos);  
    //         xmlFormOfBean = sos.toString();

    //      }
    return xmlFormOfBean;
}

From source file:Main.java

/**
 * Create QName.//from   w w  w.j  a  va 2 s.  c om
 * 
 * @param qnameString a qualified name.
 * @return a QName object.
 */
public static QName createQName(String qnameString) {
    QName qname = null;

    // Locate local part
    int index = qnameString.lastIndexOf(":");

    // Create new QName
    if (index != -1) {
        qname = new QName(qnameString.substring(0, index), qnameString.substring(index + 1));
    }

    else {
        qname = new QName(qnameString);
    }

    return qname;
}

From source file:Utils.java

public static QName getElementQName(Element el) {
    return new QName(el.getNamespaceURI(), el.getLocalName());
}

From source file:Main.java

/**
 * Utility method to marshal a JAXB annotated java object to an XML
 * formatted string.  This class is generic enough to be used for any
 * JAXB annotated java object not containing the {@link XmlRootElement}
 * annotation.//from   w  w  w  . j  ava2  s.  c o  m
 *
 * @param xmlClass   The JAXB class of the object to marshal.
 * @param xmlObject   The JAXB object to marshal.
 * @return      String containing the XML encoded object.
 */
public static String jaxbToString(Class<?> xmlClass, Object xmlObject) {

    // Make sure we are given the correct input.
    if (xmlClass == null || xmlObject == null) {
        return null;
    }

    @SuppressWarnings("unchecked")
    JAXBElement<?> jaxbElement = new JAXBElement(new QName("uri", "local"), xmlClass, xmlObject);

    return jaxbToString(xmlClass, jaxbElement);
}

From source file:Main.java

/**
 * Marshals a bean to XML./*from w  w  w.j a va  2  s  . c om*/
 * 
 * @param bean
 * @param namespaceURI
 * @param localPart
 * @return XML {@link String}
 * @throws JAXBException
 */
@SuppressWarnings("unchecked")
public static <T> String marshal(T bean, String namespaceURI, String localPart) throws JAXBException {
    QName qName = new QName(namespaceURI, localPart);
    Class<T> clazz = (Class<T>) bean.getClass();
    Marshaller marshaller = createMarshaller(clazz);
    Writer stw = new StringWriter();
    marshaller.marshal(new JAXBElement<T>(qName, clazz, bean), stw);

    return stw.toString();
}

From source file:Main.java

/**
 * Utility method that creates a new JAXBElement, which is used to marshal
 * the object/*  w  w  w .j  a  v  a2 s. co  m*/
 * @param ns the name space
 * @param elementName the name element
 * @param clazz the class of the object to marshal
 * @param obj the object to marshal
 * @param <T> the type of the object
 * @return A JAXBElement that can be used to marshal the object
 */
public static <T> JAXBElement<T> newJAXBElement(String ns, String elementName, Class<T> clazz, T obj) {
    QName qName = new QName(ns, elementName);

    return new JAXBElement<T>(qName, clazz, obj);
}

From source file:Main.java

public static QName nodeToQName(Node node) {
    return new QName(node.getNamespaceURI(), node.getLocalName());
}