blob: 71edd0d037acdbd8d6340bbee5441c834ae8d8df [file] [log] [blame]
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.component.salesforce.api.dto.composite;
import java.util.List;
import java.util.Map;
import com.thoughtworks.xstream.converters.ConversionException;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
public final class SObjectNodeXStreamConverter implements Converter {
@Override
public boolean canConvert(final Class type) {
return SObjectNode.class.equals(type);
}
@Override
public void marshal(final Object source, final HierarchicalStreamWriter writer, final MarshallingContext context) {
final SObjectNode node = (SObjectNode)source;
writer.addAttribute("type", node.object.getAttributes().getType());
writer.addAttribute("referenceId", node.object.getAttributes().getReferenceId());
context.convertAnother(node.object);
for (final Map.Entry<String, List<SObjectNode>> e : node.records.entrySet()) {
writer.startNode(e.getKey());
context.convertAnother(e.getValue());
writer.endNode();
}
}
@Override
public Object unmarshal(final HierarchicalStreamReader reader, final UnmarshallingContext context) {
throw new ConversionException("Unmarshalling is not supported");
}
}