001/*
002 * Copyright 2011-2016 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.SCIMException;
023import com.unboundid.scim.sdk.Resources;
024import com.unboundid.scim.sdk.BulkOperation;
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   * {@inheritDoc}
059   */
060  public void marshal(final SCIMException response,
061                      final OutputStream outputStream)
062      throws SCIMException
063  {
064    final XmlStreamMarshaller streamMarshaller =
065        new XmlStreamMarshaller(outputStream);
066    try
067    {
068      streamMarshaller.marshal(response);
069    }
070    finally
071    {
072      streamMarshaller.close();
073    }
074  }
075
076
077
078  /**
079   * {@inheritDoc}
080   */
081  public void marshal(final Resources<? extends BaseResource> resources,
082                      final OutputStream outputStream)
083      throws SCIMException
084  {
085    final XmlStreamMarshaller streamMarshaller =
086        new XmlStreamMarshaller(outputStream);
087    try
088    {
089      streamMarshaller.marshal(resources);
090    }
091    finally
092    {
093      streamMarshaller.close();
094    }
095  }
096
097
098  /**
099   * {@inheritDoc}
100   */
101  public void bulkMarshal(final OutputStream outputStream,
102                          final int failOnErrors,
103                          final List<BulkOperation> operations)
104      throws SCIMException
105  {
106    final XmlStreamMarshaller streamMarshaller =
107        new XmlStreamMarshaller(outputStream);
108    try
109    {
110      streamMarshaller.bulkMarshal(failOnErrors, operations);
111    }
112    finally
113    {
114      streamMarshaller.close();
115    }
116  }
117
118}