Example usage for javax.xml.namespace QName valueOf

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

Introduction

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

Prototype

public static QName valueOf(String qNameAsString) 

Source Link

Document

<p><code>QName</code> derived from parsing the formatted <code>String</code>.</p> <p>If the <code>String</code> is <code>null</code> or does not conform to #toString() QName.toString() formatting, an <code>IllegalArgumentException</code> is thrown.</p> <p><em>The <code>String</code> <strong>MUST</strong> be in the form returned by #toString() QName.toString() .</em></p> <p>The commonly accepted way of representing a <code>QName</code> as a <code>String</code> was <a href="http://jclark.com/xml/xmlns.htm">defined</a> by James Clark.

Usage

From source file:org.xchain.framework.quartz.CommandJob.java

/**
 * <p>Gets the command name out of the JobExecutionContext's JobDataMap.</p>
 *///from w w  w.j  ava2  s.c  o  m
private QName getCommandName(JobExecutionContext jobContext) throws JobExecutionException {
    JobDataMap dataMap = jobContext.getJobDetail().getJobDataMap();

    // get the name of the command.
    String commandNameString = dataMap.getString(COMMAND_NAME);
    QName commandName = null;

    if (commandNameString == null) {
        throw new JobExecutionException(
                "The command name was not specified in the job data map key 'command'.");
    }

    try {
        commandName = QName.valueOf(commandNameString);
    } catch (Exception e) {
        throw new JobExecutionException("The command name '" + commandNameString + "' is not a valid QName.",
                e);
    }
    return commandName;
}

From source file:org.xchain.framework.util.QNameConverter.java

public Object convert(Class type, Object value) {
    if (value == null) {
        return null;
    }/*from  ww  w  .  jav  a  2 s  .  c  o m*/

    if (QName.class.isAssignableFrom(value.getClass())) {
        return value;
    }

    // if we are currently in an execution, then look up any prefixes based on the currently executing context.
    if (Execution.inExecution() && value instanceof String) {
        JXPathContext context = Execution.getLocalContext();
        try {
            return JXPathContextUtil.stringToQName(context, (String) value);
        } catch (Exception e) {
            throw new ConversionException(e.getMessage(), e);
        }
    } else if (value instanceof String) {
        try {
            return QName.valueOf((String) value);
        } catch (Exception e) {
            throw new ConversionException("The string '" + value + "' could not be converted into a QName.");
        }
    }

    throw new ConversionException(
            "The object of type '" + value.getClass() + "' could not be converted to '" + QName.class + "'.");
}

From source file:xquery4j.TestEvaluator.java

public XQueryEvaluator buildQueryEvaluator() {
    XQueryEvaluator evaluator = new XQueryEvaluator();
    evaluator.setContextObject(this);
    evaluator.declareJavaClass("http://xmlbeans.apache.org/samples/xquery/employees", MyFunctions.class);
    evaluator.bindVariable(QName.valueOf("myVar"), 123);
    return evaluator;
}