You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by ds...@apache.org on 2009/09/14 14:16:02 UTC
svn commit: r814601 - in
/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl:
AbstractOBRBundleRepository.java CachingOBRBundleRepository.java
NonCachingOBRBundleRepository.java
Author: dsavage
Date: Mon Sep 14 12:16:01 2009
New Revision: 814601
URL: http://svn.apache.org/viewvc?rev=814601&view=rev
Log:
tidy up handling of caching local obr file
Modified:
felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/AbstractOBRBundleRepository.java
felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/CachingOBRBundleRepository.java
felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/NonCachingOBRBundleRepository.java
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/AbstractOBRBundleRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/AbstractOBRBundleRepository.java?rev=814601&r1=814600&r2=814601&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/AbstractOBRBundleRepository.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/AbstractOBRBundleRepository.java Mon Sep 14 12:16:01 2009
@@ -29,10 +29,12 @@
import java.net.URL;
import java.net.URLConnection;
+import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.felix.sigil.repository.AbstractBundleRepository;
+import org.xml.sax.SAXException;
public abstract class AbstractOBRBundleRepository extends AbstractBundleRepository
@@ -61,64 +63,86 @@
}
- protected void readBundles( OBRListener listener ) throws Exception
+ protected void readBundles( OBRListener listener )
{
- syncOBRIndex();
+ File index = syncOBRIndex();
OBRHandler handler = new OBRHandler( getObrURL(), getBundleCache(), listener );
- SAXParser parser = factory.newSAXParser();
- parser.parse( findLocalOBR(), handler );
+ try
+ {
+ SAXParser parser = factory.newSAXParser();
+ parser.parse( index, handler );
+ }
+ catch ( ParserConfigurationException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch ( SAXException e )
+ {
+ System.out.println( "Failed to parse " + index );
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
- private File findLocalOBR()
+ private File syncOBRIndex()
{
+ File file = null;
if ( "file".equals( getObrURL().getProtocol() ) ) {
try
{
- return new File( getObrURL().toURI() );
+ file = new File( getObrURL().toURI() );
}
catch ( URISyntaxException e )
{
// should be impossible ?
throw new IllegalStateException( "Failed to convert file url to uri", e );
- }
+ }
}
else {
- return getObrlCache();
+ file = getObrlCache();
+ if ( isUpdated() )
+ {
+ cacheIndex(file);
+ }
}
+
+ return file;
}
- private void syncOBRIndex()
+ private void cacheIndex(File file)
{
- if ( !"file".equals( getObrURL().getProtocol() ) && isUpdated() )
- {
- InputStream in = null;
- OutputStream out = null;
+ InputStream in = null;
+ OutputStream out = null;
- try
- {
- URLConnection c = getObrURL().openConnection();
- c.connect();
- in = c.getInputStream();
- File file = getObrlCache();
- if ( !file.getParentFile().exists() && !file.getParentFile().mkdirs() )
- {
- throw new IOException( "Failed to create obr cache dir " + file.getParentFile() );
- }
- out = new FileOutputStream( file );
- stream( in, out );
- }
- catch ( IOException e )
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- getObrlCache().setLastModified( 0 );
- }
- finally
+ try
+ {
+ URLConnection c = getObrURL().openConnection();
+ c.connect();
+ in = c.getInputStream();
+ if ( !file.getParentFile().exists() && !file.getParentFile().mkdirs() )
{
- close( in, out );
+ throw new IOException( "Failed to create obr cache dir " + file.getParentFile() );
}
+ out = new FileOutputStream( file );
+ stream( in, out );
+ }
+ catch ( IOException e )
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ getObrlCache().setLastModified( 0 );
+ }
+ finally
+ {
+ close( in, out );
}
}
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/CachingOBRBundleRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/CachingOBRBundleRepository.java?rev=814601&r1=814600&r2=814601&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/CachingOBRBundleRepository.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/CachingOBRBundleRepository.java Mon Sep 14 12:16:01 2009
@@ -71,24 +71,16 @@
List<ISigilBundle> cached = bundles == null ? null : bundles.get();
if ( cached == null )
{
- try
+ final LinkedList<ISigilBundle> read = new LinkedList<ISigilBundle>();
+ readBundles( new OBRListener()
{
- final LinkedList<ISigilBundle> read = new LinkedList<ISigilBundle>();
- readBundles( new OBRListener()
+ public void handleBundle( ISigilBundle bundle )
{
- public void handleBundle( ISigilBundle bundle )
- {
- read.add( bundle );
- }
- } );
- cached = read;
- bundles = new SoftReference<List<ISigilBundle>>( cached );
- }
- catch ( Exception e )
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ read.add( bundle );
+ }
+ } );
+ cached = read;
+ bundles = new SoftReference<List<ISigilBundle>>( cached );
}
return cached;
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/NonCachingOBRBundleRepository.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/NonCachingOBRBundleRepository.java?rev=814601&r1=814600&r2=814601&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/NonCachingOBRBundleRepository.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/obr/impl/NonCachingOBRBundleRepository.java Mon Sep 14 12:16:01 2009
@@ -55,27 +55,19 @@
@Override
public void accept( final IRepositoryVisitor visitor, int options )
{
- try
+ readBundles( new OBRListener()
{
- readBundles( new OBRListener()
- {
- boolean visit = true;
+ boolean visit = true;
- public void handleBundle( ISigilBundle bundle )
+ public void handleBundle( ISigilBundle bundle )
+ {
+ if ( visit )
{
- if ( visit )
- {
- visit = visitor.visit( bundle );
- }
+ visit = visitor.visit( bundle );
}
- } );
- }
- catch ( Exception e )
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ }
+ } );
}
}