<|start_filename|>src/main/groovy/org/grails/plugins/marshallers/ActionConfigBuilder.groovy<|end_filename|>
package org.grails.plugins.marshallers

public class ActionConfigBuilder{
	def config=[:]
	def methodMissing(String name,args){
		if(args.size()==1 && args[0] instanceof Closure){
			config[name]=args[0]
		}else{
			throw new IllegalStateException('Illegal syntax encountered while building serializers config: '+ name)
		}
	}
}


<|start_filename|>src/main/groovy/org/grails/plugins/marshallers/config/MarshallingConfig.groovy<|end_filename|>
package org.grails.plugins.marshallers.config
/**
 * Marshalling configuration options
 * 
 * @author dhalupa
 *
 */
class MarshallingConfig {
	/**
	 * List of field names. If a field representing one-to-many relation is marked as deep, all contained data of related objects will be serialized
	 */
	List deep
	/**
	 *  list of fields which uniquely identifies a domain object in case database id is not sufficient.
	 */
	List identifier
	/**
	 * configures a custom domain object element name which should be used instead of default one
	 */
	String elementName
	/**
	 * list of field names which will be serialized as attributes of domain object element 
	 */
	List attribute
	/**
	 * list of field names which will be ignored during serialization
	 */
	List ignore
    /**
     * exclusive list of field names which will be included during serialization (mutually exclusive with "ignore")
     */
    List include
	/**
	 * configuration option allows us to define closures with custom serialization behavior
	 */
	Map virtual
	/**
	 * configuration option allows us to define closures with custom serialization behavior
	 */
	Map serializer
	/**
	 * when true will suppress serialization of domain object identifier
	 */
	boolean shouldOutputIdentifier=true
	/**
	 * json,xml or null
	 */
	String type
	/**
	 * name of named configuration or 'default'
	 */
	String name='default'
	/**
	 * If true domain instance class name will be serialized
	 */
	Boolean shouldOutputClass
	/**
	 * If true version information will be serialized
	 */
	Boolean shouldOutputVersion

	List children=[]

    // configuration for the given class
    Class clazz
    
	def findConfigNames(type){
		def configs=[] as Set, worker
		worker={
			->
			if(delegate.type==null || delegate.type==type){
				configs<<delegate.name
			}
			delegate.children.each{child->
				worker.delegate=child
				worker()
			}
		}
		worker()
		configs
	}

	def findNamedConfig(type,name){
		def worker,result
		worker={->
			if((delegate.type==type || delegate.type==null) && name==delegate.name){
				result=delegate
			}
			delegate.children.each{child->
				worker.delegate=child
				worker()
			}
		}
		worker()
		result
	}
	
    String toString() {
        "${name}:${clazz}"
    }
}


<|start_filename|>src/main/groovy/org/grails/plugins/marshallers/config/MarshallingConfigPool.groovy<|end_filename|>
/*
	* Copyright (c) 2013, ABZ Reporting GmbH (www.abz-reporting.com) 
	* All rights reserved.
	*
	* This software is the confidential and proprietary information
	* of ABZ Reporting GmbH ("Confidential Information").  You shall not
	* disclose such Confidential Information and shall use it only
	* in accordance with the terms of the license agreement you
	* entered into with ABZ Reporting GmbH.
	*
	* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
	* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
	* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
	* DISCLAIMED.  IN NO EVENT SHALL ABZ REPORTING GMBH OR
	* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
	* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
	* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
	* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
	* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
	* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
	* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
	* SUCH DAMAGE.
	* 
	* The original code is ABRA, an XBRL processor.
	* The Initial Developer of the Original Code is <NAME>
	* <<EMAIL>>.
	* Contributor(s): <NAME>, <NAME>
	*
 */

package org.grails.plugins.marshallers.config

/**
 * @author <NAME>
 */
class MarshallingConfigPool {

    def configs = [:]
    MarshallingConfigPool parentPool
    
    def MarshallingConfigPool(configs) {
        for (c in configs) {
            this.configs.put(c.clazz, c)
        }
    }
    
    def get(Class clazz, boolean useParent = false) {
        def c = configs.get(clazz)
        if (c == null && parentPool != null && useParent) {
            c = parentPool.get(clazz, true)
        }    
        c
    }
    
}


<|start_filename|>src/main/groovy/org/grails/plugins/marshallers/config/VirtualPropertiesBuilder.groovy<|end_filename|>
package org.grails.plugins.marshallers.config

class VirtualPropertiesBuilder {
	Map properties=[:]
	
	void methodMissing(String name,args){
		properties[name]=args[0]
	}

}


<|start_filename|>src/main/java/org/grails/plugins/marshallers/MarshallingContext.java<|end_filename|>
package org.grails.plugins.marshallers;

import org.apache.commons.lang.NotImplementedException;

import java.lang.ref.WeakReference;
import java.util.*;

/**
 * Context data container backed by threadlocal variable. Stored context values are wrapped in weak references in
 * order to prevent memory leak
 *
 * @author <NAME>
 */
public class MarshallingContext implements Map<String, Object> {
    private ThreadLocal<Map<String, WeakReference>> instance = new ThreadLocal<Map<String, WeakReference>>() {
        @Override
        protected Map<String, WeakReference> initialValue() {
            return new HashMap<String, WeakReference>();
        }
    };

    @Override
    public int size() {
        return instance.get().size();
    }

    @Override
    public boolean isEmpty() {
        return instance.get().isEmpty();
    }

    @Override
    public boolean containsKey(Object key) {
        return instance.get().containsKey(key);
    }

    @Override
    public boolean containsValue(Object value) {
        throw new NotImplementedException("not implemented for marshalling context");
    }

    @Override
    public Object get(Object key) {
        WeakReference r = instance.get().get(key);
        return r.get();
    }

    @Override
    public Object put(String key, Object value) {
        WeakReference r = new WeakReference(value);
        return instance.get().put(key, r);
    }

    @Override
    public Object remove(Object key) {
        return instance.get().remove(key);
    }

    @Override
    public void putAll(Map<? extends String, ?> m) {
        throw new NotImplementedException("not implemented for marshalling context");
    }


    @Override
    public void clear() {
        instance.get().clear();
    }

    @Override
    public Set<String> keySet() {
        throw new NotImplementedException("not implemented for marshalling context");
    }

    @Override
    public Collection<Object> values() {
        throw new NotImplementedException("not implemented for marshalling context");
    }

    @Override
    public Set<Entry<String, Object>> entrySet() {
        throw new NotImplementedException("not implemented for marshalling context");
    }
}
