tag and is a simple
// type (String, Class, int, etc).
Object value = null;
String propertyName = metadata.getNestedListProperty(getLocalName(element), localName);
if (propertyName != null) {
value = parseListElement(childElement, propertyName);
}
else {
propertyName = metadata.getFlatCollectionProperty(getLocalName(element), localName);
if (propertyName != null) {
Object def = parserContext.getDelegate().parseCustomElement(childElement);
PropertyValue pv = definition.getBeanDefinition().getPropertyValues().getPropertyValue(propertyName);
if (pv != null) {
Collection l = (Collection) pv.getValue();
l.add(def);
continue;
} else {
ManagedList l = new ManagedList();
l.add(def);
value = l;
}
} else {
propertyName = metadata.getNestedProperty(getLocalName(element), localName);
if (propertyName != null) {
// lets find the first child bean that parses fine
value = parseChildExtensionBean(childElement);
}
}
}
if (propertyName == null && metadata.isFlatProperty(getLocalName(element), localName)) {
value = parseBeanFromExtensionElement(childElement, className, localName);
propertyName = localName;
}
if (propertyName == null) {
value = tryParseNestedPropertyViaIntrospection(metadata, className, childElement);
propertyName = localName;
}
if (value != null) {
definition.getBeanDefinition().getPropertyValues().addPropertyValue(propertyName, value);
}
else
{
/**
* In this case there is no nested property, so just do a normal
* addProperty like we do with attributes.
*/
String text = getElementText(childElement);
if (text != null) {
addProperty(definition, metadata, element, localName, text);
}
}
}
}
}
}
/**
* Attempts to use introspection to parse the nested property element.
*/
protected Object tryParseNestedPropertyViaIntrospection(MappingMetaData metadata, String className, Element element) {
String localName = getLocalName(element);
PropertyDescriptor descriptor = getPropertyDescriptor(className, localName);
if (descriptor != null) {
return parseNestedPropertyViaIntrospection(metadata, element, descriptor.getName(), descriptor.getPropertyType());
} else {
return parseNestedPropertyViaIntrospection(metadata, element, localName, Object.class);
}
}
/**
* Looks up the property decriptor for the given class and property name
*/
protected PropertyDescriptor getPropertyDescriptor(String className, String localName) {
BeanInfo beanInfo = qnameHelper.getBeanInfo(className);
if (beanInfo != null) {
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (int i = 0; i < descriptors.length; i++) {
PropertyDescriptor descriptor = descriptors[i];
String name = descriptor.getName();
if (name.equals(localName)) {
return descriptor;
}
}
}
return null;
}
/**
* Attempts to use introspection to parse the nested property element.
*/
private Object parseNestedPropertyViaIntrospection(MappingMetaData metadata, Element element, String propertyName, Class propertyType) {
if (isMap(propertyType)) {
return parseCustomMapElement(metadata, element, propertyName);
} else if (isCollection(propertyType)) {
return parseListElement(element, propertyName);
} else {
return parseChildExtensionBean(element);
}
}
protected Object parseListElement(Element element, String name) {
return parserContext.getDelegate().parseListElement(element, null);
}
protected Object parseCustomMapElement(MappingMetaData metadata, Element element, String name) {
Map map = new ManagedMap();
Element parent = (Element) element.getParentNode();
String entryName = metadata.getMapEntryName(getLocalName(parent), name);
String keyName = metadata.getMapKeyName(getLocalName(parent), name);
String dups = metadata.getMapDupsMode(getLocalName(parent), name);
boolean flat = metadata.isFlatMap(getLocalName(parent), name);
String defaultKey = metadata.getMapDefaultKey(getLocalName(parent), name);
if (entryName == null) entryName = "property";
if (keyName == null) keyName = "key";
if (dups == null) dups = "replace";
// TODO : support further customizations
//String valueName = "value";
//boolean keyIsAttr = true;
//boolean valueIsAttr = false;
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element childElement = (Element) node;
String localName = childElement.getLocalName();
String uri = childElement.getNamespaceURI();
if (localName == null || localName.equals("xmlns") || localName.startsWith("xmlns:")) {
continue;
}
// we could use namespaced attributes to differentiate real spring
// attributes from namespace-specific attributes
if (!flat && !isEmpty(uri) && localName.equals(entryName)) {
String key = childElement.getAttribute(keyName);
if (key == null || key.length() == 0) {
key = defaultKey;
}
if (key == null) {
throw new RuntimeException("No key defined for map " + entryName);
}
Object keyValue = getValue(key, null);
Element valueElement = getFirstChildElement(childElement);
Object value;
if (valueElement != null) {
String valueElUri = valueElement.getNamespaceURI();
String valueElLocalName = valueElement.getLocalName();
if (valueElUri == null ||
valueElUri.equals(SPRING_SCHEMA) ||
valueElUri.equals(SPRING_SCHEMA_COMPAT) ||
valueElUri.equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI)) {
if (BeanDefinitionParserDelegate.BEAN_ELEMENT.equals(valueElLocalName)) {
value = parserContext.getDelegate().parseBeanDefinitionElement(valueElement, null);
} else {
value = parserContext.getDelegate().parsePropertySubElement(valueElement, null);
}
} else {
value = parserContext.getDelegate().parseCustomElement(valueElement);
}
} else {
value = getElementText(childElement);
}
addValueToMap(map, keyValue, value, dups);
} else if (flat && !isEmpty(uri)) {
String key = childElement.getAttribute(keyName);
if (key == null || key.length() == 0) {
key = defaultKey;
}
if (key == null) {
throw new RuntimeException("No key defined for map entry " + entryName);
}
Object keyValue = getValue(key, null);
childElement.removeAttribute(keyName);
BeanDefinitionHolder bdh = parseBeanFromExtensionElement(childElement);
addValueToMap(map, keyValue, bdh, dups);
}
}
}
return map;
}
protected void addValueToMap(Map map, Object keyValue, Object value, String dups) {
if (map.containsKey(keyValue)) {
if ("discard".equalsIgnoreCase(dups)) {
// Do nothing
} else if ("replace".equalsIgnoreCase(dups)) {
map.put(keyValue, value);
} else if ("allow".equalsIgnoreCase(dups)) {
List l = new ManagedList();
l.add(map.get(keyValue));
l.add(value);
map.put(keyValue, l);
} else if ("always".equalsIgnoreCase(dups)) {
List l = (List) map.get(keyValue);
l.add(value);
}
} else {
if ("always".equalsIgnoreCase(dups)) {
List l = (List) map.get(keyValue);
if (l == null) {
l = new ManagedList();
map.put(keyValue, l);
}
l.add(value);
} else {
map.put(keyValue, value);
}
}
}
protected Element getFirstChildElement(Element element) {
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
return (Element) node;
}
}
return null;
}
protected boolean isMap(Class type) {
return Map.class.isAssignableFrom(type);
}
/**
* Returns true if the given type is a collection type or an array
*/
protected boolean isCollection(Class type) {
return type.isArray() || Collection.class.isAssignableFrom(type);
}
/**
* Iterates the children of this element to find the first nested bean
*/
protected Object parseChildExtensionBean(Element element) {
NodeList nl = element.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element childElement = (Element) node;
String uri = childElement.getNamespaceURI();
String localName = childElement.getLocalName();
if (uri == null ||
uri.equals(SPRING_SCHEMA) ||
uri.equals(SPRING_SCHEMA_COMPAT) ||
uri.equals(BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI)) {
if (BeanDefinitionParserDelegate.BEAN_ELEMENT.equals(localName)) {
return parserContext.getDelegate().parseBeanDefinitionElement(childElement, null);
} else {
return parserContext.getDelegate().parsePropertySubElement(childElement, null);
}
} else {
Object value = parserContext.getDelegate().parseCustomElement(childElement);
if (value != null) {
return value;
}
}
}
}
return null;
}
/**
* Uses META-INF/services discovery to find a Properties file with the XML
* marshaling configuration
*
* @param namespaceURI
* the namespace URI of the element
* @param localName
* the local name of the element
* @return the properties configuration of the namespace or null if none
* could be found
*/
protected MappingMetaData findNamespaceProperties(String namespaceURI, String localName) {
// lets look for the magic prefix
if (namespaceURI != null && namespaceURI.startsWith(JAVA_PACKAGE_PREFIX)) {
String packageName = namespaceURI.substring(JAVA_PACKAGE_PREFIX.length());
return new MappingMetaData(packageName);
}
String uri = NamespaceHelper.createDiscoveryPathName(namespaceURI, localName);
InputStream in = loadResource(uri);
if (in == null) {
if (namespaceURI != null && namespaceURI.length() > 0) {
uri = NamespaceHelper.createDiscoveryPathName(namespaceURI);
in = loadResource(uri);
if (in == null) {
uri = NamespaceHelper.createDiscoveryOldPathName(namespaceURI);
in = loadResource(uri);
}
}
}
if (in != null) {
try {
Properties properties = new Properties();
properties.load(in);
return new MappingMetaData(properties);
}
catch (IOException e) {
log.warn("Failed to load resource from uri: " + uri, e);
}
}
return null;
}
/**
* Loads the resource from the given URI
*/
protected InputStream loadResource(String uri) {
if (System.getProperty("xbean.dir") != null) {
File f = new File(System.getProperty("xbean.dir") + uri);
try {
return new FileInputStream(f);
} catch (FileNotFoundException e) {
// Ignore
}
}
// lets try the thread context class loader first
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(uri);
if (in == null) {
ClassLoader cl = parserContext.getReaderContext().getReader().getBeanClassLoader();
if (cl != null) {
in = cl.getResourceAsStream(uri);
}
if (in == null) {
in = getClass().getClassLoader().getResourceAsStream(uri);
if (in == null) {
log.debug("Could not find resource: " + uri);
}
}
}
return in;
}
protected boolean isEmpty(String uri) {
return uri == null || uri.length() == 0;
}
protected boolean isDefaultNamespace(String namespaceUri) {
return (!StringUtils.hasLength(namespaceUri) ||
BeanDefinitionParserDelegate.BEANS_NAMESPACE_URI.equals(namespaceUri)) ||
SPRING_SCHEMA.equals(namespaceUri) ||
SPRING_SCHEMA_COMPAT.equals(namespaceUri);
}
protected void declareLifecycleMethods(BeanDefinitionHolder definitionHolder, MappingMetaData metaData,
Element element) {
BeanDefinition definition = definitionHolder.getBeanDefinition();
if (definition instanceof AbstractBeanDefinition) {
AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) definition;
if (beanDefinition.getInitMethodName() == null) {
beanDefinition.setInitMethodName(metaData.getInitMethodName(getLocalName(element)));
}
if (beanDefinition.getDestroyMethodName() == null) {
beanDefinition.setDestroyMethodName(metaData.getDestroyMethodName(getLocalName(element)));
}
if (beanDefinition.getFactoryMethodName() == null) {
beanDefinition.setFactoryMethodName(metaData.getFactoryMethodName(getLocalName(element)));
}
}
}
// -------------------------------------------------------------------------
//
// TODO we could apply the following patches into the Spring code -
// though who knows if it'll ever make it into a release! :)
//
// -------------------------------------------------------------------------
/*
protected int parseBeanDefinitions(Element root) throws BeanDefinitionStoreException {
int beanDefinitionCount = 0;
if (isEmpty(root.getNamespaceURI()) || root.getLocalName().equals("beans")) {
NodeList nl = root.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node instanceof Element) {
Element ele = (Element) node;
if (IMPORT_ELEMENT.equals(node.getNodeName())) {
importBeanDefinitionResource(ele);
}
else if (ALIAS_ELEMENT.equals(node.getNodeName())) {
String name = ele.getAttribute(NAME_ATTRIBUTE);
String alias = ele.getAttribute(ALIAS_ATTRIBUTE);
getBeanDefinitionReader().getBeanFactory().registerAlias(name, alias);
}
else if (BEAN_ELEMENT.equals(node.getNodeName())) {
beanDefinitionCount++;
BeanDefinitionHolder bdHolder = parseBeanDefinitionElement(ele, false);
BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getBeanDefinitionReader()
.getBeanFactory());
}
else {
BeanDefinitionHolder bdHolder = parseBeanFromExtensionElement(ele);
if (bdHolder != null) {
beanDefinitionCount++;
BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getBeanDefinitionReader()
.getBeanFactory());
}
else {
log.debug("Ignoring unknown element namespace: " + ele.getNamespaceURI() + " localName: "
+ ele.getLocalName());
}
}
}
}
} else {
BeanDefinitionHolder bdHolder = parseBeanFromExtensionElement(root);
if (bdHolder != null) {
beanDefinitionCount++;
BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getBeanDefinitionReader()
.getBeanFactory());
}
else {
log.debug("Ignoring unknown element namespace: " + root.getNamespaceURI() + " localName: " + root.getLocalName());
}
}
return beanDefinitionCount;
}
protected BeanDefinitionHolder parseBeanDefinitionElement(Element ele, boolean isInnerBean) throws BeanDefinitionStoreException {
BeanDefinitionHolder bdh = super.parseBeanDefinitionElement(ele, isInnerBean);
coerceNamespaceAwarePropertyValues(bdh, ele);
return bdh;
}
protected Object parsePropertySubElement(Element element, String beanName) throws BeanDefinitionStoreException {
String uri = element.getNamespaceURI();
String localName = getLocalName(element);
if ((!isEmpty(uri) && !(uri.equals(SPRING_SCHEMA) || uri.equals(SPRING_SCHEMA_COMPAT)))
|| !reservedElementNames.contains(localName)) {
Object answer = parseBeanFromExtensionElement(element);
if (answer != null) {
return answer;
}
}
if (QNAME_ELEMENT.equals(localName) && isQnameIsOnClassPath()) {
Object answer = parseQNameElement(element);
if (answer != null) {
return answer;
}
}
return super.parsePropertySubElement(element, beanName);
}
protected Object parseQNameElement(Element element) {
return QNameReflectionHelper.createQName(element, getElementText(element));
}
*/
/**
* Returns the text of the element
*/
protected String getElementText(Element element) {
StringBuffer buffer = new StringBuffer();
NodeList nodeList = element.getChildNodes();
for (int i = 0, size = nodeList.getLength(); i < size; i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.TEXT_NODE || node.getNodeType() == Node.CDATA_SECTION_NODE) {
buffer.append(node.getNodeValue());
}
}
return buffer.toString();
}
}
././@LongLink 0000000 0000000 0000000 00000000160 00000000000 011562 L ustar root root xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/v2c/XBeanBeanDefinitionParserDelegate.java xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/v2c/XBeanBeanDefinitionParserDe0000644 0001750 0001750 00000010622 11030663323 033335 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.v2c;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import org.apache.xbean.spring.context.impl.PropertyEditorHelper;
import org.apache.xbean.spring.context.impl.QNameReflectionHelper;
import org.apache.xbean.spring.context.v2.XBeanNamespaceHandler;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.xml.BeanDefinitionParserDelegate;
import org.springframework.beans.factory.xml.XmlReaderContext;
import org.springframework.util.StringUtils;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class XBeanBeanDefinitionParserDelegate extends BeanDefinitionParserDelegate {
public static final String QNAME_ELEMENT = "qname";
private XBeanQNameHelper qnameHelper;
public XBeanBeanDefinitionParserDelegate(XmlReaderContext readerContext) {
super(readerContext);
qnameHelper = new XBeanQNameHelper(readerContext);
}
public Object parsePropertySubElement(Element ele, BeanDefinition bd, String defaultTypeClassName) {
if (!isDefaultNamespace(ele.getNamespaceURI())) {
return internalParseNestedCustomElement(ele, bd);
}
else if (ele.getTagName().equals(QNAME_ELEMENT)) {
return parseQNameElement(ele);
}
else {
return super.parsePropertySubElement(ele, bd, defaultTypeClassName);
}
}
public AbstractBeanDefinition parseBeanDefinitionElement(Element ele, String beanName, BeanDefinition containingBean) {
AbstractBeanDefinition bd = super.parseBeanDefinitionElement(ele, beanName, containingBean);
qnameHelper.coerceNamespaceAwarePropertyValues(bd, ele);
return bd;
}
public boolean isDefaultNamespace(String namespaceUri) {
return (!StringUtils.hasLength(namespaceUri) ||
BEANS_NAMESPACE_URI.equals(namespaceUri)) ||
XBeanNamespaceHandler.SPRING_SCHEMA.equals(namespaceUri) ||
XBeanNamespaceHandler.SPRING_SCHEMA_COMPAT.equals(namespaceUri);
}
protected Object parseQNameElement(Element element) {
return QNameReflectionHelper.createQName(element, getElementText(element));
}
protected String getElementText(Element element) {
StringBuffer buffer = new StringBuffer();
NodeList nodeList = element.getChildNodes();
for (int i = 0, size = nodeList.getLength(); i < size; i++) {
Node node = nodeList.item(i);
if (node.getNodeType() == Node.TEXT_NODE) {
buffer.append(node.getNodeValue());
}
}
return buffer.toString();
}
private Object internalParseNestedCustomElement(Element candidateEle, BeanDefinition containingBeanDefinition) {
try {
Method mth = getClass().getSuperclass().getDeclaredMethod("parseNestedCustomElement", new Class[] { Element.class, BeanDefinition.class });
mth.setAccessible(true);
return mth.invoke(this, new Object[] { candidateEle, containingBeanDefinition });
} catch (Exception e) {
if (e instanceof InvocationTargetException && e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
}
throw (IllegalStateException) new IllegalStateException("Unable to invoke parseNestedCustomElement method").initCause(e);
}
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/ 0000755 0001750 0001750 00000000000 11610661036 026441 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/MappingMetaData.java 0000644 0001750 0001750 00000020274 10575233120 032303 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Properties;
import java.util.StringTokenizer;
/**
* A helper class which understands how to map an XML namespaced element to
* Spring bean configurations
*
* @author James Strachan
* @version $Id$
* @since 2.0
*/
public class MappingMetaData {
private Properties properties;
private String packageName;
/**
* Creates an empty MappingMetaData for the specified Java package.
* @param packageName the Java package to map
*/
public MappingMetaData(String packageName) {
this.packageName = packageName;
this.properties = new Properties();
}
/**
* Creates MappingMetaData using the specified properties which contan the package name.
* @param properties
*/
public MappingMetaData(Properties properties) {
this.properties = properties;
}
/**
* Returns the Java class name for the given XML element name
*/
public String getClassName(String localName) {
String className = properties.getProperty(localName);
if (className == null && packageName != null) {
if (packageName.length() > 0) {
className = packageName + "." + localName;
}
else {
className = localName;
}
}
return className;
}
/**
* Returns the property name for the given element and attribute name
*
* @param elementName the XML local name of the element
* @param attributeName the XML local name of the attribute
* @return the property name to use or null if the attribute is not a valid property
*/
public String getPropertyName(String elementName, String attributeName) {
return properties.getProperty(elementName + ".alias." + attributeName, attributeName);
}
/**
* Returns a valid property name if the childElementName maps to a nested list property
*
* @param elementName the owner element
* @param childElementName is the child element name which maps to the nested list property
* @return the property name if available or null if it is not applicable
*/
public String getNestedListProperty(String elementName, String childElementName) {
return properties.getProperty(elementName + ".list." + childElementName);
}
/**
* Returns a valid property name if the childElementName maps to a nested bean property
*
* @param elementName the owner element
* @param childElementName is the child element name which maps to the nested bean property
* @return the property name if available or null if it is not applicable
*/
public String getNestedProperty(String elementName, String childElementName) {
return properties.getProperty(elementName + ".alias." + childElementName);
}
public boolean isDefaultConstructor(Constructor constructor) {
String property = properties.getProperty(constructorToPropertyName(constructor) + ".default");
if (property != null) {
return Boolean.valueOf(property).booleanValue();
}
return false;
}
public boolean isDefaultFactoryMethod(Class beanClass, Method factoryMethod) {
String property = properties.getProperty(methodToPropertyName(beanClass, factoryMethod) + ".default");
if (property != null) {
return Boolean.valueOf(property).booleanValue();
}
return false;
}
public String[] getParameterNames(Constructor constructor) {
String property = properties.getProperty(constructorToPropertyName(constructor) + ".parameterNames");
if (property != null) {
ArrayList names = Collections.list(new StringTokenizer(property, ", "));
return (String[]) names.toArray(new String[0]);
}
return null;
}
public String[] getParameterNames(Class beanClass, Method factoryMethod) {
String property = properties.getProperty(methodToPropertyName(beanClass, factoryMethod) + ".parameterNames");
if (property != null) {
ArrayList names = Collections.list(new StringTokenizer(property, ", "));
return (String[]) names.toArray(new String[0]);
}
return null;
}
public static String constructorToPropertyName(Constructor constructor) {
StringBuffer buf = new StringBuffer();
buf.append(constructor.getName()).append("(");
Class[] parameterTypes = constructor.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
Class parameterType = parameterTypes[i];
buf.append(parameterType.getName());
if (i < parameterTypes.length - 1) {
buf.append(",");
}
}
buf.append(")");
return buf.toString();
}
public static String methodToPropertyName(Class beanClass, Method method) {
StringBuffer buf = new StringBuffer();
buf.append(beanClass.getName()).append(".");
buf.append(method.getName()).append("(");
Class[] parameterTypes = method.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
Class parameterType = parameterTypes[i];
buf.append(parameterType.getName());
if (i < parameterTypes.length - 1) {
buf.append(",");
}
}
buf.append(")");
return buf.toString();
}
public String getInitMethodName(String elementName) {
return properties.getProperty(elementName + ".initMethod");
}
public String getDestroyMethodName(String elementName) {
return properties.getProperty(elementName + ".destroyMethod");
}
public String getFactoryMethodName(String elementName) {
return properties.getProperty(elementName + ".factoryMethod");
}
public String getContentProperty(String elementName) {
return properties.getProperty(elementName + ".contentProperty");
}
public String getMapEntryName(String elementName, String property) {
return properties.getProperty(elementName + "." + property + ".map.entryName");
}
public String getMapKeyName(String elementName, String property) {
return properties.getProperty(elementName + "." + property + ".map.keyName");
}
public boolean isFlatMap(String elementName, String property) {
return properties.getProperty(elementName + "." + property + ".map.flat") != null;
}
public String getMapDupsMode(String elementName, String property) {
return properties.getProperty(elementName + "." + property + ".map.dups");
}
public String getMapDefaultKey(String elementName, String property) {
return properties.getProperty(elementName + "." + property + ".map.defaultKey");
}
public String getFlatCollectionProperty(String elementName, String property)
{
return properties.getProperty(elementName + "." + property + ".flatCollection");
}
public boolean isFlatProperty(String elementName, String property) {
return properties.getProperty(elementName + "." + property + ".flat") != null;
}
public String getPropertyEditor(String elementName, String property)
{
return properties.getProperty(elementName + "." + property + ".propertyEditor");
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/FileEditor.java 0000644 0001750 0001750 00000002366 10473277125 031351 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import java.beans.PropertyEditorSupport;
import java.io.File;
/**
* Editor for java.io.File
*/
public class FileEditor extends PropertyEditorSupport {
public void setAsText(String text) throws IllegalArgumentException {
setValue(new File(text));
}
public String getAsText() {
File value = (File) getValue();
return (value != null ? value.toString() : "");
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/DefaultProperty.java 0000644 0001750 0001750 00000005224 10473277125 032450 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
/**
* DefaultProperty contains the default value assigned to a property with a specific name and type.
* @author Dain Sundstrom
* @version $Id$
* @since 2.0
*/
public class DefaultProperty {
private String name;
private Class type;
private Object value;
/**
* Creates a new empty default property. This instance is unusable until the name, type and values are assigned.
*/
public DefaultProperty() {
}
/**
* Creates new default property value for a property with the specified name and type.
* @param name the name of the property
* @param type the type of the property
* @param value the default value
*/
public DefaultProperty(String name, Class type, Object value) {
this.name = name;
this.type = type;
this.value = value;
}
/**
* Gets the property name.
* @return the property name
*/
public String getName() {
return name;
}
/**
* Sets the property name.
* @param name the property name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the property type.
* @return the property type
*/
public Class getType() {
return type;
}
/**
* Sets the property type.
* @param type the property type
*/
public void setType(Class type) {
this.type = type;
}
/**
* Gets the default value.
* @return the default value
*/
public Object getValue() {
return value;
}
/**
* Sets the default value.
* @param value the default value
*/
public void setValue(Object value) {
this.value = value;
}
/**
* {@inheritDoc}
*/
public String toString() {
return "[" + name + ", " + type + ", " + value + "]";
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/XBeanXmlBeanFactory.java 0000644 0001750 0001750 00000006642 10473277125 033120 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import java.util.Collections;
import java.util.List;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.core.io.Resource;
public class XBeanXmlBeanFactory extends DefaultListableBeanFactory {
/**
* Create a new XBeanXmlBeanFactory with the given resource,
* which must be parsable using DOM.
* @param resource XML resource to load bean definitions from
* @throws BeansException in case of loading or parsing errors
*/
public XBeanXmlBeanFactory(Resource resource) throws BeansException {
this(resource, null, Collections.EMPTY_LIST);
}
/**
* Create a new XBeanXmlBeanFactory with the given input stream,
* which must be parsable using DOM.
* @param resource XML resource to load bean definitions from
* @param parentBeanFactory parent bean factory
* @throws BeansException in case of loading or parsing errors
*/
public XBeanXmlBeanFactory(Resource resource, BeanFactory parentBeanFactory) throws BeansException {
this(resource, parentBeanFactory, Collections.EMPTY_LIST);
}
/**
* Create a new XBeanXmlBeanFactory with the given input stream,
* which must be parsable using DOM.
* @param resource XML resource to load bean definitions from
* @param xmlPreprocessors the preprocessors to apply the DOM before passing to Spring for processing
* @throws BeansException in case of loading or parsing errors
*/
public XBeanXmlBeanFactory(Resource resource, List xmlPreprocessors) throws BeansException {
this(resource, null, xmlPreprocessors);
}
/**
* Create a new XBeanXmlBeanFactory with the given input stream,
* which must be parsable using DOM.
* @param resource XML resource to load bean definitions from
* @param parentBeanFactory parent bean factory
* @param xmlPreprocessors the preprocessors to apply the DOM before passing to Spring for processing
* @throws BeansException in case of loading or parsing errors
*/
public XBeanXmlBeanFactory(Resource resource, BeanFactory parentBeanFactory, List xmlPreprocessors) throws BeansException {
super(parentBeanFactory);
XmlBeanDefinitionReader reader = XBeanHelper.createBeanDefinitionReader(null, this, xmlPreprocessors);
reader.loadBeanDefinitions(resource);
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/URIEditor.java 0000644 0001750 0001750 00000002701 10473277125 031122 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import java.beans.PropertyEditorSupport;
import java.net.URI;
import java.net.URISyntaxException;
/**
* Editor for java.net.URI
*/
public class URIEditor extends PropertyEditorSupport {
public void setAsText(String text) throws IllegalArgumentException {
try {
setValue(new URI(text));
}
catch (URISyntaxException e) {
throw new IllegalArgumentException(
"Could not convert URI for " + text + ": " + e.getMessage());
}
}
public String getAsText() {
URI value = (URI) getValue();
return (value != null ? value.toString() : "");
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/NamespaceHelper.java 0000644 0001750 0001750 00000004505 10473277125 032354 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
/**
* A helper class for turning namespaces into META-INF/services URIs
*
* @version $Revision: 1.1 $
*/
public class NamespaceHelper {
public static final String META_INF_PREFIX = "META-INF/services/org/apache/xbean/spring/";
public static final String OLD_META_INF_PREFIX = "META-INF/services/org/xbean/spring/";
/**
* Converts the namespace and localName into a valid path name we can use on
* the classpath to discover a text file
*/
public static String createDiscoveryPathName(String uri, String localName) {
if (isEmpty(uri)) {
return localName;
}
return createDiscoveryPathName(uri) + "/" + localName;
}
/**
* Converts the namespace and localName into a valid path name we can use on
* the classpath to discover a text file
*/
public static String createDiscoveryPathName(String uri) {
// TODO proper encoding required
// lets replace any dodgy characters
return META_INF_PREFIX + uri.replaceAll("://", "/").replace(':', '/').replace(' ', '_');
}
/**
* Creates the old URI for backwards compatibility
*/
public static String createDiscoveryOldPathName(String uri) {
// TODO proper encoding required
// lets replace any dodgy characters
return OLD_META_INF_PREFIX + uri.replaceAll("://", "/").replace(':', '/').replace(' ', '_');
}
public static boolean isEmpty(String uri) {
return uri == null || uri.length() == 0;
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/QNameHelper.java 0000644 0001750 0001750 00000014705 10576177725 031475 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.TypedStringValue;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.ManagedList;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import javax.xml.namespace.QName;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.List;
/**
*
* @version $Revision: 1.1 $
*/
public class QNameHelper {
private static final Log log = LogFactory.getLog(QNameHelper.class);
public static QName createQName(Element element, String qualifiedName) {
int index = qualifiedName.indexOf(':');
if (index >= 0) {
String prefix = qualifiedName.substring(0, index);
String localName = qualifiedName.substring(index + 1);
String uri = recursiveGetAttributeValue(element, "xmlns:" + prefix);
return new QName(uri, localName, prefix);
}
else {
String uri = recursiveGetAttributeValue(element, "xmlns");
if (uri != null) {
return new QName(uri, qualifiedName);
}
return new QName(qualifiedName);
}
}
/**
* Recursive method to find a given attribute value
*/
public static String recursiveGetAttributeValue(Element element, String attributeName) {
String answer = null;
try {
answer = element.getAttribute(attributeName);
}
catch (Exception e) {
if (log.isTraceEnabled()) {
log.trace("Caught exception looking up attribute: " + attributeName + " on element: " + element + ". Cause: " + e, e);
}
}
if (answer == null || answer.length() == 0) {
Node parentNode = element.getParentNode();
if (parentNode instanceof Element) {
return recursiveGetAttributeValue((Element) parentNode, attributeName);
}
}
return answer;
}
public static void coerceQNamePropertyValues(QNameReflectionParams params) {
coerceNamespaceAwarePropertyValues(params.getBeanDefinition(), params.getElement(), params.getDescriptors(), params.getIndex());
}
public static void coerceNamespaceAwarePropertyValues(AbstractBeanDefinition bd, Element element, PropertyDescriptor[] descriptors, int i) {
PropertyDescriptor descriptor = descriptors[i];
// When the property is an indexed property, the getPropertyType can return null.
if (descriptor.getPropertyType() == null) {
return;
}
if (descriptor.getPropertyType().isAssignableFrom(QName.class)) {
String name = descriptor.getName();
MutablePropertyValues propertyValues = bd.getPropertyValues();
PropertyValue propertyValue = propertyValues.getPropertyValue(name);
if (propertyValue != null) {
Object value = propertyValue.getValue();
if (value instanceof String) {
propertyValues.removePropertyValue(propertyValue);
addPropertyValue(propertyValues, name, createQName(element, (String) value));
} else if (value instanceof TypedStringValue) {
propertyValues.removePropertyValue(propertyValue);
addPropertyValue(propertyValues, name, createQName(element, ((TypedStringValue) value).getValue()));
}
}
} else if (descriptor.getPropertyType().isAssignableFrom(QName[].class)) {
String name = descriptor.getName();
MutablePropertyValues propertyValues = bd.getPropertyValues();
PropertyValue propertyValue = propertyValues.getPropertyValue(name);
if (propertyValue != null) {
Object value = propertyValue.getValue();
if (value instanceof List) {
List values = (List) value;
List newValues = new ManagedList();
for (Iterator iter = values.iterator(); iter.hasNext();) {
Object v = iter.next();
if (v instanceof String) {
newValues.add(createQName(element, (String) v));
} else {
newValues.add(v);
}
}
propertyValues.removePropertyValue(propertyValue);
propertyValues.addPropertyValue(name, newValues);
}
}
}
}
// Fix Spring 1.2.6 to 1.2.7 binary incompatibility.
// The addPropertyValueMethod has changed to return a
// value instead of void.
// So use reflectiom to handle both cases.
private static final Method addPropertyValueMethod;
static {
try {
addPropertyValueMethod = MutablePropertyValues.class.getMethod(
"addPropertyValue",
new Class[] { String.class, Object.class });
} catch (Exception e) {
throw new RuntimeException("Unable to find MutablePropertyValues:addPropertyValue", e);
}
}
public static void addPropertyValue(MutablePropertyValues values, String name, Object value) {
try {
addPropertyValueMethod.invoke(values, new Object[] { name, value });
} catch (Exception e) {
throw new RuntimeException("Error adding property definition", e);
}
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/XBeanHelper.java 0000644 0001750 0001750 00000004467 10473277125 031464 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import java.lang.reflect.Constructor;
import java.util.List;
import org.apache.xbean.spring.context.SpringApplicationContext;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
public class XBeanHelper {
public static XmlBeanDefinitionReader createBeanDefinitionReader(
SpringApplicationContext applicationContext,
BeanDefinitionRegistry registry,
List xmlPreprocessors) {
String version = "2.0";
try {
Class spring20Clazz = Class.forName("org.springframework.core.AttributeAccessorSupport");
version = "2.0";
} catch(ClassNotFoundException e) {
version = "1.2.8";
}
String className = "org.apache.xbean.spring.context.v" + version.charAt(0) + ".XBeanXmlBeanDefinitionReader";
try {
Class cl = Class.forName(className);
Constructor cstr = cl.getConstructor(new Class[] { SpringApplicationContext.class, BeanDefinitionRegistry.class, List.class });
return (XmlBeanDefinitionReader) cstr.newInstance(new Object[] { applicationContext, registry, xmlPreprocessors });
} catch (Exception e) {
throw (IllegalStateException) new IllegalStateException("Could not find valid implementation for: " + version).initCause(e);
}
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/DateEditor.java 0000644 0001750 0001750 00000003071 10473600341 031327 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import java.beans.PropertyEditorSupport;
import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;
/**
* Editor for java.util.Date
*/
public class DateEditor extends PropertyEditorSupport {
private DateFormat dateFormat = DateFormat.getInstance();
public void setAsText(String text) throws IllegalArgumentException {
try {
setValue(dateFormat.parse(text));
}
catch (ParseException e) {
throw new IllegalArgumentException(
"Could not convert Date for " + text + ": " + e.getMessage());
}
}
public String getAsText() {
Date value = (Date) getValue();
return (value != null ? dateFormat.format(value) : "");
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/QNameReflectionParams.java0000644 0001750 0001750 00000003472 10473277125 033502 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.w3c.dom.Element;
import java.beans.PropertyDescriptor;
/**
*
* @version $Revision: 1.1 $
*/
public class QNameReflectionParams {
private final AbstractBeanDefinition beanDefinition;
private final Element element;
private final PropertyDescriptor[] descriptors;
private final int index;
public QNameReflectionParams(AbstractBeanDefinition beanDefinition, Element element,
PropertyDescriptor[] descriptors, int index) {
this.beanDefinition = beanDefinition;
this.element = element;
this.descriptors = descriptors;
this.index = index;
}
public AbstractBeanDefinition getBeanDefinition() {
return beanDefinition;
}
public PropertyDescriptor[] getDescriptors() {
return descriptors;
}
public Element getElement() {
return element;
}
public int getIndex() {
return index;
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/ObjectNameEditor.java 0000644 0001750 0001750 00000003037 10473277125 032475 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import java.beans.PropertyEditorSupport;
/**
* Editor for java.net.URI
*/
public class ObjectNameEditor extends PropertyEditorSupport {
public void setAsText(String text) throws IllegalArgumentException {
try {
setValue(new ObjectName(text));
}
catch (MalformedObjectNameException e) {
throw new IllegalArgumentException("Could not convert ObjectName for " + text + ": " + e.getMessage());
}
}
public String getAsText() {
ObjectName value = (ObjectName) getValue();
return (value != null ? value.toString() : "");
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/QNameReflectionHelper.java0000644 0001750 0001750 00000006432 10473277125 033475 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import org.springframework.beans.factory.BeanDefinitionStoreException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.w3c.dom.Element;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
/**
* To avoid a runtime dependency on the QName class lets use reflection to
* process QName instances.
*
* @version $Revision: 1.1 $
*/
public class QNameReflectionHelper {
protected static Method coerceMethod;
protected static Method createMethod;
public static void coerceNamespaceAwarePropertyValues(AbstractBeanDefinition beanDefinition, Element element,
PropertyDescriptor[] descriptors, int index) {
QNameReflectionParams params = new QNameReflectionParams(beanDefinition, element, descriptors, index);
if (coerceMethod == null) {
coerceMethod = findMethod("coerceQNamePropertyValues");
}
if (coerceMethod != null) {
try {
coerceMethod.invoke(null, new Object[] { params });
}
catch (Exception e) {
throw new BeanDefinitionStoreException("Failed to invoke method: " + coerceMethod + " via reflection: " + e,
e);
}
}
}
public static Object createQName(Element element, String text) {
if (createMethod == null) {
createMethod = findMethod("createQName");
}
if (createMethod != null) {
try {
return createMethod.invoke(null, new Object[] { element, text });
}
catch (Exception e) {
throw new BeanDefinitionStoreException("Failed to invoke method: " + createMethod + " via reflection: " + e,
e);
}
}
return null;
}
protected static Method findMethod(String name) {
try {
Class type = PropertyEditorHelper.loadClass("org.apache.xbean.spring.context.impl.QNameHelper");
if (type != null) {
Method[] methods = type.getMethods();
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals(name)) {
return method;
}
}
}
} catch (Throwable t) {
// Ignore, this is usually because QName method is not in the classpath
}
return null;
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/NamedConstructorArgs.java 0000644 0001750 0001750 00000035246 10473277125 033435 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import org.springframework.beans.BeansException;
import org.springframework.beans.FatalBeanException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* NamedConstructorArgs is a BeanFactoryPostProcessor that converts property declarations into indexed constructor args
* based on the the constructor parameter names annotation. This process first selects a constructor and then fills in
* the constructor arguments from the properties defined in the bean definition. If a property is not defined in the
* bean definition, first the defaultValues map is checked for a value and if a value is not present a Java default
* value is provided for the constructor argument (e.g. numbers are assigned 0 and objects are assigned null).
*
* @author Dain Sundstrom
* @version $Id$
* @since 2.0
*/
public class NamedConstructorArgs {
private Map defaultValues = new HashMap();
/**
* Gets the default values that are assigned to constructor arguments without a defined value.
* @return the default values that are assigned to constructor arguments without a defined value
*/
public List getDefaultValues() {
List values = new LinkedList();
for (Iterator iterator = defaultValues.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
PropertyKey key = (PropertyKey) entry.getKey();
Object value = entry.getValue();
values.add(new DefaultProperty(key.name, key.type, value));
}
return values;
}
/**
* Sets the default values that are assigned to constructor arguments without a defined value.
* @param defaultValues the values that are assigned to constructor arguments without a defined value
*/
public void setDefaultValues(List defaultValues) {
this.defaultValues.clear();
for (Iterator iterator = defaultValues.iterator(); iterator.hasNext();) {
addDefaultValue((DefaultProperty) iterator.next());
}
}
/**
* Adds a default value for a property with the specified name and type.
* @param name the name of the property
* @param type the type of the property
* @param value the default value for a property with the specified name and type
*/
public void addDefaultValue(String name, Class type, Object value) {
defaultValues.put(new PropertyKey(name, type), value);
}
/**
* Adds a defautl value for a property.
* @param defaultProperty the default property information
*/
private void addDefaultValue(DefaultProperty defaultProperty) {
defaultValues.put(new PropertyKey(defaultProperty.getName(), defaultProperty.getType()), defaultProperty.getValue());
}
public void processParameters(BeanDefinitionHolder definitionHolder, MappingMetaData metadata) throws BeansException {
// this only works if we have an abstsract bean definition
if (!(definitionHolder.getBeanDefinition() instanceof AbstractBeanDefinition)) {
return;
}
AbstractBeanDefinition beanDefinition = (AbstractBeanDefinition) definitionHolder.getBeanDefinition();
ConstructorArgumentValues constructorArgumentValues = beanDefinition.getConstructorArgumentValues();
// if this bean already has constructor arguments defined, don't mess with them
if (constructorArgumentValues.getArgumentCount() > 0) {
return;
}
// try to get a list of constructor arg names to use
ConstructionInfo constructionInfo = selectConstructionMethod(beanDefinition, metadata);
if (constructionInfo == null) {
return;
}
// remove each named property and add an indexed constructor arg
MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
String[] parameterNames = constructionInfo.parameterNames;
Class[] parameterTypes = constructionInfo.parameterTypes;
for (int i = 0; i < parameterNames.length; i++) {
String parameterName = parameterNames[i];
Class parameterType = parameterTypes[i];
PropertyValue propertyValue = propertyValues.getPropertyValue(parameterName);
if (propertyValue != null) {
propertyValues.removePropertyValue(parameterName);
constructorArgumentValues.addIndexedArgumentValue(i, propertyValue.getValue(), parameterType.getName());
} else {
Object defaultValue = defaultValues.get(new PropertyKey(parameterName, parameterType));
if (defaultValue == null) {
defaultValue = DEFAULT_VALUE.get(parameterType);
}
if (defaultValue instanceof FactoryBean) {
try {
defaultValue = ((FactoryBean)defaultValue).getObject();
} catch (Exception e) {
throw new FatalBeanException("Unable to get object value from bean factory", e);
}
}
constructorArgumentValues.addIndexedArgumentValue(i, defaultValue, parameterType.getName());
}
}
// todo set any usable default values on the bean definition
}
private ConstructionInfo selectConstructionMethod(AbstractBeanDefinition beanDefinition, MappingMetaData metadata) {
Class beanClass = beanDefinition.getBeanClass();
// get a set containing the names of the defined properties
Set definedProperties = new HashSet();
PropertyValue[] values = beanDefinition.getPropertyValues().getPropertyValues();
for (int i = 0; i < values.length; i++) {
definedProperties.add(values[i].getName());
}
// first check for a factory method
if (beanDefinition.getFactoryMethodName() != null) {
return selectFactory(beanClass, beanDefinition, metadata, definedProperties);
} else {
return selectConstructor(beanClass, metadata, definedProperties);
}
}
private ConstructionInfo selectFactory(Class beanClass, AbstractBeanDefinition beanDefinition, MappingMetaData metadata, Set definedProperties) {
String factoryMethodName = beanDefinition.getFactoryMethodName();
// get the factory methods sorted by longest arg length first
Method[] methods = beanClass.getMethods();
List factoryMethods = new ArrayList(methods.length);
for (int i = 0; i < methods.length; i++) {
Method method = methods[i];
if (method.getName().equals(factoryMethodName)) {
factoryMethods.add(method);
}
}
Collections.sort(factoryMethods, new ArgLengthComparator());
// if a factory method has been annotated as the default constructor we always use that constructor
for (Iterator iterator = factoryMethods.iterator(); iterator.hasNext();) {
Method factoryMethod = (Method) iterator.next();
if (metadata.isDefaultFactoryMethod(beanClass, factoryMethod)) {
return new ConstructionInfo(beanClass, factoryMethod, metadata);
}
}
// try to find a constructor for which we have all of the properties defined
for (Iterator iterator = factoryMethods.iterator(); iterator.hasNext();) {
Method factoryMethod = (Method) iterator.next();
ConstructionInfo constructionInfo = new ConstructionInfo(beanClass, factoryMethod, metadata);
if (isUsableConstructor(constructionInfo, definedProperties)) {
return constructionInfo;
}
}
return null;
}
private ConstructionInfo selectConstructor(Class beanClass, MappingMetaData metadata, Set definedProperties) {
// get the constructors sorted by longest arg length first
List constructors = new ArrayList(Arrays.asList(beanClass.getConstructors()));
Collections.sort(constructors, new ArgLengthComparator());
// if a constructor has been annotated as the default constructor we always use that constructor
for (Iterator iterator = constructors.iterator(); iterator.hasNext();) {
Constructor constructor = (Constructor) iterator.next();
if (metadata.isDefaultConstructor(constructor)) {
return new ConstructionInfo(constructor, metadata);
}
}
// try to find a constructor for which we have all of the properties defined
for (Iterator iterator = constructors.iterator(); iterator.hasNext();) {
Constructor constructor = (Constructor) iterator.next();
ConstructionInfo constructionInfo = new ConstructionInfo(constructor, metadata);
if (isUsableConstructor(constructionInfo, definedProperties)) {
return constructionInfo;
}
}
return null;
}
private boolean isUsableConstructor(ConstructionInfo constructionInfo, Set definedProperties) {
// if we don't have parameter names this is not the constructor we are looking for
String[] parameterNames = constructionInfo.parameterNames;
if (parameterNames == null) {
return false;
}
Class[] parameterTypes = constructionInfo.parameterTypes;
for (int i = 0; i < parameterNames.length; i++) {
String parameterName = parameterNames[i];
Class parameterType = parameterTypes[i];
// can we satify this property using a defined property or default property
if (!definedProperties.contains(parameterName) && !defaultValues.containsKey(new PropertyKey(parameterName, parameterType))) {
return false;
}
}
return true;
}
private class ConstructionInfo {
private final Class[] parameterTypes;
private final String[] parameterNames;
public ConstructionInfo(Constructor constructor, MappingMetaData metadata) {
this.parameterTypes = constructor.getParameterTypes();
String[] names = metadata.getParameterNames(constructor);
// verify that we have enough parameter names
int expectedParameterCount = parameterTypes.length;
if (names != null && names.length != expectedParameterCount) {
throw new FatalBeanException("Excpected " + expectedParameterCount + " parameter names for constructor but only got " +
names.length + ": " + constructor.toString());
}
if (expectedParameterCount == 0) {
names = new String[0];
}
this.parameterNames = names;
}
public ConstructionInfo(Class beanClass, Method factoryMethod, MappingMetaData metadata) {
this.parameterTypes = factoryMethod.getParameterTypes();
String[] names = metadata.getParameterNames(beanClass, factoryMethod);
// verify that we have enough parameter names
int expectedParameterCount = parameterTypes.length;
if (names != null && names.length != expectedParameterCount) {
throw new FatalBeanException("Excpected " + expectedParameterCount + " parameter names for factory method but only got " +
names.length + ": " + factoryMethod.toString());
}
if (expectedParameterCount == 0) {
names = new String[0];
}
this.parameterNames = names;
}
}
private static class ArgLengthComparator implements Comparator {
public int compare(Object o1, Object o2) {
return getArgLength(o2) - getArgLength(o1);
}
private int getArgLength(Object object) {
if (object instanceof Method) {
return ((Method) object).getParameterTypes().length;
} else {
return ((Constructor) object).getParameterTypes().length;
}
}
}
private static class PropertyKey {
private final String name;
private final Class type;
public PropertyKey(String name, Class type) {
this.name = name;
this.type = type;
}
public boolean equals(Object object) {
if (!(object instanceof PropertyKey)) {
return false;
}
PropertyKey defaultProperty = (PropertyKey) object;
return name.equals(defaultProperty.name) && type.equals(type);
}
public int hashCode() {
int result = 17;
result = 37 * result + name.hashCode();
result = 37 * result + type.hashCode();
return result;
}
public String toString() {
return "[" + name + " " + type + "]";
}
}
private static final Map DEFAULT_VALUE;
static {
Map temp = new HashMap();
temp.put(Boolean.TYPE, Boolean.FALSE);
temp.put(Byte.TYPE, new Byte((byte) 0));
temp.put(Character.TYPE, new Character((char) 0));
temp.put(Short.TYPE, new Short((short) 0));
temp.put(Integer.TYPE, new Integer(0));
temp.put(Long.TYPE, new Long(0));
temp.put(Float.TYPE, new Float(0));
temp.put(Double.TYPE, new Double(0));
DEFAULT_VALUE = Collections.unmodifiableMap(temp);
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/impl/PropertyEditorHelper.java 0000644 0001750 0001750 00000006226 10761616442 033454 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.beans.PropertyEditorManager;
/**
* A helper method to register some custom editors
*
* @version $Revision: 1.1 $
*/
public class PropertyEditorHelper {
private static final Log log = LogFactory.getLog(PropertyEditorHelper.class);
public static void registerCustomEditors() {
registerEditor("java.io.File", "org.apache.xbean.spring.context.impl.FileEditor");
registerEditor("java.net.URI", "org.apache.xbean.spring.context.impl.URIEditor");
registerEditor("java.util.Date", "org.apache.xbean.spring.context.impl.DateEditor");
registerEditor("javax.management.ObjectName", "org.apache.xbean.spring.context.impl.ObjectNameEditor");
}
protected static void registerEditor(String typeName, String editorName) {
Class type = loadClass(typeName);
Class editor = loadClass(editorName);
if (type != null && editor != null) {
PropertyEditorManager.registerEditor(type, editor);
}
}
public static void unregisterCustomEditors() {
unregisterEditor("java.io.File");
unregisterEditor("java.net.URI");
unregisterEditor("java.util.Date");
unregisterEditor("javax.management.ObjectName");
}
protected static void unregisterEditor(String typeName) {
Class type = loadClass(typeName);
if (type != null) {
PropertyEditorManager.registerEditor(type, null);
}
}
public static Class loadClass(String name) {
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
if (contextClassLoader != null) {
try {
return contextClassLoader.loadClass(name);
}
catch (ClassNotFoundException e) {
}
catch (NoClassDefFoundError e) {
}
}
try {
return PropertyEditorHelper.class.getClassLoader().loadClass(name);
}
catch (ClassNotFoundException e) {
log.debug("Could not find class: " + name + " on the classpath");
return null;
}
catch (NoClassDefFoundError e) {
log.debug("Could not load class: " + name + " on the classpath. " + e.getMessage());
return null;
}
}
}
././@LongLink 0000000 0000000 0000000 00000000150 00000000000 011561 L ustar root root xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/ResourceXmlApplicationContext.java xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/ResourceXmlApplicationContext.j0000644 0001750 0001750 00000011674 10477627651 033704 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context;
import java.io.IOException;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import org.apache.xbean.spring.context.impl.XBeanHelper;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.ResourceEntityResolver;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.core.io.Resource;
/**
* An XBean version of a regular Spring ApplicationContext which takes a
* {@link Resource} as a parameter to load the application context
*
* @author James Strachan
* @author Dain Sundstrom
* @version $Id$
* @since 2.0
*/
public class ResourceXmlApplicationContext extends AbstractXmlApplicationContext implements SpringApplicationContext {
private final List xmlPreprocessors;
private final Resource resource;
/**
* Creates a ResourceXmlApplicationContext which loads the configuration from the specified Resource.
* @param resource the resource from which the configuration is loaded
*/
public ResourceXmlApplicationContext(Resource resource) {
this(resource, Collections.EMPTY_LIST);
}
/**
* Creates a ResourceXmlApplicationContext which loads the configuration from the specified Resource.
* @param resource the resource from which the configuration is loaded
* @param xmlPreprocessors the SpringXmlPreprocessors to apply before passing the xml to Spring for processing
*/
public ResourceXmlApplicationContext(Resource resource, List xmlPreprocessors) {
super();
this.xmlPreprocessors = xmlPreprocessors;
this.resource = resource;
refresh();
}
public ResourceXmlApplicationContext(Resource resource, ApplicationContext parent) {
this(resource, Collections.EMPTY_LIST, parent);
}
public ResourceXmlApplicationContext(Resource resource, List xmlPreprocessors, ApplicationContext parent) {
this(resource, xmlPreprocessors, parent, Collections.EMPTY_LIST);
}
public ResourceXmlApplicationContext(Resource resource, List xmlPreprocessors, ApplicationContext parent, List beanPostProcessors) {
this(resource, xmlPreprocessors, parent, beanPostProcessors, true);
}
public ResourceXmlApplicationContext(Resource resource, List xmlPreprocessors, ApplicationContext parent, List beanPostProcessors, boolean refresh) {
super(parent);
this.xmlPreprocessors = xmlPreprocessors;
this.resource = resource;
for (Iterator iter = beanPostProcessors.iterator(); iter.hasNext();) {
BeanFactoryPostProcessor processor = (BeanFactoryPostProcessor) iter.next();
addBeanFactoryPostProcessor(processor);
}
if (refresh) {
refresh();
}
}
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException {
// Create a new XmlBeanDefinitionReader for the given BeanFactory.
XmlBeanDefinitionReader beanDefinitionReader = XBeanHelper.createBeanDefinitionReader(this, beanFactory, xmlPreprocessors);
// Configure the bean definition reader with this context's
// resource loading environment.
beanDefinitionReader.setResourceLoader(this);
beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
// Allow a subclass to provide custom initialization of the reader,
// then proceed with actually loading the bean definitions.
initBeanDefinitionReader(beanDefinitionReader);
loadBeanDefinitions(beanDefinitionReader);
}
/**
* {@inheritDoc}
*/
protected void loadBeanDefinitions(XmlBeanDefinitionReader reader) throws BeansException, IOException {
reader.loadBeanDefinitions(resource);
}
/**
* {@inheritDoc}
*/
protected String[] getConfigLocations() {
return null;
}
}
././@LongLink 0000000 0000000 0000000 00000000151 00000000000 011562 L ustar root root xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/ClassPathXmlApplicationContext.java xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/ClassPathXmlApplicationContext.0000644 0001750 0001750 00000022157 10473277125 033614 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.Collections;
import java.util.List;
import org.apache.xbean.spring.context.impl.XBeanHelper;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.ResourceEntityResolver;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.ApplicationContext;
import org.springframework.core.SpringVersion;
/**
* An XBean version of the regular Spring class to provide improved XML handling.
*
* @author James Strachan
* @author Dain Sundstrom
* @version $Id$
* @since 2.0
*/
public class ClassPathXmlApplicationContext extends org.springframework.context.support.ClassPathXmlApplicationContext implements SpringApplicationContext {
private final List xmlPreprocessors;
/**
* Creates a ClassPathXmlApplicationContext which loads the configuration at the specified location on the class
* path.
* @param configLocation the location of the configuration file on the class path
* @throws BeansException if a problem occurs while reading the configuration
*/
public ClassPathXmlApplicationContext(String configLocation) throws BeansException {
this(new String[] {configLocation}, true, null, Collections.EMPTY_LIST);
}
/**
* Creates a ClassPathXmlApplicationContext which loads the configuration at the specified locations on the class
* path.
* @param configLocations the locations of the configuration files on the class path
* @throws BeansException if a problem occurs while reading the configuration
*/
public ClassPathXmlApplicationContext(String[] configLocations) throws BeansException {
this(configLocations, true, null, Collections.EMPTY_LIST);
}
/**
* Creates a ClassPathXmlApplicationContext which loads the configuration at the specified locations on the class
* path.
* @param configLocations the locations of the configuration files on the class path
* @param refresh if true the configurations are immedately loaded; otherwise the configurations are not loaded
* until refresh() is called
* @throws BeansException if a problem occurs while reading the configuration
*/
public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh) throws BeansException {
this(configLocations, refresh, null, Collections.EMPTY_LIST);
}
/**
* Creates a ClassPathXmlApplicationContext which loads the configuration at the specified locations on the class
* path.
* @param configLocations the locations of the configuration files on the class path
* @param parent the parent of this application context
* @throws BeansException if a problem occurs while reading the configuration
*/
public ClassPathXmlApplicationContext(String[] configLocations, ApplicationContext parent) throws BeansException {
this(configLocations, true, parent, Collections.EMPTY_LIST);
}
/**
* Creates a ClassPathXmlApplicationContext which loads the configuration at the specified locations on the class
* path.
* @param configLocations the locations of the configuration files on the class path
* @param refresh if true the configurations are immedately loaded; otherwise the configurations are not loaded
* until refresh() is called
* @param parent the parent of this application context
* @throws BeansException if a problem occurs while reading the configuration
*/
public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent) throws BeansException {
this(configLocations, refresh, parent, Collections.EMPTY_LIST);
}
/**
* Creates a ClassPathXmlApplicationContext which loads the configuration at the specified location on the class
* path.
* @param configLocation the location of the configuration file on the classpath
* @param xmlPreprocessors the SpringXmlPreprocessors to apply before passing the xml to Spring for processing
* @throws BeansException if a problem occurs while reading the configuration
*/
public ClassPathXmlApplicationContext(String configLocation, List xmlPreprocessors) throws BeansException {
this(new String[] {configLocation}, true, null, xmlPreprocessors);
}
/**
* Creates a ClassPathXmlApplicationContext which loads the configuration at the specified locations on the class
* path.
* @param configLocations the locations of the configuration files on the class path
* @param xmlPreprocessors the SpringXmlPreprocessors to apply before passing the xml to Spring for processing
* @throws BeansException if a problem occurs while reading the configuration
*/
public ClassPathXmlApplicationContext(String[] configLocations, List xmlPreprocessors) throws BeansException {
this(configLocations, true, null, xmlPreprocessors);
}
/**
* Creates a ClassPathXmlApplicationContext which loads the configuration at the specified locations on the class
* path.
* @param configLocations the locations of the configuration files on the class path
* @param refresh if true the configurations are immedately loaded; otherwise the configurations are not loaded
* until refresh() is called
* @param xmlPreprocessors the SpringXmlPreprocessors to apply before passing the xml to Spring for processing
* @throws BeansException if a problem occurs while reading the configuration
*/
public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, List xmlPreprocessors) throws BeansException {
this(configLocations, refresh, null, xmlPreprocessors);
}
/**
* Creates a ClassPathXmlApplicationContext which loads the configuration at the specified locations on the class
* path.
* @param configLocations the locations of the configuration files on the class path
* @param parent the parent of this application context
* @param xmlPreprocessors the SpringXmlPreprocessors to apply before passing the xml to Spring for processing
* @throws BeansException if a problem occurs while reading the configuration
*/
public ClassPathXmlApplicationContext(String[] configLocations, ApplicationContext parent, List xmlPreprocessors) throws BeansException {
this(configLocations, true, parent, xmlPreprocessors);
}
/**
* Creates a ClassPathXmlApplicationContext which loads the configuration at the specified locations on the class
* path.
* @param configLocations the locations of the configuration files on the class path
* @param refresh if true the configurations are immedately loaded; otherwise the configurations are not loaded
* until refresh() is called
* @param parent the parent of this application context
* @param xmlPreprocessors the SpringXmlPreprocessors to apply before passing the xml to Spring for processing
* @throws BeansException if a problem occurs while reading the configuration
*/
public ClassPathXmlApplicationContext(String[] configLocations, boolean refresh, ApplicationContext parent, List xmlPreprocessors) throws BeansException {
super(configLocations, false, parent);
this.xmlPreprocessors = xmlPreprocessors;
if (refresh) {
refresh();
}
}
/**
* {@inheritDoc}
*/
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException {
// Create a new XmlBeanDefinitionReader for the given BeanFactory.
XmlBeanDefinitionReader beanDefinitionReader = XBeanHelper.createBeanDefinitionReader(this, beanFactory, xmlPreprocessors);
// Configure the bean definition reader with this context's
// resource loading environment.
beanDefinitionReader.setResourceLoader(this);
beanDefinitionReader.setEntityResolver(new ResourceEntityResolver(this));
// Allow a subclass to provide custom initialization of the reader,
// then proceed with actually loading the bean definitions.
initBeanDefinitionReader(beanDefinitionReader);
loadBeanDefinitions(beanDefinitionReader);
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/context/SpringApplicationContext.java 0000644 0001750 0001750 00000006031 10473277125 033346 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.context;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.ResourceLoader;
import java.util.List;
/**
* SpringApplicationContext is an interface that defines the actual interface exposed by the application contexts
* provided by Spring. This interface should be in Spring and the Spring application contexts should implement this
* interface.
*
* @author Dain Sundstrom
* @version $Id$
* @since 2.0
*/
public interface SpringApplicationContext extends ConfigurableApplicationContext, DisposableBean, ResourceLoader{
/**
* Set a friendly name for this context.
* Typically done during initialization of concrete context implementations.
* @param displayName the display name for the context
*/
void setDisplayName(String displayName);
/**
* Gets the list of BeanPostProcessors that will get applied
* to beans created with this factory.
* @return the list of BeanPostProcessors that will get applied
* to beans created with this factory
*/
List getBeanFactoryPostProcessors();
/**
* Specify the ClassLoader to load class path resources with,
* or null
if using the thread context class loader on actual access
* (applying to the thread that does ClassPathResource calls).
* The default is that ClassLoader access will happen via the thread
* context class loader on actual access (applying to the thread that
* does ClassPathResource calls).
* @param classLoader the ClassLoader to load class path resources
*/
void setClassLoader(ClassLoader classLoader);
/**
* Return the ClassLoader to load class path resources with,
* or null
if using the thread context class loader on actual access
* (applying to the thread that does ClassPathResource calls).
*
Will get passed to ClassPathResource's constructor for all
* ClassPathResource objects created by this resource loader.
*
* @return the ClassLoader to load class path resources
* @see ClassPathResource
*/
ClassLoader getClassLoader();
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/util/ 0000755 0001750 0001750 00000000000 11610661036 024771 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/util/AbstractSpringVisitor.java 0000644 0001750 0001750 00000014415 10473277125 032157 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.util;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
/**
* Default do nothing implementation of SpringVisitor.
* @author Dain Sundstrom
* @version $Id$
* @since 2.0
*/
public abstract class AbstractSpringVisitor implements SpringVisitor {
public void visitBeanFactory(ConfigurableListableBeanFactory beanRegistry, Object data) throws BeansException {
String[] beanNames = beanRegistry.getBeanDefinitionNames();
for (int i = 0; i < beanNames.length; i++) {
String beanName = beanNames[i];
visitBeanDefinition(beanName, beanRegistry.getBeanDefinition(beanName), data);
}
}
public void visitBeanDefinitionHolder(BeanDefinitionHolder beanDefinitionHolder, Object data) throws BeansException {
visitBeanDefinition(beanDefinitionHolder.getBeanName(), beanDefinitionHolder.getBeanDefinition(), data);
}
public void visitBeanDefinition(String beanName, BeanDefinition beanDefinition, Object data) throws BeansException {
visitBeanDefinition(beanDefinition, data);
}
public void visitBeanDefinition(BeanDefinition beanDefinition, Object data) throws BeansException {
visitConstructorArgumentValues(beanDefinition.getConstructorArgumentValues(), data);
visitMutablePropertyValues(beanDefinition.getPropertyValues(), data);
}
public void visitMutablePropertyValues(MutablePropertyValues propertyValues, Object data) throws BeansException {
PropertyValue[] values = propertyValues.getPropertyValues();
for (int i = 0; i < values.length; i++) {
visitPropertyValue(values[i], data);
}
}
public void visitConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues, Object data) throws BeansException {
Map indexedArgumentValues = constructorArgumentValues.getIndexedArgumentValues();
for (Iterator iterator = indexedArgumentValues.values().iterator(); iterator.hasNext();) {
visitConstructorArgumentValue((ConstructorArgumentValues.ValueHolder) iterator.next(), data);
}
List genericArgumentValues = constructorArgumentValues.getGenericArgumentValues();
for (Iterator iterator = genericArgumentValues.iterator(); iterator.hasNext();) {
visitConstructorArgumentValue((ConstructorArgumentValues.ValueHolder) iterator.next(), data);
}
}
public void visitConstructorArgumentValue(ConstructorArgumentValues.ValueHolder valueHolder, Object data) throws BeansException {
visitNext(valueHolder.getValue(), data);
}
public void visitPropertyValue(PropertyValue propertyValue, Object data) throws BeansException {
visitNext(propertyValue.getValue(), data);
}
public void visitRuntimeBeanReference(RuntimeBeanReference beanReference, Object data) throws BeansException {
}
public void visitCollection(Collection collection, Object data) throws BeansException {
for (Iterator iterator = collection.iterator(); iterator.hasNext();) {
visitNext(iterator.next(), data);
}
}
public void visitMap(Map map, Object data) throws BeansException {
for (Iterator iterator = map.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
visitNext(entry.getKey(), data);
visitNext(entry.getValue(), data);
}
}
public void visitObject(Object value, Object data) throws BeansException {
}
protected void visitNext(Object value, Object data) throws BeansException {
if (value == null) {
return;
}
if (value instanceof ConfigurableListableBeanFactory) {
visitBeanFactory((ConfigurableListableBeanFactory) value, data);
} else if (value instanceof BeanDefinitionHolder) {
visitBeanDefinitionHolder((BeanDefinitionHolder) value, data);
} else if (value instanceof BeanDefinition) {
visitBeanDefinition((BeanDefinition) value, data);
} else if (value instanceof ConstructorArgumentValues) {
visitConstructorArgumentValues((ConstructorArgumentValues) value, data);
} else if (value instanceof ConstructorArgumentValues.ValueHolder) {
visitConstructorArgumentValue((ConstructorArgumentValues.ValueHolder) value, data);
} else if (value instanceof MutablePropertyValues) {
visitMutablePropertyValues((MutablePropertyValues) value, data);
} else if (value instanceof PropertyValue) {
visitPropertyValue((PropertyValue) value, data);
} else if (value instanceof RuntimeBeanReference) {
visitRuntimeBeanReference((RuntimeBeanReference) value, data);
} else if (value instanceof Map) {
visitMap((Map) value, data);
} else if (value instanceof Collection) {
visitCollection((Collection) value, data);
} else {
visitObject(value, data);
}
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/util/SpringVisitor.java 0000644 0001750 0001750 00000005325 10473277125 030473 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.util;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanDefinitionHolder;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.factory.config.RuntimeBeanReference;
import java.util.Collection;
import java.util.Map;
/**
* Walks a spring bean factory tree.
* @author Dain Sundstrom
* @version $Id$
* @since 2.0
*/
public interface SpringVisitor {
void visitBeanFactory(ConfigurableListableBeanFactory beanRegistry, Object data) throws BeansException;
void visitBeanDefinition(String beanName, BeanDefinition beanDefinition, Object data) throws BeansException;
void visitBeanDefinition(BeanDefinition beanDefinition, Object data) throws BeansException;
void visitMutablePropertyValues(MutablePropertyValues propertyValues, Object data) throws BeansException;
void visitConstructorArgumentValues(ConstructorArgumentValues constructorArgumentValues, Object data) throws BeansException;
void visitConstructorArgumentValue(ConstructorArgumentValues.ValueHolder valueHolder, Object data) throws BeansException;
void visitPropertyValue(PropertyValue propertyValue, Object data) throws BeansException;
void visitRuntimeBeanReference(RuntimeBeanReference beanReference, Object data) throws BeansException;
void visitCollection(Collection collection, Object data) throws BeansException;
void visitMap(Map map, Object data) throws BeansException;
void visitObject(Object value, Object data) throws BeansException;
void visitBeanDefinitionHolder(BeanDefinitionHolder beanDefinitionHolder, Object data) throws BeansException;
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/jndi/ 0000755 0001750 0001750 00000000000 11610661036 024740 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/jndi/SpringInitialContextFactory.java 0000644 0001750 0001750 00000010037 10601307603 033251 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.jndi;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceEditor;
import org.apache.xbean.spring.context.impl.XBeanXmlBeanFactory;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.spi.InitialContextFactory;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
/**
* A simple JNDI initial context which loads the JNDI namespace from a spring.xml configuration file.
* The spring.xml configuration file can be specified by the {@link Context#PROVIDER_URL} property
* which can be any spring resource string (classpath://foo.xml, or file://foo/bar.xml or a URL)
* otherwise the jndi.xml file is found on the classpath.
*
* @version $Revision: 657 $
*/
public class SpringInitialContextFactory implements InitialContextFactory {
private static final transient Log log = LogFactory.getLog(SpringInitialContextFactory.class);
private static Map cache = new HashMap();
private static Context singleton;
/**
* A factory method which can be used to initialise a singleton JNDI context from inside a Spring.xml
* such that future calls to new InitialContext() will reuse it
*/
public static Context makeInitialContext() {
singleton = new DefaultContext();
return singleton;
}
public Context getInitialContext(Hashtable environment) throws NamingException {
if (singleton != null) {
return singleton;
}
Resource resource = null;
Object value = environment.get(Context.PROVIDER_URL);
String key = "jndi.xml";
if (value == null) {
resource = new ClassPathResource(key);
}
else {
if (value instanceof Resource) {
resource = (Resource) value;
}
else {
ResourceEditor editor = new ResourceEditor();
key = value.toString();
editor.setAsText(key);
resource = (Resource) editor.getValue();
}
}
BeanFactory context = loadContext(resource, key);
Context answer = (Context) context.getBean("jndi");
if (answer == null) {
log.warn("No JNDI context available in JNDI resource: " + resource);
answer = new DefaultContext(environment, new ConcurrentHashMap());
}
return answer;
}
protected BeanFactory loadContext(Resource resource, String key) {
synchronized (cache) {
BeanFactory answer = (BeanFactory) cache.get(key);
if (answer == null) {
answer = createContext(resource);
cache.put(key, answer);
}
return answer;
}
}
protected BeanFactory createContext(Resource resource) {
log.info("Loading JNDI context from: " + resource);
return new XBeanXmlBeanFactory(resource);
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/jndi/NameParserImpl.java 0000644 0001750 0001750 00000002311 10473277125 030467 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.jndi;
import javax.naming.CompositeName;
import javax.naming.Name;
import javax.naming.NameParser;
import javax.naming.NamingException;
/**
* A default implementation of {@link NameParser}
*
* @version $Revision: 1.2 $
*/
public class NameParserImpl implements NameParser {
public Name parse(String name) throws NamingException {
return new CompositeName(name);
}
}
xbean-3.7/xbean-spring/src/main/java/org/apache/xbean/spring/jndi/DefaultContext.java 0000644 0001750 0001750 00000036311 10473277125 030550 0 ustar drazzib drazzib /**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
package org.apache.xbean.spring.jndi;
import javax.naming.Binding;
import javax.naming.CompositeName;
import javax.naming.Context;
import javax.naming.LinkRef;
import javax.naming.Name;
import javax.naming.NameClassPair;
import javax.naming.NameNotFoundException;
import javax.naming.NameParser;
import javax.naming.NamingEnumeration;
import javax.naming.NamingException;
import javax.naming.NotContextException;
import javax.naming.OperationNotSupportedException;
import javax.naming.Reference;
import javax.naming.spi.NamingManager;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
/**
* A simple spring based JNDI context which is mutable
*
* @version $Revision: 657 $
*/
public class DefaultContext implements Context, Serializable {
private static final long serialVersionUID = -5754338187296859149L;
protected static final NameParser nameParser = new NameParserImpl();
private boolean freeze = false;
protected final Hashtable environment; // environment for this context
protected final Map bindings; // bindings at my level
protected final Map treeBindings; // all bindings under me
private boolean frozen = false;
private String nameInNamespace = "";
public static final String SEPARATOR = "/";
public DefaultContext() {
environment = new Hashtable();
bindings = new HashMap();
treeBindings = new HashMap();
}
public DefaultContext(Hashtable env) {
if (env == null) {
this.environment = new Hashtable();
}
else {
this.environment = new Hashtable(env);
}
this.bindings = new HashMap();
this.treeBindings = new HashMap();
}
public DefaultContext(Hashtable environment, Map bindings) {
if (environment == null) {
this.environment = new Hashtable();
}
else {
this.environment = new Hashtable(environment);
}
this.bindings = bindings;
treeBindings = new HashMap();
frozen = true;
}
public DefaultContext(Hashtable environment, Map bindings, String nameInNamespace) {
this(environment, bindings);
this.nameInNamespace = nameInNamespace;
}
protected DefaultContext(DefaultContext clone, Hashtable env) {
this.bindings = clone.bindings;
this.treeBindings = clone.treeBindings;
this.environment = new Hashtable(env);
}
protected DefaultContext(DefaultContext clone, Hashtable env, String nameInNamespace) {
this(clone, env);
this.nameInNamespace = nameInNamespace;
}
public Object addToEnvironment(String propName, Object propVal) throws NamingException {
return environment.put(propName, propVal);
}
public Hashtable getEnvironment() throws NamingException {
return (Hashtable) environment.clone();
}
public Object removeFromEnvironment(String propName) throws NamingException {
return environment.remove(propName);
}
public Object lookup(String name) throws NamingException {
if (name.length() == 0) {
return this;
}
Object result = treeBindings.get(name);
if (result == null) {
result = bindings.get(name);
}
if (result == null) {
int pos = name.indexOf(':');
if (pos > 0) {
String scheme = name.substring(0, pos);
Context ctx = NamingManager.getURLContext(scheme, environment);
if (ctx == null) {
throw new NamingException("scheme " + scheme + " not recognized");
}
return ctx.lookup(name);
}
else {
// Split out the first name of the path
// and look for it in the bindings map.
CompositeName path = new CompositeName(name);
if (path.size() == 0) {
return this;
}
else {
String first = path.get(0);
Object obj = bindings.get(first);
if (obj == null) {
throw new NameNotFoundException(name);
}
else if (obj instanceof Context && path.size() > 1) {
Context subContext = (Context) obj;
obj = subContext.lookup(path.getSuffix(1));
}
return obj;
}
}
}
if (result instanceof LinkRef) {
LinkRef ref = (LinkRef) result;
result = lookup(ref.getLinkName());
}
if (result instanceof Reference) {
try {
result = NamingManager.getObjectInstance(result, null, null, this.environment);
}
catch (NamingException e) {
throw e;
}
catch (Exception e) {
throw (NamingException) new NamingException("could not look up : " + name).initCause(e);
}
}
if (result instanceof DefaultContext) {
String prefix = getNameInNamespace();
if (prefix.length() > 0) {
prefix = prefix + SEPARATOR;
}
result = new DefaultContext((DefaultContext) result, environment, prefix + name);
}
return result;
}
public Object lookup(Name name) throws NamingException {
return lookup(name.toString());
}
public Object lookupLink(String name) throws NamingException {
return lookup(name);
}
public Name composeName(Name name, Name prefix) throws NamingException {
Name result = (Name) prefix.clone();
result.addAll(name);
return result;
}
public String composeName(String name, String prefix) throws NamingException {
CompositeName result = new CompositeName(prefix);
result.addAll(new CompositeName(name));
return result.toString();
}
public NamingEnumeration list(String name) throws NamingException {
Object o = lookup(name);
if (o == this) {
return new DefaultContext.ListEnumeration();
}
else if (o instanceof Context) {
return ((Context) o).list("");
}
else {
throw new NotContextException();
}
}
public NamingEnumeration listBindings(String name) throws NamingException {
Object o = lookup(name);
if (o == this) {
return new DefaultContext.ListBindingEnumeration();
}
else if (o instanceof Context) {
return ((Context) o).listBindings("");
}
else {
throw new NotContextException();
}
}
public Object lookupLink(Name name) throws NamingException {
return lookupLink(name.toString());
}
public NamingEnumeration list(Name name) throws NamingException {
return list(name.toString());
}
public NamingEnumeration listBindings(Name name) throws NamingException {
return listBindings(name.toString());
}
public void bind(Name name, Object value) throws NamingException {
bind(name.toString(), value);
}
public void bind(String name, Object value) throws NamingException {
checkFrozen();
internalBind(name, value);
}
public void close() throws NamingException {
// ignore
}
public Context createSubcontext(Name name) throws NamingException {
throw new OperationNotSupportedException();
}
public Context createSubcontext(String name) throws NamingException {
throw new OperationNotSupportedException();
}
public void destroySubcontext(Name name) throws NamingException {
throw new OperationNotSupportedException();
}
public void destroySubcontext(String name) throws NamingException {
throw new OperationNotSupportedException();
}
public String getNameInNamespace() throws NamingException {
return nameInNamespace;
}
public NameParser getNameParser(Name name) throws NamingException {
return nameParser;
}
public NameParser getNameParser(String name) throws NamingException {
return nameParser;
}
public void rebind(Name name, Object value) throws NamingException {
rebind(name.toString(), value);
}
public void rebind(String name, Object value) throws NamingException {
checkFrozen();
internalBind(name, value, true);
}
public void rename(Name oldName, Name newName) throws NamingException {
checkFrozen();
Object value = lookup(oldName);
unbind(oldName);
bind(newName, value);
}
public void rename(String oldName, String newName) throws NamingException {
Object value = lookup(oldName);
unbind(oldName);
bind(newName, value);
}
public void unbind(Name name) throws NamingException {
unbind(name.toString());
}
public void unbind(String name) throws NamingException {
checkFrozen();
internalBind(name, null, true);
}
private abstract class LocalNamingEnumeration implements NamingEnumeration {
private Iterator i = bindings.entrySet().iterator();
public boolean hasMore() throws NamingException {
return i.hasNext();
}
public boolean hasMoreElements() {
return i.hasNext();
}
protected Map.Entry getNext() {
return (Map.Entry) i.next();
}
public void close() throws NamingException {
}
}
private class ListEnumeration extends DefaultContext.LocalNamingEnumeration {
public Object next() throws NamingException {
return nextElement();
}
public Object nextElement() {
Map.Entry entry = getNext();
return new NameClassPair((String) entry.getKey(), entry.getValue().getClass().getName());
}
}
private class ListBindingEnumeration extends DefaultContext.LocalNamingEnumeration {
public Object next() throws NamingException {
return nextElement();
}
public Object nextElement() {
Map.Entry entry = getNext();
return new Binding((String) entry.getKey(), entry.getValue());
}
}
public Map getEntries() {
return new HashMap(bindings);
}
public void setEntries(Map entries) throws NamingException {
if (entries != null) {
for (Iterator iter = entries.entrySet().iterator(); iter.hasNext();) {
Map.Entry entry = (Map.Entry) iter.next();
String name = (String) entry.getKey();
Object value = entry.getValue();
internalBind(name, value);
}
}
}
public boolean isFreeze() {
return freeze;
}
public void setFreeze(boolean freeze) {
this.freeze = freeze;
}
/**
* internalBind is intended for use only during setup or possibly by suitably synchronized superclasses.
* It binds every possible lookup into a map in each context. To do this, each context
* strips off one name segment and if necessary creates a new context for it. Then it asks that context
* to bind the remaining name. It returns a map containing all the bindings from the next context, plus
* the context it just created (if it in fact created it). (the names are suitably extended by the segment
* originally lopped off).
*
* @param name
* @param value
* @return
* @throws javax.naming.NamingException
*/
protected Map internalBind(String name, Object value) throws NamingException {
return internalBind(name, value, false);
}
protected Map internalBind(String name, Object value, boolean allowRebind) throws NamingException {
if (name == null || name.length() == 0){
throw new NamingException("Invalid Name " + name);
}
if (frozen){
throw new NamingException("Read only");
}
Map newBindings = new HashMap();
int pos = name.indexOf('/');
if (pos == -1) {
Object oldValue = treeBindings.put(name, value);
if (!allowRebind && oldValue != null) {
throw new NamingException("Something already bound at " + name);
}
bindings.put(name, value);
newBindings.put(name, value);
}
else {
String segment = name.substring(0, pos);
if (segment == null || segment.length()==0){
throw new NamingException("Invalid segment " + segment);
}
Object o = treeBindings.get(segment);
if (o == null) {
o = newContext();
treeBindings.put(segment, o);
bindings.put(segment, o);
newBindings.put(segment, o);
}
else if (!(o instanceof DefaultContext)) {
throw new NamingException("Something already bound where a subcontext should go");
}
DefaultContext defaultContext = (DefaultContext) o;
String remainder = name.substring(pos + 1);
Map subBindings = defaultContext.internalBind(remainder, value, allowRebind);
for (Iterator iterator = subBindings.entrySet().iterator(); iterator.hasNext();) {
Map.Entry entry = (Map.Entry) iterator.next();
String subName = segment + "/" + (String) entry.getKey();
Object bound = entry.getValue();
treeBindings.put(subName, bound);
newBindings.put(subName, bound);
}
}
return newBindings;
}
protected void checkFrozen() throws OperationNotSupportedException {
if (isFreeze()) {
throw new OperationNotSupportedException("JNDI context is frozen!");
}
}
protected DefaultContext newContext() {
return new DefaultContext();
}
}
xbean-3.7/xbean-spring/src/test/ 0000755 0001750 0001750 00000000000 11610661035 016516 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/ 0000755 0001750 0001750 00000000000 11610661035 020530 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/META-INF/ 0000755 0001750 0001750 00000000000 11610661035 021670 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/META-INF/services/ 0000755 0001750 0001750 00000000000 11610661035 023513 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/ 0000755 0001750 0001750 00000000000 11610661035 024302 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/ 0000755 0001750 0001750 00000000000 11610661035 025523 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/ 0000755 0001750 0001750 00000000000 11610661035 026620 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/ 0000755 0001750 0001750 00000000000 11610661035 030122 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/ 0000755 0001750 0001750 00000000000 11610661035 031101 5 ustar drazzib drazzib ././@LongLink 0000000 0000000 0000000 00000000153 00000000000 011564 L ustar root root xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apache.org/ xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apach0000755 0001750 0001750 00000000000 11610661035 033172 5 ustar drazzib drazzib ././@LongLink 0000000 0000000 0000000 00000000163 00000000000 011565 L ustar root root xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apache.org/schemas/ xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apach0000755 0001750 0001750 00000000000 11610661035 033172 5 ustar drazzib drazzib ././@LongLink 0000000 0000000 0000000 00000000174 00000000000 011567 L ustar root root xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apache.org/schemas/component xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apach0000644 0001750 0001750 00000001641 10541574201 033176 0 ustar drazzib drazzib #
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
#
container=org.apache.xbean.spring.example.ContainerBean
inner=org.apache.xbean.spring.example.InnerBean
././@LongLink 0000000 0000000 0000000 00000000167 00000000000 011571 L ustar root root xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apache.org/schemas/soup xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apach0000644 0001750 0001750 00000002373 10541574201 033201 0 ustar drazzib drazzib #
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
#
# START SNIPPET: config
# the default package that POJOs are in
package = org.apache.xbean.spring.example
# Mapping of XML Element localNames to classes
soup = org.apache.xbean.spring.example.SoupService
# Mapping of life-cycle methods
soup.initMethod = make
soup.destroyMethod = eat
soup.factoryMethod = newSoup
# Mapping of constructor argument names
org.apache.xbean.spring.example.SoupService.newSoup(java.lang.String).parameterNames=type
# END SNIPPET: config
././@LongLink 0000000 0000000 0000000 00000000177 00000000000 011572 L ustar root root xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apache.org/schemas/pizza-simple xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apach0000644 0001750 0001750 00000002113 10541574201 033171 0 ustar drazzib drazzib #
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
#
# START SNIPPET: config
# the default package that POJOs are in
package = org.apache.xbean.spring.example
# Mapping of XML Element localNames to classes
pizza = org.apache.xbean.spring.example.PizzaService
restaurant = org.apache.xbean.spring.example.RestaurantService
# END SNIPPET: config
././@LongLink 0000000 0000000 0000000 00000000175 00000000000 011570 L ustar root root xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apache.org/schemas/restaurant xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apach0000644 0001750 0001750 00000002410 10541574201 033171 0 ustar drazzib drazzib #
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
#
# START SNIPPET: config
# the default package that POJOs are in
package = org.apache.xbean.spring.example
# Mapping of XML Element localNames to classes
pizza = org.apache.xbean.spring.example.PizzaService
restaurant = org.apache.xbean.spring.example.RestaurantService
# Mapping of XML Attributes to property names
pizza.alias.myTopping = topping
# Mapping of nested bean properties
restaurant.dinnerMenu.list = dinnerMenu
restaurant.favourite = favourite
# END SNIPPET: config
././@LongLink 0000000 0000000 0000000 00000000170 00000000000 011563 L ustar root root xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apache.org/schemas/salad xbean-3.7/xbean-spring/src/test/resources/META-INF/services/org/apache/xbean/spring/http/xbean.apach0000644 0001750 0001750 00000002403 10541574201 033173 0 ustar drazzib drazzib #
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#
#
# START SNIPPET: config
# the default package that POJOs are in
package = org.apache.xbean.spring.example
# Mapping of XML Element localNames to classes
salad = org.apache.xbean.spring.example.SaladService
# Mapping of XML Attributes to property names
salad.alias.addCroutons = crouton
# Mapping of constructor argument names
org.apache.xbean.spring.example.SaladService(java.lang.String,java.lang.String,boolean).parameterNames=dressing size crouton
# END SNIPPET: config
xbean-3.7/xbean-spring/src/test/resources/org/ 0000755 0001750 0001750 00000000000 11610661035 021317 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/org/apache/ 0000755 0001750 0001750 00000000000 11610661035 022540 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/org/apache/xbean/ 0000755 0001750 0001750 00000000000 11610661035 023635 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/org/apache/xbean/spring/ 0000755 0001750 0001750 00000000000 11610661036 025140 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/org/apache/xbean/spring/generator/ 0000755 0001750 0001750 00000000000 11610661036 027126 5 ustar drazzib drazzib ././@LongLink 0000000 0000000 0000000 00000000152 00000000000 011563 L ustar root root xbean-3.7/xbean-spring/src/test/resources/org/apache/xbean/spring/generator/model-test-xsd-validation.xml xbean-3.7/xbean-spring/src/test/resources/org/apache/xbean/spring/generator/model-test-xsd-validatio0000644 0001750 0001750 00000004010 11252465671 033700 0 ustar drazzib drazzib
xbean-3.7/xbean-spring/src/test/resources/org/apache/xbean/spring/context/ 0000755 0001750 0001750 00000000000 11610661036 026624 5 ustar drazzib drazzib xbean-3.7/xbean-spring/src/test/resources/org/apache/xbean/spring/context/spring-extension.xml 0000644 0001750 0001750 00000002145 10512740134 032661 0 ustar drazzib drazzib