001: /*
002: * Copyright 2002-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.transaction.interceptor;
018:
019: import java.lang.reflect.Method;
020: import java.util.Collection;
021:
022: import org.springframework.beans.factory.InitializingBean;
023: import org.springframework.metadata.Attributes;
024: import org.springframework.util.Assert;
025: import org.springframework.util.ObjectUtils;
026:
027: /**
028: * Implementation of the <code>TransactionAttributeSource</code> interface that
029: * reads metadata via Spring's <code>Attributes</code> abstraction.
030: *
031: * <p>Typically used for reading in source-level attributes via
032: * Commons Attributes.
033: *
034: * @author Rod Johnson
035: * @author Juergen Hoeller
036: * @see org.springframework.metadata.Attributes
037: * @see org.springframework.metadata.commons.CommonsAttributes
038: */
039: public class AttributesTransactionAttributeSource extends
040: AbstractFallbackTransactionAttributeSource implements
041: InitializingBean {
042:
043: /**
044: * Underlying Attributes implementation that we're using.
045: */
046: private Attributes attributes;
047:
048: /**
049: * Create a new AttributesTransactionAttributeSource.
050: * @see #setAttributes
051: */
052: public AttributesTransactionAttributeSource() {
053: }
054:
055: /**
056: * Create a new AttributesTransactionAttributeSource.
057: * @param attributes the Attributes implementation to use
058: * @see org.springframework.metadata.commons.CommonsAttributes
059: */
060: public AttributesTransactionAttributeSource(Attributes attributes) {
061: if (attributes == null) {
062: throw new IllegalArgumentException("Attributes is required");
063: }
064: this .attributes = attributes;
065: }
066:
067: /**
068: * Set the Attributes implementation to use.
069: * @see org.springframework.metadata.commons.CommonsAttributes
070: */
071: public void setAttributes(Attributes attributes) {
072: this .attributes = attributes;
073: }
074:
075: public void afterPropertiesSet() {
076: if (this .attributes == null) {
077: throw new IllegalArgumentException(
078: "'attributes' is required");
079: }
080: }
081:
082: protected Collection findAllAttributes(Class clazz) {
083: Assert.notNull(this .attributes, "'attributes' is required");
084: return this .attributes.getAttributes(clazz);
085: }
086:
087: protected Collection findAllAttributes(Method method) {
088: Assert.notNull(this .attributes, "'attributes' is required");
089: return this .attributes.getAttributes(method);
090: }
091:
092: public boolean equals(Object other) {
093: if (this == other) {
094: return true;
095: }
096: if (!(other instanceof AttributesTransactionAttributeSource)) {
097: return false;
098: }
099: AttributesTransactionAttributeSource otherTas = (AttributesTransactionAttributeSource) other;
100: return ObjectUtils.nullSafeEquals(this .attributes,
101: otherTas.attributes);
102: }
103:
104: public int hashCode() {
105: return AttributesTransactionAttributeSource.class.hashCode();
106: }
107:
108: }
|