
org.fabric3.implementation.system.singleton.SingletonComponent Maven / Gradle / Ivy
The newest version!
/*
* Fabric3
* Copyright (c) 2009-2015 Metaform Systems
*
* 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.
*
* Portions originally based on Apache Tuscany 2007
* licensed under the Apache 2.0 license.
*/
package org.fabric3.implementation.system.singleton;
import javax.xml.namespace.QName;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.fabric3.api.annotation.monitor.MonitorLevel;
import org.fabric3.implementation.pojo.objectfactory.ArrayMultiplicityObjectFactory;
import org.fabric3.implementation.pojo.objectfactory.ListMultiplicityObjectFactory;
import org.fabric3.implementation.pojo.objectfactory.MapMultiplicityObjectFactory;
import org.fabric3.implementation.pojo.objectfactory.MultiplicityObjectFactory;
import org.fabric3.implementation.pojo.objectfactory.SetMultiplicityObjectFactory;
import org.fabric3.spi.container.component.InstanceDestructionException;
import org.fabric3.spi.container.component.InstanceInitException;
import org.fabric3.spi.container.component.InstanceLifecycleException;
import org.fabric3.spi.container.component.ScopedComponent;
import org.fabric3.spi.model.type.java.FieldInjectionSite;
import org.fabric3.api.model.type.java.Injectable;
import org.fabric3.api.model.type.java.InjectableType;
import org.fabric3.api.model.type.java.InjectionSite;
import org.fabric3.spi.model.type.java.MethodInjectionSite;
import org.fabric3.spi.container.objectfactory.InjectionAttributes;
import org.fabric3.spi.container.objectfactory.ObjectCreationException;
import org.fabric3.spi.container.objectfactory.ObjectFactory;
import org.fabric3.spi.container.objectfactory.SingletonObjectFactory;
/**
* Wraps an object intended to serve as a system component provided to the Fabric3 runtime by the host environment.
*/
public class SingletonComponent implements ScopedComponent {
private final URI uri;
private Object instance;
private Map sites;
private Map reinjectionMappings;
private URI classLoaderId;
private MonitorLevel level = MonitorLevel.INFO;
private AtomicBoolean started = new AtomicBoolean(false);
public SingletonComponent(URI componentId, Object instance, Map mappings) {
this.uri = componentId;
this.instance = instance;
this.reinjectionMappings = new HashMap<>();
initializeInjectionSites(instance, mappings);
}
public URI getClassLoaderId() {
return classLoaderId;
}
public void setClassLoaderId(URI classLoaderId) {
this.classLoaderId = classLoaderId;
}
public String getKey() {
return null;
}
public URI getUri() {
return uri;
}
public void start() {
started.set(true);
}
public void stop() {
started.set(false);
}
public void startUpdate() {
for (ObjectFactory factory : reinjectionMappings.keySet()) {
if (factory instanceof MultiplicityObjectFactory) {
((MultiplicityObjectFactory) factory).startUpdate();
}
}
}
public void endUpdate() {
for (ObjectFactory factory : reinjectionMappings.keySet()) {
if (factory instanceof MultiplicityObjectFactory) {
((MultiplicityObjectFactory) factory).endUpdate();
}
}
}
public QName getDeployable() {
return null;
}
public boolean isEagerInit() {
return true;
}
public Object createInstance() throws ObjectCreationException {
return instance;
}
public void releaseInstance(Object instance) {
// no-op
}
public ObjectFactory
© 2015 - 2025 Weber Informatics LLC | Privacy Policy