001: /*
002: * sqlc 1
003: * SQL Compiler
004: * Copyright (C) 2003 Hammurapi Group
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2 of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: *
020: * URL: http://www.hammurapi.biz/products/sqlc/index.html
021: * e-Mail: support@hammurapi.biz
022: */
023: package biz.hammurapi.sqlc;
024:
025: import org.apache.tools.ant.AntClassLoader;
026: import org.apache.tools.ant.BuildException;
027: import org.apache.tools.ant.Task;
028: import org.apache.tools.ant.types.Path;
029:
030: /**
031: * Interface to extend
032: * @ant.element name="interface"
033: * @author Pavel Vlasov
034: * @version $Revision: 1.3 $
035: */
036: public class InterfaceEntry extends Task {
037: private ClassLoader classLoader;
038:
039: void setClassLoader(ClassLoader classLoader) {
040: this .classLoader = classLoader;
041: }
042:
043: /**
044: * Interface name.
045: * @ant.required
046: * @param name
047: */
048: public void setName(String name) {
049: this .interfaceName = name;
050: }
051:
052: /**
053: * Maybe creates a nested classpath element.
054: * @ant :non-required
055: */
056: public Path createClasspath() {
057: if (classPath == null) {
058: classPath = new Path(getProject());
059: }
060: return classPath.createPath();
061: }
062:
063: public void setClassPath(Path classPath) {
064: if (this .classPath == null) {
065: this .classPath = classPath;
066: } else {
067: this .classPath.append(classPath);
068: }
069: }
070:
071: /**
072: * Classpath for loading classes.
073: * @ant :non-required
074: */
075: protected Path classPath;
076:
077: private String interfaceName;
078:
079: Class getInterface() {
080: try {
081: Class ret;
082: if (classPath == null) {
083: ret = Class.forName(interfaceName);
084: } else if (classLoader == null) {
085: ret = new AntClassLoader(getProject(), classPath)
086: .loadClass(interfaceName);
087: } else {
088: ret = new AntClassLoader(classLoader, getProject(),
089: classPath, true).loadClass(interfaceName);
090: }
091:
092: if (!ret.isInterface()) {
093: throw new BuildException(ret.getName()
094: + " is not an interface");
095: }
096: return ret;
097: } catch (ClassNotFoundException e) {
098: throw new BuildException("Class not found: " + e, e);
099: }
100: }
101: }
|