blob: 619a2204b9ce0576cfa865f853e0a4eeef78172b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
/*******************************************************************************
* Copyright (c) 2005 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.metatype;
import java.io.IOException;
import java.security.*;
import java.util.Hashtable;
import javax.xml.parsers.SAXParserFactory;
import org.osgi.framework.*;
import org.osgi.service.metatype.MetaTypeInformation;
import org.osgi.service.metatype.MetaTypeService;
/**
* Implementation of MetaTypeService
*/
public class MetaTypeServiceImpl implements MetaTypeService, SynchronousBundleListener {
BundleContext _context;
SAXParserFactory _parserFactory;
private Hashtable _mtps = new Hashtable(7);
/**
* Constructor of class MetaTypeServiceImpl.
*/
public MetaTypeServiceImpl(BundleContext context, SAXParserFactory parserFactory) {
this._context = context;
this._parserFactory = parserFactory;
}
/*
* (non-Javadoc)
*
* @see org.osgi.service.metatype.MetaTypeService#getMetaTypeInformation(org.osgi.framework.Bundle)
*/
public MetaTypeInformation getMetaTypeInformation(Bundle bundle) {
MetaTypeInformation mti;
try {
mti = getMetaTypeProvider(bundle);
} catch (IOException e) {
Logging.log(Logging.ERROR, "IOException in MetaTypeInformation:getMetaTypeInformation(Bundle bundle)"); //$NON-NLS-1$
e.printStackTrace();
mti = null;
}
return mti;
}
/**
* Internal Method - to get MetaTypeProvider object.
*/
private MetaTypeInformation getMetaTypeProvider(final Bundle b) throws java.io.IOException {
try {
Long bID = new Long(b.getBundleId());
synchronized (_mtps) {
if (_mtps.containsKey(bID))
return (MetaTypeInformation) _mtps.get(bID);
MetaTypeInformation mti = (MetaTypeInformation) AccessController.doPrivileged(new PrivilegedExceptionAction() {
public Object run() throws IOException {
MetaTypeInformationImpl impl = new MetaTypeInformationImpl(b, _parserFactory);
if (!impl._isThereMeta)
return new MetaTypeProviderTracker(_context, b);
return impl;
}
});
_mtps.put(bID, mti);
return mti;
}
} catch (PrivilegedActionException pae) {
throw (IOException) pae.getException();
}
}
/*
* (non-Javadoc)
*
* @see org.osgi.framework.BundleListener#bundleChanged(org.osgi.framework.BundleEvent)
*/
public void bundleChanged(BundleEvent event) {
int type = event.getType();
Long bID = new Long(event.getBundle().getBundleId());
switch (type) {
case BundleEvent.UPDATED :
case BundleEvent.UNINSTALLED :
_mtps.remove(bID);
break;
case BundleEvent.INSTALLED :
case BundleEvent.RESOLVED :
case BundleEvent.STARTED :
case BundleEvent.STOPPED :
case BundleEvent.UNRESOLVED :
default :
break;
}
}
}
|