Fixed lost reflection provider
[fedora-idea.git] / extensions / source / com / intellij / openapi / extensions / impl / ExtensionComponentAdapter.java
blob27ba75be5217181bccfa394c4a6121aa4b04027c
1 /*
2 * Copyright 2000-2005 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com.intellij.openapi.extensions.impl;
18 import com.intellij.openapi.extensions.*;
19 import com.thoughtworks.xstream.XStream;
20 import com.thoughtworks.xstream.core.util.CompositeClassLoader;
21 import com.thoughtworks.xstream.io.xml.JDomReader;
22 import org.jdom.Element;
23 import org.picocontainer.PicoContainer;
24 import org.picocontainer.PicoInitializationException;
25 import org.picocontainer.PicoIntrospectionException;
26 import org.picocontainer.defaults.AssignabilityRegistrationException;
27 import org.picocontainer.defaults.ConstructorInjectionComponentAdapter;
28 import org.picocontainer.defaults.NotConcreteRegistrationException;
30 /**
31 * @author Alexander Kireyev
33 public class ExtensionComponentAdapter extends ConstructorInjectionComponentAdapter implements LoadingOrder.Orderable {
34 private Object myComponentInstance;
35 private Element myExtensionElement;
36 private PicoContainer myContainer;
37 private PluginDescriptor myPluginDescriptor;
39 public ExtensionComponentAdapter(Class implementationClass, Element extensionElement, PicoContainer container, PluginDescriptor pluginDescriptor) {
40 super(new Object(), implementationClass);
41 myExtensionElement = extensionElement;
42 myContainer = container;
43 myPluginDescriptor = pluginDescriptor;
46 public Object getComponentInstance(final PicoContainer container) throws PicoInitializationException, PicoIntrospectionException, AssignabilityRegistrationException, NotConcreteRegistrationException {
47 //assert myContainer == container : "Different containers: " + myContainer + " - " + container;
49 if (myComponentInstance == null) {
50 if (!Element.class.equals(getComponentImplementation())) {
51 final CompositeClassLoader classLoader = new CompositeClassLoader();
52 if (myPluginDescriptor.getPluginClassLoader() != null) {
53 classLoader.add(myPluginDescriptor.getPluginClassLoader());
55 XStream xStream = new XStream(new PropertyReflectionProvider());
56 xStream.setClassLoader(classLoader);
57 xStream.registerConverter(new ElementConverter());
58 Object componentInstance = super.getComponentInstance(container);
59 if (componentInstance instanceof ReaderConfigurator) {
60 ReaderConfigurator readerConfigurator = (ReaderConfigurator) componentInstance;
61 readerConfigurator.configureReader(xStream);
63 xStream.alias(myExtensionElement.getName(), componentInstance.getClass());
64 myComponentInstance = xStream.unmarshal(new JDomReader(myExtensionElement), componentInstance);
66 else {
67 myComponentInstance = myExtensionElement;
69 if (myComponentInstance instanceof PluginAware) {
70 PluginAware pluginAware = (PluginAware) myComponentInstance;
71 pluginAware.setPluginDescriptor(myPluginDescriptor);
75 return myComponentInstance;
78 public Object getExtension() {
79 return getComponentInstance(myContainer);
82 public LoadingOrder getOrder() {
83 String orderAttr = myExtensionElement.getAttributeValue("order");
84 return LoadingOrder.readOrder(orderAttr);
87 public String getOrderId() {
88 return myExtensionElement.getAttributeValue("id");
91 public Element getExtensionElement() {
92 return myExtensionElement;
95 public Element getDescribingElement() {
96 return getExtensionElement();
99 public PluginId getPluginName() {
100 return myPluginDescriptor.getPluginId();