001 /*
002 * Copyright 2005 The Apache Software Foundation.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.vafer.jdeb.ant;
017
018 import java.io.File;
019 import java.io.FileInputStream;
020
021 import org.vafer.jdeb.mapping.LsMapper;
022 import org.vafer.jdeb.mapping.NullMapper;
023 import org.vafer.jdeb.mapping.PrefixMapper;
024
025 /**
026 * Ant "mapper" element acting as factory for the entry mapper.
027 * So far type "ls" and "prefix" are supported.
028 *
029 * @author Torsten Curdt <tcurdt@vafer.org>
030 */
031 public final class Mapper {
032
033 private String mtype;
034 private String prefix;
035 private int strip;
036 private File src;
037
038 public void setType( final String pType ) {
039 mtype = pType;
040 }
041
042 public void setPrefix( final String pPrefix ) {
043 prefix = pPrefix;
044 }
045
046 public void setStrip( final int pStrip ) {
047 strip = pStrip;
048 }
049
050 public void setSrc( final File pSrc ) {
051 src = pSrc;
052 }
053
054 public org.vafer.jdeb.mapping.Mapper createMapper() {
055 if ("prefix".equalsIgnoreCase(mtype)) {
056 return new PrefixMapper(strip, prefix);
057 } else if ("ls".equalsIgnoreCase(mtype)) {
058 try {
059 return new LsMapper(new FileInputStream(src));
060 } catch (Exception e) {
061 e.printStackTrace();
062 }
063 }
064 return new NullMapper();
065 }
066
067 }