/*
 * Copyright (c) 2011 Haulmont Technology Ltd. All Rights Reserved.
 * Haulmont Technology proprietary and confidential.
 * Use is subject to license terms.
 */

package com.haulmont.cuba.gui.data;

import com.haulmont.chile.core.model.*;

import java.util.*;

/**
 * <p>$Id$</p>
 *
 * @author devyatkin
 */

public class RuntimePropertiesMetaClass implements MetaClass {

    private Map<String, MetaProperty> properties = new LinkedHashMap<String, MetaProperty>();

    public void addProperty(MetaProperty property) {
        properties.put(property.getName(), property);
    }

    public void setProperties(List<MetaProperty> properties) {
        for (MetaProperty property : properties) {
            this.properties.put(property.getName(), property);
        }
    }

    public MetaModel getModel() {
        return null;
    }

    public Class getJavaClass() {
        return null;
    }

    public MetaProperty getProperty(String name) {
       return properties.get(name);
    }

    public MetaPropertyPath getPropertyEx(String propertyPath) {
        return new MetaPropertyPath(this, properties.get(propertyPath));
    }

    public MetaPropertyPath getPropertyPath(String propertyPath) {
        String[] properties = propertyPath.split("[.]");
        List<MetaProperty> metaProperties = new ArrayList<MetaProperty>();

		MetaProperty currentProperty;
		MetaClass currentClass = this;

		for (String property : properties) {
			if (currentClass == null) return null;
			currentProperty = currentClass.getProperty(property);
			if (currentProperty == null) return null;

			final Range range = currentProperty.getRange();
			currentClass = range.isClass() ? range.asClass() : null;

            metaProperties.add(currentProperty);
		}

		return new MetaPropertyPath(this, metaProperties.toArray(new MetaProperty[metaProperties.size()]));
    }

    public Collection<MetaProperty> getOwnProperties() {
        return null;
    }

    public Collection<MetaProperty> getProperties() {
        return properties.values();
    }

    public <T> T createInstance() throws InstantiationException, IllegalAccessException {
        return null;
    }

    public MetaClass getAncestor() {
        return null;
    }

    public Collection<MetaClass> getAncestors() {
        return null;
    }

    public Collection<MetaClass> getDescendants() {
        return null;
    }

    public String getName() {
        return null;
    }

    public String getFullName() {
        return null;
    }

    public String getCaption() {
        return null;
    }

    public String getDescription() {
        return null;
    }

    public UUID getUUID() {
        return null;
    }

    public Map<String, Object> getAnnotations() {
        return null;
    }
}

@@ -991,24 +991,25 @@
 ) %7B%0D%0A       
+ 
 return prope
@@ -1264,291 +1264,49 @@
     
-String%5B%5D properties = propertyPath.split(%22%5B.%5D%22);%0D%0A        List%3CMetaProperty%3E metaProperties = new ArrayList%3CMetaProperty%3E();%0D%0A%0D%0A%09%09MetaProperty currentProperty;%0D%0A%09%09MetaClass currentClass = this;%0D%0A%0D%0A%09%09for (String property : properties) %7B%0D%0A%09%09%09if (currentClass == null) return null;%0D%0A%09%09%09
+MetaProperty currentProperty;%0D%0A%0D%0A        
 curr
@@ -1319,27 +1319,19 @@
 perty = 
-currentClas
+thi
 s.getPro
@@ -1344,23 +1344,32 @@
 property
-);%0D%0A%09%09%09
+Path);%0D%0A        
 if (curr
@@ -1409,279 +1409,65 @@
 %0D%0A%0D%0A
-%09%09%09final Range range = currentProperty.getRange();%0D%0A%09%09%09currentClass = range.isClass() ? range.asClass() : null;%0D%0A%0D%0A            metaProperties.add(currentProperty);%0D%0A%09%09%7D%0D%0A%0D%0A%09%09return new MetaPropertyPath(this, metaProperties.toArray(new MetaProperty%5BmetaProperties.size()%5D)
+        return new MetaPropertyPath(this, currentProperty
 );%0D%0A

add the ability to create dynamic attribute names containing a point