📄 propertyset.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. * */package org.apache.tools.ant.types;import java.util.Enumeration;import java.util.Iterator;import java.util.Map;import java.util.HashSet;import java.util.Set;import java.util.TreeMap;import java.util.Hashtable;import java.util.Properties;import java.util.Vector;import org.apache.tools.ant.BuildException;import org.apache.tools.ant.Project;import org.apache.tools.ant.types.resources.PropertyResource;import org.apache.tools.ant.util.FileNameMapper;import org.apache.tools.ant.util.regexp.RegexpMatcher;import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;/** * A set of properties. * * @since Ant 1.6 */public class PropertySet extends DataType implements ResourceCollection { private boolean dynamic = true; private boolean negate = false; private Set cachedNames; private Vector ptyRefs = new Vector(); private Vector setRefs = new Vector(); private Mapper mapper; /** * This is a nested class containing a reference to some properties * and optionally a source of properties. */ public static class PropertyRef { private int count; private String name; private String regex; private String prefix; private String builtin; /** * Set the name. * @param name a <code>String</code> value. */ public void setName(String name) { assertValid("name", name); this.name = name; } /** * Set the regular expression to use to filter the properties. * @param regex a regular expression. */ public void setRegex(String regex) { assertValid("regex", regex); this.regex = regex; } /** * Set the prefix to use. * @param prefix a <code>String</code> value. */ public void setPrefix(String prefix) { assertValid("prefix", prefix); this.prefix = prefix; } /** * Builtin property names - all, system or commandline. * @param b an enumerated <code>BuildinPropertySetName</code> value. */ public void setBuiltin(BuiltinPropertySetName b) { String pBuiltIn = b.getValue(); assertValid("builtin", pBuiltIn); this.builtin = pBuiltIn; } private void assertValid(String attr, String value) { if (value == null || value.length() < 1) { throw new BuildException("Invalid attribute: " + attr); } if (++count != 1) { throw new BuildException("Attributes name, regex, and " + "prefix are mutually exclusive"); } } /** * A debug toString(). * @return a string version of this object. */ public String toString() { return "name=" + name + ", regex=" + regex + ", prefix=" + prefix + ", builtin=" + builtin; } } //end nested class /** * Allow properties of a particular name in the set. * @param name the property name to allow. */ public void appendName(String name) { PropertyRef r = new PropertyRef(); r.setName(name); addPropertyref(r); } /** * Allow properties whose names match a regex in the set. * @param regex the regular expression to use. */ public void appendRegex(String regex) { PropertyRef r = new PropertyRef(); r.setRegex(regex); addPropertyref(r); } /** * Allow properties whose names start with a prefix in the set. * @param prefix the prefix to use. */ public void appendPrefix(String prefix) { PropertyRef r = new PropertyRef(); r.setPrefix(prefix); addPropertyref(r); } /** * Allow builtin (all, system or commandline) properties in the set. * @param b the type of builtin properties. */ public void appendBuiltin(BuiltinPropertySetName b) { PropertyRef r = new PropertyRef(); r.setBuiltin(b); addPropertyref(r); } /** * Set a mapper to change property names. * @param type mapper type. * @param from source pattern. * @param to output pattern. */ public void setMapper(String type, String from, String to) { Mapper m = createMapper(); Mapper.MapperType mapperType = new Mapper.MapperType(); mapperType.setValue(type); m.setType(mapperType); m.setFrom(from); m.setTo(to); } /** * Add a property reference (nested element) to the references to be used. * @param ref a property reference. */ public void addPropertyref(PropertyRef ref) { assertNotReference(); ptyRefs.addElement(ref); } /** * Add another property set to this set. * @param ref another property set. */ public void addPropertyset(PropertySet ref) { assertNotReference(); setRefs.addElement(ref); } /** * Create a mapper to map the property names. * @return a mapper to be configured. */ public Mapper createMapper() { assertNotReference(); if (mapper != null) { throw new BuildException("Too many <mapper>s!"); } mapper = new Mapper(getProject()); return mapper; } /** * Add a nested FileNameMapper. * @param fileNameMapper the mapper to add. * @since Ant 1.6.3 */ public void add(FileNameMapper fileNameMapper) { createMapper().add(fileNameMapper); } /** * Set whether to reevaluate the set everytime the set is used. * Default is true. * * @param dynamic if true, reevaluate the property set each time * the set is used. if false cache the property set * the first time and use the cached set on subsequent * occasions. */ public void setDynamic(boolean dynamic) { assertNotReference(); this.dynamic = dynamic; } /** * Set whether to negate results. * If "true", all properties not selected by nested elements will be returned. * Default is "false". * @param negate if true, negate the selection criteria. */ public void setNegate(boolean negate) { assertNotReference(); this.negate = negate; } /** * Get the dynamic attribute. * @return true if the property set is to be evalulated each time it is used. */ public boolean getDynamic() { return isReference() ? getRef().dynamic : dynamic; } /** * Get the mapper attribute. * @return the mapper attribute. */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -