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(String localPart) 

Source Link

Document

QName constructor specifying the local part.

If the local part is null an IllegalArgumentException is thrown.

Usage

From source file:cn.hxh.springside.mapper.JaxbMapper.java

/**
 * Java Object->Xml with encoding, ?Root ElementCollection.
 *//*  ww w  .  ja v a  2s .  co  m*/
public String toXml(Collection<?> root, String rootName, String encoding) {
    try {
        CollectionWrapper wrapper = new CollectionWrapper();
        wrapper.collection = root;

        JAXBElement<CollectionWrapper> wrapperElement = new JAXBElement<CollectionWrapper>(new QName(rootName),
                CollectionWrapper.class, wrapper);

        StringWriter writer = new StringWriter();
        createMarshaller(encoding).marshal(wrapperElement, writer);

        return writer.toString();
    } catch (JAXBException e) {
        throw ExceptionUtils.unchecked(e);
    }
}

From source file:com.hp.application.automation.tools.octane.tests.TestResultIterator.java

@Override
public boolean hasNext() {
    try {/*from   www  . j a  va2 s.c  om*/
        while (items.isEmpty() && !closed) {
            if (reader.hasNext()) {
                XMLEvent event = reader.nextEvent();
                if (event instanceof StartElement) {
                    StartElement element = (StartElement) event;
                    String localName = element.getName().getLocalPart();
                    if ("test_run".equals(localName)) {
                        String moduleName = element.getAttributeByName(new QName("module")).getValue();
                        String packageName = element.getAttributeByName(new QName("package")).getValue();
                        String className = element.getAttributeByName(new QName("class")).getValue();
                        String testName = element.getAttributeByName(new QName("name")).getValue();
                        long duration = Long
                                .valueOf(element.getAttributeByName(new QName("duration")).getValue());
                        TestResultStatus status = TestResultStatus
                                .fromPrettyName(element.getAttributeByName(new QName("status")).getValue());
                        long started = Long
                                .valueOf(element.getAttributeByName(new QName("started")).getValue());
                        items.add(new JUnitTestResult(moduleName, packageName, className, testName, status,
                                duration, started, null, null));
                    } else if ("build".equals(localName)) {
                        serverId = element.getAttributeByName(new QName("server_id")).getValue();
                        jobId = element.getAttributeByName(new QName("job_id")).getValue();
                        buildId = element.getAttributeByName(new QName("build_id")).getValue();
                        Attribute subType = element.getAttributeByName(new QName("sub_type"));
                        if (subType != null) {
                            this.subType = subType.getValue();
                        }
                    }
                }
            } else {
                closed = true;
                IOUtils.closeQuietly(input);
                reader.close();
            }
        }
        return !items.isEmpty();
    } catch (XMLStreamException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.hp.application.automation.tools.octane.tests.detection.ResultFieldsXmlReader.java

public TestResultContainer readXml() {
    boolean fieldsElement = false;
    try {/*from ww w .  j a  v a  2s . c o m*/
        while (eventReader.hasNext()) {
            XMLEvent event = eventReader.nextEvent();
            if (event instanceof StartElement) {
                StartElement element = (StartElement) event;
                String localName = element.getName().getLocalPart();
                if ("test_fields".equals(localName)) {
                    fieldsElement = true;
                }
                if ("test_field".equals(localName)) {
                    if (!fieldsElement) {
                        Assert.fail(
                                "<test_field> element found, but surrounding element '<test_fields>' is missing in the XML file");
                    }
                    String type = element.getAttributeByName(new QName("type")).getValue();
                    String value = element.getAttributeByName(new QName("value")).getValue();
                    if (type.equals("Framework")) {
                        resultFields.setFramework(value);
                    } else if (type.equals("Testing_Tool_Type")) {
                        resultFields.setTestingTool(value);
                    } else if (type.equals("Test_Level")) {
                        resultFields.setTestLevel(value);
                    }
                }
                if ("test_run".equals(localName)) {
                    String moduleName = element.getAttributeByName(new QName("module")).getValue();
                    String packageName = element.getAttributeByName(new QName("package")).getValue();
                    String className = element.getAttributeByName(new QName("class")).getValue();
                    String testName = element.getAttributeByName(new QName("name")).getValue();
                    testAttributes.add(new TestAttributes(moduleName, packageName, className, testName));
                }
            }
        }
        IOUtils.closeQuietly(input);
        eventReader.close();
    } catch (XMLStreamException e) {
        throw new RuntimeException(e);
    }
    return new TestResultContainer(testAttributes, resultFields);
}

From source file:org.apache.servicemix.jms.JmsProviderEndpointTest.java

public void testSendWithoutProperties() throws Exception {
    container.activateComponent(createEndpoint(false), "servicemix-jms");

    InOnly me = client.createInOnlyExchange();
    NormalizedMessage inMessage = me.getInMessage();
    inMessage.setProperty(MSG_PROPERTY, "Test-Value");
    inMessage.setProperty(MSG_PROPERTY_BLACKLISTED, "Unwanted value");
    inMessage.setContent(new StringSource("<hello>world</hello>"));
    me.setService(new QName("jms"));
    client.sendSync(me);//from   www. ja  v a 2  s.c o  m
    assertEquals(ExchangeStatus.DONE, me.getStatus());

    Message msg = jmsTemplate.receive("destination");
    assertNull("Found not expected property", msg.getStringProperty(MSG_PROPERTY));
    assertNull("Found blacklisted property", msg.getStringProperty(MSG_PROPERTY_BLACKLISTED));
    assertNotNull(msg);
}

From source file:net.gfipm.shibboleth.config.GfipmTestDataConnectorParser.java

/** {@inheritDoc} */
@Override//from   w  ww.  j  a  v a 2s.  c  o  m
protected void doV2Parse(@Nonnull final Element config, @Nonnull final ParserContext parserContext,
        @Nonnull final BeanDefinitionBuilder builder) {
    //super.doParse(config, parserContext, builder);
    log.debug("doV2Parse {}", config);

    final String userPath = AttributeSupport.getAttributeValue(config, new QName("pathToAttributeFiles"));
    final String uidAttr = AttributeSupport.getAttributeValue(config, new QName("uidAttribute"));

    log.debug("Parsing configuration Path {}, Attribute {}", userPath, uidAttr);

    builder.addPropertyValue("pathToAttributeFiles", userPath);
    builder.addPropertyValue("uidAttribute", uidAttr);
}

From source file:org.kuali.student.common.test.resourceloader.FakeEnvResourceLoader.java

public void init() {
    Config config = new JAXBConfigImpl();
    config.putProperty(CoreConstants.Config.APPLICATION_ID, MOCK_APP_ID);
    ConfigContext.init(config);/*from w  w  w.j  a v  a 2 s  .c om*/
    SimpleServiceLocator serviceLocator = new SimpleServiceLocator();

    ConfigurationService configurationService = new ConfigurationService() {
        public String getPropertyValueAsString(String key) {
            return "{0} message";
        }

        public boolean getPropertyValueAsBoolean(String key) {
            return false;
        }

        public Map<String, String> getAllProperties() {
            return null;
        }
    };

    serviceLocator.addService(new QName(KRADServiceLocator.KUALI_CONFIGURATION_SERVICE), configurationService);

    ResourceLoader resourceLoader = new BaseResourceLoader(
            new QName(MOCK_APP_ID, RiceConstants.DEFAULT_ROOT_RESOURCE_LOADER_NAME), serviceLocator);

    try {
        GlobalResourceLoader.stop();
        GlobalResourceLoader.addResourceLoader(resourceLoader);
        GlobalResourceLoader.start();
    } catch (Exception e) {
        throw new RuntimeException("Error initializing GRL", e);
    }
}

From source file:info.rsdev.xb4j.model.bindings.SimpleFileTypeTest.java

@Before
public void setUp() throws Exception {
    this.model = new BindingModel();
    Root root = new Root(new QName("Root"), ObjectF.class);
    SimpleFileType fileType = root.setChild(new SimpleFileType(new QName("File")), "file");
    fileType.addAttribute(new Attribute(new QName("Encoding")), "xmlEncoding");
    fileType.addAttribute(new StaticAttribute(new QName("Name"), "temp.zip"), NoGetter.INSTANCE,
            NoSetter.INSTANCE);/*w  ww. ja  va2 s  .c o m*/
    fileType.addAttribute(new StaticAttribute(new QName("MimeType"), "application/octet-stream"),
            NoGetter.INSTANCE, NoSetter.INSTANCE);
    this.model.register(root);
}

From source file:com.evolveum.midpoint.schema.parser.TestParseScriptOutput.java

@Test
public void testParseRoundTrip() throws Exception {
    displayTestTitle("testParseRoundTrip");

    processParsings(v -> getPrismContext().serializerFor(language).serialize(v), "s0");
    processParsings(v -> getPrismContext().serializerFor(language).root(new QName("dummy")).serialize(v), "s1");
    processParsings(//  ww w .j a v a 2 s .  c om
            v -> getPrismContext().serializerFor(language).root(SchemaConstantsGenerated.C_USER).serialize(v),
            "s2"); // misleading item name
    processParsings(v -> getPrismContext().serializerFor(language).serializeRealValue(v.getValue()), "s3");
    processParsings(v -> getPrismContext().serializerFor(language).root(new QName("dummy"))
            .serializeAnyData(v.getValue()), "s4");
}

From source file:org.fcrepo.oai.AbstractOAIProviderIT.java

@PostConstruct
public void initTests() throws Exception {
    /* Check and/or add the default Identify response */
    if (!defaultIdentityResponseExists()) {
        IdentifyType id = oaiFactory.createIdentifyType();
        id.setRepositoryName("Fedora 4 Test Instance");
        id.setBaseURL(serverAddress);/*  ww  w. j  av a  2  s  .c o m*/

        HttpPost post = new HttpPost(serverAddress + "/oai/identify/fcr:content");
        StringWriter data = new StringWriter();
        marshaller.marshal(new JAXBElement<IdentifyType>(new QName("Identify"), IdentifyType.class, id), data);
        post.setEntity(new StringEntity(data.toString()));
        try {
            HttpResponse resp = this.client.execute(post);
            assertEquals(201, resp.getStatusLine().getStatusCode());
        } finally {
            post.releaseConnection();
        }
    }
}

From source file:de.tudarmstadt.ukp.integration.alignment.xml.AlignmentXmlWriter.java

public void writeMetaData(XmlMeta meta) throws IOException {
    try {/*ww  w  . j  a  v a  2 s .  co m*/
        marshaller.marshal(new JAXBElement<XmlMeta>(new QName("metadata"), XmlMeta.class, meta),
                xmlEventWriter);
    } catch (JAXBException e) {
        throw new IOException(e);
    }

}