/** * Create a StandardTypeLocator for the given ClassLoader. * @param classLoader the ClassLoader to delegate to */ public StandardTypeLocator(@Nullable ClassLoader classLoader) { this.classLoader = classLoader; // Similar to when writing regular Java code, it only knows about java.lang by default registerImport("java.lang"); }
/** * Create a StandardTypeLocator for the given ClassLoader. * @param classLoader the ClassLoader to delegate to */ public StandardTypeLocator(@Nullable ClassLoader classLoader) { this.classLoader = classLoader; // Similar to when writing regular Java code, it only knows about java.lang by default registerImport("java.lang"); }
@Test public void testResolvingList() { StandardEvaluationContext context = TestScenarioCreator.getTestEvaluationContext(); try { assertFalse(parser.parseExpression("T(List)!=null").getValue(context, Boolean.class)); fail("should have failed to find List"); } catch (EvaluationException ee) { // success - List not found } ((StandardTypeLocator) context.getTypeLocator()).registerImport("java.util"); assertTrue(parser.parseExpression("T(List)!=null").getValue(context, Boolean.class)); }
@Test public void testStandardTypeLocator() { StandardTypeLocator tl = new StandardTypeLocator(); List<String> prefixes = tl.getImportPrefixes(); assertEquals(1, prefixes.size()); tl.registerImport("java.util"); prefixes = tl.getImportPrefixes(); assertEquals(2, prefixes.size()); tl.removeImport("java.util"); prefixes = tl.getImportPrefixes(); assertEquals(1, prefixes.size()); }
@Test public void testImports() throws EvaluationException { StandardTypeLocator locator = new StandardTypeLocator(); assertEquals(Integer.class,locator.findType("java.lang.Integer")); assertEquals(String.class,locator.findType("java.lang.String")); List<String> prefixes = locator.getImportPrefixes(); assertEquals(1,prefixes.size()); assertTrue(prefixes.contains("java.lang")); assertFalse(prefixes.contains("java.util")); assertEquals(Boolean.class,locator.findType("Boolean")); // currently does not know about java.util by default // assertEquals(java.util.List.class,locator.findType("List")); try { locator.findType("URL"); fail("Should have failed"); } catch (EvaluationException ee) { SpelEvaluationException sEx = (SpelEvaluationException)ee; assertEquals(SpelMessage.TYPE_NOT_FOUND,sEx.getMessageCode()); } locator.registerImport("java.net"); assertEquals(java.net.URL.class,locator.findType("URL")); }
@Override protected void doInit() { Assert.state(this.queryExpression != null || this.collectionCallback != null, "no query or collectionCallback is specified"); Assert.state(this.collectionNameExpression != null, "no collection name specified"); if (this.queryExpression != null && this.collectionCallback != null) { throw new IllegalStateException("query and collectionCallback are mutually exclusive"); } if (this.evaluationContext == null) { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { ((StandardTypeLocator) typeLocator).registerImport(Query.class.getPackage().getName()); } } if (this.mongoTemplate == null) { this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mongoConverter); } }
@Override protected void onInit() { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { //Register MongoDB query API package so FQCN can be avoided in query-expression. ((StandardTypeLocator) typeLocator).registerImport("org.springframework.data.mongodb.core.query"); } if (this.mongoTemplate == null) { this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mongoConverter); } this.initialized = true; }
/** * Create a StandardTypeLocator for the given ClassLoader. * @param classLoader the ClassLoader to delegate to */ public StandardTypeLocator(@Nullable ClassLoader classLoader) { this.classLoader = classLoader; // Similar to when writing regular Java code, it only knows about java.lang by default registerImport("java.lang"); }
@Override protected void doInit() { Assert.state(this.queryExpression != null || this.collectionCallback != null, "no query or collectionCallback is specified"); Assert.state(this.collectionNameExpression != null, "no collection name specified"); if (this.queryExpression != null && this.collectionCallback != null) { throw new IllegalStateException("query and collectionCallback are mutually exclusive"); } if (this.evaluationContext == null) { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(this.getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { ((StandardTypeLocator) typeLocator).registerImport(Query.class.getPackage().getName()); } } if (this.mongoTemplate == null) { this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mongoConverter); } }
@Override protected void onInit() throws Exception { super.onInit(); TypeLocator typeLocator = getEvaluationContext().getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { /* * Register the 'org.springframework.integration.aws.support' package * you don't need a FQCN for the 'SnsMessageBuilder'. */ ((StandardTypeLocator) typeLocator).registerImport("org.springframework.integration.aws.support"); } }
@Override protected void onInit() throws Exception { super.onInit(); TypeLocator typeLocator = getEvaluationContext().getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { /* * Register the 'org.springframework.integration.aws.support' package * you don't need a FQCN for the 'SnsMessageBuilder'. */ ((StandardTypeLocator) typeLocator).registerImport("org.springframework.integration.aws.support"); } }
@Override protected void doInit() { super.doInit(); this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { /* * Register the Cassandra Query DSL package so they don't need a FQCN for QueryBuilder, for example. */ ((StandardTypeLocator) typeLocator).registerImport("com.datastax.driver.core.querybuilder"); } }
@Override protected void doInit() { super.doInit(); this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { /* * Register the Cassandra Query DSL package so they don't need a FQCN for QueryBuilder, for example. */ ((StandardTypeLocator) typeLocator).registerImport("com.datastax.driver.core.querybuilder"); } }
@Override protected void onInit() throws Exception { super.onInit(); if (this.evaluationContext == null) { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { /* * Register the twitter api package so they don't need a FQCN for TweetData. */ ((StandardTypeLocator) typeLocator).registerImport("org.springframework.social.twitter.api"); } } }
@Override protected void doInit() { super.doInit(); if (this.evaluationContext == null) { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { /* * Register the twitter api package so they don't need a FQCN for SearchParameters. */ ((StandardTypeLocator) typeLocator).registerImport("org.springframework.social.twitter.api"); } } }
@Override protected void onInit() { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { //Register MongoDB query API package so FQCN can be avoided in query-expression. ((StandardTypeLocator) typeLocator).registerImport("org.springframework.data.mongodb.core.query"); } if (this.mongoTemplate == null) { this.mongoTemplate = new MongoTemplate(this.mongoDbFactory, this.mongoConverter); } this.initialized = true; }
@Override protected void onInit() throws Exception { super.onInit(); if (this.evaluationContext == null) { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { /* * Register the twitter api package so they don't need a FQCN for TweetData. */ ((StandardTypeLocator) typeLocator).registerImport("org.springframework.social.twitter.api"); } } }
@Override protected void doInit() { super.doInit(); if (this.evaluationContext == null) { this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory()); TypeLocator typeLocator = this.evaluationContext.getTypeLocator(); if (typeLocator instanceof StandardTypeLocator) { /* * Register the twitter api package so they don't need a FQCN for SearchParameters. */ ((StandardTypeLocator) typeLocator).registerImport("org.springframework.social.twitter.api"); } } }