/**
 * Part of the CCNx Java Library.
 *
 * Copyright (C) 2008, 2009 Palo Alto Research Center, Inc.
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License version 2.1
 * as published by the Free Software Foundation. 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details. You should have received
 * a copy of the GNU Lesser General Public License along with this library;
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street,
 * Fifth Floor, Boston, MA 02110-1301 USA.
 */

package org.ccnx.ccn.protocol;

import org.ccnx.ccn.impl.encoding.XMLDecoder;
import org.ccnx.ccn.impl.encoding.XMLEncoder;
import org.ccnx.ccn.impl.support.DataUtils;
import org.ccnx.ccn.io.content.ContentDecodingException;
import org.ccnx.ccn.io.content.ContentEncodingException;


/**
 * This represents a Component with an Exclude filter
 */
public class ExcludeComponent extends Exclude.Element implements Comparable<ExcludeComponent> {
	public static final String COMPONENT_ELEMENT = "Component";
	protected byte [] body = null;
	
	public ExcludeComponent(byte [] component) {
		body = component.clone();
	}

	public ExcludeComponent() {
	}
	
	@Override
	public void decode(XMLDecoder decoder) throws ContentDecodingException {
		body = decoder.readBinaryElement(getElementLabel());
	}

	@Override
	public void encode(XMLEncoder encoder) throws ContentEncodingException {
		encoder.writeElement(getElementLabel(), body);
	}
	
	public int compareTo(ExcludeComponent component) {
		return DataUtils.compare(body, component.body);
	}

	public int compareTo(byte [] component) {
		return DataUtils.compare(body, component);
	}

	@Override
	public String getElementLabel() { return COMPONENT_ELEMENT; }

	@Override
	public boolean validate() {
		return body != null;
	}
	
	@Override
	public boolean equals(Object obj) {
		if (obj == null)
			return false;
		if (!(obj instanceof ExcludeComponent))
			return false;
		ExcludeComponent ec = (ExcludeComponent) obj;
		return DataUtils.arrayEquals(body, ec.body);
	}

	public byte [] getBytes() {
		return body.clone();
	}
}

@@ -803,16 +803,68 @@
 tocol;%0A%0A
+import org.ccnx.ccn.impl.encoding.CCNProtocolDTags;%0A
 import o
@@ -1269,68 +1269,8 @@
 %3E %7B%0A
-%09public static final String COMPONENT_ELEMENT = %22Component%22;
 %0A%09pr
@@ -1916,12 +1916,10 @@
 lic 
-Stri
+Lo
 ng g
@@ -1949,24 +1949,42 @@
 rn C
-OMPONENT_ELEMENT
+CNProtocolDTags.Component.getTag()
 ; %7D%0A

Move to new encoding model.