diff options
author | sboshev | 2011-01-12 09:44:54 +0000 |
---|---|---|
committer | sboshev | 2011-01-12 09:44:54 +0000 |
commit | a06ba04900a8b24a691a7917dc2333ef8e1656fa (patch) | |
tree | 8d5f7e22936246e4be631bfb6363d0bf67c0342e /bundles/org.eclipse.equinox.ds/src | |
parent | 4ee7ff9360e3fa68fdd2c3d35f98019280001524 (diff) | |
download | rt.equinox.bundles-a06ba04900a8b24a691a7917dc2333ef8e1656fa.tar.gz rt.equinox.bundles-a06ba04900a8b24a691a7917dc2333ef8e1656fa.tar.xz rt.equinox.bundles-a06ba04900a8b24a691a7917dc2333ef8e1656fa.zip |
The SCR public API now returns read only properties
Diffstat (limited to 'bundles/org.eclipse.equinox.ds/src')
5 files changed, 38 insertions, 26 deletions
diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ComponentContextImpl.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ComponentContextImpl.java index 2db15e068..586204202 100644 --- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ComponentContextImpl.java +++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ComponentContextImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1997-2010 by ProSyst Software GmbH + * Copyright (c) 1997-2011 by ProSyst Software GmbH * http://www.prosyst.com * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -12,7 +12,8 @@ *******************************************************************************/ package org.eclipse.equinox.internal.ds.impl; -import java.util.*; +import java.util.Dictionary; +import java.util.Vector; import org.eclipse.equinox.internal.ds.*; import org.eclipse.equinox.internal.ds.model.*; import org.eclipse.osgi.util.NLS; @@ -38,8 +39,6 @@ public class ComponentContextImpl implements ComponentContext { private SCRManager mgr; - private ReadOnlyDictionary props; - public ComponentContextImpl(ServiceComponentProp scp, Bundle usingBundle, ComponentInstanceImpl ci, SCRManager mgr) { this.scp = scp; this.componentInstance = ci; @@ -53,14 +52,7 @@ public class ComponentContextImpl implements ComponentContext { * @see org.osgi.service.component.ComponentContext#getProperties() */ public Dictionary getProperties() { - if (props == null) { - props = new ReadOnlyDictionary((Hashtable) scp.getProperties()); - } else if (props.delegate != scp.getProperties()) { - // the scp properties have been modified by configuration - // update the instance with the new properties - props.delegate = (Hashtable) scp.getProperties(); - } - return props; + return scp.getProperties(); } /* diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ComponentFactoryImpl.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ComponentFactoryImpl.java index 5f28eabe9..9a3d8e2b3 100644 --- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ComponentFactoryImpl.java +++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ComponentFactoryImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1997-2009 by ProSyst Software GmbH + * Copyright (c) 1997-2011 by ProSyst Software GmbH * http://www.prosyst.com * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -58,7 +58,7 @@ public class ComponentFactoryImpl implements ComponentFactory { } // merge properties - Hashtable props = (Hashtable) ((Hashtable) sci.getProperties()).clone(); + Hashtable props = new Hashtable((Map) sci.getProperties()); SCRUtil.copyTo(props, additionalProps); // create a new SCP (adds to resolver scpEnabled list) diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ReadOnlyDictionary.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ReadOnlyDictionary.java index f1e29914e..c58f7740f 100644 --- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ReadOnlyDictionary.java +++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/impl/ReadOnlyDictionary.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1997-2010 by ProSyst Software GmbH + * Copyright (c) 1997-2011 by ProSyst Software GmbH * http://www.prosyst.com * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -18,21 +18,25 @@ import java.util.*; * * @author Stoyan Boshev */ -class ReadOnlyDictionary extends Dictionary implements Map { +public class ReadOnlyDictionary extends Dictionary implements Map { private static final long serialVersionUID = 1L; - Hashtable delegate; + Map delegate; /** * Creates a new ReadOnlyDictionary with initial set of properties * * @param initialProps the initialProperties for this hashtable */ - ReadOnlyDictionary(Hashtable initialProps) { + public ReadOnlyDictionary(Map initialProps) { this.delegate = initialProps; } + public void updateDelegate(Map newDelegate) { + this.delegate = newDelegate; + } + /* (non-Javadoc) * @see java.util.Dictionary#put(K, V) */ @@ -67,14 +71,14 @@ class ReadOnlyDictionary extends Dictionary implements Map { * @see java.util.Dictionary#keys() */ public Enumeration keys() { - return delegate.keys(); + return Collections.enumeration(delegate.keySet()); } /* (non-Javadoc) * @see java.util.Dictionary#elements() */ public Enumeration elements() { - return delegate.elements(); + return Collections.enumeration(delegate.values()); } /* (non-Javadoc) diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ServiceComponent.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ServiceComponent.java index c3811e5a5..f05961727 100644 --- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ServiceComponent.java +++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ServiceComponent.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1997-2009 by ProSyst Software GmbH + * Copyright (c) 1997-2011 by ProSyst Software GmbH * http://www.prosyst.com * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -20,6 +20,7 @@ import java.util.*; import org.apache.felix.scr.Component; import org.apache.felix.scr.Reference; import org.eclipse.equinox.internal.ds.*; +import org.eclipse.equinox.internal.ds.impl.ReadOnlyDictionary; import org.eclipse.equinox.internal.util.io.Externalizable; import org.eclipse.equinox.internal.util.io.ExternalizableDictionary; import org.eclipse.osgi.util.NLS; @@ -84,6 +85,7 @@ public class ServiceComponent implements Externalizable, Component { // --- end: model public HashSet componentIssues = new HashSet(1, 1); + private ReadOnlyDictionary readOnlyProps; public String getComponentIssues() { if (!componentIssues.isEmpty()) { @@ -859,7 +861,14 @@ public class ServiceComponent implements Externalizable, Component { } public Dictionary getProperties() { - return properties; + if (readOnlyProps == null) { + readOnlyProps = new ReadOnlyDictionary(properties); + } else { + // the scp properties may have been modified by configuration + // update the instance with the current properties + readOnlyProps.updateDelegate(properties); + } + return readOnlyProps; } public Reference[] getReferences() { diff --git a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ServiceComponentProp.java b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ServiceComponentProp.java index 42e1d2197..d6d444acb 100644 --- a/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ServiceComponentProp.java +++ b/bundles/org.eclipse.equinox.ds/src/org/eclipse/equinox/internal/ds/model/ServiceComponentProp.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 1997-2009 by ProSyst Software GmbH + * Copyright (c) 1997-2011 by ProSyst Software GmbH * http://www.prosyst.com * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -16,8 +16,7 @@ import java.security.*; import java.util.*; import org.apache.felix.scr.Component; import org.eclipse.equinox.internal.ds.*; -import org.eclipse.equinox.internal.ds.impl.ComponentContextImpl; -import org.eclipse.equinox.internal.ds.impl.ComponentInstanceImpl; +import org.eclipse.equinox.internal.ds.impl.*; import org.eclipse.osgi.util.NLS; import org.osgi.framework.*; import org.osgi.service.component.*; @@ -70,6 +69,7 @@ public class ServiceComponentProp implements Component, PrivilegedExceptionActio protected Vector delayActivateSCPNames; private SCRManager mgr; + private ReadOnlyDictionary readOnlyProps; // next free component id private static long componentid = 0; @@ -113,7 +113,14 @@ public class ServiceComponentProp implements Component, PrivilegedExceptionActio * @return Dictionary properties */ public Dictionary getProperties() { - return properties != null ? properties : serviceComponent.properties; + if (readOnlyProps == null) { + readOnlyProps = new ReadOnlyDictionary(properties != null ? properties : serviceComponent.properties); + } else { + // the scp properties may have been modified by configuration + // update the instance with the current properties + readOnlyProps.updateDelegate(properties != null ? properties : serviceComponent.properties); + } + return readOnlyProps; } /** |