Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.s1.objects.schema;
  
  
  import java.util.List;
 import java.util.Map;

s1v2 User: GPykhov Date: 11.01.14 Time: 17:16
 
 public class ObjectSchema implements Serializable{
 
     private boolean resolved = false;
 
     private List<ObjectSchemaAttributeattributes = Objects.newArrayList();
 
     private List<ObjectSchemaTypetypes = Objects.newArrayList();
 
     public ObjectSchema(Object... args) {
         this. = Objects.newArrayList();
         this. = Objects.newArrayList();
         for(Object a:args){
             if(a instanceof ObjectSchemaAttribute){
                 this..add((ObjectSchemaAttribute)a);
             }else if(a instanceof ObjectSchemaType){
                 this..add((ObjectSchemaType)a);
             }
         }
         setAttributesSchema();
     }
 
     public ObjectSchema(List<ObjectSchemaAttributeattributesList<ObjectSchemaTypetypes) {
         if(attributes==null)
             this. = Objects.newArrayList();
         else
             this. = attributes;
         if(types==null)
             this. = Objects.newArrayList();
         else
             this. = types;
         setAttributesSchema();
     }
 
         List<Map<String,Object>> attrs = Objects.get(m"attributes");
         this. = Objects.newArrayList();
         if(!Objects.isNullOrEmpty(attrs)){
             for(Map<String,Objectaattrs){
                 .add(ObjectSchemaAttribute.createFromMap(a));
             }
         }
 
         List<Map<String,Object>> t = Objects.get(m"types");
         this. = Objects.newArrayList();
         if(!Objects.isNullOrEmpty(t)){
             for(Map<String,Objectat){
                 .add(new ObjectSchemaType(a));
             }
         }
         setAttributesSchema();
         return this;
     }
 
     protected MapAttribute rootMapAttribute = new MapAttribute(null,null);
 
     protected void setAttributesSchema(){
         .setSchema(this);
         /*for(ObjectSchemaAttribute a:attributes){
             a.setSchema(this);
             a.setParent(null);
         }*/
     }
 
     public Map<String,ObjecttoMap(){
         List<Map<String,Object>> attrs = Objects.newArrayList();
         for(ObjectSchemaAttribute a:){
             attrs.add(a.toMap());
         }
 
         List<Map<String,Object>> t = Objects.newArrayList();
         for(ObjectSchemaType a:){
             t.add(a.toMap());
         }
 
         Map<String,Objectm = Objects.newHashMap("attributes"attrs"types"t);
         return m;
     }
 
     public List<ObjectSchemaAttributegetAttributes() {
         List<ObjectSchemaAttributelist = Objects.newArrayList();
         for(ObjectSchemaAttribute a:list.add(a);
        return list;
    }
    public List<ObjectSchemaTypegetTypes() {
        List<ObjectSchemaTypelist = Objects.newArrayList();
        for(ObjectSchemaType a:list.add(a);
        return list;
    }
    public boolean isResolved() {
        return ;
    }
        return validateQuite(data,null);
    }
        return validateQuite(datafalsefalsectx);
    }
    public ValidateResultBean validateQuite(Map<String,Objectdataboolean expandboolean deepMap<String,Objectctx){
        try {
            return validate(dataexpanddeepctxtrue);
        } catch (ObjectSchemaValidationException e) {
            throw S1SystemError.wrap(e);
        }
    }
    public Map<String,Objectvalidate(Map<String,Objectdata)
            throws ObjectSchemaValidationException{
        return validate(datanull);
    }
    public Map<String,Objectvalidate(Map<String,ObjectdataMap<String,Objectctx)
            throws ObjectSchemaValidationException{
        return validate(datafalsefalsectx);
    }
    public Map<String,Objectvalidate(Map<String,Objectdataboolean expandboolean deepMap<String,Objectctx)
            throws ObjectSchemaValidationException{
        return validate(data,expand,deep,ctx,false).getValidatedData();
    }
    protected ValidateResultBean validate(Map<String,Objectdataboolean expandboolean deepMap<String,Objectctxboolean quite)
            throws ObjectSchemaValidationException{
        if(ctx==null)
            ctx = Objects.newHashMap();
        Map<String,ObjectvalidatedData = Objects.copy(data);
        ObjectSchema resolvedSchema = copyAndReset();
        resolvedSchema.resolved = true;
        resolvedSchema.rootMapAttribute.setData(validatedData);
        List<ObjectSchemaAttributeattrs = Objects.newArrayList();
        for(ObjectSchemaAttribute a:resolvedSchema.attributes){
            Object dt = validatedData.containsKey(a.getName())?validatedData.get(a.getName()):null;
            ObjectSchemaAttribute va = a.validate(dtexpanddeepctxquite);
            attrs.add(va);
            if(va.getData()==null)
                validatedData.remove(va.getName());
            else
                validatedData.put(va.getName(),va.getData());
        }
        resolvedSchema.attributes = attrs;
        return new ValidateResultBean(resolvedSchema,validatedData);
    }
    public ObjectSchema copyAndReset(){
        ObjectSchema a = new ObjectSchema();
        a.attributes = Objects.newArrayList();
        for(ObjectSchemaAttribute a1:){
            a.attributes.add(a1.copyAndReset());
        }
        a.types = Objects.newArrayList();
        for(ObjectSchemaType a1:){
            a.types.add(a1.copy());
        }
        a.setAttributesSchema();
        return a;
    }

    
    public static class ValidateResultBean {
        private ObjectSchema resolvedSchema;
        private Map<String,ObjectvalidatedData;
        public ValidateResultBean(ObjectSchema resolvedSchemaMap<StringObjectvalidatedData) {
            this. = resolvedSchema;
            this. = validatedData;
        }
        public ObjectSchema getResolvedSchema() {
            return ;
        }
        public Map<StringObjectgetValidatedData() {
            return ;
        }
    }
New to GrepCode? Check out our FAQ X