Android Open Source - meets-android Serializable






From Project

Back to project page meets-android.

License

The source code is released under:

MIT License

If you think the Android project meets-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.theagilemonkeys.meets.utils.soap;
//from w  ww.  j  a  va 2 s  . co  m
import com.google.api.client.util.Key;

import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Hashtable;
import java.util.LinkedHashMap;

/**
 * Android Meets SDK
 * Original work Copyright (c) 2014 [TheAgileMonkeys]
 *
 * @author ??lvaro Lpez Espinosa
 */
public class Serializable {

    /**
     * Annotation to allow specify the type of collections
     */
    public @Retention(RetentionPolicy.RUNTIME) @interface PropertyName {
        String value();
    }

    public static class Object implements KvmSerializable {
        private static final java.util.List unserializableTypes = Arrays.asList(Float.class, float.class, Double.class, double.class);
        private java.util.List<Field> fields = null;

        private java.util.List<Field> getFields(){
            if (fields != null) return fields;

            fields = new ArrayList<Field>();

            for(Field field : getClass().getDeclaredFields() ){
                Key keyAnnotation = field.getAnnotation(Key.class);
                if ( keyAnnotation != null ) fields.add(field);
            }

            return fields;
        }


        private java.lang.Object getPropertyValue(Field field) throws IllegalAccessException {
            // This is fix the serialization problems Soap has with doubles and floats
            java.lang.Object val = field.get(this);
            if ( unserializableTypes.contains(field.getType()) ) {
                val = String.valueOf(val);
            }
            return val;
        }

        @Override
        public java.lang.Object getProperty(int i) {
            try{
                Field field = getFields().get(i);
                field.setAccessible(true);
                return getPropertyValue(field);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }

        @Override
        public int getPropertyCount() {
            return getFields().size();
        }

        @Override
        public void setProperty(int i, java.lang.Object o) {
            try{
                Field field = getFields().get(i);
                field.setAccessible(true);
                field.set(this, o);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e.getMessage(), e);
            }
        }

        @Override
        public void getPropertyInfo(int i, Hashtable hashtable, PropertyInfo propertyInfo) {
            Field field = getFields().get(i);

            //Check if this field has a specific name
            PropertyName propertyName = field.getAnnotation(PropertyName.class);
            if (propertyName != null)
                propertyInfo.setName(propertyName.value());
            else
                propertyInfo.setName(field.getName());

            propertyInfo.setType(field.getType());
        }
    }

    public static class List<TYPE> extends ArrayList<TYPE> implements KvmSerializable {
        protected String listItemName = "item";

        public List() {}

        public List(Collection<TYPE> c) {
            super(c);
        }

        @Override
        public java.lang.Object getProperty(int i) {
            return get(i);
        }

        @Override
        public int getPropertyCount() {
            return size();
        }

        @Override
        public void setProperty(int i, java.lang.Object o) {
            add((TYPE) o);
        }

        @Override
        public void getPropertyInfo(int i, Hashtable hashtable, PropertyInfo propertyInfo) {
            propertyInfo.setName(listItemName);
            propertyInfo.setType(get(i).getClass());
        }
    }

    public static class Map<KEY_TYPE, VALUE_TYPE> extends LinkedHashMap<KEY_TYPE, VALUE_TYPE> implements KvmSerializable {
        private java.util.List<VALUE_TYPE> values = null;
        private java.util.List<KEY_TYPE> keys = null;

        private java.util.List<VALUE_TYPE> getMapValues(){
            if (values != null) return values;
            values = new ArrayList<VALUE_TYPE>(values());
            return values;
        }

        private java.util.List<KEY_TYPE> getMapKeys(){
            if (keys != null) return keys;
            keys = new ArrayList<KEY_TYPE>(keySet());
            return keys;
        }

        @Override
        public java.lang.Object getProperty(int i) {
            return getMapValues().get(i);
        }

        @Override
        public int getPropertyCount() {
            return size();
        }

        @Override
        public void setProperty(int i, java.lang.Object o) {
            throw new UnsupportedOperationException();
        }

        @Override
        public void getPropertyInfo(int i, Hashtable hashtable, PropertyInfo propertyInfo) {
            KEY_TYPE key = getMapKeys().get(i);
            propertyInfo.setName(String.valueOf(key));
            propertyInfo.setType(get(key).getClass());
        }
    }
}




Java Source Code List

com.theagilemonkeys.meets.ApiMethodModelHelperInterface.java
com.theagilemonkeys.meets.ApiMethodModelHelper.java
com.theagilemonkeys.meets.ApiMethod.java
com.theagilemonkeys.meets.MeetsSpiceService.java
com.theagilemonkeys.meets.Meets.java
com.theagilemonkeys.meets.magento.RestApiMethod.java
com.theagilemonkeys.meets.magento.SoapApiMethod.java
com.theagilemonkeys.meets.magento.methods.CatalogCategoryInfo.java
com.theagilemonkeys.meets.magento.methods.CatalogCategoryLevel.java
com.theagilemonkeys.meets.magento.methods.CatalogCategoryTree.java
com.theagilemonkeys.meets.magento.methods.CatalogInventoryStockItemList.java
com.theagilemonkeys.meets.magento.methods.CatalogProductAttributeOptions.java
com.theagilemonkeys.meets.magento.methods.CatalogProductInfo.java
com.theagilemonkeys.meets.magento.methods.CatalogProductList.java
com.theagilemonkeys.meets.magento.methods.CustomerAddressCreate.java
com.theagilemonkeys.meets.magento.methods.CustomerAddressDelete.java
com.theagilemonkeys.meets.magento.methods.CustomerAddressInfo.java
com.theagilemonkeys.meets.magento.methods.CustomerAddressList.java
com.theagilemonkeys.meets.magento.methods.CustomerAddressUpdate.java
com.theagilemonkeys.meets.magento.methods.CustomerCustomerCreate.java
com.theagilemonkeys.meets.magento.methods.CustomerCustomerInfo.java
com.theagilemonkeys.meets.magento.methods.CustomerCustomerList.java
com.theagilemonkeys.meets.magento.methods.CustomerCustomerUpdate.java
com.theagilemonkeys.meets.magento.methods.Products.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartCreate.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartCustomerAddresses.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartCustomerSet.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartInfo.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartOrder.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartPaymentList.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartPaymentMethod.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartProductAdd.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartProductRemove.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartShippingList.java
com.theagilemonkeys.meets.magento.methods.ShoppingCartShippingMethod.java
com.theagilemonkeys.meets.magento.models.MageMeetsAddress.java
com.theagilemonkeys.meets.magento.models.MageMeetsCartItem.java
com.theagilemonkeys.meets.magento.models.MageMeetsCartPayment.java
com.theagilemonkeys.meets.magento.models.MageMeetsCartShipping.java
com.theagilemonkeys.meets.magento.models.MageMeetsCart.java
com.theagilemonkeys.meets.magento.models.MageMeetsCategory.java
com.theagilemonkeys.meets.magento.models.MageMeetsCustomer.java
com.theagilemonkeys.meets.magento.models.MageMeetsProduct.java
com.theagilemonkeys.meets.magento.models.MageStockInfoList.java
com.theagilemonkeys.meets.magento.models.MageStockItem.java
com.theagilemonkeys.meets.magento.models.base.MageMeetsCollectionPojos.java
com.theagilemonkeys.meets.magento.models.base.MageMeetsCollection.java
com.theagilemonkeys.meets.magento.models.base.MageMeetsFactory.java
com.theagilemonkeys.meets.magento.models.base.MageMeetsModel.java
com.theagilemonkeys.meets.models.MeetsAddress.java
com.theagilemonkeys.meets.models.MeetsCart.java
com.theagilemonkeys.meets.models.MeetsCategory.java
com.theagilemonkeys.meets.models.MeetsCustomer.java
com.theagilemonkeys.meets.models.MeetsProduct.java
com.theagilemonkeys.meets.models.MeetsStock.java
com.theagilemonkeys.meets.models.base.MeetsCollectionPojos.java
com.theagilemonkeys.meets.models.base.MeetsCollection.java
com.theagilemonkeys.meets.models.base.MeetsFactory.java
com.theagilemonkeys.meets.models.base.MeetsListener.java
com.theagilemonkeys.meets.models.base.MeetsModel.java
com.theagilemonkeys.meets.utils.Copier.java
com.theagilemonkeys.meets.utils.StringUtils.java
com.theagilemonkeys.meets.utils.soap.Serializable.java
com.theagilemonkeys.meets.utils.soap.SoapParser.java