Browse Source

1. Change Parameterizable interface's setParameters method signature such that it takes in an array of type Parameter instead of Hashtable.

2.  Introduce "type" as an attribute to nested param.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@271376 13f79535-47bb-0310-9956-ffa450edef68
master
Magesh Umasankar 23 years ago
parent
commit
8aa365e5d7
5 changed files with 110 additions and 44 deletions
  1. +14
    -7
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineBreaks.java
  2. +2
    -2
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java
  3. +3
    -33
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/AntFilterReader.java
  4. +89
    -0
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/Parameter.java
  5. +2
    -2
      proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/Parameterizable.java

+ 14
- 7
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/filters/StripLineBreaks.java View File

@@ -3,8 +3,8 @@ package org.apache.tools.ant.filters;
import java.io.FilterReader;
import java.io.IOException;
import java.io.Reader;
import java.util.Hashtable;

import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameterizable;

/**
@@ -28,7 +28,7 @@ public final class StripLineBreaks
*/
private static final String LINE_BREAKS_KEY = "linebreaks";

private Hashtable parameters;
private Parameter[] parameters;

/**
* Create a new filtered reader.
@@ -73,15 +73,22 @@ public final class StripLineBreaks
* the option is requested, then line breaks are probably in the source string.
*/
private final String stripLineBreaks(final String source) {
final int len=source.length();
final String userDefinedLineBreaks =
(String) parameters.get(LINE_BREAKS_KEY);
final int len = source.length();
String userDefinedLineBreaks = null;
if (parameters != null) {
for (int i = 0; i < parameters.length; i++) {
if (LINE_BREAKS_KEY.equals(parameters[i].getName())) {
userDefinedLineBreaks = parameters[i].getValue();
break;
}
}
}

String lineBreaks = DEFAULT_LINE_BREAKS;
if (userDefinedLineBreaks != null) {
lineBreaks = userDefinedLineBreaks;
}
final StringBuffer dest=new StringBuffer(len);
final StringBuffer dest = new StringBuffer(len);
for(int i=0;i<len;++i) {
final char ch=source.charAt(i);
if(lineBreaks.indexOf(ch)==-1) {
@@ -95,7 +102,7 @@ public final class StripLineBreaks
/**
* Set Parameters
*/
public final void setParameters(final Hashtable parameters) {
public final void setParameters(final Parameter[] parameters) {
this.parameters = parameters;
}
}

+ 2
- 2
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/taskdefs/LoadFile.java View File

@@ -58,12 +58,12 @@ import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.AntFilterReader;
import org.apache.tools.ant.types.FilterReaderSet;
import org.apache.tools.ant.types.Parameter;
import org.apache.tools.ant.types.Parameterizable;

import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Hashtable;
import java.util.Vector;

/**
@@ -272,7 +272,7 @@ public final class LoadFile extends Task {
instream =
(Reader) constructors[0].newInstance(rdr);
if (Parameterizable.class.isAssignableFrom(clazz)) {
final Hashtable params = filter.getParams();
final Parameter[] params = filter.getParams();
((Parameterizable)
instream).setParameters(params);
}


+ 3
- 33
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/AntFilterReader.java View File

@@ -57,7 +57,6 @@ import java.io.FilterReader;
import java.util.Hashtable;
import java.util.Vector;

import org.apache.tools.ant.types.Parameterizable;
import org.apache.tools.ant.BuildException;

/**
@@ -94,38 +93,9 @@ public final class AntFilterReader {
parameters.addElement(param);
}

public final Hashtable getParams() {
final int size = parameters.size();
final Hashtable params = new Hashtable();
for (int i = 0; i < size; i++) {
final Parameter param = (Parameter) parameters.elementAt(i);
final String name = param.getName();
final String value = param.getValue();
if (name != null && value != null) {
params.put(name, value);
}
}
public final Parameter[] getParams() {
Parameter[] params = new Parameter[parameters.size()];
parameters.copyInto(params);
return params;
}

public static final class Parameter {
private String name = null;
private String value = null;

public final void setName(final String name) {
this.name = name;
}

public final void setValue(final String value) {
this.value = value;
}

public final String getName() {
return name;
}

public final String getValue() {
return value;
}
}
}

+ 89
- 0
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/Parameter.java View File

@@ -0,0 +1,89 @@
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Ant", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.tools.ant.types;

/**
* A parameter is composed of a name, type and value.
*
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public final class Parameter {
private String name = null;
private String type = null;
private String value = null;

public final void setName(final String name) {
this.name = name;
}

public final void setType(final String type) {
this.type = type;
}

public final void setValue(final String value) {
this.value = value;
}

public final String getName() {
return name;
}

public final String getType() {
return type;
}

public final String getValue() {
return value;
}
}

+ 2
- 2
proposal/sandbox/filterreaders/src/main/org/apache/tools/ant/types/Parameterizable.java View File

@@ -53,7 +53,7 @@
*/
package org.apache.tools.ant.types;

import java.util.Hashtable;
import java.util.Vector;

/**
* Parameterizable objects take genric key value pairs.
@@ -61,5 +61,5 @@ import java.util.Hashtable;
* @author <a href="mailto:umagesh@apache.org">Magesh Umasankar</a>
*/
public interface Parameterizable {
void setParameters(Hashtable parameters);
void setParameters(Parameter[] parameters);
}

Loading…
Cancel
Save