Hi, Jim/Jeremy.
I think I'm confused here. Are you saying the processor framework has
already been in the "trunk" so that we need to copy them over to the
"sandbox"? I need this feature to implement JavaComponentTypeLoader.
Also attached is a patch with the following things:
1) Skeleton for JavaImplementationLoader and JavaComponentTypeLoader
2) Make "loaderRegistry" protected in ComponentTypeLoaderExtension
3) Fixed some compiling issues
Thanks,
Raymond
3) What's the replacement for "org/apache/tuscany/core/config/**" which
uses
to host the class like "Java5ComponentTypeIntrospector"?
Jim added a more general annotation processing framework into core in
the trunk. The component type loaders should use that for
introspecting the implementation.
Yea the idea with that is it's visitor based which allows people to
extend it with custom processors (i.e. the runtime doesn't know about
any annotations). Jeremy mentioned he was going to plug this into the
load process, so when that's done we can look at how that fits into
the loader work.
Index:
containers/container.java/src/main/java/org/apache/tuscany/container/java/JavaComponentTypeLoader.java
===================================================================
---
containers/container.java/src/main/java/org/apache/tuscany/container/java/JavaComponentTypeLoader.java
(revision 0)
+++
containers/container.java/src/main/java/org/apache/tuscany/container/java/JavaComponentTypeLoader.java
(revision 0)
@@ -0,0 +1,112 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tuscany.container.java;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.core.loader.AssemblyConstants;
+import org.apache.tuscany.core.model.PojoComponentType;
+import org.apache.tuscany.core.util.JavaIntrospectionHelper;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.ComponentTypeLoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.loader.UnrecognizedElementException;
+import org.apache.tuscany.spi.model.ComponentType;
+
+/**
+ * @version $Rev$ $Date$
+ */
+public class JavaComponentTypeLoader extends
ComponentTypeLoaderExtension<JavaImplementation> {
+
+ public JavaComponentTypeLoader() {
+ super();
+ }
+
+ public void load(JavaImplementation implementation, DeploymentContext
deploymentContext) {
+ Class<?> implClass = implementation.getImplementationClass();
+ URL resource =
implClass.getResource(JavaIntrospectionHelper.getBaseName(implClass) +
".componentType");
+ try {
+ if (resource == null) {
+ loadByIntrospection(implementation);
+ } else {
+ loadFromSidefile(implementation, resource, deploymentContext);
+ }
+ } catch (LoaderException e) {
+ // throw new TuscanyRuntimeException(e);
+ }
+ }
+
+ protected void loadByIntrospection(JavaImplementation implementation) {
+ Class<?> implClass = implementation.getImplementationClass();
+ PojoComponentType componentType = null; // FIXME:
introspector.introspect(implClass);
+ implementation.setComponentType(componentType);
+ }
+
+ protected ComponentType loadFromSidefile(JavaImplementation
implementation, URL sidefile, DeploymentContext deploymentContext)
+ throws LoaderException {
+ try {
+ XMLStreamReader reader;
+ InputStream is;
+ is = sidefile.openStream();
+ try {
+ XMLInputFactory factory = deploymentContext.getXmlFactory();
+ reader = factory.createXMLStreamReader(is);
+ try {
+ reader.nextTag();
+ if
(!AssemblyConstants.COMPONENT_TYPE.equals(reader.getName())) {
+ UnrecognizedElementException e = new
UnrecognizedElementException(reader.getName());
+ e.setResourceURI(sidefile.toString());
+ throw e;
+ }
+ return (ComponentType) loaderRegistry.load(reader,
deploymentContext);
+ } finally {
+ try {
+ reader.close();
+ } catch (XMLStreamException e) {
+ // ignore
+ }
+ }
+ } finally {
+ try {
+ is.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ } catch (IOException e) {
+ LoaderException sfe = new LoaderException(e.getMessage());
+ sfe.setResourceURI(sidefile.toString());
+ throw sfe;
+ } catch (XMLStreamException e) {
+ LoaderException sfe = new LoaderException(e.getMessage());
+ sfe.setResourceURI(sidefile.toString());
+ throw sfe;
+ }
+ }
+
+ @Override
+ protected Class<JavaImplementation> getTypeClass() {
+ return JavaImplementation.class;
+ }
+
+}
Property changes on:
containers\container.java\src\main\java\org\apache\tuscany\container\java\JavaComponentTypeLoader.java
___________________________________________________________________
Name: svn:keywords
+ Rev,Date
Name: svn:eol-style
+ native
Index:
containers/container.java/src/main/java/org/apache/tuscany/container/java/JavaImplementationLoader.java
===================================================================
---
containers/container.java/src/main/java/org/apache/tuscany/container/java/JavaImplementationLoader.java
(revision 0)
+++
containers/container.java/src/main/java/org/apache/tuscany/container/java/JavaImplementationLoader.java
(revision 0)
@@ -0,0 +1,33 @@
+package org.apache.tuscany.container.java;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
+
+import org.apache.tuscany.core.loader.AssemblyConstants;
+import org.apache.tuscany.core.loader.StAXUtil;
+import org.apache.tuscany.spi.deployer.DeploymentContext;
+import org.apache.tuscany.spi.extension.LoaderExtension;
+import org.apache.tuscany.spi.loader.LoaderException;
+import org.apache.tuscany.spi.model.ModelObject;
+
+public class JavaImplementationLoader extends LoaderExtension {
+ public static final QName IMPLEMENTATION_JAVA = new
QName(AssemblyConstants.SCA_NAMESPACE, "implementation.java");
+
+ @Override
+ protected QName getXMLType() {
+ return IMPLEMENTATION_JAVA;
+ }
+
+ public ModelObject load(XMLStreamReader reader, DeploymentContext
deploymentContext) throws XMLStreamException, LoaderException {
+ assert IMPLEMENTATION_JAVA.equals(reader.getName());
+ JavaImplementation implementation = new JavaImplementation();
+ String implClass = reader.getAttributeValue(null, "class");
+ Class<?> implementationClass = StAXUtil.loadClass(implClass,
deploymentContext.getClassLoader());
+ implementation.setImplementationClass(implementationClass);
+ registry.loadComponentType(implementation, deploymentContext);
+ StAXUtil.skipToEndElement(reader);
+ return implementation;
+ }
+
+}
Property changes on:
containers\container.java\src\main\java\org\apache\tuscany\container\java\JavaImplementationLoader.java
___________________________________________________________________
Name: svn:keywords
+ Rev,Date
Name: svn:eol-style
+ native
Index:
containers/container.spring/src/test/java/org/apache/tuscany/container/spring/SpringReferenceTestCase.java
===================================================================
---
containers/container.spring/src/test/java/org/apache/tuscany/container/spring/SpringReferenceTestCase.java
(revision 409419)
+++
containers/container.spring/src/test/java/org/apache/tuscany/container/spring/SpringReferenceTestCase.java
(working copy)
@@ -39,7 +39,7 @@
private ConfigurableApplicationContext createSpringContext() {
StaticApplicationContext beanFactory = new StaticApplicationContext();
BeanDefinition definition = new RootBeanDefinition(TestBeanImpl.class);
- RuntimeBeanReference ref = new ("bar");
+ RuntimeBeanReference ref = new RuntimeBeanReference("bar");
PropertyValue val = new PropertyValue("bean", ref);
definition.getPropertyValues().addPropertyValue(val);
beanFactory.registerBeanDefinition("foo", definition);
Index:
core2/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.java
===================================================================
---
core2/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.java
(revision 409419)
+++
core2/src/main/java/org/apache/tuscany/core/monitor/JavaLoggingMonitorFactory.java
(working copy)
@@ -21,18 +21,18 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.HashMap;
+import java.util.Locale;
import java.util.Map;
+import java.util.MissingResourceException;
import java.util.Properties;
+import java.util.ResourceBundle;
import java.util.WeakHashMap;
-import java.util.ResourceBundle;
-import java.util.Locale;
-import java.util.MissingResourceException;
import java.util.logging.Level;
+import java.util.logging.LogRecord;
import java.util.logging.Logger;
-import java.util.logging.LogRecord;
-import org.apache.tuscany.common.monitor.LogLevel;
-import org.apache.tuscany.common.monitor.MonitorFactory;
+import org.apache.tuscany.spi.monitor.LogLevel;
+import org.apache.tuscany.spi.monitor.MonitorFactory;
/**
* A factory for monitors that forwards events to a [EMAIL PROTECTED]
java.util.logging.Logger Java Logging (JSR47) Logger}.
Index:
core2/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.java
===================================================================
--- core2/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.java
(revision 409419)
+++ core2/src/main/java/org/apache/tuscany/core/monitor/NullMonitorFactory.java
(working copy)
@@ -20,7 +20,7 @@
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
-import org.apache.tuscany.common.monitor.MonitorFactory;
+import org.apache.tuscany.spi.monitor.MonitorFactory;
/**
* Implementation of a [EMAIL PROTECTED] MonitorFactory} that produces
implementations that simply return.
Index:
core2/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java
===================================================================
---
core2/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java
(revision 409419)
+++
core2/src/test/java/org/apache/tuscany/core/monitor/JavaLoggingTestCase.java
(working copy)
@@ -26,9 +26,8 @@
import junit.framework.TestCase;
-import org.apache.tuscany.common.monitor.MonitorFactory;
-import org.apache.tuscany.common.monitor.LogLevel;
-import org.apache.tuscany.core.monitor.JavaLoggingMonitorFactory;
+import org.apache.tuscany.spi.monitor.LogLevel;
+import org.apache.tuscany.spi.monitor.MonitorFactory;
/**
* Test case for the JavaLoggingMonitorFactory.
Index:
spi/src/main/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtension.java
===================================================================
---
spi/src/main/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtension.java
(revision 409419)
+++
spi/src/main/java/org/apache/tuscany/spi/extension/ComponentTypeLoaderExtension.java
(working copy)
@@ -28,7 +28,7 @@
* @version $Rev$ $Date$
*/
public abstract class ComponentTypeLoaderExtension<T extends Implementation>
implements ComponentTypeLoader<T> {
- private LoaderRegistry loaderRegistry;
+ protected LoaderRegistry loaderRegistry;
@Property
public void setLoaderRegistry(LoaderRegistry loaderRegistry) {
Index: spi/src/main/java/org/apache/tuscany/spi/monitor/LogLevel.java
===================================================================
--- spi/src/main/java/org/apache/tuscany/spi/monitor/LogLevel.java
(revision 409419)
+++ spi/src/main/java/org/apache/tuscany/spi/monitor/LogLevel.java
(working copy)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.tuscany.common.monitor;
+package org.apache.tuscany.spi.monitor;
import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Retention;
Index: spi/src/main/java/org/apache/tuscany/spi/monitor/MonitorFactory.java
===================================================================
--- spi/src/main/java/org/apache/tuscany/spi/monitor/MonitorFactory.java
(revision 409419)
+++ spi/src/main/java/org/apache/tuscany/spi/monitor/MonitorFactory.java
(working copy)
@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.tuscany.common.monitor;
+package org.apache.tuscany.spi.monitor;
/**
* A MonitorFactory creates implementations of components' monitor interfaces
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]