Skip to content

Commit

Permalink
Format java files in o.e.equinox.metatype
Browse files Browse the repository at this point in the history
This was achieved by running:
eclipse -consolelog -nosplash -application org.eclipse.jdt.core.JavaCodeFormatter \
  -config .settings/org.eclipse.jdt.core.prefs . -data `mktemp -d`

Signed-off-by: Torbjörn SVENSSON <[email protected]>
  • Loading branch information
Torbjorn-Svensson authored and vogella committed Oct 13, 2023
1 parent 92470d2 commit 6c308b7
Show file tree
Hide file tree
Showing 19 changed files with 621 additions and 512 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,35 @@
import org.osgi.service.metatype.AttributeDefinition;

/**
* An {@link Extendable extendable} version of {@link AttributeDefinition
* attribute definition} allowing access to any {@link
* Extendable#getExtensionAttributes(String) extension attributes} provided by
* third parties.
* An {@link Extendable extendable} version of {@link AttributeDefinition
* attribute definition} allowing access to any
* {@link Extendable#getExtensionAttributes(String) extension attributes}
* provided by third parties.
* <p/>
* For example, an Equinox attribute definition will contain all XML attributes
* specified as part of the &lt;AD/&gt; element with namespaces other than the
* specified as part of the &lt;AD/&gt; element with namespaces other than the
* metatype namespace as extension attributes.
*
* @since 1.2
* @noimplement This interface is not intended to be implemented by clients.
*/
public interface EquinoxAttributeDefinition extends AttributeDefinition, Extendable {
/**
* Get the maximum value this attribute may hold as specified by the
* optional "max" XML attribute of the &lt;AD&gt; element.
* Get the maximum value this attribute may hold as specified by the optional
* "max" XML attribute of the &lt;AD&gt; element.
*
* @return The maximum value this attribute may hold, or <code>null</code>
* if unspecified.
* @return The maximum value this attribute may hold, or <code>null</code> if
* unspecified.
* @since 1.3
*/
public String getMax();

/**
* Get the minimum value this attribute may hold as specified by the
* optional "min" XML attribute of the &lt;AD&gt; element.
* Get the minimum value this attribute may hold as specified by the optional
* "min" XML attribute of the &lt;AD&gt; element.
*
* @return The minimum value this attribute may hold, or <code>null</code>
* if unspecified.
* @return The minimum value this attribute may hold, or <code>null</code> if
* unspecified.
* @since 1.3
*/
public String getMin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/
public interface EquinoxMetaTypeInformation extends MetaTypeInformation {
/**
* Returns {@link Extendable extendable} versions of {@link
* EquinoxObjectClassDefinition object class definitions}.
* Returns {@link Extendable extendable} versions of
* {@link EquinoxObjectClassDefinition object class definitions}.
*/
EquinoxObjectClassDefinition getObjectClassDefinition(String id, String locale);
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
import org.osgi.service.metatype.MetaTypeService;

/**
* A {@link MetaTypeService} providing {@link MetaTypeInformation} instances
* with {@link Extendable extendable} versions of {@link
* EquinoxObjectClassDefinition object class definitions}.
* A {@link MetaTypeService} providing {@link MetaTypeInformation} instances
* with {@link Extendable extendable} versions of
* {@link EquinoxObjectClassDefinition object class definitions}.
*
* @since 1.2
*
*/
public interface EquinoxMetaTypeService extends MetaTypeService {
/**
* Returns a {@link MetaTypeInformation} that provides {@link Extendable
* Returns a {@link MetaTypeInformation} that provides {@link Extendable
* extendable} versions of {@link EquinoxObjectClassDefinition object class
* definitions}.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
import org.osgi.service.metatype.ObjectClassDefinition;

/**
* An {@link Extendable extendable} version of {@link ObjectClassDefinition
* object class definition} allowing access to any {@link
* Extendable#getExtensionAttributes(String) extension attributes} provided by
* third parties.
* An {@link Extendable extendable} version of {@link ObjectClassDefinition
* object class definition} allowing access to any
* {@link Extendable#getExtensionAttributes(String) extension attributes}
* provided by third parties.
* <p/>
* For example, an Equinox object class definition will contain all XML
* For example, an Equinox object class definition will contain all XML
* attributes specified as part of the &lt;OCD/&gt; element with namespaces
* other than the metatype namespace as extension attributes.
*
Expand All @@ -27,8 +27,8 @@
*/
public interface EquinoxObjectClassDefinition extends ObjectClassDefinition, Extendable {
/**
* Returns {@link Extendable extendable} versions of {@link
* EquinoxAttributeDefinition attribute definitions}.
* Returns {@link Extendable extendable} versions of
* {@link EquinoxAttributeDefinition attribute definitions}.
*/
EquinoxAttributeDefinition[] getAttributeDefinitions(int filter);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,32 +18,33 @@
* attribute is a property that describes the object. An extension attribute is
* a custom property added by a third party.
*
* The use case for this interface was to expose third party attributes
* included in the metadata XML on elements that support <anyAttribute/>
* according to the metatype schema, but it is not strictly limited to this use.
* The use case for this interface was to expose third party attributes included
* in the metadata XML on elements that support <anyAttribute/> according to the
* metatype schema, but it is not strictly limited to this use.
*
* @since 1.2
*
*/
public interface Extendable {
/**
* Returns a {@link Map map} containing the extension attributes for the
* specified {@link #getExtensionUris() URI}. The map key is the attribute
* name, and the map value is the attribute value. If the specified URI has
* no extension attributes, the map will be {@code null}.
* specified {@link #getExtensionUris() URI}. The map key is the attribute name,
* and the map value is the attribute value. If the specified URI has no
* extension attributes, the map will be {@code null}.
*
* @param uri - The URI for which extension attributes are desired.
* @return A map containing the extension attributes for the specified URI,
* or {@code null} if there are none.
* @return A map containing the extension attributes for the specified URI, or
* {@code null} if there are none.
* @see #getExtensionUris()
*/
Map<String, String> getExtensionAttributes(String uri);

/**
* Returns the {@link Set set} of URIs for which {@link
* #getExtensionAttributes(String) extension attributes} exist. It is
* guaranteed that there is at least one extension attribute for each URI
* in the set.
* Returns the {@link Set set} of URIs for which
* {@link #getExtensionAttributes(String) extension attributes} exist. It is
* guaranteed that there is at least one extension attribute for each URI in the
* set.
*
* @return A set containing the URIs for which extension attributes exist.
* @see #getExtensionAttributes(String)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,26 @@
*/
public class Activator implements BundleActivator {
/*
* The following filter guarantees only services meeting the following
* criteria will be tracked.
* The following filter guarantees only services meeting the following criteria
* will be tracked.
*
* (1) A ManagedService or ManagedServiceFactory registered with a
* SERVICE_PID property. May also be registered as a MetaTypeProvider.
* (2) A MetaTypeProvider registered with a METATYPE_PID or
* METATYPE_FACTORY_PID property.
* (1) A ManagedService or ManagedServiceFactory registered with a SERVICE_PID
* property. May also be registered as a MetaTypeProvider. (2) A
* MetaTypeProvider registered with a METATYPE_PID or METATYPE_FACTORY_PID
* property.
*
* Note that it's still necessary to inspect a ManagedService or
* ManagedServiceFactory to ensure it also implements MetaTypeProvider.
*/
private static final String FILTER = "(|(&(" + Constants.OBJECTCLASS + '=' + ManagedService.class.getName() + "*)(" + Constants.SERVICE_PID + "=*))(&(" + Constants.OBJECTCLASS + '=' + MetaTypeProvider.class.getName() + ")(|(" + MetaTypeProvider.METATYPE_PID + "=*)(" + MetaTypeProvider.METATYPE_FACTORY_PID + "=*))))"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
private static final String FILTER = "(|(&(" + Constants.OBJECTCLASS + '=' + ManagedService.class.getName() + "*)(" //$NON-NLS-1$ //$NON-NLS-2$
+ Constants.SERVICE_PID + "=*))(&(" + Constants.OBJECTCLASS + '=' + MetaTypeProvider.class.getName() //$NON-NLS-1$
+ ")(|(" + MetaTypeProvider.METATYPE_PID + "=*)(" + MetaTypeProvider.METATYPE_FACTORY_PID + "=*))))"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
private static final String SERVICE_PID = "org.osgi.impl.service.metatype.MetaTypeService"; //$NON-NLS-1$

private LogTracker logServiceTracker;
// Could be ManagedService, ManagedServiceFactory, or MetaTypeProvider.
// The tracker tracks all services regardless of bundle. Services are
// filtered by bundle later in the MetaTypeProviderTracker class. It may
// filtered by bundle later in the MetaTypeProviderTracker class. It may
// therefore be shared among multiple instances of that class.
private ServiceTracker<Object, Object> metaTypeProviderTracker;
private ServiceTracker<SAXParserFactory, SAXParserFactory> saxParserFactoryTracker;
Expand All @@ -60,7 +62,8 @@ public void start(BundleContext context) throws InvalidSyntaxException {
synchronized (this) {
lsTracker = logServiceTracker = new LogTracker(context, System.out);
mtpTracker = metaTypeProviderTracker = new ServiceTracker<>(context, filter, null);
spfTracker = saxParserFactoryTracker = new ServiceTracker<>(context, SAXParserFactory.class, new SAXParserFactoryTrackerCustomizer(context, lsTracker, mtpTracker));
spfTracker = saxParserFactoryTracker = new ServiceTracker<>(context, SAXParserFactory.class,
new SAXParserFactoryTrackerCustomizer(context, lsTracker, mtpTracker));
}
// Do this first to make logging available as early as possible.
lsTracker.open();
Expand Down Expand Up @@ -95,7 +98,8 @@ synchronized ServiceTracker<SAXParserFactory, SAXParserFactory> getSAXParserFact
return saxParserFactoryTracker;
}

private class SAXParserFactoryTrackerCustomizer implements ServiceTrackerCustomizer<SAXParserFactory, SAXParserFactory> {
private class SAXParserFactoryTrackerCustomizer
implements ServiceTrackerCustomizer<SAXParserFactory, SAXParserFactory> {
private final BundleContext bundleCtx;
private final LogTracker logService;
private final ServiceTracker<Object, Object> mtpTracker;
Expand All @@ -104,7 +108,8 @@ private class SAXParserFactoryTrackerCustomizer implements ServiceTrackerCustomi
private ServiceRegistration<?> metaTypeServiceRegistration;
private SAXParserFactory saxParserFactory;

public SAXParserFactoryTrackerCustomizer(BundleContext bundleContext, LogTracker logService, ServiceTracker<Object, Object> metaTypeProviderTracker) {
public SAXParserFactoryTrackerCustomizer(BundleContext bundleContext, LogTracker logService,
ServiceTracker<Object, Object> metaTypeProviderTracker) {
this.bundleCtx = bundleContext;
this.logService = logService;
this.mtpTracker = metaTypeProviderTracker;
Expand All @@ -126,9 +131,12 @@ public SAXParserFactory addingService(ServiceReference<SAXParserFactory> ref) {
// Nothing to do case. Current factory is explicitly namespace aware.
else if (saxParserFactory.isNamespaceAware()) {
return parserFactory;
} else if (parserFactory.isNamespaceAware() || // Previous factory not set for namespace awareness but the new one is case.
// Now the fun case. Neither factory is set for namespace awareness. Need to see if we're currently using
// a factory incapable of creating namespace aware parsers and, if so, if it can be replaced with the new one.
} else if (parserFactory.isNamespaceAware() || // Previous factory not set for namespace awareness but
// the new one is case.
// Now the fun case. Neither factory is set for namespace awareness. Need to see
// if we're currently using
// a factory incapable of creating namespace aware parsers and, if so, if it can
// be replaced with the new one.
(!supportsNamespaceAwareness(saxParserFactory) && supportsNamespaceAwareness(parserFactory))) {
oldFactory = saxParserFactory;
saxParserFactory = parserFactory;
Expand All @@ -140,7 +148,8 @@ else if (saxParserFactory.isNamespaceAware()) {
return parserFactory;
}

private void swapFactories(SAXParserFactory oldFactory, SAXParserFactory newFactory, ServiceRegistration<?> registration, MetaTypeServiceImpl service) {
private void swapFactories(SAXParserFactory oldFactory, SAXParserFactory newFactory,
ServiceRegistration<?> registration, MetaTypeServiceImpl service) {
if (oldFactory == null) {
registerMetaTypeService();
return;
Expand All @@ -158,7 +167,8 @@ public void removedService(ServiceReference<SAXParserFactory> ref, SAXParserFact
MetaTypeServiceImpl service = null;
synchronized (this) {
if (object == saxParserFactory) {
// This means the SAXParserFactory was used to start the MetaTypeService and we need to reset.
// This means the SAXParserFactory was used to start the MetaTypeService and we
// need to reset.
saxParserFactory = null;
registration = metaTypeServiceRegistration;
service = metaTypeService;
Expand All @@ -170,9 +180,11 @@ public void removedService(ServiceReference<SAXParserFactory> ref, SAXParserFact
// See if another factory is available
SAXParserFactory factory = findBestPossibleFactory();
// If the factory is null, either the bundle is stopping or there are no
// available services. Either way, we don't want to register the MetaType service.
// available services. Either way, we don't want to register the MetaType
// service.
if (factory != null) {
// We have another parser so let's restart the MetaType service if it hasn't been already.
// We have another parser so let's restart the MetaType service if it hasn't
// been already.
boolean register = false;
synchronized (this) {
// If not null, something else beat us to the punch.
Expand Down Expand Up @@ -233,7 +245,9 @@ private void registerMetaTypeService() {
} catch (IOException e) {
logService.log(LogTracker.LOG_WARNING, "Error loading cached metatype info.", e); //$NON-NLS-1$
}
ServiceRegistration<?> registration = bundleCtx.registerService(new String[] {MetaTypeService.class.getName(), EquinoxMetaTypeService.class.getName()}, service, properties);
ServiceRegistration<?> registration = bundleCtx.registerService(
new String[] { MetaTypeService.class.getName(), EquinoxMetaTypeService.class.getName() }, service,
properties);
synchronized (this) {
metaTypeServiceRegistration = registration;
}
Expand Down
Loading

0 comments on commit 6c308b7

Please sign in to comment.