Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A deegree-spring integration module #135

Merged
merged 21 commits into from
Jul 2, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b3be386
module 'deegree-spring' added
copierrj Jun 21, 2013
1b3dcc5
ApplicationContextHolderManager added
copierrj Jun 21, 2013
33b2474
BootstrapApplicationContextHolderProvider implemented
copierrj Jun 24, 2013
dcd7848
SpringConnectionProvider implemented
copierrj Jun 24, 2013
5b53a6c
formatting
copierrj Jun 25, 2013
9e4ad0a
Resource.destroy implemented for ApplicationContextHolder
copierrj Jun 25, 2013
de698c0
AbstractSpringResourceBuilder implemented
copierrj Jun 25, 2013
78ffa5c
SpringConnectionProvider: SQLDialect is now also fetched from
copierrj Jun 25, 2013
882cad7
additional debug logging
copierrj Jun 25, 2013
b9f9758
GenericSpringResourceBuilder and GenericSpringResourceMetadata
copierrj Jun 25, 2013
458b675
SpringOWSMetadataProviderProvider implemented
copierrj Jun 25, 2013
7724be7
bugfix AbstractSpringResourceBuilder.getBean: wrong exception for cases
copierrj Jun 26, 2013
36b9826
BootstrapApplicationContextHolderBuilder now uses the workspace module
copierrj Jun 26, 2013
751bf6e
metadata injection implemented
copierrj Jun 26, 2013
58d0ea8
bugfix GenericSpringResourceMetadata:
copierrj Jun 26, 2013
176e980
copyright headers added
copierrj Jun 28, 2013
d0c1712
javadoc added
copierrj Jun 28, 2013
b4d3b39
deegree-spring pom.xml update
copierrj Jun 28, 2013
e37d4bf
AbstractSpringResourceBuilderTest added
copierrj Jun 28, 2013
7b74df2
Test application context configuration moved into separate class
copierrj Jun 28, 2013
95b7dc5
GenericSpringResourceBuilderTest added (includes some related minor
copierrj Jun 28, 2013
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions deegree-spring/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.deegree</groupId>
<artifactId>deegree</artifactId>
<version>3.4-pre3-SNAPSHOT</version>
</parent>
<artifactId>deegree-spring</artifactId>
<description>deegree Spring framework integration module</description>

<build>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
</plugin>
</plugins>
</build>

<properties>
<deegree.module.status>ok</deegree.module.status>
<spring.version>3.2.3.RELEASE</spring.version>
</properties>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.deegree</groupId>
<artifactId>deegree-core-workspace</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.deegree</groupId>
<artifactId>deegree-core-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.deegree</groupId>
<artifactId>deegree-core-db</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.deegree</groupId>
<artifactId>deegree-services-commons</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
//$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;

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;

/**
* 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 <a href="mailto:reijer.copier@idgis.nl">Reijer Copier</a>
* @author last edited by: $Author$
*
* @version $Revision$, $Date$
*/
public abstract class AbstractSpringResourceBuilder<T extends Resource> implements ResourceBuilder<T> {

private static final Logger LOG = LoggerFactory.getLogger( AbstractSpringResourceBuilder.class );

private final Workspace workspace;

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> B getBean( final Class<B> 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> B getBean( final Class<B> 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> B getBean( final Class<B> 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<String, B> beans = applicationContext.getBeansOfType( clazz );
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 );
break;
default:
if ( conventionalBeanName != null ) {
if ( beans.containsKey( conventionalBeanName ) ) {
bean = beans.get( conventionalBeanName );

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 bares the conventional name '"
+ conventionalBeanName
+ "'. Suggestion: add bean name to configuration." );
}
} else {
throw new ResourceInitException( "Multiple beans of type " + className
+ " are found in ApplicationContext." );
}
}
}

return bean;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
//$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;
import org.deegree.workspace.ResourceMetadata;

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 <a href="mailto:reijer.copier@idgis.nl">Reijer Copier</a>
* @author last edited by: $Author$
*
* @version $Revision$, $Date$
*/
public class ApplicationContextHolder implements Resource {

private final ResourceMetadata<ApplicationContextHolder> metadata;

private final ConfigurableApplicationContext applicationContext;

public ApplicationContextHolder( final ResourceMetadata<ApplicationContextHolder> metadata,
final ConfigurableApplicationContext applicationContext ) {
this.metadata = metadata;
this.applicationContext = applicationContext;
}

@Override
public ResourceMetadata<ApplicationContextHolder> getMetadata() {
return metadata;
}

@Override
public void init() {

}

@Override
public void destroy() {
applicationContext.close();
}

public ApplicationContext getApplicationContext() {
return applicationContext;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//$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;
import org.deegree.workspace.standard.DefaultResourceManagerMetadata;

/**
* The ApplicationContextHolderManager manages the
* {@link org.deegree.spring.ApplicationContextHolder} resources within
* a deegree workspace.
*
* @author <a href="mailto:reijer.copier@idgis.nl">Reijer Copier</a>
* @author last edited by: $Author$
*
* @version $Revision$, $Date$
*/
public class ApplicationContextHolderManager extends DefaultResourceManager<ApplicationContextHolder> {

public ApplicationContextHolderManager() {
super( new DefaultResourceManagerMetadata<ApplicationContextHolder>( ApplicationContextHolderProvider.class,
"spring application context holders",
"spring" ) );
}
}
Loading