diff options
author | kitfox | 2007-05-29 23:56:56 +0200 |
---|---|---|
committer | kitfox | 2007-05-29 23:56:56 +0200 |
commit | c31602a69e3e03cde5b2362faadefbb0f751d60d (patch) | |
tree | 6e34d2037ce308e860d93a6d5a7006c0a9dc88a0 | |
parent | Restructuring content. (diff) | |
download | svg-salamander-core-c31602a69e3e03cde5b2362faadefbb0f751d60d.tar.gz svg-salamander-core-c31602a69e3e03cde5b2362faadefbb0f751d60d.tar.xz svg-salamander-core-c31602a69e3e03cde5b2362faadefbb0f751d60d.zip |
reverting to original source tree
git-svn-id: https://svn.java.net/svn/svgsalamander~svn/trunk/svg-core@35 7dc7fa77-23fb-e6ad-8e2e-c86bd48ed22b
9 files changed, 0 insertions, 1007 deletions
diff --git a/src/main/java/com/kitfox/salamander/SVGConstants.java b/src/main/java/com/kitfox/salamander/SVGConstants.java deleted file mode 100755 index 2e4b120..0000000 --- a/src/main/java/com/kitfox/salamander/SVGConstants.java +++ /dev/null @@ -1,22 +0,0 @@ -/*
- * SVGConstants.java
- *
- * Created on April 12, 2007, 7:13 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander;
-
-/**
- *
- * @author kitfox
- */
-public interface SVGConstants
-{
- public static final String NAMESPACE_SVG = "http://www.w3.org/2000/svg";
- public static final String PUBLIC_IDENTIFIER_SVG = "PUBLIC \"-//W3C//DTD SVG 1.1//EN\"";
- public static final String SYSTEM_IDENTIFIER_SVG = "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd";
- public static final String MIME_TYPE_SVG = "image/svg+xml";
-}
diff --git a/src/main/java/com/kitfox/salamander/parser/SVGParser.java b/src/main/java/com/kitfox/salamander/parser/SVGParser.java deleted file mode 100755 index d588b08..0000000 --- a/src/main/java/com/kitfox/salamander/parser/SVGParser.java +++ /dev/null @@ -1,96 +0,0 @@ -/*
- * SVGParser.java
- *
- * Created on April 11, 2007, 5:07 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.parser;
-
-import java.io.BufferedInputStream;
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
-
-/**
- *
- * @author kitfox
- */
-public class SVGParser
-{
- public static interface SVGParserListener
- {
-
- }
-
- /** Creates a new instance of SVGParser */
- public SVGParser()
- {
- }
-
- /**
- * Parse an SVG document. The document may be either uncompressed XML (.svg)
- * or a zipped document (.svgz). This routine will automatically detect
- * zipped documents and unzip them.
- */
- public static void parse(File source, SVGParserListener listener)
- {
- try
- {
- XMLReader parser;
- parser = XMLReaderFactory.createXMLReader();
- SVGParserHandler handler = new SVGParserHandler(listener);
- parser.setContentHandler(handler);
-
- FileInputStream fis = new FileInputStream(source);
- BufferedInputStream bis = new BufferedInputStream(fis);
- bis.mark(4);
- //Check for gzip magic number
- DataInputStream din = new DataInputStream(bis);
- long magicNumber = din.readLong();
- bis.reset();
-
- InputStream svgStream;
- if ((int)magicNumber == 0x4b50)
- {
- //PK Zip file
- ZipInputStream zin = new ZipInputStream(bis);
- ZipEntry entry = zin.getNextEntry();
- byte[] buf = new byte[(int)entry.getSize()];
- for (int offset = 0; offset < buf.length; offset += zin.read(buf, offset, buf.length - offset));
- zin.closeEntry();
- zin.close();
-
- svgStream = new ByteArrayInputStream(buf);
- }
- else
- {
- //Treat input as uncompressed XML
- svgStream = bis;
- }
-
- InputSource is = new InputSource(svgStream);
- parser.parse(is);
-
- }
- catch (SAXException ex)
- {
- ex.printStackTrace();
- }
- catch (IOException ex)
- {
- ex.printStackTrace();
- }
- }
-}
diff --git a/src/main/java/com/kitfox/salamander/parser/SVGParserAntTask.java b/src/main/java/com/kitfox/salamander/parser/SVGParserAntTask.java deleted file mode 100755 index 4c7a251..0000000 --- a/src/main/java/com/kitfox/salamander/parser/SVGParserAntTask.java +++ /dev/null @@ -1,98 +0,0 @@ -/*
- * GraphicsCodeGenAntTask.java
- *
- * Created on March 3, 2007, 9:31 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.parser;
-
-import java.io.File;
-import java.util.ArrayList;
-import javax.imageio.ImageIO;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.FileScanner;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.FileSet;
-
-/**
- * This ant task examines a directory hierarchy containing .xml files and
- * for the XML files rooted in the GraphicsCodeGen.GRAPHICS_NS namespace,
- * causes code generation to be run. Task will only update code that is missing
- * or out of date to minimize processing time.
- *
- * <code>
- * <graphicsCodeGeneration>
- * <fileset dir="${root.dir}">
- * <include name="com/kitfox/monsters/** / *"/>
- * </fileset>
- * <fileset dir="${dir2}">
- * </fileset>
- * </graphicsCodeGeneration>
- * </code>
- *
- * @author kitfox
- */
-public class SVGParserAntTask extends Task
-{
-// Path examinePath;
- private ArrayList<FileSet> filesets = new ArrayList<FileSet>();
-
-
- /** Creates a new instance of GraphicsCodeGenAntTask */
- public SVGParserAntTask()
- {
- }
-
- /**
- * Adds a set of files.
- */
- public void addFileset(FileSet set)
- {
- filesets.add(set);
- }
-
- /**
- * The examine path should be a subset of the classpath and include all the
- * classes that should be examined for possible inclusion in the services list.
- */
-// public Path createExaminePath() throws BuildException
-// {
-// if (examinePath == null)
-// {
-// examinePath = new Path(getProject());
-// return examinePath;
-// }
-// throw new BuildException("Only one examine path can be set");
-// }
-
- public void execute() throws BuildException
- {
- /*
- //This is necessary for ImageIO to find all pluggable image readers on the
- // classpath
- ImageIO.scanForPlugins();
-
- for (FileSet fileSet: filesets)
- {
- FileScanner scanner = fileSet.getDirectoryScanner(getProject());
- String[] files = scanner.getIncludedFiles();
-
- File dir = fileSet.getDir();
-
- for (String fileName: files)
- {
-// if (!fileName.getName().endsWith(".xml")) continue;
- File file = new File(dir, fileName);
-//System.err.println("*****File " + file);
-
- //Conditionally generate code
- GraphicsCodeGen.generateCode(file, true);
- }
- }
- */
- }
-
-}
diff --git a/src/main/java/com/kitfox/salamander/parser/SVGParserHandler.java b/src/main/java/com/kitfox/salamander/parser/SVGParserHandler.java deleted file mode 100755 index 8119984..0000000 --- a/src/main/java/com/kitfox/salamander/parser/SVGParserHandler.java +++ /dev/null @@ -1,80 +0,0 @@ -/*
- * GraphicsDocumentHandler.java
- *
- * Created on March 3, 2007, 7:49 PM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.parser;
-
-import com.kitfox.salamander.parser.SVGParser.SVGParserListener;
-import org.xml.sax.Attributes;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.Locator;
-import org.xml.sax.SAXException;
-
-
-/**
- *
- * @author kitfox
- */
-public class SVGParserHandler implements ContentHandler
-{
-// LinkedList<CodeGenNode> nodeStack = new LinkedList<CodeGenNode>();
-
- final SVGParserListener listener;
-
- /** Creates a new instance of GraphicsDocumentHandler */
- public SVGParserHandler(SVGParserListener listener)
- {
- this.listener = listener;
- }
-
- public void setDocumentLocator(Locator locator)
- {
- }
-
- public void startDocument() throws SAXException
- {
- }
-
- public void endDocument() throws SAXException
- {
- }
-
- public void startPrefixMapping(String prefix, String uri) throws SAXException
- {
- }
-
- public void endPrefixMapping(String prefix) throws SAXException
- {
- }
-
- public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
- {
- }
-
-
- public void endElement(String uri, String localName, String qName) throws SAXException
- {
- }
-
- public void characters(char[] ch, int start, int length) throws SAXException
- {
- }
-
- public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
- {
- }
-
- public void processingInstruction(String target, String data) throws SAXException
- {
- }
-
- public void skippedEntity(String name) throws SAXException
- {
- }
-
-}
diff --git a/src/main/java/com/kitfox/salamander/renderer/SRMarkedNode.java b/src/main/java/com/kitfox/salamander/renderer/SRMarkedNode.java deleted file mode 100755 index 0b6aa00..0000000 --- a/src/main/java/com/kitfox/salamander/renderer/SRMarkedNode.java +++ /dev/null @@ -1,42 +0,0 @@ -/*
- * SRTreeNode.java
- *
- * Created on April 12, 2007, 8:07 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.renderer;
-
-import com.kitfox.salamander.renderer.SRTreeNode.RenderingSurface;
-import java.awt.geom.Point2D;
-import java.util.List;
-
-/**
- * Nodes that provide points where markers can be placed.
- *
- * @author kitfox
- */
-abstract public class SRMarkedNode extends SRTreeNode
-{
- /** Creates a new instance of SRTreeNode */
- public SRMarkedNode()
- {
- }
-
- abstract protected List<Point2D.Float> getMarkerPoints();
-
- /**
- * Draw content specific to this element (not including child elements)
- */
- protected void renderLocal(RenderingSurface surface)
- {
- super.renderLocal(surface);
-
- for (Point2D.Float pt: getMarkerPoints())
- {
- getMarkerPoints();
- }
- }
-}
diff --git a/src/main/java/com/kitfox/salamander/renderer/SRTreeNode.java b/src/main/java/com/kitfox/salamander/renderer/SRTreeNode.java deleted file mode 100755 index 6f88129..0000000 --- a/src/main/java/com/kitfox/salamander/renderer/SRTreeNode.java +++ /dev/null @@ -1,83 +0,0 @@ -/*
- * SRTreeNode.java
- *
- * Created on April 12, 2007, 8:07 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.renderer;
-
-import com.kitfox.salamander.renderer.SurfaceManager.SurfaceInfo;
-import java.util.ArrayList;
-
-/**
- *
- * @author kitfox
- */
-abstract public class SRTreeNode
-{
- public static class RenderingSurface
- {
- }
-
- ArrayList<SRTreeNode> children = new ArrayList<SRTreeNode>();
-
- /** Creates a new instance of SRTreeNode */
- public SRTreeNode()
- {
- }
-
- public void addChild(SRTreeNode child)
- {
- children.add(child);
- }
-
- public boolean removeChild(SRTreeNode child)
- {
- return children.remove(child);
- }
-
- protected void render(RenderingSurface surface)
- {
- /*
- if (isFiltered() || isComplexClipArea())
- {
- RenderingSurface oldSurf = surface;
- //New surface initialized to transparent black
- SurfaceInfo backing = SurfaceManager.getDefault().getSurface(width, height, surface.getGraphicsConfiguration());
- surface = new RenderingSurface(backing);
-
- renderLocal(surface);
-
- for (SRTreeNode child: children)
- {
- child.render(surface);
- }
-
- applyFilters(surface);
- applyClipArea();
- oldSurf.overlay(surface);
- }
- else
- {
- applyClipArea();
- renderLocal(surface);
-
- for (SRTreeNode child: children)
- {
- child.render(surface);
- }
- }
- */
- }
-
- /**
- * Draw content specific to this element (not including child elements)
- */
- protected void renderLocal(RenderingSurface surface)
- {
- //No rendering by default
- }
-}
diff --git a/src/main/java/com/kitfox/salamander/renderer/SurfaceManager.java b/src/main/java/com/kitfox/salamander/renderer/SurfaceManager.java deleted file mode 100755 index 83cd227..0000000 --- a/src/main/java/com/kitfox/salamander/renderer/SurfaceManager.java +++ /dev/null @@ -1,236 +0,0 @@ -/*
- * SurfaceManager.java
- *
- * Created on April 12, 2007, 8:37 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.renderer;
-
-import java.awt.AlphaComposite;
-import java.awt.Graphics2D;
-import java.awt.GraphicsConfiguration;
-import java.awt.image.BufferedImage;
-import java.lang.ref.WeakReference;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.TreeSet;
-import java.util.WeakHashMap;
-
-/**
- *
- * @author kitfox
- */
-public class SurfaceManager implements Runnable
-{
- public class SurfaceInfo
- {
- private BufferedImage image;
- private BufImgInfo info;
-
- SurfaceInfo(BufferedImage image, BufImgInfo info)
- {
- this.image = image;
- this.info = info;
- }
-
- public BufferedImage getBuffer()
- {
- return image;
- }
-
- /**
- * Release resources to be recycled. Do not use the image after calling this.
- */
- public void dispose()
- {
- image = null;
- allocatedSurfs.remove(info);
- pooledSurfs.add(info);
- info.touch();
- info = null;
- }
- }
-
- static class BufImgInfo implements Comparable<BufImgInfo>
- {
- final int width;
- final int height;
- final int area;
- WeakReference<SurfaceInfo> surfRef;
- final BufferedImage image;
- long touchTime;
-
- BufImgInfo(BufferedImage image)
- {
- this.width = image.getWidth();
- this.height = image.getHeight();
- this.area = width * height;
-// ref = new SoftReference(img);
- this.image = image;
-// this.surfRef = new WeakReference<SurfaceInfo>(null);
- }
-
- public void attach(SurfaceInfo surf)
- {
- surfRef = new WeakReference(surf);
-// touch();
- }
-
- public int compareTo(SurfaceManager.BufImgInfo obj)
- {
- return area < obj.area ? -1 : (area > obj.area ? 1 : 0);
- }
-
- void touch()
- {
- touchTime = System.currentTimeMillis();
- }
- }
-
- private static final SurfaceManager singleton = new SurfaceManager();
- TreeSet<BufImgInfo> pooledSurfs = new TreeSet<BufImgInfo>();
- HashSet<BufImgInfo> allocatedSurfs = new HashSet<BufImgInfo>();
-// WeakHashMap<SurfaceInfo, BufImgInfo> surfaces = new WeakHashMap<SurfaceInfo, BufImgInfo>();
-
- int SWEEP_DELAY = 10000; //Every 10 seconds
-
- /** Creates a new instance of SurfaceManager */
- private SurfaceManager()
- {
- Thread thread = new Thread(this);
- thread.setDaemon(true);
- thread.start();
- }
-
- public static SurfaceManager getDefault()
- {
- return singleton;
- }
-
- /**
- * @return a new, cleared temporary surface to render upon. Remember to call
- * dispose() on the SurfaceInfo when you're finished with it.
- */
- public SurfaceInfo getSurface(int width, int height, GraphicsConfiguration gc)
- {
- SurfaceInfo surfInfo;
- BufImgInfo bufInfo = null;
- int targetArea = width * height;
-
- //Search for exising surface
- Iterator<BufImgInfo> it = pooledSurfs.iterator();
- for (; it.hasNext();)
- {
- BufImgInfo info = it.next();
- if (info.area >= targetArea)
- {
- if (info.width >= width && info.height >= height)
- {
- bufInfo = info;
- }
- break;
- }
- }
-
- if (bufInfo == null)
- {
- for (; it.hasNext();)
- {
- BufImgInfo info = it.next();
- if (info.area / 2 <= targetArea)
- {
- //Do not use exceptionally poorly fit buffers
- break;
- }
- if (info.width >= width && info.height >= height)
- {
- bufInfo = info;
- break;
- }
- }
- }
-
- if (bufInfo != null)
- {
- //Refurbish
-// BufferedImage img = bufInfo.ref.get();
- BufferedImage img = bufInfo.image;
-
- Graphics2D g = img.createGraphics();
-
- g.setComposite(AlphaComposite.Clear);
- g.fillRect(0, 0, width, height);
-
- g.dispose();
-
- surfInfo = new SurfaceInfo(img.getSubimage(0, 0, width, height), bufInfo);
-// surfaces.put(surfInfo, bufInfo);
- allocatedSurfs.add(bufInfo);
- pooledSurfs.remove(bufInfo);
- }
- else
- {
- //Create a new surface
- BufferedImage img;
- if (gc.getColorModel().hasAlpha())
- {
- img = gc.createCompatibleImage(width, height);
- }
- else
- {
- img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
- }
-
- bufInfo = new BufImgInfo(img);
- surfInfo = new SurfaceInfo(img, bufInfo);
-// surfaces.put(surfInfo, bufInfo);
- allocatedSurfs.add(bufInfo);
- }
-
- bufInfo.attach(surfInfo);
- return surfInfo;
- }
-
- public void run()
- {
- while (true)
- {
- /*
- //Clean up memory leaked images
- for (Iterator<BufImgInfo> it = allocatedSurfs.iterator(); it.hasNext();)
- {
- BufImgInfo info = it.next();
- if (info.surfRef.get() == null)
- {
- it.remove();
- pooledSurfs.add(info);
- info.touch();
- }
- }
- */
-
- //Kill out of date pooled surfaces
- long curTime = System.currentTimeMillis();
- for (Iterator<BufImgInfo> it = pooledSurfs.iterator(); it.hasNext();)
- {
- BufImgInfo info = it.next();
- if ((curTime - info.touchTime) > SWEEP_DELAY)
- {
- it.remove();
- }
- }
-
- try
- {
- Thread.sleep(1000);
- }
- catch (InterruptedException ex)
- {
- ex.printStackTrace();
- }
- }
- }
-}
diff --git a/src/main/java/com/kitfox/salamander/writer/SVGWriter.java b/src/main/java/com/kitfox/salamander/writer/SVGWriter.java deleted file mode 100755 index 4d51fc5..0000000 --- a/src/main/java/com/kitfox/salamander/writer/SVGWriter.java +++ /dev/null @@ -1,34 +0,0 @@ -/*
- * SVGWriter.java
- *
- * Created on April 12, 2007, 7:17 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.salamander.writer;
-
-import com.kitfox.salamander.SVGConstants;
-import java.io.PrintWriter;
-
-/**
- *
- * @author kitfox
- */
-public class SVGWriter implements SVGConstants
-{
- final PrintWriter pw;
-
- /** Creates a new instance of SVGWriter */
- public SVGWriter(PrintWriter pw)
- {
- this.pw = pw;
- }
-
- private void writeHeader()
- {
- pw.printf("<!DOCTYPE svg %s \"%s\"\n", PUBLIC_IDENTIFIER_SVG, SYSTEM_IDENTIFIER_SVG);
- }
-
-}
diff --git a/src/main/java/com/kitfox/util/ServicesListerAntTask.java b/src/main/java/com/kitfox/util/ServicesListerAntTask.java deleted file mode 100755 index 7d8bc4c..0000000 --- a/src/main/java/com/kitfox/util/ServicesListerAntTask.java +++ /dev/null @@ -1,316 +0,0 @@ -/*
- * ServicesListerAntTask.java
- *
- * Created on September 17, 2006, 4:08 AM
- *
- * To change this template, choose Tools | Template Manager
- * and open the template in the editor.
- */
-
-package com.kitfox.util;
-
-import java.io.BufferedWriter;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.FilenameFilter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.lang.reflect.Modifier;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.Iterator;
-import org.apache.tools.ant.taskdefs.DefBase;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.types.Resource;
-import org.apache.tools.ant.types.resources.FileResource;
-
-/**
- * This ant task examines a directory hierarchy containing .class files and
- * constructs lists of all classes that extend a given base class. This
- * is meant to facilitate the generation of META-INF/services lists
- * for jar files.
- *
- * <code>
- * <servicesLister>
- * <examinepath>
- * <pathelement location="${path-to-find-classfiles-to-be-analyzed}">
- * </examinepath>
- * <classpath>
- * <pathelement location="${classpath-needed-to-construct-Class-objects-of-classes-in-examine-path}">
- * </classpath>
- * <service className="name.of.class.to.build.list.For1" toDir="location/to/save/generated.list1">
- * <service className="name.of.class.to.build.list.For2" toDir="location/to/save/generated.list2">
- * </servicesLister>
- * </code>
- *
- * @author kitfox
- */
-public class ServicesListerAntTask extends DefBase
-{
- /**
- * Contains info for a single service to generate a list for. There may be
- * zero or more services tags embedded in the servicesLister task.
- *
- * If the toFile parameter is set to the name of a directory, the output
- * file name is computed at new File(toFile, className)
- */
- public class Service
- {
- private String className;
- private File toFile;
- private File toDir;
- private Class targetClass;
-
- ArrayList<String> targets = new ArrayList<String>();
-
- public String getClassName()
- {
- return className;
- }
-
- public void setClassName(String className)
- {
- this.className = className;
- }
-
- public File getToFile()
- {
- return toFile;
- }
-
- public void setToFile(File toFile)
- {
- this.toFile = toFile;
- }
-
- public File getToDir()
- {
- return toDir;
- }
-
- public void setToDir(File toDir)
- {
- if (toDir.exists() && !toDir.isDirectory())
- {
- throw new BuildException("toDir argument must be a directory: " + toDir);
- }
- this.toDir = toDir;
- }
-
- public Class getTargetClass()
- {
- return targetClass;
- }
-
- public void setTargetClass(Class targetClass)
- {
- this.targetClass = targetClass;
- }
-
- private void writeTarget(String className)
- {
- targets.add(className);
- }
-
- private void writeToFile()
- {
- try
- {
- if (toFile != null)
- {
- if (toFile.exists() && toFile.isDirectory())
- {
- toFile = new File(toFile, className);
- }
- }
- else
- {
- if (toDir == null)
- {
- throw new BuildException("Must specify either a toFile or a toDir parameter");
- }
- toFile = new File(toDir, className);
- }
-
-
- //Make sure parent directory exists
- File parent = toFile.getParentFile();
- if (!parent.exists())
- {
- parent.mkdirs();
- }
-
- FileWriter fout = new FileWriter(toFile);
- PrintWriter pw = new PrintWriter(new BufferedWriter(fout));
-
- pw.println("#Automatically generated services list");
- pw.println("#Mark McKay - " + new Date());
-
- for (String target: targets)
- {
- pw.println(target);
- }
-
- pw.close();
- }
- catch (IOException e)
- {
- throw new BuildException(e);
- }
- }
- }
-
- Path examinePath;
-// ResourceCollection targetRes;
- ArrayList<Service> services = new ArrayList<Service>();
-
- /**
- * The examine path should be a subset of the classpath and include all the
- * classes that should be examined for possible inclusion in the services list.
- */
- public Path createExaminePath() throws BuildException
- {
- if (examinePath == null)
- {
- examinePath = new Path(getProject());
- return examinePath;
- }
- throw new BuildException("Only one examine path can be set");
- }
-
- /*
- public void addFileSet(FileSet fileSet)
- {
- if (this.targetRes != null)
- {
- throw new BuildException("Resources to be examined set multiple times");
- }
- this.targetRes = fileSet;
- }
- */
-
- public Service createService()
- {
- Service service = new Service();
- services.add(service);
- return service;
- }
-
- /**
- * Creates a new instance of ServicesListerAntTask
- */
- public ServicesListerAntTask()
- {
- }
-
- static final FilenameFilter FFILTER_CLASS = new FilenameFilter()
- {
- public boolean accept(File dir, String name)
- {
- return name.endsWith(".class");
- }
- };
-
- public void scanPath(ClassLoader loader, File dir, File pathRoot)
- {
- String pathAbs = pathRoot.getAbsolutePath();
-//System.err.println("***Abs path: " + pathAbs);
-// File[] fileList = dir.listFiles(FFILTER_CLASS);
- for (File file: dir.listFiles())
- {
- if (file.getName().endsWith(".class"))
- {
- String fileAbs = file.getAbsolutePath();
-//System.err.println("***Abs file: " + fileAbs);
- String relName = fileAbs.substring(pathAbs.length() + 1, fileAbs.length() - ".class".length());
- relName = relName.replaceAll("[/\\\\]", ".");
-//System.err.println("***Rel name: " + relName);
- Class cls;
- try
- {
- cls = loader.loadClass(relName);
- }
- catch (ClassNotFoundException ex)
- {
- throw new BuildException(ex);
- }
-
- if (cls == null)
- {
- log("Could not examine class " + file);
- continue;
- }
- else
- {
- //Ignore classes that cannot be instantiated
- int mod = cls.getModifiers();
- if (!Modifier.isPublic(mod) || Modifier.isAbstract(mod) || Modifier.isInterface(mod))
- {
- continue;
- }
- }
-
- for (Service service: services)
- {
- if (service.getTargetClass().isAssignableFrom(cls))
- {
- service.writeTarget(relName);
- }
- }
- }
- else if (file.isDirectory())
- {
- scanPath(loader, file, pathRoot);
- }
- }
- }
-
- public void execute() throws BuildException
- {
- if (examinePath == null)
- {
- throw new BuildException("Examine path not set - please specify path to files to check for services");
- }
-
- ClassLoader loader = createLoader();
-
- for (Service service: services)
- {
- String name = service.getClassName();
- Class cls;
- try
- {
- cls = loader.loadClass(name);
- }
- catch (ClassNotFoundException ex)
- {
- throw new BuildException(String.format("Could not find %s in classpath", name), ex);
- }
- service.setTargetClass(cls);
- }
-
-
- for (Iterator it = examinePath.iterator(); it.hasNext();)
- {
- Resource res = (Resource)it.next();
- if (!(res instanceof FileResource)) continue;
-
-//System.err.println("*****Resource " + res.getName() + ", " + res.getClass().getName() + ", " + res.toString());
- File root = ((FileResource)res).getFile();
-//System.err.println("*****File " + Name() + " " + res);
-
- //Find all .class files under the path
- scanPath(loader, root, root);
- }
-
-
- //Write all to disk
- for (Service service: services)
- {
- service.writeToFile();
- }
-
- }
-
-}
|