FileDocCategorySizeDatePackage
DotnetResource.javaAPI DocApache Ant 1.707147Wed Dec 13 06:16:20 GMT 2006org.apache.tools.ant.taskdefs.optional.dotnet

DotnetResource

public class DotnetResource extends Object
Used by {@link DotnetCompile} to name resources. Could be upgraded to a datatype in the distant future. A resource maps to /res:file,name

Fields Summary
private File
file
name of resource
private boolean
embed
embed (default) or link the resource
private Boolean
isPublic
this is used in VBC and JSC
private String
name
name of the object
private ArrayList
fileSets
A list of filesets with resources.
private String
namespace
a namespace to be used with
Constructors Summary
Methods Summary
public voidaddFileset(org.apache.tools.ant.types.FileSet fileset)
Adds a resource file set.

param
fileset FileSet

        fileSets.add(fileset);
    
private voidcheckParameters()

        if (hasFilesets()) {
            if (getName() != null) {
                throw new BuildException(
                        "Cannot use <resource name=\"...\"> attribute with filesets");
            }
            if (getFile() != null) {
                throw new BuildException(
                        "Cannot use <resource file=\"...\"> attribute with filesets");
            }
        } else {
            if (getNamespace() != null) {
                throw new BuildException(
                        "Cannot use <resource namespace=\"...\"> attribute without filesets");
            }
        }
    
public java.io.FilegetFile()
The file resource.

return
the file resource.

        return file;
    
public java.lang.StringgetName()
The name of the resource.

return
the name of the resource.

        return name;
    
public java.lang.StringgetNamespace()
Filesets root namespace. The value always ends with '.' .

return
String namespace name

        return namespace;
    
private java.lang.StringgetParameter(java.lang.String fileName, java.lang.String name, boolean csharpStyle)

        StringBuffer buffer = new StringBuffer();
        buffer.append(isEmbed() ? "/resource" : "/linkresource");
        buffer.append(':");
        buffer.append(fileName);
        if (name != null) {
            buffer.append(',");
            buffer.append(name);
            if (csharpStyle) {
                if (getPublic() != null) {
                    throw new BuildException("This compiler does not support the "
                            + "public/private option.");
                } else {
                    if (getPublic() != null) {
                        buffer.append(',");
                        buffer.append(getPublic().booleanValue() ? "public" : "private");

                    }
                }
            } else if (getPublic() != null) {
                throw new BuildException("You cannot have a public or private "
                        + "option without naming the resource");
            }
        }
        return buffer.toString();
    
public voidgetParameters(org.apache.tools.ant.Project p, NetCommand command, boolean csharpStyle)
build the C# style parameter (which has no public/private option)

param
p the current project.
param
command the command.
param
csharpStyle a boolean attribute.

        checkParameters();
        if (hasFilesets()) {
            for (Iterator listIter = fileSets.iterator(); listIter.hasNext();) {
                FileSet fs = (FileSet) listIter.next();
                String baseDirectory = fs.getDir(p).toString();
                String namespace = getNamespace(); // ends with '.' or null
                DirectoryScanner ds = fs.getDirectoryScanner(p);
                String[] files = ds.getIncludedFiles();
                for (int i = 0; i < files.length; i++) {
                    String file = files[i];
                    command.addArgument(getParameter(baseDirectory + File.separatorChar + file,
                            (namespace == null ? null : namespace
                                    + file.replace(File.separatorChar, '.")), csharpStyle));
                }
            }
        } else {
            command.addArgument(getParameter(getFile().toString(), getName(), csharpStyle));
        }
    
public java.lang.BooleangetPublic()
Get the public attribute.

return
the public attribute.

        return isPublic;
    
public booleanhasFilesets()
Checks that node has embedded

return
boolean

        return fileSets.size() > 0;
    
public booleanisEmbed()
Return the embed attribute.

return
the embed value.


                 
       
        return embed;
    
public voidsetEmbed(boolean embed)
embed the resource in the assembly (default, true) or just link to it.

param
embed a boolean value.

        this.embed = embed;
    
public voidsetFile(java.io.File file)
name the resource

param
file the file.

        this.file = file;
    
public voidsetName(java.lang.String name)
should the resource have a name?

param
name the name of the resource.

        this.name = name;
    
public voidsetNamespace(java.lang.String namespace)
Sets filesets root namespace.

param
namespace String root namespace

        if (namespace == null) {
            this.namespace = null;
        } else {
            this.namespace = (namespace.length() == 0 || namespace.endsWith(".") ? namespace
                    : namespace + '.");
        }
    
public voidsetPublic(java.lang.Boolean aPublic)
VB and J# only: is a resource public or not?

param
aPublic a boolean value.

        isPublic = aPublic;