Project

General

Profile

« Previous | Next » 

Revision 47441

merged uoa-commons and uoa-utils. Packages and class names remain the same

View differences:

modules/uoa-utils/trunk/src/test/java/eu/dnetlib/utils/parser/text.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<result xmlns:dri="http://www.driver-repository.eu/namespace/dri" xmlns:oaf="http://namespace.openaire.eu/oaf" xmlns:dc="http://purl.org/dc/elements/1.1/" type="result">
3
   <field name="resultId" multiplicity="false" indexId="objIdentifier" label="Object id" value="WOS:000277866500014"/>
4
   <field name="title" indexId="resulttitle" multiplicity="true" label="Title" value="Analysis of cell viability in intervertebral disc: Effect of endplate permeability on cell population"/>
5
   <field name="subject" indexId="resultsubject" multiplicity="true" label="Subject(s)" value="Biophysics"/>
6
   <field name="subject" indexId="resultsubject" multiplicity="true" label="Subject(s)" value="Engineering, Biomedical"/>
7
   <field name="dateofacceptance" indexId="resultdateofacceptance" multiplicity="true" label="Date of acceptance" value="2010-01-01"/>
8
   <field name="description" indexId="resultdescription" multiplicity="true" label="Description" value="Responsible for making and maintaining the extracellular matrix, the cells of intervertebral discs are supplied with essential nutrients by diffusion from the blood supply through mainly the cartilaginous endplates (CEPs) and disc tissue. Decrease in transport rate and increase in cellular activity may adversely disturb the intricate supply-demand balance leading ultimately to cell death and disc degeneration. The present numerical study aimed to introduce for the first time cell viability criteria into nonlinear coupled nutrition transport equations thereby evaluating the dynamic nutritional processes governing viable cell population and concentrations of oxygen, glucose and lactic acid in the disc as CEP exchange area dropped from a fully permeable condition to an almost impermeable one. A uniaxial model of an in vitro cell culture analogue of the disc is first employed to examine and validate cell viability criteria. An axisymmetric model of the disc with four distinct regions was subsequently used to investigate the survival of cells at different CEP exchange areas. In agreement with measurements, predictions of the diffusion chamber model demonstrated substantial cell death as essential nutrient concentrations fell to levels too low to support cells. Cells died away from the nutrient supply and at higher cell densities. In the disc model, the nucleus region being farthest away from supply sources was most affected; cell death initiated first as CEP exchange area dropped below similar to 40% and continued exponentially thereafter to depletion as CEP calcified further. In cases with loss of endplate permeability and/or disruptions therein, as well as changes in geometry and fall in diffusivity associated with fluid outflow, the nutrient concentrations could fall to levels inadequate to maintain cellular activity or viability, resulting in cell death and disc degeneration. (C) 2010 Elsevier Ltd. All rights reserved."/>
9
   <field name="publisher" indexId="resultpublisher" multiplicity="true" label="Publisher(s)" value="ELSEVIER SCI LTD"/>
10
   <field name="typeclass" indexId="resulttypeclass" multiplicity="true" label="Type class" value="0001"/>
11
   <field name="language" indexId="resultlanguage" multiplicity="true" label="Language(s)" value="eng"/>
12
   <field name="rights" indexId="resultrights" multiplicity="true" label="Acces mode" value="Closed Access"/>
13
   <field name="type" indexId="resulttype" multiplicity="true" label="Type" value="Article"/>
14
   <field name="booleanValue" indexId="resulttype" multiplicity="true" label="Type" value="wrongvalue"/>
15
   <field name="compliancy" indexId="resulttype" multiplicity="true" label="Type" value="true"/>
16
   <field name="odnumberofitemsdate" indexId="datasourceodnumberofitemsdate" multiplicity="true" label="date" value="2012-10-30"/>
17
   <field name="author" indexId="" multiplicity="true">
18
      <field name="personId" indexId="relpersonid" multiplicity="false" label="Person id" value="WOS:000277866500014_A._Shirazi-Adl"/>
19
      <field name="fullname" indexId="relperson" multiplicity="false" label="Person fullname" value="A. Shirazi-Adl"/>
20
   </field>
21
   <field name="author" indexId="" multiplicity="true">
22
      <field name="personId" indexId="relpersonid" multiplicity="false" label="Person id" value="WOS:000277866500014_M._Taheri"/>
23
      <field name="fullname" indexId="relperson" multiplicity="false" label="Person fullname" value="M. Taheri"/>
24
   </field>
25
   <field name="author" indexId="" multiplicity="true">
26
      <field name="personId" indexId="relpersonid" multiplicity="false" label="Person id" value="WOS:000277866500014_J._P._G._Urban"/>
27
      <field name="fullname" indexId="relperson" multiplicity="false" label="Person fullname" value="J. P. G. Urban"/>
28
   </field>
29
   <field name="project" indexId="" multiplicity="true">
30
      <field name="project id" indexId="relprojectid" multiplicity="false" label="Project id" value="ec::201626"/>
31
      <field name="projectname" indexId="relprojectname" multiplicity="false" label="Project(s)" value="GENODISC"/>
32
      <field name="projectdescription" indexId="relprojectdescription" multiplicity="false" label="Project description" value="Disc-degeneration linked pathologies: novel biomarkers and diagnostics for targeting treatment and repair"/>
33
      <field name="projectcontracttypeclass" indexId="???" multiplicity="false" label="Project contract type class" value="CP"/>
34
      <field name="projectcontracttypescheme" indexId="???" multiplicity="false" label="Project contract type scheme" value="ec:FP7contractTypes"/>
35
   </field>
36
   <field name="project" indexId="" multiplicity="true">
37
		<field name="project id" indexId="objIdentifier" multiplicity="false" label="Project id" value="ec::216444"/>
38
		<field name="projectcode" indexId="projectcode" multiplicity="false" label="Project(s)" value="216444"/>
39
		<field name="projectacronym" indexId="projectacronym" multiplicity="false" label="Project(s)" value="PETAMEDIA"/>
40
		<field name="projecttitle" indexId="projecttitle" multiplicity="false" label="Project title" value="PEer-to-peer TAgged MEDIA"/>
41
		<field name="projectcontracttypeid" indexId="projectcontracttypeid" multiplicity="false" label="Project contract type id" value="NoE"/>
42
		<field name="projectcontracttypename" indexId="projectcontracttypename" multiplicity="false" label="Project contract type name" value="Network of Excellence"/>
43
	</field>
44
   <field name="repository" indexId="" multiplicity="true">
45
      <field name="instanceId" indexId="" multiplicity="false" value="WOS:000277866500014"/>
46
      <field name="datasource" indexId="" multiplicity="true">
47
         <field name="hostedby" indexId="resulthostingdatasourceid" multiplicity="false" value="openaire"/>
48
         <field name="collectedfrom" indexId="resultcollectedfromdatasourceid" multiplicity="false" value=""/>
49
      </field>
50
      <field name="identifier" indexId="resultidentifier" multiplicity="true" value="http://dx.doi.org/10.1016/j.jbiomech.2010.01.023"/>
51
   </field>
52
</result>
modules/uoa-utils/trunk/src/test/java/eu/dnetlib/utils/parser/ParserTest.java
1
package eu.dnetlib.utils.parser;
2

  
3
import static org.junit.Assert.assertEquals;
4
import static org.junit.Assert.assertNotNull;
5
import static org.junit.Assert.assertNull;
6

  
7
import javax.xml.xpath.XPathExpressionException;
8

  
9
import org.junit.Before;
10
import org.junit.Test;
11

  
12

  
13
public class ParserTest {
14

  
15
	private String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><result xmlns:dri=\"http://www.driver-repository.eu/namespace/dri\" xmlns:oaf=\"http://namespace.openaire.eu/oaf\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\" type=\"result\">   <field name=\"resultId\" multiplicity=\"false\" indexId=\"objIdentifier\" label=\"Object id\" value=\"WOS:000277866500014\"/>   <field name=\"title\" indexId=\"resulttitle\" multiplicity=\"true\" label=\"Title\" value=\"Analysis of cell viability in intervertebral disc: Effect of endplate permeability on cell population\"/>   <field name=\"subject\" indexId=\"resultsubject\" multiplicity=\"true\" label=\"Subject(s)\" value=\"Biophysics\"/>   <field name=\"subject\" indexId=\"resultsubject\" multiplicity=\"true\" label=\"Subject(s)\" value=\"Engineering, Biomedical\"/>   <field name=\"dateofacceptance\" indexId=\"resultdateofacceptance\" multiplicity=\"true\" label=\"Date of acceptance\" value=\"2010-01-01\"/>   <field name=\"description\" indexId=\"resultdescription\" multiplicity=\"true\" label=\"Description\" value=\"Responsible for making and maintaining the extracellular matrix, the cells of intervertebral discs are supplied with essential nutrients by diffusion from the blood supply through mainly the cartilaginous endplates (CEPs) and disc tissue. Decrease in transport rate and increase in cellular activity may adversely disturb the intricate supply-demand balance leading ultimately to cell death and disc degeneration. The present numerical study aimed to introduce for the first time cell viability criteria into nonlinear coupled nutrition transport equations thereby evaluating the dynamic nutritional processes governing viable cell population and concentrations of oxygen, glucose and lactic acid in the disc as CEP exchange area dropped from a fully permeable condition to an almost impermeable one. A uniaxial model of an in vitro cell culture analogue of the disc is first employed to examine and validate cell viability criteria. An axisymmetric model of the disc with four distinct regions was subsequently used to investigate the survival of cells at different CEP exchange areas. In agreement with measurements, predictions of the diffusion chamber model demonstrated substantial cell death as essential nutrient concentrations fell to levels too low to support cells. Cells died away from the nutrient supply and at higher cell densities. In the disc model, the nucleus region being farthest away from supply sources was most affected; cell death initiated first as CEP exchange area dropped below similar to 40% and continued exponentially thereafter to depletion as CEP calcified further. In cases with loss of endplate permeability and/or disruptions therein, as well as changes in geometry and fall in diffusivity associated with fluid outflow, the nutrient concentrations could fall to levels inadequate to maintain cellular activity or viability, resulting in cell death and disc degeneration. (C) 2010 Elsevier Ltd. All rights reserved.\"/>   <field name=\"publisher\" indexId=\"resultpublisher\" multiplicity=\"true\" label=\"Publisher(s)\" value=\"ELSEVIER SCI LTD\"/>   <field name=\"typeclass\" indexId=\"resulttypeclass\" multiplicity=\"true\" label=\"Type class\" value=\"0001\"/>   <field name=\"language\" indexId=\"resultlanguage\" multiplicity=\"true\" label=\"Language(s)\" value=\"eng\"/>   <field name=\"rights\" indexId=\"resultrights\" multiplicity=\"true\" label=\"Acces mode\" value=\"Closed Access\"/>   <field name=\"type\" indexId=\"resulttype\" multiplicity=\"true\" label=\"Type\" value=\"Article\"/>   " + 
16
	"<field name=\"author\" indexId=\"\" multiplicity=\"true\" value=\"WOS:000277866500014_A._Shirazi-Adl\">" +
17
		" <field name=\"personId\" indexId=\"relpersonid\" multiplicity=\"false\" label=\"Person id\" value=\"WOS:000277866500014_A._Shirazi-Adl\"/>" +
18
		" <field name=\"fullname\" indexId=\"relperson\" multiplicity=\"false\" label=\"Person fullname\" value=\"A. Shirazi-Adl\"/>  " +
19
	" </field> " +
20
	"<field name=\"author\" indexId=\"objIdentifier\" multiplicity=\"true\" value=\"WOS:000292086400014_Yuriy_I._Prostov\">" +
21
			"<field name=\"personId\" indexId=\"objIdentifier\" multiplicity=\"false\" label=\"Person id\" value=\"WOS:000292086400014_Yuriy_I._Prostov\"/>" +
22
			"<field name=\"role\" indexId=\"\" multiplicity=\"false\" label=\"role\" value=\"author\"/>" +
23
			"<field name=\"fullname\" indexId=\"personfullname\" multiplicity=\"false\" label=\"Person fullname\" value=\"Prostov, Yuriy I.\"/>" +
24
			"<field name=\"ranking\" indexId=\"\" multiplicity=\"false\" label=\"ranking\" value=\"3\"/>" +
25
	"</field>" +
26
	"<field name=\"author\" indexId=\"objIdentifier\" multiplicity=\"true\" value=\"WOS:000292086400014_Duc-Truong_Pham\">" +
27
		"<field name=\"personId\" indexId=\"objIdentifier\" multiplicity=\"false\" label=\"Person id\" value=\"WOS:000292086400014_Duc-Truong_Pham\"/>" +
28
		"<field name=\"role\" indexId=\"\" multiplicity=\"false\" label=\"role\" value=\"author\"/>" +
29
		"<field name=\"fullname\" indexId=\"personfullname\" multiplicity=\"false\" label=\"Person fullname\" value=\"Pham, Duc-Truong\"/>" +
30
		"<field name=\"ranking\" indexId=\"\" multiplicity=\"false\" label=\"ranking\" value=\"1\"/>" +
31
	"</field>" +
32
	"<field name=\"author\" indexId=\"objIdentifier\" multiplicity=\"true\" value=\"WOS:000292086400014_Maria_M._Suarez-Alvarez\">" +
33
		"<field name=\"personId\" indexId=\"objIdentifier\" multiplicity=\"false\" label=\"Person id\" value=\"WOS:000292086400014_Maria_M._Suarez-Alvarez\"/>" +
34
		"<field name=\"role\" indexId=\"\" multiplicity=\"false\" label=\"role\" value=\"author\"/>" +
35
		"<field name=\"fullname\" indexId=\"personfullname\" multiplicity=\"false\" label=\"Person fullname\" value=\"Suarez-Alvarez, Maria M.\"/>" +
36
		"<field name=\"ranking\" indexId=\"\" multiplicity=\"false\" label=\"ranking\" value=\"2\"/>"+
37
	"</field>" +	
38
	"<field name=\"project\" indexId=\"objIdentifier\" multiplicity=\"true\" value=\"ec::216444\">" +
39
		"<field name=\"projectid\" indexId=\"relprojectid\" multiplicity=\"false\" label=\"Project id\" value=\"ec::201626\"/>      " +
40
		"<field name=\"projectname\" indexId=\"relprojectname\" multiplicity=\"false\" label=\"Project(s)\" value=\"GENODISC\"/>      " +
41
		"<field name=\"projectdescription\" indexId=\"relprojectdescription\" multiplicity=\"false\" label=\"Project description\" value=\"Disc-degeneration linked pathologies: novel biomarkers and diagnostics for targeting treatment and repair\"/>      " +
42
		"<field name=\"projectcontracttypeclass\" indexId=\"???\" multiplicity=\"false\" label=\"Project contract type class\" value=\"CP\"/>      " +
43
		"<field name=\"projectcontracttypescheme\" indexId=\"???\" multiplicity=\"false\" label=\"Project contract type scheme\" value=\"ec:FP7contractTypes\"/>   " +
44
	"</field>   " +
45
	"<field name=\"project\" indexId=\"objIdentifier\" multiplicity=\"true\" value=\"ec::224853\">" +
46
		"<field name=\"projectid\" indexId=\"objIdentifier\" multiplicity=\"false\" label=\"Project id\" value=\"ec::216444\"/>" +
47
		"<field name=\"projectcode\" indexId=\"projectcode\" multiplicity=\"false\" label=\"Project(s)\" value=\"216444\"/>" +
48
		"<field name=\"projectacronym\" indexId=\"projectacronym\" multiplicity=\"false\" label=\"Project(s)\" value=\"PETAMEDIA\"/>" +
49
		"<field name=\"projecttitle\" indexId=\"projecttitle\" multiplicity=\"false\" label=\"Project title\" value=\"PEer-to-peer TAgged MEDIA\"/>" +
50
		"<field name=\"projectcontracttypeid\" indexId=\"projectcontracttypeid\" multiplicity=\"false\" label=\"Project contract type id\" value=\"NoE\"/>" +
51
		"<field name=\"projectcontracttypename\" indexId=\"projectcontracttypename\" multiplicity=\"false\" label=\"Project contract type name\" value=\"Network of Excellence\"/>" +
52
	"</field>" +
53
	
54
	"<field name=\"repository\" indexId=\"\" multiplicity=\"true\">      " +
55
		"<field name=\"instanceId\" indexId=\"\" multiplicity=\"false\" value=\"WOS:000277866500014\"/>      " +
56
			"<field name=\"datasource\" indexId=\"\" multiplicity=\"true\">         " +
57
			"<field name=\"hostedby\" indexId=\"resulthostingdatasourceid\" multiplicity=\"false\" value=\"\"/>         " +
58
			"<field name=\"collectedfrom\" indexId=\"resultcollectedfromdatasourceid\" multiplicity=\"false\" value=\"openaire\"/>     " +
59
		"</field>      " +
60
		"<field name=\"identifier\" indexId=\"resultidentifier\" multiplicity=\"true\" value=\"http://dx.doi.org/10.1016/j.jbiomech.2010.01.023\"/>   " +
61
	"</field>" +
62
	
63
	"<field name=\"booleanValue\" indexId=\"resulttype\" multiplicity=\"true\" label=\"Type\" value=\"wrongvalue\"/>" +
64
	"<field name=\"compliancy\" indexId=\"resulttype\" multiplicity=\"true\" label=\"Type\" value=\"true\"/>" +
65
	"<field name=\"odnumberofitemsdate\" indexId=\"datasourceodnumberofitemsdate\" multiplicity=\"true\" label=\"date\" value=\"2012-10-30\"/>" +
66
	"<field name=\"odnumberofitems\" indexId=\"datasourceodnumberofitems\" multiplicity=\"true\" label=\"number of items\" value=\"9767\"/>" +
67
	"<field name=\"numberofitems\" indexId=\"datasourceodnumberofitems\" multiplicity=\"true\" label=\"number of items\" value=\"\"/>" +		   
68
"</result>";
69
	
70
	private Parser parser = null;
71
	
72
	@Before
73
	public void setup() {
74
		parser = new Parser(xml);
75
	}
76
	
77
	@Test
78
	public void getValuesTest() throws XPathExpressionException{
79
		//String existing
80
		assertNotNull(parser.getValues("author.fullname"));
81
		assertEquals(4, parser.getValues("author.fullname").length);
82
		assertEquals("Prostov, Yuriy I.", parser.getValues("author.fullname")[1]);
83
		
84
		//String existing
85
		assertNotNull(parser.getValues("resultId"));
86
		assertEquals(1, parser.getValues("resultId").length);
87
		assertEquals("WOS:000277866500014", parser.getValue("resultId"));
88
		
89
		//String not existing
90
		assertNull(parser.getValue("foo"));
91
		assertNull(parser.getValues("foo"));
92
		
93
		assertEquals("openaire",parser.getValue("repository.datasource.collectedfrom"));		
94
		assertNull(parser.getValue("repository.foo.collectedfrom"));
95
		
96
		//String existing - wrong request		
97
		assertNull(parser.getValue("project", new String[]{"ec::216444"}));
98
		
99
		//String existing - right request
100
		assertEquals("PETAMEDIA", parser.getValue("project.projectacronym", new String[]{"ec::224853"}));
101
		
102
		//String existing - right request
103
		assertEquals("PETAMEDIA", parser.getValue("project.projectacronym",new String[]{"ec::224853"}));
104
		
105
		//String not existing - right request
106
		assertNull(parser.getValue("project.projectname", new String[]{"ec::224853"}));
107
		
108
		//Boolean check
109
		assertNotNull(parser.getBoolean("booleanValue"));
110
		assertEquals(Boolean.FALSE, parser.getBoolean("booleanValue"));
111
		
112
		assertNotNull(parser.getBoolean("compliancy"));
113
		assertEquals(Boolean.TRUE, parser.getBoolean("compliancy"));
114
		
115
		assertNull(parser.getBoolean("notexisting"));
116
		
117
		//Date check
118
		assertNull(parser.getDate("notexisting","wrong-format"));
119
		assertNull(parser.getDate("odnumberofitemsdate","wrong-format"));
120
		
121
		assertNotNull(parser.getDate("odnumberofitemsdate","yyyy-mm-dd"));
122
		
123
		//Integer check
124
		assertNull(parser.getInteger("repository.datasource.collectedfrom"));
125
		assertNotNull(parser.getInteger("odnumberofitems"));
126
		
127
		assertEquals(parser.getInteger("odnumberofitems"), new Integer(9767));
128
		assertNull(parser.getInteger("numberofitems"));
129

  
130
		for (String name :parser.getValues("author")) {
131
			System.out.println(parser.getValue("author.fullname", new String[]{name}));
132
		}
133
	}
134
}
modules/uoa-utils/trunk/src/main/java/gr/uoa/di/driver/util/RefreshingServiceLocator.java
1
package gr.uoa.di.driver.util;
2

  
3
import java.util.concurrent.ScheduledExecutorService;
4
import java.util.concurrent.TimeUnit;
5

  
6
import org.apache.log4j.Logger;
7

  
8
import eu.dnetlib.api.DriverService;
9

  
10
/**
11
 * An implementation of the service locator that keeps a cache of the service
12
 * and refreshes it periodically.
13
 * 
14
 * The actual task of service discovery is performed by a locator that is 
15
 * injected. 
16
 * 
17
 * @author <a href="mailto:antleb@di.uoa.gr">Antonis Lempesis</a>
18
 *
19
 * @param <S> the service type
20
 */
21
public class RefreshingServiceLocator<S extends DriverService> implements
22
		ServiceLocator<S> {
23
	/** The locator used to discover the service */
24
	private ServiceLocator<S> locator = null;
25
	/** the cached instance of the service */
26
	private S service = null;
27
	/** the executor that runs the refresh tasks */
28
	private ScheduledExecutorService executor = null;
29
	/** the discovery period in milliseconds*/
30
	private long period = 0;
31

  
32
	@Override
33
	public synchronized S getService() {
34
		if (service == null)
35
			init();
36
		
37
		return service;
38
	}
39

  
40
	/** 
41
	 * Called to initialize the locator. Performs the first service lookup and
42
	 * also schedules the periodic refresh of the cache. 
43
	 * 
44
	 * */
45
	private void init() {
46
		this.service = locator.getService();
47

  
48
		executor.scheduleWithFixedDelay(new RefreshTask(), period, period,
49
				TimeUnit.MILLISECONDS);
50
	}
51

  
52
	/**
53
	 * A very simple runnable that refreshed the cache. No synchronization is
54
	 * needed during cache refresh: The old instance will be returned while the
55
	 * locator is working to refresh the cache.
56
	 * 
57
	 * @author <a href="mailto:antleb@di.uoa.gr">Antonis Lempesis</a>
58
	 *
59
	 */
60
	private class RefreshTask implements Runnable {
61
		private Logger logger = Logger.getLogger(RefreshTask.class);
62

  
63
		@Override
64
		public void run() {
65
			try {
66
				logger.debug("Refreshing service cache");
67
				service = locator.getService();
68
			} catch (Exception e) {
69
				logger.info("Error refreshing service", e);
70
			}
71
		}
72
	}
73

  
74
	public ServiceLocator<S> getLocator() {
75
		return locator;
76
	}
77

  
78
	public void setLocator(ServiceLocator<S> locator) {
79
		this.locator = locator;
80
	}
81

  
82
	public ScheduledExecutorService getExecutor() {
83
		return executor;
84
	}
85

  
86
	public void setExecutor(ScheduledExecutorService executor) {
87
		this.executor = executor;
88
	}
89

  
90
	public long getPeriod() {
91
		return period;
92
	}
93

  
94
	public void setPeriod(long period) {
95
		this.period = period;
96
	}
97
}
modules/uoa-utils/trunk/src/main/java/gr/uoa/di/driver/util/FallBackServiceLocator.java
1
package gr.uoa.di.driver.util;
2

  
3
import eu.dnetlib.api.DriverService;
4

  
5
public class FallBackServiceLocator<S extends DriverService>
6
	implements ServiceLocator<S> {
7

  
8
	private ServiceLocator<S> mainLocator = null;
9
	private ServiceLocator<S> fallBackLocator = null;
10
	
11
	@Override
12
	public S getService() {
13
		S service = null;
14
		
15
		if (mainLocator != null)
16
			service = mainLocator.getService();
17
		
18
		if (service == null && fallBackLocator != null)
19
			service = fallBackLocator.getService();
20
		
21
		return service;
22
	}
23

  
24
	public FallBackServiceLocator(ServiceLocator<S> mainLocator,
25
			ServiceLocator<S> fallBackLocator) {
26
		this.mainLocator = mainLocator;
27
		this.fallBackLocator = fallBackLocator;
28
	}
29

  
30
	public void setMainLocator(ServiceLocator<S> mainLocator) {
31
		this.mainLocator = mainLocator;
32
	}
33

  
34
	public void setFallBackLocator(ServiceLocator<S> fallBackLocator) {
35
		this.fallBackLocator = fallBackLocator;
36
	}
37
}
modules/uoa-utils/trunk/src/main/java/gr/uoa/di/driver/util/ServiceLocator.java
1
package gr.uoa.di.driver.util;
2

  
3
import eu.dnetlib.api.DriverService;
4

  
5
public interface ServiceLocator<S extends DriverService> {
6
	
7
	public S getService();
8
}
modules/uoa-utils/trunk/src/main/java/gr/uoa/di/driver/util/ServiceNameResolverImpl.java
1
package gr.uoa.di.driver.util;
2

  
3
import java.util.HashMap;
4
import java.util.Map;
5

  
6
import eu.dnetlib.api.DriverService;
7
import eu.dnetlib.enabling.tools.registration.ServiceNameResolver;
8

  
9
public class ServiceNameResolverImpl implements ServiceNameResolver {
10
	private Map<Class<?>, String> override = new HashMap<Class<?>, String>();
11

  
12
	@Override
13
	public String getName(Object service) {
14
		return getName(service.getClass());
15
	}
16

  
17
	@Override
18
	public String getName(Class<?> serviceInterface) {
19
		String serviceName = null;
20
		
21
		for (Class<?> i : serviceInterface.getInterfaces()) {
22
			if (DriverService.class.isAssignableFrom(i)) {
23
				if (override.get(i) != null)
24
					serviceName = override.get(i);
25
				else
26
					serviceName = i.getSimpleName();
27
			}
28
		}
29

  
30
		return serviceName;
31
	}
32

  
33
	public Map<Class<?>, String> getOverride() {
34
		return override;
35
	}
36

  
37
	public void setOverride(Map<Class<?>, String> override) {
38
		this.override = override;
39
	}
40
}
modules/uoa-utils/trunk/src/main/java/gr/uoa/di/driver/util/ServiceLocatorFactory.java
1
package gr.uoa.di.driver.util;
2

  
3
import eu.dnetlib.api.DriverService;
4

  
5
/**
6
 * A factory to create service locators.
7
 * 
8
 * @author <a href="mailto:antleb@di.uoa.gr">Antonis Lempesis</a>
9
 *
10
 */
11
public interface ServiceLocatorFactory {
12

  
13
	/**
14
	 * Creates a dynamic service locator.
15
	 * 
16
	 * @param <S> the service type.
17
	 * @param serviceClass the service class.
18
	 * @return A service locator for services of type S.
19
	 */
20
	public <S extends DriverService> ServiceLocator<S> newServiceLocator(
21
			Class<S> serviceClass);
22
	
23
	/**
24
	 * Creates a service locator. It can be either static (if serviceUrl != null)
25
	 * or dynamic.
26
	 * 
27
	 * @param <S> the service type.
28
	 * @param serviceClass the service class.
29
	 * @param serviceUrl The service URL.
30
	 * @return A service locator for services of type S.
31
	 */
32
	public <S extends DriverService> ServiceLocator<S> newServiceLocator(
33
			Class<S> serviceClass, String serviceUrl);
34
}
modules/uoa-utils/trunk/src/main/java/gr/uoa/di/driver/util/StaticServiceLocator.java
1
package gr.uoa.di.driver.util;
2

  
3
import eu.dnetlib.api.DriverService;
4

  
5
/**
6
 * An implementation of the ServiceLocator that returns a predefined instance
7
 * of a service.
8
 * 
9
 * Can be used for debug purposes, FallBackLocator or when 2 services A and B 
10
 * are deployed in the same application (in this case, service A will get an 
11
 * instance of a StaticServiceLocator<B> in order to avoid calls to the IS and 
12
 * traversing the whole SOAP stack in order to communicate with B). 
13
 * 
14
 * @author <a href="mailto:antleb@di.uoa.gr">Antonis Lempesis</a>
15
 *
16
 * @param <S>
17
 */
18
public class StaticServiceLocator<S extends DriverService>
19
	implements ServiceLocator<S> {
20
	
21
	private S service = null;
22
	
23
	public StaticServiceLocator() {
24
		
25
	}
26

  
27
	public StaticServiceLocator(S service) {
28
		this.service = service;
29
	}
30
	
31
	@Override
32
	public S getService() {
33
		return service;
34
	}
35

  
36
	public void setService(S service) {
37
		this.service = service;
38
	}
39
}
modules/uoa-utils/trunk/src/main/java/eu/dnetlib/utils/cql/CqlRuntimeException.java
1
/**
2
 * 
3
 */
4
package eu.dnetlib.utils.cql;
5

  
6
/**
7
 * @author stoumpos
8
 * 
9
 */
10

  
11
@SuppressWarnings("serial")
12
public class CqlRuntimeException extends RuntimeException {
13
	
14
	public CqlRuntimeException(String message, Throwable cause) {
15
		super(message, cause);
16
	}
17

  
18
}
modules/uoa-utils/trunk/src/main/java/eu/dnetlib/utils/cql/CqlQuery.java
1
package eu.dnetlib.utils.cql;
2

  
3
import static eu.dnetlib.utils.cql.CqlClause.CqlClauseType.BOOLEAN;
4
import static eu.dnetlib.utils.cql.CqlClause.CqlClauseType.RELATION;
5
import static eu.dnetlib.utils.cql.CqlClause.CqlClauseType.TERM;
6

  
7
import java.util.ArrayList;
8
import java.util.List;
9

  
10
/**
11
 * @author stoumpos
12
 * 
13
 */
14
public class CqlQuery {
15

  
16
	CqlClause root = null;
17

  
18
	CqlQuery() {
19
		this(null);
20
	}
21

  
22
	CqlQuery(CqlClause root) {
23
		this.root = root;
24
	}
25

  
26
	public CqlClause getRoot() {
27
		return root;
28
	}
29

  
30
	public void setRoot(CqlClause root) {
31
		this.root = root;
32
	}
33

  
34
	@Override
35
	public String toString() {
36
		return (root == null) ? "null" : root.toCqlString();
37
	}
38

  
39

  
40
	/**
41
	 * Return <code>true</code> if this query is a superset of
42
	 * <code>query</code>, otherwise <code>false</code>.
43
	 */
44
	public boolean contains(CqlQuery query) {
45
		return contains(root, query.getRoot());
46
	}
47
	
48
	private boolean contains(CqlClause big, CqlClause small) {
49
		
50
		if (big.type ==  BOOLEAN && small.type ==  BOOLEAN) {
51
			return containsBooleans((CqlBoolean) big, (CqlBoolean) small);
52
		
53
		} else if (big.type ==  BOOLEAN) {
54
			// small is either term or relation
55
			return containsBooleanTerm((CqlBoolean) big, small);
56
			
57
		} else if (small.type ==  BOOLEAN) {
58
			// big is either term or relation
59
			return containsTermBoolean(big, (CqlBoolean) small);
60
			
61
		} else if (big.type == RELATION && small.type == RELATION) {
62
			CqlRelation bigRelation = (CqlRelation) big;
63
			CqlRelation smallRelation = (CqlRelation) small;
64
			return bigRelation.index.equals(smallRelation.index)
65
				&& bigRelation.operator.equals(smallRelation.operator)
66
				&& bigRelation.value.equals(smallRelation.value);
67
			
68
		} else if (big.type == TERM && small.type == TERM) {
69
			return ((CqlTerm) big).term.equals(((CqlTerm) small).term);
70
		}
71
				
72
		return false;
73
	}
74

  
75
	private boolean containsBooleans(CqlBoolean a, CqlBoolean b) {
76
		if (a.getOperator().equalsIgnoreCase(b.getOperator())) {
77
			
78
			ArrayList<CqlClause> aList = unfold(a);
79
			ArrayList<CqlClause> bList = unfold(b);
80
			
81
			if (a.operator.equalsIgnoreCase("and")) {
82
				return subset(aList, bList);
83
				
84
			} else if (a.operator.equalsIgnoreCase("or")) {
85
				return superset(bList, aList);
86
				
87
			} else {
88
				throw new IllegalArgumentException(
89
						"Unsupported operator: " + a.operator);
90
			}
91
			
92
		} else {
93
			return contains(a, b.getLeft()) && contains(a, b.getRight());
94
				
95
		}
96
	}
97
	
98
	public ArrayList<CqlClause> unfold(CqlBoolean bool) {
99
		
100
		String op = bool.operator;
101
		ArrayList<CqlClause> siblings = new ArrayList<CqlClause>();
102
		
103
		if (bool.left.type == BOOLEAN
104
				&& ((CqlBoolean) bool.left).operator.equalsIgnoreCase(op)) {
105
			siblings.addAll(unfold((CqlBoolean) bool.left));
106
		} else {
107
			siblings.add(bool.left);
108
		}
109
		
110
		if (bool.right.type == BOOLEAN
111
				&& ((CqlBoolean) bool.right).operator.equalsIgnoreCase(op)) {
112
			siblings.addAll(unfold((CqlBoolean) bool.right));
113
		} else {
114
			siblings.add(bool.right);
115
		}
116
		
117
		return siblings;
118
	}
119

  
120
	
121
	private boolean superset(List<CqlClause> superset, List<CqlClause> subset) {
122
		if (subset.size() > superset.size()) {
123
			return false;
124
		}
125
		for (CqlClause sub : subset) {
126
			boolean found = false;
127
			for (CqlClause sup : superset) {
128
				if (contains(sup, sub)) {
129
					found = true;
130
					break;
131
				}
132
			}
133
			if (!found) {
134
				return false;
135
			}
136
		}
137
		return true;
138
	}
139

  
140
	private boolean subset(List<CqlClause> subset, List<CqlClause> superset) {
141
		if (subset.size() > superset.size()) {
142
			return false;
143
		}
144
		for (CqlClause sub : subset) {
145
			boolean found = false;
146
			for (CqlClause sup : superset) {
147
				if (contains(sub, sup)) {
148
					found = true;
149
					break;
150
				}
151
			}
152
			if (!found) {
153
				return false;
154
			}
155
		}
156
		return true;
157
	}
158

  
159
	private boolean containsBooleanTerm(CqlBoolean bool, CqlClause clause) {
160

  
161
		if (bool.getOperator().equalsIgnoreCase("and")) {
162
			// warn: assume clause is either term or relation
163
			return false;
164
		}
165
		
166
		return contains(bool.getLeft(), clause)
167
				|| contains(bool.getRight(), clause);
168
	}
169
	
170
	private boolean containsTermBoolean(CqlClause clause, CqlBoolean bool) {
171
		
172
		if (bool.getOperator().equalsIgnoreCase("or")) {
173
			// warn: assume clause is either term or relation
174
			return false;
175
		}
176
		
177
		return contains(clause, bool.getLeft())
178
				|| contains(clause, bool.getRight());
179
	}
180
}
modules/uoa-utils/trunk/src/main/java/eu/dnetlib/utils/cql/CqlTerm.java
1
package eu.dnetlib.utils.cql;
2

  
3

  
4
/**
5
 * @author stoumpos
6
 * 
7
 */
8
public class CqlTerm extends CqlClause {
9

  
10
	String term = null;
11

  
12
	public CqlTerm() {
13
		this(null);
14
	}
15

  
16
	public CqlTerm(String term) {
17
		super(CqlClauseType.TERM);
18
		this.term = term;
19
	}
20

  
21
	public String getTerm() {
22
		return term;
23
	}
24

  
25
	public void setTerm(String term) {
26
		this.term = term;
27
	}
28

  
29
	@Override
30
	public String toCqlString() {
31
		return term;
32
	}
33

  
34
	@Override
35
	public String toNodeString(String prefix) {
36
		return prefix + "term: " + toCqlString();
37
	}
38
}
modules/uoa-utils/trunk/src/main/java/eu/dnetlib/utils/cql/CqlClause.java
1
package eu.dnetlib.utils.cql;
2

  
3
/**
4
 * @author stoumpos
5
 * 
6
 */
7
public abstract class CqlClause
8
{
9
	public static enum CqlClauseType { BOOLEAN, RELATION, TERM };
10
	
11
	public final CqlClauseType type;
12
	
13
	CqlClause(CqlClauseType type) {
14
		super();
15
		this.type = type;
16
	}
17
	
18
	@Override
19
	public String toString()
20
	{
21
		return toCqlString();
22
	}
23
	
24
	public abstract String toCqlString();
25

  
26
	public abstract String toNodeString(String prefix);
27
}
modules/uoa-utils/trunk/src/main/java/eu/dnetlib/utils/cql/CqlParser.java
1
// $ANTLR 3.0.1 Cql.g3 2013-07-19 13:56:26
2

  
3
	package eu.dnetlib.utils.cql;
4

  
5

  
6
import org.antlr.runtime.*;
7
import java.util.Stack;
8
import java.util.List;
9
import java.util.ArrayList;
10

  
11

  
12
import org.antlr.runtime.tree.*;
13

  
14
public class CqlParser extends Parser {
15
    public static final String[] tokenNames = new String[] {
16
        "<invalid>", "<EOR>", "<DOWN>", "<UP>", "AND", "OR", "NOT", "PROX", "WITHIN", "EXACT", "ALL", "ANY", "IDENTIFIER", "STRING", "QUOTE", "WHITESPACE", "'>'", "'='", "'/'", "'('", "')'", "'<'", "'>='", "'<='", "'<>'"
17
    };
18
    public static final int QUOTE=14;
19
    public static final int ANY=11;
20
    public static final int IDENTIFIER=12;
21
    public static final int ALL=10;
22
    public static final int OR=5;
23
    public static final int WITHIN=8;
24
    public static final int PROX=7;
25
    public static final int WHITESPACE=15;
26
    public static final int EXACT=9;
27
    public static final int NOT=6;
28
    public static final int AND=4;
29
    public static final int EOF=-1;
30
    public static final int STRING=13;
31

  
32
        public CqlParser(TokenStream input) {
33
            super(input);
34
        }
35
        
36
    protected TreeAdaptor adaptor = new CommonTreeAdaptor();
37

  
38
    public void setTreeAdaptor(TreeAdaptor adaptor) {
39
        this.adaptor = adaptor;
40
    }
41
    public TreeAdaptor getTreeAdaptor() {
42
        return adaptor;
43
    }
44

  
45
    public String[] getTokenNames() { return tokenNames; }
46
    public String getGrammarFileName() { return "Cql.g3"; }
47

  
48

  
49
      @Override
50
      public void reportError(RecognitionException e) {
51
        throw new CqlRuntimeException("Parser Error", e);
52
      }
53

  
54

  
55
    public static class cql_return extends ParserRuleReturnScope {
56
        public CqlQuery query;
57
        CommonTree tree;
58
        public Object getTree() { return tree; }
59
    };
60

  
61
    // $ANTLR start cql
62
    // Cql.g3:33:1: cql returns [CqlQuery query] : q= cqlquery ;
63
    public final cql_return cql() throws RecognitionException {
64
        cql_return retval = new cql_return();
65
        retval.start = input.LT(1);
66

  
67
        CommonTree root_0 = null;
68

  
69
        cqlquery_return q = null;
70

  
71

  
72

  
73
        try {
74
            // Cql.g3:33:30: (q= cqlquery )
75
            // Cql.g3:33:32: q= cqlquery
76
            {
77
            root_0 = (CommonTree)adaptor.nil();
78

  
79
            pushFollow(FOLLOW_cqlquery_in_cql78);
80
            q=cqlquery();
81
            _fsp--;
82

  
83
            adaptor.addChild(root_0, q.getTree());
84

  
85
            						//System.out.println("query tree: " +
86
            						//		((CommonTree)q.tree).toStringTree() );
87
            						retval.query = q.query;
88
            					
89

  
90
            }
91

  
92
            retval.stop = input.LT(-1);
93

  
94
                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
95
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
96

  
97
        }
98
        catch (RecognitionException re) {
99
            reportError(re);
100
            recover(input,re);
101
        }
102
        finally {
103
        }
104
        return retval;
105
    }
106
    // $ANTLR end cql
107

  
108
    public static class cqlquery_return extends ParserRuleReturnScope {
109
        public CqlQuery query;
110
        CommonTree tree;
111
        public Object getTree() { return tree; }
112
    };
113

  
114
    // $ANTLR start cqlquery
115
    // Cql.g3:41:1: cqlquery returns [CqlQuery query] : ( qscope q= cqlquery | c= scopedClause );
116
    public final cqlquery_return cqlquery() throws RecognitionException {
117
        cqlquery_return retval = new cqlquery_return();
118
        retval.start = input.LT(1);
119

  
120
        CommonTree root_0 = null;
121

  
122
        cqlquery_return q = null;
123

  
124
        scopedClause_return c = null;
125

  
126
        qscope_return qscope1 = null;
127

  
128

  
129

  
130
        try {
131
            // Cql.g3:42:5: ( qscope q= cqlquery | c= scopedClause )
132
            int alt1=2;
133
            int LA1_0 = input.LA(1);
134

  
135
            if ( (LA1_0==16) ) {
136
                alt1=1;
137
            }
138
            else if ( ((LA1_0>=AND && LA1_0<=PROX)||(LA1_0>=IDENTIFIER && LA1_0<=STRING)||LA1_0==19) ) {
139
                alt1=2;
140
            }
141
            else {
142
                NoViableAltException nvae =
143
                    new NoViableAltException("41:1: cqlquery returns [CqlQuery query] : ( qscope q= cqlquery | c= scopedClause );", 1, 0, input);
144

  
145
                throw nvae;
146
            }
147
            switch (alt1) {
148
                case 1 :
149
                    // Cql.g3:42:7: qscope q= cqlquery
150
                    {
151
                    root_0 = (CommonTree)adaptor.nil();
152

  
153
                    pushFollow(FOLLOW_qscope_in_cqlquery104);
154
                    qscope1=qscope();
155
                    _fsp--;
156

  
157
                    pushFollow(FOLLOW_cqlquery_in_cqlquery109);
158
                    q=cqlquery();
159
                    _fsp--;
160

  
161
                    adaptor.addChild(root_0, q.getTree());
162
                     retval.query = q.query; 
163

  
164
                    }
165
                    break;
166
                case 2 :
167
                    // Cql.g3:43:7: c= scopedClause
168
                    {
169
                    root_0 = (CommonTree)adaptor.nil();
170

  
171
                    pushFollow(FOLLOW_scopedClause_in_cqlquery121);
172
                    c=scopedClause();
173
                    _fsp--;
174

  
175
                    adaptor.addChild(root_0, c.getTree());
176
                     retval.query = new CqlQuery(c.clause); 
177

  
178
                    }
179
                    break;
180

  
181
            }
182
            retval.stop = input.LT(-1);
183

  
184
                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
185
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
186

  
187
        }
188
        catch (RecognitionException re) {
189
            reportError(re);
190
            recover(input,re);
191
        }
192
        finally {
193
        }
194
        return retval;
195
    }
196
    // $ANTLR end cqlquery
197

  
198
    public static class qscope_return extends ParserRuleReturnScope {
199
        CommonTree tree;
200
        public Object getTree() { return tree; }
201
    };
202

  
203
    // $ANTLR start qscope
204
    // Cql.g3:45:1: qscope : ( '>' prefix '=' uri | '>' uri );
205
    public final qscope_return qscope() throws RecognitionException {
206
        qscope_return retval = new qscope_return();
207
        retval.start = input.LT(1);
208

  
209
        CommonTree root_0 = null;
210

  
211
        Token char_literal2=null;
212
        Token char_literal4=null;
213
        Token char_literal6=null;
214
        prefix_return prefix3 = null;
215

  
216
        uri_return uri5 = null;
217

  
218
        uri_return uri7 = null;
219

  
220

  
221
        CommonTree char_literal2_tree=null;
222
        CommonTree char_literal4_tree=null;
223
        CommonTree char_literal6_tree=null;
224

  
225
        try {
226
            // Cql.g3:47:9: ( '>' prefix '=' uri | '>' uri )
227
            int alt2=2;
228
            int LA2_0 = input.LA(1);
229

  
230
            if ( (LA2_0==16) ) {
231
                switch ( input.LA(2) ) {
232
                case IDENTIFIER:
233
                    {
234
                    int LA2_2 = input.LA(3);
235

  
236
                    if ( ((LA2_2>=AND && LA2_2<=PROX)||(LA2_2>=IDENTIFIER && LA2_2<=STRING)||LA2_2==16||LA2_2==19) ) {
237
                        alt2=2;
238
                    }
239
                    else if ( (LA2_2==17) ) {
240
                        alt2=1;
241
                    }
242
                    else {
243
                        NoViableAltException nvae =
244
                            new NoViableAltException("45:1: qscope : ( '>' prefix '=' uri | '>' uri );", 2, 2, input);
245

  
246
                        throw nvae;
247
                    }
248
                    }
249
                    break;
250
                case STRING:
251
                    {
252
                    int LA2_3 = input.LA(3);
253

  
254
                    if ( ((LA2_3>=AND && LA2_3<=PROX)||(LA2_3>=IDENTIFIER && LA2_3<=STRING)||LA2_3==16||LA2_3==19) ) {
255
                        alt2=2;
256
                    }
257
                    else if ( (LA2_3==17) ) {
258
                        alt2=1;
259
                    }
260
                    else {
261
                        NoViableAltException nvae =
262
                            new NoViableAltException("45:1: qscope : ( '>' prefix '=' uri | '>' uri );", 2, 3, input);
263

  
264
                        throw nvae;
265
                    }
266
                    }
267
                    break;
268
                case AND:
269
                    {
270
                    int LA2_4 = input.LA(3);
271

  
272
                    if ( (LA2_4==17) ) {
273
                        alt2=1;
274
                    }
275
                    else if ( ((LA2_4>=AND && LA2_4<=PROX)||(LA2_4>=IDENTIFIER && LA2_4<=STRING)||LA2_4==16||LA2_4==19) ) {
276
                        alt2=2;
277
                    }
278
                    else {
279
                        NoViableAltException nvae =
280
                            new NoViableAltException("45:1: qscope : ( '>' prefix '=' uri | '>' uri );", 2, 4, input);
281

  
282
                        throw nvae;
283
                    }
284
                    }
285
                    break;
286
                case OR:
287
                    {
288
                    int LA2_5 = input.LA(3);
289

  
290
                    if ( (LA2_5==17) ) {
291
                        alt2=1;
292
                    }
293
                    else if ( ((LA2_5>=AND && LA2_5<=PROX)||(LA2_5>=IDENTIFIER && LA2_5<=STRING)||LA2_5==16||LA2_5==19) ) {
294
                        alt2=2;
295
                    }
296
                    else {
297
                        NoViableAltException nvae =
298
                            new NoViableAltException("45:1: qscope : ( '>' prefix '=' uri | '>' uri );", 2, 5, input);
299

  
300
                        throw nvae;
301
                    }
302
                    }
303
                    break;
304
                case NOT:
305
                    {
306
                    int LA2_6 = input.LA(3);
307

  
308
                    if ( (LA2_6==17) ) {
309
                        alt2=1;
310
                    }
311
                    else if ( ((LA2_6>=AND && LA2_6<=PROX)||(LA2_6>=IDENTIFIER && LA2_6<=STRING)||LA2_6==16||LA2_6==19) ) {
312
                        alt2=2;
313
                    }
314
                    else {
315
                        NoViableAltException nvae =
316
                            new NoViableAltException("45:1: qscope : ( '>' prefix '=' uri | '>' uri );", 2, 6, input);
317

  
318
                        throw nvae;
319
                    }
320
                    }
321
                    break;
322
                case PROX:
323
                    {
324
                    int LA2_7 = input.LA(3);
325

  
326
                    if ( (LA2_7==17) ) {
327
                        alt2=1;
328
                    }
329
                    else if ( ((LA2_7>=AND && LA2_7<=PROX)||(LA2_7>=IDENTIFIER && LA2_7<=STRING)||LA2_7==16||LA2_7==19) ) {
330
                        alt2=2;
331
                    }
332
                    else {
333
                        NoViableAltException nvae =
334
                            new NoViableAltException("45:1: qscope : ( '>' prefix '=' uri | '>' uri );", 2, 7, input);
335

  
336
                        throw nvae;
337
                    }
338
                    }
339
                    break;
340
                default:
341
                    NoViableAltException nvae =
342
                        new NoViableAltException("45:1: qscope : ( '>' prefix '=' uri | '>' uri );", 2, 1, input);
343

  
344
                    throw nvae;
345
                }
346

  
347
            }
348
            else {
349
                NoViableAltException nvae =
350
                    new NoViableAltException("45:1: qscope : ( '>' prefix '=' uri | '>' uri );", 2, 0, input);
351

  
352
                throw nvae;
353
            }
354
            switch (alt2) {
355
                case 1 :
356
                    // Cql.g3:47:11: '>' prefix '=' uri
357
                    {
358
                    root_0 = (CommonTree)adaptor.nil();
359

  
360
                    char_literal2=(Token)input.LT(1);
361
                    match(input,16,FOLLOW_16_in_qscope137); 
362
                    char_literal2_tree = (CommonTree)adaptor.create(char_literal2);
363
                    adaptor.addChild(root_0, char_literal2_tree);
364

  
365
                    pushFollow(FOLLOW_prefix_in_qscope139);
366
                    prefix3=prefix();
367
                    _fsp--;
368

  
369
                    adaptor.addChild(root_0, prefix3.getTree());
370
                    char_literal4=(Token)input.LT(1);
371
                    match(input,17,FOLLOW_17_in_qscope141); 
372
                    char_literal4_tree = (CommonTree)adaptor.create(char_literal4);
373
                    adaptor.addChild(root_0, char_literal4_tree);
374

  
375
                    pushFollow(FOLLOW_uri_in_qscope143);
376
                    uri5=uri();
377
                    _fsp--;
378

  
379
                    adaptor.addChild(root_0, uri5.getTree());
380

  
381
                    }
382
                    break;
383
                case 2 :
384
                    // Cql.g3:47:32: '>' uri
385
                    {
386
                    root_0 = (CommonTree)adaptor.nil();
387

  
388
                    char_literal6=(Token)input.LT(1);
389
                    match(input,16,FOLLOW_16_in_qscope147); 
390
                    char_literal6_tree = (CommonTree)adaptor.create(char_literal6);
391
                    adaptor.addChild(root_0, char_literal6_tree);
392

  
393
                    pushFollow(FOLLOW_uri_in_qscope149);
394
                    uri7=uri();
395
                    _fsp--;
396

  
397
                    adaptor.addChild(root_0, uri7.getTree());
398

  
399
                    }
400
                    break;
401

  
402
            }
403
            retval.stop = input.LT(-1);
404

  
405
                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
406
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
407

  
408
        }
409
        catch (RecognitionException re) {
410
            reportError(re);
411
            recover(input,re);
412
        }
413
        finally {
414
        }
415
        return retval;
416
    }
417
    // $ANTLR end qscope
418

  
419
    public static class prefix_return extends ParserRuleReturnScope {
420
        CommonTree tree;
421
        public Object getTree() { return tree; }
422
    };
423

  
424
    // $ANTLR start prefix
425
    // Cql.g3:48:1: prefix : term ;
426
    public final prefix_return prefix() throws RecognitionException {
427
        prefix_return retval = new prefix_return();
428
        retval.start = input.LT(1);
429

  
430
        CommonTree root_0 = null;
431

  
432
        term_return term8 = null;
433

  
434

  
435

  
436
        try {
437
            // Cql.g3:48:9: ( term )
438
            // Cql.g3:48:11: term
439
            {
440
            root_0 = (CommonTree)adaptor.nil();
441

  
442
            pushFollow(FOLLOW_term_in_prefix158);
443
            term8=term();
444
            _fsp--;
445

  
446
            adaptor.addChild(root_0, term8.getTree());
447

  
448
            }
449

  
450
            retval.stop = input.LT(-1);
451

  
452
                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
453
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
454

  
455
        }
456
        catch (RecognitionException re) {
457
            reportError(re);
458
            recover(input,re);
459
        }
460
        finally {
461
        }
462
        return retval;
463
    }
464
    // $ANTLR end prefix
465

  
466
    public static class uri_return extends ParserRuleReturnScope {
467
        CommonTree tree;
468
        public Object getTree() { return tree; }
469
    };
470

  
471
    // $ANTLR start uri
472
    // Cql.g3:49:1: uri : term ;
473
    public final uri_return uri() throws RecognitionException {
474
        uri_return retval = new uri_return();
475
        retval.start = input.LT(1);
476

  
477
        CommonTree root_0 = null;
478

  
479
        term_return term9 = null;
480

  
481

  
482

  
483
        try {
484
            // Cql.g3:49:7: ( term )
485
            // Cql.g3:49:9: term
486
            {
487
            root_0 = (CommonTree)adaptor.nil();
488

  
489
            pushFollow(FOLLOW_term_in_uri168);
490
            term9=term();
491
            _fsp--;
492

  
493
            adaptor.addChild(root_0, term9.getTree());
494

  
495
            }
496

  
497
            retval.stop = input.LT(-1);
498

  
499
                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
500
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
501

  
502
        }
503
        catch (RecognitionException re) {
504
            reportError(re);
505
            recover(input,re);
506
        }
507
        finally {
508
        }
509
        return retval;
510
    }
511
    // $ANTLR end uri
512

  
513
    public static class scopedClause_return extends ParserRuleReturnScope {
514
        public CqlClause clause;
515
        CommonTree tree;
516
        public Object getTree() { return tree; }
517
    };
518

  
519
    // $ANTLR start scopedClause
520
    // Cql.g3:50:1: scopedClause returns [CqlClause clause] : left= searchClause (op= booleanGroup right= searchClause )* ;
521
    public final scopedClause_return scopedClause() throws RecognitionException {
522
        scopedClause_return retval = new scopedClause_return();
523
        retval.start = input.LT(1);
524

  
525
        CommonTree root_0 = null;
526

  
527
        searchClause_return left = null;
528

  
529
        booleanGroup_return op = null;
530

  
531
        searchClause_return right = null;
532

  
533

  
534

  
535
        try {
536
            // Cql.g3:53:41: (left= searchClause (op= booleanGroup right= searchClause )* )
537
            // Cql.g3:54:3: left= searchClause (op= booleanGroup right= searchClause )*
538
            {
539
            root_0 = (CommonTree)adaptor.nil();
540

  
541
            pushFollow(FOLLOW_searchClause_in_scopedClause188);
542
            left=searchClause();
543
            _fsp--;
544

  
545
            adaptor.addChild(root_0, left.getTree());
546
             retval.clause = left.clause; 
547
            // Cql.g3:55:3: (op= booleanGroup right= searchClause )*
548
            loop3:
549
            do {
550
                int alt3=2;
551
                int LA3_0 = input.LA(1);
552

  
553
                if ( ((LA3_0>=AND && LA3_0<=PROX)) ) {
554
                    alt3=1;
555
                }
556

  
557

  
558
                switch (alt3) {
559
            	case 1 :
560
            	    // Cql.g3:55:4: op= booleanGroup right= searchClause
561
            	    {
562
            	    pushFollow(FOLLOW_booleanGroup_in_scopedClause197);
563
            	    op=booleanGroup();
564
            	    _fsp--;
565

  
566
            	    root_0 = (CommonTree)adaptor.becomeRoot(op.getTree(), root_0);
567
            	    pushFollow(FOLLOW_searchClause_in_scopedClause202);
568
            	    right=searchClause();
569
            	    _fsp--;
570

  
571
            	    adaptor.addChild(root_0, right.getTree());
572
            	     retval.clause = new CqlBoolean(retval.clause, op.value, right.clause); 
573

  
574
            	    }
575
            	    break;
576

  
577
            	default :
578
            	    break loop3;
579
                }
580
            } while (true);
581

  
582

  
583
            }
584

  
585
            retval.stop = input.LT(-1);
586

  
587
                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
588
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
589

  
590
        }
591
        catch (RecognitionException re) {
592
            reportError(re);
593
            recover(input,re);
594
        }
595
        finally {
596
        }
597
        return retval;
598
    }
599
    // $ANTLR end scopedClause
600

  
601
    public static class booleanGroup_return extends ParserRuleReturnScope {
602
        public String value;
603
        CommonTree tree;
604
        public Object getTree() { return tree; }
605
    };
606

  
607
    // $ANTLR start booleanGroup
608
    // Cql.g3:60:1: booleanGroup returns [String value] : b= bool ( modifierList )? ;
609
    public final booleanGroup_return booleanGroup() throws RecognitionException {
610
        booleanGroup_return retval = new booleanGroup_return();
611
        retval.start = input.LT(1);
612

  
613
        CommonTree root_0 = null;
614

  
615
        bool_return b = null;
616

  
617
        modifierList_return modifierList10 = null;
618

  
619

  
620

  
621
        try {
622
            // Cql.g3:60:37: (b= bool ( modifierList )? )
623
            // Cql.g3:61:2: b= bool ( modifierList )?
624
            {
625
            root_0 = (CommonTree)adaptor.nil();
626

  
627
            pushFollow(FOLLOW_bool_in_booleanGroup230);
628
            b=bool();
629
            _fsp--;
630

  
631
            adaptor.addChild(root_0, b.getTree());
632
            // Cql.g3:61:9: ( modifierList )?
633
            int alt4=2;
634
            int LA4_0 = input.LA(1);
635

  
636
            if ( (LA4_0==18) ) {
637
                alt4=1;
638
            }
639
            switch (alt4) {
640
                case 1 :
641
                    // Cql.g3:61:10: modifierList
642
                    {
643
                    pushFollow(FOLLOW_modifierList_in_booleanGroup233);
644
                    modifierList10=modifierList();
645
                    _fsp--;
646

  
647
                    adaptor.addChild(root_0, modifierList10.getTree());
648

  
649
                    }
650
                    break;
651

  
652
            }
653

  
654
             retval.value = b.value; 
655

  
656
            }
657

  
658
            retval.stop = input.LT(-1);
659

  
660
                retval.tree = (CommonTree)adaptor.rulePostProcessing(root_0);
661
                adaptor.setTokenBoundaries(retval.tree, retval.start, retval.stop);
662

  
663
        }
664
        catch (RecognitionException re) {
665
            reportError(re);
666
            recover(input,re);
667
        }
668
        finally {
669
        }
670
        return retval;
671
    }
672
    // $ANTLR end booleanGroup
673

  
674
    public static class bool_return extends ParserRuleReturnScope {
675
        public String value;
676
        CommonTree tree;
677
        public Object getTree() { return tree; }
678
    };
679

  
680
    // $ANTLR start bool
681
    // Cql.g3:62:1: bool returns [String value] : ( AND | OR | NOT | PROX );
682
    public final bool_return bool() throws RecognitionException {
683
        bool_return retval = new bool_return();
684
        retval.start = input.LT(1);
685

  
686
        CommonTree root_0 = null;
687

  
688
        Token AND11=null;
689
        Token OR12=null;
690
        Token NOT13=null;
691
        Token PROX14=null;
692

  
693
        CommonTree AND11_tree=null;
694
        CommonTree OR12_tree=null;
695
        CommonTree NOT13_tree=null;
696
        CommonTree PROX14_tree=null;
697

  
698
        try {
699
            // Cql.g3:63:2: ( AND | OR | NOT | PROX )
700
            int alt5=4;
701
            switch ( input.LA(1) ) {
702
            case AND:
703
                {
704
                alt5=1;
705
                }
706
                break;
707
            case OR:
708
                {
709
                alt5=2;
710
                }
711
                break;
712
            case NOT:
713
                {
714
                alt5=3;
715
                }
716
                break;
717
            case PROX:
718
                {
719
                alt5=4;
720
                }
721
                break;
722
            default:
723
                NoViableAltException nvae =
724
                    new NoViableAltException("62:1: bool returns [String value] : ( AND | OR | NOT | PROX );", 5, 0, input);
725

  
726
                throw nvae;
727
            }
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff