下面列出了怎么用javax.naming.OperationNotSupportedException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Checks to see if a supported version of PyDev is installed.
*
* @return True if a supported version of PyDev is installed; otherwise, false.
*/
public static boolean isSupportedPyDevInstalled() {
try {
if (PyDevUtilsInternal.isPyDevInstalled()) {
// Make sure the installed version of PyDev is new enough to support the following
// operation.
getJython27InterpreterNames();
return true;
}
}
catch (OperationNotSupportedException | NoClassDefFoundError e) {
// Fall through to return false
}
return false;
}
/**
* Handles extra things that should happen when we are launching in debug mode.
*/
private static void handleDebugMode() {
Display.getDefault().asyncExec(() -> {
// Switch to debug perspective
if (PlatformUI.getWorkbench() != null) {
IPerspectiveDescriptor descriptor =
PlatformUI.getWorkbench().getPerspectiveRegistry().findPerspectiveWithId(
IDebugUIConstants.ID_DEBUG_PERSPECTIVE);
EclipseMessageUtils.getWorkbenchPage().setPerspective(descriptor);
}
// Start PyDev debugger
if (PyDevUtils.isSupportedPyDevInstalled()) {
try {
PyDevUtils.startPyDevRemoteDebugger();
}
catch (OperationNotSupportedException e) {
EclipseMessageUtils.error(
"Failed to start the PyDev remote debugger. PyDev version is not supported.");
}
}
});
}
@Override
protected Iterator<T> initializeIterator() {
// for setting up the same environment in the executors.
final SparkSession spark = SparkSession.builder()
.config(sessionInitialConf)
.getOrCreate();
final Dataset<T> dataset;
try {
dataset = SparkSession.initializeDataset(spark, commands);
} catch (final OperationNotSupportedException e) {
throw new IllegalStateException(e);
}
// Spark does lazy evaluation: it doesn't load the full dataset, but only the partition it is asked for.
final RDD<T> rdd = dataset.sparkRDD();
final Iterable<T> iterable = () -> JavaConverters.asJavaIteratorConverter(
rdd.iterator(rdd.getPartitions()[partitionIndex], TaskContext$.MODULE$.empty())).asJava();
return iterable.iterator();
}
/**
* Throws a naming exception is Context is not writable.
* @return <code>true</code> if the Context is writable
* @throws NamingException if the Context is not writable and
* <code>exceptionOnFailedWrite</code> is <code>true</code>
*/
protected boolean checkWritable() throws NamingException {
if (isWritable()) {
return true;
} else {
if (exceptionOnFailedWrite) {
throw new javax.naming.OperationNotSupportedException(
sm.getString("namingContext.readOnly"));
}
}
return false;
}
/**
* Gets a list of discovered Jython 2.7 interpreter names.
*
* @return a list of discovered Jython 2.7 interpreter names.
* @throws OperationNotSupportedException if PyDev is not installed or it does not support this
* operation.
*/
public static List<String> getJython27InterpreterNames() throws OperationNotSupportedException {
try {
return PyDevUtilsInternal.getJython27InterpreterNames();
}
catch (NoClassDefFoundError | NoSuchMethodError e) {
throw new OperationNotSupportedException(e.getMessage());
}
}
/**
* Adds the given Jython interpreter to PyDev.
*
* @param interpreterName The name of the interpreter to add.
* @param interpreterFile The interpreter file to add.
* @param interpreterLibDir The interpreter library directory to add.
* @throws OperationNotSupportedException if PyDev is not installed or it does not support this
* operation.
*/
public static void addJythonInterpreter(String interpreterName, File interpreterFile,
File interpreterLibDir)
throws OperationNotSupportedException {
try {
PyDevUtilsInternal.addJythonInterpreter(interpreterName, interpreterFile,
interpreterLibDir);
}
catch (NoClassDefFoundError | NoSuchMethodError e) {
throw new OperationNotSupportedException(e.getMessage());
}
}
/**
* Starts the PyDev remote debugger.
*
* @throws OperationNotSupportedException if PyDev is not installed or it does not support this
* operation.
*/
public static void startPyDevRemoteDebugger() throws OperationNotSupportedException {
try {
PyDevUtilsInternal.startPyDevRemoteDebugger();
}
catch (NoClassDefFoundError | NoSuchMethodError e) {
throw new OperationNotSupportedException(e.getMessage());
}
}
/**
* Validates the fields on the page and updates the page's status.
* Should be called every time a field on the page changes.
*/
private void validate() {
String message = null;
boolean pyDevInstalled = PyDevUtils.isSupportedPyDevInstalled();
boolean pyDevEnabled = enablePythonCheckboxButton.getSelection();
boolean comboEnabled = pyDevInstalled && pyDevEnabled;
if (pyDevEnabled) {
if (!pyDevInstalled) {
message = "PyDev version " + PyDevUtils.MIN_SUPPORTED_VERSION +
" or later is not installed.";
}
else {
try {
List<String> interpreters = PyDevUtils.getJython27InterpreterNames();
if (interpreters.isEmpty()) {
message = "No Jython interpreters found. Click the + button to add one.";
}
}
catch (OperationNotSupportedException e) {
message = "PyDev version is not supported.";
comboEnabled = false;
}
}
}
jythonCombo.setEnabled(comboEnabled);
addJythonButton.setEnabled(comboEnabled);
setErrorMessage(message);
setPageComplete(message == null);
}
/**
* Populates the Jython combo box with discovered Jython names.
*/
private void populateJythonCombo() {
jythonCombo.removeAll();
try {
for (String jythonName : PyDevUtils.getJython27InterpreterNames()) {
jythonCombo.add(jythonName);
}
}
catch (OperationNotSupportedException e) {
// Nothing to do. Combo should and will be empty.
}
if (jythonCombo.getItemCount() > 0) {
jythonCombo.select(0);
}
}
/**
* Method to reproduce the initial Dataset on separate evaluators when reading from sources.
*
* @param spark sparkSession to start from.
* @param commandList commands required to setup the dataset.
* @param <T> type of the resulting dataset's data.
* @return the initialized dataset.
* @throws OperationNotSupportedException exception when the command is not yet supported.
*/
public static <T> Dataset<T> initializeDataset(final SparkSession spark,
final LinkedHashMap<String, Object[]> commandList)
throws OperationNotSupportedException {
Object result = spark;
for (Map.Entry<String, Object[]> command : commandList.entrySet()) {
final String[] cmd = command.getKey().split("#");
final String className = cmd[0];
final String methodName = cmd[1];
final Object[] args = command.getValue();
final Class<?>[] argTypes = Stream.of(args).map(Object::getClass).toArray(Class[]::new);
if (!className.contains("SparkSession")
&& !className.contains("DataFrameReader")
&& !className.contains("Dataset")) {
throw new OperationNotSupportedException(command + " is not yet supported.");
}
try {
final Method method = result.getClass().getDeclaredMethod(methodName, argTypes);
result = method.invoke(result, args);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
return (Dataset<T>) result;
}
@Override
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public Object lookup(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public Object lookupLink(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public void bind(Name name, Object obj) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public void unbind(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public void rebind(Name name, Object obj) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public void rename(Name oldName, Name newName) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public Context createSubcontext(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public void destroySubcontext(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public String getNameInNamespace() throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public NameParser getNameParser(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public NameParser getNameParser(String name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public Name composeName(Name name, Name prefix) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public NamingEnumeration<NameClassPair> list(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public NamingEnumeration<Binding> listBindings(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public Object lookup(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public Object lookupLink(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public void bind(Name name, Object obj) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}
@Override
public void unbind(Name name) throws NamingException {
throw new OperationNotSupportedException("SimpleNamingContext does not support [javax.naming.Name]");
}