/*
* 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.Stack;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ComponentHelper;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectComponent;
import org.apache.tools.ant.util.IdentityStack;
/**
* Base class for those classes that can appear inside the build file
* as stand alone data types.
*
*
This class handles the common description attribute and provides
* a default implementation for reference handling and checking for
* circular references that is appropriate for types that can not be
* nested inside elements of the same type (i.e. <patternset>
* but not <path>).
*
*/
public abstract class DataType extends ProjectComponent implements Cloneable {
// CheckStyle:VisibilityModifier OFF
/**
* Value to the refid attribute.
*
* @deprecated since 1.7.
* The user should not be directly referencing
* variable. Please use {@link #getRefid} instead.
*/
protected Reference ref;
/**
* Are we sure we don't hold circular references?
*
*
Subclasses are responsible for setting this value to false
* if we'd need to investigate this condition (usually because a
* child element has been added that is a subclass of
* DataType).
*
* @deprecated since 1.7.
* The user should not be directly referencing
* variable. Please use {@link #setChecked} or
* {@link #isChecked} instead.
*/
protected boolean checked = true;
// CheckStyle:VisibilityModifier ON
/**
* Has the refid attribute of this element been set?
* @return true if the refid attribute has been set
*/
public boolean isReference() {
return ref != null;
}
/**
* Set the value of the refid attribute.
*
*
Subclasses may need to check whether any other attributes
* have been set as well or child elements have been created and
* thus override this method. if they do the must call
* super.setRefid.
* @param ref the reference to use
*/
public void setRefid(final Reference ref) {
this.ref = ref;
checked = false;
}
/**
* Gets as descriptive as possible a name used for this datatype instance.
* @return String name.
*/
protected String getDataTypeName() {
return ComponentHelper.getElementName(getProject(), this, true);
}
/**
* Convenience method.
* @since Ant 1.7
*/
protected void dieOnCircularReference() {
dieOnCircularReference(getProject());
}
/**
* Convenience method.
* @param p the Ant Project instance against which to resolve references.
* @since Ant 1.7
*/
protected void dieOnCircularReference(Project p) {
if (checked || !isReference()) {
return;
}
dieOnCircularReference(new IdentityStack