Top Description Inners Fields Constructors Methods
org.python.core.packagecache

public abstract Class PackageManager

extends Object
Class Inheritance
Known Direct Subclasses
org.python.core.packagecache.CachedJarsPackageManager
Imports
org.objectweb.asm.ClassReader, .ClassVisitor, .Opcodes, org.python.core.Py, .PyJavaPackage, .PyList, .PyObject, .PyStringMap, java.io.IOException, .InputStream, java.util.LinkedHashSet, .Set, .StringTokenizer

Abstract package manager.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
public PyJavaPackage
topLevelPackage

Nominal top-level package of all (Java) packages, containing "java", "com", "org", etc..

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public abstract void
addDirectory(File
A directory.
dir
)

Append a directory to the list of directories searched for java packages and java classes.

public abstract void
addJar(String
A directory name.
jarfile
,
boolean cache)

Append a jar file to the list of locations searched for java packages and java classes.

public abstract void
addJarDir(String
A directory name.
dir
,
boolean cache)

Append a directory to the list of directories searched for java packages and java classes.

protected PyList
basicDoDir(PyJavaPackage jpkg, boolean instantiate, boolean exclpkgs)

Basic helper implementation of doDir.

protected static int
checkAccess(InputStream cstream)

Check that a given stream is a valid Java .class file, and return its access permissions as an int.

public abstract PyList

Returns:

resulting list of names (PyList of PyString)
doDir
(PyJavaPackage
queried package
jpkg
,
boolean
if true then instatiate reported names in package dict
instantiate
,
boolean
exclude packages (just when instantiate is false)
exclpkgs
)

Reports the specified package content names.

public abstract Class<T>
findClass(String pkg, String name, String reason)

public Class<T>
findClass(String pkg, String name)

public PyObject

Returns:

the package named
lookupName
(String
(dotted) package name
name
)

Given the (dotted) name of a package, find the PyJavaPackage corresponding, by navigating from the topLevelPackage, successively applying PyObject#__findattr__(String).

public PyJavaPackage

Returns:

created/updated package
makeJavaPackage
(String
package name
name
,
String
comma or @-sign separated string
classes
,
String
involved; can be null
jarfile
)

Create (or ensure we have) a PyJavaPackage for the named package and add to it the names of classes mentioned here.

protected PyList
merge(PyList list1, PyList list2)

Helper merging list2 into list1.

public void
public abstract boolean

Returns:

true if pkg exists
packageExists
(String
parent pkg name
pkg
,
String
candidate name
name
)

Dynamically check if pkg.name exists as java pkg in the controlled hierarchy.

protected static Set<String>

Returns:

set of tokens trimmed of white space
split
(String
compound string to split into tokens (null treated as "".
target
,
String
characters, any of which will be treated as a token separator
sep
)

Helper to split a textual list into a list.

protected static Set<String>
split(String target)

Equivalent to split(target, ",").

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

topLevelPackageback to summary
public PyJavaPackage topLevelPackage

Nominal top-level package of all (Java) packages, containing "java", "com", "org", etc..

Constructor Detail

PackageManagerback to summary
public PackageManager()

Method Detail

addDirectoryback to summary
public abstract void addDirectory(File dir)

Append a directory to the list of directories searched for java packages and java classes.

Parameters
dir:File

A directory.

addJarback to summary
public abstract void addJar(String jarfile, boolean cache)

Append a jar file to the list of locations searched for java packages and java classes.

Parameters
jarfile:String

A directory name.

addJarDirback to summary
public abstract void addJarDir(String dir, boolean cache)

Append a directory to the list of directories searched for java packages and java classes.

Parameters
dir:String

A directory name.

basicDoDirback to summary
protected PyList basicDoDir(PyJavaPackage jpkg, boolean instantiate, boolean exclpkgs)

Basic helper implementation of doDir. It merges information from jpkg PyJavaPackage#clsSet and PyJavaPackage#__dict__.

checkAccessback to summary
protected static int checkAccess(InputStream cstream) throws IOException

Check that a given stream is a valid Java .class file, and return its access permissions as an int.

doDirback to summary
public abstract PyList doDir(PyJavaPackage jpkg, boolean instantiate, boolean exclpkgs)

Reports the specified package content names. Should be overridden. Used by PyJavaPackage#__dir__ and PyJavaPackage#fillDir.

Parameters
jpkg:PyJavaPackage

queried package

instantiate:boolean

if true then instatiate reported names in package dict

exclpkgs:boolean

exclude packages (just when instantiate is false)

Returns:PyList

resulting list of names (PyList of PyString)

findClassback to summary
public abstract Class<T> findClass(String pkg, String name, String reason)
findClassback to summary
public Class<T> findClass(String pkg, String name)
lookupNameback to summary
public PyObject lookupName(String name)

Given the (dotted) name of a package, find the PyJavaPackage corresponding, by navigating from the topLevelPackage, successively applying PyObject#__findattr__(String). This in fact drives the creation of PyJavaPackage objects since it indirectly calls packageExists(String, String).

Parameters
name:String

(dotted) package name

Returns:PyObject

the package named

makeJavaPackageback to summary
public PyJavaPackage makeJavaPackage(String name, String classes, String jarfile)

Create (or ensure we have) a PyJavaPackage for the named package and add to it the names of classes mentioned here. These classes are added as "place holders" only, so they become members of it, without being instantiated. This method relies on PyJavaPackage#addPackage(java.lang.String, java.lang.String) and PyJavaPackage#addPlaceholders.

Parameters
name:String

package name

classes:String

comma or @-sign separated string

jarfile:String

involved; can be null

Returns:PyJavaPackage

created/updated package

mergeback to summary
protected PyList merge(PyList list1, PyList list2)

Helper merging list2 into list1. Returns list1.

notifyPackageImportback to summary
public void notifyPackageImport(String pkg, String name)
packageExistsback to summary
public abstract boolean packageExists(String pkg, String name)

Dynamically check if pkg.name exists as java pkg in the controlled hierarchy. Should be overridden.

Parameters
pkg:String

parent pkg name

name:String

candidate name

Returns:boolean

true if pkg exists

splitback to summary
protected static Set<String> split(String target, String sep)

Helper to split a textual list into a list. The semantics are basically those of StringTokenizer, followed by String.trim() and duplicate removal.

Parameters
target:String

compound string to split into tokens (null treated as "".

sep:String

characters, any of which will be treated as a token separator

Returns:Set<String>

set of tokens trimmed of white space

splitback to summary
protected static Set<String> split(String target)

Equivalent to split(target, ","). See split(String, String).

org.python.core.packagecache back to summary

private Class PackageManager.AccessVisitor

extends ClassVisitor
Class Inheritance

ASM visitor class supporting checkAccess(InputStream).

Field Summary

Modifier and TypeField and Description
private int
Inherited from org.objectweb.asm.ClassVisitor:
apicv

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public int
public void
visit(int
the class version. The minor version is stored in the 16 most significant bits, and the major version in the 16 least significant bits.
version
,
int
the class's access flags (see Opcodes). This parameter also indicates if the class is deprecated Opcodes#ACC_DEPRECATED or a record Opcodes#ACC_RECORD.
access
,
String
the internal name of the class (see Type#getInternalName()).
name
,
String
the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.
signature
,
String
the internal of name of the super class (see Type#getInternalName()). For interfaces, the super class is Object. May be null, but only for the Object class.
superName
,
String[]
the internal names of the class's interfaces (see Type#getInternalName()). May be null.
interfaces
)

Overrides org.objectweb.asm.ClassVisitor.visit.

Visits the header of the class.

Inherited from org.objectweb.asm.ClassVisitor:
getDelegatevisitAnnotationvisitAttributevisitEndvisitFieldvisitInnerClassvisitMethodvisitModulevisitNestHostvisitNestMembervisitOuterClassvisitPermittedSubclassvisitRecordComponentvisitSourcevisitTypeAnnotation

Field Detail

class_accessback to summary
private int class_access

Constructor Detail

AccessVisitorback to summary
public AccessVisitor() throws IOException

Method Detail

getClassAccessback to summary
public int getClassAccess()
visitback to summary
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces)

Overrides org.objectweb.asm.ClassVisitor.visit.

Doc from org.objectweb.asm.ClassVisitor.visit.

Visits the header of the class.

Parameters
version:int

the class version. The minor version is stored in the 16 most significant bits, and the major version in the 16 least significant bits.

access:int

the class's access flags (see Opcodes). This parameter also indicates if the class is deprecated Opcodes#ACC_DEPRECATED or a record Opcodes#ACC_RECORD.

name:String

the internal name of the class (see Type#getInternalName()).

signature:String

the signature of this class. May be null if the class is not a generic one, and does not extend or implement generic classes or interfaces.

superName:String

the internal of name of the super class (see Type#getInternalName()). For interfaces, the super class is Object. May be null, but only for the Object class.

interfaces:String[]

the internal names of the class's interfaces (see Type#getInternalName()). May be null.

Annotations
@Override