Merge "Removed parser EDMx Api and refactor atom parser"
diff --git a/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/IODataParser.java b/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/IODataParser.java
index 1fc65bf..75415a8 100644
--- a/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/IODataParser.java
+++ b/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/IODataParser.java
@@ -14,7 +14,6 @@
 import org.eclipse.ogee.client.exceptions.MarshalerException;
 import org.eclipse.ogee.client.exceptions.ParserException;
 import org.eclipse.ogee.client.model.edmx.Edmx;
-import org.eclipse.ogee.client.model.generic.ComplexTypeCollection;
 import org.eclipse.ogee.client.model.generic.ODataCollection;
 import org.eclipse.ogee.client.model.generic.ODataEntry;
 import org.eclipse.ogee.client.model.generic.ODataProperty;
@@ -106,14 +105,4 @@
 	 */
 	public String format(Edmx edmx) throws MarshalerException;
 
-	/**
-	 * Converts Atom / JSON format to ComplexTypeCollection object
-	 * 
-	 * @param response
-	 * @param serviceOperationName
-	 * @return
-	 * @throws ParserException
-	 */
-	public ComplexTypeCollection parseComplexTypeCollection(String response,
-			String serviceOperationName) throws ParserException;
 }
diff --git a/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/ODataAtomParser.java b/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/ODataAtomParser.java
index 2df3148..78a5d9d 100644
--- a/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/ODataAtomParser.java
+++ b/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/ODataAtomParser.java
@@ -28,7 +28,6 @@
 import org.eclipse.ogee.client.model.atom.AtomFeed;
 import org.eclipse.ogee.client.model.atom.ODataPropertyImpl;
 import org.eclipse.ogee.client.model.edmx.Edmx;
-import org.eclipse.ogee.client.model.generic.ComplexTypeCollection;
 import org.eclipse.ogee.client.model.generic.ODataCollection;
 import org.eclipse.ogee.client.model.generic.ODataEntry;
 import org.eclipse.ogee.client.model.generic.ODataProperty;
@@ -36,7 +35,6 @@
 import org.eclipse.ogee.client.nls.messages.Messages;
 import org.eclipse.ogee.client.parser.impl.AppServiceTagFactory;
 import org.eclipse.ogee.client.parser.impl.AtomFeedAndEntryTagFactory;
-import org.eclipse.ogee.client.parser.impl.CollectionComplexTagFactory;
 import org.eclipse.ogee.client.parser.impl.Marshaller;
 import org.eclipse.ogee.client.parser.impl.ODataSaxHandler;
 import org.eclipse.ogee.client.parser.impl.TagFactory;
@@ -308,112 +306,6 @@
 		}
 	}
 
-	/**
-	 * Converts Edmx XML to an Edmx object
-	 * 
-	 * @param xml
-	 *            Edmx XML
-	 * @return Edmx
-	 * @throws ParserException
-	 */
-	/*
-	 * private Edmx fromXmlToEdmx(String xml) throws ParserException { if (xml
-	 * != null) { xml = xml.trim(); } if (xml == null || xml.length() == 0) {
-	 * String message = Messages.getString("ODataAtomParser.15"); //$NON-NLS-1$
-	 * LOGGER.warning(message); throw new ParserException(message); }
-	 * 
-	 * CustomEdmxConverter converter = new CustomEdmxConverter();
-	 * 
-	 * if (converter.isCustomEdmxFormat(xml)) { xml =
-	 * converter.convertToPlainEdmx(xml); }
-	 * 
-	 * InputStream inputStream = null;
-	 * 
-	 * try { inputStream = new ByteArrayInputStream(
-	 * xml.getBytes(CHARACTER_ENCODING)); Edmx edmx = null; if
-	 * (xml.contains("</Annotation>")) //$NON-NLS-1$ { edmx =
-	 * fromXmlToEdmx(inputStream, 40); } else { edmx =
-	 * fromXmlToEdmx(inputStream, 30); }
-	 * 
-	 * return edmx; } catch (IOException e) { throw
-	 * logAndCreateParserException(xml, e); } finally { if (inputStream != null)
-	 * { try { inputStream.close(); } catch (IOException e) {
-	 * LOGGER.severe(e.getMessage()); } } } }
-	 */
-
-	/**
-	 * Converts XML in OData ATOM format to ODataPropertyImpl object
-	 * 
-	 * @param xml
-	 *            OData ATOM format
-	 * @param serviceOperationName
-	 * @return ODataPropertyImpl
-	 * @throws ParserException
-	 */
-	private ComplexTypeCollection fromXmlToRootElement(String xml,
-			String serviceOperationName) throws ParserException {
-		if (xml != null) {
-			xml = xml.trim();
-		}
-		if (xml == null || xml.length() == 0) {
-			String message = Messages.getString("ODataAtomParser.18"); //$NON-NLS-1$
-			LOGGER.warning(message);
-			throw new ParserException(message);
-		}
-
-		InputStream inputStream = null;
-
-		try {
-			inputStream = new ByteArrayInputStream(
-					xml.getBytes(CHARACTER_ENCODING));
-			ComplexTypeCollection rootElement = fromXmlToRootElement(
-					inputStream, serviceOperationName);
-
-			return rootElement;
-		} catch (IOException e) {
-			LOGGER.severe(e.getMessage());
-			throw new ParserException(e);
-		} finally {
-			if (inputStream != null) {
-				try {
-					inputStream.close();
-				} catch (IOException e) {
-					LOGGER.severe(e.getMessage());
-				}
-			}
-		}
-	}
-
-	private ComplexTypeCollection fromXmlToRootElement(InputStream inputStream,
-			String serviceOperationName) throws ParserException {
-		if (inputStream == null) {
-			String message = Messages.getString("ODataAtomParser.16"); //$NON-NLS-1$
-			LOGGER.warning(message);
-			throw new ParserException(message);
-		}
-
-		ComplexTypeCollection rootElement = (ComplexTypeCollection) parseObject(
-				inputStream, new CollectionComplexTagFactory(
-						serviceOperationName));
-		return rootElement;
-	}
-
-	/**
-	 * Parses a complex type collection given the xml and service operation's
-	 * name parameters.
-	 * 
-	 * @param xml
-	 *            - the xml string.
-	 * @param serviceOperationName
-	 *            - the service operation's name.
-	 * @return - A parsed complex type collection.
-	 * @throws ParserException
-	 */
-	public ComplexTypeCollection parseComplexTypeCollection(String xml,
-			String serviceOperationName) throws ParserException {
-		return fromXmlToRootElement(xml, serviceOperationName);
-	}
-
 	private static ParserException logAndCreateParserException(String xml,
 			Exception e) {
 		LOGGER.severe(Messages.getString("ODataAtomParser.17") + xml); //$NON-NLS-1$
diff --git a/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/ODataJSONParser.java b/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/ODataJSONParser.java
index 3593c71..4d72181 100644
--- a/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/ODataJSONParser.java
+++ b/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/ODataJSONParser.java
@@ -29,7 +29,6 @@
 import org.eclipse.ogee.client.jsonsimple.parser.JSONParser;
 import org.eclipse.ogee.client.jsonsimple.parser.ParseException;
 import org.eclipse.ogee.client.model.edmx.Edmx;
-import org.eclipse.ogee.client.model.generic.ComplexTypeCollection;
 import org.eclipse.ogee.client.model.generic.ODataCollection;
 import org.eclipse.ogee.client.model.generic.ODataEntry;
 import org.eclipse.ogee.client.model.generic.ODataProperty;
@@ -475,30 +474,4 @@
 	public String format(Edmx edmx) throws MarshalerException {
 		return Marshaller.getInstance().format(edmx);
 	}
-
-	@Override
-	public ComplexTypeCollection parseComplexTypeCollection(String xml,
-			String serviceOperationName) throws ParserException {
-		ODataCollection parseODataCollection = ODataParserFactory
-				.createInstance(Representation.JSON).parseODataCollection(xml);
-		ComplexTypeCollection result = new ComplexTypeCollection(
-				serviceOperationName);
-		result.setName(serviceOperationName);
-		ODataPropertyJson[] elements = new ODataPropertyJson[parseODataCollection
-				.getEntries().length];
-		int i = 0;
-		for (ODataEntry entry : parseODataCollection.getEntries()) {
-			ODataPropertyJson property = new ODataPropertyJson();
-			property.setName("d:element");
-			ODataProperty[] properties = entry.getProperties();
-			for (ODataProperty oDataProperty : properties) {
-				property.putChildProperty(oDataProperty);
-			}
-			elements[i] = property;
-			i++;
-		}
-
-		result.setElements(elements);
-		return result;
-	}
 }
diff --git a/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/impl/CollectionComplexTagFactory.java b/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/impl/CollectionComplexTagFactory.java
deleted file mode 100644
index d8b218a..0000000
--- a/org.eclipse.ogee.client/src/org/eclipse/ogee/client/parser/impl/CollectionComplexTagFactory.java
+++ /dev/null
@@ -1,140 +0,0 @@
-/*******************************************************************************
- *  Copyright (c) 2012-2014 SAP SE.
- *  All rights reserved. This program and the accompanying materials
- *  are made available under the terms of the Eclipse Public License v1.0
- *  which accompanies this distribution, and is available at
- *  http://www.eclipse.org/legal/epl-v10.html
- *
- *  Contributors:
- *  SAP SE - initial API and implementation and/or initial documentation
- *
- *******************************************************************************/
-package org.eclipse.ogee.client.parser.impl;
-
-import org.eclipse.ogee.client.model.atom.ODataPropertyImpl;
-import org.eclipse.ogee.client.model.generic.Arrays;
-import org.eclipse.ogee.client.model.generic.ComplexTypeCollection;
-import org.eclipse.ogee.client.model.generic.ODataProperty;
-import org.xml.sax.Attributes;
-
-/**
- * Auxiliary class for parsing a complex type collection. Not to be used
- * explicitly.
- * 
- */
-public class CollectionComplexTagFactory implements TagFactory {
-	private ComplexTypeCollection root;
-
-	public CollectionComplexTagFactory(String serviceOperation) {
-		super();
-		root = new ComplexTypeCollection(serviceOperation);
-	}
-
-	public TagObject createTagObject(String tagName, Attributes attr) {
-		TagObject result = new TagObject();
-		result.setTag(tagName);
-
-		int attrCount = attr.getLength();
-
-		if (tagName.equalsIgnoreCase(this.root.getQualifiedName())) {
-			if (attrCount > 0) {
-				String attrName, attrValue;
-				for (int i = 0; i < attrCount; i++) {
-					attrName = attr.getQName(i);
-					attrValue = attr.getValue(i);
-
-					this.root.setAttribute(attrName, attrValue);
-				}
-			}
-			result.setObject(this.root);
-		} else if (tagName.equalsIgnoreCase("d:element")) {
-			ODataPropertyImpl element = new ODataPropertyImpl();
-			if (attrCount > 0) {
-				String attrName, attrValue;
-				for (int i = 0; i < attrCount; i++) {
-					attrName = attr.getQName(i);
-					attrValue = attr.getValue(i);
-					if (attrName.equalsIgnoreCase(M_TYPE))
-						element.setType(attr.getValue(i));
-					else
-						element.setAttribute(attrName, attrValue);
-				}
-			}
-			result.setObject(element);
-		} else if (tagName.startsWith(D)) {
-			ODataPropertyImpl valueObject = new ODataPropertyImpl();
-			if (attrCount > 0) {
-				String attrName, attrValue;
-				for (int i = 0; i < attrCount; i++) {
-					attrName = attr.getQName(i);
-					attrValue = attr.getValue(i);
-					if (attrName.equalsIgnoreCase(M_TYPE))
-						valueObject.setType(attrValue);
-					else
-						valueObject.setAttribute(attrName, attrValue);
-				}
-			}
-			result.setObject(valueObject);
-		}
-
-		return result;
-	}
-
-	public void setValue(TagObject tagObject, String value) {
-		String tagName = tagObject.getTag();
-		if (!tagName.equalsIgnoreCase(this.root.getName())) {
-			if (tagName.startsWith(D)
-					&& !tagName.equalsIgnoreCase(this.root.getQualifiedName())) {
-				ODataPropertyImpl valueObject = (ODataPropertyImpl) tagObject
-						.getObject();
-				valueObject.setValue(value);
-				valueObject.setName(tagName);
-			} else if (tagObject.getObject() == null && value != null) {
-				tagObject.setObject(value);
-			}
-		}
-
-	}
-
-	public void addChild(TagObject parent, TagObject tagObject) {
-		String tag = tagObject.getTag();
-		String parentTag = parent.getTag();
-
-		if (parentTag.equalsIgnoreCase(this.root.getQualifiedName())) {
-			this.root = (ComplexTypeCollection) parent.getObject();
-
-			if (tag.equalsIgnoreCase("d:element")) {
-				ODataProperty[] elements = (ODataProperty[]) this.root
-						.getElements();
-				if (elements == null) {
-					this.root.setElements(new ODataPropertyImpl[0]);
-					elements = (ODataPropertyImpl[]) this.root.getElements();
-				}
-
-				ODataPropertyImpl element = (ODataPropertyImpl) tagObject
-						.getObject();
-				Arrays.add(this.root, elements, element);
-
-			}
-
-		} else if (parentTag.equalsIgnoreCase("d:element")) {
-			ODataPropertyImpl element = (ODataPropertyImpl) parent.getObject();
-
-			if (tag.startsWith(D)) {
-				ODataPropertyImpl dataValue = (ODataPropertyImpl) tagObject
-						.getObject();
-				element.putChildDataValue(dataValue);
-			}
-		} else if (!parentTag.equalsIgnoreCase(this.root.getQualifiedName())) {
-			ODataPropertyImpl parentDataValue = (ODataPropertyImpl) parent
-					.getObject();
-			if (tag.startsWith(D)) {
-				ODataPropertyImpl dataValue = (ODataPropertyImpl) tagObject
-						.getObject();
-				parentDataValue.putChildDataValue(dataValue);
-			}
-		}
-
-	}
-
-}