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 2010/08/02 19:08:20 UTC
svn commit: r981604 [6/22] - in /felix/trunk/sigil:
common/core.tests/src/org/apache/felix/sigil/common/core/
common/core.tests/src/org/apache/felix/sigil/common/core/internal/model/osgi/
common/core/src/org/apache/felix/sigil/common/bnd/ common/core/s...
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/OBRHandler.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/OBRHandler.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/OBRHandler.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/OBRHandler.java Mon Aug 2 17:08:03 2010
@@ -19,7 +19,6 @@
package org.apache.felix.sigil.common.obr.impl;
-
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
@@ -49,7 +48,6 @@ import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import org.xml.sax.helpers.DefaultHandler;
-
final class OBRHandler extends DefaultHandler
{
private static final String PACKAGE = "package";
@@ -67,175 +65,178 @@ final class OBRHandler extends DefaultHa
private IPackageExport export;
private int depth;
-
- public OBRHandler( URL obrURL, File bundleCache, OBRListener listener )
+ public OBRHandler(URL obrURL, File bundleCache, OBRListener listener)
{
this.obrURL = obrURL;
this.cacheDir = bundleCache;
this.listener = listener;
}
-
- public void setDocumentLocator( Locator locator )
+ public void setDocumentLocator(Locator locator)
{
this.locator = locator;
}
-
- public void startElement( String uri, String localName, String qName, Attributes attributes ) throws SAXException
+ public void startElement(String uri, String localName, String qName,
+ Attributes attributes) throws SAXException
{
- if ( depth++ == 0 && !"repository".equals( qName ) ) {
- throw new SAXParseException("Invalid OBR document, expected repository top level element", locator);
+ if (depth++ == 0 && !"repository".equals(qName))
+ {
+ throw new SAXParseException(
+ "Invalid OBR document, expected repository top level element", locator);
}
- else if ( "resource".equals( qName ) )
+ else if ("resource".equals(qName))
{
- startResource( attributes );
+ startResource(attributes);
}
- else if ( "capability".equals( qName ) )
+ else if ("capability".equals(qName))
{
- startCapability( attributes );
+ startCapability(attributes);
}
- else if ( "require".equals( qName ) )
+ else if ("require".equals(qName))
{
- startRequire( attributes );
+ startRequire(attributes);
}
- else if ( "p".equals( qName ) )
+ else if ("p".equals(qName))
{
- startProperty( attributes );
+ startProperty(attributes);
}
}
-
- public void endElement( String uri, String localName, String qName ) throws SAXException
+ public void endElement(String uri, String localName, String qName)
+ throws SAXException
{
depth--;
- if ( "resource".equals( qName ) )
+ if ("resource".equals(qName))
{
endResource();
}
- else if ( "capability".equals( qName ) )
+ else if ("capability".equals(qName))
{
endCapability();
}
- else if ( "require".equals( qName ) )
+ else if ("require".equals(qName))
{
endRequire();
}
- else if ( "p".equals( qName ) )
+ else if ("p".equals(qName))
{
endProperty();
}
}
-
- private void startResource( Attributes attributes ) throws SAXException
+ private void startResource(Attributes attributes) throws SAXException
{
try
{
- String uri = attributes.getValue( "", URI );
- if ( uri.endsWith( ".jar" ) )
+ String uri = attributes.getValue("", URI);
+ if (uri.endsWith(".jar"))
{
- if ( !sanity.add( uri ) )
+ if (!sanity.add(uri))
{
- throw new RuntimeException( uri );
+ throw new RuntimeException(uri);
}
- ISigilBundle b = ModelElementFactory.getInstance().newModelElement( ISigilBundle.class );
- IBundleModelElement info = ModelElementFactory.getInstance()
- .newModelElement( IBundleModelElement.class );
- info.setSymbolicName( attributes.getValue( "", SYMBOLIC_NAME ) );
- info.setVersion( VersionTable.getVersion(attributes.getValue( "", VERSION ) ) );
- info.setName( attributes.getValue( "", PRESENTATION_NAME ) );
- URI l = makeAbsolute( uri );
- info.setUpdateLocation( l );
- if ( "file".equals( l.getScheme() ) ) {
- b.setLocation( new File( l ) );
+ ISigilBundle b = ModelElementFactory.getInstance().newModelElement(
+ ISigilBundle.class);
+ IBundleModelElement info = ModelElementFactory.getInstance().newModelElement(
+ IBundleModelElement.class);
+ info.setSymbolicName(attributes.getValue("", SYMBOLIC_NAME));
+ info.setVersion(VersionTable.getVersion(attributes.getValue("", VERSION)));
+ info.setName(attributes.getValue("", PRESENTATION_NAME));
+ URI l = makeAbsolute(uri);
+ info.setUpdateLocation(l);
+ if ("file".equals(l.getScheme()))
+ {
+ b.setLocation(new File(l));
}
- else {
- b.setLocation( cachePath( info ) );
+ else
+ {
+ b.setLocation(cachePath(info));
}
- b.setBundleInfo( info );
+ b.setBundleInfo(info);
bundle = b;
}
}
- catch ( Exception e )
+ catch (Exception e)
{
- throw new SAXParseException( "Failed to build bundle info", locator, e );
+ throw new SAXParseException("Failed to build bundle info", locator, e);
}
}
-
- private URI makeAbsolute( String uri ) throws URISyntaxException
+ private URI makeAbsolute(String uri) throws URISyntaxException
{
- URI l = new URI( uri );
- if ( !l.isAbsolute() )
+ URI l = new URI(uri);
+ if (!l.isAbsolute())
{
String base = obrURL.toExternalForm();
- int i = base.lastIndexOf( "/" );
- if ( i != -1 )
+ int i = base.lastIndexOf("/");
+ if (i != -1)
{
- base = base.substring( 0, i );
- l = new URI( base + ( uri.startsWith( "/" ) ? "" : "/" ) + uri );
+ base = base.substring(0, i);
+ l = new URI(base + (uri.startsWith("/") ? "" : "/") + uri);
}
}
return l;
}
-
- private File cachePath( IBundleModelElement info )
+ private File cachePath(IBundleModelElement info)
{
- return new File( cacheDir, info.getSymbolicName() + "_" + info.getVersion() + ".jar" );
+ return new File(cacheDir, info.getSymbolicName() + "_" + info.getVersion()
+ + ".jar");
}
-
- private void startCapability( Attributes attributes )
+ private void startCapability(Attributes attributes)
{
- if ( bundle != null )
+ if (bundle != null)
{
- if ( PACKAGE.equals( attributes.getValue( "", "name" ) ) )
+ if (PACKAGE.equals(attributes.getValue("", "name")))
{
- export = ModelElementFactory.getInstance().newModelElement( IPackageExport.class );
+ export = ModelElementFactory.getInstance().newModelElement(
+ IPackageExport.class);
}
}
}
-
- private void startRequire( Attributes attributes ) throws SAXParseException
+ private void startRequire(Attributes attributes) throws SAXParseException
{
- if ( bundle != null )
+ if (bundle != null)
{
- String name = attributes.getValue( "name" );
- if ( PACKAGE.equals( name ) )
+ String name = attributes.getValue("name");
+ if (PACKAGE.equals(name))
{
- IPackageImport pi = ModelElementFactory.getInstance().newModelElement( IPackageImport.class );
+ IPackageImport pi = ModelElementFactory.getInstance().newModelElement(
+ IPackageImport.class);
try
{
- LDAPExpr expr = LDAPParser.parseExpression( attributes.getValue( "filter" ) );
- pi.setPackageName( decodePackage( expr, locator ) );
- pi.setVersions( decodeVersions( expr, locator ) );
- pi.setOptional( Boolean.valueOf( attributes.getValue( "optional" ) ) );
- bundle.getBundleInfo().addImport( pi );
+ LDAPExpr expr = LDAPParser.parseExpression(attributes.getValue("filter"));
+ pi.setPackageName(decodePackage(expr, locator));
+ pi.setVersions(decodeVersions(expr, locator));
+ pi.setOptional(Boolean.valueOf(attributes.getValue("optional")));
+ bundle.getBundleInfo().addImport(pi);
}
- catch ( LDAPParseException e )
+ catch (LDAPParseException e)
{
- throw new SAXParseException( "Failed to parse filter", locator, e );
+ throw new SAXParseException("Failed to parse filter", locator, e);
}
}
- else if ( "bundle".equals( name ) )
+ else if ("bundle".equals(name))
{
- IRequiredBundle b = ModelElementFactory.getInstance().newModelElement( IRequiredBundle.class );
+ IRequiredBundle b = ModelElementFactory.getInstance().newModelElement(
+ IRequiredBundle.class);
try
{
- LDAPExpr expr = LDAPParser.parseExpression( attributes.getValue( "filter" ) );
- b.setSymbolicName( decodeSymbolicName( expr, locator ) );
- b.setVersions( decodeVersions( expr, locator ) );
- b.setOptional( Boolean.valueOf( attributes.getValue( "optional" ) ) );
- bundle.getBundleInfo().addRequiredBundle( b );
+ LDAPExpr expr = LDAPParser.parseExpression(attributes.getValue("filter"));
+ b.setSymbolicName(decodeSymbolicName(expr, locator));
+ b.setVersions(decodeVersions(expr, locator));
+ b.setOptional(Boolean.valueOf(attributes.getValue("optional")));
+ bundle.getBundleInfo().addRequiredBundle(b);
}
- catch ( Exception e )
+ catch (Exception e)
{
- System.err.println( "Failed to parse filter in bundle " + bundle.getBundleInfo().getSymbolicName() );
- throw new SAXParseException( "Failed to parse filter in bundle "
- + bundle.getBundleInfo().getSymbolicName(), locator, e );
+ System.err.println("Failed to parse filter in bundle "
+ + bundle.getBundleInfo().getSymbolicName());
+ throw new SAXParseException("Failed to parse filter in bundle "
+ + bundle.getBundleInfo().getSymbolicName(), locator, e);
}
}
//else if ( "ee".equals( name ) ) {
@@ -252,125 +253,120 @@ final class OBRHandler extends DefaultHa
}
}
-
- private static VersionRange decodeVersions( LDAPExpr expr, Locator locator ) throws SAXParseException
+ private static VersionRange decodeVersions(LDAPExpr expr, Locator locator)
+ throws SAXParseException
{
try
{
- return VersionRangeHelper.decodeVersions( expr );
+ return VersionRangeHelper.decodeVersions(expr);
}
- catch ( NumberFormatException e )
+ catch (NumberFormatException e)
{
- throw new SAXParseException( e.getMessage(), locator );
+ throw new SAXParseException(e.getMessage(), locator);
}
}
-
- private void startProperty( Attributes attributes )
+ private void startProperty(Attributes attributes)
{
- if ( export != null )
+ if (export != null)
{
- String name = attributes.getValue( "", "n" );
- String value = attributes.getValue( "", "v" );
- if ( PACKAGE.equals( name ) )
+ String name = attributes.getValue("", "n");
+ String value = attributes.getValue("", "v");
+ if (PACKAGE.equals(name))
{
- export.setPackageName( value );
+ export.setPackageName(value);
}
- else if ( "uses".equals( name ) )
+ else if ("uses".equals(name))
{
- String[] split = value.split( "," );
- export.setUses( Arrays.asList( split ) );
+ String[] split = value.split(",");
+ export.setUses(Arrays.asList(split));
}
- else if ( "version".equals( name ) )
+ else if ("version".equals(name))
{
- export.setVersion( VersionTable.getVersion( value ) );
+ export.setVersion(VersionTable.getVersion(value));
}
}
}
-
private void endResource()
{
- if ( bundle != null )
+ if (bundle != null)
{
- listener.handleBundle( bundle );
+ listener.handleBundle(bundle);
bundle = null;
}
}
-
private void endCapability()
{
- if ( bundle != null )
+ if (bundle != null)
{
- if ( export != null )
+ if (export != null)
{
- bundle.getBundleInfo().addExport( export );
+ bundle.getBundleInfo().addExport(export);
export = null;
}
}
}
-
private void endRequire()
{
// TODO Auto-generated method stub
}
-
private void endProperty()
{
// TODO Auto-generated method stub
}
-
- private static String decodePackage( LDAPExpr expr, Locator locator ) throws SAXParseException
+ private static String decodePackage(LDAPExpr expr, Locator locator)
+ throws SAXParseException
{
- ArrayList<SimpleTerm> terms = new ArrayList<SimpleTerm>( 1 );
+ ArrayList<SimpleTerm> terms = new ArrayList<SimpleTerm>(1);
- findTerms( "package", expr, terms );
+ findTerms("package", expr, terms);
- if ( terms.isEmpty() )
+ if (terms.isEmpty())
{
- throw new SAXParseException( "Missing name filter in " + expr, locator );
+ throw new SAXParseException("Missing name filter in " + expr, locator);
}
- return terms.get( 0 ).getRval();
+ return terms.get(0).getRval();
}
-
- private static String decodeSymbolicName( LDAPExpr expr, Locator locator ) throws SAXParseException
+ private static String decodeSymbolicName(LDAPExpr expr, Locator locator)
+ throws SAXParseException
{
- ArrayList<SimpleTerm> terms = new ArrayList<SimpleTerm>( 1 );
+ ArrayList<SimpleTerm> terms = new ArrayList<SimpleTerm>(1);
- findTerms( "symbolicname", expr, terms );
+ findTerms("symbolicname", expr, terms);
- if ( terms.isEmpty() )
+ if (terms.isEmpty())
{
- throw new SAXParseException( "Missing name filter in " + expr, locator );
+ throw new SAXParseException("Missing name filter in " + expr, locator);
}
- return terms.get( 0 ).getRval();
+ return terms.get(0).getRval();
}
-
- private static void findTerms( String string, LDAPExpr expr, List<SimpleTerm> terms ) throws SAXParseException
+ private static void findTerms(String string, LDAPExpr expr, List<SimpleTerm> terms)
+ throws SAXParseException
{
- if ( expr instanceof SimpleTerm )
+ if (expr instanceof SimpleTerm)
{
- SimpleTerm term = ( SimpleTerm ) expr;
- if ( term.getName().equals( string ) )
+ SimpleTerm term = (SimpleTerm) expr;
+ if (term.getName().equals(string))
{
- terms.add( term );
+ terms.add(term);
}
}
else
{
- for ( LDAPExpr c : expr.getChildren() )
+ for (LDAPExpr c : expr.getChildren())
{
- findTerms( string, c, terms );
+ findTerms(string, c, terms);
}
}
}
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/OBRListener.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/OBRListener.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/OBRListener.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/OBRListener.java Mon Aug 2 17:08:03 2010
@@ -19,11 +19,9 @@
package org.apache.felix.sigil.common.obr.impl;
-
import org.apache.felix.sigil.common.model.eclipse.ISigilBundle;
-
public interface OBRListener
{
- void handleBundle( ISigilBundle bundle );
+ void handleBundle(ISigilBundle bundle);
}
Modified: felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/VersionRangeHelper.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/VersionRangeHelper.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/VersionRangeHelper.java (original)
+++ felix/trunk/sigil/common/obr/src/org/apache/felix/sigil/common/obr/impl/VersionRangeHelper.java Mon Aug 2 17:08:03 2010
@@ -19,7 +19,6 @@
package org.apache.felix.sigil.common.obr.impl;
-
import java.util.ArrayList;
import java.util.List;
@@ -31,67 +30,68 @@ import org.apache.felix.sigil.common.osg
import org.apache.felix.sigil.common.osgi.VersionTable;
import org.osgi.framework.Version;
-
public class VersionRangeHelper
{
- public static VersionRange decodeVersions( LDAPExpr expr ) throws NumberFormatException
+ public static VersionRange decodeVersions(LDAPExpr expr) throws NumberFormatException
{
- ArrayList<LDAPExpr> terms = new ArrayList<LDAPExpr>( 1 );
+ ArrayList<LDAPExpr> terms = new ArrayList<LDAPExpr>(1);
- findExpr( "version", expr, terms );
+ findExpr("version", expr, terms);
- if ( terms.isEmpty() )
+ if (terms.isEmpty())
{
// woo hoo!
return VersionRange.ANY_VERSION;
}
else
{
- switch ( terms.size() )
+ switch (terms.size())
{
case 1:
{
- return parseSimpleVersionRange( terms.get( 0 ) );
+ return parseSimpleVersionRange(terms.get(0));
}
case 2:
{
- return parseCompoundVersionRange( terms.get( 0 ), terms.get( 1 ) );
+ return parseCompoundVersionRange(terms.get(0), terms.get(1));
}
default:
{
// (&(version>=min)(!(version=min))(version<=max)(!(version=max))) - (min,max) - not dealt with!!
// (&(|(version>min)(version=min))(|(version<max)(version=max))) - [min,max] - not dealt with!!
- throw new NumberFormatException( "Failed to parse complicated version expression " + expr );
+ throw new NumberFormatException(
+ "Failed to parse complicated version expression " + expr);
}
}
}
}
-
// (&(version>=min)(version<=max)) - [min,max]
// (&(version>min)(version<max)) - (min,max)
//
// (&(!(version<min))(!(version>max))) - [min,max]
// (&(!(version<=min))(!(version>=max)) - (min,max)
- private static VersionRange parseCompoundVersionRange( LDAPExpr left, LDAPExpr right ) throws NumberFormatException
+ private static VersionRange parseCompoundVersionRange(LDAPExpr left, LDAPExpr right)
+ throws NumberFormatException
{
- VersionRange one = parseSimpleVersionRange( left );
- VersionRange two = parseSimpleVersionRange( right );
+ VersionRange one = parseSimpleVersionRange(left);
+ VersionRange two = parseSimpleVersionRange(right);
// sanity check
- if ( one.isPointVersion() || two.isPointVersion() )
+ if (one.isPointVersion() || two.isPointVersion())
{
- throw new NumberFormatException( "Unexpected point version in compound expression " + left );
+ throw new NumberFormatException(
+ "Unexpected point version in compound expression " + left);
}
- VersionRange max = one.getFloor().equals( Version.emptyVersion ) ? one : two;
+ VersionRange max = one.getFloor().equals(Version.emptyVersion) ? one : two;
VersionRange min = max == one ? two : one;
- return new VersionRange( min.isOpenFloor(), min.getFloor(), max.getCeiling(), max.isOpenCeiling() );
+ return new VersionRange(min.isOpenFloor(), min.getFloor(), max.getCeiling(),
+ max.isOpenCeiling());
}
-
// possible variations
// (version=v) - [v,v]
//
@@ -105,122 +105,118 @@ public class VersionRangeHelper
// (!(version<min)) - [min,*)
// (!(version>=max)) - [0,max)
// (!(version<=min)) - (0,*)
- private static VersionRange parseSimpleVersionRange( LDAPExpr expr ) throws NumberFormatException
+ private static VersionRange parseSimpleVersionRange(LDAPExpr expr)
+ throws NumberFormatException
{
Version min = Version.emptyVersion;
Version max = VersionRange.INFINITE_VERSION;
boolean openFloor = false;
boolean openCeiling = false;
- if ( expr instanceof Not )
+ if (expr instanceof Not)
{
- Not n = ( Not ) expr;
- SimpleTerm t = ( SimpleTerm ) n.getEx();
- if ( t.getOp() == Ops.EQ )
+ Not n = (Not) expr;
+ SimpleTerm t = (SimpleTerm) n.getEx();
+ if (t.getOp() == Ops.EQ)
{
- throw new NumberFormatException( "Unexpected point version in negated expression " + expr );
+ throw new NumberFormatException(
+ "Unexpected point version in negated expression " + expr);
}
- if ( !isMax( t.getOp() ) )
+ if (!isMax(t.getOp()))
{
- max = toVersion( t );
- openCeiling = !openFloor( t );
+ max = toVersion(t);
+ openCeiling = !openFloor(t);
}
- else if ( !isMin( t.getOp() ) )
+ else if (!isMin(t.getOp()))
{
- min = toVersion( t );
- openFloor = !openCeiling( t );
+ min = toVersion(t);
+ openFloor = !openCeiling(t);
}
else
{
- throw new IllegalStateException( "Unexpected operator " + t.getOp() );
+ throw new IllegalStateException("Unexpected operator " + t.getOp());
}
}
else
{
- SimpleTerm t = ( SimpleTerm ) expr;
- if ( t.getOp().equals( Ops.EQ ) )
+ SimpleTerm t = (SimpleTerm) expr;
+ if (t.getOp().equals(Ops.EQ))
{
- max = toVersion( t );
+ max = toVersion(t);
min = max;
openFloor = false;
openCeiling = false;
}
- else if ( isMax( t.getOp() ) )
+ else if (isMax(t.getOp()))
{
- max = toVersion( t );
- openCeiling = openCeiling( t );
+ max = toVersion(t);
+ openCeiling = openCeiling(t);
}
- else if ( isMin( t.getOp() ) )
+ else if (isMin(t.getOp()))
{
- min = toVersion( t );
- openFloor = openFloor( t );
+ min = toVersion(t);
+ openFloor = openFloor(t);
}
else
{
- throw new IllegalStateException( "Unexpected operator " + t.getOp() );
+ throw new IllegalStateException("Unexpected operator " + t.getOp());
}
}
- return new VersionRange( openFloor, min, max, openCeiling );
+ return new VersionRange(openFloor, min, max, openCeiling);
}
-
- private static Version toVersion( SimpleTerm t )
+ private static Version toVersion(SimpleTerm t)
{
- return VersionTable.getVersion( t.getRval() );
+ return VersionTable.getVersion(t.getRval());
}
-
- private static boolean isMax( Ops op )
+ private static boolean isMax(Ops op)
{
return op == Ops.LE || op == Ops.LT;
}
-
- private static boolean isMin( Ops op )
+ private static boolean isMin(Ops op)
{
return op == Ops.GE || op == Ops.GT;
}
-
- private static boolean openFloor( SimpleTerm t )
+ private static boolean openFloor(SimpleTerm t)
{
return t.getOp() == Ops.GT;
}
-
- private static boolean openCeiling( SimpleTerm t )
+ private static boolean openCeiling(SimpleTerm t)
{
return t.getOp() == Ops.LT;
}
-
- private static void findExpr( String string, LDAPExpr expr, List<LDAPExpr> terms )
+ private static void findExpr(String string, LDAPExpr expr, List<LDAPExpr> terms)
{
- if ( expr instanceof SimpleTerm )
+ if (expr instanceof SimpleTerm)
{
- SimpleTerm term = ( SimpleTerm ) expr;
- if ( term.getName().equals( string ) )
+ SimpleTerm term = (SimpleTerm) expr;
+ if (term.getName().equals(string))
{
- terms.add( term );
+ terms.add(term);
}
}
- else if ( expr instanceof Not )
+ else if (expr instanceof Not)
{
- Not not = ( Not ) expr;
- if ( not.getEx() instanceof SimpleTerm )
+ Not not = (Not) expr;
+ if (not.getEx() instanceof SimpleTerm)
{
- SimpleTerm term = ( SimpleTerm ) not.getEx();
- if ( term.getName().equals( string ) )
+ SimpleTerm term = (SimpleTerm) not.getEx();
+ if (term.getName().equals(string))
{
- terms.add( not );
+ terms.add(not);
}
}
}
else
{
- for ( LDAPExpr c : expr.getChildren() )
+ for (LDAPExpr c : expr.getChildren())
{
- findExpr( string, c, terms );
+ findExpr(string, c, terms);
}
}
}
Modified: felix/trunk/sigil/common/osgi.test/src/org/apache/felix/sigil/common/osgi/LDAPParserTest.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi.test/src/org/apache/felix/sigil/common/osgi/LDAPParserTest.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi.test/src/org/apache/felix/sigil/common/osgi/LDAPParserTest.java (original)
+++ felix/trunk/sigil/common/osgi.test/src/org/apache/felix/sigil/common/osgi/LDAPParserTest.java Mon Aug 2 17:08:03 2010
@@ -23,40 +23,48 @@ import junit.framework.TestCase;
public class LDAPParserTest extends TestCase
{
- private static final SimpleTerm A_B = new SimpleTerm( "a", Ops.EQ, "b" );
- private static final SimpleTerm C_D = new SimpleTerm( "c", Ops.EQ, "d" );
-
- public void testSimple() {
- LDAPExpr expr = LDAPParser.parseExpression( "(a=b)" );
- assertEquals( expr, A_B );
- }
-
- public void testSimpleWhiteSpace() {
- LDAPExpr expr = LDAPParser.parseExpression( " ( a = b ) " );
- assertEquals( expr, A_B );
- }
-
- public void testNot() {
- LDAPExpr expr = LDAPParser.parseExpression( "(!(a=b))" );
- assertEquals( expr, Not.apply(A_B));
- }
-
- public void testAnd() {
- LDAPExpr expr = LDAPParser.parseExpression( "(&(a=b)(c=d))" );
- assertEquals( expr, And.apply(A_B, C_D) );
- }
-
- public void testOr() {
- LDAPExpr expr = LDAPParser.parseExpression( "(|(a=b)(c=d))" );
- assertEquals( expr, Or.apply(A_B, C_D) );
- }
-
- public void testParseException() {
- try {
- LDAPExpr expr = LDAPParser.parseExpression( ".(a=b)" );
- fail( "Unexpectedly parsed invalid ldap expr " + expr);
+ private static final SimpleTerm A_B = new SimpleTerm("a", Ops.EQ, "b");
+ private static final SimpleTerm C_D = new SimpleTerm("c", Ops.EQ, "d");
+
+ public void testSimple()
+ {
+ LDAPExpr expr = LDAPParser.parseExpression("(a=b)");
+ assertEquals(expr, A_B);
+ }
+
+ public void testSimpleWhiteSpace()
+ {
+ LDAPExpr expr = LDAPParser.parseExpression(" ( a = b ) ");
+ assertEquals(expr, A_B);
+ }
+
+ public void testNot()
+ {
+ LDAPExpr expr = LDAPParser.parseExpression("(!(a=b))");
+ assertEquals(expr, Not.apply(A_B));
+ }
+
+ public void testAnd()
+ {
+ LDAPExpr expr = LDAPParser.parseExpression("(&(a=b)(c=d))");
+ assertEquals(expr, And.apply(A_B, C_D));
+ }
+
+ public void testOr()
+ {
+ LDAPExpr expr = LDAPParser.parseExpression("(|(a=b)(c=d))");
+ assertEquals(expr, Or.apply(A_B, C_D));
+ }
+
+ public void testParseException()
+ {
+ try
+ {
+ LDAPExpr expr = LDAPParser.parseExpression(".(a=b)");
+ fail("Unexpectedly parsed invalid ldap expr " + expr);
}
- catch (LDAPParseException e) {
+ catch (LDAPParseException e)
+ {
// expected
}
}
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/AbstractExpr.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/AbstractExpr.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/AbstractExpr.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/AbstractExpr.java Mon Aug 2 17:08:03 2010
@@ -21,10 +21,12 @@ package org.apache.felix.sigil.common.os
public abstract class AbstractExpr implements LDAPExpr
{
- public void visit(ExprVisitor visitor) {
+ public void visit(ExprVisitor visitor)
+ {
visitor.visitExpr(this);
- for ( LDAPExpr expr : getChildren() ) {
- visitor.visitExpr( expr );
+ for (LDAPExpr expr : getChildren())
+ {
+ visitor.visitExpr(expr);
}
}
}
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/And.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/And.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/And.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/And.java Mon Aug 2 17:08:03 2010
@@ -19,10 +19,8 @@
package org.apache.felix.sigil.common.osgi;
-
import java.util.Map;
-
public class And extends AbstractExpr
{
@@ -31,58 +29,55 @@ public class And extends AbstractExpr
private static final long serialVersionUID = 1L;
private LDAPExpr[] children;
-
- public static LDAPExpr apply( LDAPExpr... terms )
+ public static LDAPExpr apply(LDAPExpr... terms)
{
- if ( terms == null )
+ if (terms == null)
{
- throw new NullPointerException( "terms cannot be null" );
+ throw new NullPointerException("terms cannot be null");
}
- else if ( terms.length == 0 )
+ else if (terms.length == 0)
{
return Expressions.T;
}
- else if ( terms.length == 1 )
+ else if (terms.length == 1)
{
return terms[0];
}
LDAPExpr[] filtered = new LDAPExpr[terms.length];
int ctr = 0;
- for ( int i = 0; i < terms.length; i++ )
+ for (int i = 0; i < terms.length; i++)
{
- if ( terms[i].equals( Expressions.F ) )
+ if (terms[i].equals(Expressions.F))
return Expressions.F;
- if ( terms[i].equals( Expressions.T ) )
+ if (terms[i].equals(Expressions.T))
continue;
filtered[ctr] = terms[i];
ctr++;
}
- if ( ctr == 0 )
+ if (ctr == 0)
{
return Expressions.T;
}
- else if ( ctr == 1 )
+ else if (ctr == 1)
{
return filtered[0];
}
LDAPExpr[] andTerms = new LDAPExpr[ctr];
- System.arraycopy( filtered, 0, andTerms, 0, ctr );
+ System.arraycopy(filtered, 0, andTerms, 0, ctr);
- return new And( andTerms );
+ return new And(andTerms);
}
-
- private And( LDAPExpr... children )
+ private And(LDAPExpr... children)
{
this.children = children;
}
-
- public boolean eval( Map<String, ?> map )
+ public boolean eval(Map<String, ?> map)
{
- for ( int i = 0; i < children.length; i++ )
+ for (int i = 0; i < children.length; i++)
{
- if ( !children[i].eval( map ) )
+ if (!children[i].eval(map))
{
return false;
}
@@ -90,32 +85,29 @@ public class And extends AbstractExpr
return true;
}
-
public LDAPExpr[] getChildren()
{
return children;
}
-
- public void setChildren( LDAPExpr[] children )
+ public void setChildren(LDAPExpr[] children)
{
this.children = children;
}
-
@Override
- public boolean equals( Object other )
+ public boolean equals(Object other)
{
- if ( other instanceof And )
+ if (other instanceof And)
{
- And that = ( And ) other;
- if ( children.length != that.children.length )
+ And that = (And) other;
+ if (children.length != that.children.length)
{
return false;
}
- for ( int i = 0; i < children.length; i++ )
+ for (int i = 0; i < children.length; i++)
{
- if ( !children[i].equals( that.children[i] ) )
+ if (!children[i].equals(that.children[i]))
{
return false;
}
@@ -125,17 +117,16 @@ public class And extends AbstractExpr
return false;
}
-
@Override
public String toString()
{
- StringBuffer buf = new StringBuffer( 256 );
- buf.append( "(&" );
- for ( int i = 0; i < children.length; i++ )
+ StringBuffer buf = new StringBuffer(256);
+ buf.append("(&");
+ for (int i = 0; i < children.length; i++)
{
- buf.append( " " ).append( children[i] ).append( " " );
+ buf.append(" ").append(children[i]).append(" ");
}
- buf.append( ")" );
+ buf.append(")");
return buf.toString();
}
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ExprVisitor.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ExprVisitor.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ExprVisitor.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ExprVisitor.java Mon Aug 2 17:08:03 2010
@@ -19,7 +19,6 @@
package org.apache.felix.sigil.common.osgi;
-
public interface ExprVisitor
{
void visitExpr(LDAPExpr expr);
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Expressions.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Expressions.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Expressions.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Expressions.java Mon Aug 2 17:08:03 2010
@@ -19,40 +19,35 @@
package org.apache.felix.sigil.common.osgi;
-
import java.util.Map;
-
public class Expressions
{
- public static LDAPExpr and( LDAPExpr... terms )
+ public static LDAPExpr and(LDAPExpr... terms)
{
- return And.apply( terms );
+ return And.apply(terms);
}
-
- public static LDAPExpr or( LDAPExpr... terms )
+ public static LDAPExpr or(LDAPExpr... terms)
{
- return Or.apply( terms );
+ return Or.apply(terms);
}
-
- public static LDAPExpr not( LDAPExpr e )
+ public static LDAPExpr not(LDAPExpr e)
{
- return Not.apply( e );
+ return Not.apply(e);
}
public static LDAPExpr T = Bool.TRUE;
public static LDAPExpr F = Bool.FALSE;
-
// supports direct use of wildcards for ease of testing, but not literal *s
- public static SimpleTerm ex( String name, Ops op, String rhs )
+ public static SimpleTerm ex(String name, Ops op, String rhs)
{
- rhs = rhs.replace( '*', SimpleTerm.WILDCARD );
- return new SimpleTerm( name, op, rhs );
+ rhs = rhs.replace('*', SimpleTerm.WILDCARD);
+ return new SimpleTerm(name, op, rhs);
}
}
@@ -64,35 +59,30 @@ class Bool implements LDAPExpr
*
*/
private static final long serialVersionUID = 1L;
- public static final Bool TRUE = new Bool( true );
- public static final Bool FALSE = new Bool( false );
+ public static final Bool TRUE = new Bool(true);
+ public static final Bool FALSE = new Bool(false);
private boolean bool;
-
- public Bool( boolean bool )
+ public Bool(boolean bool)
{
this.bool = bool;
}
-
- public boolean eval( Map<String, ?> map )
+ public boolean eval(Map<String, ?> map)
{
return bool;
}
-
- public void visit( ExprVisitor v )
+ public void visit(ExprVisitor v)
{
}
-
public LDAPExpr[] getChildren()
{
return CHILDLESS;
}
-
public String toString()
{
return "(" + bool + ")";
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/FilterValidator.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/FilterValidator.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/FilterValidator.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/FilterValidator.java Mon Aug 2 17:08:03 2010
@@ -19,19 +19,17 @@
package org.apache.felix.sigil.common.osgi;
-
public interface FilterValidator
{
public static FilterValidator ACCEPT_ALL = new AcceptEverythingValidator();
-
- boolean validate( LDAPExpr filter );
+ boolean validate(LDAPExpr filter);
static class AcceptEverythingValidator implements FilterValidator
{
- public boolean validate( LDAPExpr filter )
+ public boolean validate(LDAPExpr filter)
{
return true;
}
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPExpr.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPExpr.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPExpr.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPExpr.java Mon Aug 2 17:08:03 2010
@@ -19,30 +19,23 @@
package org.apache.felix.sigil.common.osgi;
-
import java.io.Serializable;
import java.util.Map;
-
public interface LDAPExpr extends Serializable
{
public static final LDAPExpr[] CHILDLESS = new LDAPExpr[0];
-
- public static LDAPExpr ACCEPT_ALL = Expressions.T;
+ public static LDAPExpr ACCEPT_ALL = Expressions.T;
LDAPExpr[] getChildren();
+ void visit(ExprVisitor v);
- void visit( ExprVisitor v );
-
-
- boolean equals( Object other );
-
+ boolean equals(Object other);
int hashCode();
-
- boolean eval( Map<String, ?> map );
+ boolean eval(Map<String, ?> map);
}
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParseException.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParseException.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParseException.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParseException.java Mon Aug 2 17:08:03 2010
@@ -19,45 +19,42 @@
package org.apache.felix.sigil.common.osgi;
-
public class LDAPParseException extends RuntimeException
{
private static final long serialVersionUID = 2L;
private ParseState ps;
- private static final String LINE_SEPARATOR = System.getProperty( "line.separator", "\\r\\n" );
-
+ private static final String LINE_SEPARATOR = System.getProperty("line.separator",
+ "\\r\\n");
- public LDAPParseException( String message, ParseState ps )
+ public LDAPParseException(String message, ParseState ps)
{
- super( message );
+ super(message);
this.ps = ps;
}
-
- public LDAPParseException( String message )
+ public LDAPParseException(String message)
{
- super( message );
+ super(message);
}
-
@Override
public String getMessage()
{
- if ( ps == null )
+ if (ps == null)
{
return super.getMessage();
}
String basicMessage = super.getMessage();
- StringBuffer buf = new StringBuffer( basicMessage.length() + ps.str.length() * 2 );
- buf.append( basicMessage ).append( LINE_SEPARATOR );
- buf.append( ps.str ).append( LINE_SEPARATOR );
- for ( int i = 0; i < ps.pos; i++ )
+ StringBuffer buf = new StringBuffer(basicMessage.length() + ps.str.length() * 2);
+ buf.append(basicMessage).append(LINE_SEPARATOR);
+ buf.append(ps.str).append(LINE_SEPARATOR);
+ for (int i = 0; i < ps.pos; i++)
{
- buf.append( " " );
+ buf.append(" ");
}
- buf.append( "^" );
+ buf.append("^");
return buf.toString();
}
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParser.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParser.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParser.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/LDAPParser.java Mon Aug 2 17:08:03 2010
@@ -19,7 +19,6 @@
package org.apache.felix.sigil.common.osgi;
-
import static org.apache.felix.sigil.common.osgi.Expressions.and;
import static org.apache.felix.sigil.common.osgi.Expressions.not;
import static org.apache.felix.sigil.common.osgi.Expressions.or;
@@ -33,226 +32,219 @@ import static org.apache.felix.sigil.com
import java.util.ArrayList;
import java.util.List;
-
public class LDAPParser
{
private static final LDAPParser parser = new LDAPParser();
-
- public static LDAPExpr parseExpression( String strExpr ) throws LDAPParseException
+ public static LDAPExpr parseExpression(String strExpr) throws LDAPParseException
{
- return parser.parse( strExpr );
+ return parser.parse(strExpr);
}
- public LDAPExpr parse( String strExpr ) throws LDAPParseException
+ public LDAPExpr parse(String strExpr) throws LDAPParseException
{
- if ( strExpr == null || strExpr.trim().length() == 0 )
+ if (strExpr == null || strExpr.trim().length() == 0)
{
return LDAPExpr.ACCEPT_ALL;
}
- ParseState ps = new ParseState( strExpr );
- LDAPExpr expr = parseExpr( ps );
+ ParseState ps = new ParseState(strExpr);
+ LDAPExpr expr = parseExpr(ps);
ps.skipWhitespace();
- if ( !ps.isEndOfString() )
+ if (!ps.isEndOfString())
{
- error( "expected end of expression ", ps );
+ error("expected end of expression ", ps);
}
return expr;
}
-
- public LDAPExpr parseExpr( ParseState ps ) throws LDAPParseException
+ public LDAPExpr parseExpr(ParseState ps) throws LDAPParseException
{
ps.skipWhitespace();
- if ( !( ps.peek() == '(' ) )
+ if (!(ps.peek() == '('))
{
- error( "expected (", ps );
+ error("expected (", ps);
}
ps.read();
LDAPExpr expr = null;
ps.skipWhitespace();
char ch = ps.peek();
- switch ( ch )
+ switch (ch)
{
case '&':
ps.readAndSkipWhiteSpace();
List<LDAPExpr> andList = new ArrayList<LDAPExpr>();
- while ( ps.peek() == '(' )
+ while (ps.peek() == '(')
{
- andList.add( parseExpr( ps ) );
+ andList.add(parseExpr(ps));
ps.skipWhitespace();
}
- LDAPExpr[] andArr = andList.toArray( new LDAPExpr[andList.size()] );
- expr = and( andArr );
+ LDAPExpr[] andArr = andList.toArray(new LDAPExpr[andList.size()]);
+ expr = and(andArr);
break;
case '|':
ps.readAndSkipWhiteSpace();
List<LDAPExpr> orList = new ArrayList<LDAPExpr>();
- while ( ps.peek() == '(' )
+ while (ps.peek() == '(')
{
- orList.add( parseExpr( ps ) );
+ orList.add(parseExpr(ps));
ps.skipWhitespace();
}
- LDAPExpr[] orArray = orList.toArray( new LDAPExpr[orList.size()] );
- expr = or( orArray );
+ LDAPExpr[] orArray = orList.toArray(new LDAPExpr[orList.size()]);
+ expr = or(orArray);
break;
case '!':
ps.readAndSkipWhiteSpace();
- expr = not( parseExpr( ps ) );
+ expr = not(parseExpr(ps));
break;
default:
- if ( isNameChar( ch ) )
+ if (isNameChar(ch))
{
- expr = parseSimple( ps );
+ expr = parseSimple(ps);
}
else
{
- error( "unexpected character: '" + ch + "'", ps );
+ error("unexpected character: '" + ch + "'", ps);
}
}
ps.skipWhitespace();
- if ( ps.peek() != ')' )
+ if (ps.peek() != ')')
{
- error( "expected )", ps );
+ error("expected )", ps);
}
ps.read();
return expr;
}
-
- void error( String message, ParseState ps ) throws LDAPParseException
+ void error(String message, ParseState ps) throws LDAPParseException
{
- throw new LDAPParseException( message, ps );
+ throw new LDAPParseException(message, ps);
}
-
- private SimpleTerm parseSimple( ParseState ps ) throws LDAPParseException
+ private SimpleTerm parseSimple(ParseState ps) throws LDAPParseException
{
// read name
- StringBuffer name = new StringBuffer( 16 );
- for ( char c = ps.peek(); !ps.isEndOfString() && isNameChar( c ); c = ps.peek() )
+ StringBuffer name = new StringBuffer(16);
+ for (char c = ps.peek(); !ps.isEndOfString() && isNameChar(c); c = ps.peek())
{
ps.read();
- name.append( c );
+ name.append(c);
}
ps.skipWhitespace();
Ops op = null;
// read op
- if ( ps.lookingAt( "=" ) )
+ if (ps.lookingAt("="))
{
op = EQ;
- ps.skip( 1 );
+ ps.skip(1);
}
- else if ( ps.lookingAt( ">=" ) )
+ else if (ps.lookingAt(">="))
{
op = GE;
- ps.skip( 2 );
+ ps.skip(2);
}
- else if ( ps.lookingAt( "<=" ) )
+ else if (ps.lookingAt("<="))
{
op = LE;
- ps.skip( 2 );
+ ps.skip(2);
}
- else if ( ps.lookingAt( ">" ) )
+ else if (ps.lookingAt(">"))
{
op = GT;
- ps.skip( 1 );
+ ps.skip(1);
}
- else if ( ps.lookingAt( "<" ) )
+ else if (ps.lookingAt("<"))
{
op = LT;
- ps.skip( 1 );
+ ps.skip(1);
}
- else if ( ps.lookingAt( "-=" ) )
+ else if (ps.lookingAt("-="))
{
op = APPROX;
- ps.skip( 2 );
+ ps.skip(2);
}
- else if ( ps.isEndOfString() )
+ else if (ps.isEndOfString())
{
- error( "unexpected end of expression", ps );
+ error("unexpected end of expression", ps);
}
else
{
- error( "unexpected character: '" + ps.peek() + "'", ps );
+ error("unexpected character: '" + ps.peek() + "'", ps);
}
ps.skipWhitespace();
boolean escaped = false;
- StringBuffer value = new StringBuffer( 16 );
+ StringBuffer value = new StringBuffer(16);
- while ( !ps.isEndOfString() && !Character.isWhitespace( ps.peek() ) && !( ps.peek() == ')' && !escaped ) )
+ while (!ps.isEndOfString() && !Character.isWhitespace(ps.peek())
+ && !(ps.peek() == ')' && !escaped))
{
char ch = ps.peek();
- if ( ch == '\\' )
+ if (ch == '\\')
{
escaped = true;
ps.read();
}
- else if ( ch == '*' )
+ else if (ch == '*')
{
- if ( escaped )
+ if (escaped)
{
- value.append( ch );
+ value.append(ch);
escaped = false;
}
else
{
- value.append( SimpleTerm.WILDCARD );
+ value.append(SimpleTerm.WILDCARD);
}
ps.read();
}
- else if ( isLiteralValue( ch ) )
+ else if (isLiteralValue(ch))
{
- if ( escaped )
+ if (escaped)
{
- error( "incorrectly applied escape of '" + ch + "'", ps );
+ error("incorrectly applied escape of '" + ch + "'", ps);
}
- value.append( ps.read() );
+ value.append(ps.read());
}
- else if ( isEscapedValue( ch ) )
+ else if (isEscapedValue(ch))
{
- if ( !escaped )
+ if (!escaped)
{
- error( "missing escape for '" + ch + "'", ps );
+ error("missing escape for '" + ch + "'", ps);
}
- value.append( ps.read() );
+ value.append(ps.read());
escaped = false;
}
else
{
- error( "unexpected character: '" + ps.peek() + "'", ps );
+ error("unexpected character: '" + ps.peek() + "'", ps);
}
}
ps.skipWhitespace();
- SimpleTerm expr = new SimpleTerm( name.toString(), op, value.toString() );
+ SimpleTerm expr = new SimpleTerm(name.toString(), op, value.toString());
return expr;
}
-
- private boolean isNameChar( int ch )
+ private boolean isNameChar(int ch)
{
- return !( Character.isWhitespace( ch ) || ( ch == '(' ) || ( ch == ')' ) || ( ch == '<' ) || ( ch == '>' )
- || ( ch == '=' ) || ( ch == '~' ) || ( ch == '*' ) || ( ch == '\\' ) );
+ return !(Character.isWhitespace(ch) || (ch == '(') || (ch == ')') || (ch == '<')
+ || (ch == '>') || (ch == '=') || (ch == '~') || (ch == '*') || (ch == '\\'));
}
-
- private boolean isLiteralValue( int ch )
+ private boolean isLiteralValue(int ch)
{
- return !( Character.isWhitespace( ch ) || ( ch == '(' ) || ( ch == ')' ) || ( ch == '*' ) );
+ return !(Character.isWhitespace(ch) || (ch == '(') || (ch == ')') || (ch == '*'));
}
-
- private boolean isEscapedValue( int ch )
+ private boolean isEscapedValue(int ch)
{
- return ( ch == '(' ) || ( ch == ')' ) || ( ch == '*' );
+ return (ch == '(') || (ch == ')') || (ch == '*');
}
}
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Not.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Not.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Not.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Not.java Mon Aug 2 17:08:03 2010
@@ -19,10 +19,8 @@
package org.apache.felix.sigil.common.osgi;
-
import java.util.Map;
-
public class Not extends AbstractExpr
{
@@ -32,76 +30,66 @@ public class Not extends AbstractExpr
private static final long serialVersionUID = 1L;
private LDAPExpr[] children;
-
- public static LDAPExpr apply( LDAPExpr e )
+ public static LDAPExpr apply(LDAPExpr e)
{
- if ( e == null )
+ if (e == null)
{
- throw new NullPointerException( "cannot apply Not to a null expression" );
+ throw new NullPointerException("cannot apply Not to a null expression");
}
- if ( e.equals( Expressions.T ) )
+ if (e.equals(Expressions.T))
{
return Expressions.F;
}
- if ( e.equals( Expressions.F ) )
+ if (e.equals(Expressions.F))
{
return Expressions.T;
}
- return new Not( e );
+ return new Not(e);
}
-
- private Not( LDAPExpr child )
+ private Not(LDAPExpr child)
{
- this.children = new LDAPExpr[]
- { child };
+ this.children = new LDAPExpr[] { child };
}
-
- public boolean eval( Map<String, ?> map )
+ public boolean eval(Map<String, ?> map)
{
- return !children[0].eval( map );
+ return !children[0].eval(map);
}
-
public LDAPExpr getEx()
{
return children[0];
}
-
public LDAPExpr[] getChildren()
{
return children;
}
-
- public void setChild( LDAPExpr child )
+ public void setChild(LDAPExpr child)
{
- this.children = new LDAPExpr[]
- { child };
+ this.children = new LDAPExpr[] { child };
}
-
@Override
- public boolean equals( Object other )
+ public boolean equals(Object other)
{
- if ( other instanceof Not )
+ if (other instanceof Not)
{
- Not that = ( Not ) other;
- return children[0].equals( that.children[0] );
+ Not that = (Not) other;
+ return children[0].equals(that.children[0]);
}
return false;
}
-
@Override
public String toString()
{
- StringBuffer buf = new StringBuffer( 256 );
- buf.append( "(!" );
- buf.append( " " ).append( children[0] ).append( " " );
- buf.append( ")" );
+ StringBuffer buf = new StringBuffer(256);
+ buf.append("(!");
+ buf.append(" ").append(children[0]).append(" ");
+ buf.append(")");
return buf.toString();
}
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Ops.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Ops.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Ops.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Ops.java Mon Aug 2 17:08:03 2010
@@ -19,7 +19,6 @@
package org.apache.felix.sigil.common.osgi;
-
public enum Ops
{
EQ, GE, LE, GT, LT, APPROX;
@@ -27,7 +26,7 @@ public enum Ops
@Override
public String toString()
{
- switch ( this )
+ switch (this)
{
case EQ:
return "=";
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Or.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Or.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Or.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Or.java Mon Aug 2 17:08:03 2010
@@ -19,10 +19,8 @@
package org.apache.felix.sigil.common.osgi;
-
import java.util.Map;
-
public class Or extends AbstractExpr
{
@@ -32,58 +30,55 @@ public class Or extends AbstractExpr
private static final long serialVersionUID = 1L;
private LDAPExpr[] children;
-
- public static LDAPExpr apply( LDAPExpr... terms )
+ public static LDAPExpr apply(LDAPExpr... terms)
{
- if ( terms == null )
+ if (terms == null)
{
- throw new NullPointerException( "terms cannot be null" );
+ throw new NullPointerException("terms cannot be null");
}
- else if ( terms.length == 0 )
+ else if (terms.length == 0)
{
return Expressions.T;
}
- else if ( terms.length == 1 )
+ else if (terms.length == 1)
{
return terms[0];
}
LDAPExpr[] filtered = new LDAPExpr[terms.length];
int ctr = 0;
- for ( int i = 0; i < terms.length; i++ )
+ for (int i = 0; i < terms.length; i++)
{
- if ( terms[i].equals( Expressions.T ) )
+ if (terms[i].equals(Expressions.T))
return Expressions.T;
- if ( terms[i].equals( Expressions.F ) )
+ if (terms[i].equals(Expressions.F))
continue;
filtered[ctr] = terms[i];
ctr++;
}
- if ( ctr == 0 )
+ if (ctr == 0)
{
return Expressions.F;
}
- else if ( ctr == 1 )
+ else if (ctr == 1)
{
return filtered[0];
}
LDAPExpr[] orTerms = new LDAPExpr[ctr];
- System.arraycopy( filtered, 0, orTerms, 0, ctr );
+ System.arraycopy(filtered, 0, orTerms, 0, ctr);
- return new Or( orTerms );
+ return new Or(orTerms);
}
-
- private Or( LDAPExpr... children )
+ private Or(LDAPExpr... children)
{
this.children = children;
}
-
- public boolean eval( Map<String, ?> map )
+ public boolean eval(Map<String, ?> map)
{
- for ( int i = 0; i < children.length; i++ )
+ for (int i = 0; i < children.length; i++)
{
- if ( children[i].eval( map ) )
+ if (children[i].eval(map))
{
return true;
}
@@ -91,32 +86,29 @@ public class Or extends AbstractExpr
return false;
}
-
public LDAPExpr[] getChildren()
{
return children;
}
-
- public void setChildren( LDAPExpr[] children )
+ public void setChildren(LDAPExpr[] children)
{
this.children = children;
}
-
@Override
- public boolean equals( Object other )
+ public boolean equals(Object other)
{
- if ( other instanceof Or )
+ if (other instanceof Or)
{
- Or that = ( Or ) other;
- if ( children.length != that.children.length )
+ Or that = (Or) other;
+ if (children.length != that.children.length)
{
return false;
}
- for ( int i = 0; i < children.length; i++ )
+ for (int i = 0; i < children.length; i++)
{
- if ( children[i].equals( that.children[i] ) )
+ if (children[i].equals(that.children[i]))
{
return true;
}
@@ -126,17 +118,16 @@ public class Or extends AbstractExpr
return false;
}
-
@Override
public String toString()
{
- StringBuffer buf = new StringBuffer( 256 );
- buf.append( "(|" );
- for ( int i = 0; i < children.length; i++ )
+ StringBuffer buf = new StringBuffer(256);
+ buf.append("(|");
+ for (int i = 0; i < children.length; i++)
{
- buf.append( " " ).append( children[i] ).append( " " );
+ buf.append(" ").append(children[i]).append(" ");
}
- buf.append( ")" );
+ buf.append(")");
return buf.toString();
}
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ParseState.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ParseState.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ParseState.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/ParseState.java Mon Aug 2 17:08:03 2010
@@ -19,10 +19,8 @@
package org.apache.felix.sigil.common.osgi;
-
import java.io.Serializable;
-
/**
* @author dave
*
@@ -35,39 +33,34 @@ class ParseState implements Serializable
String str;
-
- ParseState( String str )
+ ParseState(String str)
{
this.str = str;
}
-
- public boolean lookingAt( String start )
+ public boolean lookingAt(String start)
{
- return str.substring( pos ).startsWith( start );
+ return str.substring(pos).startsWith(start);
}
-
- public CharSequence skip( int n )
+ public CharSequence skip(int n)
{
int end = pos + n < str.length() ? pos + n : str.length();
int start = pos;
pos = end;
- return str.subSequence( start, end );
+ return str.subSequence(start, end);
}
-
public char read()
{
- char ch = str.charAt( pos );
- if ( pos < str.length() )
+ char ch = str.charAt(pos);
+ if (pos < str.length())
{
pos++;
}
return ch;
}
-
public char readAndSkipWhiteSpace()
{
char ch = read();
@@ -75,26 +68,23 @@ class ParseState implements Serializable
return ch;
}
-
char peek()
{
- if ( isEndOfString() )
+ if (isEndOfString())
{
- return ( char ) -1;
+ return (char) -1;
}
- return str.charAt( pos );
+ return str.charAt(pos);
}
-
boolean isEndOfString()
{
return pos == str.length();
}
-
void skipWhitespace()
{
- while ( pos < str.length() && Character.isWhitespace( str.charAt( pos ) ) )
+ while (pos < str.length() && Character.isWhitespace(str.charAt(pos)))
{
pos++;
}
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/SimpleTerm.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/SimpleTerm.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/SimpleTerm.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/SimpleTerm.java Mon Aug 2 17:08:03 2010
@@ -19,13 +19,11 @@
package org.apache.felix.sigil.common.osgi;
-
import java.lang.reflect.Constructor;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
-
public class SimpleTerm extends AbstractExpr
{
@@ -34,59 +32,54 @@ public class SimpleTerm extends Abstract
*/
private static final long serialVersionUID = 1L;
public static final char WILDCARD = 2 ^ 16 - 1;
- private static final String WILDCARD_STRING = new String( new char[]
- { SimpleTerm.WILDCARD } );
+ private static final String WILDCARD_STRING = new String(
+ new char[] { SimpleTerm.WILDCARD });
private Ops op;
private String name;
private String rval;
-
- public SimpleTerm( String name, Ops op, String value )
+ public SimpleTerm(String name, Ops op, String value)
{
this.op = op;
this.name = name.intern();
this.rval = value.intern();
}
-
public String getName()
{
return name;
}
-
public Ops getOp()
{
return op;
}
-
public String getRval()
{
return rval;
}
-
- public boolean eval( Map<String, ?> map )
+ public boolean eval(Map<String, ?> map)
{
- Object lval = map.get( name );
- if ( lval == null )
+ Object lval = map.get(name);
+ if (lval == null)
{
return false;
}
- else if ( Ops.EQ == op && WILDCARD_STRING.equals( lval ) )
+ else if (Ops.EQ == op && WILDCARD_STRING.equals(lval))
{
return true;
}
// any match in the vector will do
- else if ( lval instanceof Vector<?> )
+ else if (lval instanceof Vector<?>)
{
- Vector<?> vec = ( Vector<?> ) lval;
- for ( Iterator<?> i = vec.iterator(); i.hasNext(); )
+ Vector<?> vec = (Vector<?>) lval;
+ for (Iterator<?> i = vec.iterator(); i.hasNext();)
{
- if ( check( i.next() ) )
+ if (check(i.next()))
{
return true;
}
@@ -94,85 +87,84 @@ public class SimpleTerm extends Abstract
return false;
}
// any match in the array will do
- else if ( lval instanceof Object[] )
+ else if (lval instanceof Object[])
{
- Object[] arr = ( Object[] ) lval;
- for ( int i = 0; i < arr.length; i++ )
+ Object[] arr = (Object[]) lval;
+ for (int i = 0; i < arr.length; i++)
{
- if ( check( arr[i] ) )
+ if (check(arr[i]))
{
return true;
}
}
return false;
}
- return check( lval );
+ return check(lval);
}
-
@SuppressWarnings("unchecked")
- private boolean check( Object lval )
+ private boolean check(Object lval)
{
- if ( lval == null )
+ if (lval == null)
{
return false;
}
- else if ( Ops.EQ == op && WILDCARD_STRING.equals( lval ) )
+ else if (Ops.EQ == op && WILDCARD_STRING.equals(lval))
{
return true;
}
Object rhs = null;
- if ( lval instanceof String )
+ if (lval instanceof String)
{
- if ( Ops.APPROX == op )
+ if (Ops.APPROX == op)
{
- rhs = collapseWhiteSpace( rval );
- lval = collapseWhiteSpace( ( String ) lval );
+ rhs = collapseWhiteSpace(rval);
+ lval = collapseWhiteSpace((String) lval);
}
- if ( Ops.EQ == op || Ops.APPROX == op )
+ if (Ops.EQ == op || Ops.APPROX == op)
{
- return stringCheck( ( String ) lval );
+ return stringCheck((String) lval);
}
// rhs already a string
}
- else if ( lval.getClass() == Byte.class )
+ else if (lval.getClass() == Byte.class)
{
- rhs = Byte.valueOf( rval );
+ rhs = Byte.valueOf(rval);
}
- else if ( lval.getClass() == Short.class )
+ else if (lval.getClass() == Short.class)
{
- rhs = Short.valueOf( rval );
+ rhs = Short.valueOf(rval);
}
- else if ( lval.getClass() == Integer.class )
+ else if (lval.getClass() == Integer.class)
{
- rhs = Integer.valueOf( rval );
+ rhs = Integer.valueOf(rval);
}
- else if ( lval.getClass() == Long.class )
+ else if (lval.getClass() == Long.class)
{
- rhs = Long.valueOf( rval );
+ rhs = Long.valueOf(rval);
}
- else if ( lval.getClass() == Float.class )
+ else if (lval.getClass() == Float.class)
{
- rhs = Float.valueOf( rval );
+ rhs = Float.valueOf(rval);
}
- else if ( lval.getClass() == Double.class )
+ else if (lval.getClass() == Double.class)
{
- rhs = Double.valueOf( rval );
+ rhs = Double.valueOf(rval);
}
else
{
try
{
- Constructor<?> stringCtor = lval.getClass().getConstructor( new Class[]
- { String.class } );
- rhs = stringCtor.newInstance( rval );
+ Constructor<?> stringCtor = lval.getClass().getConstructor(
+ new Class[] { String.class });
+ rhs = stringCtor.newInstance(rval);
}
- catch ( Exception e )
+ catch (Exception e)
{
// log it
e.printStackTrace();
@@ -180,18 +172,18 @@ public class SimpleTerm extends Abstract
}
}
- if ( !( lval instanceof Comparable ) )
+ if (!(lval instanceof Comparable))
{
- return Ops.EQ == op && lval.equals( rval );
+ return Ops.EQ == op && lval.equals(rval);
}
else
{
- Comparable<? super Object> lhs = ( Comparable<? super Object> ) lval;
+ Comparable<? super Object> lhs = (Comparable<? super Object>) lval;
- int compare = lhs.compareTo( rhs );
+ int compare = lhs.compareTo(rhs);
- switch ( op )
+ switch (op)
{
case EQ:
return compare == 0;
@@ -211,12 +203,11 @@ public class SimpleTerm extends Abstract
return false;
}
-
- private boolean stringCheck( String lhs )
+ private boolean stringCheck(String lhs)
{
String rhs;
- switch ( op )
+ switch (op)
{
case EQ:
case APPROX:
@@ -229,35 +220,35 @@ public class SimpleTerm extends Abstract
int valLength = lhs.length();
int patLength = rval.length();
- if ( valLength == 0 && patLength == 0 )
+ if (valLength == 0 && patLength == 0)
{
return true;
}
boolean wc = false;
int j = 0;
- for ( int i = 0; i < patLength; i++ )
+ for (int i = 0; i < patLength; i++)
{
// trailing wildcards
- char pc = rhs.charAt( i );
- if ( j == valLength )
+ char pc = rhs.charAt(i);
+ if (j == valLength)
{
- if ( pc != SimpleTerm.WILDCARD )
+ if (pc != SimpleTerm.WILDCARD)
{
return false;
}
continue;
}
- if ( pc == SimpleTerm.WILDCARD )
+ if (pc == SimpleTerm.WILDCARD)
{
wc = true;
continue;
}
- while ( wc && j < valLength - 1 && lhs.charAt( j ) != pc )
+ while (wc && j < valLength - 1 && lhs.charAt(j) != pc)
{
j++;
}
- if ( lhs.charAt( j ) != pc )
+ if (lhs.charAt(j) != pc)
{
return false;
}
@@ -267,79 +258,74 @@ public class SimpleTerm extends Abstract
j++;
}
}
- return ( wc || j == valLength );
+ return (wc || j == valLength);
}
-
- private String collapseWhiteSpace( String in )
+ private String collapseWhiteSpace(String in)
{
- StringBuffer out = new StringBuffer( in.trim().length() );
+ StringBuffer out = new StringBuffer(in.trim().length());
boolean white = false;
- for ( int i = 0; i < in.length(); i++ )
+ for (int i = 0; i < in.length(); i++)
{
- char ch = in.charAt( i );
- if ( Character.isWhitespace( ch ) )
+ char ch = in.charAt(i);
+ if (Character.isWhitespace(ch))
{
white = true;
}
else
{
- if ( white )
+ if (white)
{
- out.append( " " );
+ out.append(" ");
white = false;
}
- out.append( ch );
+ out.append(ch);
}
}
return out.toString();
}
-
public LDAPExpr[] getChildren()
{
return CHILDLESS;
}
-
@Override
- public boolean equals( Object other )
+ public boolean equals(Object other)
{
- if ( other instanceof SimpleTerm )
+ if (other instanceof SimpleTerm)
{
- SimpleTerm that = ( SimpleTerm ) other;
- return name.equals( that.name ) && op.equals( that.op ) && rval.equals( that.rval );
+ SimpleTerm that = (SimpleTerm) other;
+ return name.equals(that.name) && op.equals(that.op) && rval.equals(that.rval);
}
return false;
}
-
@Override
public String toString()
{
- return "(" + name + " " + op.toString() + " " + escape( rval ) + ")";
+ return "(" + name + " " + op.toString() + " " + escape(rval) + ")";
}
-
- private String escape( String raw )
+ private String escape(String raw)
{
- StringBuffer buf = new StringBuffer( raw.length() + 10 );
- for ( int i = 0; i < raw.length(); i++ )
+ StringBuffer buf = new StringBuffer(raw.length() + 10);
+ for (int i = 0; i < raw.length(); i++)
{
- char ch = raw.charAt( i );
- switch ( ch )
+ char ch = raw.charAt(i);
+ switch (ch)
{
case SimpleTerm.WILDCARD:
- buf.append( "*" );
+ buf.append("*");
break;
case '(':
case ')':
case '*':
- buf.append( "\\" ).append( ch );
+ buf.append("\\").append(ch);
break;
default:
- buf.append( ch );
+ buf.append(ch);
}
}
return buf.toString();
Modified: felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Utils.java
URL: http://svn.apache.org/viewvc/felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Utils.java?rev=981604&r1=981603&r2=981604&view=diff
==============================================================================
--- felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Utils.java (original)
+++ felix/trunk/sigil/common/osgi/src/org/apache/felix/sigil/common/osgi/Utils.java Mon Aug 2 17:08:03 2010
@@ -19,47 +19,44 @@
package org.apache.felix.sigil.common.osgi;
-
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-
public class Utils
{
- public static MapBuilder map( String name, Object value )
+ public static MapBuilder map(String name, Object value)
{
- return new MapBuilder().put( name, value );
+ return new MapBuilder().put(name, value);
}
-
- public static String toString( Map<String, Object> attrs )
+ public static String toString(Map<String, Object> attrs)
{
- if ( attrs == null )
+ if (attrs == null)
{
return "NULL";
}
- StringBuffer buf = new StringBuffer( 128 );
- List<String> keys = new ArrayList<String>( attrs.keySet() );
- Collections.sort( keys );
- buf.append( "{" );
+ StringBuffer buf = new StringBuffer(128);
+ List<String> keys = new ArrayList<String>(attrs.keySet());
+ Collections.sort(keys);
+ buf.append("{");
- for ( int i = 0; i < keys.size(); i++ )
+ for (int i = 0; i < keys.size(); i++)
{
- Object name = keys.get( i );
- Object value = attrs.get( name );
- buf.append( name ).append( "=" ).append( value ).append( "," );
+ Object name = keys.get(i);
+ Object value = attrs.get(name);
+ buf.append(name).append("=").append(value).append(",");
}
- if ( buf.length() > 1 )
+ if (buf.length() > 1)
{
- buf.delete( buf.length() - 1, buf.length() );
+ buf.delete(buf.length() - 1, buf.length());
}
- buf.append( "}" );
+ buf.append("}");
return buf.toString();
}
@@ -68,15 +65,13 @@ public class Utils
{
private Map<String, Object> map = new HashMap<String, Object>();
-
- public MapBuilder put( String name, Object value )
+ public MapBuilder put(String name, Object value)
{
- map.put( name, value );
+ map.put(name, value);
return this;
}
-
public Map<String, Object> toMap()
{
return map;