ConnectorDescriptionConverter.java :  » Library » bonita » org » bonitasoft » studio » repository » connectors » Java Open Source

Java Open Source » Library » bonita 
bonita » org » bonitasoft » studio » repository » connectors » ConnectorDescriptionConverter.java
/**
 * Copyright (C) 2009 BonitaSoft S.A.
 * BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2.0 of the License, or
 * (at your option) any later version.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package org.bonitasoft.studio.repository.connectors;

import org.ow2.bonita.connector.core.ConnectorDescription;

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;

/**
 * @author Mickael Istria
 *
 */
public class ConnectorDescriptionConverter implements Converter {

  /**
   * 
   */
  private static final String CONNECTOR_ID_ATTRIBUTE = "connectorId";

  /* (non-Javadoc)
   * @see com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object, com.thoughtworks.xstream.io.HierarchicalStreamWriter, com.thoughtworks.xstream.converters.MarshallingContext)
   */
  public void marshal(Object object, HierarchicalStreamWriter writer, MarshallingContext arg2) {
    ConnectorDescription connectorDesc = (ConnectorDescription)object;
    writer.addAttribute(CONNECTOR_ID_ATTRIBUTE, connectorDesc.getId());
  }

  /* (non-Javadoc)
   * @see com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks.xstream.io.HierarchicalStreamReader, com.thoughtworks.xstream.converters.UnmarshallingContext)
   */
  public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext arg1) {
    String connectorId = reader.getAttribute(CONNECTOR_ID_ATTRIBUTE);
    return ConnectorRepository.getInstance().getConnectorAPI().getConnector(connectorId);
  }

  /* (non-Javadoc)
   * @see com.thoughtworks.xstream.converters.ConverterMatcher#canConvert(java.lang.Class)
   */
  public boolean canConvert(Class arg0) {
    return arg0.equals(ConnectorDescription.class);
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.