Package javax.xml.bind.annotation

Examples of javax.xml.bind.annotation.XmlElements


                             && value instanceof Collection){
                           // XML choice list
                             /*
                                *  Step 5.10.2.4.4.1: Is it XML choice list?. If assign find right element name.
                                */
                           XmlElements xmlElms =  declaredField.getAnnotation(XmlElements.class);
                           Collection<?> valueList = (Collection<?>)value;
                           if(!valueList.isEmpty()){
                             // use first object to identify type
                             ArrayList<Map<String,Object>> group = new ArrayList<Map<String,Object>>();
                             for(Object ob : valueList){
                               for(XmlElement elm : xmlElms.value()){
                                 // TODO JAXBElement
                                 if(((Class<?>)elm.type()).isAssignableFrom(ob.getClass())){
                                   Map<String,Object> objectMap = new HashMap<String, Object>();
                                   objectMap.put(elm.name(), ob);
                                   group.add(objectMap);
                                   break;// XmlElement list break
                                 }
                               }
                             }
                             hasData = this.add(name, group, null, hasData, property) || hasData;
                             continue nextProperty;
                           } else {
                             // If choice element id empty, don't print it at all
                             if(!this.metaDataMode){
                               continue nextProperty;
                             } else {
                               name  = "CHOICE";
                               Map<String,Object> choices     = new HashMap<String, Object>();
                               for(XmlElement elm : xmlElms.value()){
                                 try{
                                   choices.put(elm.name(), getMetaDataInstance(elm.type(),null,null));
                                 }catch(Throwable th){
                                   //
                                   choices.put(elm.name(),"object");
                                 }
                               }
                               value = choices;
                             }
                           }
                         }else if(declaredField.isAnnotationPresent(XmlElementRefs.class)
                             && Collection.class.isAssignableFrom(declaredField.getType())
                             && value instanceof Collection){
                           // XML choice list
                             /*
                                *  Step 5.10.2.4.4.1: Is it XML choice list?. If assign find right element name.
                                */
                           XmlElementRefs xmlElms =  declaredField.getAnnotation(XmlElementRefs.class);
                           Collection<?> valueList = (Collection<?>)value;
                           if(!valueList.isEmpty()){
                             // use first object to identify type
                             Map<String,List<Object>> group = new HashMap<String,List<Object>>();
                             for(Object ob : valueList){
                               for(XmlElementRef elm : xmlElms.value()) {
                                 if(ob instanceof JAXBElement<?>) {
                                   JAXBElement<?> element = (JAXBElement<?>)ob;
                                   if(element.getName().getLocalPart().equals(elm.name())){// namespace too
                                     name = elm.name();
                                     if(!group.containsKey(name))
                                       group.put(name, new ArrayList<Object>());
                                     group.get(name).add(element.getValue());
                                     break;// Break element list
                                   }
                                 } else {
                                   if(((Class<?>)elm.type()).isAssignableFrom(ob.getClass())){
                                     name = elm.name();
                                     if(!group.containsKey(name))
                                       group.put(name, new ArrayList<Object>());
                                     group.get(name).add(ob);
                                     break;// Break element list
                                   }
                                 }
                               }
                             }
                             for(Map.Entry<String, List<Object>> entry : group.entrySet()){
                               hasData = this.add(entry.getKey(), entry.getValue(), null, hasData, property) || hasData;
                                       // TODO this.setExprStack(expr);
                             }
                             continue nextProperty;
                           } else {
                             // If choice element id empty, don't print it at all
                             if(!this.metaDataMode){
                               continue nextProperty;
                             } else {
                               name  = "CHOICE";
                               Map<String,Object> choices     = new HashMap<String, Object>();
                               for(XmlElementRef elm : xmlElms.value()){
                                 try{
                                   choices.put(elm.name(), getMetaDataInstance(elm.type(),null,null));
                                 }catch(Throwable th){
                                   //
                                   choices.put(elm.name(),"object");
View Full Code Here


    super(context, accessor);
   
    if (accessor.getAnnotation(XmlList.class) != null)
      throw new JAXBException(L.l("@XmlList cannot be used with @XmlElements"));

    XmlElements elements = accessor.getAnnotation(XmlElements.class);

    if (elements.value().length == 0) {
      // XXX special case : equivalent to unannotated
    }

    if (elements.value().length == 1) {
      // XXX special case : equivalent to @XmlElement
    }

    _qnameMap = new LinkedHashMap<Class,QName>();
    Map<QName,Property> qnameToPropertyMap =
      new LinkedHashMap<QName,Property>();
    Map<Class,Property> classToPropertyMap =
      new LinkedHashMap<Class,Property>();

    for (XmlElement element : elements.value()) {
      if (XmlElement.DEFAULT.class.equals(element.type()))
        throw new JAXBException(L.l("@XmlElement annotations in @XmlElements must specify a type"));

      QName qname = qnameFromXmlElement(element);
      Property property = _context.createProperty(element.type());
View Full Code Here

    else
      multiProperty = (MultiProperty) _property;

    Collection<Property> properties = multiProperty.getProperties();

    XmlElements xmlElements = _accessor.getAnnotation(XmlElements.class);
    XmlElement[] elements = xmlElements.value();

    int i = 0;

    for (Property property : properties) {
      out.writeEmptyElement(XML_SCHEMA_PREFIX, "element",
View Full Code Here

      accessor.getAnnotation(XmlAttribute.class);
    XmlElement xmlElement =
      accessor.getAnnotation(XmlElement.class);
    XmlElementRef xmlElementRef =
      accessor.getAnnotation(XmlElementRef.class);
    XmlElements xmlElements =
      accessor.getAnnotation(XmlElements.class);
    XmlID xmlID =
      accessor.getAnnotation(XmlID.class);
    XmlIDREF xmlIDREF =
      accessor.getAnnotation(XmlIDREF.class);
View Full Code Here

     * If you think this test is a mistake: beware, this test is smarter than you.
     */
    @Test
    public void acceptedCommandsCanBeSerializedTest() throws Exception {
        Field commandsField = JaxbCommandsRequest.class.getDeclaredField("commands");
        XmlElements xmlElemsAnno = (XmlElements) commandsField.getAnnotations()[0];
        XmlElement[] xmlElems = xmlElemsAnno.value();

        Set<Class> cmdSet = getAcceptedCommandClassSet();
        assertEquals(AcceptedServerCommands.class.getSimpleName() + " contains a different set of Commands than "
                + JaxbCommandsRequest.class.getSimpleName(), cmdSet.size(), xmlElems.length);
        Set<String> xmlElemNameSet = new HashSet<String>();
View Full Code Here

    }
    @Test
    public void allCommandResponseTypesNeedXmlElemIdTest() throws Exception {
        Field commandsField = JaxbCommandsResponse.class.getDeclaredField("responses");
        XmlElements xmlElemsAnno = (XmlElements) commandsField.getAnnotations()[0];
        XmlElement[] xmlElems = xmlElemsAnno.value();

        Set<Class<?>> cmdSet = new HashSet<Class<?>>();
        {
            Set<Class<? extends JaxbCommandResponse>> subTypes = reflections.getSubTypesOf(JaxbCommandResponse.class);
            cmdSet.addAll(subTypes);
View Full Code Here

        XmlTransient t = null;
        XmlAnyAttribute aa = null;
        XmlAttribute a = null;
        XmlValue v = null;
        XmlElement e1 = null;
        XmlElements e2 = null;
        XmlElementRef r1 = null;
        XmlElementRefs r2 = null;
        XmlAnyElement xae = null;
        XmlMixed mx = null;
View Full Code Here

        if(types==null) {
            types = new FinalArrayList<TypeRefImpl<TypeT,ClassDeclT>>();
            XmlElement[] ann=null;

            XmlElement xe = seed.readAnnotation(XmlElement.class);
            XmlElements xes = seed.readAnnotation(XmlElements.class);

            if(xe!=null && xes!=null) {
                parent.builder.reportError(new IllegalAnnotationException(
                        Messages.MUTUALLY_EXCLUSIVE_ANNOTATIONS.format(
                                nav().getClassName(parent.getClazz())+'#'+seed.getName(),
                                xe.annotationType().getName(), xes.annotationType().getName()),
                        xe, xes ));
            }

            isRequired = true;

            if(xe!=null)
                ann = new XmlElement[]{xe};
            else
            if(xes!=null)
                ann = xes.value();

            if(ann==null) {
                // default
                TypeT t = getIndividualType();
                if(!nav().isPrimitive(t) || isCollection())
View Full Code Here

        if(types==null) {
            types = new FinalArrayList<TypeRefImpl<TypeT,ClassDeclT>>();
            XmlElement[] ann=null;

            XmlElement xe = seed.readAnnotation(XmlElement.class);
            XmlElements xes = seed.readAnnotation(XmlElements.class);

            if(xe!=null && xes!=null) {
                parent.builder.reportError(new IllegalAnnotationException(
                        Messages.MUTUALLY_EXCLUSIVE_ANNOTATIONS.format(
                                nav().getClassName(parent.getClazz())+'#'+seed.getName(),
                                xe.annotationType().getName(), xes.annotationType().getName()),
                        xe, xes ));
            }

            isRequired = true;

            if(xe!=null)
                ann = new XmlElement[]{xe};
            else
            if(xes!=null)
                ann = xes.value();

            if(ann==null) {
                // default
                TypeT t = getIndividualType();
                if(!nav().isPrimitive(t) || isCollection())
View Full Code Here

        XmlTransient t = null;
        XmlAnyAttribute aa = null;
        XmlAttribute a = null;
        XmlValue v = null;
        XmlElement e1 = null;
        XmlElements e2 = null;
        XmlElementRef r1 = null;
        XmlElementRefs r2 = null;
        XmlAnyElement xae = null;
        XmlMixed mx = null;
View Full Code Here

TOP

Related Classes of javax.xml.bind.annotation.XmlElements

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.