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:Main.java

public static void main(String[] args) throws Exception {
    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
    XMLEventFactory eventFactory = XMLEventFactory.newInstance();
    XMLEventWriter writer = outputFactory.createXMLEventWriter(System.out);

    writer.add(eventFactory.createStartDocument("UTF-8", "1.0"));
    writer.add(eventFactory.createStartElement(new QName("p"), null, null));
    XMLEvent sampleElement = eventFactory.createStartElement("", null, "s", null, null);
    writer.add(sampleElement);//  w ww.ja v  a2s.c om
    writer.add(eventFactory.createEndElement("", null, "s"));
    writer.add(sampleElement);
    writer.add(eventFactory.createEndDocument());
    writer.flush();
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    MyMessage sarm = new MyMessage();
    MyGroupResponse[] sgr = new MyGroupResponse[2];
    sgr[0] = new MyGroupResponse();
    sgr[1] = new MyGroupResponse();
    sarm.setSailingGroup(sgr);/*from   w w  w  .  j  a  v a2 s . co  m*/

    JAXBElement<MyMessage> rootElement = new JAXBElement<MyMessage>(new QName("root"), MyMessage.class, sarm);

    JAXBContext jc = JAXBContext.newInstance(MyMessage.class, MyGroup.class, MyGroupResponse.class);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(rootElement, System.out);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Object value = "Hello World";

    JAXBContext jc = JAXBContext.newInstance(String.class, Bar.class);
    JAXBIntrospector introspector = jc.createJAXBIntrospector();
    Marshaller marshaller = jc.createMarshaller();
    if (null == introspector.getElementName(value)) {
        JAXBElement jaxbElement = new JAXBElement(new QName("ROOT"), Object.class, value);
        marshaller.marshal(jaxbElement, System.out);
    } else {/*from w ww .  j a  v a2s  .  c om*/
        marshaller.marshal(value, System.out);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jxbc = JAXBContext.newInstance(Main.class);
    Marshaller marshaller = jxbc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
    marshaller.marshal(new JAXBElement(new QName("root"), Main.class, new Main("test")), System.out);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Customer.class);

    Customer customer = new Customer();
    customer.setFirstName("Jane");
    customer.setLastName("Doe");

    PhoneNumber workPhone = new PhoneNumber();
    workPhone.setType("work");
    workPhone.setNumber("555-1111");
    customer.getPhoneNumbers().add(workPhone);

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    JAXBElement<Customer> rootElement = new JAXBElement<Customer>(new QName("customer"), Customer.class,
            customer);//w  w  w. ja v a2  s .  c om
    marshaller.marshal(rootElement, System.out);
}

From source file:org.jasig.portlet.data.Exporter.java

public static void main(String[] args) throws Exception {
    String dir = args[0];/* www.ja va 2  s .  c  o m*/
    String importExportContext = args[1];
    String sessionFactoryBeanName = args[2];
    String modelClassName = args[3];
    String serviceBeanName = args[4];
    String serviceBeanMethodName = args[5];

    ApplicationContext context = PortletApplicationContextLocator.getApplicationContext(importExportContext);
    SessionFactory sessionFactory = context.getBean(sessionFactoryBeanName, SessionFactory.class);
    Class<?> modelClass = Class.forName(modelClassName);

    Object service = context.getBean(serviceBeanName);
    Session session = sessionFactory.getCurrentSession();
    Transaction transaction = session.beginTransaction();

    JAXBContext jc = JAXBContext.newInstance(modelClass);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Method method = service.getClass().getMethod(serviceBeanMethodName);
    List<?> objects = (List<?>) method.invoke(service, null);

    for (Object o : objects) {
        session.lock(o, LockMode.NONE);
        JAXBElement je2 = new JAXBElement(new QName(modelClass.getSimpleName().toLowerCase()), modelClass, o);
        String output = dir + File.separator + UUID.randomUUID().toString() + ".xml";
        try {
            marshaller.marshal(je2, new FileOutputStream(output));
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
    transaction.commit();
}

From source file:org.jasig.portlet.announcements.Exporter.java

public static void main(String[] args) throws Exception {

    String dir = args[0];/* w w  w  . jav a  2s.c  o m*/
    ApplicationContext context = PortletApplicationContextLocator
            .getApplicationContext(PortletApplicationContextLocator.DATABASE_CONTEXT_LOCATION);
    SessionFactory sessionFactory = context.getBean(SESSION_FACTORY_BEAN_NAME, SessionFactory.class);
    IAnnouncementService announcementService = context.getBean(ANNOUNCEMENT_SVC_BEAN_NAME,
            IAnnouncementService.class);

    Session session = sessionFactory.getCurrentSession();
    Transaction transaction = session.beginTransaction();

    JAXBContext jc = JAXBContext.newInstance(Topic.class);
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    List<Topic> topics = announcementService.getAllTopics();
    for (Topic topic : topics) {
        if (topic.getSubscriptionMethod() == 4) {
            continue;
        }

        session.lock(topic, LockMode.NONE);
        JAXBElement<Topic> je2 = new JAXBElement<Topic>(new QName("topic"), Topic.class, topic);
        String output = dir + File.separator + UUID.randomUUID().toString() + ".xml";
        System.out.println("Exporting Topic " + topic.getId() + " to file " + output);
        try {
            marshaller.marshal(je2, new FileOutputStream(output));
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
    transaction.commit();
}

From source file:Main.java

public static String attribute(XMLEvent e, String name) {
    return e.asStartElement().getAttributeByName(new QName(name)).getValue();
}

From source file:Main.java

public static int getIntElement(StartElement startElement, String elementName) {
    int parent = 0;
    Attribute parentIdAttr = startElement.getAttributeByName(new QName(elementName));
    if (parentIdAttr != null) {
        parent = Integer.parseInt(parentIdAttr.getValue());
    }/*www.j  a v a 2s .  co  m*/
    return parent;
}

From source file:Main.java

public static EndElement ee(String name) {
    return eventFactory.createEndElement(new QName(name), null);
}