001/*
002 * Copyright 2011-2013 UnboundID Corp.
003 *
004 * This program is free software; you can redistribute it and/or modify
005 * it under the terms of the GNU General Public License (GPLv2 only)
006 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
007 * as published by the Free Software Foundation.
008 *
009 * This program is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012 * GNU General Public License for more details.
013 *
014 * You should have received a copy of the GNU General Public License
015 * along with this program; if not, see <http://www.gnu.org/licenses>.
016 */
017
018package com.unboundid.scim.marshal.xml;
019
020import com.unboundid.scim.data.BaseResource;
021import com.unboundid.scim.marshal.Marshaller;
022import com.unboundid.scim.sdk.BulkOperation;
023import com.unboundid.scim.sdk.Resources;
024import com.unboundid.scim.sdk.SCIMException;
025
026import java.io.OutputStream;
027import java.util.List;
028
029
030
031/**
032 * This class provides a SCIM object marshaller implementation to write SCIM
033 * objects to their XML representation.
034 */
035public class XmlMarshaller implements Marshaller
036{
037  /**
038   * {@inheritDoc}
039   */
040  public void marshal(final BaseResource resource,
041                      final OutputStream outputStream)
042      throws SCIMException
043  {
044    final XmlStreamMarshaller streamMarshaller =
045        new XmlStreamMarshaller(outputStream);
046    try
047    {
048      streamMarshaller.marshal(resource);
049    }
050    finally
051    {
052      streamMarshaller.close();
053    }
054  }
055
056
057
058  /**
059   * {@inheritDoc}
060   */
061  public void marshal(final SCIMException response,
062                      final OutputStream outputStream)
063      throws SCIMException
064  {
065    final XmlStreamMarshaller streamMarshaller =
066        new XmlStreamMarshaller(outputStream);
067    try
068    {
069      streamMarshaller.marshal(response);
070    }
071    finally
072    {
073      streamMarshaller.close();
074    }
075  }
076
077
078
079  /**
080   * {@inheritDoc}
081   */
082  public void marshal(final Resources<? extends BaseResource> resources,
083                      final OutputStream outputStream)
084      throws SCIMException
085  {
086    final XmlStreamMarshaller streamMarshaller =
087        new XmlStreamMarshaller(outputStream);
088    try
089    {
090      streamMarshaller.marshal(resources);
091    }
092    finally
093    {
094      streamMarshaller.close();
095    }
096  }
097
098
099
100  /**
101   * {@inheritDoc}
102   */
103  public void bulkMarshal(final OutputStream outputStream,
104                          final int failOnErrors,
105                          final List<BulkOperation> operations)
106      throws SCIMException
107  {
108    final XmlStreamMarshaller streamMarshaller =
109        new XmlStreamMarshaller(outputStream);
110    try
111    {
112      streamMarshaller.bulkMarshal(failOnErrors, operations);
113    }
114    finally
115    {
116      streamMarshaller.close();
117    }
118  }
119}