From b3be38694572f58e8663fa70443e93e8f1bfab93 Mon Sep 17 00:00:00 2001 From: copierrj Date: Fri, 21 Jun 2013 16:40:36 +0200 Subject: [PATCH 01/21] module 'deegree-spring' added --- deegree-spring/pom.xml | 9 +++++++++ pom.xml | 1 + 2 files changed, 10 insertions(+) create mode 100644 deegree-spring/pom.xml diff --git a/deegree-spring/pom.xml b/deegree-spring/pom.xml new file mode 100644 index 0000000000..17639953a2 --- /dev/null +++ b/deegree-spring/pom.xml @@ -0,0 +1,9 @@ + + 4.0.0 + + org.deegree + deegree + 3.4-pre3-SNAPSHOT + + deegree-spring + \ No newline at end of file diff --git a/pom.xml b/pom.xml index f079663a4d..ff920514dc 100644 --- a/pom.xml +++ b/pom.xml @@ -1013,6 +1013,7 @@ deegree-themes deegree-tools deegree-workspaces + deegree-spring From 1b3dcc512677cdb47f131a5be65f32f49c6fe123 Mon Sep 17 00:00:00 2001 From: copierrj Date: Fri, 21 Jun 2013 17:45:47 +0200 Subject: [PATCH 02/21] ApplicationContextHolderManager added --- deegree-spring/pom.xml | 27 ++++++++++++++ .../spring/ApplicationContextHolder.java | 36 +++++++++++++++++++ .../ApplicationContextHolderManager.java | 12 +++++++ .../ApplicationContextHolderProvider.java | 7 ++++ .../org.deegree.workspace.ResourceManager | 1 + 5 files changed, 83 insertions(+) create mode 100644 deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java create mode 100644 deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java create mode 100644 deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java create mode 100644 deegree-spring/src/main/resources/META-INF/services/org.deegree.workspace.ResourceManager diff --git a/deegree-spring/pom.xml b/deegree-spring/pom.xml index 17639953a2..cf70e052e2 100644 --- a/deegree-spring/pom.xml +++ b/deegree-spring/pom.xml @@ -6,4 +6,31 @@ 3.4-pre3-SNAPSHOT deegree-spring + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + + + + org.springframework + spring-context + 3.2.3.RELEASE + + + org.deegree + deegree-core-workspace + ${project.version} + + + org.deegree + deegree-core-commons + ${project.version} + + \ No newline at end of file diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java new file mode 100644 index 0000000000..d7d3a39a73 --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java @@ -0,0 +1,36 @@ +package org.deegree.spring; + +import org.deegree.workspace.Resource; +import org.deegree.workspace.ResourceMetadata; + +import org.springframework.context.ApplicationContext; + +public class ApplicationContextHolder implements Resource { + + private final ResourceMetadata metadata; + private final ApplicationContext applicationContext; + + public ApplicationContextHolder( final ResourceMetadata metadata, final ApplicationContext applicationContext ) { + this.metadata = metadata; + this.applicationContext = applicationContext; + } + + @Override + public ResourceMetadata getMetadata() { + return metadata; + } + + @Override + public void init() { + + } + + @Override + public void destroy() { + + } + + public ApplicationContext getApplicationContext() { + return applicationContext; + } +} diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java new file mode 100644 index 0000000000..f60cad148c --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java @@ -0,0 +1,12 @@ +package org.deegree.spring; + +import org.deegree.workspace.standard.DefaultResourceManager; +import org.deegree.workspace.standard.DefaultResourceManagerMetadata; + +public class ApplicationContextHolderManager extends DefaultResourceManager { + + public ApplicationContextHolderManager() { + super( new DefaultResourceManagerMetadata( ApplicationContextHolderProvider.class, + "spring application context holders", "spring") ); + } +} diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java new file mode 100644 index 0000000000..3d4f61925c --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java @@ -0,0 +1,7 @@ +package org.deegree.spring; + +import org.deegree.workspace.standard.AbstractResourceProvider; + +public abstract class ApplicationContextHolderProvider extends AbstractResourceProvider { + +} diff --git a/deegree-spring/src/main/resources/META-INF/services/org.deegree.workspace.ResourceManager b/deegree-spring/src/main/resources/META-INF/services/org.deegree.workspace.ResourceManager new file mode 100644 index 0000000000..c2fdff9591 --- /dev/null +++ b/deegree-spring/src/main/resources/META-INF/services/org.deegree.workspace.ResourceManager @@ -0,0 +1 @@ +org.deegree.spring.ApplicationContextHolderManager \ No newline at end of file From 33b2474ce15c8a2ddb7ff190a0b1d0953814e9c0 Mon Sep 17 00:00:00 2001 From: copierrj Date: Mon, 24 Jun 2013 11:20:29 +0200 Subject: [PATCH 03/21] BootstrapApplicationContextHolderProvider implemented --- ...tstrapApplicationContextHolderBuilder.java | 45 ++++++++++++++++++ ...strapApplicationContextHolderMetadata.java | 46 +++++++++++++++++++ ...strapApplicationContextHolderProvider.java | 33 +++++++++++++ .../schemas/spring/3.4.0/bootstrap.xsd | 26 +++++++++++ ...ee.spring.ApplicationContextHolderProvider | 1 + 5 files changed, 151 insertions(+) create mode 100644 deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java create mode 100644 deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java create mode 100644 deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java create mode 100644 deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/bootstrap.xsd create mode 100644 deegree-spring/src/main/resources/META-INF/services/org.deegree.spring.ApplicationContextHolderProvider diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java new file mode 100644 index 0000000000..00af2ebc75 --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java @@ -0,0 +1,45 @@ +package org.deegree.spring.bootstrap; + +import org.deegree.spring.ApplicationContextHolder; +import org.deegree.spring.bootstrap.jaxb.BootstrapApplicationContextHolderConfig; +import org.deegree.workspace.ResourceBuilder; +import org.deegree.workspace.ResourceInitException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.support.GenericXmlApplicationContext; + +public class BootstrapApplicationContextHolderBuilder implements ResourceBuilder { + + private final BootstrapApplicationContextHolderMetadata metadata; + private final BootstrapApplicationContextHolderConfig config; + + public BootstrapApplicationContextHolderBuilder( BootstrapApplicationContextHolderMetadata metadata, + BootstrapApplicationContextHolderConfig config ) { + + this.metadata = metadata; + this.config = config; + } + + @Override + public ApplicationContextHolder build() { + try { + final ApplicationContext context; + final String contextClass = config.getContextClass(); + if ( contextClass != null) { + context = new AnnotationConfigApplicationContext ( Class.forName( contextClass ) ); + } else { + final String contextConfigLocation = config.getContextConfigLocation(); + if ( contextConfigLocation == null) { + throw new ResourceInitException ( "Both ContextClass and ContextConfigLocation are missing from BootstrapApplicationContextHolderConfig" ); + } + + context = new GenericXmlApplicationContext ( contextConfigLocation ); + } + + return new ApplicationContextHolder ( metadata, context ); + } catch ( Exception e ) { + throw new ResourceInitException ( "Couldn't build BootstrapApplicationContextHolder", e ); + } + } + +} diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java new file mode 100644 index 0000000000..75ba5e8a2c --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java @@ -0,0 +1,46 @@ +package org.deegree.spring.bootstrap; + +import static org.deegree.spring.bootstrap.BootstrapApplicationContextHolderProvider.CONFIG_SCHEMA; + +import org.deegree.commons.xml.jaxb.JAXBUtils; +import org.deegree.spring.ApplicationContextHolder; +import org.deegree.spring.bootstrap.jaxb.BootstrapApplicationContextHolderConfig; +import org.deegree.workspace.ResourceBuilder; +import org.deegree.workspace.ResourceInitException; +import org.deegree.workspace.ResourceLocation; +import org.deegree.workspace.Workspace; +import org.deegree.workspace.standard.AbstractResourceMetadata; +import org.deegree.workspace.standard.AbstractResourceProvider; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class BootstrapApplicationContextHolderMetadata extends AbstractResourceMetadata { + + private static final Logger LOG = LoggerFactory.getLogger( BootstrapApplicationContextHolderMetadata.class ); + + private static final String CONFIG_JAXB_PACKAGE = "org.deegree.spring.bootstrap.jaxb"; + + public BootstrapApplicationContextHolderMetadata( Workspace workspace, + ResourceLocation location, + AbstractResourceProvider provider ) { + super( workspace, location, provider ); + } + + @Override + public ResourceBuilder prepare() { + BootstrapApplicationContextHolderConfig config; + + try { + config = (BootstrapApplicationContextHolderConfig) JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, CONFIG_SCHEMA, + location.getAsStream(), workspace ); + } catch ( Exception e ) { + LOG.trace( "Stack trace:", e ); + throw new ResourceInitException( e.getLocalizedMessage(), e ); + } + + return new BootstrapApplicationContextHolderBuilder( this, config ); + } +} + + diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java new file mode 100644 index 0000000000..676b7d315f --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java @@ -0,0 +1,33 @@ +package org.deegree.spring.bootstrap; + +import java.net.URL; + +import org.deegree.spring.ApplicationContextHolder; +import org.deegree.spring.ApplicationContextHolderProvider; + +import org.deegree.workspace.ResourceLocation; +import org.deegree.workspace.ResourceMetadata; +import org.deegree.workspace.Workspace; + +public class BootstrapApplicationContextHolderProvider extends ApplicationContextHolderProvider { + + private static final String CONFIG_NS = "http://www.deegree.org/spring/bootstrap"; + static final URL CONFIG_SCHEMA = BootstrapApplicationContextHolderProvider.class.getResource( "/META-INF/schemas/spring/3.4.0/bootstrap.xsd" ); + + @Override + public String getNamespace() { + return CONFIG_NS; + } + + @Override + public ResourceMetadata createFromLocation( Workspace workspace, + ResourceLocation location ) { + return new BootstrapApplicationContextHolderMetadata ( workspace, location, this ); + } + + @Override + public URL getSchema() { + return CONFIG_SCHEMA; + } + +} diff --git a/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/bootstrap.xsd b/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/bootstrap.xsd new file mode 100644 index 0000000000..8152c98329 --- /dev/null +++ b/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/bootstrap.xsd @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/deegree-spring/src/main/resources/META-INF/services/org.deegree.spring.ApplicationContextHolderProvider b/deegree-spring/src/main/resources/META-INF/services/org.deegree.spring.ApplicationContextHolderProvider new file mode 100644 index 0000000000..8ba0c909df --- /dev/null +++ b/deegree-spring/src/main/resources/META-INF/services/org.deegree.spring.ApplicationContextHolderProvider @@ -0,0 +1 @@ +org.deegree.spring.bootstrap.BootstrapApplicationContextHolderProvider \ No newline at end of file From dcd784873c20e7ae5f183a957d5cfe546b16828e Mon Sep 17 00:00:00 2001 From: copierrj Date: Mon, 24 Jun 2013 17:28:27 +0200 Subject: [PATCH 04/21] SpringConnectionProvider implemented --- deegree-spring/pom.xml | 21 +++++- .../spring/db/SpringConnectionProvider.java | 53 ++++++++++++++ .../db/SpringConnectionProviderBuilder.java | 73 +++++++++++++++++++ .../db/SpringConnectionProviderMetadata.java | 48 ++++++++++++ .../db/SpringConnectionProviderProvider.java | 30 ++++++++ .../META-INF/schemas/spring/3.4.0/db.xsd | 27 +++++++ .../org.deegree.db.ConnectionProviderProvider | 1 + 7 files changed, 252 insertions(+), 1 deletion(-) create mode 100644 deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java create mode 100644 deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java create mode 100644 deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java create mode 100644 deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java create mode 100644 deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/db.xsd create mode 100644 deegree-spring/src/main/resources/META-INF/services/org.deegree.db.ConnectionProviderProvider diff --git a/deegree-spring/pom.xml b/deegree-spring/pom.xml index cf70e052e2..57c571860a 100644 --- a/deegree-spring/pom.xml +++ b/deegree-spring/pom.xml @@ -16,11 +16,20 @@ + + 3.2.3.RELEASE + + org.springframework spring-context - 3.2.3.RELEASE + ${spring.version} + + + org.springframework + spring-jdbc + ${spring.version} org.deegree @@ -32,5 +41,15 @@ deegree-core-commons ${project.version} + + org.deegree + deegree-core-db + ${project.version} + + + org.deegree + deegree-sqldialect-postgis + ${project.version} + \ No newline at end of file diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java new file mode 100644 index 0000000000..25d450946c --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java @@ -0,0 +1,53 @@ +package org.deegree.spring.db; + +import java.sql.Connection; + +import javax.sql.DataSource; + +import org.deegree.db.ConnectionProvider; +import org.deegree.sqldialect.SQLDialect; + +import org.springframework.jdbc.datasource.DataSourceUtils; + +public class SpringConnectionProvider implements ConnectionProvider { + + private final SpringConnectionProviderMetadata metadata; + private final DataSource dataSource; + private final SQLDialect dialect; + + public SpringConnectionProvider( final SpringConnectionProviderMetadata metadata, final DataSource dataSource, final SQLDialect dialect ) { + this.metadata = metadata; + this.dataSource = dataSource; + this.dialect = dialect; + } + + @Override + public SpringConnectionProviderMetadata getMetadata() { + return metadata; + } + + @Override + public void init() { + + } + + @Override + public void destroy() { + + } + + @Override + public Connection getConnection() { + return DataSourceUtils.getConnection( dataSource ); + } + + @Override + public SQLDialect getDialect() { + return dialect; + } + + @Override + public void invalidate( Connection conn ) { + DataSourceUtils.releaseConnection( conn, dataSource ); + } +} diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java new file mode 100644 index 0000000000..6b982f22d0 --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java @@ -0,0 +1,73 @@ +package org.deegree.spring.db; + +import java.util.Map; + +import javax.sql.DataSource; + +import org.deegree.db.ConnectionProvider; +import org.deegree.spring.ApplicationContextHolder; +import org.deegree.spring.ApplicationContextHolderProvider; +import org.deegree.spring.db.jaxb.SpringConnectionProviderConfig; +import org.deegree.sqldialect.postgis.PostGISDialect; +import org.deegree.workspace.ResourceBuilder; +import org.deegree.workspace.ResourceInitException; +import org.deegree.workspace.Workspace; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.context.ApplicationContext; + +public class SpringConnectionProviderBuilder implements ResourceBuilder{ + + private static final Logger LOG = LoggerFactory.getLogger( SpringConnectionProviderBuilder.class ); + + private final SpringConnectionProviderMetadata metadata; + private final Workspace workspace; + private final SpringConnectionProviderConfig config; + + public SpringConnectionProviderBuilder ( final SpringConnectionProviderMetadata metadata, final Workspace workspace, final SpringConnectionProviderConfig config ) { + this.metadata = metadata; + this.workspace = workspace; + this.config = config; + } + + @Override + public ConnectionProvider build() { + final String applicationContextHolderId = config.getApplicationContextHolder(); + final String dataSourceName = config.getDataSourceName(); + + LOG.debug( "Building SpringConnectionProvider (applicationContextHolder: {}, dataSourceName: {})", applicationContextHolderId, dataSourceName ); + + final ApplicationContextHolder applicationContextHolder = workspace.getResource( ApplicationContextHolderProvider.class, applicationContextHolderId ); + final ApplicationContext applicationContext = applicationContextHolder.getApplicationContext(); + + final DataSource dataSource; + if( dataSourceName != null) { + try { + dataSource = applicationContext.getBean( dataSourceName, DataSource.class ); + + LOG.info( "Bean with name '{}' fetched from ApplicationContext", dataSourceName ); + } catch(Exception e) { + throw new ResourceInitException( "Couldn't fetch bean with type DataSource and name '" + dataSourceName + "' from ApplicationContext", e ); + } + } else { + final Map dataSources = applicationContext.getBeansOfType(DataSource.class); + if( dataSources.size() == 1 ) { + dataSource = dataSources.values().iterator().next(); + + LOG.info( "Single DataSource bean fetched from ApplicationContext" ); + } else { + if( dataSources.containsKey( "dataSource" ) ) { + dataSource = dataSources.get( "dataSource" ); + + LOG.info( "Multiple DataSource beans found in ApplicationContext, bean named 'dataSource' selected." ); + } else { + throw new ResourceInitException( "Multiple beans with type DataSource are found in ApplicationContext, non of them are named 'dataSource'. Suggestion: add bean name to configuration" ); + } + } + } + + return new SpringConnectionProvider( metadata, dataSource, new PostGISDialect( false ) ); + } +} diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java new file mode 100644 index 0000000000..a44d1c8cb0 --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java @@ -0,0 +1,48 @@ +package org.deegree.spring.db; + +import static org.deegree.spring.db.SpringConnectionProviderProvider.CONFIG_SCHEMA; + +import org.deegree.commons.xml.jaxb.JAXBUtils; +import org.deegree.db.ConnectionProvider; +import org.deegree.workspace.ResourceInitException; +import org.deegree.workspace.ResourceLocation; +import org.deegree.workspace.Workspace; +import org.deegree.workspace.standard.AbstractResourceMetadata; +import org.deegree.workspace.standard.AbstractResourceProvider; +import org.deegree.workspace.standard.DefaultResourceIdentifier; + +import org.deegree.spring.ApplicationContextHolder; +import org.deegree.spring.ApplicationContextHolderProvider; +import org.deegree.spring.db.jaxb.SpringConnectionProviderConfig; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SpringConnectionProviderMetadata extends AbstractResourceMetadata { + + private static final Logger LOG = LoggerFactory.getLogger( SpringConnectionProviderMetadata.class ); + + private static final String CONFIG_JAXB_PACKAGE = "org.deegree.spring.db.jaxb"; + + public SpringConnectionProviderMetadata( Workspace workspace, ResourceLocation location, + AbstractResourceProvider provider ) { + super( workspace, location, provider ); + } + + @Override + public SpringConnectionProviderBuilder prepare() { + + final SpringConnectionProviderConfig config; + try { + config = (SpringConnectionProviderConfig)JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, CONFIG_SCHEMA, + location.getAsStream(), workspace ); + + final String applicationContextHolder = config.getApplicationContextHolder(); + dependencies.add( new DefaultResourceIdentifier( ApplicationContextHolderProvider.class, applicationContextHolder ) ); + } catch ( Exception e ) { + LOG.trace( "Stack trace:", e ); + throw new ResourceInitException( e.getLocalizedMessage(), e ); + } + + return new SpringConnectionProviderBuilder( this, workspace, config ); + } +} diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java new file mode 100644 index 0000000000..12ae66bf34 --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java @@ -0,0 +1,30 @@ +package org.deegree.spring.db; + +import java.net.URL; + +import org.deegree.db.ConnectionProvider; +import org.deegree.db.ConnectionProviderProvider; +import org.deegree.workspace.ResourceLocation; +import org.deegree.workspace.Workspace; + +public class SpringConnectionProviderProvider extends ConnectionProviderProvider { + + private static final String CONFIG_NS = "http://www.deegree.org/spring/db"; + static final URL CONFIG_SCHEMA = SpringConnectionProviderProvider.class.getResource( "/META-INF/schemas/spring/3.4.0/db.xsd" ); + + @Override + public String getNamespace() { + return CONFIG_NS; + } + + @Override + public SpringConnectionProviderMetadata createFromLocation( Workspace workspace, + ResourceLocation location ) { + return new SpringConnectionProviderMetadata( workspace, location, this ); + } + + @Override + public URL getSchema() { + return CONFIG_SCHEMA; + } +} diff --git a/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/db.xsd b/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/db.xsd new file mode 100644 index 0000000000..73f3c0ae61 --- /dev/null +++ b/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/db.xsd @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/deegree-spring/src/main/resources/META-INF/services/org.deegree.db.ConnectionProviderProvider b/deegree-spring/src/main/resources/META-INF/services/org.deegree.db.ConnectionProviderProvider new file mode 100644 index 0000000000..749646606f --- /dev/null +++ b/deegree-spring/src/main/resources/META-INF/services/org.deegree.db.ConnectionProviderProvider @@ -0,0 +1 @@ +org.deegree.spring.db.SpringConnectionProviderProvider \ No newline at end of file From 5b53a6ccf08729294057ef568a7dac54083fe18f Mon Sep 17 00:00:00 2001 From: copierrj Date: Tue, 25 Jun 2013 09:29:55 +0200 Subject: [PATCH 05/21] formatting --- .../spring/ApplicationContextHolder.java | 14 +++--- .../ApplicationContextHolderManager.java | 5 +- ...tstrapApplicationContextHolderBuilder.java | 26 +++++----- ...strapApplicationContextHolderMetadata.java | 17 +++---- ...strapApplicationContextHolderProvider.java | 7 +-- .../spring/db/SpringConnectionProvider.java | 13 +++-- .../db/SpringConnectionProviderBuilder.java | 49 +++++++++++-------- .../db/SpringConnectionProviderMetadata.java | 22 +++++---- .../db/SpringConnectionProviderProvider.java | 5 +- 9 files changed, 88 insertions(+), 70 deletions(-) diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java index d7d3a39a73..84ec6bc0fe 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java @@ -6,11 +6,13 @@ import org.springframework.context.ApplicationContext; public class ApplicationContextHolder implements Resource { - + private final ResourceMetadata metadata; + private final ApplicationContext applicationContext; - - public ApplicationContextHolder( final ResourceMetadata metadata, final ApplicationContext applicationContext ) { + + public ApplicationContextHolder( final ResourceMetadata metadata, + final ApplicationContext applicationContext ) { this.metadata = metadata; this.applicationContext = applicationContext; } @@ -22,14 +24,14 @@ public ResourceMetadata getMetadata() { @Override public void init() { - + } @Override public void destroy() { - + } - + public ApplicationContext getApplicationContext() { return applicationContext; } diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java index f60cad148c..190298412f 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java @@ -6,7 +6,8 @@ public class ApplicationContextHolderManager extends DefaultResourceManager { public ApplicationContextHolderManager() { - super( new DefaultResourceManagerMetadata( ApplicationContextHolderProvider.class, - "spring application context holders", "spring") ); + super( new DefaultResourceManagerMetadata( ApplicationContextHolderProvider.class, + "spring application context holders", + "spring" ) ); } } diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java index 00af2ebc75..2d2c3fe146 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java @@ -11,13 +11,14 @@ public class BootstrapApplicationContextHolderBuilder implements ResourceBuilder { private final BootstrapApplicationContextHolderMetadata metadata; - private final BootstrapApplicationContextHolderConfig config; + + private final BootstrapApplicationContextHolderConfig config; public BootstrapApplicationContextHolderBuilder( BootstrapApplicationContextHolderMetadata metadata, BootstrapApplicationContextHolderConfig config ) { - + this.metadata = metadata; - this.config = config; + this.config = config; } @Override @@ -25,20 +26,21 @@ public ApplicationContextHolder build() { try { final ApplicationContext context; final String contextClass = config.getContextClass(); - if ( contextClass != null) { - context = new AnnotationConfigApplicationContext ( Class.forName( contextClass ) ); + if ( contextClass != null ) { + context = new AnnotationConfigApplicationContext( Class.forName( contextClass ) ); } else { final String contextConfigLocation = config.getContextConfigLocation(); - if ( contextConfigLocation == null) { - throw new ResourceInitException ( "Both ContextClass and ContextConfigLocation are missing from BootstrapApplicationContextHolderConfig" ); + if ( contextConfigLocation == null ) { + throw new ResourceInitException( + "Both ContextClass and ContextConfigLocation are missing from BootstrapApplicationContextHolderConfig" ); } - - context = new GenericXmlApplicationContext ( contextConfigLocation ); + + context = new GenericXmlApplicationContext( contextConfigLocation ); } - - return new ApplicationContextHolder ( metadata, context ); + + return new ApplicationContextHolder( metadata, context ); } catch ( Exception e ) { - throw new ResourceInitException ( "Couldn't build BootstrapApplicationContextHolder", e ); + throw new ResourceInitException( "Couldn't build BootstrapApplicationContextHolder", e ); } } diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java index 75ba5e8a2c..7e8902a665 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java @@ -16,11 +16,11 @@ import org.slf4j.LoggerFactory; public class BootstrapApplicationContextHolderMetadata extends AbstractResourceMetadata { - + private static final Logger LOG = LoggerFactory.getLogger( BootstrapApplicationContextHolderMetadata.class ); - + private static final String CONFIG_JAXB_PACKAGE = "org.deegree.spring.bootstrap.jaxb"; - + public BootstrapApplicationContextHolderMetadata( Workspace workspace, ResourceLocation location, AbstractResourceProvider provider ) { @@ -30,17 +30,16 @@ public BootstrapApplicationContextHolderMetadata( Workspace workspace, @Override public ResourceBuilder prepare() { BootstrapApplicationContextHolderConfig config; - + try { - config = (BootstrapApplicationContextHolderConfig) JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, CONFIG_SCHEMA, - location.getAsStream(), workspace ); + config = (BootstrapApplicationContextHolderConfig) JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, + CONFIG_SCHEMA, + location.getAsStream(), workspace ); } catch ( Exception e ) { LOG.trace( "Stack trace:", e ); throw new ResourceInitException( e.getLocalizedMessage(), e ); } - + return new BootstrapApplicationContextHolderBuilder( this, config ); } } - - diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java index 676b7d315f..bb5aba761e 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java @@ -10,8 +10,9 @@ import org.deegree.workspace.Workspace; public class BootstrapApplicationContextHolderProvider extends ApplicationContextHolderProvider { - - private static final String CONFIG_NS = "http://www.deegree.org/spring/bootstrap"; + + private static final String CONFIG_NS = "http://www.deegree.org/spring/bootstrap"; + static final URL CONFIG_SCHEMA = BootstrapApplicationContextHolderProvider.class.getResource( "/META-INF/schemas/spring/3.4.0/bootstrap.xsd" ); @Override @@ -22,7 +23,7 @@ public String getNamespace() { @Override public ResourceMetadata createFromLocation( Workspace workspace, ResourceLocation location ) { - return new BootstrapApplicationContextHolderMetadata ( workspace, location, this ); + return new BootstrapApplicationContextHolderMetadata( workspace, location, this ); } @Override diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java index 25d450946c..bc276c723f 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java @@ -10,12 +10,15 @@ import org.springframework.jdbc.datasource.DataSourceUtils; public class SpringConnectionProvider implements ConnectionProvider { - + private final SpringConnectionProviderMetadata metadata; + private final DataSource dataSource; + private final SQLDialect dialect; - - public SpringConnectionProvider( final SpringConnectionProviderMetadata metadata, final DataSource dataSource, final SQLDialect dialect ) { + + public SpringConnectionProvider( final SpringConnectionProviderMetadata metadata, final DataSource dataSource, + final SQLDialect dialect ) { this.metadata = metadata; this.dataSource = dataSource; this.dialect = dialect; @@ -27,7 +30,7 @@ public SpringConnectionProviderMetadata getMetadata() { } @Override - public void init() { + public void init() { } @@ -42,7 +45,7 @@ public Connection getConnection() { } @Override - public SQLDialect getDialect() { + public SQLDialect getDialect() { return dialect; } diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java index 6b982f22d0..708f8d41ea 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java @@ -18,15 +18,18 @@ import org.springframework.context.ApplicationContext; -public class SpringConnectionProviderBuilder implements ResourceBuilder{ - +public class SpringConnectionProviderBuilder implements ResourceBuilder { + private static final Logger LOG = LoggerFactory.getLogger( SpringConnectionProviderBuilder.class ); - + private final SpringConnectionProviderMetadata metadata; + private final Workspace workspace; + private final SpringConnectionProviderConfig config; - - public SpringConnectionProviderBuilder ( final SpringConnectionProviderMetadata metadata, final Workspace workspace, final SpringConnectionProviderConfig config ) { + + public SpringConnectionProviderBuilder( final SpringConnectionProviderMetadata metadata, final Workspace workspace, + final SpringConnectionProviderConfig config ) { this.metadata = metadata; this.workspace = workspace; this.config = config; @@ -36,34 +39,38 @@ public SpringConnectionProviderBuilder ( final SpringConnectionProviderMetadata public ConnectionProvider build() { final String applicationContextHolderId = config.getApplicationContextHolder(); final String dataSourceName = config.getDataSourceName(); - - LOG.debug( "Building SpringConnectionProvider (applicationContextHolder: {}, dataSourceName: {})", applicationContextHolderId, dataSourceName ); - - final ApplicationContextHolder applicationContextHolder = workspace.getResource( ApplicationContextHolderProvider.class, applicationContextHolderId ); + + LOG.debug( "Building SpringConnectionProvider (applicationContextHolder: {}, dataSourceName: {})", + applicationContextHolderId, dataSourceName ); + + final ApplicationContextHolder applicationContextHolder = workspace.getResource( ApplicationContextHolderProvider.class, + applicationContextHolderId ); final ApplicationContext applicationContext = applicationContextHolder.getApplicationContext(); - + final DataSource dataSource; - if( dataSourceName != null) { + if ( dataSourceName != null ) { try { dataSource = applicationContext.getBean( dataSourceName, DataSource.class ); - + LOG.info( "Bean with name '{}' fetched from ApplicationContext", dataSourceName ); - } catch(Exception e) { - throw new ResourceInitException( "Couldn't fetch bean with type DataSource and name '" + dataSourceName + "' from ApplicationContext", e ); + } catch ( Exception e ) { + throw new ResourceInitException( "Couldn't fetch bean with type DataSource and name '" + dataSourceName + + "' from ApplicationContext", e ); } } else { - final Map dataSources = applicationContext.getBeansOfType(DataSource.class); - if( dataSources.size() == 1 ) { + final Map dataSources = applicationContext.getBeansOfType( DataSource.class ); + if ( dataSources.size() == 1 ) { dataSource = dataSources.values().iterator().next(); - + LOG.info( "Single DataSource bean fetched from ApplicationContext" ); } else { - if( dataSources.containsKey( "dataSource" ) ) { + if ( dataSources.containsKey( "dataSource" ) ) { dataSource = dataSources.get( "dataSource" ); - - LOG.info( "Multiple DataSource beans found in ApplicationContext, bean named 'dataSource' selected." ); + + LOG.info( "Multiple DataSource beans found in ApplicationContext, bean named 'dataSource' selected." ); } else { - throw new ResourceInitException( "Multiple beans with type DataSource are found in ApplicationContext, non of them are named 'dataSource'. Suggestion: add bean name to configuration" ); + throw new ResourceInitException( + "Multiple beans with type DataSource are found in ApplicationContext, non of them are named 'dataSource'. Suggestion: add bean name to configuration" ); } } } diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java index a44d1c8cb0..daaaeea0ab 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java @@ -17,10 +17,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SpringConnectionProviderMetadata extends AbstractResourceMetadata { - +public class SpringConnectionProviderMetadata extends AbstractResourceMetadata { + private static final Logger LOG = LoggerFactory.getLogger( SpringConnectionProviderMetadata.class ); - + private static final String CONFIG_JAXB_PACKAGE = "org.deegree.spring.db.jaxb"; public SpringConnectionProviderMetadata( Workspace workspace, ResourceLocation location, @@ -30,19 +30,21 @@ public SpringConnectionProviderMetadata( Workspace workspace, ResourceLocation( ApplicationContextHolderProvider.class, applicationContextHolder ) ); + config = (SpringConnectionProviderConfig) JAXBUtils.unmarshall( CONFIG_JAXB_PACKAGE, CONFIG_SCHEMA, + location.getAsStream(), workspace ); + + final String applicationContextHolder = config.getApplicationContextHolder(); + dependencies.add( new DefaultResourceIdentifier( + ApplicationContextHolderProvider.class, + applicationContextHolder ) ); } catch ( Exception e ) { LOG.trace( "Stack trace:", e ); throw new ResourceInitException( e.getLocalizedMessage(), e ); } - + return new SpringConnectionProviderBuilder( this, workspace, config ); } } diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java index 12ae66bf34..0a9de34dc1 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java @@ -8,8 +8,9 @@ import org.deegree.workspace.Workspace; public class SpringConnectionProviderProvider extends ConnectionProviderProvider { - + private static final String CONFIG_NS = "http://www.deegree.org/spring/db"; + static final URL CONFIG_SCHEMA = SpringConnectionProviderProvider.class.getResource( "/META-INF/schemas/spring/3.4.0/db.xsd" ); @Override @@ -19,7 +20,7 @@ public String getNamespace() { @Override public SpringConnectionProviderMetadata createFromLocation( Workspace workspace, - ResourceLocation location ) { + ResourceLocation location ) { return new SpringConnectionProviderMetadata( workspace, location, this ); } From 9e4ad0a800b0acc6dfc1f62cc7d71c8f9619a405 Mon Sep 17 00:00:00 2001 From: copierrj Date: Tue, 25 Jun 2013 09:44:32 +0200 Subject: [PATCH 06/21] Resource.destroy implemented for ApplicationContextHolder --- .../java/org/deegree/spring/ApplicationContextHolder.java | 7 ++++--- .../BootstrapApplicationContextHolderBuilder.java | 4 ++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java index 84ec6bc0fe..26ee8a0742 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java @@ -4,15 +4,16 @@ import org.deegree.workspace.ResourceMetadata; import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; public class ApplicationContextHolder implements Resource { private final ResourceMetadata metadata; - private final ApplicationContext applicationContext; + private final ConfigurableApplicationContext applicationContext; public ApplicationContextHolder( final ResourceMetadata metadata, - final ApplicationContext applicationContext ) { + final ConfigurableApplicationContext applicationContext ) { this.metadata = metadata; this.applicationContext = applicationContext; } @@ -29,7 +30,7 @@ public void init() { @Override public void destroy() { - + applicationContext.close(); } public ApplicationContext getApplicationContext() { diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java index 2d2c3fe146..45177b5f9e 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java @@ -4,7 +4,7 @@ import org.deegree.spring.bootstrap.jaxb.BootstrapApplicationContextHolderConfig; import org.deegree.workspace.ResourceBuilder; import org.deegree.workspace.ResourceInitException; -import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; @@ -24,7 +24,7 @@ public BootstrapApplicationContextHolderBuilder( BootstrapApplicationContextHold @Override public ApplicationContextHolder build() { try { - final ApplicationContext context; + final ConfigurableApplicationContext context; final String contextClass = config.getContextClass(); if ( contextClass != null ) { context = new AnnotationConfigApplicationContext( Class.forName( contextClass ) ); From de698c0699c70d3ce6cd3c02b920fa4c7ba992cd Mon Sep 17 00:00:00 2001 From: copierrj Date: Tue, 25 Jun 2013 11:13:56 +0200 Subject: [PATCH 07/21] AbstractSpringResourceBuilder implemented --- .../spring/AbstractSpringResourceBuilder.java | 73 +++++++++++++++++++ .../db/SpringConnectionProviderBuilder.java | 61 +++------------- .../db/SpringConnectionProviderMetadata.java | 2 +- 3 files changed, 83 insertions(+), 53 deletions(-) create mode 100644 deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java diff --git a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java new file mode 100644 index 0000000000..d8e55305cd --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java @@ -0,0 +1,73 @@ +package org.deegree.spring; + +import java.util.Map; + +import org.deegree.workspace.Resource; +import org.deegree.workspace.ResourceBuilder; +import org.deegree.workspace.ResourceInitException; +import org.deegree.workspace.Workspace; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.springframework.context.ApplicationContext; + +public abstract class AbstractSpringResourceBuilder implements ResourceBuilder { + + private static final Logger LOG = LoggerFactory.getLogger( AbstractSpringResourceBuilder.class ); + + private final Workspace workspace; + + private final String applicationContextHolderId; + + public AbstractSpringResourceBuilder( final Workspace workspace, final String applicationContextHolderId ) { + this.workspace = workspace; + this.applicationContextHolderId = applicationContextHolderId; + } + + protected B getBean( final Class clazz, final String beanName, final String conventionalBeanName ) { + final String className = clazz.getCanonicalName(); + + final ApplicationContextHolder applicationContextHolder = workspace.getResource( ApplicationContextHolderProvider.class, + applicationContextHolderId ); + final ApplicationContext applicationContext = applicationContextHolder.getApplicationContext(); + + final B bean; + if ( beanName != null ) { + try { + bean = applicationContext.getBean( beanName, clazz ); + + LOG.info( "Bean with name '{}' fetched from ApplicationContext.", beanName ); + } catch ( Exception e ) { + throw new ResourceInitException( "Couldn't fetch bean with type '" + className + "' and name '" + + beanName + "' from ApplicationContext.", e ); + } + } else { + final Map beans = applicationContext.getBeansOfType( clazz ); + if ( beans.size() == 1 ) { + bean = beans.values().iterator().next(); + + LOG.info( "Single {} bean fetched from ApplicationContext.", className ); + } else { + if ( conventionalBeanName != null ) { + if ( beans.containsKey( conventionalBeanName ) ) { + bean = beans.get( conventionalBeanName ); + + LOG.info( "Multiple {} beans found in ApplicationContext, bean named '{}' selected.", + className, conventionalBeanName ); + } else { + throw new ResourceInitException( "Multiple beans with type " + className + + " are found in ApplicationContext, none of them are named '" + + conventionalBeanName + + "'. Suggestion: add bean name to configuration." ); + } + } else { + throw new ResourceInitException( "Multiple beans with type " + className + + " are found in ApplicationContext." ); + } + } + } + + return bean; + } +} diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java index 708f8d41ea..90207b9a05 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java @@ -1,80 +1,37 @@ package org.deegree.spring.db; -import java.util.Map; - import javax.sql.DataSource; import org.deegree.db.ConnectionProvider; -import org.deegree.spring.ApplicationContextHolder; -import org.deegree.spring.ApplicationContextHolderProvider; +import org.deegree.spring.AbstractSpringResourceBuilder; import org.deegree.spring.db.jaxb.SpringConnectionProviderConfig; import org.deegree.sqldialect.postgis.PostGISDialect; -import org.deegree.workspace.ResourceBuilder; -import org.deegree.workspace.ResourceInitException; import org.deegree.workspace.Workspace; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.context.ApplicationContext; - -public class SpringConnectionProviderBuilder implements ResourceBuilder { +public class SpringConnectionProviderBuilder extends AbstractSpringResourceBuilder { private static final Logger LOG = LoggerFactory.getLogger( SpringConnectionProviderBuilder.class ); - private final SpringConnectionProviderMetadata metadata; - - private final Workspace workspace; - private final SpringConnectionProviderConfig config; - public SpringConnectionProviderBuilder( final SpringConnectionProviderMetadata metadata, final Workspace workspace, + private final SpringConnectionProviderMetadata metadata; + + public SpringConnectionProviderBuilder( final Workspace workspace, final SpringConnectionProviderMetadata metadata, final SpringConnectionProviderConfig config ) { + super( workspace, config.getApplicationContextHolder() ); + this.metadata = metadata; - this.workspace = workspace; this.config = config; } @Override public ConnectionProvider build() { - final String applicationContextHolderId = config.getApplicationContextHolder(); - final String dataSourceName = config.getDataSourceName(); - - LOG.debug( "Building SpringConnectionProvider (applicationContextHolder: {}, dataSourceName: {})", - applicationContextHolderId, dataSourceName ); - - final ApplicationContextHolder applicationContextHolder = workspace.getResource( ApplicationContextHolderProvider.class, - applicationContextHolderId ); - final ApplicationContext applicationContext = applicationContextHolder.getApplicationContext(); - - final DataSource dataSource; - if ( dataSourceName != null ) { - try { - dataSource = applicationContext.getBean( dataSourceName, DataSource.class ); - - LOG.info( "Bean with name '{}' fetched from ApplicationContext", dataSourceName ); - } catch ( Exception e ) { - throw new ResourceInitException( "Couldn't fetch bean with type DataSource and name '" + dataSourceName - + "' from ApplicationContext", e ); - } - } else { - final Map dataSources = applicationContext.getBeansOfType( DataSource.class ); - if ( dataSources.size() == 1 ) { - dataSource = dataSources.values().iterator().next(); - - LOG.info( "Single DataSource bean fetched from ApplicationContext" ); - } else { - if ( dataSources.containsKey( "dataSource" ) ) { - dataSource = dataSources.get( "dataSource" ); - - LOG.info( "Multiple DataSource beans found in ApplicationContext, bean named 'dataSource' selected." ); - } else { - throw new ResourceInitException( - "Multiple beans with type DataSource are found in ApplicationContext, non of them are named 'dataSource'. Suggestion: add bean name to configuration" ); - } - } - } + LOG.debug( "Building SpringConnectionProvider" ); + final DataSource dataSource = getBean( DataSource.class, config.getDataSourceName(), "dataSource" ); return new SpringConnectionProvider( metadata, dataSource, new PostGISDialect( false ) ); } } diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java index daaaeea0ab..34b681b724 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java @@ -45,6 +45,6 @@ public SpringConnectionProviderBuilder prepare() { throw new ResourceInitException( e.getLocalizedMessage(), e ); } - return new SpringConnectionProviderBuilder( this, workspace, config ); + return new SpringConnectionProviderBuilder( workspace, this, config ); } } From 78ffa5c685d43394d7f0d2788681e969d3246c8e Mon Sep 17 00:00:00 2001 From: copierrj Date: Tue, 25 Jun 2013 11:26:38 +0200 Subject: [PATCH 08/21] SpringConnectionProvider: SQLDialect is now also fetched from ApplicationContext --- deegree-spring/pom.xml | 5 ----- .../org/deegree/spring/AbstractSpringResourceBuilder.java | 8 ++++++++ .../spring/db/SpringConnectionProviderBuilder.java | 5 +++-- .../main/resources/META-INF/schemas/spring/3.4.0/db.xsd | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/deegree-spring/pom.xml b/deegree-spring/pom.xml index 57c571860a..f39416f652 100644 --- a/deegree-spring/pom.xml +++ b/deegree-spring/pom.xml @@ -46,10 +46,5 @@ deegree-core-db ${project.version} - - org.deegree - deegree-sqldialect-postgis - ${project.version} - \ No newline at end of file diff --git a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java index d8e55305cd..16c4ff0433 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java @@ -25,6 +25,14 @@ public AbstractSpringResourceBuilder( final Workspace workspace, final String ap this.applicationContextHolderId = applicationContextHolderId; } + protected B getBean( final Class clazz ) { + return getBean( clazz, null ); + } + + protected B getBean( final Class clazz, final String beanName ) { + return getBean( clazz, beanName, null ); + } + protected B getBean( final Class clazz, final String beanName, final String conventionalBeanName ) { final String className = clazz.getCanonicalName(); diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java index 90207b9a05..470d40d2cf 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java @@ -5,7 +5,7 @@ import org.deegree.db.ConnectionProvider; import org.deegree.spring.AbstractSpringResourceBuilder; import org.deegree.spring.db.jaxb.SpringConnectionProviderConfig; -import org.deegree.sqldialect.postgis.PostGISDialect; +import org.deegree.sqldialect.SQLDialect; import org.deegree.workspace.Workspace; import org.slf4j.Logger; @@ -32,6 +32,7 @@ public ConnectionProvider build() { LOG.debug( "Building SpringConnectionProvider" ); final DataSource dataSource = getBean( DataSource.class, config.getDataSourceName(), "dataSource" ); - return new SpringConnectionProvider( metadata, dataSource, new PostGISDialect( false ) ); + final SQLDialect dialect = getBean( SQLDialect.class, config.getSQLDialectName() ); + return new SpringConnectionProvider( metadata, dataSource, dialect ); } } diff --git a/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/db.xsd b/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/db.xsd index 73f3c0ae61..412032db50 100644 --- a/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/db.xsd +++ b/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/db.xsd @@ -21,6 +21,7 @@ + From 882cad7ae2d16c5f2357d71303bfe740c6b7d722 Mon Sep 17 00:00:00 2001 From: copierrj Date: Tue, 25 Jun 2013 17:11:18 +0200 Subject: [PATCH 09/21] additional debug logging --- .../BootstrapApplicationContextHolderBuilder.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java index 45177b5f9e..2a8a61554e 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java @@ -4,11 +4,17 @@ import org.deegree.spring.bootstrap.jaxb.BootstrapApplicationContextHolderConfig; import org.deegree.workspace.ResourceBuilder; import org.deegree.workspace.ResourceInitException; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; public class BootstrapApplicationContextHolderBuilder implements ResourceBuilder { + + private static final Logger LOG = LoggerFactory.getLogger( BootstrapApplicationContextHolderBuilder.class ); private final BootstrapApplicationContextHolderMetadata metadata; @@ -23,10 +29,13 @@ public BootstrapApplicationContextHolderBuilder( BootstrapApplicationContextHold @Override public ApplicationContextHolder build() { + LOG.debug( "Building BootstrapApplicationContextHolder." ); + try { final ConfigurableApplicationContext context; final String contextClass = config.getContextClass(); if ( contextClass != null ) { + LOG.debug( "Using ContextClass {},", contextClass ); context = new AnnotationConfigApplicationContext( Class.forName( contextClass ) ); } else { final String contextConfigLocation = config.getContextConfigLocation(); @@ -34,12 +43,14 @@ public ApplicationContextHolder build() { throw new ResourceInitException( "Both ContextClass and ContextConfigLocation are missing from BootstrapApplicationContextHolderConfig" ); } - + + LOG.debug( "Using ContextConfigLocation {},", contextConfigLocation ); context = new GenericXmlApplicationContext( contextConfigLocation ); } return new ApplicationContextHolder( metadata, context ); } catch ( Exception e ) { + LOG.debug( "Couldn't build BootstrapApplicationContextHolder", e ); throw new ResourceInitException( "Couldn't build BootstrapApplicationContextHolder", e ); } } From b9f9758a72f4dcc0f66d243a79660085d3e39fa6 Mon Sep 17 00:00:00 2001 From: copierrj Date: Tue, 25 Jun 2013 17:13:10 +0200 Subject: [PATCH 10/21] GenericSpringResourceBuilder and GenericSpringResourceMetadata implemented --- .../spring/GenericSpringResourceBuilder.java | 26 +++++++++ .../spring/GenericSpringResourceMetadata.java | 54 +++++++++++++++++++ .../META-INF/schemas/spring/3.4.0/generic.xsd | 21 ++++++++ 3 files changed, 101 insertions(+) create mode 100644 deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java create mode 100644 deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java create mode 100644 deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/generic.xsd diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java new file mode 100644 index 0000000000..33cdcee3c1 --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java @@ -0,0 +1,26 @@ +package org.deegree.spring; + +import org.deegree.spring.jaxb.SingleBeanRef; + +import org.deegree.workspace.Resource; +import org.deegree.workspace.Workspace; + +public class GenericSpringResourceBuilder extends AbstractSpringResourceBuilder { + + private final Class clazz; + + private final String beanName; + + public GenericSpringResourceBuilder( final Workspace workspace, final SingleBeanRef singleBeanRef, + final Class clazz ) { + super( workspace, singleBeanRef.getApplicationContextHolder() ); + + this.clazz = clazz; + this.beanName = singleBeanRef.getBeanName(); + } + + @Override + public T build() { + return getBean( clazz, beanName ); + } +} diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java new file mode 100644 index 0000000000..90ece6c66d --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java @@ -0,0 +1,54 @@ +package org.deegree.spring; + +import java.net.URL; + +import javax.xml.bind.JAXBElement; + +import org.deegree.commons.xml.jaxb.JAXBUtils; +import org.deegree.spring.jaxb.SingleBeanRef; + +import org.deegree.workspace.Resource; +import org.deegree.workspace.ResourceBuilder; +import org.deegree.workspace.ResourceInitException; +import org.deegree.workspace.ResourceLocation; +import org.deegree.workspace.Workspace; +import org.deegree.workspace.standard.AbstractResourceMetadata; +import org.deegree.workspace.standard.AbstractResourceProvider; + +public class GenericSpringResourceMetadata extends AbstractResourceMetadata { + + private final String configJaxbPackage; + + private final URL configSchema; + + private final Class clazz; + + public GenericSpringResourceMetadata( final Workspace workspace, final ResourceLocation location, + final AbstractResourceProvider provider, final String configJaxbPackage, + final URL configSchema, final Class clazz ) { + super( workspace, location, provider ); + + this.configJaxbPackage = configJaxbPackage; + this.configSchema = configSchema; + this.clazz = clazz; + } + + @Override + public ResourceBuilder prepare() { + final SingleBeanRef config; + + try { + final JAXBElement element = (JAXBElement) JAXBUtils.unmarshall( configJaxbPackage, configSchema, + location.getAsStream(), workspace ); + if ( element.getDeclaredType().equals( SingleBeanRef.class ) ) { + config = (SingleBeanRef) element.getValue(); + } else { + throw new ResourceInitException( "Wrong configuration object passed to GenericSpringResourceMetadata." ); + } + } catch ( Exception e ) { + throw new ResourceInitException( "Couldn't construct GenericSpringResourceBuilder.", e ); + } + + return new GenericSpringResourceBuilder( workspace, config, clazz ); + } +} diff --git a/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/generic.xsd b/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/generic.xsd new file mode 100644 index 0000000000..84d25070c1 --- /dev/null +++ b/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/generic.xsd @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file From 458b67596f32a11f385bddff819c75f6ac0d5b58 Mon Sep 17 00:00:00 2001 From: copierrj Date: Tue, 25 Jun 2013 17:13:43 +0200 Subject: [PATCH 11/21] SpringOWSMetadataProviderProvider implemented --- deegree-spring/pom.xml | 5 +++ .../SpringOWSMetadataProviderProvider.java | 37 +++++++++++++++++++ .../schemas/spring/3.4.0/metadata.xsd | 26 +++++++++++++ ...adata.provider.OWSMetadataProviderProvider | 1 + 4 files changed, 69 insertions(+) create mode 100644 deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java create mode 100644 deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/metadata.xsd create mode 100644 deegree-spring/src/main/resources/META-INF/services/org.deegree.services.metadata.provider.OWSMetadataProviderProvider diff --git a/deegree-spring/pom.xml b/deegree-spring/pom.xml index f39416f652..2811689a22 100644 --- a/deegree-spring/pom.xml +++ b/deegree-spring/pom.xml @@ -46,5 +46,10 @@ deegree-core-db ${project.version} + + org.deegree + deegree-services-commons + ${project.version} + \ No newline at end of file diff --git a/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java new file mode 100644 index 0000000000..8dfe72cf3e --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java @@ -0,0 +1,37 @@ +package org.deegree.spring.services; + +import java.net.URL; + +import org.deegree.services.metadata.OWSMetadataProvider; +import org.deegree.services.metadata.provider.OWSMetadataProviderProvider; +import org.deegree.spring.GenericSpringResourceMetadata; +import org.deegree.workspace.ResourceLocation; +import org.deegree.workspace.ResourceMetadata; +import org.deegree.workspace.Workspace; + +public class SpringOWSMetadataProviderProvider extends OWSMetadataProviderProvider { + + private static final String CONFIG_NS = "http://www.deegree.org/spring/metadata"; + + private static final URL CONFIG_SCHEMA = SpringOWSMetadataProviderProvider.class.getResource( "/META-INF/schemas/spring/3.4.0/metadata.xsd" ); + + private static final String CONFIG_JAXB_PACKAGE = "org.deegree.spring.metadata.jaxb"; + + @Override + public String getNamespace() { + return CONFIG_NS; + } + + @Override + public ResourceMetadata createFromLocation( Workspace workspace, + ResourceLocation location ) { + + return new GenericSpringResourceMetadata( workspace, location, this, CONFIG_JAXB_PACKAGE, + CONFIG_SCHEMA, OWSMetadataProvider.class ); + } + + @Override + public URL getSchema() { + return CONFIG_SCHEMA; + } +} diff --git a/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/metadata.xsd b/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/metadata.xsd new file mode 100644 index 0000000000..8cf8bea0d9 --- /dev/null +++ b/deegree-spring/src/main/resources/META-INF/schemas/spring/3.4.0/metadata.xsd @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/deegree-spring/src/main/resources/META-INF/services/org.deegree.services.metadata.provider.OWSMetadataProviderProvider b/deegree-spring/src/main/resources/META-INF/services/org.deegree.services.metadata.provider.OWSMetadataProviderProvider new file mode 100644 index 0000000000..2c0798eb9f --- /dev/null +++ b/deegree-spring/src/main/resources/META-INF/services/org.deegree.services.metadata.provider.OWSMetadataProviderProvider @@ -0,0 +1 @@ +org.deegree.spring.services.SpringOWSMetadataProviderProvider \ No newline at end of file From 7724be7c56304fce9707d9c0aa8925786d472706 Mon Sep 17 00:00:00 2001 From: copierrj Date: Wed, 26 Jun 2013 10:18:40 +0200 Subject: [PATCH 12/21] bugfix AbstractSpringResourceBuilder.getBean: wrong exception for cases where there is no bean at all of the specified type --- .../spring/AbstractSpringResourceBuilder.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java index 16c4ff0433..c4c3b5e56b 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java @@ -52,11 +52,16 @@ protected B getBean( final Class clazz, final String beanName, final Stri } } else { final Map beans = applicationContext.getBeansOfType( clazz ); - if ( beans.size() == 1 ) { + switch ( beans.size() ) { + case 0: + throw new ResourceInitException( "No beans of type " + className + + " found in ApplicationContext." ); + case 1: bean = beans.values().iterator().next(); LOG.info( "Single {} bean fetched from ApplicationContext.", className ); - } else { + break; + default: if ( conventionalBeanName != null ) { if ( beans.containsKey( conventionalBeanName ) ) { bean = beans.get( conventionalBeanName ); @@ -64,13 +69,13 @@ protected B getBean( final Class clazz, final String beanName, final Stri LOG.info( "Multiple {} beans found in ApplicationContext, bean named '{}' selected.", className, conventionalBeanName ); } else { - throw new ResourceInitException( "Multiple beans with type " + className + throw new ResourceInitException( "Multiple beans of type " + className + " are found in ApplicationContext, none of them are named '" + conventionalBeanName + "'. Suggestion: add bean name to configuration." ); } } else { - throw new ResourceInitException( "Multiple beans with type " + className + throw new ResourceInitException( "Multiple beans of type " + className + " are found in ApplicationContext." ); } } From 36b9826d9d4e7e5a791d8638347d70cd9a7aa473 Mon Sep 17 00:00:00 2001 From: copierrj Date: Wed, 26 Jun 2013 10:48:38 +0200 Subject: [PATCH 13/21] BootstrapApplicationContextHolderBuilder now uses the workspace module classloader --- ...tstrapApplicationContextHolderBuilder.java | 33 ++++++++++++------- ...strapApplicationContextHolderMetadata.java | 2 +- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java index 2a8a61554e..163d8c9afb 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java @@ -8,7 +8,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; @@ -20,9 +19,12 @@ public class BootstrapApplicationContextHolderBuilder implements ResourceBuilder private final BootstrapApplicationContextHolderConfig config; - public BootstrapApplicationContextHolderBuilder( BootstrapApplicationContextHolderMetadata metadata, - BootstrapApplicationContextHolderConfig config ) { + private final ClassLoader classLoader; + public BootstrapApplicationContextHolderBuilder( ClassLoader classLoader, + BootstrapApplicationContextHolderMetadata metadata, + BootstrapApplicationContextHolderConfig config ) { + this.classLoader = classLoader; this.metadata = metadata; this.config = config; } @@ -32,23 +34,32 @@ public ApplicationContextHolder build() { LOG.debug( "Building BootstrapApplicationContextHolder." ); try { - final ConfigurableApplicationContext context; final String contextClass = config.getContextClass(); + if ( contextClass != null ) { - LOG.debug( "Using ContextClass {},", contextClass ); - context = new AnnotationConfigApplicationContext( Class.forName( contextClass ) ); + LOG.debug( "Using ContextClass {}", contextClass ); + + final AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); + context.setClassLoader( classLoader ); + context.register( classLoader.loadClass( contextClass ) ); + context.refresh(); + + return new ApplicationContextHolder( metadata, context ); } else { final String contextConfigLocation = config.getContextConfigLocation(); if ( contextConfigLocation == null ) { throw new ResourceInitException( "Both ContextClass and ContextConfigLocation are missing from BootstrapApplicationContextHolderConfig" ); } - - LOG.debug( "Using ContextConfigLocation {},", contextConfigLocation ); - context = new GenericXmlApplicationContext( contextConfigLocation ); - } - return new ApplicationContextHolder( metadata, context ); + LOG.debug( "Using ContextConfigLocation {}", contextConfigLocation ); + final GenericXmlApplicationContext context = new GenericXmlApplicationContext(); + context.setClassLoader( classLoader ); + context.load( contextConfigLocation ); + context.refresh(); + + return new ApplicationContextHolder( metadata, context ); + } } catch ( Exception e ) { LOG.debug( "Couldn't build BootstrapApplicationContextHolder", e ); throw new ResourceInitException( "Couldn't build BootstrapApplicationContextHolder", e ); diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java index 7e8902a665..607bfbce01 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java @@ -40,6 +40,6 @@ public ResourceBuilder prepare() { throw new ResourceInitException( e.getLocalizedMessage(), e ); } - return new BootstrapApplicationContextHolderBuilder( this, config ); + return new BootstrapApplicationContextHolderBuilder( workspace.getModuleClassLoader(), this, config ); } } From 751bf6e19f658d88477f34364c5db0130e955585 Mon Sep 17 00:00:00 2001 From: copierrj Date: Wed, 26 Jun 2013 16:26:04 +0200 Subject: [PATCH 14/21] metadata injection implemented --- .../spring/GenericSpringResourceBuilder.java | 30 +++++++++++++++++-- .../spring/GenericSpringResourceMetadata.java | 2 +- .../spring/annotation/InjectMetadata.java | 9 ++++++ 3 files changed, 38 insertions(+), 3 deletions(-) create mode 100644 deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java index 33cdcee3c1..7ed7083997 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java @@ -1,26 +1,52 @@ package org.deegree.spring; +import java.lang.reflect.Field; + +import org.deegree.spring.annotation.InjectMetadata; import org.deegree.spring.jaxb.SingleBeanRef; import org.deegree.workspace.Resource; +import org.deegree.workspace.ResourceInitException; import org.deegree.workspace.Workspace; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class GenericSpringResourceBuilder extends AbstractSpringResourceBuilder { + private static final Logger LOG = LoggerFactory.getLogger( GenericSpringResourceBuilder.class ); + private final Class clazz; private final String beanName; + private final GenericSpringResourceMetadata metadata; + public GenericSpringResourceBuilder( final Workspace workspace, final SingleBeanRef singleBeanRef, - final Class clazz ) { + final Class clazz, final GenericSpringResourceMetadata metadata ) { super( workspace, singleBeanRef.getApplicationContextHolder() ); this.clazz = clazz; this.beanName = singleBeanRef.getBeanName(); + this.metadata = metadata; } @Override public T build() { - return getBean( clazz, beanName ); + final T t = getBean( clazz, beanName ); + + try { + for ( Field f : t.getClass().getDeclaredFields() ) { + if ( f.getAnnotation( InjectMetadata.class ) != null ) { + f.setAccessible( true ); + f.set( t, metadata ); + } + } + } catch ( Exception e ) { + LOG.debug( "Couldn't inject metadata.", e ); + throw new ResourceInitException( "Couldn't inject metadata.", e ); + } + + return t; } } diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java index 90ece6c66d..5213ec3b9c 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java @@ -49,6 +49,6 @@ public ResourceBuilder prepare() { throw new ResourceInitException( "Couldn't construct GenericSpringResourceBuilder.", e ); } - return new GenericSpringResourceBuilder( workspace, config, clazz ); + return new GenericSpringResourceBuilder( workspace, config, clazz, this ); } } diff --git a/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java new file mode 100644 index 0000000000..88242810b4 --- /dev/null +++ b/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java @@ -0,0 +1,9 @@ +package org.deegree.spring.annotation; + +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +public @interface InjectMetadata { + +} From 58d0ea88a02481f40d8f6d8ac65ba8d75feae09b Mon Sep 17 00:00:00 2001 From: copierrj Date: Wed, 26 Jun 2013 17:02:24 +0200 Subject: [PATCH 15/21] bugfix GenericSpringResourceMetadata: ApplicationContextHolder dependencies missing --- .../org/deegree/spring/GenericSpringResourceMetadata.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java index 5213ec3b9c..c468fbc51e 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java @@ -14,6 +14,7 @@ import org.deegree.workspace.Workspace; import org.deegree.workspace.standard.AbstractResourceMetadata; import org.deegree.workspace.standard.AbstractResourceProvider; +import org.deegree.workspace.standard.DefaultResourceIdentifier; public class GenericSpringResourceMetadata extends AbstractResourceMetadata { @@ -42,6 +43,11 @@ public ResourceBuilder prepare() { location.getAsStream(), workspace ); if ( element.getDeclaredType().equals( SingleBeanRef.class ) ) { config = (SingleBeanRef) element.getValue(); + + final String applicationContextHolder = config.getApplicationContextHolder(); + dependencies.add( new DefaultResourceIdentifier( + ApplicationContextHolderProvider.class, + applicationContextHolder ) ); } else { throw new ResourceInitException( "Wrong configuration object passed to GenericSpringResourceMetadata." ); } From 176e980fd3d251204651897b42431ede4a870a2b Mon Sep 17 00:00:00 2001 From: copierrj Date: Fri, 28 Jun 2013 11:04:30 +0200 Subject: [PATCH 16/21] copyright headers added --- .../spring/AbstractSpringResourceBuilder.java | 40 +++++++++++++++++++ .../spring/ApplicationContextHolder.java | 40 +++++++++++++++++++ .../ApplicationContextHolderManager.java | 40 +++++++++++++++++++ .../ApplicationContextHolderProvider.java | 40 +++++++++++++++++++ .../spring/GenericSpringResourceBuilder.java | 40 +++++++++++++++++++ .../spring/GenericSpringResourceMetadata.java | 40 +++++++++++++++++++ .../spring/annotation/InjectMetadata.java | 40 +++++++++++++++++++ ...tstrapApplicationContextHolderBuilder.java | 40 +++++++++++++++++++ ...strapApplicationContextHolderMetadata.java | 40 +++++++++++++++++++ ...strapApplicationContextHolderProvider.java | 40 +++++++++++++++++++ .../spring/db/SpringConnectionProvider.java | 40 +++++++++++++++++++ .../db/SpringConnectionProviderBuilder.java | 40 +++++++++++++++++++ .../db/SpringConnectionProviderMetadata.java | 40 +++++++++++++++++++ .../db/SpringConnectionProviderProvider.java | 40 +++++++++++++++++++ .../SpringOWSMetadataProviderProvider.java | 40 +++++++++++++++++++ 15 files changed, 600 insertions(+) diff --git a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java index c4c3b5e56b..169606e3e7 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring; import java.util.Map; diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java index 26ee8a0742..030fad629c 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring; import org.deegree.workspace.Resource; diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java index 190298412f..223132f7bb 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring; import org.deegree.workspace.standard.DefaultResourceManager; diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java index 3d4f61925c..2a5c166754 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring; import org.deegree.workspace.standard.AbstractResourceProvider; diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java index 7ed7083997..2fee6ec937 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring; import java.lang.reflect.Field; diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java index c468fbc51e..f0e5ca0015 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring; import java.net.URL; diff --git a/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java index 88242810b4..caaddde4a3 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring.annotation; import java.lang.annotation.Retention; diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java index 163d8c9afb..d13c174262 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring.bootstrap; import org.deegree.spring.ApplicationContextHolder; diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java index 607bfbce01..0d37776887 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring.bootstrap; import static org.deegree.spring.bootstrap.BootstrapApplicationContextHolderProvider.CONFIG_SCHEMA; diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java index bb5aba761e..f42a06df04 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring.bootstrap; import java.net.URL; diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java index bc276c723f..3f47116c43 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring.db; import java.sql.Connection; diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java index 470d40d2cf..fb247e25d2 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring.db; import javax.sql.DataSource; diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java index 34b681b724..773b371324 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring.db; import static org.deegree.spring.db.SpringConnectionProviderProvider.CONFIG_SCHEMA; diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java index 0a9de34dc1..a8a3bbe81b 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring.db; import java.net.URL; diff --git a/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java index 8dfe72cf3e..9e64159416 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org +----------------------------------------------------------------------------*/ package org.deegree.spring.services; import java.net.URL; From d0c1712c8de407c13e4f7ce6ec1a4b0dfd846461 Mon Sep 17 00:00:00 2001 From: copierrj Date: Fri, 28 Jun 2013 14:10:38 +0200 Subject: [PATCH 17/21] javadoc added --- .../spring/AbstractSpringResourceBuilder.java | 49 ++++++++++++++++++- .../spring/ApplicationContextHolder.java | 9 ++++ .../ApplicationContextHolderManager.java | 10 ++++ .../ApplicationContextHolderProvider.java | 10 ++++ .../spring/GenericSpringResourceBuilder.java | 18 +++++++ .../spring/GenericSpringResourceMetadata.java | 12 +++++ .../spring/annotation/InjectMetadata.java | 16 +++++- ...tstrapApplicationContextHolderBuilder.java | 16 ++++++ ...strapApplicationContextHolderMetadata.java | 10 ++++ ...strapApplicationContextHolderProvider.java | 11 +++++ .../spring/db/SpringConnectionProvider.java | 14 ++++++ .../db/SpringConnectionProviderBuilder.java | 9 ++++ .../db/SpringConnectionProviderMetadata.java | 12 +++++ .../db/SpringConnectionProviderProvider.java | 11 +++++ .../SpringOWSMetadataProviderProvider.java | 10 ++++ 15 files changed, 214 insertions(+), 3 deletions(-) diff --git a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java index 169606e3e7..5b3653d266 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java @@ -52,6 +52,17 @@ import org.springframework.context.ApplicationContext; +/** + * The AbstractSpringResourceBuilder can be extended in order to create a + * {@link org.deegree.workspace.ResourceBuilder} that fetches beans from + * the {@link org.springframework.context.ApplicationContext} contained in + * the specified {@link org.deegree.spring.ApplicationContextHolder}. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public abstract class AbstractSpringResourceBuilder implements ResourceBuilder { private static final Logger LOG = LoggerFactory.getLogger( AbstractSpringResourceBuilder.class ); @@ -60,19 +71,53 @@ public abstract class AbstractSpringResourceBuilder implemen private final String applicationContextHolderId; + /** + * Creates an AbstractSpringResourceBuilder for a given workspace and application context holder. + * + * @param workspace A reference to the current workspace. + * @param applicationContextHolderId The resource identifier of the application context holder. + */ public AbstractSpringResourceBuilder( final Workspace workspace, final String applicationContextHolderId ) { this.workspace = workspace; this.applicationContextHolderId = applicationContextHolderId; } + /** + * Get a bean for a given type. + * + * @param clazz The type of bean to fetch. + * @throws org.deegree.workspace.ResourceInitException if there is not + * exactly one single bean of given type. + * @return A bean. + */ protected B getBean( final Class clazz ) { return getBean( clazz, null ); } + /** + * Get a bean for a given name and type. + * + * @param clazz The type of bean to fetch. + * @param beanName The name of the bean. Allowed to be null. + * @throws org.deegree.workspace.ResourceInitException if the requested + * bean does not exist. + * @return A bean. + */ protected B getBean( final Class clazz, final String beanName ) { return getBean( clazz, beanName, null ); } + /** + * Get a bean for a given name and type. + * + * @param clazz The type of bean to fetch. + * @param beanName The name of the bean. Allowed to be null. + * @param conventionalBeanName The conventional Spring name of this type of bean. + * Allowed to be null. Only used in case beanName is null. + * @throws org.deegree.workspace.ResourceInitException if the requested + * bean does not exist. + * @return A bean. + */ protected B getBean( final Class clazz, final String beanName, final String conventionalBeanName ) { final String className = clazz.getCanonicalName(); @@ -106,11 +151,11 @@ protected B getBean( final Class clazz, final String beanName, final Stri if ( beans.containsKey( conventionalBeanName ) ) { bean = beans.get( conventionalBeanName ); - LOG.info( "Multiple {} beans found in ApplicationContext, bean named '{}' selected.", + LOG.info( "Multiple {} beans found in ApplicationContext, bean named '{}' selected by convention.", className, conventionalBeanName ); } else { throw new ResourceInitException( "Multiple beans of type " + className - + " are found in ApplicationContext, none of them are named '" + + " are found in ApplicationContext, none of bares the conventional name '" + conventionalBeanName + "'. Suggestion: add bean name to configuration." ); } diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java index 030fad629c..bc92f9dc4f 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolder.java @@ -46,6 +46,15 @@ import org.springframework.context.ApplicationContext; import org.springframework.context.ConfigurableApplicationContext; +/** + * The ApplicationContextHolder is a deegree {@link org.deegree.workspace.Resource} + * that contains a Spring {@link org.springframework.context.ApplicationContext}. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class ApplicationContextHolder implements Resource { private final ResourceMetadata metadata; diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java index 223132f7bb..b48d0e78dd 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderManager.java @@ -43,6 +43,16 @@ import org.deegree.workspace.standard.DefaultResourceManager; import org.deegree.workspace.standard.DefaultResourceManagerMetadata; +/** + * The ApplicationContextHolderManager manages the + * {@link org.deegree.spring.ApplicationContextHolder} resources within + * a deegree workspace. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class ApplicationContextHolderManager extends DefaultResourceManager { public ApplicationContextHolderManager() { diff --git a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java index 2a5c166754..0427a0a766 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/ApplicationContextHolderProvider.java @@ -42,6 +42,16 @@ import org.deegree.workspace.standard.AbstractResourceProvider; +/** + * An ApplicationContextHolderProvider is responsible for constructing + * an {@link ApplicationContextHolder} containing an + * {@link org.springframework.context.ApplicationContext}. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public abstract class ApplicationContextHolderProvider extends AbstractResourceProvider { } diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java index 2fee6ec937..958ac4fafa 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java @@ -52,6 +52,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * A GenericSpringResourceBuilder can be used to provide a single bean + * as deegree workspace resource. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class GenericSpringResourceBuilder extends AbstractSpringResourceBuilder { private static final Logger LOG = LoggerFactory.getLogger( GenericSpringResourceBuilder.class ); @@ -62,6 +71,14 @@ public class GenericSpringResourceBuilder extends AbstractSp private final GenericSpringResourceMetadata metadata; + /** + * Creates a GenericSpringResourceBuilder for a given workspace bean reference. + * + * @param workspace A reference to the current workspace. + * @param singleBeanRef A configuration snippet containing the reference to the bean. + * @param clazz The type of the bean. + * @param metadata The metadata to be associated with the bean. + */ public GenericSpringResourceBuilder( final Workspace workspace, final SingleBeanRef singleBeanRef, final Class clazz, final GenericSpringResourceMetadata metadata ) { super( workspace, singleBeanRef.getApplicationContextHolder() ); @@ -76,6 +93,7 @@ public T build() { final T t = getBean( clazz, beanName ); try { + // Wire the the metadata in the bean. for ( Field f : t.getClass().getDeclaredFields() ) { if ( f.getAnnotation( InjectMetadata.class ) != null ) { f.setAccessible( true ); diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java index f0e5ca0015..7f5e57e23f 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java @@ -56,6 +56,18 @@ import org.deegree.workspace.standard.AbstractResourceProvider; import org.deegree.workspace.standard.DefaultResourceIdentifier; +/** + * A GenericSpringResourceMetadata is to be used as the + * {@link org.deegree.workspace.ResourceMetadata} for resources + * provided by {@link org.deegree.spring.GenericSpringResourceBuilder}. + * It registers the configured + * {@link org.deegree.spring.ApplicationContextHolder} as dependency. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class GenericSpringResourceMetadata extends AbstractResourceMetadata { private final String configJaxbPackage; diff --git a/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java index caaddde4a3..0689adb165 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/annotation/InjectMetadata.java @@ -40,9 +40,23 @@ ----------------------------------------------------------------------------*/ package org.deegree.spring.annotation; +import java.lang.annotation.Documented; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; - +import java.lang.annotation.Target; +import java.lang.annotation.ElementType; + +/** + * Identifies the field where {@link org.deegree.spring.GenericSpringResourceBuilder} should + * inject the reference to {@link org.deegree.spring.GenericSpringResourceMetadata}. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ +@Documented +@Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) public @interface InjectMetadata { diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java index d13c174262..cba27bb9d9 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderBuilder.java @@ -51,6 +51,22 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.support.GenericXmlApplicationContext; +/** + * The BootstrapApplicationContextHolderBuilder bootstraps a + * Spring {@link org.springframework.context.ApplicationContext} and + * wraps it in an {@link org.deegree.spring.ApplicationContextHolder} + * + * This builder is the deegree workspace equivalent of Spring classes like + * {@link org.springframework.web.servlet.FrameworkServlet}, + * {@link org.springframework.web.context.ContextLoaderListener} or + * other Spring classes that construct a root + * {@link org.springframework.context.ApplicationContext}. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class BootstrapApplicationContextHolderBuilder implements ResourceBuilder { private static final Logger LOG = LoggerFactory.getLogger( BootstrapApplicationContextHolderBuilder.class ); diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java index 0d37776887..235aa0f6b7 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderMetadata.java @@ -55,6 +55,16 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * BootstrapApplicationContextHolderMetadata is used as + * {@link org.deegree.workspace.ResourceMetadata} by + * {@link org.deegree.spring.bootstrap.BootstrapApplicationContextHolderProvider}. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class BootstrapApplicationContextHolderMetadata extends AbstractResourceMetadata { private static final Logger LOG = LoggerFactory.getLogger( BootstrapApplicationContextHolderMetadata.class ); diff --git a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java index f42a06df04..6d62d546fc 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/bootstrap/BootstrapApplicationContextHolderProvider.java @@ -49,6 +49,17 @@ import org.deegree.workspace.ResourceMetadata; import org.deegree.workspace.Workspace; +/** + * BootstrapApplicationContextHolderProvider provides a + * {@link org.deegree.spring.bootstrap.BootstrapApplicationContextHolderMetadata} object + * which is subsequently used to construct a + * {@link org.deegree.spring.bootstrap.BootstrapApplicationContextHolderBuilder}. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class BootstrapApplicationContextHolderProvider extends ApplicationContextHolderProvider { private static final String CONFIG_NS = "http://www.deegree.org/spring/bootstrap"; diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java index 3f47116c43..15fb993194 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProvider.java @@ -49,6 +49,20 @@ import org.springframework.jdbc.datasource.DataSourceUtils; +/** + * A SpringConnectionProvider provides a {@link java.sql.Connection} from a + * {@link javax.sql.DataSource} available as bean within the configured + * application context using + * {@link org.springframework.jdbc.datasource.DataSourceUtils}. + * + * The {@link org.deegree.sqldialect.SQLDialect} is also + * expected to be available as bean. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class SpringConnectionProvider implements ConnectionProvider { private final SpringConnectionProviderMetadata metadata; diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java index fb247e25d2..7acfa03624 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderBuilder.java @@ -51,6 +51,15 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * SpringConnectionProviderBuilder is used to build a + * @{link org.deegree.spring.db.SpringConnectionProvider}. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class SpringConnectionProviderBuilder extends AbstractSpringResourceBuilder { private static final Logger LOG = LoggerFactory.getLogger( SpringConnectionProviderBuilder.class ); diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java index 773b371324..362dddca21 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderMetadata.java @@ -57,6 +57,18 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +/** + * SpringConnectionProviderMetadata is used as the + * {@link org.deegree.workspace.ResourceMetadata} by the + * {@link org.deegree.spring.db.SpringConnectionProviderProvider} + * It registers the configured + * {@link org.deegree.spring.ApplicationContextHolder} as dependency. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class SpringConnectionProviderMetadata extends AbstractResourceMetadata { private static final Logger LOG = LoggerFactory.getLogger( SpringConnectionProviderMetadata.class ); diff --git a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java index a8a3bbe81b..c9e6b2a443 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/db/SpringConnectionProviderProvider.java @@ -47,6 +47,17 @@ import org.deegree.workspace.ResourceLocation; import org.deegree.workspace.Workspace; +/** + * SpringConnectionProviderProvider provides a + * {@link org.deegree.spring.db.SpringConnectionProviderMetadata} object + * which is subsequently used to construct a + * {@link org.deegree.spring.db.SpringConnectionProviderBuilder}. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class SpringConnectionProviderProvider extends ConnectionProviderProvider { private static final String CONFIG_NS = "http://www.deegree.org/spring/db"; diff --git a/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java index 9e64159416..8234510c9b 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java @@ -49,6 +49,16 @@ import org.deegree.workspace.ResourceMetadata; import org.deegree.workspace.Workspace; +/** + * SpringOWSMetadataProviderProvider enables a bean implementing + * {@link org.deegree.services.metadata.OWSMetadataProvider} + * to be used within a deegree workspace. + * + * @author Reijer Copier + * @author last edited by: $Author$ + * + * @version $Revision$, $Date$ + */ public class SpringOWSMetadataProviderProvider extends OWSMetadataProviderProvider { private static final String CONFIG_NS = "http://www.deegree.org/spring/metadata"; From b4d3b3990c436121a19bfe970fbd7f222ebed74f Mon Sep 17 00:00:00 2001 From: copierrj Date: Fri, 28 Jun 2013 14:49:21 +0200 Subject: [PATCH 18/21] deegree-spring pom.xml update --- deegree-spring/pom.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deegree-spring/pom.xml b/deegree-spring/pom.xml index 2811689a22..dfc3eff9a5 100644 --- a/deegree-spring/pom.xml +++ b/deegree-spring/pom.xml @@ -6,6 +6,7 @@ 3.4-pre3-SNAPSHOT deegree-spring + deegree Spring framework integration module @@ -17,6 +18,7 @@ + ok 3.2.3.RELEASE From e37d4bf271c7e0b3da9124c0d54579088db493e2 Mon Sep 17 00:00:00 2001 From: copierrj Date: Fri, 28 Jun 2013 15:53:18 +0200 Subject: [PATCH 19/21] AbstractSpringResourceBuilderTest added --- deegree-spring/pom.xml | 121 ++++++----- .../spring/AbstractSpringResourceBuilder.java | 2 +- .../AbstractSpringResourceBuilderTest.java | 205 ++++++++++++++++++ 3 files changed, 271 insertions(+), 57 deletions(-) create mode 100644 deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java diff --git a/deegree-spring/pom.xml b/deegree-spring/pom.xml index dfc3eff9a5..1e6c7e1031 100644 --- a/deegree-spring/pom.xml +++ b/deegree-spring/pom.xml @@ -1,57 +1,66 @@ - - 4.0.0 - - org.deegree - deegree - 3.4-pre3-SNAPSHOT - - deegree-spring - deegree Spring framework integration module - - - - - org.jvnet.jaxb2.maven2 - maven-jaxb2-plugin - - - - - - ok - 3.2.3.RELEASE - - - - - org.springframework - spring-context - ${spring.version} - - - org.springframework - spring-jdbc - ${spring.version} - - - org.deegree - deegree-core-workspace - ${project.version} - - - org.deegree - deegree-core-commons - ${project.version} - - - org.deegree - deegree-core-db - ${project.version} - - - org.deegree - deegree-services-commons - ${project.version} - - + + 4.0.0 + + org.deegree + deegree + 3.4-pre3-SNAPSHOT + + deegree-spring + deegree Spring framework integration module + + + + + org.jvnet.jaxb2.maven2 + maven-jaxb2-plugin + + + + + + ok + 3.2.3.RELEASE + + + + + junit + junit + + + org.mockito + mockito-core + + + org.springframework + spring-context + ${spring.version} + + + org.springframework + spring-jdbc + ${spring.version} + + + org.deegree + deegree-core-workspace + ${project.version} + + + org.deegree + deegree-core-commons + ${project.version} + + + org.deegree + deegree-core-db + ${project.version} + + + org.deegree + deegree-services-commons + ${project.version} + + \ No newline at end of file diff --git a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java index 5b3653d266..5ced590348 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/AbstractSpringResourceBuilder.java @@ -155,7 +155,7 @@ protected B getBean( final Class clazz, final String beanName, final Stri className, conventionalBeanName ); } else { throw new ResourceInitException( "Multiple beans of type " + className - + " are found in ApplicationContext, none of bares the conventional name '" + + " are found in ApplicationContext, none of them bares the conventional name '" + conventionalBeanName + "'. Suggestion: add bean name to configuration." ); } diff --git a/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java b/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java new file mode 100644 index 0000000000..8d975fca50 --- /dev/null +++ b/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java @@ -0,0 +1,205 @@ +package org.deegree.spring; + +import org.deegree.workspace.Resource; +import org.deegree.workspace.ResourceInitException; +import org.deegree.workspace.ResourceMetadata; +import org.deegree.workspace.Workspace; + +import org.springframework.context.annotation.AnnotationConfigApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +public class AbstractSpringResourceBuilderTest { + + static abstract class TestResource implements Resource { + + @Override + public void destroy() { + + } + + @Override + @SuppressWarnings("unchecked") + public ResourceMetadata getMetadata() { + return mock( ResourceMetadata.class ); + } + + @Override + public void init() { + + } + } + + static class NoBean extends TestResource { + } + + static class SingleBean extends TestResource { + } + + static class ContentBean extends TestResource { + + final String content; + + ContentBean( final String content ) { + this.content = content; + } + + String getContent() { + return content; + } + } + + @Configuration + static class Config { + + @Bean + public SingleBean singleBean() { + return new SingleBean(); + } + + @Bean + public ContentBean contentBean0() { + return new ContentBean( "contentBean0" ); + } + + @Bean + public ContentBean contentBean1() { + return new ContentBean( "contentBean1" ); + } + + @Bean + public ContentBean contentBean() { + return new ContentBean( "contentBean" ); + } + } + + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( Config.class ); + + ApplicationContextHolder contextHolder = new ApplicationContextHolder( null, context ); + + Workspace workspace; + + @Before + public void setUp() { + workspace = mock( Workspace.class ); + when( workspace.getResource( ApplicationContextHolderProvider.class, "test" ) ).thenReturn( contextHolder ); + } + + @Test(expected = ResourceInitException.class) + public void testGetNonExistingBeanType() { + final AbstractSpringResourceBuilder builder = new AbstractSpringResourceBuilder( + workspace, + "test" ) { + + @Override + public NoBean build() { + return getBean( NoBean.class ); + } + }; + + builder.build(); + } + + @Test(expected = ResourceInitException.class) + public void testGetNonExistingBeanName() { + final AbstractSpringResourceBuilder builder = new AbstractSpringResourceBuilder( + workspace, + "test" ) { + + @Override + public SingleBean build() { + return getBean( SingleBean.class, "wrongName" ); + } + }; + + builder.build(); + } + + @Test + public void testGetSingleBean() { + final AbstractSpringResourceBuilder builder = new AbstractSpringResourceBuilder( + workspace, + "test" ) { + + @Override + public SingleBean build() { + return getBean( SingleBean.class ); + } + }; + + assertEquals( context.getBean( SingleBean.class ), builder.build() ); + } + + @Test(expected = ResourceInitException.class) + public void testGetBeanNameMissing() { + final AbstractSpringResourceBuilder builder = new AbstractSpringResourceBuilder( + workspace, + "test" ) { + + @Override + public ContentBean build() { + return getBean( ContentBean.class ); + } + }; + + builder.build(); + } + + @Test + public void testGetNamedBean() { + final AbstractSpringResourceBuilder builder = new AbstractSpringResourceBuilder( + workspace, + "test" ) { + + @Override + public ContentBean build() { + return getBean( ContentBean.class, "contentBean0" ); + } + }; + + final ContentBean bean = builder.build(); + assertNotNull( bean ); + assertEquals( "contentBean0", bean.getContent() ); + } + + @Test + public void testGetConventionallyNamedBean() { + final AbstractSpringResourceBuilder builder = new AbstractSpringResourceBuilder( + workspace, + "test" ) { + + @Override + public ContentBean build() { + return getBean( ContentBean.class, null, "contentBean" ); + } + }; + + final ContentBean bean = builder.build(); + assertNotNull( bean ); + assertEquals( "contentBean", bean.getContent() ); + } + + @Test(expected = ResourceInitException.class) + public void testGetNonConventionallyNamedBean() { + final AbstractSpringResourceBuilder builder = new AbstractSpringResourceBuilder( + workspace, + "test" ) { + + @Override + public ContentBean build() { + return getBean( ContentBean.class, null, "defaultContentBean" ); + } + }; + + builder.build(); + } +} From 7b74df283e214e59c3c49ea9193d194b0c604432 Mon Sep 17 00:00:00 2001 From: copierrj Date: Fri, 28 Jun 2013 16:17:25 +0200 Subject: [PATCH 20/21] Test application context configuration moved into separate class --- .../AbstractSpringResourceBuilderTest.java | 72 ++----------------- .../java/org/deegree/spring/TestContext.java | 71 ++++++++++++++++++ 2 files changed, 76 insertions(+), 67 deletions(-) create mode 100644 deegree-spring/src/test/java/org/deegree/spring/TestContext.java diff --git a/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java b/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java index 8d975fca50..ba37587363 100644 --- a/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java +++ b/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java @@ -1,13 +1,13 @@ package org.deegree.spring; -import org.deegree.workspace.Resource; +import org.deegree.spring.TestContext.ContentBean; +import org.deegree.spring.TestContext.NoBean; +import org.deegree.spring.TestContext.SingleBean; + import org.deegree.workspace.ResourceInitException; -import org.deegree.workspace.ResourceMetadata; import org.deegree.workspace.Workspace; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.junit.Before; import org.junit.Test; @@ -20,69 +20,7 @@ public class AbstractSpringResourceBuilderTest { - static abstract class TestResource implements Resource { - - @Override - public void destroy() { - - } - - @Override - @SuppressWarnings("unchecked") - public ResourceMetadata getMetadata() { - return mock( ResourceMetadata.class ); - } - - @Override - public void init() { - - } - } - - static class NoBean extends TestResource { - } - - static class SingleBean extends TestResource { - } - - static class ContentBean extends TestResource { - - final String content; - - ContentBean( final String content ) { - this.content = content; - } - - String getContent() { - return content; - } - } - - @Configuration - static class Config { - - @Bean - public SingleBean singleBean() { - return new SingleBean(); - } - - @Bean - public ContentBean contentBean0() { - return new ContentBean( "contentBean0" ); - } - - @Bean - public ContentBean contentBean1() { - return new ContentBean( "contentBean1" ); - } - - @Bean - public ContentBean contentBean() { - return new ContentBean( "contentBean" ); - } - } - - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( Config.class ); + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( TestContext.class ); ApplicationContextHolder contextHolder = new ApplicationContextHolder( null, context ); diff --git a/deegree-spring/src/test/java/org/deegree/spring/TestContext.java b/deegree-spring/src/test/java/org/deegree/spring/TestContext.java new file mode 100644 index 0000000000..5ef4afc9ed --- /dev/null +++ b/deegree-spring/src/test/java/org/deegree/spring/TestContext.java @@ -0,0 +1,71 @@ +package org.deegree.spring; + +import org.deegree.spring.annotation.InjectMetadata; +import org.deegree.workspace.Resource; +import org.deegree.workspace.ResourceMetadata; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class TestContext { + + public static class TestResource implements Resource { + + @InjectMetadata + private ResourceMetadata metadata; + + @Override + public void destroy() { + + } + + @Override + public ResourceMetadata getMetadata() { + return metadata; + } + + @Override + public void init() { + + } + } + + public static class NoBean extends TestResource { + } + + public static class SingleBean extends TestResource { + } + + public static class ContentBean extends TestResource { + + final String content; + + ContentBean( final String content ) { + this.content = content; + } + + public String getContent() { + return content; + } + } + + @Bean + public SingleBean singleBean() { + return new SingleBean(); + } + + @Bean + public ContentBean contentBean0() { + return new ContentBean( "contentBean0" ); + } + + @Bean + public ContentBean contentBean1() { + return new ContentBean( "contentBean1" ); + } + + @Bean + public ContentBean contentBean() { + return new ContentBean( "contentBean" ); + } +} From 95b7dc5ffa1c1d545044a51c22ff5161465423fb Mon Sep 17 00:00:00 2001 From: copierrj Date: Fri, 28 Jun 2013 17:39:43 +0200 Subject: [PATCH 21/21] GenericSpringResourceBuilderTest added (includes some related minor changes) --- .../spring/GenericSpringResourceBuilder.java | 40 ++++-- .../spring/GenericSpringResourceMetadata.java | 11 +- .../SpringOWSMetadataProviderProvider.java | 3 +- .../AbstractSpringResourceBuilderTest.java | 40 ++++++ .../GenericSpringResourceBuilderTest.java | 127 ++++++++++++++++++ .../java/org/deegree/spring/TestContext.java | 54 +++++++- .../spring/test/jaxb/ObjectFactory.java | 58 ++++++++ .../deegree/spring/test/jaxb/TestConfig.java | 59 ++++++++ .../resources/org/deegree/spring/test.xml | 3 + 9 files changed, 369 insertions(+), 26 deletions(-) create mode 100644 deegree-spring/src/test/java/org/deegree/spring/GenericSpringResourceBuilderTest.java create mode 100644 deegree-spring/src/test/java/org/deegree/spring/test/jaxb/ObjectFactory.java create mode 100644 deegree-spring/src/test/java/org/deegree/spring/test/jaxb/TestConfig.java create mode 100644 deegree-spring/src/test/resources/org/deegree/spring/test.xml diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java index 958ac4fafa..feb959cc11 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceBuilder.java @@ -37,7 +37,7 @@ http://www.geographie.uni-bonn.de/deegree/ e-mail: info@deegree.org -----------------------------------------------------------------------------*/ + ----------------------------------------------------------------------------*/ package org.deegree.spring; import java.lang.reflect.Field; @@ -53,8 +53,7 @@ import org.slf4j.LoggerFactory; /** - * A GenericSpringResourceBuilder can be used to provide a single bean - * as deegree workspace resource. + * A GenericSpringResourceBuilder can be used to provide a single bean as deegree workspace resource. * * @author Reijer Copier * @author last edited by: $Author$ @@ -74,10 +73,14 @@ public class GenericSpringResourceBuilder extends AbstractSp /** * Creates a GenericSpringResourceBuilder for a given workspace bean reference. * - * @param workspace A reference to the current workspace. - * @param singleBeanRef A configuration snippet containing the reference to the bean. - * @param clazz The type of the bean. - * @param metadata The metadata to be associated with the bean. + * @param workspace + * A reference to the current workspace. + * @param singleBeanRef + * A configuration snippet containing the reference to the bean. + * @param clazz + * The type of the bean. + * @param metadata + * The metadata to be associated with the bean. */ public GenericSpringResourceBuilder( final Workspace workspace, final SingleBeanRef singleBeanRef, final Class clazz, final GenericSpringResourceMetadata metadata ) { @@ -88,18 +91,27 @@ public GenericSpringResourceBuilder( final Workspace workspace, final SingleBean this.metadata = metadata; } + private void wireMetadata( Class clazz, Object o ) + throws IllegalArgumentException, IllegalAccessException { + + for ( Field f : clazz.getDeclaredFields() ) { + if ( f.getAnnotation( InjectMetadata.class ) != null ) { + f.setAccessible( true ); + f.set( o, metadata ); + } + } + + if ( !clazz.equals( Object.class ) ) { + wireMetadata( clazz.getSuperclass(), o ); + } + } + @Override public T build() { final T t = getBean( clazz, beanName ); try { - // Wire the the metadata in the bean. - for ( Field f : t.getClass().getDeclaredFields() ) { - if ( f.getAnnotation( InjectMetadata.class ) != null ) { - f.setAccessible( true ); - f.set( t, metadata ); - } - } + wireMetadata( t.getClass(), t ); } catch ( Exception e ) { LOG.debug( "Couldn't inject metadata.", e ); throw new ResourceInitException( "Couldn't inject metadata.", e ); diff --git a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java index 7f5e57e23f..46f5a26a9b 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java +++ b/deegree-spring/src/main/java/org/deegree/spring/GenericSpringResourceMetadata.java @@ -40,8 +40,6 @@ ----------------------------------------------------------------------------*/ package org.deegree.spring; -import java.net.URL; - import javax.xml.bind.JAXBElement; import org.deegree.commons.xml.jaxb.JAXBUtils; @@ -72,17 +70,14 @@ public class GenericSpringResourceMetadata extends AbstractR private final String configJaxbPackage; - private final URL configSchema; - private final Class clazz; public GenericSpringResourceMetadata( final Workspace workspace, final ResourceLocation location, final AbstractResourceProvider provider, final String configJaxbPackage, - final URL configSchema, final Class clazz ) { + final Class clazz ) { super( workspace, location, provider ); - this.configJaxbPackage = configJaxbPackage; - this.configSchema = configSchema; + this.configJaxbPackage = configJaxbPackage; this.clazz = clazz; } @@ -91,7 +86,7 @@ public ResourceBuilder prepare() { final SingleBeanRef config; try { - final JAXBElement element = (JAXBElement) JAXBUtils.unmarshall( configJaxbPackage, configSchema, + final JAXBElement element = (JAXBElement) JAXBUtils.unmarshall( configJaxbPackage, provider.getSchema(), location.getAsStream(), workspace ); if ( element.getDeclaredType().equals( SingleBeanRef.class ) ) { config = (SingleBeanRef) element.getValue(); diff --git a/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java b/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java index 8234510c9b..b52dfb8481 100644 --- a/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java +++ b/deegree-spring/src/main/java/org/deegree/spring/services/SpringOWSMetadataProviderProvider.java @@ -76,8 +76,7 @@ public String getNamespace() { public ResourceMetadata createFromLocation( Workspace workspace, ResourceLocation location ) { - return new GenericSpringResourceMetadata( workspace, location, this, CONFIG_JAXB_PACKAGE, - CONFIG_SCHEMA, OWSMetadataProvider.class ); + return new GenericSpringResourceMetadata( workspace, location, this, CONFIG_JAXB_PACKAGE, OWSMetadataProvider.class ); } @Override diff --git a/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java b/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java index ba37587363..834d644b6a 100644 --- a/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java +++ b/deegree-spring/src/test/java/org/deegree/spring/AbstractSpringResourceBuilderTest.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org + ----------------------------------------------------------------------------*/ package org.deegree.spring; import org.deegree.spring.TestContext.ContentBean; diff --git a/deegree-spring/src/test/java/org/deegree/spring/GenericSpringResourceBuilderTest.java b/deegree-spring/src/test/java/org/deegree/spring/GenericSpringResourceBuilderTest.java new file mode 100644 index 0000000000..59b2dfaf94 --- /dev/null +++ b/deegree-spring/src/test/java/org/deegree/spring/GenericSpringResourceBuilderTest.java @@ -0,0 +1,127 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org + ----------------------------------------------------------------------------*/ +package org.deegree.spring; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.io.InputStream; +import java.net.URL; + +import org.deegree.spring.TestContext.SingleBean; +import org.deegree.workspace.ResourceBuilder; +import org.deegree.workspace.ResourceLocation; +import org.deegree.workspace.ResourceMetadata; +import org.deegree.workspace.Workspace; +import org.deegree.workspace.standard.AbstractResourceProvider; +import org.deegree.workspace.standard.DefaultResourceIdentifier; +import org.junit.Before; +import org.junit.Test; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; + +public class GenericSpringResourceBuilderTest { + + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( TestContext.class ); + + ApplicationContextHolder contextHolder = new ApplicationContextHolder( null, context ); + + Workspace workspace; + + static class TestProvider extends AbstractResourceProvider { + + @Override + public String getNamespace() { + return "http://www.deegree.org/spring/test"; + } + + @Override + public ResourceMetadata createFromLocation( Workspace workspace, + ResourceLocation location ) { + return new GenericSpringResourceMetadata( workspace, location, this, + "org.deegree.spring.test.jaxb", SingleBean.class ); + } + + @Override + public URL getSchema() { + return null; + } + } + + @Before + public void setUp() { + workspace = mock( Workspace.class ); + when( workspace.getResource( ApplicationContextHolderProvider.class, "test" ) ).thenReturn( contextHolder ); + when( workspace.getModuleClassLoader() ).thenReturn( GenericSpringResourceBuilderTest.class.getClassLoader() ); + } + + @Test + public void testInjectMetadata() { + + final TestProvider provider = new TestProvider(); + + final InputStream testConfig = GenericSpringResourceBuilderTest.class.getClassLoader().getResourceAsStream( "org/deegree/spring/test.xml" ); + assertNotNull( testConfig ); + + @SuppressWarnings("unchecked") + final ResourceLocation location = mock( ResourceLocation.class ); + when( location.getAsStream() ).thenReturn( testConfig ); + when( location.getIdentifier() ).thenReturn( new DefaultResourceIdentifier( TestProvider.class, + "test" ) ); + + final ResourceMetadata metadata = provider.createFromLocation( workspace, location ); + assertNotNull( metadata ); + + final ResourceBuilder builder = metadata.prepare(); + assertNotNull( builder ); + + final SingleBean beanFromComtext = context.getBean( SingleBean.class ); + assertNull( beanFromComtext.getMetadata() ); + + final SingleBean beanFromBuilder = builder.build(); + assertNotNull( beanFromBuilder ); + assertEquals( beanFromComtext, beanFromBuilder ); + + assertEquals( metadata, beanFromBuilder.getMetadata() ); + } +} diff --git a/deegree-spring/src/test/java/org/deegree/spring/TestContext.java b/deegree-spring/src/test/java/org/deegree/spring/TestContext.java index 5ef4afc9ed..71dc8393fc 100644 --- a/deegree-spring/src/test/java/org/deegree/spring/TestContext.java +++ b/deegree-spring/src/test/java/org/deegree/spring/TestContext.java @@ -1,3 +1,43 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org + ----------------------------------------------------------------------------*/ package org.deegree.spring; import org.deegree.spring.annotation.InjectMetadata; @@ -8,9 +48,9 @@ @Configuration public class TestContext { - + public static class TestResource implements Resource { - + @InjectMetadata private ResourceMetadata metadata; @@ -34,6 +74,16 @@ public static class NoBean extends TestResource { } public static class SingleBean extends TestResource { + + private String property; + + public String getProperty() { + return property; + } + + public void setProperty( String property ) { + this.property = property; + } } public static class ContentBean extends TestResource { diff --git a/deegree-spring/src/test/java/org/deegree/spring/test/jaxb/ObjectFactory.java b/deegree-spring/src/test/java/org/deegree/spring/test/jaxb/ObjectFactory.java new file mode 100644 index 0000000000..480682e04a --- /dev/null +++ b/deegree-spring/src/test/java/org/deegree/spring/test/jaxb/ObjectFactory.java @@ -0,0 +1,58 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org + ----------------------------------------------------------------------------*/ +package org.deegree.spring.test.jaxb; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; + +import org.deegree.spring.jaxb.SingleBeanRef; + +@XmlRegistry +public class ObjectFactory { + + @XmlElementDecl(namespace = "http://www.deegree.org/spring/test", name = "SpringServicesTest") + public JAXBElement createSpringOWSMetadataProviderConfig( SingleBeanRef value ) { + return new JAXBElement( new QName( "http://www.deegree.org/spring/test", "SpringServicesTest" ), + SingleBeanRef.class, value ); + } +} \ No newline at end of file diff --git a/deegree-spring/src/test/java/org/deegree/spring/test/jaxb/TestConfig.java b/deegree-spring/src/test/java/org/deegree/spring/test/jaxb/TestConfig.java new file mode 100644 index 0000000000..5539b88e45 --- /dev/null +++ b/deegree-spring/src/test/java/org/deegree/spring/test/jaxb/TestConfig.java @@ -0,0 +1,59 @@ +//$HeadURL$ +/*---------------------------------------------------------------------------- + This file is part of deegree, http://deegree.org/ + Copyright (C) 2013 by: + + IDgis bv + + This library is free software; you can redistribute it and/or modify it under + the terms of the GNU Lesser General Public License as published by the Free + Software Foundation; either version 2.1 of the License, or (at your option) + any later version. + This library is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more + details. + You should have received a copy of the GNU Lesser General Public License + along with this library; if not, write to the Free Software Foundation, Inc., + 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact information: + + IDgis bv + Boomkamp 16 + 7461 AX Rijssen + The Netherlands + http://idgis.nl/ + + lat/lon GmbH + Aennchenstr. 19, 53177 Bonn + Germany + http://lat-lon.de/ + + Department of Geography, University of Bonn + Prof. Dr. Klaus Greve + Postfach 1147, 53001 Bonn + Germany + http://www.geographie.uni-bonn.de/deegree/ + + e-mail: info@deegree.org + ----------------------------------------------------------------------------*/ +package org.deegree.spring.test.jaxb; + +import javax.xml.bind.JAXBElement; +import javax.xml.namespace.QName; + +import org.deegree.spring.jaxb.SingleBeanRef; + +public class TestConfig extends JAXBElement { + + private static final long serialVersionUID = -4402750689025345875L; + + public TestConfig() { + this( null ); + } + + public TestConfig( SingleBeanRef value ) { + super( new QName( "http://www.deegree.org/spring/test", "SpringServicesTest" ), SingleBeanRef.class, value ); + } +} diff --git a/deegree-spring/src/test/resources/org/deegree/spring/test.xml b/deegree-spring/src/test/resources/org/deegree/spring/test.xml new file mode 100644 index 0000000000..52ac943622 --- /dev/null +++ b/deegree-spring/src/test/resources/org/deegree/spring/test.xml @@ -0,0 +1,3 @@ + + test + \ No newline at end of file