Android Open Source - kvs-schema Schema Model






From Project

Back to project page kvs-schema.

License

The source code is released under:

MIT License

If you think the Android project kvs-schema 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.rejasupotaro.android.kvs.internal;
/*from w ww  .  ja v  a2  s.com*/
import com.rejasupotaro.android.kvs.internal.exceptions.TableNameIsInvalidException;
import com.rejaupotaro.android.kvs.annotations.Key;
import com.rejaupotaro.android.kvs.annotations.Table;

import java.util.ArrayList;
import java.util.List;

import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.util.Elements;

public class SchemaModel {
    private TypeElement element;
    private String packageName;
    private String originalClassName;
    private String className;
    private String tableName;
    private List<VariableElement> keys = new ArrayList<>();

    public TypeElement getElement() {
        return element;
    }

    public String getPackageName() {
        return packageName;
    }

    public String getOriginalClassName() {
        return originalClassName;
    }

    public String getClassName() {
        return className;
    }

    public String getTableName() {
        return tableName;
    }

    public List<VariableElement> getKeys() {
        return keys;
    }

    public SchemaModel(TypeElement element, Elements elementUtils) {
        this.element = element;
        Table table = element.getAnnotation(Table.class);
        this.tableName = table.value();
        this.packageName = getPackageName(elementUtils, element);
        this.originalClassName = getClassName(element, packageName);
        if (!originalClassName.endsWith("Schema")) {
            throw new TableNameIsInvalidException(originalClassName + " is invalid. Table class name should end with 'Schema'");
        }
        this.className = originalClassName.replace("Schema", "");

        findAnnotations(element);
    }

    private void findAnnotations(Element element) {
        for (Element enclosedElement : element.getEnclosedElements()) {
            findAnnotations(enclosedElement);

            Key key = enclosedElement.getAnnotation(Key.class);
            if (key != null) {
                keys.add((VariableElement) enclosedElement);
            }
        }
    }

    private String getPackageName(Elements elementUtils, TypeElement type) {
        return elementUtils.getPackageOf(type).getQualifiedName().toString();
    }

    private static String getClassName(TypeElement type, String packageName) {
        int packageLen = packageName.length() + 1;
        return type.getQualifiedName().toString().substring(packageLen).replace('.', '$');
    }
}




Java Source Code List

com.example.android.kvs.ApplicationTest.java
com.example.android.kvs.ExamplePrefsSchema.java
com.example.android.kvs.MainActivity.java
com.rejasupotaro.android.kvs.ApplicationTest.java
com.rejasupotaro.android.kvs.PrefSchema.java
com.rejasupotaro.android.kvs.Schema.java
com.rejasupotaro.android.kvs.internal.Classes.java
com.rejasupotaro.android.kvs.internal.EnvParser.java
com.rejasupotaro.android.kvs.internal.SchemaModel.java
com.rejasupotaro.android.kvs.internal.SchemaProcessor.java
com.rejasupotaro.android.kvs.internal.SchemaWriter.java
com.rejasupotaro.android.kvs.internal.StringUtils.java
com.rejasupotaro.android.kvs.internal.exceptions.TableNameDuplicateException.java
com.rejasupotaro.android.kvs.internal.exceptions.TableNameIsInvalidException.java
com.rejasupotaro.android.kvs.internal.exceptions.TableNameIsNotDefinedException.java
com.rejaupotaro.android.kvs.annotations.Key.java
com.rejaupotaro.android.kvs.annotations.Table.java