You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2010/07/28 23:01:01 UTC
svn commit: r980211 [2/3] - in /tuscany/sca-java-2.x/trunk/modules:
implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/spring/processor/
implementation-spring-runtime/src/main/java/org/apache/tuscany/sca/implementation/sp...
Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java?rev=980211&r1=980210&r2=980211&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/introspect/SpringXMLComponentTypeLoader.java Wed Jul 28 21:01:00 2010
@@ -100,8 +100,7 @@ public class SpringXMLComponentTypeLoade
private Monitor monitor;
private SpringBeanIntrospector beanIntrospector;
- public SpringXMLComponentTypeLoader(ExtensionPointRegistry registry,
- Monitor monitor) {
+ public SpringXMLComponentTypeLoader(ExtensionPointRegistry registry, Monitor monitor) {
super();
this.registry = registry;
FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
@@ -113,7 +112,7 @@ public class SpringXMLComponentTypeLoade
this.xmlInputFactory = factories.getFactory(XMLInputFactory.class);
this.monitor = monitor;
}
-
+
/**
* Report a exception.
*
@@ -122,10 +121,16 @@ public class SpringXMLComponentTypeLoade
* @param model
*/
private void error(String message, Object model, Exception ex) {
- if (monitor != null) {
- Problem problem = monitor.createProblem(this.getClass().getName(), "impl-spring-validation-messages", Severity.ERROR, model, message, ex);
- monitor.problem(problem);
- }
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(this.getClass().getName(),
+ "impl-spring-validation-messages",
+ Severity.ERROR,
+ model,
+ message,
+ ex);
+ monitor.problem(problem);
+ }
}
/**
@@ -136,10 +141,16 @@ public class SpringXMLComponentTypeLoade
* @param model
*/
private void error(String message, Object model, Object... messageParameters) {
- if (monitor != null) {
- Problem problem = monitor.createProblem(this.getClass().getName(), "impl-spring-validation-messages", Severity.ERROR, model, message, (Object[])messageParameters);
- monitor.problem(problem);
- }
+ if (monitor != null) {
+ Problem problem =
+ monitor.createProblem(this.getClass().getName(),
+ "impl-spring-validation-messages",
+ Severity.ERROR,
+ model,
+ message,
+ (Object[])messageParameters);
+ monitor.problem(problem);
+ }
}
protected Class<SpringImplementation> getImplementationClass() {
@@ -151,9 +162,10 @@ public class SpringXMLComponentTypeLoade
* Spring implementation
*
*/
- public void load(SpringImplementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionReadException {
+ public void load(SpringImplementation implementation, ModelResolver resolver, ProcessorContext context)
+ throws ContributionReadException {
//System.out.println("Spring TypeLoader - load method start");
- ComponentType componentType = implementation.getComponentType();
+ ComponentType componentType = implementation.getComponentType();
/* Check that there is a component type object already set */
if (componentType == null) {
throw new ContributionReadException("SpringXMLLoader load: implementation has no ComponentType object");
@@ -164,10 +176,11 @@ public class SpringXMLComponentTypeLoade
if (!componentType.isUnresolved())
implementation.setUnresolved(false);
} // end if
- //System.out.println("Spring TypeLoader - load method complete");
+ //System.out.println("Spring TypeLoader - load method complete");
} // end method load
- private Class<?> resolveClass(ModelResolver resolver, String className, ProcessorContext context) throws ClassNotFoundException {
+ private Class<?> resolveClass(ModelResolver resolver, String className, ProcessorContext context)
+ throws ClassNotFoundException {
ClassReference classReference = new ClassReference(className);
classReference = resolver.resolveModel(ClassReference.class, classReference, context);
if (classReference.isUnresolved()) {
@@ -184,7 +197,8 @@ public class SpringXMLComponentTypeLoade
* @param implementation SpringImplementation into which to load the component type information
* @throws ContributionReadException Failed to read the contribution
*/
- private void loadFromXML(SpringImplementation implementation, ModelResolver resolver, ProcessorContext context) throws ContributionReadException {
+ private void loadFromXML(SpringImplementation implementation, ModelResolver resolver, ProcessorContext context)
+ throws ContributionReadException {
XMLStreamReader reader;
List<SpringBeanElement> beans = new ArrayList<SpringBeanElement>();
List<SpringSCAServiceElement> services = new ArrayList<SpringSCAServiceElement>();
@@ -195,31 +209,38 @@ public class SpringXMLComponentTypeLoade
List<URL> contextResources = new ArrayList<URL>();
String contextPath = implementation.getLocation();
- try {
+ try {
resource = resolveLocation(resolver, contextPath, context);
contextResources = getApplicationContextResource(resource);
-
+
implementation.setClassLoader(new ContextClassLoader(resolver, context));
implementation.setResource(contextResources);
// The URI is used to uniquely identify the Implementation
implementation.setURI(resource.toString());
-
- for (URL contextResource : contextResources) {
- List<SpringBeanElement> appCxtBeans = new ArrayList<SpringBeanElement>();
+
+ for (URL contextResource : contextResources) {
+ List<SpringBeanElement> appCxtBeans = new ArrayList<SpringBeanElement>();
List<SpringSCAServiceElement> appCxtServices = new ArrayList<SpringSCAServiceElement>();
List<SpringSCAReferenceElement> appCxtReferences = new ArrayList<SpringSCAReferenceElement>();
List<SpringSCAPropertyElement> appCxtProperties = new ArrayList<SpringSCAPropertyElement>();
- reader = xmlInputFactory.createXMLStreamReader(contextResource.openStream());
- // Read the beans, services, references and properties for individual application context
- readContextDefinition(resolver, reader, contextPath, appCxtBeans, appCxtServices, appCxtReferences, appCxtProperties, context);
- // Validate the beans from individual application context for uniqueness
- validateBeans(appCxtBeans, appCxtServices, appCxtReferences, appCxtProperties);
- // Add all the validated beans to the generic list
- beans.addAll(appCxtBeans);
- services.addAll(appCxtServices);
- references.addAll(appCxtReferences);
- scaproperties.addAll(appCxtProperties);
- reader.close();
+ reader = xmlInputFactory.createXMLStreamReader(contextResource.openStream());
+ // Read the beans, services, references and properties for individual application context
+ readContextDefinition(resolver,
+ reader,
+ contextPath,
+ appCxtBeans,
+ appCxtServices,
+ appCxtReferences,
+ appCxtProperties,
+ context);
+ // Validate the beans from individual application context for uniqueness
+ validateBeans(appCxtBeans, appCxtServices, appCxtReferences, appCxtProperties);
+ // Add all the validated beans to the generic list
+ beans.addAll(appCxtBeans);
+ services.addAll(appCxtServices);
+ references.addAll(appCxtReferences);
+ scaproperties.addAll(appCxtProperties);
+ reader.close();
}
} catch (IOException e) {
throw new ContributionReadException(e);
@@ -235,8 +256,8 @@ public class SpringXMLComponentTypeLoade
return;
} // end method loadFromXML
- private URL resolveLocation(ModelResolver resolver, String contextPath, ProcessorContext context) throws MalformedURLException,
- ContributionReadException {
+ private URL resolveLocation(ModelResolver resolver, String contextPath, ProcessorContext context)
+ throws MalformedURLException, ContributionReadException {
URL resource = null;
URI uri = URI.create(contextPath);
if (!uri.isAbsolute()) {
@@ -259,12 +280,13 @@ public class SpringXMLComponentTypeLoade
* Method which returns the XMLStreamReader for the Spring application-context.xml file
* specified in the location attribute
*/
- private XMLStreamReader getApplicationContextReader(ModelResolver resolver, String location, ProcessorContext context) throws ContributionReadException {
+ private XMLStreamReader getApplicationContextReader(ModelResolver resolver,
+ String location,
+ ProcessorContext context) throws ContributionReadException {
try {
URL resource = getApplicationContextResource(resolveLocation(resolver, location, context)).get(0);
- XMLStreamReader reader =
- xmlInputFactory.createXMLStreamReader(resource.openStream());
+ XMLStreamReader reader = xmlInputFactory.createXMLStreamReader(resource.openStream());
return reader;
} catch (IOException e) {
throw new ContributionReadException(e);
@@ -284,7 +306,8 @@ public class SpringXMLComponentTypeLoade
List<SpringBeanElement> beans,
List<SpringSCAServiceElement> services,
List<SpringSCAReferenceElement> references,
- List<SpringSCAPropertyElement> scaproperties, ProcessorContext context) throws ContributionReadException {
+ List<SpringSCAPropertyElement> scaproperties,
+ ProcessorContext context) throws ContributionReadException {
SpringBeanElement bean = null;
@@ -296,74 +319,84 @@ public class SpringXMLComponentTypeLoade
QName qname = reader.getName();
//System.out.println("Spring TypeLoader - found element with name: " + qname.toString());
if (SpringImplementationConstants.IMPORT_ELEMENT.equals(qname)) {
- //FIXME - put the sequence of code below which gets the ireader into a subsidiary method
+ //FIXME - put the sequence of code below which gets the ireader into a subsidiary method
String location = reader.getAttributeValue(null, "resource");
if (location != null) {
- // FIXME - need to find a right way of generating this path
- String resourcePath = contextPath.substring(0, contextPath.lastIndexOf("/")+1) + location;
+ // FIXME - need to find a right way of generating this path
+ String resourcePath =
+ contextPath.substring(0, contextPath.lastIndexOf("/") + 1) + location;
XMLStreamReader ireader = getApplicationContextReader(resolver, resourcePath, context);
// Read the context definition for the identified imported resource
- readContextDefinition(resolver, ireader, contextPath, beans, services, references, scaproperties, context);
+ readContextDefinition(resolver,
+ ireader,
+ contextPath,
+ beans,
+ services,
+ references,
+ scaproperties,
+ context);
}
} else if (SpringImplementationConstants.SCA_SERVICE_ELEMENT.equals(qname)) {
- // The value of the @name attribute of an <sca:service/> subelement of a <beans/>
- // element MUST be unique amongst the <sca:service/> subelements of the <beans/> element.
- if (!services.isEmpty() && (services.contains(reader.getAttributeValue(null, "name"))))
- error("ScaServiceNameNotUnique", resolver);
-
- SpringSCAServiceElement service =
- new SpringSCAServiceElement(reader.getAttributeValue(null, "name"),
- reader.getAttributeValue(null, "target"));
+ // The value of the @name attribute of an <sca:service/> subelement of a <beans/>
+ // element MUST be unique amongst the <sca:service/> subelements of the <beans/> element.
+ if (!services.isEmpty() && (services.contains(reader.getAttributeValue(null, "name"))))
+ error("ScaServiceNameNotUnique", resolver);
+
+ SpringSCAServiceElement service =
+ new SpringSCAServiceElement(reader.getAttributeValue(null, "name"),
+ reader.getAttributeValue(null, "target"));
if (reader.getAttributeValue(null, "type") != null)
- service.setType(reader.getAttributeValue(null, "type"));
+ service.setType(reader.getAttributeValue(null, "type"));
policyProcessor.readPolicies(service, reader);
services.add(service);
} else if (SpringImplementationConstants.SCA_REFERENCE_ELEMENT.equals(qname)) {
- // The value of the @name attribute of an <sca:reference/> subelement of a <beans/>
- // element MUST be unique amongst the @name attributes of the <sca:reference/> subelements,
- // of the <beans/> element.
- if (!references.isEmpty() && (references.contains(reader.getAttributeValue(null, "name"))))
- error("ScaReferenceNameNotUnique", resolver);
-
- SpringSCAReferenceElement reference =
- new SpringSCAReferenceElement(reader.getAttributeValue(null, "name"),
- reader.getAttributeValue(null, "type"));
+ // The value of the @name attribute of an <sca:reference/> subelement of a <beans/>
+ // element MUST be unique amongst the @name attributes of the <sca:reference/> subelements,
+ // of the <beans/> element.
+ if (!references.isEmpty() && (references.contains(reader.getAttributeValue(null, "name"))))
+ error("ScaReferenceNameNotUnique", resolver);
+
+ SpringSCAReferenceElement reference =
+ new SpringSCAReferenceElement(reader.getAttributeValue(null, "name"),
+ reader.getAttributeValue(null, "type"));
if (reader.getAttributeValue(null, "default") != null)
- reference.setDefaultBean(reader.getAttributeValue(null, "default"));
+ reference.setDefaultBean(reader.getAttributeValue(null, "default"));
policyProcessor.readPolicies(reference, reader);
- references.add(reference);
+ references.add(reference);
} else if (SpringImplementationConstants.SCA_PROPERTY_ELEMENT.equals(qname)) {
- // The value of the @name attribute of an <sca:property/> subelement of a <beans/>
- // element MUST be unique amongst the @name attributes of the <sca:property/> subelements,
- // of the <beans/> element.
- if (!scaproperties.isEmpty() && (scaproperties.contains(reader.getAttributeValue(null, "name"))))
- error("ScaPropertyNameNotUnique", resolver);
-
- SpringSCAPropertyElement scaproperty =
- new SpringSCAPropertyElement(reader.getAttributeValue(null, "name"), reader
- .getAttributeValue(null, "type"));
+ // The value of the @name attribute of an <sca:property/> subelement of a <beans/>
+ // element MUST be unique amongst the @name attributes of the <sca:property/> subelements,
+ // of the <beans/> element.
+ if (!scaproperties.isEmpty() && (scaproperties.contains(reader.getAttributeValue(null,
+ "name"))))
+ error("ScaPropertyNameNotUnique", resolver);
+
+ SpringSCAPropertyElement scaproperty =
+ new SpringSCAPropertyElement(reader.getAttributeValue(null, "name"),
+ reader.getAttributeValue(null, "type"));
scaproperties.add(scaproperty);
} else if (SpringImplementationConstants.BEAN_ELEMENT.equals(qname)) {
- bean = new SpringBeanElement(reader.getAttributeValue(null, "id"),
- reader.getAttributeValue(null, "class"));
+ bean =
+ new SpringBeanElement(reader.getAttributeValue(null, "id"),
+ reader.getAttributeValue(null, "class"));
if (reader.getAttributeValue(null, "abstract") != null)
- if (reader.getAttributeValue(null, "abstract").equals("true"))
- bean.setAbstractBean(true);
+ if (reader.getAttributeValue(null, "abstract").equals("true"))
+ bean.setAbstractBean(true);
if (reader.getAttributeValue(null, "parent") != null)
- if (!reader.getAttributeValue(null, "parent").equals(""))
- bean.setParentAttribute(true);
+ if (!reader.getAttributeValue(null, "parent").equals(""))
+ bean.setParentAttribute(true);
if (reader.getAttributeValue(null, "factory-bean") != null)
- if (!reader.getAttributeValue(null, "factory-bean").equals(""))
- bean.setFactoryBeanAttribute(true);
+ if (!reader.getAttributeValue(null, "factory-bean").equals(""))
+ bean.setFactoryBeanAttribute(true);
if (reader.getAttributeValue(null, "factory-method") != null)
- if (!reader.getAttributeValue(null, "factory-method").equals(""))
- bean.setFactoryMethodAttribute(true);
+ if (!reader.getAttributeValue(null, "factory-method").equals(""))
+ bean.setFactoryMethodAttribute(true);
// Set the first name as bean name, when the @id attribute is absent.
if (reader.getAttributeValue(null, "id") == null) {
- if (reader.getAttributeValue(null, "name") != null) {
- String[] names = (reader.getAttributeValue(null, "name")).split(",");
- bean.setId(names[0]);
- }
+ if (reader.getAttributeValue(null, "name") != null) {
+ String[] names = (reader.getAttributeValue(null, "name")).split(",");
+ bean.setId(names[0]);
+ }
}
beans.add(bean);
// Read the <bean> element and its child elements
@@ -383,34 +416,33 @@ public class SpringXMLComponentTypeLoade
}
}
-
/**
* Method which reads the bean definitions from Spring application-context.xml file and identifies
* the defined beans, properties, services and references
*/
- private void readBeanDefinition(XMLStreamReader reader,
- SpringBeanElement bean,
- List<SpringBeanElement> beans) throws ContributionReadException {
+ private void readBeanDefinition(XMLStreamReader reader, SpringBeanElement bean, List<SpringBeanElement> beans)
+ throws ContributionReadException {
- SpringBeanElement innerbean = null;
+ SpringBeanElement innerbean = null;
SpringPropertyElement property = null;
SpringConstructorArgElement constructorArg = null;
-
+
try {
- boolean completed = false;
+ boolean completed = false;
while (!completed) {
switch (reader.next()) {
case START_ELEMENT:
QName qname = reader.getName();
if (SpringImplementationConstants.BEAN_ELEMENT.equals(qname)) {
- innerbean = new SpringBeanElement(reader.getAttributeValue(null, "id"), reader
- .getAttributeValue(null, "class"));
- // Set the first name as bean name, when the @id attribute is absent.
+ innerbean =
+ new SpringBeanElement(reader.getAttributeValue(null, "id"),
+ reader.getAttributeValue(null, "class"));
+ // Set the first name as bean name, when the @id attribute is absent.
if (reader.getAttributeValue(null, "id") == null) {
- if (reader.getAttributeValue(null, "name") != null) {
- String[] names = (reader.getAttributeValue(null, "name")).split(",");
- innerbean.setId(names[0]);
- }
+ if (reader.getAttributeValue(null, "name") != null) {
+ String[] names = (reader.getAttributeValue(null, "name")).split(",");
+ innerbean.setId(names[0]);
+ }
}
innerbean.setInnerBean(true);
beans.add(innerbean);
@@ -418,34 +450,37 @@ public class SpringXMLComponentTypeLoade
} else if (SpringImplementationConstants.PROPERTY_ELEMENT.equals(qname)) {
property = new SpringPropertyElement(reader.getAttributeValue(null, "name"));
if (reader.getAttributeValue(null, "ref") != null)
- property.addRef(reader.getAttributeValue(null, "ref"));
+ property.addRef(reader.getAttributeValue(null, "ref"));
bean.addProperty(property);
} else if (SpringImplementationConstants.CONSTRUCTORARG_ELEMENT.equals(qname)) {
constructorArg = new SpringConstructorArgElement(reader.getAttributeValue(null, "type"));
if (reader.getAttributeValue(null, "ref") != null)
- constructorArg.addRef(reader.getAttributeValue(null, "ref"));
+ constructorArg.addRef(reader.getAttributeValue(null, "ref"));
if (reader.getAttributeValue(null, "index") != null)
- constructorArg.setIndex((new Integer(reader.getAttributeValue(null, "index"))).intValue());
+ constructorArg.setIndex((new Integer(reader.getAttributeValue(null, "index")))
+ .intValue());
if (reader.getAttributeValue(null, "value") != null)
- constructorArg.addValue(reader.getAttributeValue(null, "value"));
+ constructorArg.addValue(reader.getAttributeValue(null, "value"));
bean.addCustructorArgs(constructorArg);
} else if (SpringImplementationConstants.REF_ELEMENT.equals(qname)) {
- String ref = reader.getAttributeValue(null, "bean");
+ String ref = reader.getAttributeValue(null, "bean");
// Check if the parent element is a property
- if (property != null) property.addRef(ref);
+ if (property != null)
+ property.addRef(ref);
// Check if the parent element is a constructor-arg
- if (constructorArg != null) constructorArg.addRef(ref);
+ if (constructorArg != null)
+ constructorArg.addRef(ref);
} else if (SpringImplementationConstants.VALUE_ELEMENT.equals(qname)) {
String value = reader.getElementText();
// Check if the parent element is a constructor-arg
- if (constructorArg != null) constructorArg.addValue(value);
- } else if (SpringImplementationConstants.LIST_ELEMENT.equals(qname) ||
- SpringImplementationConstants.SET_ELEMENT.equals(qname) ||
- SpringImplementationConstants.MAP_ELEMENT.equals(qname)) {
- if (property != null)
- readCollections(reader, bean, beans, property, null);
if (constructorArg != null)
- readCollections(reader, bean, beans, null, constructorArg);
+ constructorArg.addValue(value);
+ } else if (SpringImplementationConstants.LIST_ELEMENT.equals(qname) || SpringImplementationConstants.SET_ELEMENT
+ .equals(qname) || SpringImplementationConstants.MAP_ELEMENT.equals(qname)) {
+ if (property != null)
+ readCollections(reader, bean, beans, property, null);
+ if (constructorArg != null)
+ readCollections(reader, bean, beans, null, constructorArg);
} // end if
break;
case END_ELEMENT:
@@ -463,8 +498,7 @@ public class SpringXMLComponentTypeLoade
throw new ContributionReadException(e);
}
}
-
-
+
/**
* Method which reads the collection elements from Spring application-context.xml file and identifies
* the defined beans, list, maps and sets
@@ -474,54 +508,62 @@ public class SpringXMLComponentTypeLoade
List<SpringBeanElement> beans,
SpringPropertyElement property,
SpringConstructorArgElement constructorArg) throws ContributionReadException {
-
- SpringBeanElement innerbean = null;
-
+
+ SpringBeanElement innerbean = null;
+
try {
- boolean completed = false;
+ boolean completed = false;
while (!completed) {
switch (reader.next()) {
case START_ELEMENT:
QName qname = reader.getName();
if (SpringImplementationConstants.BEAN_ELEMENT.equals(qname)) {
- innerbean = new SpringBeanElement(reader.getAttributeValue(null, "id"), reader
- .getAttributeValue(null, "class"));
- // Set the first name as bean name, when the @id attribute is absent.
+ innerbean =
+ new SpringBeanElement(reader.getAttributeValue(null, "id"),
+ reader.getAttributeValue(null, "class"));
+ // Set the first name as bean name, when the @id attribute is absent.
if (reader.getAttributeValue(null, "id") == null)
- if (reader.getAttributeValue(null, "name") != null) {
- String[] names = (reader.getAttributeValue(null, "name")).split(",");
- innerbean.setId(names[0]);
- }
+ if (reader.getAttributeValue(null, "name") != null) {
+ String[] names = (reader.getAttributeValue(null, "name")).split(",");
+ innerbean.setId(names[0]);
+ }
innerbean.setInnerBean(true);
beans.add(innerbean);
readBeanDefinition(reader, innerbean, beans);
} else if (SpringImplementationConstants.REF_ELEMENT.equals(qname)) {
- String ref = reader.getAttributeValue(null, "bean");
- if (property != null) property.addRef(ref);
- if (constructorArg != null) constructorArg.addRef(ref);
- } else if (SpringImplementationConstants.LIST_ELEMENT.equals(qname) ||
- SpringImplementationConstants.SET_ELEMENT.equals(qname) ||
- SpringImplementationConstants.MAP_ELEMENT.equals(qname)) {
- if (property != null)
- readCollections(reader, innerbean, beans, property, null);
- if (constructorArg != null)
- readCollections(reader, innerbean, beans, null, constructorArg);
+ String ref = reader.getAttributeValue(null, "bean");
+ if (property != null)
+ property.addRef(ref);
+ if (constructorArg != null)
+ constructorArg.addRef(ref);
+ } else if (SpringImplementationConstants.LIST_ELEMENT.equals(qname) || SpringImplementationConstants.SET_ELEMENT
+ .equals(qname) || SpringImplementationConstants.MAP_ELEMENT.equals(qname)) {
+ if (property != null)
+ readCollections(reader, innerbean, beans, property, null);
+ if (constructorArg != null)
+ readCollections(reader, innerbean, beans, null, constructorArg);
} else if (SpringImplementationConstants.ENTRY_ELEMENT.equals(qname)) {
String keyRef = reader.getAttributeValue(null, "key-ref");
String valueRef = reader.getAttributeValue(null, "value-ref");
- if (property != null) {property.addRef(keyRef); property.addRef(valueRef);}
- if (constructorArg != null) {constructorArg.addRef(keyRef); constructorArg.addRef(valueRef);}
+ if (property != null) {
+ property.addRef(keyRef);
+ property.addRef(valueRef);
+ }
+ if (constructorArg != null) {
+ constructorArg.addRef(keyRef);
+ constructorArg.addRef(valueRef);
+ }
} // end if
break;
case END_ELEMENT:
if (SpringImplementationConstants.LIST_ELEMENT.equals(reader.getName())) {
- completed = true;
+ completed = true;
break;
} else if (SpringImplementationConstants.SET_ELEMENT.equals(reader.getName())) {
- completed = true;
+ completed = true;
break;
} else if (SpringImplementationConstants.MAP_ELEMENT.equals(reader.getName())) {
- completed = true;
+ completed = true;
break;
} // end if
} // end switch
@@ -553,14 +595,14 @@ public class SpringXMLComponentTypeLoade
* at another bean in the application context becomes a property in the component type
*/
- JavaImplementation javaImplementation = null;
+ JavaImplementation javaImplementation = null;
ComponentType componentType = implementation.getComponentType();
try {
// Deal with the services first....
Iterator<SpringSCAServiceElement> its = services.iterator();
while (its.hasNext()) {
- SpringSCAServiceElement serviceElement = its.next();
+ SpringSCAServiceElement serviceElement = its.next();
Class<?> interfaze = resolveClass(resolver, serviceElement.getType(), context);
Service theService = createService(interfaze, serviceElement.getName());
// Spring allows duplication of bean definitions in multiple context scenario,
@@ -568,23 +610,23 @@ public class SpringXMLComponentTypeLoade
// we will remove any older definition and use the latest.
Service duplicate = null;
for (Service service : componentType.getServices()) {
- if (service.getName().equals(theService.getName()))
- duplicate = service;
+ if (service.getName().equals(theService.getName()))
+ duplicate = service;
}
if (duplicate != null)
- componentType.getServices().remove(duplicate);
-
+ componentType.getServices().remove(duplicate);
+
componentType.getServices().add(theService);
// Add this service to the Service / Bean map
String beanName = serviceElement.getTarget();
for (SpringBeanElement beanElement : beans) {
if (beanName.equals(beanElement.getId())) {
- if (isvalidBeanForService(beanElement)) {
- // add the required intents and policySets for the service
+ if (isvalidBeanForService(beanElement)) {
+ // add the required intents and policySets for the service
theService.getRequiredIntents().addAll(serviceElement.getRequiredIntents());
theService.getPolicySets().addAll(serviceElement.getPolicySets());
implementation.setBeanForService(theService, beanElement);
- }
+ }
}
} // end for
} // end while
@@ -599,12 +641,12 @@ public class SpringXMLComponentTypeLoade
// for the duplicate definitions found.
Reference duplicate = null;
for (Reference reference : componentType.getReferences()) {
- if (reference.getName().equals(theReference.getName()))
- duplicate = reference;
+ if (reference.getName().equals(theReference.getName()))
+ duplicate = reference;
}
if (duplicate != null)
- componentType.getReferences().remove(duplicate);
-
+ componentType.getReferences().remove(duplicate);
+
// add the required intents and policySets for this reference
theReference.getRequiredIntents().addAll(referenceElement.getRequiredIntents());
theReference.getPolicySets().addAll(referenceElement.getPolicySets());
@@ -627,12 +669,12 @@ public class SpringXMLComponentTypeLoade
// for the duplicate definitions found.
Property duplicate = null;
for (Property property : componentType.getProperties()) {
- if (property.getName().equals(theProperty.getName()))
- duplicate = property;
+ if (property.getName().equals(theProperty.getName()))
+ duplicate = property;
}
if (duplicate != null)
- componentType.getProperties().remove(duplicate);
-
+ componentType.getProperties().remove(duplicate);
+
componentType.getProperties().add(theProperty);
// Remember the Java Class (ie the type) for this property
implementation.setPropertyClass(theProperty.getName(), propType);
@@ -648,17 +690,17 @@ public class SpringXMLComponentTypeLoade
while (itb.hasNext()) {
SpringBeanElement beanElement = itb.next();
// If its not a valid bean for service, ignore it
- if (!isvalidBeanForService(beanElement)) continue;
+ if (!isvalidBeanForService(beanElement))
+ continue;
// Load the Spring bean class
Class<?> beanClass = resolveClass(resolver, beanElement.getClassName(), context);
// Introspect the bean
- beanIntrospector =
- new SpringBeanIntrospector(registry, beanElement.getCustructorArgs());
+ beanIntrospector = new SpringBeanIntrospector(registry, beanElement.getCustructorArgs());
ComponentType beanComponentType = assemblyFactory.createComponentType();
javaImplementation = beanIntrospector.introspectBean(beanClass, beanComponentType);
// Set the service name as bean name
- for (Service componentService : beanComponentType.getServices())
- componentService.setName(beanElement.getId());
+ for (Service componentService : beanComponentType.getServices())
+ componentService.setName(beanElement.getId());
// Get the service interface defined by this Spring Bean and add to
// the component type of the Spring Assembly
List<Service> beanServices = beanComponentType.getServices();
@@ -675,12 +717,11 @@ public class SpringXMLComponentTypeLoade
SpringBeanElement beanElement = itb.next();
// Ignore if the bean has no properties and constructor arguments
if (beanElement.getProperties().isEmpty() && beanElement.getCustructorArgs().isEmpty())
- continue;
+ continue;
Class<?> beanClass = resolveClass(resolver, beanElement.getClassName(), context);
// Introspect the bean
- beanIntrospector =
- new SpringBeanIntrospector(registry, beanElement.getCustructorArgs());
+ beanIntrospector = new SpringBeanIntrospector(registry, beanElement.getCustructorArgs());
ComponentType beanComponentType = assemblyFactory.createComponentType();
javaImplementation = beanIntrospector.introspectBean(beanClass, beanComponentType);
Map<String, JavaElementImpl> propertyMap = javaImplementation.getPropertyMembers();
@@ -694,60 +735,62 @@ public class SpringXMLComponentTypeLoade
while (itp.hasNext()) {
SpringPropertyElement propertyElement = itp.next();
for (String propertyRef : propertyElement.getRefs()) {
- if (propertyRefUnresolved(propertyRef, beans, references, scaproperties)) {
- // This means an unresolved reference from the spring bean...
- for (Reference reference : beanReferences) {
- if (propertyElement.getName().equals(reference.getName())) {
- // The name of the reference in this case is the string in
- // the @ref attribute of the Spring property element, NOT the
- // name of the field in the Spring bean....
- reference.setName(propertyRef);
- componentType.getReferences().add(reference);
- } // end if
- } // end for
-
- // Store the unresolved references as unresolvedBeanRef in the Spring Implementation type
- for (Property scaproperty : beanProperties) {
- if (propertyElement.getName().equals(scaproperty.getName())) {
- // The name of the reference in this case is the string in
- // the @ref attribute of the Spring property element, NOT the
- // name of the field in the Spring bean....
- Class<?> interfaze = resolveClass(resolver, (propertyMap.get(propertyElement.getName()).getType()).getName(), context);
- Reference theReference = createReference(interfaze, propertyRef);
- implementation.setUnresolvedBeanRef(propertyRef, theReference);
- } // end if
- } // end for
- } // end if
+ if (propertyRefUnresolved(propertyRef, beans, references, scaproperties)) {
+ // This means an unresolved reference from the spring bean...
+ for (Reference reference : beanReferences) {
+ if (propertyElement.getName().equals(reference.getName())) {
+ // The name of the reference in this case is the string in
+ // the @ref attribute of the Spring property element, NOT the
+ // name of the field in the Spring bean....
+ reference.setName(propertyRef);
+ componentType.getReferences().add(reference);
+ } // end if
+ } // end for
+
+ // Store the unresolved references as unresolvedBeanRef in the Spring Implementation type
+ for (Property scaproperty : beanProperties) {
+ if (propertyElement.getName().equals(scaproperty.getName())) {
+ // The name of the reference in this case is the string in
+ // the @ref attribute of the Spring property element, NOT the
+ // name of the field in the Spring bean....
+ Class<?> interfaze =
+ resolveClass(resolver,
+ (propertyMap.get(propertyElement.getName()).getType()).getName(),
+ context);
+ Reference theReference = createReference(interfaze, propertyRef);
+ implementation.setUnresolvedBeanRef(propertyRef, theReference);
+ } // end if
+ } // end for
+ } // end if
} // end for
} // end while
Iterator<SpringConstructorArgElement> itcr = beanElement.getCustructorArgs().iterator();
while (itcr.hasNext()) {
- SpringConstructorArgElement conArgElement = itcr.next();
- for (String constructorArgRef : conArgElement.getRefs()) {
- if (propertyRefUnresolved(constructorArgRef, beans, references, scaproperties)) {
- for (JavaParameterImpl parameter : constructor.getParameters()) {
- String paramType = parameter.getType().getName();
- Class<?> interfaze = resolveClass(resolver, paramType, context);
- // Create a component type reference/property if the constructor-arg element has a
- // type attribute OR index attribute declared...
- if ((conArgElement.getType() != null && paramType.equals(conArgElement.getType())) ||
- (conArgElement.getIndex() != -1 && (conArgElement.getIndex() == parameter.getIndex())))
- {
- if (parameter.getClassifer().getName().equals("org.osoa.sca.annotations.Reference")) {
- Reference theReference = createReference(interfaze, constructorArgRef);
- componentType.getReferences().add(theReference);
- }
- if (parameter.getClassifer().getName().equals("org.osoa.sca.annotations.Property")) {
- // Store the unresolved references as unresolvedBeanRef in the Spring Implementation type
- // we might need to verify with the component definition later.
- Reference theReference = createReference(interfaze, constructorArgRef);
- implementation.setUnresolvedBeanRef(constructorArgRef, theReference);
- }
- }
- } // end for
- } // end if
- } // end for
+ SpringConstructorArgElement conArgElement = itcr.next();
+ for (String constructorArgRef : conArgElement.getRefs()) {
+ if (propertyRefUnresolved(constructorArgRef, beans, references, scaproperties)) {
+ for (JavaParameterImpl parameter : constructor.getParameters()) {
+ String paramType = parameter.getType().getName();
+ Class<?> interfaze = resolveClass(resolver, paramType, context);
+ // Create a component type reference/property if the constructor-arg element has a
+ // type attribute OR index attribute declared...
+ if ((conArgElement.getType() != null && paramType.equals(conArgElement.getType())) || (conArgElement
+ .getIndex() != -1 && (conArgElement.getIndex() == parameter.getIndex()))) {
+ if (parameter.getClassifer().getName().equals("org.osoa.sca.annotations.Reference")) {
+ Reference theReference = createReference(interfaze, constructorArgRef);
+ componentType.getReferences().add(theReference);
+ }
+ if (parameter.getClassifer().getName().equals("org.osoa.sca.annotations.Property")) {
+ // Store the unresolved references as unresolvedBeanRef in the Spring Implementation type
+ // we might need to verify with the component definition later.
+ Reference theReference = createReference(interfaze, constructorArgRef);
+ implementation.setUnresolvedBeanRef(constructorArgRef, theReference);
+ }
+ }
+ } // end for
+ } // end if
+ } // end for
} // end while
} // end while
@@ -793,7 +836,7 @@ public class SpringXMLComponentTypeLoade
break;
} // end if
} // end while
- // Scan over the SCA reference elements looking for a match
+ // Scan over the SCA reference elements looking for a match
if (unresolved) {
Iterator<SpringSCAReferenceElement> itr = references.iterator();
while (itr.hasNext()) {
@@ -804,7 +847,7 @@ public class SpringXMLComponentTypeLoade
} // end if
} // end while
} // end if
- // Scan over the SCA property elements looking for a match
+ // Scan over the SCA property elements looking for a match
if (unresolved) {
Iterator<SpringSCAPropertyElement> itsp = scaproperties.iterator();
while (itsp.hasNext()) {
@@ -824,35 +867,35 @@ public class SpringXMLComponentTypeLoade
return unresolved;
} // end method propertyRefUnresolved
-
+
/**
* Validates whether the <sca:service>, <sca:reference> and <sca:property> elements
* has unique names within the application context.
*/
private void validateBeans(List<SpringBeanElement> beans,
- List<SpringSCAServiceElement> services,
- List<SpringSCAReferenceElement> references,
- List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException {
-
- // The @target attribute of a <service/> subelement of a <beans/> element
- // MUST have the value of the @name attribute of one of the <bean/>
- // subelements of the <beans/> element.
- Iterator<SpringSCAServiceElement> its = services.iterator();
+ List<SpringSCAServiceElement> services,
+ List<SpringSCAReferenceElement> references,
+ List<SpringSCAPropertyElement> scaproperties) throws ContributionReadException {
+
+ // The @target attribute of a <service/> subelement of a <beans/> element
+ // MUST have the value of the @name attribute of one of the <bean/>
+ // subelements of the <beans/> element.
+ Iterator<SpringSCAServiceElement> its = services.iterator();
while (its.hasNext()) {
- SpringSCAServiceElement serviceElement = its.next();
- boolean targetBeanExists = false;
- Iterator<SpringBeanElement> itb = beans.iterator();
- while (itb.hasNext()) {
- SpringBeanElement beanElement = itb.next();
- if (serviceElement.getTarget().equals(beanElement.getId()))
- targetBeanExists = true;
- }
- if (!targetBeanExists)
- error("TargetBeanDoesNotExist", beans);
+ SpringSCAServiceElement serviceElement = its.next();
+ boolean targetBeanExists = false;
+ Iterator<SpringBeanElement> itb = beans.iterator();
+ while (itb.hasNext()) {
+ SpringBeanElement beanElement = itb.next();
+ if (serviceElement.getTarget().equals(beanElement.getId()))
+ targetBeanExists = true;
+ }
+ if (!targetBeanExists)
+ error("TargetBeanDoesNotExist", beans);
} // end while
-
- // The value of the @name attribute of an <sca:reference/> subelement of a <beans/>
- // element MUST be unique amongst the @name attributes of the <sca:property/>
+
+ // The value of the @name attribute of an <sca:reference/> subelement of a <beans/>
+ // element MUST be unique amongst the @name attributes of the <sca:property/>
// subelements and the <bean/> subelements of the <beans/> element.
// AND
// The @default attribute of a <sca:reference/> subelement of a <beans/>
@@ -860,213 +903,219 @@ public class SpringXMLComponentTypeLoade
// subelements of the <beans/> element.
Iterator<SpringSCAReferenceElement> itr = references.iterator();
while (itr.hasNext()) {
- SpringSCAReferenceElement referenceElement = itr.next();
- boolean defaultBeanExists = true;
- boolean isUniqueReferenceName = true;
- Iterator<SpringBeanElement> itb = beans.iterator();
- while (itb.hasNext()) {
- SpringBeanElement beanElement = itb.next();
- if (referenceElement.getDefaultBean() != null)
- if (referenceElement.getDefaultBean().equals(beanElement.getId()))
- defaultBeanExists = false;
- if (referenceElement.getName().equals(beanElement.getId()))
- isUniqueReferenceName = false;
- }
- Iterator<SpringSCAPropertyElement> itp = scaproperties.iterator();
- while (itp.hasNext()) {
- SpringSCAPropertyElement propertyElement = itp.next();
- if (referenceElement.getName().equals(propertyElement.getName()))
- isUniqueReferenceName = false;
- }
- if (!defaultBeanExists)
- error("DefaultBeanDoesNotExist", beans);
- if (!isUniqueReferenceName)
- error("ScaReferenceNameNotUnique", beans);
+ SpringSCAReferenceElement referenceElement = itr.next();
+ boolean defaultBeanExists = true;
+ boolean isUniqueReferenceName = true;
+ Iterator<SpringBeanElement> itb = beans.iterator();
+ while (itb.hasNext()) {
+ SpringBeanElement beanElement = itb.next();
+ if (referenceElement.getDefaultBean() != null)
+ if (referenceElement.getDefaultBean().equals(beanElement.getId()))
+ defaultBeanExists = false;
+ if (referenceElement.getName().equals(beanElement.getId()))
+ isUniqueReferenceName = false;
+ }
+ Iterator<SpringSCAPropertyElement> itp = scaproperties.iterator();
+ while (itp.hasNext()) {
+ SpringSCAPropertyElement propertyElement = itp.next();
+ if (referenceElement.getName().equals(propertyElement.getName()))
+ isUniqueReferenceName = false;
+ }
+ if (!defaultBeanExists)
+ error("DefaultBeanDoesNotExist", beans);
+ if (!isUniqueReferenceName)
+ error("ScaReferenceNameNotUnique", beans);
} // end while
-
- // The value of the @name attribute of an <sca:property/> subelement of a <beans/>
- // element MUST be unique amongst the @name attributes of the <sca:reference/>
+
+ // The value of the @name attribute of an <sca:property/> subelement of a <beans/>
+ // element MUST be unique amongst the @name attributes of the <sca:reference/>
// subelements and the <bean/> subelements of the <beans/> element.
Iterator<SpringSCAPropertyElement> itp = scaproperties.iterator();
while (itp.hasNext()) {
- SpringSCAPropertyElement propertyElement = itp.next();
- boolean isUniquePropertyName = true;
- Iterator<SpringBeanElement> itb = beans.iterator();
- while (itb.hasNext()) {
- SpringBeanElement beanElement = itb.next();
- if (propertyElement.getName().equals(beanElement.getId()))
- isUniquePropertyName = false;
- }
- Iterator<SpringSCAReferenceElement> itrp = references.iterator();
+ SpringSCAPropertyElement propertyElement = itp.next();
+ boolean isUniquePropertyName = true;
+ Iterator<SpringBeanElement> itb = beans.iterator();
+ while (itb.hasNext()) {
+ SpringBeanElement beanElement = itb.next();
+ if (propertyElement.getName().equals(beanElement.getId()))
+ isUniquePropertyName = false;
+ }
+ Iterator<SpringSCAReferenceElement> itrp = references.iterator();
while (itrp.hasNext()) {
- SpringSCAReferenceElement referenceElement = itrp.next();
- if (propertyElement.getName().equals(referenceElement.getName()))
- isUniquePropertyName = false;
+ SpringSCAReferenceElement referenceElement = itrp.next();
+ if (propertyElement.getName().equals(referenceElement.getName()))
+ isUniquePropertyName = false;
}
- if (!isUniquePropertyName)
- error("ScaPropertyNameNotUnique", beans);
+ if (!isUniquePropertyName)
+ error("ScaPropertyNameNotUnique", beans);
} // end while
}
-
+
/**
* Validates whether a bean definition is valid for exposing as service.
*/
private boolean isvalidBeanForService(SpringBeanElement beanElement) {
-
- if (beanElement.isInnerBean())
- return false;
- if (beanElement.hasParentAttribute())
- return false;
- if (beanElement.hasFactoryMethodAttribute())
- return false;
- if (beanElement.hasFactoryBeanAttribute())
- return false;
- if (beanElement.getClassName() == null)
- return false;
- if (beanElement.getClassName().startsWith("org.springframework"))
- return false;
+
+ if (beanElement.isInnerBean())
+ return false;
+ if (beanElement.hasParentAttribute())
+ return false;
+ if (beanElement.hasFactoryMethodAttribute())
+ return false;
+ if (beanElement.hasFactoryBeanAttribute())
+ return false;
+ if (beanElement.getClassName() == null)
+ return false;
+ if (beanElement.getClassName().startsWith("org.springframework"))
+ return false;
// return true otherwise
- return true;
+ return true;
}
-
-
+
/**
* Gets hold of the application-context.xml file as a Spring resource
* @param locationAttr - the location attribute from the <implementation.spring../> element
* @param cl - the ClassLoader for the Spring implementation
*/
- protected List<URL> getApplicationContextResource(URL url)
- throws ContributionReadException {
+ protected List<URL> getApplicationContextResource(URL url) throws ContributionReadException {
File manifestFile = null;
File appXmlFile;
File appXmlFolder;
File locationFile = null;
List<URL> appCtxResources = new ArrayList<URL>();
-
+
if (url != null) {
String path = url.getPath();
locationFile = new File(path);
} else {
- throw new ContributionReadException("SpringXMLComponentTypeLoader getApplicationContextResource: "
- + "unable to find resource file " + url);
+ throw new ContributionReadException(
+ "SpringXMLComponentTypeLoader getApplicationContextResource: " + "unable to find resource file "
+ + url);
}
if (locationFile.isDirectory()) {
try {
- manifestFile = new File(locationFile, "META-INF"+ File.separator +"MANIFEST.MF");
+ manifestFile = new File(locationFile, "META-INF" + File.separator + "MANIFEST.MF");
if (manifestFile.exists()) {
Manifest mf = new Manifest(new FileInputStream(manifestFile));
Attributes mainAttrs = mf.getMainAttributes();
String appCtxPath = mainAttrs.getValue("Spring-Context");
if (appCtxPath != null) {
- String[] cxtPaths = appCtxPath.split(";");
- for (String path : cxtPaths) {
- appXmlFile = new File(locationFile, path.trim());
- if (appXmlFile.exists()) {
- appCtxResources.add(appXmlFile.toURI().toURL());
- }
- }
- return appCtxResources;
+ String[] cxtPaths = appCtxPath.split(";");
+ for (String path : cxtPaths) {
+ appXmlFile = new File(locationFile, path.trim());
+ if (appXmlFile.exists()) {
+ appCtxResources.add(appXmlFile.toURI().toURL());
+ }
+ }
+ return appCtxResources;
}
- }
+ }
// No MANIFEST.MF file OR no manifest-specified Spring context , then read all the
// xml files available in the META-INF/spring folder.
appXmlFolder = new File(locationFile, "META-INF" + File.separator + "spring");
if (appXmlFolder.exists()) {
- File[] files = appXmlFolder.listFiles();
- for (File appFile: files) {
- if (appFile.getName().endsWith(".xml")) {
- appCtxResources.add(appFile.toURI().toURL());
- }
- }
- return appCtxResources;
+ File[] files = appXmlFolder.listFiles();
+ for (File appFile : files) {
+ if (appFile.getName().endsWith(".xml")) {
+ appCtxResources.add(appFile.toURI().toURL());
+ }
+ }
+ return appCtxResources;
}
} catch (IOException e) {
throw new ContributionReadException("Error reading manifest " + manifestFile);
}
} else {
- if (locationFile.isFile() && locationFile.getName().endsWith(".jar")) {
+ if (locationFile.isFile() && locationFile.getName().endsWith(".jar")) {
try {
- JarFile jf = new JarFile(locationFile);
+ JarFile jf = new JarFile(locationFile);
JarEntry je;
Manifest mf = jf.getManifest();
if (mf != null) {
Attributes mainAttrs = mf.getMainAttributes();
String appCtxPath = mainAttrs.getValue("Spring-Context");
if (appCtxPath != null) {
- String[] cxtPaths = appCtxPath.split(";");
- for (String path : cxtPaths) {
- je = jf.getJarEntry(path.trim());
- if (je != null)
- appCtxResources.add(new URL("jar:" + locationFile.toURI().toURL() + "!/" + appCtxPath));
- }
- return appCtxResources;
+ String[] cxtPaths = appCtxPath.split(";");
+ for (String path : cxtPaths) {
+ je = jf.getJarEntry(path.trim());
+ if (je != null)
+ appCtxResources.add(new URL("jar:" + locationFile.toURI().toURL()
+ + "!/"
+ + appCtxPath));
+ }
+ return appCtxResources;
}
}
// No MANIFEST.MF file OR no manifest-specified Spring context , then read all the
// .xml files available in the META-INF/spring folder.
Enumeration<JarEntry> entries = jf.entries();
while (entries.hasMoreElements()) {
- je = entries.nextElement();
- if (je.getName().startsWith("META-INF/spring/") && je.getName().endsWith(".xml")) {
- appCtxResources.add(new URL("jar:" + locationFile.toURI().toURL() + "!/" + je.getName()));
- }
+ je = entries.nextElement();
+ if (je.getName().startsWith("META-INF/spring/") && je.getName().endsWith(".xml")) {
+ appCtxResources.add(new URL("jar:" + locationFile.toURI().toURL() + "!/" + je.getName()));
+ }
}
return appCtxResources;
} catch (IOException e) {
// TODO: create a more appropriate exception type
- throw new ContributionReadException("SpringXMLComponentTypeLoader getApplicationContextResource: "
- + " IO exception reading context file.", e);
+ throw new ContributionReadException(
+ "SpringXMLComponentTypeLoader getApplicationContextResource: " + " IO exception reading context file.",
+ e);
}
- }
- else {
- if (locationFile.getName().endsWith(".xml")) {
- appCtxResources.add(url);
- return appCtxResources;
- }
- else {
- // Deal with the directory inside a jar file, in case the contribution itself is a JAR file.
- try {
- if (locationFile.getPath().indexOf(".jar") > 0) {
- String jarPath = url.getPath().substring(5, url.getPath().indexOf("!"));
- JarFile jf = new JarFile(jarPath);
- JarEntry je = jf.getJarEntry(url.getPath().substring(url.getPath().indexOf("!/")+2)
- + "/" + "META-INF" + "/" + "MANIFEST.MF");
- if (je != null) {
- Manifest mf = new Manifest(jf.getInputStream(je));
- Attributes mainAttrs = mf.getMainAttributes();
- String appCtxPath = mainAttrs.getValue("Spring-Context");
- if (appCtxPath != null) {
- String[] cxtPaths = appCtxPath.split(";");
- for (String path : cxtPaths) {
- je = jf.getJarEntry(url.getPath().substring(url.getPath().indexOf("!/")+2) + "/" + path.trim());
- if (je != null) {
- appCtxResources.add(new URL("jar:" + url.getPath() + "/" + path.trim()));
- }
- }
- return appCtxResources;
- }
- }
- // No MANIFEST.MF file OR no manifest-specified Spring context , then read all the
- // .xml files available in the META-INF/spring folder.
- Enumeration<JarEntry> entries = jf.entries();
- while (entries.hasMoreElements()) {
- je = entries.nextElement();
- if (je.getName().startsWith("META-INF/spring/") && je.getName().endsWith(".xml")) {
- appCtxResources.add(new URL("jar:" + url.getPath() + "/" + je.getName()));
- }
- }
+ } else {
+ if (locationFile.getName().endsWith(".xml")) {
+ appCtxResources.add(url);
+ return appCtxResources;
+ } else {
+ // Deal with the directory inside a jar file, in case the contribution itself is a JAR file.
+ try {
+ if (locationFile.getPath().indexOf(".jar") > 0) {
+ String jarPath = url.getPath().substring(5, url.getPath().indexOf("!"));
+ JarFile jf = new JarFile(jarPath);
+ JarEntry je =
+ jf.getJarEntry(url.getPath().substring(url.getPath().indexOf("!/") + 2) + "/"
+ + "META-INF"
+ + "/"
+ + "MANIFEST.MF");
+ if (je != null) {
+ Manifest mf = new Manifest(jf.getInputStream(je));
+ Attributes mainAttrs = mf.getMainAttributes();
+ String appCtxPath = mainAttrs.getValue("Spring-Context");
+ if (appCtxPath != null) {
+ String[] cxtPaths = appCtxPath.split(";");
+ for (String path : cxtPaths) {
+ je =
+ jf.getJarEntry(url.getPath().substring(url.getPath().indexOf("!/") + 2) + "/"
+ + path.trim());
+ if (je != null) {
+ appCtxResources.add(new URL("jar:" + url.getPath() + "/" + path.trim()));
+ }
+ }
+ return appCtxResources;
+ }
+ }
+ // No MANIFEST.MF file OR no manifest-specified Spring context , then read all the
+ // .xml files available in the META-INF/spring folder.
+ Enumeration<JarEntry> entries = jf.entries();
+ while (entries.hasMoreElements()) {
+ je = entries.nextElement();
+ if (je.getName().startsWith("META-INF/spring/") && je.getName().endsWith(".xml")) {
+ appCtxResources.add(new URL("jar:" + url.getPath() + "/" + je.getName()));
+ }
+ }
return appCtxResources;
- }
- } catch (IOException e) {
+ }
+ } catch (IOException e) {
throw new ContributionReadException("Error reading manifest " + manifestFile);
}
- }
- }
+ }
+ }
}
- throw new ContributionReadException("SpringXMLComponentTypeLoader getApplicationContextResource: "
- + "unable to read resource file " + url);
+ throw new ContributionReadException(
+ "SpringXMLComponentTypeLoader getApplicationContextResource: " + "unable to read resource file "
+ + url);
} // end method getApplicationContextResource
/**
@@ -1114,40 +1163,40 @@ public class SpringXMLComponentTypeLoade
return reference;
}
-
+
private class ContextClassLoader extends ClassLoader {
- public ContextClassLoader(ModelResolver resolver, ProcessorContext context) {
- super();
- this.resolver = resolver;
- this.context = context;
- }
-
- private ModelResolver resolver;
- private ProcessorContext context;
-
- @Override
- protected Class<?> findClass(String name) throws ClassNotFoundException {
- return SpringXMLComponentTypeLoader.this.resolveClass(resolver, name, context);
- }
-
- @Override
- protected URL findResource(String name) {
- try {
- return resolveLocation(resolver, name, context);
- } catch (Exception e) {
- return null;
- }
- }
-
- @Override
- protected Enumeration<URL> findResources(String name) throws IOException {
- URL url = findResource(name);
- if (url != null) {
- return Collections.enumeration(Arrays.asList(url));
- } else {
- Collection<URL> urls = Collections.emptyList();
- return Collections.enumeration(urls);
- }
- }
+ public ContextClassLoader(ModelResolver resolver, ProcessorContext context) {
+ super();
+ this.resolver = resolver;
+ this.context = context;
+ }
+
+ private ModelResolver resolver;
+ private ProcessorContext context;
+
+ @Override
+ protected Class<?> findClass(String name) throws ClassNotFoundException {
+ return SpringXMLComponentTypeLoader.this.resolveClass(resolver, name, context);
+ }
+
+ @Override
+ protected URL findResource(String name) {
+ try {
+ return resolveLocation(resolver, name, context);
+ } catch (Exception e) {
+ return null;
+ }
+ }
+
+ @Override
+ protected Enumeration<URL> findResources(String name) throws IOException {
+ URL url = findResource(name);
+ if (url != null) {
+ return Collections.enumeration(Arrays.asList(url));
+ } else {
+ Collection<URL> urls = Collections.emptyList();
+ return Collections.enumeration(urls);
+ }
+ }
}
-} // end class SpringXMLComponentTypeLoader
\ No newline at end of file
+} // end class SpringXMLComponentTypeLoader
Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ComponentTie.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ComponentTie.java?rev=980211&r1=980210&r2=980211&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ComponentTie.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/ComponentTie.java Wed Jul 28 21:01:00 2010
@@ -30,7 +30,7 @@ import org.apache.tuscany.sca.runtime.Ru
public class ComponentTie {
private RuntimeComponent component;
-
+
public ComponentTie(RuntimeComponent component) {
this.component = component;
}
Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/PropertyValueTie.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/PropertyValueTie.java?rev=980211&r1=980210&r2=980211&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/PropertyValueTie.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/PropertyValueTie.java Wed Jul 28 21:01:00 2010
@@ -35,7 +35,7 @@ public class PropertyValueTie {
private RuntimeComponent component;
private JavaPropertyValueObjectFactory propertyFactory;
-
+
public PropertyValueTie(RuntimeComponent component, JavaPropertyValueObjectFactory propertyFactory) {
this.component = component;
this.propertyFactory = propertyFactory;
@@ -46,8 +46,8 @@ public class PropertyValueTie {
for (ComponentProperty prop : props) {
if (prop.getName().equals(name)) {
return propertyFactory.createValueFactory(prop, prop.getValue(), type).getInstance();
- }
- }
+ }
+ }
return null; // property name not found
}
}
Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java?rev=980211&r1=980210&r2=980211&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringContextStub.java Wed Jul 28 21:01:00 2010
@@ -43,11 +43,11 @@ public class SpringContextStub {
private Method getBeanMethod;
public SpringContextStub(RuntimeComponent component,
- SpringImplementation implementation,
- ProxyFactory proxyService,
- JavaPropertyValueObjectFactory propertyValueObjectFactory) {
+ SpringImplementation implementation,
+ ProxyFactory proxyService,
+ JavaPropertyValueObjectFactory propertyValueObjectFactory) {
- initTie(component, implementation, propertyValueObjectFactory);
+ initTie(component, implementation, propertyValueObjectFactory);
}
@@ -60,14 +60,21 @@ public class SpringContextStub {
try {
- Class<?> stubClass = Class.forName("org.apache.tuscany.sca.implementation.spring.runtime.context.SpringImplementationStub", true, cl);
- Constructor<?> stubConstructor = stubClass.getConstructor(new Class<?>[]{Object.class});
- Object stub = stubConstructor.newInstance(new SpringImplementationTie(implementation, component, propertyValueObjectFactory));
-
- Class<?> tieClass = Class.forName("org.apache.tuscany.sca.implementation.spring.runtime.context.SpringContextTie", true, cl);
- Constructor<?> tieConstructor = tieClass.getConstructor(new Class<?>[]{stubClass, List.class});
+ Class<?> stubClass =
+ Class.forName("org.apache.tuscany.sca.implementation.spring.runtime.context.SpringImplementationStub",
+ true,
+ cl);
+ Constructor<?> stubConstructor = stubClass.getConstructor(new Class<?>[] {Object.class});
+ Object stub =
+ stubConstructor.newInstance(new SpringImplementationTie(implementation, component,
+ propertyValueObjectFactory));
+
+ Class<?> tieClass =
+ Class
+ .forName("org.apache.tuscany.sca.implementation.spring.runtime.context.SpringContextTie", true, cl);
+ Constructor<?> tieConstructor = tieClass.getConstructor(new Class<?>[] {stubClass, List.class});
this.tie = tieConstructor.newInstance(stub, implementation.getResource());
-
+
this.startMethod = tieClass.getMethod("start");
this.closeMethod = tieClass.getMethod("close");
this.getBeanMethod = tieClass.getMethod("getBean", String.class);
@@ -85,7 +92,7 @@ public class SpringContextStub {
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ e.printStackTrace();
throw new RuntimeException(e);
}
}
@@ -98,7 +105,7 @@ public class SpringContextStub {
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ e.printStackTrace();
throw new RuntimeException(e);
}
}
@@ -111,7 +118,7 @@ public class SpringContextStub {
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ e.printStackTrace();
throw new RuntimeException(e);
}
}
@@ -126,9 +133,9 @@ public class SpringContextStub {
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
- e.printStackTrace();
+ e.printStackTrace();
throw new RuntimeException(e);
}
}
-}
\ No newline at end of file
+}
Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java?rev=980211&r1=980210&r2=980211&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProvider.java Wed Jul 28 21:01:00 2010
@@ -33,12 +33,12 @@ import org.apache.tuscany.sca.runtime.Ru
*/
public class SpringImplementationProvider implements ImplementationProvider {
private RuntimeComponent component;
-
+
// A Spring application context object
private SpringContextStub springContext;
-
+
private SpringImplementation implementation;
-
+
private JavaPropertyValueObjectFactory propertyValueObjectFactory;
/**
@@ -56,14 +56,14 @@ public class SpringImplementationProvide
this.component = component;
this.propertyValueObjectFactory = propertyValueObjectFactory;
- springContext = new SpringContextStub(component, implementation, proxyService, propertyValueObjectFactory);
-
+ springContext = new SpringContextStub(component, implementation, proxyService, propertyValueObjectFactory);
+
} // end constructor
public Invoker createInvoker(RuntimeComponentService service, Operation operation) {
return new SpringInvoker(component, springContext, service, operation);
}
-
+
public boolean supportsOneWayInvocation() {
return false;
}
@@ -79,7 +79,7 @@ public class SpringImplementationProvide
* Stop this implementation instance
*/
public void stop() {
- springContext.close();
+ springContext.close();
}
} // end class SpringImplementationProvider
Modified: tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java?rev=980211&r1=980210&r2=980211&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java (original)
+++ tuscany/sca-java-2.x/trunk/modules/implementation-spring/src/main/java/org/apache/tuscany/sca/implementation/spring/invocation/SpringImplementationProviderFactory.java Wed Jul 28 21:01:00 2010
@@ -44,8 +44,8 @@ public class SpringImplementationProvide
*/
public SpringImplementationProviderFactory(ExtensionPointRegistry extensionPoints) {
super();
-
- proxyFactory = ExtensibleProxyFactory.getInstance(extensionPoints);
+
+ proxyFactory = ExtensibleProxyFactory.getInstance(extensionPoints);
// TODO: could the runtime have a default PropertyValueObjectFactory?
propertyFactory = new JavaPropertyValueObjectFactory(new MediatorImpl(extensionPoints));
@@ -60,10 +60,7 @@ public class SpringImplementationProvide
*/
public ImplementationProvider createImplementationProvider(RuntimeComponent component,
SpringImplementation implementation) {
- return new SpringImplementationProvider(component,
- implementation,
- proxyFactory,
- propertyFactory);
+ return new SpringImplementationProvider(component, implementation, proxyFactory, propertyFactory);
}
/**