/**
 * == @Spearal ==>
 * 
 * Copyright (C) 2014 Franck WOLFF & William DRAI (http://www.spearal.io)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.spearal.impl.descriptor;

import org.spearal.SpearalContext;
import org.spearal.SpearalPropertyFilter;
import org.spearal.configuration.FilteredBeanDescriptorFactory;
import org.spearal.configuration.PropertyFactory.Property;
import org.spearal.impl.util.ClassDescriptionUtil;

/**
 * @author Franck WOLFF
 */
public class FilteredBeanDescriptorFactoryImpl implements FilteredBeanDescriptorFactory {
	
	private static class FilteredBeanDescriptorImpl implements FilteredBeanDescriptor {

		private final String description;
		private final Property[] properties;
		
		public FilteredBeanDescriptorImpl(String description, Property[] properties) {
			this.description = description;
			this.properties = properties;
		}

		@Override
		public String getDescription() {
			return description;
		}

		@Override
		public Property[] getProperties() {
			return properties;
		}

		@Override
		public boolean isCacheable() {
			return true;
		}
	}

	@Override
	public FilteredBeanDescriptor createDescription(SpearalContext context, SpearalPropertyFilter filter, Object value) {
		Class<?> type = value.getClass();
		Property[] properties = filter.get(type);
		String description = ClassDescriptionUtil.createAliasedDescription(context, type, properties);
		return new FilteredBeanDescriptorImpl(description, properties);
	}
}

@@ -833,16 +833,90 @@
 actory;%0A
+import org.spearal.configuration.PartialObjectFactory.PartialObjectProxy;%0A
 import o
@@ -1684,174 +1684,1215 @@
 %0A%09%7D%0A
-%0A%09@Override%0A%09public FilteredBeanDescriptor createDescription(SpearalContext context, SpearalPropertyFilter filter, Object value) %7B%0A%09%09Class%3C?%3E type = value.getClass();
+%09%0A%09private static class FilteredPartialBeanDescriptorImpl extends FilteredBeanDescriptorImpl %7B%0A%0A%09%09public FilteredPartialBeanDescriptorImpl(String description, Property%5B%5D properties) %7B%0A%09%09%09super(description, properties);%0A%09%09%7D%0A%0A%09%09@Override%0A%09%09public boolean isCacheable() %7B%0A%09%09%09return false;%0A%09%09%7D%0A%09%7D%0A%0A%09@Override%0A%09public FilteredBeanDescriptor createDescription(SpearalContext context, SpearalPropertyFilter filter, Object value) %7B%0A%09%09Class%3C?%3E type = value.getClass();%0A%09%09%0A%09%09if (value instanceof PartialObjectProxy) %7B%0A%09%09%09type = type.getSuperclass();%0A%09%09%09Property%5B%5D filteredProperties = filter.get(type).clone();%0A%09%09%09Property%5B%5D partialProperties = ((PartialObjectProxy)value).$getDefinedProperties();%0A%09%09%09%0A%09%09%09filteredPropertiesLoop:%0A%09%09%09for (int i = 0; i %3C filteredProperties.length; i++) %7B%0A%09%09%09%09Property filteredProperty = filteredProperties%5Bi%5D;%0A%09%09%09%09for (Property property : partialProperties) %7B%0A%09%09%09%09%09if (property.equals(filteredProperty))%0A%09%09%09%09%09%09continue filteredPropertiesLoop;%0A%09%09%09%09%7D%0A%09%09%09%09filteredProperties%5Bi%5D = null;%0A%09%09%09%7D%0A%09%09%09%0A%09%09%09String description = ClassDescriptionUtil.createAliasedDescription(context, type, filteredProperties);%0A%09%09%09return new FilteredPartialBeanDescriptorImpl(description, filteredProperties);%0A%09%09%7D%0A%09%09
 %0A%09%09P

Add support for partial object encoding.