Java XML JAXB Context getContextPath(Class... classes)

Here you can find the source of getContextPath(Class... classes)

Description

get Context Path

License

Open Source License

Declaration

public static String getContextPath(Class<?>... classes) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Main {
    public static String getContextPath(Class<?>... classes) {
        if (classes == null) {
            throw new IllegalArgumentException("The validated object is null");
        }//from   w ww.  j a v  a2s  .com
        for (int i = 0; i < classes.length; i++) {
            if (classes[i] == null) {
                throw new IllegalArgumentException("The validated array contains null element at index: " + i);
            }
        }

        final StringBuilder contextPath = new StringBuilder();

        for (int index = 0; index < classes.length; index++) {
            if (index > 0) {
                contextPath.append(':');
            }
            contextPath.append(classes[index].getPackage().getName());
        }
        return contextPath.toString();
    }

    public static String toString(JAXBContext context, Object object) throws JAXBException {
        final Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        final StringWriter sw = new StringWriter();
        marshaller.marshal(object, sw);
        return sw.toString();
    }
}

Related

  1. getContext(Class clazz)
  2. getContext(final Class theClass)
  3. getContext(String uddiVersion)
  4. getContextFor(final Class clazz)
  5. getContextForNamespace(String namespace)
  6. getCustomContext()
  7. getCustomIdentityJAXBContext()
  8. getJaxbContext(Class... classes)
  9. getJaxbContext(Class... classTypes)