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:com.evolveum.midpoint.repo.sql.query2.definition.ClassDefinitionParser.java

private JpaLinkDefinition parseMethod(Method method) {
    CollectionSpecification collectionSpecification; // non-null if return type is Set<X>, null if it's X
    Type returnedContentType; // X in return type, which is either X or Set<X>
    if (Set.class.isAssignableFrom(method.getReturnType())) {
        // e.g. Set<RObject> or Set<String> or Set<REmbeddedReference<RFocus>>
        Type returnType = method.getGenericReturnType();
        if (!(returnType instanceof ParameterizedType)) {
            throw new IllegalStateException("Method " + method + " returns a non-parameterized collection");
        }/*from w  w w .  j  a  v a 2s  . c o  m*/
        returnedContentType = ((ParameterizedType) returnType).getActualTypeArguments()[0];
        collectionSpecification = new CollectionSpecification();
    } else {
        returnedContentType = method.getReturnType();
        collectionSpecification = null;
    }

    ItemPath itemPath = getJaxbName(method);
    String jpaName = getJpaName(method);
    Class jpaClass = getClass(returnedContentType);

    // sanity check
    if (Set.class.isAssignableFrom(jpaClass)) {
        throw new IllegalStateException("Collection within collection is not supported: method=" + method);
    }

    JpaLinkDefinition<? extends JpaDataNodeDefinition> linkDefinition;
    Any any = method.getAnnotation(Any.class);
    if (any != null) {
        JpaAnyContainerDefinition targetDefinition = new JpaAnyContainerDefinition(jpaClass);
        QName jaxbNameForAny = new QName(any.jaxbNameNamespace(), any.jaxbNameLocalPart());
        linkDefinition = new JpaLinkDefinition<>(jaxbNameForAny, jpaName, collectionSpecification, false,
                targetDefinition);
    } else if (ObjectReference.class.isAssignableFrom(jpaClass)) {
        boolean embedded = method.isAnnotationPresent(Embedded.class);
        // computing referenced entity type from returned content type like RObjectReference<RFocus> or REmbeddedReference<RRole>
        Class referencedJpaClass;
        if (returnedContentType instanceof ParameterizedType) {
            referencedJpaClass = getClass(
                    ((ParameterizedType) returnedContentType).getActualTypeArguments()[0]);
        } else {
            referencedJpaClass = RObject.class;
        }
        JpaReferenceDefinition targetDefinition = new JpaReferenceDefinition(jpaClass, referencedJpaClass);
        linkDefinition = new JpaLinkDefinition<>(itemPath, jpaName, collectionSpecification, embedded,
                targetDefinition);
    } else if (isEntity(jpaClass)) {
        JpaEntityDefinition content = parseClass(jpaClass);
        boolean embedded = method.isAnnotationPresent(Embedded.class)
                || jpaClass.isAnnotationPresent(Embeddable.class);
        linkDefinition = new JpaLinkDefinition<JpaDataNodeDefinition>(itemPath, jpaName,
                collectionSpecification, embedded, content);
    } else {
        boolean lob = method.isAnnotationPresent(Lob.class);
        boolean enumerated = method.isAnnotationPresent(Enumerated.class);
        //todo implement also lookup for @Table indexes
        boolean indexed = method.isAnnotationPresent(Index.class);
        Class jaxbClass = getJaxbClass(method, jpaClass);

        if (method.isAnnotationPresent(IdQueryProperty.class)) {
            if (collectionSpecification != null) {
                throw new IllegalStateException(
                        "ID property is not allowed to be multivalued; for method " + method);
            }
            itemPath = new ItemPath(new IdentifierPathSegment());
        } else if (method.isAnnotationPresent(OwnerIdGetter.class)) {
            if (collectionSpecification != null) {
                throw new IllegalStateException(
                        "Owner ID property is not allowed to be multivalued; for method " + method);
            }
            itemPath = new ItemPath(new ParentPathSegment(), new IdentifierPathSegment());
        }

        JpaPropertyDefinition propertyDefinition = new JpaPropertyDefinition(jpaClass, jaxbClass, lob,
                enumerated, indexed);
        // Note that properties are considered to be embedded
        linkDefinition = new JpaLinkDefinition<JpaDataNodeDefinition>(itemPath, jpaName,
                collectionSpecification, true, propertyDefinition);
    }
    return linkDefinition;
}

From source file:com.baidu.api.client.core.VersionService.java

public void generateHeader() {
    try {//from ww  w .  ja va  2 s .  com
        authHeader = new AuthHeader();
        authHeader.setUsername(username);
        authHeader.setPassword(password);
        authHeader.setToken(token);
        authHeader.setTarget(target);

        Header header = new Header(new QName(currentVersion.getHeaderNameSpace(), "AuthHeader"), authHeader,
                new JAXBDataBinding(AuthHeader.class));
        headers = new ArrayList<>();
        headers.add(header);
        log.info("Current user: " + username);
    } catch (JAXBException e) {
        log.fatal("Failed to genarate AuthHeader!", e);
        throw new ClientInternalException("Failed to genarate AuthHeader!");
    }
}

From source file:de.drv.dsrv.spoc.web.webservice.jax.ExtraSchemaValidationHandler.java

private boolean handleException(final SOAPBody soapBody, final String errorText,
        final ExtraErrorReasonType reason) {

    try {/*from   w  ww.jav  a 2  s . c  om*/
        // Bisherigen Inhalt des SOAP-Bodys entfernen
        soapBody.removeContents();

        // SOAP-Fault erzeugen
        final SOAPFault fault = soapBody.addFault();
        fault.setFaultString(this.soapFaultString);
        fault.setFaultCode(new QName(SOAPConstants.URI_NS_SOAP_ENVELOPE, SOAP_FAULT_CODE));

        final ExtraJaxbMarshaller extraJaxbMarshaller = new ExtraJaxbMarshaller();
        final ExtraErrorType extraError = ExtraHelper.generateError(reason, this.extraErrorCode, errorText);
        extraJaxbMarshaller.marshalExtraError(extraError, fault.addDetail());

        return false;
    } catch (final Exception e) {
        LOG.error("Fehler bei Exception-Behandlung.", e);
        throw new WebServiceException(resourceBundle.getString(Messages.ERROR_NON_EXTRA_TEXT));
    }
}

From source file:org.javelin.sws.ext.bind.jaxb.JaxbTest.java

@Test
public void marshalIllegalName() throws Exception {
    JAXBContext ctx = JAXBContext.newInstance(org.javelin.sws.ext.bind.jaxb.context1.MyClassJ1.class);
    Marshaller m = ctx.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

    // and I thought it's illegal...
    m.marshal(new JAXBElement<String>(new QName("a", "a a"), String.class, "hello"), System.out);
}

From source file:se.vgregion.portal.patientcontext.SearchControllerTest.java

@Test
public void testSearchEventSecondSearch() throws Exception {
    SearchPatientFormBean formBean = new SearchPatientFormBean();
    formBean.setSearchText("191212121212");
    PatientContext pCtx = new PatientContext();
    MockActionResponse mockRes = new MockActionResponse();
    MockPortletPreferences mockPrefs = new MockPortletPreferences();

    controller.searchEvent(formBean, pCtx, mockRes, mockPrefs);

    formBean.setSearchText("191212121213");
    controller.searchEvent(formBean, pCtx, mockRes, mockPrefs);

    PatientEvent patient = pCtx.getCurrentPatient();
    assertNotNull(patient);//w  w  w.ja va2s  .co  m
    assertEquals("191212121213", patient.getInputText());
    assertEquals(2, pCtx.getPatientHistorySize());
    assertEquals(2, pCtx.getPatientHistory().size());
    assertTrue(mockRes.getEventNames().hasNext());

    PatientEvent patientEvent = (PatientEvent) mockRes
            .getEvent(new QName("http://vgregion.se/patientcontext/events", "pctx.change"));
    assertSame(patientEvent, pCtx.getCurrentPatient());
}

From source file:com.nortal.jroad.endpoint.AbstractXTeeBaseEndpoint.java

@SuppressWarnings("unchecked")
private XTeeHeader parseXteeHeader(SOAPMessage paringMessage) throws SOAPException {
    XTeeHeader pais = new XTeeHeader();
    if (paringMessage.getSOAPHeader() == null) {
        return pais;
    }/*from ww w.  ja va2s .  c o  m*/

    SOAPHeader header = paringMessage.getSOAPHeader();
    for (Iterator<Node> headerElemendid = header.getChildElements(); headerElemendid.hasNext();) {
        Node headerElement = headerElemendid.next();
        if (!SOAPUtil.isTextNode(headerElement) && headerElement.getFirstChild() != null) {
            String localName = headerElement.getLocalName();
            String value = headerElement.getFirstChild().getNodeValue();
            pais.addElement(new QName(headerElement.getNamespaceURI(), localName), value);
        }
    }
    return pais;
}

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

@Override
public List<QName> getAllPropertyNames(Resource r) {
    BeanPropertyResource anno = getAnnotation(r);
    if (anno == null) {
        return null;
    }// w  w  w.j  a va2  s .  c om
    PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors(r);
    List<QName> list = new ArrayList<QName>();
    for (PropertyDescriptor pd : pds) {
        if (pd.getReadMethod() != null) {
            list.add(new QName(anno.value(), pd.getName()));
        }
    }
    return list;
}

From source file:com.evolveum.midpoint.schema.constants.ObjectTypes.java

public static ObjectTypes getObjectTypeFromTypeQName(QName typeQName) {
    if (typeQName == null) {
        return null;
    }/*  ww w. ja  va2  s  .  c om*/
    // HACK WARNING! FIXME
    // UGLY HORRIBLE TERRIBLE AWFUL HACK FOLLOWS
    // The JAXB fails to correctly process QNames in default namespace (no prefix)
    // e.g it will not understand this: type="RoleType", even if defatult namespace
    // is set, it will parse it as null namespace.
    // Therefore substitute null namespace with common namespace
    if (typeQName.getNamespaceURI() == null || typeQName.getNamespaceURI().isEmpty()) {
        typeQName = new QName(SchemaConstants.NS_C, typeQName.getLocalPart());
    }
    // END OF UGLY HACK

    for (ObjectTypes type : values()) {
        if (QNameUtil.match(type.getTypeQName(), typeQName)) {
            return type;
        }
    }
    throw new IllegalArgumentException("Unsupported object type qname " + typeQName);
}

From source file:com.evolveum.midpoint.prism.parser.XPathHolder.java

/**
 * Parses XPath-like expression (midPoint flavour), with regards to domNode from where the namespace declarations
 * (embedded in XML using xmlns attributes) are taken.
 *
 * @param xpath text representation of the XPath-like expression
 * @param domNode context (DOM node from which the expression was taken)
 * @param namespaceMap externally specified namespaces
 *//*from   ww  w  .  j a va2s  . c  o  m*/
private void parse(String xpath, Node domNode, Map<String, String> namespaceMap) {

    segments = new ArrayList<XPathSegment>();
    absolute = false;

    if (".".equals(xpath)) {
        return;
    }

    // Check for explicit namespace declarations.
    TrivialXPathParser parser = TrivialXPathParser.parse(xpath);
    explicitNamespaceDeclarations = parser.getNamespaceMap();

    // Continue parsing with Xpath without the "preamble"
    xpath = parser.getPureXPathString();

    String[] segArray = xpath.split("/");
    for (int i = 0; i < segArray.length; i++) {
        if (segArray[i] == null || segArray[i].isEmpty()) {
            if (i == 0) {
                absolute = true;
                // ignore the first empty segment of absolute path
                continue;
            } else {
                throw new IllegalArgumentException(
                        "XPath " + xpath + " has an empty segment (number " + i + ")");
            }
        }

        String segmentStr = segArray[i];
        XPathSegment idValueFilterSegment;

        // is ID value filter attached to this segment?
        int idValuePosition = segmentStr.indexOf('[');
        if (idValuePosition >= 0) {
            if (!segmentStr.endsWith("]")) {
                throw new IllegalArgumentException(
                        "XPath " + xpath + " has a ID segment not ending with ']': '" + segmentStr + "'");
            }
            String value = segmentStr.substring(idValuePosition + 1, segmentStr.length() - 1);
            segmentStr = segmentStr.substring(0, idValuePosition);
            idValueFilterSegment = new XPathSegment(value);
        } else {
            idValueFilterSegment = null;
        }

        // processing the rest (i.e. the first part) of the segment

        boolean variable = false;
        if (segmentStr.startsWith("$")) {
            // We have variable here
            variable = true;
            segmentStr = segmentStr.substring(1);
        }

        String[] qnameArray = segmentStr.split(":");
        if (qnameArray.length > 2) {
            throw new IllegalArgumentException(
                    "Unsupported format: more than one colon in XPath segment: " + segArray[i]);
        }
        QName qname;
        if (qnameArray.length == 1 || qnameArray[1] == null || qnameArray[1].isEmpty()) {
            // default namespace <= empty prefix
            String namespace = findNamespace(null, domNode, namespaceMap);
            qname = new QName(namespace, qnameArray[0]);
        } else {
            String namespacePrefix = qnameArray[0];
            String namespace = findNamespace(namespacePrefix, domNode, namespaceMap);
            if (namespace == null) {
                QNameUtil.reportUndeclaredNamespacePrefix(namespacePrefix, xpath);
                namespacePrefix = QNameUtil.markPrefixAsUndeclared(namespacePrefix);
            }
            qname = new QName(namespace, qnameArray[1], namespacePrefix);
        }
        segments.add(new XPathSegment(qname, variable));
        if (idValueFilterSegment != null) {
            segments.add(idValueFilterSegment);
        }
    }
}

From source file:com.hp.autonomy.frontend.reports.powerpoint.SlideShowTemplate.java

/**
 * Given an existing slide, search its relations to find a chart object.
 * @param slide a slide from the template.
 * @param error if we can't find a slide, this error message will be returned as the exception.
 * @return a pair containing the chart.xml data and the graphical object which represented it on the slide.
 * @throws TemplateLoadException if we can't find a chart object.
 *///from ww w  .  j av  a2 s .  c  o  m
private ImmutablePair<XSLFChart, CTGraphicalObjectFrame> getChart(final XSLFSlide slide, final String error)
        throws TemplateLoadException {
    for (POIXMLDocumentPart.RelationPart part : slide.getRelationParts()) {
        if (part.getDocumentPart() instanceof XSLFChart) {
            final String relId = part.getRelationship().getId();

            for (XSLFShape shape : slide.getShapes()) {
                if (shape instanceof XSLFGraphicFrame) {
                    final CTGraphicalObjectFrame frameXML = (CTGraphicalObjectFrame) shape.getXmlObject();
                    final XmlObject[] children = frameXML.getGraphic().getGraphicData()
                            .selectChildren(new QName(XSSFRelation.NS_CHART, "chart"));

                    for (final XmlObject child : children) {
                        final String imageRel = child.getDomNode().getAttributes()
                                .getNamedItemNS(RELATION_NAMESPACE, "id").getNodeValue();

                        if (relId.equals(imageRel)) {
                            return new ImmutablePair<>(part.getDocumentPart(), frameXML);
                        }
                    }
                }
            }
        }
    }

    throw new TemplateLoadException(error);
}