summaryrefslogtreecommitdiffstats
path: root/tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl
diff options
context:
space:
mode:
Diffstat (limited to 'tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl')
-rw-r--r--tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/AbstractModuleComponentConfigurationLoader.java164
-rw-r--r--tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/Java5ComponentTypeIntrospector.java139
-rw-r--r--tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/StAXModuleComponentConfigurationLoaderImpl.java91
3 files changed, 0 insertions, 394 deletions
diff --git a/tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/AbstractModuleComponentConfigurationLoader.java b/tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/AbstractModuleComponentConfigurationLoader.java
deleted file mode 100644
index a77031b8c5..0000000000
--- a/tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/AbstractModuleComponentConfigurationLoader.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- *
- * Copyright 2005 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.core.config.impl;
-
-import org.apache.tuscany.common.resource.ResourceLoader;
-import org.apache.tuscany.core.config.ConfigurationLoadException;
-import org.apache.tuscany.core.config.ModuleComponentConfigurationLoader;
-import org.apache.tuscany.core.config.ComponentTypeIntrospector;
-import org.apache.tuscany.core.config.processor.ProcessorUtils;
-import org.apache.tuscany.core.system.context.SystemCompositeContextImpl;
-import org.apache.tuscany.core.context.impl.CompositeContextImpl;
-import org.apache.tuscany.model.assembly.AssemblyFactory;
-import org.apache.tuscany.model.assembly.AssemblyContext;
-import org.apache.tuscany.model.assembly.Module;
-import org.apache.tuscany.model.assembly.ModuleComponent;
-import org.apache.tuscany.model.assembly.ModuleFragment;
-import org.apache.tuscany.model.assembly.ComponentType;
-
-import java.io.IOException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * @version $Rev$ $Date$
- */
-public abstract class AbstractModuleComponentConfigurationLoader implements ModuleComponentConfigurationLoader {
- private static final String SCA_MODULE_FILE_NAME = "sca.module";
- //FIXME can fragments have a variable prefix name?
- private static final String SCA_FRAGMENT_FILE_NAME = "sca.fragment";
- private static final String SYSTEM_MODULE_FILE_NAME = "system.module";
- //FIXME can fragments have a variable prefix name?
- private static final String SYSTEM_FRAGMENT_FILE_NAME = "system.fragment";
-
- protected final AssemblyContext modelContext;
- protected final ResourceLoader resourceLoader;
- protected final AssemblyFactory assemblyFactory;
-
- // JFM HACK
- private ComponentTypeIntrospector introspector;
-
- private ComponentType systemType;
-
- private ComponentType compositeType;
-
- protected ComponentTypeIntrospector getIntrospector(){
- if (introspector == null){
- introspector = ProcessorUtils.createCoreIntrospector(assemblyFactory);
- }
- return introspector;
- }
-
- protected ComponentType getSystemCompositeComponentType() throws ConfigurationLoadException {
- if (systemType == null){
- systemType = getIntrospector().introspect(SystemCompositeContextImpl.class);
- }
- return systemType;
- }
-
- protected ComponentType getCompositeComponentType() throws ConfigurationLoadException {
- if (compositeType == null){
- compositeType = getIntrospector().introspect(CompositeContextImpl.class);
- }
- return compositeType;
- }
- /// JFM HACK
-
- protected AbstractModuleComponentConfigurationLoader(AssemblyContext modelContext) {
- this.modelContext = modelContext;
- resourceLoader = modelContext.getApplicationResourceLoader();
- assemblyFactory = modelContext.getAssemblyFactory();
- }
-
- public ModuleComponent loadSystemModuleComponent(String name, String uri) throws ConfigurationLoadException {
- ModuleComponent mc = loadModuleComponent(SYSTEM_MODULE_FILE_NAME, SYSTEM_FRAGMENT_FILE_NAME, name, uri);
- //JFM HACK - this is completely gross since it overwrites existing component type
- mc.getImplementation().setImplementationClass(SystemCompositeContextImpl.class);
- mc.getImplementation().setComponentType(getSystemCompositeComponentType());
- //END HACK
- return mc;
- }
-
- public ModuleComponent loadModuleComponent(String name, String uri) throws ConfigurationLoadException {
- ModuleComponent mc = loadModuleComponent(SCA_MODULE_FILE_NAME, SCA_FRAGMENT_FILE_NAME, name, uri);
- //JFM HACK
- mc.getImplementation().setImplementationClass(CompositeContextImpl.class);
- mc.getImplementation().setComponentType(getCompositeComponentType());
- //END HACK
- return mc;
- }
-
- protected ModuleComponent loadModuleComponent(String moduleFileName, String fragmentFileName, String name, String uri) throws ConfigurationLoadException {
-
- // Load the sca.module file
- URL moduleUrl;
- moduleUrl = resourceLoader.getResource(moduleFileName);
-
-
- if (moduleUrl == null) {
- throw new ConfigurationLoadException(moduleFileName);
- }
-
- // Load the sca.fragment files
- Iterator<URL> i;
- try {
- i = resourceLoader.getResources(fragmentFileName);
- } catch (IOException e) {
- throw new ConfigurationLoadException(fragmentFileName, e);
- }
- List<URL> moduleFragmentUris=new ArrayList<URL>();
- while (i.hasNext()) {
- URL url=i.next();
- moduleFragmentUris.add(url);
- }
-
- return loadModuleComponent(name, uri, moduleUrl, moduleFragmentUris);
- }
-
- public ModuleComponent loadModuleComponent(String name, String uri, URL url) throws ConfigurationLoadException {
- return loadModuleComponent( name, uri, url, null);
- }
-
- public ModuleComponent loadModuleComponent(String name, String uri, URL moduleUri, Collection<URL> moduleFragmentUris) throws ConfigurationLoadException {
-
- // Load the module file
- Module module=loadModule(moduleUri);
- // Load the sca.fragment files
- if (moduleFragmentUris!=null) {
- for (URL moduleFragmentUri : moduleFragmentUris) {
- ModuleFragment moduleFragment=loadModuleFragment(moduleFragmentUri);
- module.getModuleFragments().add(moduleFragment);
- }
- }
-
- // Create the module component
- ModuleComponent moduleComponent=assemblyFactory.createModuleComponent();
- moduleComponent.setName(name);
- moduleComponent.setURI(uri);
- moduleComponent.setImplementation(module);
- moduleComponent.initialize(modelContext);
-
- return moduleComponent;
- }
-
- public abstract Module loadModule(URL url) throws ConfigurationLoadException;
-
- public abstract ModuleFragment loadModuleFragment(URL url) throws ConfigurationLoadException;
-}
diff --git a/tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/Java5ComponentTypeIntrospector.java b/tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/Java5ComponentTypeIntrospector.java
deleted file mode 100644
index fdbb6e0942..0000000000
--- a/tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/Java5ComponentTypeIntrospector.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.core.config.impl;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-
-import org.apache.tuscany.core.config.ComponentTypeIntrospector;
-import org.apache.tuscany.core.config.ConfigurationLoadException;
-import org.apache.tuscany.core.config.JavaIntrospectionHelper;
-import org.apache.tuscany.core.config.processor.ProcessorUtils;
-import org.apache.tuscany.core.extension.config.ImplementationProcessor;
-import org.apache.tuscany.core.system.annotation.Autowire;
-import org.apache.tuscany.core.system.assembly.SystemAssemblyFactory;
-import org.apache.tuscany.model.assembly.AssemblyFactory;
-import org.apache.tuscany.model.assembly.ComponentType;
-import org.osoa.sca.annotations.Init;
-import org.osoa.sca.annotations.ComponentName;
-
-/**
- * Introspects Java annotation-based metata data
- *
- * @version $Rev$ $Date$
- */
-@org.osoa.sca.annotations.Service(ComponentTypeIntrospector.class)
-public class Java5ComponentTypeIntrospector implements ComponentTypeIntrospector {
-
- private AssemblyFactory factory;
-
- private List<ImplementationProcessor> processors = new ArrayList<ImplementationProcessor>();
-
- public Java5ComponentTypeIntrospector() {
- }
-
- public Java5ComponentTypeIntrospector(AssemblyFactory factory) {
- this.factory = factory;
- }
-
- @Autowire
- public void setFactory(SystemAssemblyFactory factory) {
- this.factory = factory;
- //FIXME JFM HACK
- List<ImplementationProcessor> processors = ProcessorUtils.createCoreProcessors(factory);
- for (ImplementationProcessor processor : processors) {
- this.registerProcessor(processor);
- }
- // END hack
- }
-
- @ComponentName
- protected String name;
-
- @Init(eager = true)
- public void init(){
- }
-
- public void registerProcessor(ImplementationProcessor processor) {
- processors.add(processor);
- }
-
- public void unregisterProcessor(ImplementationProcessor processor) {
- processors.remove(processor);
- }
-
- /**
- * Visits the given implementation type and calls back to {@link org.apache.tuscany.core.extension.config.ImplementationProcessor}s
- * registered with this introspector to build up a {@link ComponentType}
- *
- * @return ComponentType representing the implementation type metadata
- * @throws ConfigurationLoadException if there is an error introspecting the implementation type
- */
- public ComponentType introspect(Class<?> implClass) throws ConfigurationLoadException {
- ComponentType compType = factory.createComponentType();
- return introspect(implClass, compType);
- }
-
- public ComponentType introspect(Class<?> implClass, ComponentType compType) throws ConfigurationLoadException {
- for (ImplementationProcessor processor : processors) {
- processor.visitClass(implClass, compType);
- }
- Constructor[] constructors = implClass.getConstructors();
- for (Constructor constructor : constructors) {
- for (ImplementationProcessor processor : processors) {
- processor.visitConstructor(constructor, compType);
- }
- }
- Method[] methods = implClass.getMethods();
- for (Method method : methods) {
- for (ImplementationProcessor processor : processors) {
- processor.visitMethod(method, compType);
- }
- }
- Set<Field> fields = JavaIntrospectionHelper.getAllPublicAndProtectedFields(implClass);
- for (Field field : fields) {
- for (ImplementationProcessor processor : processors) {
- processor.visitField(field, compType);
- }
- }
- Class superClass = implClass.getSuperclass();
- if (superClass != null) {
- visitSuperClass(superClass, compType);
- }
- for (ImplementationProcessor processor : processors) {
- processor.visitEnd(implClass, compType);
- }
- return compType;
- }
-
- private void visitSuperClass(Class<?> superClass, ComponentType compType) throws ConfigurationLoadException {
- if (!Object.class.equals(superClass)) {
- for (ImplementationProcessor processor : processors) {
- processor.visitSuperClass(superClass, compType);
- }
- superClass = superClass.getSuperclass();
- if (superClass != null) {
- visitSuperClass(superClass, compType);
- }
- }
- }
-
-}
diff --git a/tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/StAXModuleComponentConfigurationLoaderImpl.java b/tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/StAXModuleComponentConfigurationLoaderImpl.java
deleted file mode 100644
index 3bd6e6361d..0000000000
--- a/tags/java-M1-20060522/java/sca/core/src/main/java/org/apache/tuscany/core/config/impl/StAXModuleComponentConfigurationLoaderImpl.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/**
- *
- * Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
- *
- * 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.core.config.impl;
-
-import org.apache.tuscany.core.config.ConfigurationLoadException;
-import org.apache.tuscany.core.loader.StAXLoaderRegistry;
-import org.apache.tuscany.core.loader.LoaderContext;
-import org.apache.tuscany.model.assembly.AssemblyContext;
-import org.apache.tuscany.model.assembly.Module;
-import org.apache.tuscany.model.assembly.ModuleFragment;
-
-import javax.xml.stream.XMLInputFactory;
-import javax.xml.stream.XMLStreamConstants;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import java.io.IOException;
-import java.net.URL;
-
-/**
- * @version $Rev$ $Date$
- */
-public class StAXModuleComponentConfigurationLoaderImpl extends AbstractModuleComponentConfigurationLoader {
- private final XMLInputFactory xmlFactory;
- private final StAXLoaderRegistry registry;
-
- public StAXModuleComponentConfigurationLoaderImpl(AssemblyContext modelContext, XMLInputFactory xmlFactory, StAXLoaderRegistry registry) {
- super(modelContext);
- this.xmlFactory = xmlFactory;
- this.registry = registry;
- }
-
- public Module loadModule(URL url) throws ConfigurationLoadException {
- registry.setContext(modelContext);
- try {
- XMLStreamReader reader = xmlFactory.createXMLStreamReader(url.openStream());
- getDocumentRoot(reader);
- return (Module) registry.load(reader, new LoaderContext(resourceLoader));
- } catch (XMLStreamException e) {
- ConfigurationLoadException ce = new ConfigurationLoadException(e);
- ce.setResourceURI(url.toString());
- throw ce;
- } catch (IOException e) {
- ConfigurationLoadException ce = new ConfigurationLoadException(e);
- ce.setResourceURI(url.toString());
- throw ce;
- } finally {
- registry.setContext(null);
- }
- }
-
- public ModuleFragment loadModuleFragment(URL url) throws ConfigurationLoadException {
- registry.setContext(modelContext);
- try {
- XMLStreamReader reader = xmlFactory.createXMLStreamReader(url.openStream());
- getDocumentRoot(reader);
- return (ModuleFragment) registry.load(reader, new LoaderContext(resourceLoader));
- } catch (XMLStreamException e) {
- ConfigurationLoadException ce = new ConfigurationLoadException(e);
- ce.setResourceURI(url.toString());
- throw ce;
- } catch (IOException e) {
- ConfigurationLoadException ce = new ConfigurationLoadException(e);
- ce.setResourceURI(url.toString());
- throw ce;
- } finally {
- registry.setContext(null);
- }
- }
-
- private static void getDocumentRoot(XMLStreamReader reader) throws XMLStreamException {
- while (true) {
- if (reader.next() == XMLStreamConstants.START_ELEMENT) {
- return;
- }
- }
- }
-}