Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Josh
committed
May 13, 2010
1 parent
13f2df3
commit 8e6c397
Showing
4 changed files
with
551 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
Copyright (C) 2010 Shopzilla, Inc | ||
|
||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
|
||
|
||
http://tech.shopzilla.com | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
<!-- | ||
* | ||
* Copyright (C) 2010 Shopzilla, Inc | ||
* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* | ||
* | ||
* http://tech.shopzilla.com | ||
* | ||
* | ||
--> | ||
|
||
<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/maven-v4_0_0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.shopzilla.utilities</groupId> | ||
<artifactId>spring</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>core</name> | ||
<properties> | ||
<spring.version>3.0.2.RELEASE</spring.version> | ||
<junit.version>4.7</junit.version> | ||
</properties> | ||
|
||
<contributors> | ||
<contributor> | ||
<name>Tim Morrow</name> | ||
<email>tmorrow@Shopzilla.com</email> | ||
<url>http://timmorrow.org/</url> | ||
</contributor> | ||
<contributor> | ||
<name>Rod Barlow</name> | ||
<email>rbarlow@Shopzilla.com</email> | ||
<url>http://rodneybarlow.org</url> | ||
</contributor> | ||
<contributor> | ||
<name>Robert Roland</name> | ||
<email>rroland@shopzilla.com</email> | ||
<url>http://robertroland.org</url> | ||
</contributor> | ||
<contributor> | ||
<name>Josh Long</name> | ||
<email>jlong@shopzilla.com</email> | ||
<url>http://joshlong.com</url> | ||
</contributor> | ||
<contributor> | ||
<name>Mark Lui</name> | ||
<email>mlui@Shopzilla.com</email> | ||
</contributor> | ||
</contributors> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context-support</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
<version>${spring.version}</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-context-support</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-core</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jmock</groupId> | ||
<artifactId>jmock</artifactId> | ||
<version>2.5.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jmock</groupId> | ||
<artifactId>jmock-legacy</artifactId> | ||
<version>2.5.1</version> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<defaultGoal>install</defaultGoal> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-help-plugin</artifactId> | ||
<version>2.1</version> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>2.1</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>cobertura-maven-plugin</artifactId> | ||
<configuration> | ||
<formats> | ||
<format>html</format> | ||
<format>xml</format> | ||
</formats> | ||
<check> | ||
<!-- 90% --> | ||
<totalLineRate>90</totalLineRate> | ||
<totalBranchRate>90</totalBranchRate> | ||
</check> | ||
<instrumentation> | ||
<ignores> | ||
<ignore>org.apache.commons.logging.*</ignore> | ||
</ignores> | ||
</instrumentation> | ||
</configuration> | ||
<executions> | ||
<execution> | ||
<goals> | ||
<goal>clean</goal> | ||
<goal>check</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<reporting> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-project-info-reports-plugin</artifactId> | ||
<inherited>true</inherited> | ||
<reportSets> | ||
<reportSet> | ||
<reports> | ||
<report>index</report> | ||
</reports> | ||
</reportSet> | ||
<reportSet> | ||
<id>sunlink</id> | ||
<reports> | ||
<report>javadoc</report> | ||
</reports> | ||
<inherited>true</inherited> | ||
<configuration> | ||
<links> | ||
<link>http://java.sun.com/javase/6/docs/api/</link> | ||
</links> | ||
</configuration> | ||
</reportSet> | ||
</reportSets> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-checkstyle-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-docck-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<configuration> | ||
|
||
<links> | ||
<link>http://java.sun.com/javase/6/docs/api/</link> | ||
</links> | ||
<linksource>true</linksource> | ||
<quiet>true</quiet> | ||
<show>private</show> | ||
<sourcepath>${basedir}/src/main/java;${basedir}/src/test/java</sourcepath> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-jxr-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<artifactId>maven-surefire-report-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>cobertura-maven-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>findbugs-maven-plugin</artifactId> | ||
<configuration> | ||
<threshold>Normal</threshold> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</reporting> | ||
|
||
|
||
</project> |
117 changes: 117 additions & 0 deletions
117
src/main/java/com/shopzilla/spring/util/config/ShopzillaNamespaceUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* | ||
* Copyright (C) 2010 Shopzilla, Inc | ||
* | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
* | ||
* | ||
* http://tech.shopzilla.com | ||
* | ||
* | ||
*/ | ||
|
||
package com.shopzilla.spring.util.config; | ||
|
||
import org.springframework.beans.factory.support.BeanDefinitionBuilder; | ||
import org.springframework.core.Conventions; | ||
import org.springframework.util.StringUtils; | ||
import org.w3c.dom.Element; | ||
|
||
/** | ||
* This class was stolen largely from {@link org.springframework.integration.config.xml.IntegrationNamespaceUtils} from the Spring Integration project: it's useful, but we can't risk having a forced dependency on it ATM. | ||
*/ | ||
public class ShopzillaNamespaceUtils { | ||
|
||
/** | ||
* Populates the specified bean definition property with the value of the attribute whose name is provided if that attribute is defined in the given element. | ||
* | ||
* @param builder the bean definition to be configured | ||
* @param element the XML element where the attribute should be defined | ||
* @param attributeName the name of the attribute whose value will be used to populate the property | ||
* @param propertyName the name of the property to be populated | ||
*/ | ||
public void setValueIfAttributeDefined(BeanDefinitionBuilder builder, Element element, | ||
String attributeName, String propertyName) { | ||
String attributeValue = element.getAttribute(attributeName); | ||
|
||
if (StringUtils.hasText(attributeValue)) { | ||
builder.addPropertyValue(propertyName, attributeValue); | ||
} | ||
} | ||
|
||
/** | ||
* Populates the bean definition property corresponding to the specified attributeName with the value of that attribute if it is defined in the given element. <p>The property name will be the camel-case equivalent of the lower case hyphen separated attribute (e.g. the "foo-bar" attribute would | ||
* match the "fooBar" property). | ||
* | ||
* @param beanDefinitionBuilder - the bean definition to be configured | ||
* @param element - the XML element where the attribute should be defined | ||
* @param attributeName - the name of the attribute whose value will be set on the property | ||
* | ||
* @see org.springframework.core.Conventions#attributeNameToPropertyName(String) | ||
*/ | ||
public void setValueIfAttributeDefined(BeanDefinitionBuilder beanDefinitionBuilder, | ||
Element element, String attributeName) { | ||
setValueIfAttributeDefined(beanDefinitionBuilder, element, attributeName, | ||
Conventions.attributeNameToPropertyName(attributeName)); | ||
} | ||
|
||
/** | ||
* Populates the specified bean definition property with the reference to a bean. The bean reference is identified by the value from the attribute whose name is provided if that attribute is defined in the given element. | ||
* | ||
* @param builder the bean definition to be configured | ||
* @param element the XML element where the attribute should be defined | ||
* @param attributeName the name of the attribute whose value will be used as a bean reference to populate the property | ||
* @param propertyName the name of the property to be populated | ||
*/ | ||
public void setReferenceIfAttributeDefined(BeanDefinitionBuilder builder, Element element, | ||
String attributeName, String propertyName) { | ||
String attributeValue = element.getAttribute(attributeName); | ||
|
||
if (StringUtils.hasText(attributeValue)) { | ||
builder.addPropertyReference(propertyName, attributeValue); | ||
} | ||
} | ||
|
||
/** | ||
* Populates the bean definition property corresponding to the specified attributeName with the reference to a bean identified by the value of that attribute if the attribute is defined in the given element. <p>The property name will be the camel-case equivalent of the lower case hyphen | ||
* separated attribute (e.g. the "foo-bar" attribute would match the "fooBar" property). | ||
* | ||
* @param builder - the bean definition to be configured | ||
* @param element - the XML element where the attribute should be defined | ||
* @param attributeName - the name of the attribute whose value will be used as a bean reference to populate the property | ||
* | ||
* @see Conventions#attributeNameToPropertyName(String) | ||
* @see Conventions#attributeNameToPropertyName(String) | ||
*/ | ||
public void setReferenceIfAttributeDefined(BeanDefinitionBuilder builder, Element element, | ||
String attributeName) { | ||
setReferenceIfAttributeDefined(builder, element, attributeName, | ||
Conventions.attributeNameToPropertyName(attributeName)); | ||
} | ||
|
||
/** | ||
* Provides a user friendly description of an element based on its node name and, if available, its "id" attribute value. This is useful for creating error messages from within bean definition parsers. | ||
*/ | ||
public String createElementDescription(Element element) { | ||
String elementId = "'" + element.getNodeName() + "'"; | ||
String id = element.getAttribute("id"); | ||
|
||
if (StringUtils.hasText(id)) { | ||
elementId += (" with id='" + id + "'"); | ||
} | ||
|
||
return elementId; | ||
} | ||
} |
Oops, something went wrong.