subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From br...@apache.org
Subject svn commit: r1658112 - in /subversion/trunk/subversion/bindings/javahl/native: ./ jniwrapper/
Date Sat, 07 Feb 2015 22:27:08 GMT
Author: brane
Date: Sat Feb  7 22:27:07 2015
New Revision: 1658112

URL: http://svn.apache.org/r1658112
Log:
Change the JavaHL new-style list wrapper to use Java iterators
instead of converting the list to an std::vector.

[in subversion/bindings/javahl/native]
* jniwrapper/jni_iterator.hpp, jniwrapper/jni_iterator.cpp: New
  (Java::BaseIterator): New wrapper class for java.util.Iterator.

* jniwrapper/jni_exception.hpp
  (Java::IndexOutOfBoundsException): Add a ClassImpl subclass
   so that the Java exception class can be registered in the
   class cache.
  (Java::NoSuchElementException): New exception wrapper.

* jniwrapper/jni_base.cpp
  (Java::IndexOutOfBoundsException::ClassImpl): Implement destructor.
  (Java::NoSuchElementException): Implement.

* jniwrapper/jni_list.hpp
  (Java::BaseImmutableList): Replaces Java::BaseList.
  (Java::ImmutableList): Replaces Java::List.
  (Java::BaseList): Replaces Java::BaseMutableList.
   Derives from Java::BaseImmutableList instead of Java::Object.
  (Java::List): Replaces Java::MutableList.
* jniwrapper/jni_list.cpp: Update list implementation.

* jniwrapper/jni_object.hpp
  (Java::ClassCacheImpl):
   Declare get_exc_index_out_of_bounds and get_exc_no_such_element.
* jniwrapper/jni_class_cache.cpp
  (Java::ClassCacheImpl):
   Implement get_exc_index_out_of_bounds and get_exc_no_such_element.
   Update implementation of get_list, get_array_list and get_iterator.

* jniwrapper/jni_string_map.hpp
  (Java::BaseMap): Use Java::BaseIterator instead of the
   private iterator class.
* jniwrapper/jni_string_map.cpp
  (BaseMap::Iterator): Remove implementation.
  (BaseMap::convert_to_map): Use the new iterator class.

* AuthnCallback.cpp,
  org_apache_subversion_javahl_util_ConfigLib.cpp,
  org_apache_subversion_javahl_util_PropLib.cpp:
   Update to new list types.

Added:
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.cpp   (with
props)
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.hpp   (with
props)
Modified:
    subversion/trunk/subversion/bindings/javahl/native/AuthnCallback.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_base.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_exception.hpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.hpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_object.hpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp
    subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp
    subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_ConfigLib.cpp
    subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_PropLib.cpp

Modified: subversion/trunk/subversion/bindings/javahl/native/AuthnCallback.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/AuthnCallback.cpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/AuthnCallback.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/AuthnCallback.cpp Sat Feb  7 22:27:07
2015
@@ -242,7 +242,7 @@ AuthnCallback::SSLServerCertInfo::SSLSer
     svn_x509_certinfo_get_hostnames(certinfo);
   if (hostnames)
     {
-      ::Java::MutableList< ::Java::String> hn(env, hostnames->nelts);
+      ::Java::List< ::Java::String> hn(env, hostnames->nelts);
       for (int i = 0; i < hostnames->nelts; ++i)
         hn.add(::Java::String(env, APR_ARRAY_IDX(hostnames, i, const char*)));
       jhostnames = hn.get();

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_base.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_base.cpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_base.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_base.cpp Sat Feb  7
22:27:07 2015
@@ -325,6 +325,7 @@ const char* const OutOfMemoryError::m_cl
 
 const char* const IndexOutOfBoundsException::m_class_name =
   "java/lang/IndexOutOfBoundsException";
+IndexOutOfBoundsException::ClassImpl::~ClassImpl() {}
 
 const char* const IOException::m_class_name =
   "java/io/IOException";
@@ -332,6 +333,10 @@ const char* const IOException::m_class_n
 const char* const IllegalArgumentException::m_class_name =
   "java/lang/IllegalArgumentException";
 
+const char *const NoSuchElementException::m_class_name =
+  "java/util/NoSuchElementException";
+NoSuchElementException::ClassImpl::~ClassImpl() {}
+
 // Implementation of jni_stack.hpp
 
 void handle_svn_error(Env env, ::svn_error_t* err)

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_class_cache.cpp Sat
Feb  7 22:27:07 2015
@@ -163,12 +163,18 @@ class ClassCacheImpl
       return pimpl;                                             \
     }
 
-  JNIWRAPPER_DEFINE_CACHED_CLASS(list, BaseList);
-  JNIWRAPPER_DEFINE_CACHED_CLASS(array_list, BaseMutableList);
+  JNIWRAPPER_DEFINE_CACHED_CLASS(exc_index_out_of_bounds,
+                                 IndexOutOfBoundsException);
+  JNIWRAPPER_DEFINE_CACHED_CLASS(exc_no_such_element,
+                                 NoSuchElementException);
+
+  JNIWRAPPER_DEFINE_CACHED_CLASS(iterator, BaseIterator);
+
+  JNIWRAPPER_DEFINE_CACHED_CLASS(list, BaseImmutableList);
+  JNIWRAPPER_DEFINE_CACHED_CLASS(array_list, BaseList);
 
   JNIWRAPPER_DEFINE_CACHED_CLASS(map, BaseMap);
   JNIWRAPPER_DEFINE_CACHED_CLASS(set, BaseMap::Set);
-  JNIWRAPPER_DEFINE_CACHED_CLASS(iterator, BaseMap::Iterator);
   JNIWRAPPER_DEFINE_CACHED_CLASS(map_entry, BaseMap::Entry);
   JNIWRAPPER_DEFINE_CACHED_CLASS(hash_map, BaseMutableMap);
 
@@ -279,6 +285,9 @@ JNIWRAPPER_IMPL_CLASS_CACHE_ACCESSOR(cla
 JNIWRAPPER_IMPL_CLASS_CACHE_ACCESSOR(throwable);
 JNIWRAPPER_IMPL_CLASS_CACHE_ACCESSOR(string);
 
+JNIWRAPPER_IMPL_CLASS_CACHE_ACCESSOR(exc_index_out_of_bounds);
+JNIWRAPPER_IMPL_CLASS_CACHE_ACCESSOR(exc_no_such_element);
+
 JNIWRAPPER_IMPL_CLASS_CACHE_ACCESSOR(list);
 JNIWRAPPER_IMPL_CLASS_CACHE_ACCESSOR(array_list);
 

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_exception.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_exception.hpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_exception.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_exception.hpp Sat Feb
 7 22:27:07 2015
@@ -264,6 +264,23 @@ public:
     {}
 
 private:
+  /**
+   * This object's implementation details.
+   */
+  class ClassImpl : public Object::ClassImpl
+  {
+    friend class ClassCacheImpl;
+
+  protected:
+    explicit ClassImpl(Env env, jclass cls)
+      : Object::ClassImpl(env, cls)
+      {}
+
+  public:
+    virtual ~ClassImpl();
+  };
+
+  friend class ClassCacheImpl;
   static const char* const m_class_name;
 };
 
@@ -305,6 +322,43 @@ private:
   static const char* const m_class_name;
 };
 
+/**
+ * Generator class for exceptions of type
+ * @c java.util.NoSuchElementException.
+ *
+ * @since New in 1.9.
+ */
+class NoSuchElementException : public Exception
+{
+public:
+  /**
+   * Constructs an exception generator object.
+   */
+  explicit NoSuchElementException(Env env)
+    : Exception(env, m_class_name)
+    {}
+
+private:
+  /**
+   * This object's implementation details.
+   */
+  class ClassImpl : public Object::ClassImpl
+  {
+    friend class ClassCacheImpl;
+
+  protected:
+    explicit ClassImpl(Env env, jclass cls)
+      : Object::ClassImpl(env, cls)
+      {}
+
+  public:
+    virtual ~ClassImpl();
+  };
+
+  friend class ClassCacheImpl;
+  static const char* const m_class_name;
+};
+
 } // namespace Java
 
-#endif // SVN_JAVAHL_JNIWRAPPER_ENV_HPP
+#endif // SVN_JAVAHL_JNIWRAPPER_EXCEPTION_HPP

Added: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.cpp?rev=1658112&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.cpp (added)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.cpp Sat Feb
 7 22:27:07 2015
@@ -0,0 +1,63 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ * @endcopyright
+ */
+
+#include <stdexcept>
+
+#include "jni_iterator.hpp"
+
+#include "svn_private_config.h"
+
+namespace Java {
+
+// Class Java::BaseIterator
+
+const char* const BaseIterator::m_class_name = "java/util/Iterator";
+
+BaseIterator::ClassImpl::ClassImpl(Env env, jclass cls)
+  : Object::ClassImpl(env, cls),
+    m_mid_has_next(env.GetMethodID(cls, "hasNext", "()Z")),
+    m_mid_next(env.GetMethodID(cls, "next", "()Ljava/lang/Object;"))
+{}
+
+BaseIterator::ClassImpl::~ClassImpl() {}
+
+jobject BaseIterator::next()
+{
+  try
+    {
+      return m_env.CallObjectMethod(m_jthis, impl().m_mid_next);
+    }
+  catch (const SignalExceptionThrown&)
+    {
+      // Just rethrow if it's not a NoSuchElementException.
+      if (!m_env.IsInstanceOf(
+              m_env.ExceptionOccurred(),
+              ClassCache::get_exc_no_such_element(m_env)->get_class()))
+        throw;
+
+      m_env.ExceptionClear();
+      throw std::range_error(_("Iterator out of bounds"));
+    }
+}
+
+} // namespace Java

Propchange: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.hpp?rev=1658112&view=auto
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.hpp (added)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.hpp Sat Feb
 7 22:27:07 2015
@@ -0,0 +1,91 @@
+/**
+ * @copyright
+ * ====================================================================
+ *    Licensed to the Apache Software Foundation (ASF) under one
+ *    or more contributor license agreements.  See the NOTICE file
+ *    distributed with this work for additional information
+ *    regarding copyright ownership.  The ASF licenses this file
+ *    to you under the Apache License, Version 2.0 (the
+ *    "License"); you may not use this file except in compliance
+ *    with the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *    Unless required by applicable law or agreed to in writing,
+ *    software distributed under the License is distributed on an
+ *    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *    KIND, either express or implied.  See the License for the
+ *    specific language governing permissions and limitations
+ *    under the License.
+ * ====================================================================
+ * @endcopyright
+ */
+
+#ifndef SVN_JAVAHL_JNIWRAPPER_ITERATOR_HPP
+#define SVN_JAVAHL_JNIWRAPPER_ITERATOR_HPP
+
+#include "jni_env.hpp"
+#include "jni_object.hpp"
+
+namespace Java {
+
+/**
+ * Non-template base for a Java iterator.
+ *
+ * @since New in 1.9.
+ */
+class BaseIterator : public Object
+{
+protected:
+  /**
+   * Constructs the iterator wrapper.
+   */
+  explicit BaseIterator(Env env, jobject jiterator)
+    : Object(env, ClassCache::get_iterator(env), jiterator)
+    {}
+
+public:
+  /**
+   * Returns @c false at the end of the iteration.
+   */
+  bool has_next() const
+    {
+      return m_env.CallBooleanMethod(m_jthis, impl().m_mid_has_next);
+    }
+
+  /**
+   * Returns the next object in the iteration.
+   * @throw std::range_error if the next object is not available.
+   */
+  jobject next();
+
+private:
+  /**
+   * This object's implementation details.
+   */
+  class ClassImpl : public Object::ClassImpl
+  {
+    friend class ClassCacheImpl;
+
+  protected:
+    explicit ClassImpl(Env env, jclass cls);
+
+  public:
+    virtual ~ClassImpl();
+
+    const MethodID m_mid_has_next;
+    const MethodID m_mid_next;
+  };
+
+  const ClassImpl& impl() const
+    {
+      return *dynamic_cast<const ClassImpl*>(m_impl);
+    }
+
+  friend class ClassCacheImpl;
+  static const char* const m_class_name;
+};
+
+} // namespace Java
+
+#endif // SVN_JAVAHL_JNIWRAPPER_ITERATOR_HPP

Propchange: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_iterator.hpp
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.cpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.cpp Sat Feb  7
22:27:07 2015
@@ -21,54 +21,65 @@
  * @endcopyright
  */
 
+#include <stdexcept>
+#include <string>
+
 #include "jni_list.hpp"
 
+#include "svn_private_config.h"
+
 namespace Java {
 
-// Class Java::BaseList
+// Class Java::BaseImmutableList
 
-const char* const BaseList::m_class_name = "java/util/List";
+const char* const BaseImmutableList::m_class_name = "java/util/List";
 
-BaseList::ClassImpl::ClassImpl(Env env, jclass cls)
+BaseImmutableList::ClassImpl::ClassImpl(Env env, jclass cls)
   : Object::ClassImpl(env, cls),
     m_mid_size(env.GetMethodID(cls, "size", "()I")),
-    m_mid_get(env.GetMethodID(cls, "get", "(I)Ljava/lang/Object;"))
+    m_mid_get(env.GetMethodID(cls, "get", "(I)Ljava/lang/Object;")),
+    m_mid_add(env.GetMethodID(cls, "add", "(Ljava/lang/Object;)Z")),
+    m_mid_clear(env.GetMethodID(cls, "clear", "()V")),
+    m_mid_iter(env.GetMethodID(cls, "listIterator", "()Ljava/util/ListIterator;"))
 {}
 
-BaseList::ClassImpl::~ClassImpl() {}
+BaseImmutableList::ClassImpl::~ClassImpl() {}
 
-BaseList::ovector
-BaseList::convert_to_vector(Env env, jobject jlist)
+jobject BaseImmutableList::operator[](jint index) const
 {
-  const ClassImpl* pimpl =
-    dynamic_cast<const ClassImpl*>(ClassCache::get_list(env));
-  const jint length = env.CallIntMethod(jlist, pimpl->m_mid_size);
-
-  if (!length)
-    return ovector();
-
-  ovector contents(length);
-  ovector::iterator it;
-  jint i;
-  for (i = 0, it = contents.begin(); it != contents.end(); ++it, ++i)
-    *it = env.CallObjectMethod(jlist, pimpl->m_mid_get, i);
-  return contents;
+  try
+    {
+      return m_env.CallObjectMethod(m_jthis, impl().m_mid_get, index);
+    }
+  catch (const SignalExceptionThrown&)
+    {
+      // Just rethrow if it's not an IndexOutOfBoundsException.
+      if (!m_env.IsInstanceOf(
+              m_env.ExceptionOccurred(),
+              ClassCache::get_exc_index_out_of_bounds(m_env)->get_class()))
+        throw;
+
+      m_env.ExceptionClear();
+      std::string msg(_("List index out of bounds: "));
+      msg += index;
+      throw std::out_of_range(msg.c_str());
+    }
 }
 
+BaseImmutableList::Iterator BaseImmutableList::get_iterator() const
+{
+  return Iterator(m_env, m_env.CallObjectMethod(m_jthis, impl().m_mid_iter));
+}
 
-// Class Java::BaseMutableList
+// Class Java::BaseList
 
-const char* const BaseMutableList::m_class_name = "java/util/ArrayList";
+const char* const BaseList::m_class_name = "java/util/ArrayList";
 
-BaseMutableList::ClassImpl::ClassImpl(Env env, jclass cls)
-  : Object::ClassImpl(env, cls),
-    m_mid_ctor(env.GetMethodID(cls, "<init>", "(I)V")),
-    m_mid_add(env.GetMethodID(cls, "add", "(Ljava/lang/Object;)Z")),
-    m_mid_clear(env.GetMethodID(cls, "clear", "()V")),
-    m_mid_get(env.GetMethodID(cls, "get", "(I)Ljava/lang/Object;")),
-    m_mid_size(env.GetMethodID(cls, "size", "()I"))
+BaseList::ClassImpl::ClassImpl(Env env, jclass cls)
+  : BaseImmutableList::ClassImpl(env, cls),
+    m_mid_ctor(env.GetMethodID(cls, "<init>", "(I)V"))
 {}
 
-BaseMutableList::ClassImpl::~ClassImpl() {}
+BaseList::ClassImpl::~ClassImpl() {}
 
 } // namespace Java

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.hpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_list.hpp Sat Feb  7
22:27:07 2015
@@ -24,56 +24,90 @@
 #ifndef SVN_JAVAHL_JNIWRAPPER_LIST_HPP
 #define SVN_JAVAHL_JNIWRAPPER_LIST_HPP
 
-#include <algorithm>
-#include <vector>
-
 #include "jni_env.hpp"
 #include "jni_object.hpp"
+#include "jni_iterator.hpp"
 
 namespace Java {
 
 /**
  * Non-template base for an immutable type-safe Java list.
  *
- * Converts the list to a @c std::vector of @c jobject references.
- *
  * @since New in 1.9.
  */
-class BaseList : public Object
+class BaseImmutableList : public Object
 {
-  typedef std::vector<jobject> ovector;
-
 public:
   /**
    * Returns the number of elements in the list.
    */
   jint length() const
     {
-      return jint(m_contents.size());
+      return m_env.CallIntMethod(m_jthis, impl().m_mid_size);
+    }
+
+  /**
+   * Checks if the list is empty.
+   */
+  bool is_empty() const
+    {
+      return (length() == 0);
     }
 
 protected:
   /**
-   * Constructs the list wrapper, converting the contents to an
-   * @c std::vector.
+   * Constructs the list wrapper
    */
-  explicit BaseList(Env env, jobject jlist)
-    : Object(env, ClassCache::get_list(env), jlist),
-      m_contents(convert_to_vector(env, m_jthis))
+  explicit BaseImmutableList(Env env, jobject jlist)
+    : Object(env, ClassCache::get_list(env), jlist)
     {}
 
   /**
-   * Returns the object reference at @a index.
-   * @throw std::out_of_range if the index value is not valid.
+   * Constructor used by BaseList
    */
-  jobject operator[](jint index) const
+  explicit BaseImmutableList(Env env, const Object::ClassImpl* pimpl,
+                             jobject jlist)
+    : Object(env, pimpl, jlist)
+    {}
+
+  /**
+   * Clears the contents of the list.
+   */
+  void clear()
     {
-      return m_contents[ovector::size_type(index)];
+      m_env.CallVoidMethod(m_jthis, impl().m_mid_clear);
     }
 
-  const ovector m_contents;
+  /**
+   * Appends @a obj to the end of the list.
+   */
+  void add(jobject obj)
+    {
+      m_env.CallVoidMethod(m_jthis, impl().m_mid_add, obj);
+    }
+
+  /**
+   * Returns the object reference at @a index.
+   * @throw std::out_of_range if the index value is not valid.
+   */
+  jobject operator[](jint index) const;
+
+  /**
+   * Iterator used by subclasses.
+   */
+  class Iterator : public BaseIterator
+  {
+    friend class BaseImmutableList;
+    explicit Iterator(Env env, jobject jiterator)
+      : BaseIterator(env, jiterator)
+      {}
+  };
+
+  /**
+   * Returns an iterator instance.
+   */
+  Iterator get_iterator() const;
 
-private:
   /**
    * This object's implementation details.
    */
@@ -89,11 +123,15 @@ private:
 
     const MethodID m_mid_size;
     const MethodID m_mid_get;
+    const MethodID m_mid_add;
+    const MethodID m_mid_clear;
+    const MethodID m_mid_iter;
   };
 
+private:
+  friend class Iterator;
   friend class ClassCacheImpl;
   static const char* const m_class_name;
-  static ovector convert_to_vector(Env env, jobject jlist);
 
   const ClassImpl& impl() const
     {
@@ -107,15 +145,14 @@ private:
  * @since New in 1.9.
  */
 template <typename T, typename NativeT=jobject>
-class List : public BaseList
+class ImmutableList : public BaseImmutableList
 {
 public:
   /**
-   * Constructs the list wrapper, converting the contents to an
-   * @c std::vector.
+   * Constructs the list wrapper.
    */
-  explicit List(Env env, jobject jlist)
-    : BaseList(env, jlist)
+  explicit ImmutableList(Env env, jobject jlist)
+    : BaseImmutableList(env, jlist)
     {}
 
   /**
@@ -124,7 +161,7 @@ public:
    */
   T operator[](jint index) const
     {
-      return T(m_env, NativeT(BaseList::operator[](index)));
+      return T(m_env, NativeT(BaseImmutableList::operator[](index)));
     }
 
   /**
@@ -135,29 +172,11 @@ public:
   template<typename F>
   F for_each(F function) const
     {
-      const FunctorAdapter<F> adapter(m_env, function);
-      std::for_each(m_contents.begin(), m_contents.end(), adapter);
+      Iterator iter(get_iterator());
+      while (iter.has_next())
+        function(T(m_env, NativeT(iter.next())));
       return function;
     }
-
-private:
-  template<typename F>
-  struct FunctorAdapter
-  {
-    explicit FunctorAdapter(const Env& env, F& function)
-      : m_env(env),
-        m_function(function)
-      {}
-
-    void operator()(const jobject& obj) const
-      {
-        const T item(m_env, NativeT(obj));
-        m_function(item);
-      }
-
-    const Env& m_env;
-    F& m_function;
-  };
 };
 
 /**
@@ -165,7 +184,7 @@ private:
  *
  * @since New in 1.9.
  */
-class BaseMutableList : public Object
+class BaseList : public BaseImmutableList
 {
 public:
   /**
@@ -173,66 +192,40 @@ public:
    */
   void clear()
     {
-      m_env.CallVoidMethod(m_jthis, impl().m_mid_clear);
-    }
-
-  /**
-   * Returns the number of elements in the list.
-   */
-  jint length() const
-    {
-      return m_env.CallIntMethod(m_jthis, impl().m_mid_size);
-    }
-
-  /**
-   * Checks if the list is empty.
-   */
-  bool is_empty() const
-    {
-      return (length() == 0);
+      BaseImmutableList::clear();
     }
 
 protected:
   /**
-   * Constructs the list wrapper, deriving the class from @a jlist.
+   * Constructs the list wrapper, treating @a jlist as a @c java.util.List.
    */
-  explicit BaseMutableList(Env env, jobject jlist)
-    : Object(env, ClassCache::get_array_list(env), jlist)
+  explicit BaseList(Env env, jobject jlist)
+    : BaseImmutableList(env, jlist)
     {}
 
   /**
    * Constructs and wraps an empty list of type @c java.util.ArrayList
    * with initial allocation size @a length.
    */
-  explicit BaseMutableList(Env env, jint length)
-    : Object(env, ClassCache::get_array_list(env))
+  explicit BaseList(Env env, jint length)
+    : BaseImmutableList(env, ClassCache::get_array_list(env), NULL)
     {
       set_this(env.NewObject(get_class(), impl().m_mid_ctor, length));
     }
 
-
   /**
    * Appends @a obj to the end of the list.
    */
   void add(jobject obj)
     {
-      m_env.CallBooleanMethod(m_jthis, impl().m_mid_add, obj);
-    }
-
-  /**
-   * Returns the object reference at @a index.
-   * @note Throws a Java exception if the index value is not valid.
-   */
-  jobject operator[](jint index) const
-    {
-      return m_env.CallObjectMethod(m_jthis, impl().m_mid_get, index);
+      BaseImmutableList::add(obj);
     }
 
 private:
   /**
    * This object's implementation details.
    */
-  class ClassImpl : public Object::ClassImpl
+  class ClassImpl : public BaseImmutableList::ClassImpl
   {
     friend class ClassCacheImpl;
 
@@ -243,10 +236,6 @@ private:
     virtual ~ClassImpl();
 
     const MethodID m_mid_ctor;
-    const MethodID m_mid_add;
-    const MethodID m_mid_clear;
-    const MethodID m_mid_get;
-    const MethodID m_mid_size;
   };
 
   friend class ClassCacheImpl;
@@ -264,39 +253,53 @@ private:
  * @since New in 1.9.
  */
 template <typename T, typename NativeT=jobject>
-class MutableList : public BaseMutableList
+class List : public BaseList
 {
 public:
   /**
    * Constructs the list wrapper, deriving the class from @a jlist.
    */
-  explicit MutableList(Env env, jobject jlist)
-    : BaseMutableList(env, jlist)
+  explicit List(Env env, jobject jlist)
+    : BaseList(env, jlist)
     {}
 
   /**
    * Constructs and wraps an empty list of type @c java.util.ArrayList
    * with initial allocation size @a length.
    */
-  explicit MutableList(Env env, jint length_ = 0)
-    : BaseMutableList(env, length_)
+  explicit List(Env env, jint length_ = 0)
+    : BaseList(env, length_)
     {}
 
   /**
+   * Returns a wrapper object for the object reference at @a index.
+   * @throw std::out_of_range if the index value is not valid.
+   */
+  T operator[](jint index) const
+    {
+      return T(m_env, NativeT(BaseList::operator[](index)));
+    }
+
+  /**
    * Appends @a obj to the end of the list.
    */
   void add(const T& obj)
     {
-      BaseMutableList::add(obj.get());
+      BaseList::add(obj.get());
     }
 
   /**
-   * Returns a wrapper object for the object reference at @a index.
-   * @note Throws a Java exception if the index value is not valid.
+   * Iterates over the items in the list, calling @a function for
+   * each item.
+   * @see std::for_each
    */
-  T operator[](jint index) const
+  template<typename F>
+  F for_each(F function) const
     {
-      return T(m_env, NativeT(BaseMutableList::operator[](index)));
+      Iterator iter(get_iterator());
+      while (iter.has_next())
+        function(T(m_env, NativeT(iter.next())));
+      return function;
     }
 };
 

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_object.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_object.hpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_object.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_object.hpp Sat Feb 
7 22:27:07 2015
@@ -171,6 +171,9 @@ public:
   JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(throwable);
   JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(string);
 
+  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(exc_index_out_of_bounds);
+  JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(exc_no_such_element);
+
   JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(list);
   JNIWRAPPER_DECLARE_CACHED_CLASS_ACCESSOR(array_list);
 

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.cpp Sat Feb
 7 22:27:07 2015
@@ -52,16 +52,6 @@ BaseMap::Set::ClassImpl::ClassImpl(Env e
 
 BaseMap::Set::ClassImpl::~ClassImpl() {}
 
-const char* const BaseMap::Iterator::m_class_name = "java/util/Iterator";
-
-BaseMap::Iterator::ClassImpl::ClassImpl(Env env, jclass cls)
-  : Object::ClassImpl(env, cls),
-    m_mid_has_next(env.GetMethodID(cls, "hasNext", "()Z")),
-    m_mid_next(env.GetMethodID(cls, "next", "()Ljava/lang/Object;"))
-{}
-
-BaseMap::Iterator::ClassImpl::~ClassImpl() {}
-
 const char* const BaseMap::Entry::m_class_name = "java/util/Map$Entry";
 
 BaseMap::Entry::ClassImpl::ClassImpl(Env env, jclass cls)
@@ -95,18 +85,16 @@ BaseMap::somap BaseMap::convert_to_map(E
 
   // Get an iterator over the map's entry set
   const jobject entries = env.CallObjectMethod(jmap, pimpl->m_mid_entry_set);
-  const jobject iterator = env.CallObjectMethod(entries,
-                                                Set::impl(env).m_mid_iterator);
-
-  const Iterator::ClassImpl& iterimpl = Iterator::impl(env);
   const Entry::ClassImpl& entimpl = Entry::impl(env);
 
-  // Yterate over the map, filling the native map
+  Iterator iterator(env, env.CallObjectMethod(entries,
+                                              Set::impl(env).m_mid_iterator));
+
+  // Iterate over the map, filling the native map
   somap contents;
-  while (env.CallBooleanMethod(iterator, iterimpl.m_mid_has_next))
+  while (iterator.has_next())
     {
-      const jobject entry =
-        env.CallObjectMethod(iterator, iterimpl.m_mid_next);
+      const jobject entry = iterator.next();
       const String keystr(
           env, jstring(env.CallObjectMethod(entry, entimpl.m_mid_get_key)));
       const jobject value(

Modified: subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp (original)
+++ subversion/trunk/subversion/bindings/javahl/native/jniwrapper/jni_string_map.hpp Sat Feb
 7 22:27:07 2015
@@ -30,6 +30,7 @@
 
 #include "jni_env.hpp"
 #include "jni_object.hpp"
+#include "jni_iterator.hpp"
 
 namespace Java {
 
@@ -123,30 +124,12 @@ private:
       }
   };
 
-  struct Iterator
+  class Iterator : public BaseIterator
   {
-    /**
-     * This object's implementation details.
-     */
-    class ClassImpl : public Object::ClassImpl
-    {
-      friend class ClassCacheImpl;
-
-    protected:
-      explicit ClassImpl(Env env, jclass cls);
-
-    public:
-      virtual ~ClassImpl();
-
-      const MethodID m_mid_has_next;
-      const MethodID m_mid_next;
-    };
-
-    static const char* const m_class_name;
-    static const ClassImpl& impl(Env env)
-      {
-        return *dynamic_cast<const ClassImpl*>(ClassCache::get_iterator(env));
-      }
+    friend class BaseMap;
+    explicit Iterator(Env env, jobject jiterator)
+      : BaseIterator(env, jiterator)
+      {}
   };
 
   struct Entry

Modified: subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_ConfigLib.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_ConfigLib.cpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_ConfigLib.cpp
(original)
+++ subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_ConfigLib.cpp
Sat Feb  7 22:27:07 2015
@@ -343,7 +343,7 @@ Java_org_apache_subversion_javahl_util_C
         const char* const m_text_pattern;
 
         const ::Java::Env m_env;
-        ::Java::MutableList<JavaHL::Credential> m_credentials;
+        ::Java::List<JavaHL::Credential> m_credentials;
 
         bool match_array(const char* pattern,
                          const apr_array_header_t* hostnames)

Modified: subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_PropLib.cpp
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_PropLib.cpp?rev=1658112&r1=1658111&r2=1658112&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_PropLib.cpp
(original)
+++ subversion/trunk/subversion/bindings/javahl/native/org_apache_subversion_javahl_util_PropLib.cpp
Sat Feb  7 22:27:07 2015
@@ -291,7 +291,7 @@ Java_org_apache_subversion_javahl_util_P
                              pool.getPool()));
       }
 
-      Java::MutableList<JavaHL::ExternalItem> items(env, externals->nelts);
+      Java::List<JavaHL::ExternalItem> items(env, externals->nelts);
       for (jint i = 0; i < externals->nelts; ++i)
         {
           // References to the newly created external items are stored
@@ -323,7 +323,7 @@ Java_org_apache_subversion_javahl_util_P
     {
       const Java::Env env(jenv);
 
-      const Java::List<JavaHL::ExternalItem> items(env, jitems);
+      const Java::ImmutableList<JavaHL::ExternalItem> items(env, jitems);
       const Java::String parent_dir(env, jparent_dir);
 
       // Using a "global" iteration pool since we don't keep a context



Mime
View raw message