下面列出了javax.xml.bind.helpers.ValidationEventLocatorImpl#javax.xml.namespace.NamespaceContext 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public synchronized XPathExpression getXpathExpressionWrapped() {
if (this.xpathExpressionWrapped == null && (this.getStatus() == null || this.getStatus().isOk())) {
String thisPath = this.getPath();
if (thisPath != null) {
XPath xPath = XPathFactory.newInstance().newXPath();
NamespaceContext namespaceContextThis = this.getNamespaceContext();
if (namespaceContextThis != null) {
xPath.setNamespaceContext(namespaceContextThis);
}
try {
this.xpathExpressionWrapped = xPath.compile(thisPath);
} catch (XPathExpressionException ex) {
this.status = new StdStatus(StdStatusCode.STATUS_CODE_SYNTAX_ERROR, "Error compiling XPath " + thisPath + ": " + ex.getMessage());
}
}
}
return this.xpathExpressionWrapped;
}
public void run() {
NamespaceContext ns = nsc;
if(xsw!=null) ns = xsw.getNamespaceContext();
if(xew!=null) ns = xew.getNamespaceContext();
// StAX javadoc isn't very clear on the behavior,
// so work defensively in anticipation of broken implementations.
if(ns==null)
return;
// we can't enumerate all the in-scope namespace bindings in StAX,
// so we only look for the known static namespace URIs.
// this is less than ideal, but better than nothing.
for( String nsUri : serializer.grammar.nameList.namespaceURIs ) {
String p = ns.getPrefix(nsUri);
if(p!=null)
serializer.addInscopeBinding(nsUri,p);
}
}
@Override
public void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException {
if(locator!=null)
this.locator = locator;
this.environmentNamespaceContext = nsContext;
// reset the object
result = null;
current = root;
patchersLen=0;
aborted = false;
isUnmarshalInProgress = true;
nsLen=0;
if(expectedType!=null)
root.loader = EXPECTED_TYPE_ROOT_LOADER;
else
root.loader = DEFAULT_ROOT_LOADER;
idResolver.startDocument(this);
}
@Override
public void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException {
if(locator!=null)
this.locator = locator;
this.environmentNamespaceContext = nsContext;
// reset the object
result = null;
current = root;
patchersLen=0;
aborted = false;
isUnmarshalInProgress = true;
nsLen=0;
if(expectedType!=null)
root.loader = EXPECTED_TYPE_ROOT_LOADER;
else
root.loader = DEFAULT_ROOT_LOADER;
idResolver.startDocument(this);
}
private NodeList getWSDLDefintionNode(Node bindings, Node target) {
return evaluateXPathMultiNode(bindings, target, "wsdl:definitions",
new NamespaceContext() {
@Override
public String getNamespaceURI(String prefix) {
return "http://schemas.xmlsoap.org/wsdl/";
}
@Override
public String getPrefix(String nsURI) {
throw new UnsupportedOperationException();
}
@Override
public Iterator getPrefixes(String namespaceURI) {
throw new UnsupportedOperationException();
}
});
}
public void marshal(Marshaller m, Object object, OutputStream output, NamespaceContext nsContext) throws JAXBException {
m.setProperty(Marshaller.JAXB_FRAGMENT,true);
try {
((MarshallerImpl)m).marshal(object,output,nsContext);
} finally {
m.setProperty(Marshaller.JAXB_FRAGMENT,false);
}
}
public Collection<XSComponent> select(String scd, NamespaceContext nsContext) {
try {
return SCD.create(scd,nsContext).select(this);
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
protected XPathExpression createXPathExpression(NamespaceContext context, String xPathExpr) {
XPath xpath = createXPath(context);
try {
return xpath.compile(xPathExpr);
} catch (XPathExpressionException e) {
String msg = getMessage(e);
throw new FitFailureException("Unable to compile xpath: " + xPathExpr + "\n" + msg);
}
}
/**
* Create a new {@link XPath} without any special settings using the default
* {@link XPathFactory}.
*
* @return The created non-<code>null</code> {@link XPath} object
*/
@Nonnull
public static XPath createNewXPath ()
{
return createNewXPath (s_aXPathFactory,
(XPathVariableResolver) null,
(XPathFunctionResolver) null,
(NamespaceContext) null);
}
/**
*<p>
* Note: Root namespace context works best if automatic prefix
* creation ("namespace/prefix repairing" in StAX lingo) is enabled.
*/
@Override
public void setNamespaceContext(NamespaceContext ctxt)
throws XMLStreamException
{
// This is only allowed before root element output:
if (mState != STATE_PROLOG) {
throwOutputError("Called setNamespaceContext() after having already output root element.");
}
mRootNsContext = ctxt;
mCurrElem.setRootNsContext(ctxt);
}
@Nullable
public static Boolean evalXPathToBoolean (@Nullable final XPathVariableResolver aVariableResolver,
@Nullable final XPathFunctionResolver aFunctionResolver,
@Nullable final NamespaceContext aNamespaceContext,
@Nonnull final String sXPath,
@Nonnull final Document aDoc)
{
return evalXPathToBoolean (XPathHelper.createNewXPath (aVariableResolver, aFunctionResolver, aNamespaceContext),
sXPath,
aDoc);
}
public static String _printQName(QName val, NamespaceContext nsc) {
// Double-check
String qname;
String prefix = nsc.getPrefix(val.getNamespaceURI());
String localPart = val.getLocalPart();
if (prefix == null || prefix.length() == 0) { // be defensive
qname = localPart;
} else {
qname = prefix + ':' + localPart;
}
return qname;
}
public Collection<XSComponent> select(String scd, NamespaceContext nsContext) {
try {
return SCD.create(scd,nsContext).select(this);
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
public Collection<XSComponent> select(String scd, NamespaceContext nsContext) {
try {
return SCD.create(scd,nsContext).select(this);
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
/**
* @since 2.0.2
*/
public void marshal(T object,OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
Marshaller m = context.marshallerPool.take();
m.setAttachmentMarshaller(am);
marshal(m,object,output,nsContext);
m.setAttachmentMarshaller(null);
context.marshallerPool.recycle(m);
}
/**
* Adds all defined servlet names to a set, then adds a
* {@link ServletMappingElement} to the problems list for all
* <servlet-mapping> elements whose <servlet-name> is undefined.
*/
private void validateServletMapping() {
try {
XPath xPath = FACTORY.newXPath();
NamespaceContext nsContext = new JavaContext();
xPath.setNamespaceContext(nsContext);
String selectServletNames = "//prefix:servlet/prefix:servlet-name";
NodeList servletNameNodes = (NodeList) xPath
.compile(selectServletNames)
.evaluate(document, XPathConstants.NODESET);
Set<String> servletNames = new HashSet<>();
for (int i = 0; i < servletNameNodes.getLength(); i++) {
String servletName = servletNameNodes.item(i).getTextContent();
servletNames.add(servletName);
}
String selectServletMappings = "//prefix:servlet-mapping/prefix:servlet-name";
NodeList servletMappings = (NodeList) xPath
.compile(selectServletMappings)
.evaluate(document, XPathConstants.NODESET);
for (int i = 0; i < servletMappings.getLength(); i++) {
Node servletMapping = servletMappings.item(i);
String textContent = servletMapping.getTextContent();
if (!servletNames.contains(textContent)) {
DocumentLocation location = (DocumentLocation) servletMapping.getUserData("location");
ElementProblem element =
new ServletMappingElement(textContent, location, textContent.length());
problems.add(element);
}
}
} catch (XPathExpressionException ex) {
throw new RuntimeException("Invalid XPath expression");
}
}
/**
* @since 2.0.2
*/
public void marshal(T object,OutputStream output, NamespaceContext nsContext, AttachmentMarshaller am) throws JAXBException {
Marshaller m = context.marshallerPool.take();
m.setAttachmentMarshaller(am);
marshal(m,object,output,nsContext);
m.setAttachmentMarshaller(null);
context.marshallerPool.recycle(m);
}
public XSComponent selectSingle(String scd, NamespaceContext nsContext) {
try {
return SCD.create(scd,nsContext).selectSingle(this);
} catch (ParseException e) {
throw new IllegalArgumentException(e);
}
}
@Override
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
this.eventWriter.setNamespaceContext(context);
}
protected abstract NamespaceContext getDefaultValueNamespaceContext(
API propertyInfo);
public String printQName(QName val, NamespaceContext nsc) {
return _printQName(val, nsc);
}
@Override
public final T parseValue(final NamespaceContext namespaceContext, final String str) {
return codec.deserialize(str);
}
@Override
public NamespaceContext getNamespaceContext ()
{
return writer.getNamespaceContext();
}
public NamespaceContext getNamespaceContext() {
return _reader.getNamespaceContext();
}
public NamespaceContext getNamespaceContext() {
return reader.getNamespaceContext();
}
public void startDocument(LocatorEx locator, NamespaceContext nsContext) throws SAXException {
this.nsContext = nsContext;
validator.setDocumentLocator(locator);
validator.startDocument();
next.startDocument(locator,nsContext);
}
@Override
public NamespaceContextEx getNamespaceContext() {
NamespaceContext nsContext = writer.getNamespaceContext();
return new MtomNamespaceContextEx(nsContext);
}
public DOMXPathNameConvertor(NamespaceContext nsContext){
this.nsContext = nsContext;
}
@Override
public void setNamespaceContext(NamespaceContext context) throws XMLStreamException {
delegate.setNamespaceContext(context);
}
public static XPathExpression createXPathExpression(NamespaceContext context, String xPathQuery) throws XPathExpressionException {
XPath xpath = XPathFactory.newInstance().newXPath();
xpath.setNamespaceContext(context);
return xpath.compile(xPathQuery);
}