Inspector | Message | Severity | Location |
---|---|---|---|
Java Inspector 048 | Copyrights information should be present in each file. | 1 | |
Java Inspector 058 | Make inner classes "private" | 1 | 60:9 |
Java Inspector 085 | Do not declare runtime exceptions in the throws clause. | 2 | 141:9 |
Java Inspector 089 | Parameter path is not documented | 2 | 68:17 |
Java Inspector 089 | Method documentation is too short. It is only 2 words. Should be at least 3 words. | 2 | 77:9 |
Java Inspector 089 | Method return value is not properly documented | 2 | 77:9 |
Java Inspector 089 | Undocumented constructor | 2 | 83:9 |
Java Inspector 089 | Parameter url is not documented | 2 | 98:9 |
Java Inspector 089 | Undocumented parameter file | 2 | 110:9 |
Java Inspector 089 | Javadoc contains tag for non-existent parameter url | 2 | 110:9 |
Java Inspector 089 | Undocumented parameter resource | 2 | 122:9 |
Java Inspector 089 | Javadoc contains tag for non-existent parameter url | 2 | 122:9 |
Java Inspector 089 | Undocumented method | 2 | 141:9 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 129:50 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 133:50 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 137:50 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 153:66 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 153:87 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 157:58 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 162:51 |
Java Inspector 026 | Avoid hardwired string literals. Allowed literals: [] | 3 | 163:64 |
1/*
2 * hgcommons 9
3 * Hammurapi Group Common Library
4 * Copyright (C) 2003 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.biz/hammurapi-biz/ef/xmenu/hammurapi-group/products/products/hgcommons/index.html
21 * e-Mail: support@hammurapi.biz
22 */
23package biz.hammurapi.ant;
24
25import java.io.File;
26import java.io.IOException;
27import java.io.InputStream;
28import java.net.URL;
29import java.util.ArrayList;
30import java.util.Collection;
31import java.util.Iterator;
32
33import org.apache.tools.ant.BuildException;
34import org.apache.tools.ant.Task;
35
36import biz.hammurapi.config.Command;
37import biz.hammurapi.config.ConfigurationException;
38import biz.hammurapi.config.Context;
39import biz.hammurapi.config.DomConfigFactory;
40import biz.hammurapi.config.DomConfigurableContainer;
41
42
43/**
44 * Container wrapped in Ant task.
45 * Instantiates container, mounts /logger and /taks and then
46 * executes nested <command> entries
47 * @ant.task name="Container" category="Common"
48 * @author Pavel Vlasov
49 * @revision $Revision$
50 */
51public class ContainerTask extends Task {
52 private Collection executes=new ArrayList();
53
54 /**
55 * Context to "execute".
56 * @ant.type name="Execute" category="Common"
57 * @author Pavel Vlasov
58 * @revision $Revision$
59 */
60 public class Execute extends ObjectEntry {
61 private String path;
62
63 /**
64 * Path to component to execute
65 * @ant.required
66 * @param path
67 */
68 public void setPath(String path) {
69 this.path=path;
70 }
71 }
72
73 /**
74 * Execute command
75 * @return
76 */
77 public Execute createExecute() {
78 Execute ret=new Execute();
79 executes.add(ret);
80 return ret;
81 }
82
83 public ContainerTask() {
84 super();
85 }
86
87 private String url;
88 private File file;
89 private String resource;
90
91 /**
92 * URL to load configuration from.
93 * One of URL, file or resource is mandatory.
94 * These attributes are mutually exclusive.
95 * @ant.not-required
96 * @param url
97 */
98 public void setUrl(String url) {
99 checkAlreadySet();
100 this.url=url;
101 }
102
103 /**
104 * File to load configuration from.
105 * One of URL, file or resource is mandatory.
106 * These attributes are mutually exclusive.
107 * @ant.not-required
108 * @param url
109 */
110 public void setFile(File file) {
111 checkAlreadySet();
112 this.file=file;
113 }
114
115 /**
116 * Classloader resource to load configuration from.
117 * One of URL, file or resource is mandatory.
118 * These attributes are mutually exclusive.
119 * @ant.not-required
120 * @param url
121 */
122 public void setResource(String resource) {
123 checkAlreadySet();
124 this.resource=resource;
125 }
126
127 private void checkAlreadySet() {
128 if (url!=null) {
129 throw new BuildException("url already set");
130 }
131
132 if (file!=null) {
133 throw new BuildException("file already set");
134 }
135
136 if (resource!=null) {
137 throw new BuildException("resource already set");
138 }
139 }
140
141 public void execute() throws BuildException {
142 try {
143 ClassLoader classLoader = getClass().getClassLoader();
144 DomConfigFactory factory=new DomConfigFactory(classLoader, (Context) null);
145 Object o;
146 if (url!=null) {
147 o=factory.create(new URL(url), null);
148 } else if (file!=null) {
149 o=factory.create(file, null);
150 } else if (resource!=null) {
151 InputStream in=classLoader.getResourceAsStream(resource);
152 if (in==null) {
153 throw new BuildException("Resource "+resource+" not found");
154 }
155 o=factory.create(in, null);
156 } else {
157 throw new BuildException("One of url, file or resource attributes must be set");
158 }
159
160 if (o instanceof DomConfigurableContainer) {
161 DomConfigurableContainer container=(DomConfigurableContainer) o;
162 if (container.get("task")==null) {
163 container.addComponent("task", this);
164 }
165
166 container.start();
167 try {
168 Iterator it=executes.iterator();
169 while (it.hasNext()) {
170 Execute execute=(Execute) it.next();
171 Object target=container.get(execute.path);
172 if (target instanceof Command) {
173 ((Command) target).execute(execute.getObject(classLoader));
174 }
175 }
176 } finally {
177 container.stop();
178 }
179 }
180 } catch (IOException e) {
181 throw new BuildException(e.toString(), e);
182 } catch (ConfigurationException e) {
183 throw new BuildException(e.toString(), e);
184 }
185
186 }
187
188
189}
190