Class Utils
java.lang.Object
de.uni_hildesheim.sse.easy.loader.framework.Utils
Some basic utility functions. Some may be present in existing libraries,
but we aim at avoiding the use of libraries in this loader in order to
avoid class loading conflicts.
- Author:
- Holger Eichelberger
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classAn internal data structure for storing information about a JAR Manifest file. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanactivateDsInstance(ClassLoader loader, String className) Activates a DS class / instance.Analyzes the given bundles for cyclic dependencies.private static booleancallMethod(ClassLoader loader, String className, String methodName, Object param, String callType) Calls a DS method.static voidcloseQuietly(Closeable closeable) Closes the givencloseablewithout throwing an exception.private static voidcollectBundlesToInitialize(BundleInfo info, List<BundleInfo> result, boolean topLevel, Map<String, BundleInfo> mapping) Collects those bundles (including the given one and dependent bundles), which shall be initialized explicitly.static voidcopy(InputStream is, OutputStream os) Copiesistoos.static FilecreateTempFile(String name) Creates a temp file.static booleandeactivateDsInstance(ClassLoader loader, String className) Deactivates a DS class / instance.static List<BundleInfo> filter(List<BundleInfo> infos, IBundleFilter filter) Filters the giveninfosaccording tofilter.Returns all JAR files infolder.private static MethodfindMethod(Class<?> cls, String methodName, Object param) Searches for the specified method in the given class or (if available) the super classes.findRecentBundles(File folder) Returns all recent bundles infolder.private static List<BundleInfo> getBundlesToInitialize(Map<BundleInfo, List<BundleInfo>> cache, BundleInfo info, Map<String, BundleInfo> mapping) Returns the bundles to initialize.static booleanjarEntryToFile(JarFile jarFile, JarEntry entry, File target) Copies the contents of a JAR entry to the giventargetfile.static voidloadBundles(List<File> files, IBundleFilter filter, Object tag) Loads the bundles from the given file folder.static voidsetTempDir(File tempDir) Sets the temp directory for extracting and reading temporary files.static List<BundleInfo> sortByContainment(List<BundleInfo> infos) Sorts the given bundle informations according to the containment of their bundles to initialize.static booleanstartBundle(ClassLoader loader, String className) Starts the bundle activator given byclassName.static booleanstopBundle(ClassLoader loader, String className) Stops the bundle activator given byclassName.static final URL[]Turns a list of URLs into an array of URLS.static URL[]Turns files into an URL array.
-
Field Details
-
CLASS_SUFFIX
- See Also:
-
TEXT_CANNOT_INITIALIZE
- See Also:
-
temp
-
-
Constructor Details
-
Utils
private Utils()Prevents external creation.
-
-
Method Details
-
closeQuietly
Closes the givencloseablewithout throwing an exception.- Parameters:
closeable- the closeable to be closed, may be null
-
toArray
Turns a list of URLs into an array of URLS.- Parameters:
urls- the URLs to be turned into an array- Returns:
- the related URL array
-
copy
Copiesistoos.- Parameters:
is- the input streamos- the output stream- Throws:
IOException- in case of I/O problems
-
analyzeForCyclicDependencies
Analyzes the given bundles for cyclic dependencies.- Parameters:
infos- the bundle information objects to be analyzed- Returns:
- empty if there are no cyclic dependencies, the dependency paths leading to cyclic dependencies else
-
sortByContainment
Sorts the given bundle informations according to the containment of their bundles to initialize. This method aims at simulating a startup process and tries putting those bundles with less/few bundles at the beginning.- Parameters:
infos- the information objects to be sorted- Returns:
- the sorted information objects
-
getBundlesToInitialize
private static List<BundleInfo> getBundlesToInitialize(Map<BundleInfo, List<BundleInfo>> cache, BundleInfo info, Map<String, BundleInfo> mapping) Returns the bundles to initialize.- Parameters:
cache- the initialization set cache (may be modified as a side effect)info- the information object to return the initialization formapping- the name/version-bundle mapping- Returns:
- the bundles to initialize
-
collectBundlesToInitialize
private static void collectBundlesToInitialize(BundleInfo info, List<BundleInfo> result, boolean topLevel, Map<String, BundleInfo> mapping) Collects those bundles (including the given one and dependent bundles), which shall be initialized explicitly.- Parameters:
info- the bundle info to collect information forresult- the bundle information objects to be initialized (modified as a side effect)topLevel- whether this is a top-level callmapping- the name/version-bundle mapping
-
activateDsInstance
Activates a DS class / instance.- Parameters:
loader- the class loader to find the DS classclassName- the class name of the class to activated in (simple) DS way- Returns:
trueif successful,falseelse
-
deactivateDsInstance
Deactivates a DS class / instance.- Parameters:
loader- the class loader to find the DS classclassName- the class name of the class to de-activated in (simple) DS way- Returns:
trueif successful,falseelse
-
callMethod
private static boolean callMethod(ClassLoader loader, String className, String methodName, Object param, String callType) Calls a DS method.- Parameters:
loader- the class loader to find the DS classclassName- the class name of the class to de-activated in (simple) DS waymethodName- the name of the method to be called (1-parameter ComponentContext)param- the only param to be passed in, must not be nullcallType- additional info to be printed out in case of problems- Returns:
trueif successful,falseelse
-
findMethod
Searches for the specified method in the given class or (if available) the super classes.- Parameters:
cls- the class to search inmethodName- the method name to search forparam- the param (and type) to search for- Returns:
- the found method (may be null if not found)
-
startBundle
Starts the bundle activator given byclassName.- Parameters:
loader- the class loader to find the DS classclassName- the class name of the class to de-activated in (simple) DS way- Returns:
trueif successful,falseelse
-
stopBundle
Stops the bundle activator given byclassName.- Parameters:
loader- the class loader to find the DS classclassName- the class name of the class to de-activated in (simple) DS way- Returns:
trueif successful,falseelse
-
loadBundles
Loads the bundles from the given file folder.- Parameters:
files- the files to load fromfilter- an optional bundle filter determining the actual bundles to load (may be null)tag- an optional tag to identify bundles for later use
-
findRecentBundles
Returns all recent bundles infolder.- Parameters:
folder- the folder to analyze- Returns:
- all recent JAR files in
folder(oder versions of the same bundle are skipped)
-
findJars
Returns all JAR files infolder.- Parameters:
folder- the folder to analyze- Returns:
- all JAR files in
folder
-
filter
Filters the giveninfosaccording tofilter.- Parameters:
infos- the bundle information objects to be filteredfilter- theIBundleFilterto be applied- Returns:
- the filtered bundle information objects
-
toURLs
Turns files into an URL array.- Parameters:
files- the files to be turned into URLs- Returns:
- the resulting URLs
- Throws:
MalformedURLException- in case that at least one of the files cannot be turned into an URL
-
setTempDir
Sets the temp directory for extracting and reading temporary files.- Parameters:
tempDir- A folder used by the unpacking process.
-
createTempFile
Creates a temp file.- Parameters:
name- the name/subpath of the temp file to be created- Returns:
- the temp file
- Throws:
IOException- in case of I/O problems
-
jarEntryToFile
Copies the contents of a JAR entry to the giventargetfile.- Parameters:
jarFile- the JAR file being processedentry- the JAR entrytarget- the target file- Returns:
trueif successful,falseelse
-