1 | /*
|
---|
2 | * Copyright 2000-2004 The Apache Software Foundation
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | *
|
---|
16 | */
|
---|
17 | package org.apache.tools.ant.taskdefs.optional.dotnet;
|
---|
18 |
|
---|
19 | import org.apache.tools.ant.BuildException;
|
---|
20 |
|
---|
21 | import java.io.File;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | * class used by DotnetCompile to name resources, could be upgraded to a datatype
|
---|
25 | * in the distant future.
|
---|
26 | * a resource maps to /res:file,name
|
---|
27 | */
|
---|
28 | public class DotnetResource {
|
---|
29 |
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * name of resource
|
---|
33 | */
|
---|
34 | private File file;
|
---|
35 |
|
---|
36 | /**
|
---|
37 | * embed (default) or link the resource
|
---|
38 | */
|
---|
39 | private boolean embed = true;
|
---|
40 |
|
---|
41 | /**
|
---|
42 | * this is used in VBC and JSC
|
---|
43 | */
|
---|
44 | private Boolean isPublic = null;
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * name of the object
|
---|
48 | */
|
---|
49 | private String name = null;
|
---|
50 |
|
---|
51 | public boolean isEmbed() {
|
---|
52 | return embed;
|
---|
53 | }
|
---|
54 |
|
---|
55 | /**
|
---|
56 | * embed the resource in the assembly (default, true) or just link to it.
|
---|
57 | * @param embed
|
---|
58 | */
|
---|
59 | public void setEmbed(boolean embed) {
|
---|
60 | this.embed = embed;
|
---|
61 | }
|
---|
62 |
|
---|
63 | public File getFile() {
|
---|
64 | return file;
|
---|
65 | }
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * name the resource
|
---|
69 | * @param file
|
---|
70 | */
|
---|
71 | public void setFile(File file) {
|
---|
72 | this.file = file;
|
---|
73 | }
|
---|
74 |
|
---|
75 | public Boolean getPublic() {
|
---|
76 | return isPublic;
|
---|
77 | }
|
---|
78 |
|
---|
79 | /**
|
---|
80 | * VB and J# only: is a resource public or not?
|
---|
81 | * @param aPublic
|
---|
82 | */
|
---|
83 | public void setPublic(Boolean aPublic) {
|
---|
84 | isPublic = aPublic;
|
---|
85 | }
|
---|
86 |
|
---|
87 | public String getName() {
|
---|
88 | return name;
|
---|
89 | }
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * should the resource have a name?
|
---|
93 | * @param name
|
---|
94 | */
|
---|
95 | public void setName(String name) {
|
---|
96 | this.name = name;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /**
|
---|
100 | * build the C# style parameter (which has no public/private option)
|
---|
101 | * @return the built C# style parameter
|
---|
102 | */
|
---|
103 | public String getCSharpStyleParameter() {
|
---|
104 | StringBuffer buffer = new StringBuffer();
|
---|
105 | buffer.append(isEmbed() ? "/resource" : "/linkresource");
|
---|
106 | buffer.append(':');
|
---|
107 | buffer.append(getFile().toString());
|
---|
108 | if (getName() != null) {
|
---|
109 | buffer.append(',');
|
---|
110 | buffer.append(getName());
|
---|
111 | }
|
---|
112 | if (getPublic() != null) {
|
---|
113 | throw new BuildException("This compiler does not support the "
|
---|
114 | + "public/private option.");
|
---|
115 | }
|
---|
116 | return buffer.toString();
|
---|
117 | }
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * This method gets the style of param used by VB and javascript
|
---|
121 | * @return The style VB parameter being used.
|
---|
122 | */
|
---|
123 | public String getVbStyleParameter() {
|
---|
124 | StringBuffer buffer = new StringBuffer();
|
---|
125 | buffer.append(isEmbed() ? "/resource" : "/linkresource");
|
---|
126 | buffer.append(':');
|
---|
127 | buffer.append(getFile().toString());
|
---|
128 | if (getName() != null) {
|
---|
129 | buffer.append(',');
|
---|
130 | buffer.append(getName());
|
---|
131 | if (getPublic() != null) {
|
---|
132 | buffer.append(',');
|
---|
133 | buffer.append(getPublic().booleanValue()
|
---|
134 | ? "public" : "private");
|
---|
135 |
|
---|
136 | }
|
---|
137 | } else if (getPublic() != null) {
|
---|
138 | throw new BuildException("You cannot have a public or private "
|
---|
139 | + "option without naming the resource");
|
---|
140 | }
|
---|
141 | return buffer.toString();
|
---|
142 | }
|
---|
143 | }
|
---|