[jboss-cvs] JBossAS SVN: r106074 - projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jun 15 16:50:48 EDT 2010
Author: alesj
Date: 2010-06-15 16:50:48 -0400 (Tue, 15 Jun 2010)
New Revision: 106074
Added:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ResourceNamedInputStream.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/VirtualFileNamedInputStream.java
Modified:
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/LazyNamedInputStream.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/PatternVisitor.java
projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java
Log:
Make I/O lazy.
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/LazyNamedInputStream.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/LazyNamedInputStream.java 2010-06-15 20:28:02 UTC (rev 106073)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/LazyNamedInputStream.java 2010-06-15 20:50:48 UTC (rev 106074)
@@ -25,8 +25,6 @@
import java.io.IOException;
import java.io.InputStream;
-import org.jboss.classloading.spi.visitor.ResourceContext;
-
import org.hibernate.ejb.packaging.NamedInputStream;
/**
@@ -34,28 +32,38 @@
*
* @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
*/
-public class LazyNamedInputStream extends NamedInputStream
+public abstract class LazyNamedInputStream extends NamedInputStream
{
- private ResourceContext resource;
-
- public LazyNamedInputStream(ResourceContext resource)
+ public LazyNamedInputStream(String name)
{
- // null check is already done in getName
- super(PatternFilter.getName(resource), null);
- this.resource = resource;
+ super(name, null);
}
+ /**
+ * Get lazy input stream.
+ *
+ * @return the input stream
+ * @throws IOException for any I/O error
+ */
+ protected abstract InputStream getLazyStream() throws IOException;
+
@Override
public InputStream getStream()
{
- try
+ InputStream is = super.getStream();
+ if (is == null)
{
- return resource.getInputStream();
+ try
+ {
+ is = getLazyStream();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ super.setStream(is);
}
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
+ return is;
}
@Override
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/PatternVisitor.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/PatternVisitor.java 2010-06-15 20:28:02 UTC (rev 106073)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/PatternVisitor.java 2010-06-15 20:50:48 UTC (rev 106074)
@@ -59,6 +59,6 @@
public void visit(ResourceContext resource)
{
URL ownerURL = scanner.getOwnerURL(resource);
- scanner.addFile(ownerURL, pattern, new LazyNamedInputStream(resource));
+ scanner.addFile(ownerURL, pattern, new ResourceNamedInputStream(resource));
}
}
\ No newline at end of file
Copied: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ResourceNamedInputStream.java (from rev 106056, projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/LazyNamedInputStream.java)
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ResourceNamedInputStream.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ResourceNamedInputStream.java 2010-06-15 20:50:48 UTC (rev 106074)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.hibernate;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.jboss.classloading.spi.visitor.ResourceContext;
+
+/**
+ * Resource context named input stream.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ResourceNamedInputStream extends LazyNamedInputStream
+{
+ private ResourceContext resource;
+
+ public ResourceNamedInputStream(ResourceContext resource)
+ {
+ // null check is already done in getName
+ super(PatternFilter.getName(resource));
+ this.resource = resource;
+ }
+
+ protected InputStream getLazyStream() throws IOException
+ {
+ return resource.getInputStream();
+ }
+}
\ No newline at end of file
Modified: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java 2010-06-15 20:28:02 UTC (rev 106073)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/ScannerImpl.java 2010-06-15 20:50:48 UTC (rev 106074)
@@ -411,20 +411,13 @@
private Set<NamedInputStream> toNIS(Iterable<VirtualFile> files)
{
- try
+ Set<NamedInputStream> result = new HashSet<NamedInputStream>();
+ for (VirtualFile file : files)
{
- Set<NamedInputStream> result = new HashSet<NamedInputStream>();
- for (VirtualFile file : files)
- {
- NamedInputStream nis = new NamedInputStream(file.getName(), file.openStream());
- result.add(nis);
- }
- return result;
+ NamedInputStream nis = new VirtualFileNamedInputStream(file);
+ result.add(nis);
}
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
+ return result;
}
// For back compatible Hibernate versions
Copied: projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/VirtualFileNamedInputStream.java (from rev 106056, projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/LazyNamedInputStream.java)
===================================================================
--- projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/VirtualFileNamedInputStream.java (rev 0)
+++ projects/scanning/trunk/plugins/src/main/java/org/jboss/scanning/hibernate/VirtualFileNamedInputStream.java 2010-06-15 20:50:48 UTC (rev 106074)
@@ -0,0 +1,56 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.scanning.hibernate;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import org.jboss.vfs.VirtualFile;
+
+/**
+ * VFS named input stream.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class VirtualFileNamedInputStream extends LazyNamedInputStream
+{
+ private VirtualFile file;
+
+ private static String name(VirtualFile file)
+ {
+ if (file == null)
+ throw new IllegalArgumentException("Null file");
+ return file.getName();
+ }
+
+ public VirtualFileNamedInputStream(VirtualFile file)
+ {
+ super(name(file));
+ this.file = file;
+ }
+
+ protected InputStream getLazyStream() throws IOException
+ {
+ return file.openStream();
+ }
+}
\ No newline at end of file
More information about the jboss-cvs-commits
mailing list