package com.cooliris.picasa;import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;import org.xml.sax.Attributes;public abstract class Entry {    public static final String[] ID_PROJECTION = { "_id" };    // The primary key of the entry. by_zh    @Column("_id") //使用    public long id = 0;    @Retention(RetentionPolicy.RUNTIME) //使用失效。 注解存在于类文件中,而且在运行时虚拟机可以获取注解信息。 by_zh    @Target(ElementType.TYPE) //此注解只能用来对类、接口以及枚举类型进行注解 by_zh    public @interface Table {        String value();    }    @Retention(RetentionPolicy.RUNTIME)    @Target(ElementType.FIELD) //此注解只能用来对成员变量进行注解    public @interface Column {        String value(); //注解属性,value是获取此属性值的方法的名称。        boolean indexed() default false;        boolean fullText() default false;    }    public void clear() {        id = 0;    }    public void setPropertyFromXml(String uri, String localName, Attributes attrs, String content) {        throw new UnsupportedOperationException("Entry class does not support XML parsing");    }}

private static final class PhotoProjection extends Entry {        public static final EntrySchema SCHEMA = new EntrySchema(PhotoProjection.class);        @Column("edit_uri")        public String editUri;        @Column("title")        public String title;        @Column("summary")        public String summary;        @Column("date_taken")        public long dateTaken;        @Column("latitude")        public double latitude;        @Column("longitude")        public double longitude;        @Column("thumbnail_url")        public String thumbnailUrl;        @Column("screennail_url")        public String screennailUrl;        @Column("content_url")        public String contentUrl;        @Column("content_type")        public String contentType;        @Column("html_page_url")        public String htmlPageUrl;    }


下面是在另一个类中使用注解:
private ColumnInfo[] parseColumnInfo(Class<? extends Object> clazz) {        // Gather metadata from each annotated field.        ArrayList<ColumnInfo> columns = new ArrayList<ColumnInfo>();        Field[] fields = clazz.getFields();        for (int i = 0; i != fields.length; ++i) {            // Get column metadata from the annotation.            Field field = fields[i];            Entry.Column info = ((AnnotatedElement) field).getAnnotation(Entry.Column.class);            if (info == null) {                continue;            }            // Determine the field type.            int type;            Class<?> fieldType = field.getType();            if (fieldType == String.class) {                type = TYPE_STRING;            } else if (fieldType == boolean.class) {                type = TYPE_BOOLEAN;            } else if (fieldType == short.class) {                type = TYPE_SHORT;            } else if (fieldType == int.class) {                type = TYPE_INT;            } else if (fieldType == long.class) {                type = TYPE_LONG;            } else if (fieldType == float.class) {                type = TYPE_FLOAT;            } else if (fieldType == double.class) {                type = TYPE_DOUBLE;            } else if (fieldType == byte[].class) {                type = TYPE_BLOB;            } else {                throw new IllegalArgumentException("Unsupported field type for column: " + fieldType.getName());            }            // Add the column to the array.            int index = columns.size();            columns.add(new ColumnInfo(info.value(), type, info.indexed(), info.fullText(), field, index)); //使用注解 by_zh        }



@Entry.Table("photos")public final class PhotoEntry extends Entry {    public static final EntrySchema SCHEMA = new EntrySchema(PhotoEntry.class);    /**     * The user account that is the sync source for this entry. Must be set     * before insert/update.     */    @Column("sync_account")    public String syncAccount;    /**     * The "edit" URI of the photo.     */    @Column("edit_uri")    public String editUri;......}

更多相关文章

  1. 箭头函数的基础使用
  2. NPM 和webpack 的基础使用
  3. Python list sort方法的具体使用
  4. 【阿里云镜像】使用阿里巴巴DNS镜像源——DNS配置教程
  5. android ImageView的scaleType属性
  6. android SwitchPreference ListPreference使用
  7. Android(安卓)8.0新特性调研
  8. xpose框架使用android studio
  9. 关于Android(安卓)相对布局中的属性 的介绍和运用

随机推荐

  1. cocos2dx android 返回键 Menu键 事件
  2. HbuilderX 发布 android
  3. 手动root android 模拟器(emulator)详细
  4. Android(安卓)启动优化-IdleHandler
  5. Android的多媒体框架OpenCore(PacketVideo
  6. Android(安卓)EditText 为空提示 密码隐
  7. Android(安卓)指纹识别
  8. Android(安卓)Studio 视图解析
  9. Android子线程真的不能更新UI么
  10. android发送/接收json数据