@Override
	public Node encode(mxCodec enc, Object obj)
	{
		Element node = enc.document.createElement(getName());

		if (obj instanceof mxStylesheet)
		{
			mxStylesheet stylesheet = (mxStylesheet) obj;
			Iterator<Map.Entry<String, Map<String, Object>>> it = stylesheet
					.getStyles().entrySet().iterator();

			while (it.hasNext())
			{
				Map.Entry<String, Map<String, Object>> entry = it.next();

				Element styleNode = enc.document.createElement("add");
				String stylename = entry.getKey();
				styleNode.setAttribute("as", stylename);

				Map<String, Object> style = entry.getValue();
				Iterator<Map.Entry<String, Object>> it2 = style.entrySet()
						.iterator();

				while (it2.hasNext())
				{
					Map.Entry<String, Object> entry2 = it2.next();
					Element entryNode = enc.document.createElement("add");
					entryNode.setAttribute("as",
							String.valueOf(entry2.getKey()));
					entryNode.setAttribute("value", getStringValue(entry2));
					styleNode.appendChild(entryNode);
				}

				if (styleNode.getChildNodes().getLength() > 0)
				{
					node.appendChild(styleNode);
				}
			}
		}

		return node;
	}