001/*
002 * Copyright (c) 2007-2015 Concurrent, Inc. All Rights Reserved.
003 *
004 * Project and contact information: http://www.cascading.org/
005 *
006 * This file is part of the Cascading project.
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *     http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020
021package cascading.tuple;
022
023import java.util.ArrayList;
024import java.util.List;
025import java.util.Map;
026import java.util.Properties;
027
028import cascading.property.Props;
029import cascading.util.Util;
030
031/**
032 * Class TupleEntrySchemeIteratorProps is a fluent helper class to set properties which control the behavior of the
033 * {@link cascading.tuple.TupleEntrySchemeIterator}.
034 */
035public class TupleEntrySchemeIteratorProps extends Props
036  {
037  public static final String PERMITTED_EXCEPTIONS = "cascading.tuple.tupleentryiterator.exceptions.permit";
038
039  private Class<? extends Exception>[] permittedExceptions = null;
040
041  /**
042   * Method setPermittedExceptions(  Map<Object, Object> properties, Class<? extends Exception>[] ... exceptions )
043   * is used to set an array of exceptions, which are allowed to be ignored in the TupleEntySchemeInterator. If the array
044   * is null, it will be ignored.
045   * <p>Note that the array will be converted to a comma separated String. If you read the the property back, you can
046   * convert it back to classes via the asClasses method.</p>
047   *
048   * @param properties a Map<Object, Object>
049   * @param exceptions an array of exception classes.
050   */
051  public static void setPermittedExceptions( Map<Object, Object> properties, Class<? extends Exception>... exceptions )
052    {
053    if( exceptions != null )
054      {
055      List<String> classNames = new ArrayList<String>();
056
057      for( Class<? extends Exception> clazz : exceptions )
058        classNames.add( clazz.getName() );
059
060      properties.put( PERMITTED_EXCEPTIONS, Util.join( classNames, "," ) );
061      }
062    }
063
064  /**
065   * Creates a new TupleEntrySchemeIteratorProps instance.
066   *
067   * @return TupleEntrySchemeIteratorProps instance
068   */
069  public static TupleEntrySchemeIteratorProps tupleEntrySchemeIteratorProps()
070    {
071    return new TupleEntrySchemeIteratorProps();
072    }
073
074  /**
075   * Constructs a new TupleEntrySchemeIteratorProps instance.
076   */
077  public TupleEntrySchemeIteratorProps()
078    {
079    }
080
081  public Class<? extends Exception>[] getPermittedExceptions()
082    {
083    return permittedExceptions;
084    }
085
086  /**
087   * Method setPermittedExceptions is used to set an array of exceptions which are allowed to be ignored in the
088   * TupleEntrySchemeIterator.
089   * <p/>
090   * If the array is null, it will be ignored.
091   *
092   * @param permittedExceptions an array of exception classes.
093   */
094  public TupleEntrySchemeIteratorProps setPermittedExceptions( Class<? extends Exception>[] permittedExceptions )
095    {
096    this.permittedExceptions = permittedExceptions;
097    return this;
098    }
099
100  @Override
101  protected void addPropertiesTo( Properties properties )
102    {
103    setPermittedExceptions( properties, permittedExceptions );
104    }
105  }