Java XML JAXB Context isElement(String contextPath, Object object)

Here you can find the source of isElement(String contextPath, Object object)

Description

is Element

License

Open Source License

Declaration

public static boolean isElement(String contextPath, Object object) 

Method Source Code

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

import java.util.HashMap;
import java.util.Map;
import javax.xml.bind.JAXBContext;

import javax.xml.bind.JAXBException;

public class Main {
    private static Map<String, JAXBContext> contextCache = new HashMap<String, JAXBContext>();

    public static boolean isElement(String contextPath, Object object) {
        try {/*from w  ww .  j a  v a 2s  . c  o  m*/
            return object != null && getJAXBContext(contextPath).createJAXBIntrospector().isElement(object);
        } catch (JAXBException ex) {
            throw new RuntimeException(ex);
        }
    }

    public static JAXBContext getJAXBContext(String contextPath) throws JAXBException {
        if (contextCache.containsKey(contextPath)) {
            return contextCache.get(contextPath);
        } else {
            final JAXBContext context = JAXBContext.newInstance(contextPath);
            contextCache.put(contextPath, context);
            return context;
        }
    }
}

Related

  1. getJAXBContext(String namespaces)
  2. getJAXBContext(String packagePrefix)
  3. getJAXBContextForWebService(Class webService)
  4. getRequestContext()
  5. getRightsContext()
  6. parseXMLFile(String fileName, String contextPath)
  7. toString(JAXBContext context, Object object)
  8. toXML(JAXBContext context, T obj)