Examples of XmlElement


Examples of javax.xml.bind.annotation.XmlElement

                       /*
                       *  Step 5.10.2.4.2: Read property value from object. If value null attempt to get it from default value.
                       */
                       try{
                           Field declaredField = getDeclaredField(clazz,name);
                           XmlElement   xmlElm   =  declaredField.getAnnotation(XmlElement.class);
                             if(xmlElm != null){
                               if(!xmlElm.defaultValue().equals(NULL) && isJSONPrimitive(propertyType)){
                                 value = xmlElm.defaultValue();
                               } else if(!xmlElm.nillable() && createDefaultOnNonNullable){
                                 if(!isJSONPrimitive(propertyType)){
                                   if(!stackNillableInstances.contains(propertyType)){
                                     stackNillableInstances.push(propertyType);
                                     value = getNewInstance(propertyType);
                                     hasData = this.add(name, value, null, hasData, property) || hasData;
                                     stackNillableInstances.pop();
                                   }
                                   continue nextProperty;
                                 }else{
                                   // Primitive don't have any default WHAT TODO . E.g. Integer object can't be instantiated.
                                 }
                               }
                             }
                         }catch(Throwable th){}
                         // Value still null
                         if(value == null && JSONCodec.excludeNullProperties && !this.metaDataMode){
                           continue nextProperty;
                         } else if(this.metaDataMode) {
                       // In meta data mode always get data via meta provider.
                       value = getMetaDataInstance(propertyType, accessor.getAnnotation(JSONWebService.class),
                              getDeclaredField(clazz,name));
                      }
                    }else if(this.metaDataMode && propertyType.isPrimitive()){
                      // Primitive meta data. In case like int value become 0. But it may be from default
                     value = getMetaDataInstance(propertyType, accessor.getAnnotation(JSONWebService.class),
                          getDeclaredField(clazz,name));
                    }
                     
                  /*
                     *  Step 5.10.2.4.3: read property custom config. If it is serializable continue process with specified name if any
                     */
                  JSONWebService properyConfig = accessor.getAnnotation(JSONWebService.class);
                   if (properyConfig != null) {
                         if (!properyConfig.serialize())
                             continue;
                         else if (properyConfig.name().length() > 0)
                             name = properyConfig.name();
                     }else{
                    /*
                     *  Step 5.10.2.4.4: JSON config not present. Then read XML configuration.
                     */   
                       try{
                        // XML annotation present at field level.
                         Field     declaredField   = getDeclaredField(clazz,name);
                         XmlElement   xmlElm       = declaredField.getAnnotation(XmlElement.class);
                          /*
                           *  Step 5.10.2.4.5: If XML transient ignore property.
                           */
                         if (declaredField.isAnnotationPresent(XmlMimeType.class)){
                           if(this.metaDataMode){
                             value  = declaredField.getAnnotation(XmlMimeType.class).value();
                           }else{
                             Map<String,Object> attachment = new HashMap<String, Object>();;
                             attachment .put("name", name);
                             attachment.put("value", value);
                             attachment.put("mimeType",declaredField.getAnnotation(XmlMimeType.class).value());
                             attachments   .add(attachment);
                             continue nextProperty;
                           }
                         } else if(xmlElm != null) {// MAjor hits are here
                           /*
                                *  Step 5.10.2.4.4.2: Xml elements .
                                */
                           if(!xmlElm.name().equals(XML_DEFAULT)){
                             name = xmlElm.name();
                           }
                         }else if(declaredField.isAnnotationPresent(XmlElements.class) && Collection.class.isAssignableFrom(declaredField.getType())
                             && value instanceof Collection){
                           // XML choice list
                             /*
 
View Full Code Here

Examples of javax.xml.bind.annotation.XmlElement

    * @return
    */
   private Object getMetaDataInstance(Class<?> propertyType, JSONWebService webService, Field field){
     String defaultVal = null;
     if(field != null && field.isAnnotationPresent(XmlElement.class)){
       XmlElement element = field.getAnnotation(XmlElement.class);
      if(!element.defaultValue().equals(NULL)){
        if(propertyType.isEnum()){
          defaultVal  = element.defaultValue();
          // In case of enum meta data is decided list
        } else if(Boolean.TYPE.equals(propertyType) || Boolean.class.equals(propertyType)){
          return Boolean.valueOf(element.defaultValue());
        } else {
          return element.defaultValue();
        }
      }
    }
    
     if(WSJSONPopulator.isJSONPrimitive(propertyType)){
View Full Code Here

Examples of javax.xml.bind.annotation.XmlElement

            // Process Attachments
            XmlMimeType   ann     = f.getAnnotation(XmlMimeType.class);
            writeMethod.invoke(object, new Object[]{handleMimeAttachement(f.getType(),ann,expectedJSONPropName)});
          } else if(f.isAnnotationPresent(XmlElement.class)){
            // Handle default value
            XmlElement     element   = f.getAnnotation(XmlElement.class);
            // JSON property name is same as in XML annotation, but class property name is different.
            if(!element.name().equals(NULL) && elements.containsKey(element.name())){
              writeMethod.invoke(object,
                  convert(propertyType, f.getType(), elements.get(element.name()),
                      writeMethod.getAnnotation(JSONWebService.class), writeMethod));
            } else if (!element.defaultValue().equals(NULL) && isJSONPrimitive(propertyType)){
              if(traceEnabled)
                traceLog.info(String.format("Input do not have %s. Populating default value: %s. flag to populate: %b",
                    expectedJSONPropName, element.defaultValue(), createDefaultOnNonNullable));
              writeMethod.invoke(object,
                  convert(propertyType, f.getType(), element.defaultValue(),
                      writeMethodConfig, writeMethod));
            } else if (!element.nillable() && createDefaultOnNonNullable) {
              // there is no default value and non nullable.
              if(!isJSONPrimitive(propertyType)){
                if(traceEnabled)
                  traceLog.warn("Non nillable object(\""+expectedJSONPropName +
                    "\") with nill value, populating default.");
View Full Code Here

Examples of javax.xml.bind.annotation.XmlElement

                fieldName = JAXBUtils.nameToIdentifier(
                                partName,
                               JAXBUtils.IdentifierType.VARIABLE);
            }
           
            XmlElement el = null;
            for (Field field : wrapperType.getClass().getDeclaredFields()) {
                if (field.getName().equals(fieldName)) {
                    //JAXB Type get XmlElement Annotation
                    el = field.getAnnotation(XmlElement.class);
                    assert el != null;
                }
            }
           
            if (part == null) {
                if (!el.nillable()) {
                    throw new IllegalArgumentException("null value for field not permitted.");
                }
                return;
            }

            String modifier =
                JAXBUtils.nameToIdentifier(partName, JAXBUtils.IdentifierType.SETTER);           
           
            boolean setInvoked = false;
            for (Method method : wrapperType.getClass().getMethods()) {
                if (method.getParameterTypes() != null
                    && method.getParameterTypes().length == 1
                    && modifier.equals(method.getName())) {
                   
                    Class<?> clazz = method.getParameterTypes()[0];
                    if (method.getParameterTypes()[0].isPrimitive()) {
                        clazz = el.type();
                    }
                   
                    if (clazz.isAssignableFrom(part.getClass())) {
                        method.invoke(wrapperType, part);
                        setInvoked = true;
View Full Code Here

Examples of javax.xml.bind.annotation.XmlElement

     
      for (int i = 0; i < a.length; i++)
      {
         if(a[i] instanceof XmlElement)
         {
            XmlElement xme = (XmlElement)a[i];
            xme.name().equals(name);
            results = true;
         }
      }
      return results;
   }
View Full Code Here

Examples of javax.xml.bind.annotation.XmlElement

    if (root != null) {
      name = root.name();
      namespace = !root.namespace().equals("##default") ? root.namespace() : "";
      rootElement = true;
    } else {
      XmlElement element = bean.getAnnotation(XmlElement.class);
      if (element != null) {
        name = element.name();
        namespace = !element.namespace().equals("##default") ? element.namespace() : "";
      }
    }
   
    return new JavaXMLBean(bean, name, namespace, rootElement);
  }
View Full Code Here

Examples of javax.xml.bind.annotation.XmlElement

   
    for (IClassMemberWritableValue member : members) {
      if (member.getAnnotation(XmlAttribute.class) != null) continue;
      if (member.getAnnotation(XmlAnyElement.class) != null) continue;
     
      XmlElement element = member.getAnnotation(XmlElement.class);
     
      String namespace = element != null && !element.namespace().equals("##default") ? element.namespace() : "";
      String xmlName = element != null && !"".equals( element.name() ) ? element.name() : member.getName();
     
      if (this.isSimple(member)) {
        elements.put("".equals(namespace) ? xmlName : (namespace + ":" + xmlName), new JavaXMLSimpleElement(member, namespace, xmlName));
      } else {
        elements.put("".equals(namespace) ? xmlName : (namespace + ":" + xmlName), this.createRealType(member, context));
View Full Code Here

Examples of javax.xml.bind.annotation.XmlElement

  {
    super(context, accessor);

    // XXX respect the type from the XmlElement annotation

    XmlElement element = accessor.getAnnotation(XmlElement.class);
    boolean xmlList = (accessor.getAnnotation(XmlList.class) != null);

    XmlMimeType xmlMimeType = accessor.getAnnotation(XmlMimeType.class);
    String mimeType = null;
   
    if (xmlMimeType != null)
      mimeType = xmlMimeType.value();

    _property = _context.createProperty(accessor.getGenericType(), false,
                                        mimeType, xmlList);

    if (element != null) {
      _qname = qnameFromXmlElement(element);
      _nillable = element.nillable();
    }
    else {
      XmlSchema xmlSchema = accessor.getPackageAnnotation(XmlSchema.class);

      if (xmlSchema != null &&
View Full Code Here

Examples of javax.xml.bind.annotation.XmlElement

  }

  public void generateSchema(XMLStreamWriter out)
    throws JAXBException, XMLStreamException
  {
    XmlElement element = _accessor.getAnnotation(XmlElement.class);
    XmlList xmlList = _accessor.getAnnotation(XmlList.class);

    if (xmlList != null) {
      out.writeStartElement(XML_SCHEMA_PREFIX, "element",
                            W3C_XML_SCHEMA_NS_URI);
      out.writeAttribute("name", _accessor.getName());

      out.writeStartElement(XML_SCHEMA_PREFIX, "simpleType",
                            W3C_XML_SCHEMA_NS_URI);

      out.writeEmptyElement(XML_SCHEMA_PREFIX, "list",
                            W3C_XML_SCHEMA_NS_URI);

      String itemType =
        StaxUtil.qnameToString(out, _property.getSchemaType());
     
      out.writeAttribute("itemType", itemType);

      out.writeEndElement(); // simpleType

      out.writeEndElement(); // element
    }
    else {
      out.writeEmptyElement(XML_SCHEMA_PREFIX, "element",
                            W3C_XML_SCHEMA_NS_URI);

      if (! _generateRICompatibleSchema ||
          ! _accessor.getType().isPrimitive()) {

        if (element != null) {
          if (element.required())
            out.writeAttribute("minOccurs", "1");
          else
            out.writeAttribute("minOccurs", "0");

          if (element.nillable())
            out.writeAttribute("nillable", "true");
        }
        else
          out.writeAttribute("minOccurs", "0");
      }

      if (_property.getMaxOccurs() != null)
        out.writeAttribute("maxOccurs", _property.getMaxOccurs());

      if ((element != null && element.nillable()) ||
          Collection.class.isAssignableFrom(_accessor.getType()) ||
          (_accessor.getType().isArray() &&
           ! byte.class.equals(_accessor.getType().getComponentType())))
        out.writeAttribute("nillable", "true");
View Full Code Here

Examples of javax.xml.bind.annotation.XmlElement

            if (generateGenericType(type)) {
                buildGenericElements(schema, seq, f);
            } else {
                JAXBBeanInfo beanInfo = getBeanInfo(type);
                if (beanInfo != null) {
                    XmlElement xmlElementAnno = f.getAnnotation(XmlElement.class);
                    addElement(schema, seq, beanInfo, new QName(namespace, f.getName()), isArray(type), xmlElementAnno);
                }
            }
        }
        for (Method m : Utils.getGetters(cls, accessType)) {
            //map method
            Type type = Utils.getMethodReturnType(m);
            // we want to return the right type for collections so if we get null
            // from the return type we check if it's ParameterizedType and get the
            // generic return type.
            if ((type == null) && (m.getGenericReturnType() instanceof ParameterizedType)) {
                type = m.getGenericReturnType();
            }
           
            if (generateGenericType(type)) {
                buildGenericElements(schema, seq, m, type);
            } else {
                JAXBBeanInfo beanInfo = getBeanInfo(type);
                if (beanInfo != null) {
                    int idx = m.getName().startsWith("get") ? 3 : 2;
                    String name = m.getName().substring(idx);
                    name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
                    XmlElement  xmlElementAnno =  m.getAnnotation(XmlElement.class);
                    addElement(schema, seq, beanInfo, new QName(namespace, name), isArray(type), xmlElementAnno);
                }
            }
        }
        // Create element in xsd:sequence for Exception.class
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.