commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mben...@apache.org
Subject svn commit: r833108 - /commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g
Date Thu, 05 Nov 2009 18:12:18 GMT
Author: mbenson
Date: Thu Nov  5 18:12:17 2009
New Revision: 833108

URL: http://svn.apache.org/viewvc?rev=833108&view=rev
Log:
weak reference back to owning ParserEntityFactory from EntityTreeParser

Modified:
    commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g

Modified: commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g
URL: http://svn.apache.org/viewvc/commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g?rev=833108&r1=833107&r2=833108&view=diff
==============================================================================
--- commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g (original)
+++ commons/sandbox/flatfile/trunk/src/main/antlr/EntityTreeParser.g Thu Nov  5 18:12:17 2009
@@ -38,7 +38,7 @@
 }
 
 {
-	private ParserEntityFactory entityFactory;
+	private java.lang.ref.WeakReference<ParserEntityFactory> entityFactoryRef;
 	private Stack<String> stk = new Stack<String>();
 
 	public synchronized Entity createEntity(EntityDefinition def) {
@@ -62,7 +62,7 @@
 	}
 
 	public void setEntityFactory(ParserEntityFactory entityFactory) {
-		this.entityFactory = entityFactory;
+		this.entityFactoryRef = new java.lang.ref.WeakReference<ParserEntityFactory>(entityFactory);
 	}
 
 	private void runChecks(EntityDefinition def, Entity e) {
@@ -90,6 +90,9 @@
 		}
 	}
 
+	private ParserEntityFactory getEntityFactory() {
+		return entityFactoryRef.get();
+	}
 }
 
 /* public */ load
@@ -108,7 +111,7 @@
 						ed.setChecks(new ArrayList<AST>(checks));
 						checks.clear();
 					}
-					entityFactory.add(name, ed);
+					getEntityFactory().add(name, ed);
 				}
 			)+
 		)
@@ -118,7 +121,7 @@
 { HashMap<String, String> m = new HashMap<String, String>(); String key = null,
value = null; }
 	:	#(	o:OPTIONS
 			( #( ASSIGN key=optionKV value=optionKV { m.put(key, value); } ) )+
-		) { entityFactory.setDefaultOptions(o.getText(), m); }
+		) { getEntityFactory().setDefaultOptions(o.getText(), m); }
 	;
 
 protected entity returns [Entity e = null]
@@ -131,12 +134,7 @@
 	;
 
 protected typeRef returns [Entity e = null]
-{
-	if (entityFactory == null) {
-		throw new IllegalStateException("entityFactory is null");
-	}
-}
-	:	#(t:TYPEREF { e = entityFactory.getEntity(t.getText()); }
+	:	#(t:TYPEREF { e = getEntityFactory().getEntity(t.getText()); }
 			( entityOptions[e] )?
 			( e=value[e] )?
 		)
@@ -185,12 +183,12 @@
 	;
 
 protected fieldDef returns [Entity e = null]
-	:	(	l:LENGTH { e = entityFactory.createField(Integer.parseInt(l.getText())); }
+	:	(	l:LENGTH { e = getEntityFactory().createField(Integer.parseInt(l.getText())); }
 			( entityOptions[e] )?
 			( e=value[e] )?
-		|	v:VALUE { e = entityFactory.createField(getBytes(v.getText())); }
+		|	v:VALUE { e = getEntityFactory().createField(getBytes(v.getText())); }
 			( e=immutable[e] )?
-		|	#(	RANGE { e = entityFactory.createDynamicField(); }
+		|	#(	RANGE { e = getEntityFactory().createDynamicField(); }
 				( n:MIN { ((DynamicField) e).getBounds().setMinimum(Integer.parseInt(n.getText())); }
)?
 				( x:MAX { ((DynamicField) e).getBounds().setMaximum(Integer.parseInt(x.getText())); }
)?
 			)



Mime
View raw message