Example usage for javax.xml.namespace QName getLocalPart

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

Introduction

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

Prototype

public String getLocalPart() 

Source Link

Document

Get the local part of this QName.

Usage

From source file:com.evolveum.midpoint.util.DOMUtil.java

/**
 * Sets QName value for a given element.
 *
 * Contrary to standard XML semantics, namespace-less QNames are specified as simple names without prefix
 * (regardless of default prefix used in the XML document).
 *
 * @param element Element whose text content should be set to represent QName value
 * @param elementValue QName value to be stored into the element
 *///from  w ww  . j av  a2  s. c o m
public static void setQNameValue(Element element, QName elementValue) {
    if (elementValue == null) {
        setElementTextContent(element, "");
    } else if (XMLConstants.NULL_NS_URI.equals(elementValue.getNamespaceURI())) {
        if (QNameUtil.isPrefixUndeclared(elementValue.getPrefix())) {
            setElementTextContent(element, elementValue.getPrefix() + ":" + elementValue.getLocalPart());
        } else {
            setElementTextContent(element, elementValue.getLocalPart());
        }
    } else {
        String prefix = lookupOrCreateNamespaceDeclaration(element, elementValue.getNamespaceURI(),
                elementValue.getPrefix(), element, false);
        assert StringUtils.isNotBlank(prefix);
        String stringValue = prefix + ":" + elementValue.getLocalPart();
        setElementTextContent(element, stringValue);
    }
}

From source file:com.evolveum.midpoint.prism.marshaller.BeanMarshaller.java

private XNode marshalHeterogeneousList(Object bean, SerializationContext ctx) throws SchemaException {
    // structurally similar to a specific path through marshalXmlTypeToMap
    Class<?> beanClass = bean.getClass();
    QName propertyName = getHeterogeneousListPropertyName(beanClass);
    Method getter = inspector.findPropertyGetter(beanClass, propertyName.getLocalPart());
    Object getterResult = getValue(bean, getter, propertyName.getLocalPart());
    if (!(getterResult instanceof Collection)) {
        throw new IllegalStateException("Heterogeneous list property " + propertyName
                + " does not contain a collection but " + MiscUtil.getObjectName(getterResult));
    }/*  www  .  j av a2s  .co m*/
    ListXNode xlist = new ListXNode();
    for (Object value : (Collection) getterResult) {
        if (!(value instanceof JAXBElement)) {
            throw new IllegalStateException(
                    "Heterogeneous list contains a value that is not a JAXBElement: " + value);
        }
        JAXBElement jaxbElement = (JAXBElement) value;
        Object realValue = jaxbElement.getValue();
        if (realValue == null) {
            throw new IllegalStateException("Heterogeneous list contains a null value"); // TODO
        }
        QName typeName = inspector.determineTypeForClass(realValue.getClass());
        XNode marshaled = marshallValue(realValue, typeName, false, ctx);
        marshaled.setElementName(jaxbElement.getName());
        setExplicitTypeDeclarationIfNeededForHeteroList(marshaled, realValue);
        xlist.add(marshaled);
    }
    return xlist;
}

From source file:edu.brandeis.cs.planner.utils.WsdlClient.java

public Object callService(QName operationName, Object... params) throws MalformedURLException, RemoteException {
    call.setTargetEndpointAddress(new URL(conf.getSoapAddress()));
    // prepare operator & parameters.
    String soapAction = getSoapActions(operationName.getLocalPart());
    if (soapAction != null && soapAction.length() > 0)
        System.out.println("SoapAction:" + soapAction);
    call.setSOAPActionURI(soapAction);//from  ww w . ja v  a 2s .com
    // method.
    //        if (operationName.getNamespaceURI().toLowerCase().startsWith("http")) {
    //            String uri = new URL(new URL(operationName.getNamespaceURI()), operationName.getLocalPart()).toString();
    //            call.setSOAPActionURI(uri);
    //        }
    call.setOperationName(operationName);
    // parameters
    return call.invoke(params);
}

From source file:com.collabnet.ccf.pi.sfee.v44.SFEEReader.java

@Override
public boolean handleException(Throwable cause, ConnectionManager<Connection> connectionManager) {
    if (cause == null)
        return false;
    if ((cause instanceof java.net.SocketException || cause instanceof java.net.UnknownHostException)
            && connectionManager.isEnableRetryAfterNetworkTimeout()) {
        return true;
    } else if (cause instanceof ConnectionException && connectionManager.isEnableRetryAfterNetworkTimeout()) {
        return true;
    } else if (cause instanceof AxisFault) {
        QName faultCode = ((AxisFault) cause).getFaultCode();
        if (faultCode.getLocalPart().equals("InvalidSessionFault")
                && connectionManager.isEnableReloginAfterSessionTimeout()) {
            return true;
        }// w  w w.j  a v a  2 s  . c  o m
    } else if (cause instanceof RemoteException) {
        Throwable innerCause = cause.getCause();
        return handleException(innerCause, connectionManager);
    } else if (cause instanceof CCFRuntimeException) {
        Throwable innerCause = cause.getCause();
        return handleException(innerCause, connectionManager);
    }
    return false;
}

From source file:de.uzk.hki.da.cb.CreatePremisAction.java

/**
 * Accepts a premis.xml file and creates a new xml file for each jhove section  
 * /*from www  .j  a  va2s .  com*/
 * @author Thomas Kleinke
 * Extract jhove data.
 *
 * @param premisFilePath the premis file path
 * @param outputFolder the output folder
 * @throws XMLStreamException the xML stream exception
 */
public void extractJhoveData(String premisFilePath, String outputFolder) throws XMLStreamException {

    outputFolder += "/premis_output/";

    FileInputStream inputStream = null;

    try {
        inputStream = new FileInputStream(premisFilePath);
    } catch (FileNotFoundException e) {
        throw new RuntimeException("Couldn't find file " + premisFilePath, e);
    }

    XMLInputFactory inputFactory = XMLInputFactory.newInstance();
    XMLStreamReader streamReader = inputFactory.createXMLStreamReader(inputStream);

    boolean textElement = false;
    boolean jhoveSection = false;
    boolean objectIdentifierValue = false;
    int tab = 0;
    String fileId = "";

    while (streamReader.hasNext()) {
        int event = streamReader.next();

        switch (event) {

        case XMLStreamConstants.START_ELEMENT:

            if (streamReader.getLocalName().equals("jhove")) {
                jhoveSection = true;
                String outputFilePath = outputFolder + fileId.replace('/', '_').replace('.', '_') + ".xml";
                if (!new File(outputFolder).exists())
                    new File(outputFolder).mkdirs();
                writer = startNewDocument(outputFilePath);
            }

            if (streamReader.getLocalName().equals("objectIdentifierValue"))
                objectIdentifierValue = true;

            if (jhoveSection) {
                writer.writeDTD("\n");
                indent(tab);
                tab++;

                String prefix = streamReader.getPrefix();

                if (prefix != null && !prefix.equals("")) {
                    writer.setPrefix(prefix, streamReader.getNamespaceURI());
                    writer.writeStartElement(streamReader.getNamespaceURI(), streamReader.getLocalName());
                } else
                    writer.writeStartElement(streamReader.getLocalName());

                for (int i = 0; i < streamReader.getNamespaceCount(); i++)
                    writer.writeNamespace(streamReader.getNamespacePrefix(i), streamReader.getNamespaceURI(i));

                for (int i = 0; i < streamReader.getAttributeCount(); i++) {
                    QName qname = streamReader.getAttributeName(i);
                    String attributeName = qname.getLocalPart();
                    String attributePrefix = qname.getPrefix();
                    if (attributePrefix != null && !attributePrefix.equals(""))
                        attributeName = attributePrefix + ":" + attributeName;

                    writer.writeAttribute(attributeName, streamReader.getAttributeValue(i));
                }
            }

            break;

        case XMLStreamConstants.CHARACTERS:
            if (objectIdentifierValue) {
                fileId = streamReader.getText();
                objectIdentifierValue = false;
            }

            if (jhoveSection && !streamReader.isWhiteSpace()) {
                writer.writeCharacters(streamReader.getText());
                textElement = true;
            }
            break;

        case XMLStreamConstants.END_ELEMENT:
            if (jhoveSection) {
                tab--;

                if (!textElement) {
                    writer.writeDTD("\n");
                    indent(tab);
                }

                writer.writeEndElement();
                textElement = false;

                if (streamReader.getLocalName().equals("jhove")) {
                    jhoveSection = false;
                    finalizeDocument();
                }
            }
            break;

        case XMLStreamConstants.END_DOCUMENT:
            streamReader.close();
            try {
                inputStream.close();
            } catch (IOException e) {
                throw new RuntimeException("Failed to close input stream", e);
            }
            break;

        default:
            break;
        }
    }
}

From source file:com.bradmcevoy.property.BeanPropertySource.java

@Override
public PropertyMetaData getPropertyMetaData(QName name, Resource r) {
    log.debug("getPropertyMetaData");
    BeanPropertyResource anno = getAnnotation(r);
    if (anno == null) {
        log.debug(" no annotation: ", r.getClass().getCanonicalName());
        return PropertyMetaData.UNKNOWN;
    }//w  ww.  ja  v  a  2s  . c om
    if (!name.getNamespaceURI().equals(anno.value())) {
        log.debug("different namespace", anno.value(), name.getNamespaceURI());
        return PropertyMetaData.UNKNOWN;
    }

    PropertyDescriptor pd = getPropertyDescriptor(r, name.getLocalPart());
    if (pd == null || pd.getReadMethod() == null) {
        LogUtils.debug(log, "getPropertyMetaData: no read method:", name.getLocalPart(), r.getClass());
        return PropertyMetaData.UNKNOWN;
    } else {
        BeanPropertyAccess propAnno = pd.getReadMethod().getAnnotation(BeanPropertyAccess.class);
        if (propAnno != null) {
            if (!propAnno.value()) {
                log.trace(
                        "getPropertyMetaData: property is annotated and value is false, so do not allow access");
                return PropertyMetaData.UNKNOWN;
            } else {
                log.trace("getPropertyMetaData: property is annotated and value is true, so allow access");
            }
        } else {
            if (anno.enableByDefault()) {
                log.trace(
                        "getPropertyMetaData: no property annotation, property annotation is enable by default so allow access");
            } else {
                log.trace(
                        "getPropertyMetaData:no property annotation, class annotation says disable by default, decline access");
                return PropertyMetaData.UNKNOWN;
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("writable: " + anno.writable() + " - " + (pd.getWriteMethod() != null));
        }
        boolean writable = anno.writable() && (pd.getWriteMethod() != null);
        if (writable) {
            return new PropertyMetaData(PropertyAccessibility.WRITABLE, pd.getPropertyType());
        } else {
            return new PropertyMetaData(PropertyAccessibility.READ_ONLY, pd.getPropertyType());
        }
    }
}

From source file:io.milton.property.BeanPropertySource.java

@Override
public PropertyMetaData getPropertyMetaData(QName name, Resource r) {
    log.debug("getPropertyMetaData");
    BeanPropertyResource anno = getAnnotation(r);
    if (anno == null) {
        log.debug(" no annotation: ", r.getClass().getCanonicalName());
        return PropertyMetaData.UNKNOWN;
    }//w  ww.  ja  va 2  s.  c  o m
    if (!name.getNamespaceURI().equals(anno.value())) {
        log.debug("different namespace", anno.value(), name.getNamespaceURI());
        return PropertyMetaData.UNKNOWN;
    }

    PropertyDescriptor pd = getPropertyDescriptor(r, name.getLocalPart());
    if (pd == null || pd.getReadMethod() == null) {
        LogUtils.debug(log, "getPropertyMetaData: no read method:", name.getLocalPart(), r.getClass());
        return PropertyMetaData.UNKNOWN;
    } else {
        BeanProperty propAnno = pd.getReadMethod().getAnnotation(BeanProperty.class);
        if (propAnno != null) {
            if (!propAnno.value()) {
                log.trace(
                        "getPropertyMetaData: property is annotated and value is false, so do not allow access");
                return PropertyMetaData.UNKNOWN;
            } else {
                log.trace("getPropertyMetaData: property is annotated and value is true, so allow access");
            }
        } else {
            if (anno.enableByDefault()) {
                log.trace(
                        "getPropertyMetaData: no property annotation, property annotation is enable by default so allow access");
            } else {
                log.trace(
                        "getPropertyMetaData:no property annotation, class annotation says disable by default, decline access");
                return PropertyMetaData.UNKNOWN;
            }
        }
        if (log.isDebugEnabled()) {
            log.debug("writable: " + anno.writable() + " - " + (pd.getWriteMethod() != null));
        }
        boolean writable = anno.writable() && (pd.getWriteMethod() != null);
        if (writable) {
            return new PropertyMetaData(PropertyAccessibility.WRITABLE, pd.getPropertyType());
        } else {
            return new PropertyMetaData(PropertyAccessibility.READ_ONLY, pd.getPropertyType());
        }
    }
}

From source file:com.legstar.proxy.invoke.jaxws.WebServiceInvoker.java

/**
 * Try to extract something meaningful from a SOAP Fault.
 * // www .  ja  v  a 2s  .com
 * @param e the SOAP Fault exception
 * @return a fault description
 */
@SuppressWarnings("rawtypes")
public String getFaultReasonText(final SOAPFaultException e) {
    if (_log.isDebugEnabled()) {
        SOAPFault fault = e.getFault();
        if (fault != null) {
            QName code = fault.getFaultCodeAsQName();
            String string = fault.getFaultString();
            String actor = fault.getFaultActor();
            _log.debug("SOAP fault contains: ");
            _log.debug("  Fault code = " + code.toString());
            _log.debug("  Local name = " + code.getLocalPart());
            _log.debug("  Namespace prefix = " + code.getPrefix() + ", bound to " + code.getNamespaceURI());
            _log.debug("  Fault string = " + string);
            if (actor != null) {
                _log.debug("  Fault actor = " + actor);
            }
            Detail detail = fault.getDetail();
            if (detail != null) {
                Iterator entries = detail.getDetailEntries();
                while (entries.hasNext()) {
                    DetailEntry newEntry = (DetailEntry) entries.next();
                    String value = newEntry.getValue();
                    _log.debug("  Detail entry = " + value);
                }
            }
        } else {
            _log.debug(e);
        }
    }
    SOAPFault fault = e.getFault();
    if (fault != null) {
        StringBuffer faultMessage = new StringBuffer(e.getFault().getFaultString());
        Detail detail = fault.getDetail();
        if (detail != null) {
            Iterator entries = detail.getDetailEntries();
            while (entries.hasNext()) {
                DetailEntry newEntry = (DetailEntry) entries.next();
                faultMessage.append(" [" + newEntry.getValue() + "]");
            }
        }
        return faultMessage.toString();
    } else {
        return e.getMessage();
    }

}

From source file:com.evolveum.midpoint.prism.marshaller.ItemPathHolder.java

public Element toElement(QName elementQName, Document document) {
    return toElement(elementQName.getNamespaceURI(), elementQName.getLocalPart(), document);
}

From source file:com.evolveum.midpoint.web.component.wizard.resource.component.schemahandling.ResourceAttributeEditor.java

private String prepareReferenceDisplayValue(ItemPathType object) {
    if (object == null || object.getItemPath() == null) {
        return "";
    }//from  ww  w  .j  a  v  a  2 s  .c om

    ItemPath path = object.getItemPath();
    if (path.getSegments().size() != 1) {
        return path.toString();
    }

    QName name = ItemPathUtil.getOnlySegmentQName(path);

    StringBuilder sb = new StringBuilder();
    String prefix = SchemaConstants.NS_ICF_SCHEMA.equals(name.getNamespaceURI()) ? "icfs" : "ri";
    sb.append(prefix);
    sb.append(": ");
    sb.append(name.getLocalPart());

    return sb.toString();
}