MultiMarshaller.java :  » REST » pj2r » com » google » code » pj2r » resources » Java Open Source

Java Open Source » REST » pj2r 
pj2r » com » google » code » pj2r » resources » MultiMarshaller.java
/*
 *  Copyright 2009 Johan Maasing.
 * 
 *  Licensed 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.
 *  under the License.
 */
package com.google.code.pj2r.resources;

import com.google.code.pj2r.Marshaller;
import com.google.code.pj2r.MarshallingException;
import java.util.List;
import javax.servlet.http.HttpServletRequest;

/**
 * A meta-marshaller that delegates to a list of other marshallers.
 * @author Johan Maasing
 */
public class MultiMarshaller implements Marshaller {

  private final List<Marshaller> marshallers;

  /**
   * Create a new multi-marshaller.
   * @param marshallers The lsit of marshallers to delegate marshalling to. May not be null or empty.
   */
  public MultiMarshaller(final List<Marshaller> marshallers) {
    if (marshallers == null) {
      throw new IllegalArgumentException("List of marshallers may not be null");
    }
    if (marshallers.size() < 1) {
      throw new IllegalArgumentException("List of marshallers may not be empty");
    }
    this.marshallers = marshallers;
  }

  @Override
  public void marshal(HttpServletRequest request, Object result) throws MarshallingException {
    for (Marshaller marshaller : marshallers) {
      marshaller.marshal(request, result);
    }
  }
}
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.