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. import org.apache.tools.ant.BuildException;
  19. import java.io.File;
  20. /**
  21. * class used by DotnetCompile to name resources, could be upgraded to a datatype
  22. * in the distant future.
  23. * a resource maps to /res:file,name
  24. */
  25. public class DotnetResource {
  26. /**
  27. * name of resource
  28. */
  29. private File file;
  30. /**
  31. * embed (default) or link the resource
  32. */
  33. private boolean embed = true;
  34. /**
  35. * this is used in VBC and JSC
  36. */
  37. private Boolean isPublic = null;
  38. /**
  39. * name of the object
  40. */
  41. private String name = null;
  42. public boolean isEmbed() {
  43. return embed;
  44. }
  45. /**
  46. * embed the resource in the assembly (default, true) or just link to it.
  47. * @param embed
  48. */
  49. public void setEmbed(boolean embed) {
  50. this.embed = embed;
  51. }
  52. public File getFile() {
  53. return file;
  54. }
  55. /**
  56. * name the resource
  57. * @param file
  58. */
  59. public void setFile(File file) {
  60. this.file = file;
  61. }
  62. public Boolean getPublic() {
  63. return isPublic;
  64. }
  65. /**
  66. * VB and J# only: is a resource public or not?
  67. * @param aPublic
  68. */
  69. public void setPublic(Boolean aPublic) {
  70. isPublic = aPublic;
  71. }
  72. public String getName() {
  73. return name;
  74. }
  75. /**
  76. * should the resource have a name?
  77. * @param name
  78. */
  79. public void setName(String name) {
  80. this.name = name;
  81. }
  82. /**
  83. * build the C# style parameter (which has no public/private option)
  84. * @return the built C# style parameter
  85. */
  86. public String getCSharpStyleParameter() {
  87. StringBuffer buffer = new StringBuffer();
  88. buffer.append(isEmbed() ? "/resource" : "/linkresource");
  89. buffer.append(':');
  90. buffer.append(getFile().toString());
  91. if (getName() != null) {
  92. buffer.append(',');
  93. buffer.append(getName());
  94. }
  95. if (getPublic() != null) {
  96. throw new BuildException("This compiler does not support the "
  97. + "public/private option.");
  98. }
  99. return buffer.toString();
  100. }
  101. /**
  102. * This method gets the style of param used by VB and javascript
  103. * @return The style VB parameter being used.
  104. */
  105. public String getVbStyleParameter() {
  106. StringBuffer buffer = new StringBuffer();
  107. buffer.append(isEmbed() ? "/resource" : "/linkresource");
  108. buffer.append(':');
  109. buffer.append(getFile().toString());
  110. if (getName() != null) {
  111. buffer.append(',');
  112. buffer.append(getName());
  113. if (getPublic() != null) {
  114. buffer.append(',');
  115. buffer.append(getPublic().booleanValue()
  116. ? "public" : "private");
  117. }
  118. } else if (getPublic() != null) {
  119. throw new BuildException("You cannot have a public or private "
  120. + "option without naming the resource");
  121. }
  122. return buffer.toString();
  123. }
  124. }