// Path: src/main/java/pl/maciejwalkowiak/plist/PlistSerializerImpl.java
// public class PlistSerializerImpl implements PlistSerializer {
// 	private static final Logger logger = LoggerFactory.getLogger(PlistSerializerImpl.class);
// 
// 	private HandlerWrapper handlerWrapper;
// 	private BasicObjectSerializer basicObjectSerializer;
// 	private FieldSerializer fieldSerializer;
// 	private NamingStrategy namingStrategy = new DefaultNamingStrategy();
// 
// 	public PlistSerializerImpl(NamingStrategy namingStrategy) {
// 		this();
// 		this.namingStrategy = namingStrategy;
// 	}
// 
// 	public PlistSerializerImpl() {
// 		this.handlerWrapper = new HandlerWrapper(this);
// 		this.fieldSerializer = new FieldSerializer(handlerWrapper, this);
// 		this.basicObjectSerializer = new BasicObjectSerializer(handlerWrapper);
// 	}
// 
// 	public String toXmlPlist(Object objectToConvert) {
// 		StringBuilder result = new StringBuilder(HEADER);
// 
// 		result.append(serialize(objectToConvert));
// 
// 		result.append(FOOTER);
// 
// 		return result.toString();
// 	}
// 
// 	public String serialize(Object objectToConvert) {
// 		StringBuilder result = new StringBuilder();
// 
// 		logger.debug("converting object = {}", objectToConvert);
// 
// 		if (objectToConvert != null) {
// 			if (handlerWrapper.isSupported(objectToConvert)) {
// 				result.append(basicObjectSerializer.serializeBasicObject(objectToConvert));
// 			} else {
// 				result.append(fieldSerializer.serializeFields(objectToConvert));
// 			}
// 		}
// 
// 		return result.toString();
// 	}
// 
// 	public void setAdditionalHandlers(List<Handler> additionalHandlers) {
// 		handlerWrapper.addAdditionalHandlers(additionalHandlers);
// 	}
// 
// 	public NamingStrategy getNamingStrategy() {
// 		return namingStrategy;
// 	}
// 
// 	HandlerWrapper getHandlerWrapper() {
// 		return handlerWrapper;
// 	}
// }
// 
// Path: src/main/java/pl/maciejwalkowiak/plist/XMLHelper.java
// public class XMLHelper {
// 	private XMLHelper() {}
// 
// 	private Object objectToWrap;
// 
// 	public static XMLHelper wrap(Object object) {
// 		if (object == null) {
// 			throw new IllegalArgumentException("object to wrap cannot be null");
// 		}
// 
// 		XMLHelper xmlHelper = new XMLHelper();
// 		xmlHelper.objectToWrap = object;
// 
// 		return xmlHelper;
// 	}
// 
// 	public String with(String wrappedWith) {
// 		if (wrappedWith == null || wrappedWith.isEmpty()) {
// 			throw new IllegalArgumentException("wrappedWith cannot be null or empty");
// 		}
// 
// 		StringBuilder result = new StringBuilder();
// 
// 		result.append("<").append(wrappedWith).append(">").append(this.objectToWrap).append("</").append(wrappedWith).append(">");
// 
// 		return result.toString();
// 	}
// }


import pl.maciejwalkowiak.plist.PlistSerializerImpl;
import pl.maciejwalkowiak.plist.XMLHelper;
import java.util.Collection;
/*
 * Copyright (c) 2012 Maciej Walkowiak
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package pl.maciejwalkowiak.plist.handler;



/**
 * @author Maciej Walkowiak
 */
public class CollectionHandler extends AbstractHandler {

	public CollectionHandler(PlistSerializerImpl plistSerializer) {
		super(plistSerializer);
	}

	public boolean supports(Object object) {
		return object instanceof Collection || isArray(object);
	}

	public String doHandle(Object object) {
		StringBuilder result = new StringBuilder();

		Collection col = (Collection) object;

		for (Object o: col) {
			result.append(plistSerializer.serialize(o));
		}

		return XMLHelper.wrap(result).with("array");
	}

// Path: src/main/java/pl/maciejwalkowiak/plist/PlistSerializerImpl.java
// public class PlistSerializerImpl implements PlistSerializer {
// 	private static final Logger logger = LoggerFactory.getLogger(PlistSerializerImpl.class);
// 
// 	private HandlerWrapper handlerWrapper;
// 	private BasicObjectSerializer basicObjectSerializer;
// 	private FieldSerializer fieldSerializer;
// 	private NamingStrategy namingStrategy = new DefaultNamingStrategy();
// 
// 	public PlistSerializerImpl(NamingStrategy namingStrategy) {
// 		this();
// 		this.namingStrategy = namingStrategy;
// 	}
// 
// 	public PlistSerializerImpl() {
// 		this.handlerWrapper = new HandlerWrapper(this);
// 		this.fieldSerializer = new FieldSerializer(handlerWrapper, this);
// 		this.basicObjectSerializer = new BasicObjectSerializer(handlerWrapper);
// 	}
// 
// 	public String toXmlPlist(Object objectToConvert) {
// 		StringBuilder result = new StringBuilder(HEADER);
// 
// 		result.append(serialize(objectToConvert));
// 
// 		result.append(FOOTER);
// 
// 		return result.toString();
// 	}
// 
// 	public String serialize(Object objectToConvert) {
// 		StringBuilder result = new StringBuilder();
// 
// 		logger.debug("converting object = {}", objectToConvert);
// 
// 		if (objectToConvert != null) {
// 			if (handlerWrapper.isSupported(objectToConvert)) {
// 				result.append(basicObjectSerializer.serializeBasicObject(objectToConvert));
// 			} else {
// 				result.append(fieldSerializer.serializeFields(objectToConvert));
// 			}
// 		}
// 
// 		return result.toString();
// 	}
// 
// 	public void setAdditionalHandlers(List<Handler> additionalHandlers) {
// 		handlerWrapper.addAdditionalHandlers(additionalHandlers);
// 	}
// 
// 	public NamingStrategy getNamingStrategy() {
// 		return namingStrategy;
// 	}
// 
// 	HandlerWrapper getHandlerWrapper() {
// 		return handlerWrapper;
// 	}
// }
// 
// Path: src/main/java/pl/maciejwalkowiak/plist/XMLHelper.java
// public class XMLHelper {
// 	private XMLHelper() {}
// 
// 	private Object objectToWrap;
// 
// 	public static XMLHelper wrap(Object object) {
// 		if (object == null) {
// 			throw new IllegalArgumentException("object to wrap cannot be null");
// 		}
// 
// 		XMLHelper xmlHelper = new XMLHelper();
// 		xmlHelper.objectToWrap = object;
// 
// 		return xmlHelper;
// 	}
// 
// 	public String with(String wrappedWith) {
// 		if (wrappedWith == null || wrappedWith.isEmpty()) {
// 			throw new IllegalArgumentException("wrappedWith cannot be null or empty");
// 		}
// 
// 		StringBuilder result = new StringBuilder();
// 
// 		result.append("<").append(wrappedWith).append(">").append(this.objectToWrap).append("</").append(wrappedWith).append(">");
// 
// 		return result.toString();
// 	}
// }


// Path: src/main/java/pl/maciejwalkowiak/plist/handler/CollectionHandler.java
import pl.maciejwalkowiak.plist.PlistSerializerImpl;
import pl.maciejwalkowiak.plist.XMLHelper;
import java.util.Collection;

/*
 * Copyright (c) 2012 Maciej Walkowiak
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package pl.maciejwalkowiak.plist.handler;



/**
 * @author Maciej Walkowiak
 */
public class CollectionHandler extends AbstractHandler {

	public CollectionHandler(PlistSerializerImpl plistSerializer) {
		super(plistSerializer);
	}

	public boolean supports(Object object) {
		return object instanceof Collection || isArray(object);
	}

	public String doHandle(Object object) {
		StringBuilder result = new StringBuilder();

		Collection col = (Collection) object;

		for (Object o: col) {
			result.append(plistSerializer.serialize(o));
		}

		return XMLHelper.wrap(result).with("array");
	}

	private boolean isArray(final Object obj) {