516 // anyType
517 JaxBeanInfo bi = beanInfoMap.get(Object.class);
518 if(bi==null) {
519 bi = new AnyTypeBeanInfo(this,e);
520 beanInfoMap.put(Object.class,bi);
521 }
522 return bi;
523 }
524
525 throw new IllegalArgumentException();
526 }
527
528 /**
529 * Gets the {@link JaxBeanInfo} object that can handle
530 * the given JAXB-bound object.
531 *
532 * <p>
533 * This method traverses the base classes of the given object.
534 *
535 * @return null
536 * if <tt>c</tt> isn't a JAXB-bound class and <tt>fatal==false</tt>.
537 */
538 public final JaxBeanInfo getBeanInfo(Object o) {
539 // don't allow xs:anyType beanInfo to handle all the unbound objects
540 for( Class c=o.getClass(); c!=Object.class; c=c.getSuperclass()) {
541 JaxBeanInfo bi = beanInfoMap.get(c);
542 if(bi!=null) return bi;
543 }
544 if(o instanceof Element)
545 return beanInfoMap.get(Object.class); // return the BeanInfo for xs:anyType
546 for( Class c : o.getClass().getInterfaces()) {
547 JaxBeanInfo bi = beanInfoMap.get(c);
548 if(bi!=null) return bi;
549 }
550 return null;
551 }
552
553 /**
554 * Gets the {@link JaxBeanInfo} object that can handle
555 * the given JAXB-bound object.
556 *
560 */
561 public final JaxBeanInfo getBeanInfo(Object o,boolean fatal) throws JAXBException {
562 JaxBeanInfo bi = getBeanInfo(o);
563 if(bi!=null) return bi;
564 if(fatal) {
565 if(o instanceof Document)
566 throw new JAXBException(Messages.ELEMENT_NEEDED_BUT_FOUND_DOCUMENT.format(o.getClass()));
567 throw new JAXBException(Messages.UNKNOWN_CLASS.format(o.getClass()));
568 }
569 return null;
570 }
571
572 /**
573 * Gets the {@link JaxBeanInfo} object that can handle
574 * the given JAXB-bound class.
575 *
576 * <p>
577 * This method doesn't look for base classes.
578 *
579 * @return null
580 * if <tt>c</tt> isn't a JAXB-bound class and <tt>fatal==false</tt>.
581 */
582 public final <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz) {
583 return (JaxBeanInfo<T>)beanInfoMap.get(clazz);
584 }
585
586 /**
587 * Gets the {@link JaxBeanInfo} object that can handle
588 * the given JAXB-bound class.
589 *
590 * @param fatal
591 * if true, the failure to look up will throw an exception.
592 * Otherwise it will just return null.
593 */
594 public final <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz,boolean fatal) throws JAXBException {
595 JaxBeanInfo<T> bi = getBeanInfo(clazz);
596 if(bi!=null) return bi;
597 if(fatal)
598 throw new JAXBException(clazz.getName()+" is not known to this context");
599 return null;
600 }
|
516 // anyType
517 JaxBeanInfo bi = beanInfoMap.get(Object.class);
518 if(bi==null) {
519 bi = new AnyTypeBeanInfo(this,e);
520 beanInfoMap.put(Object.class,bi);
521 }
522 return bi;
523 }
524
525 throw new IllegalArgumentException();
526 }
527
528 /**
529 * Gets the {@link JaxBeanInfo} object that can handle
530 * the given JAXB-bound object.
531 *
532 * <p>
533 * This method traverses the base classes of the given object.
534 *
535 * @return null
536 * if {@code c} isn't a JAXB-bound class and {@code fatal==false}.
537 */
538 public final JaxBeanInfo getBeanInfo(Object o) {
539 // don't allow xs:anyType beanInfo to handle all the unbound objects
540 for( Class c=o.getClass(); c!=Object.class; c=c.getSuperclass()) {
541 JaxBeanInfo bi = beanInfoMap.get(c);
542 if(bi!=null) return bi;
543 }
544 if(o instanceof Element)
545 return beanInfoMap.get(Object.class); // return the BeanInfo for xs:anyType
546 for( Class c : o.getClass().getInterfaces()) {
547 JaxBeanInfo bi = beanInfoMap.get(c);
548 if(bi!=null) return bi;
549 }
550 return null;
551 }
552
553 /**
554 * Gets the {@link JaxBeanInfo} object that can handle
555 * the given JAXB-bound object.
556 *
560 */
561 public final JaxBeanInfo getBeanInfo(Object o,boolean fatal) throws JAXBException {
562 JaxBeanInfo bi = getBeanInfo(o);
563 if(bi!=null) return bi;
564 if(fatal) {
565 if(o instanceof Document)
566 throw new JAXBException(Messages.ELEMENT_NEEDED_BUT_FOUND_DOCUMENT.format(o.getClass()));
567 throw new JAXBException(Messages.UNKNOWN_CLASS.format(o.getClass()));
568 }
569 return null;
570 }
571
572 /**
573 * Gets the {@link JaxBeanInfo} object that can handle
574 * the given JAXB-bound class.
575 *
576 * <p>
577 * This method doesn't look for base classes.
578 *
579 * @return null
580 * if {@code c} isn't a JAXB-bound class and {@code fatal==false}.
581 */
582 public final <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz) {
583 return (JaxBeanInfo<T>)beanInfoMap.get(clazz);
584 }
585
586 /**
587 * Gets the {@link JaxBeanInfo} object that can handle
588 * the given JAXB-bound class.
589 *
590 * @param fatal
591 * if true, the failure to look up will throw an exception.
592 * Otherwise it will just return null.
593 */
594 public final <T> JaxBeanInfo<T> getBeanInfo(Class<T> clazz,boolean fatal) throws JAXBException {
595 JaxBeanInfo<T> bi = getBeanInfo(clazz);
596 if(bi!=null) return bi;
597 if(fatal)
598 throw new JAXBException(clazz.getName()+" is not known to this context");
599 return null;
600 }
|