/**
   * Closes given {@link #transportManagers} of this <tt>Conference</tt> and removes corresponding
   * channel bundle.
   */
  void closeTransportManager(TransportManager transportManager) {
    synchronized (transportManagers) {
      for (Iterator<IceUdpTransportManager> i = transportManagers.values().iterator();
          i.hasNext(); ) {
        if (i.next() == transportManager) {
          i.remove();
          // Presumably, we have a single association for
          // transportManager.
          break;
        }
      }

      // Close manager
      try {
        transportManager.close();
      } catch (Throwable t) {
        logger.warn(
            "Failed to close an IceUdpTransportManager of" + " conference " + getID() + "!", t);
        // The whole point of explicitly closing the
        // transportManagers of this Conference is to prevent memory
        // leaks. Hence, it does not make sense to possibly leave
        // TransportManagers open because a TransportManager has
        // failed to close.
        if (t instanceof InterruptedException) Thread.currentThread().interrupt();
        else if (t instanceof ThreadDeath) throw (ThreadDeath) t;
      }
    }
  }
  static {
    try {
      Map<String, Method> orderedMethods = new TreeMap<String, Method>();
      for (Method m : MBeanServerConnection.class.getDeclaredMethods()) {
        orderedMethods.put(m.toGenericString(), m);
      }
      Method[] methods = orderedMethods.values().toArray(new Method[orderedMethods.size()]);
      Map<String, Method> asynchMethods = new TreeMap<String, Method>();
      for (Method asynchMethod : AsynchJMXResponseListener.class.getDeclaredMethods()) {
        asynchMethods.put(asynchMethod.getName(), asynchMethod);
      }

      Map<Method, Byte> m2k = new HashMap<Method, Byte>(methods.length);
      Map<Byte, Method> k2m = new HashMap<Byte, Method>(methods.length);
      Map<Byte, Method> k2am = new HashMap<Byte, Method>(methods.length);
      for (int i = 0; i < methods.length; i++) {
        m2k.put(methods[i], (byte) i);
        k2m.put((byte) i, methods[i]);
        Method asynchMethod = asynchMethods.get(methods[i].getName() + "Response");
        if (asynchMethod == null)
          throw new RuntimeException(
              "Failed to find asynch handler for [" + methods[i].toGenericString() + "]",
              new Throwable());
        k2am.put((byte) i, asynchMethod);
      }
      methodToKey = Collections.unmodifiableMap(m2k);
      keyToMethod = Collections.unmodifiableMap(k2m);
      keyToAsynchMethod = Collections.unmodifiableMap(k2am);
    } catch (Exception ex) {
      throw new RuntimeException(ex);
    }
  }
示例#3
0
 public JavaType[] typesAsArray() {
   if (_bindings == null) {
     _resolve();
   }
   if (_bindings.size() == 0) {
     return NO_TYPES;
   }
   return _bindings.values().toArray(new JavaType[_bindings.size()]);
 }
  void decode(final T o, final Entry e) throws LDAPPersistException {
    if (superclassHandler != null) {
      superclassHandler.decode(o, e);
    }

    setDNAndEntryFields(o, e);

    final ArrayList<String> failureReasons = new ArrayList<String>(5);
    boolean successful = true;

    for (final FieldInfo i : fieldMap.values()) {
      successful &= i.decode(o, e, failureReasons);
    }

    for (final SetterInfo i : setterMap.values()) {
      successful &= i.invokeSetter(o, e, failureReasons);
    }

    Throwable cause = null;
    if (postDecodeMethod != null) {
      try {
        postDecodeMethod.invoke(o);
      } catch (final Throwable t) {
        debugException(t);

        if (t instanceof InvocationTargetException) {
          cause = ((InvocationTargetException) t).getTargetException();
        } else {
          cause = t;
        }

        successful = false;
        failureReasons.add(
            ERR_OBJECT_HANDLER_ERROR_INVOKING_POST_DECODE_METHOD.get(
                postDecodeMethod.getName(), type.getName(), getExceptionMessage(t)));
      }
    }

    if (!successful) {
      throw new LDAPPersistException(concatenateStrings(failureReasons), o, cause);
    }
  }
  /**
   * @param cls Component class.
   * @param <T> Component type.
   * @return Component class instance or {@code null} if no one plugin override this component.
   */
  public <T> T createComponent(Class<T> cls) {
    for (PluginProvider plugin : plugins.values()) {
      PluginContext ctx = pluginContextForProvider(plugin);

      T comp = (T) plugin.createComponent(ctx, cls);

      if (comp != null) return comp;
    }

    return null;
  }
  /** Closes the {@link #transportManagers} of this <tt>Conference</tt>. */
  private void closeTransportManagers() {
    synchronized (transportManagers) {
      for (Iterator<IceUdpTransportManager> i = transportManagers.values().iterator();
          i.hasNext(); ) {
        IceUdpTransportManager transportManager = i.next();

        i.remove();
        closeTransportManager(transportManager);
      }
    }
  }
  public Map defaultArguments() {
    Map defaults = new LinkedHashMap();
    Collection values = defaultArguments.values();

    Iterator iter = values.iterator();
    while (iter.hasNext()) {
      ArgumentImpl argument = (ArgumentImpl) iter.next();
      defaults.put(argument.name(), argument.clone());
    }
    return defaults;
  }
示例#8
0
 Map<String, FieldAndMethods> getFieldAndMethodsObjects(
     Scriptable scope, Object javaObject, boolean isStatic) {
   Map<String, FieldAndMethods> ht = isStatic ? staticFieldAndMethods : fieldAndMethods;
   if (ht == null) return null;
   int len = ht.size();
   Map<String, FieldAndMethods> result = new HashMap<String, FieldAndMethods>(len);
   for (FieldAndMethods fam : ht.values()) {
     FieldAndMethods famNew = new FieldAndMethods(scope, fam.methods, fam.field);
     famNew.javaObject = javaObject;
     result.put(fam.field.getName(), famNew);
   }
   return result;
 }
  /** Print plugins information. */
  private void ackPluginsInfo() {
    U.quietAndInfo(log, "Configured plugins:");

    if (plugins.isEmpty()) {
      U.quietAndInfo(log, "  ^-- None");
      U.quietAndInfo(log, "");
    } else {
      for (PluginProvider plugin : plugins.values()) {
        U.quietAndInfo(log, "  ^-- " + plugin.name() + " " + plugin.version());
        U.quietAndInfo(log, "  ^-- " + plugin.copyright());
        U.quietAndInfo(log, "");
      }
    }
  }
示例#10
0
文件: Query.java 项目: aaberg/sql2o
  public Query bind(final Object pojo) {
    Class clazz = pojo.getClass();
    Map<String, PojoIntrospector.ReadableProperty> propertyMap =
        PojoIntrospector.readableProperties(clazz);
    for (PojoIntrospector.ReadableProperty property : propertyMap.values()) {
      try {
        if (this.getParamNameToIdxMap().containsKey(property.name)) {

          @SuppressWarnings("unchecked")
          final Class<Object> type = (Class<Object>) property.type;
          this.addParameter(property.name, type, property.get(pojo));
        }
      } catch (IllegalArgumentException ex) {
        logger.debug("Ignoring Illegal Arguments", ex);
      } catch (IllegalAccessException | InvocationTargetException ex) {
        throw new RuntimeException(ex);
      }
    }
    return this;
  }
  List<Modification> getModifications(
      final T o, final boolean deleteNullValues, final String... attributes)
      throws LDAPPersistException {
    final ReadOnlyEntry originalEntry;
    if (entryField != null) {
      originalEntry = getEntry(o);
    } else {
      originalEntry = null;
    }
    if (originalEntry != null) {
      try {
        final T decodedOrig = decode(originalEntry);
        final Entry reEncodedOriginal = encode(decodedOrig, originalEntry.getParentDNString());

        final Entry newEntry = encode(o, originalEntry.getParentDNString());
        final List<Modification> mods =
            Entry.diff(reEncodedOriginal, newEntry, true, false, attributes);
        if (!deleteNullValues) {
          final Iterator<Modification> iterator = mods.iterator();
          while (iterator.hasNext()) {
            final Modification m = iterator.next();
            if (m.getRawValues().length == 0) {
              iterator.remove();
            }
          }
        }

        HashSet<String> stripAttrs = null;
        for (final FieldInfo i : fieldMap.values()) {
          if (!i.includeInModify()) {
            if (stripAttrs == null) {
              stripAttrs = new HashSet<String>(10);
            }
            stripAttrs.add(toLowerCase(i.getAttributeName()));
          }
        }

        for (final GetterInfo i : getterMap.values()) {
          if (!i.includeInModify()) {
            if (stripAttrs == null) {
              stripAttrs = new HashSet<String>(10);
            }
            stripAttrs.add(toLowerCase(i.getAttributeName()));
          }
        }

        if (stripAttrs != null) {
          final Iterator<Modification> iterator = mods.iterator();
          while (iterator.hasNext()) {
            final Modification m = iterator.next();
            if (stripAttrs.contains(toLowerCase(m.getAttributeName()))) {
              iterator.remove();
            }
          }
        }

        return mods;
      } catch (final Exception e) {
        debugException(e);
      } finally {
        setDNAndEntryFields(o, originalEntry);
      }
    }

    final HashSet<String> attrSet;
    if ((attributes == null) || (attributes.length == 0)) {
      attrSet = null;
    } else {
      attrSet = new HashSet<String>(attributes.length);
      for (final String s : attributes) {
        attrSet.add(toLowerCase(s));
      }
    }

    final ArrayList<Modification> mods = new ArrayList<Modification>(5);

    for (final Map.Entry<String, FieldInfo> e : fieldMap.entrySet()) {
      final String attrName = toLowerCase(e.getKey());
      if ((attrSet != null) && (!attrSet.contains(attrName))) {
        continue;
      }

      final FieldInfo i = e.getValue();
      if (!i.includeInModify()) {
        continue;
      }

      final Attribute a = i.encode(o, false);
      if (a == null) {
        if (!deleteNullValues) {
          continue;
        }

        if ((originalEntry != null) && (!originalEntry.hasAttribute(attrName))) {
          continue;
        }

        mods.add(new Modification(ModificationType.REPLACE, i.getAttributeName()));
        continue;
      }

      if (originalEntry != null) {
        final Attribute originalAttr = originalEntry.getAttribute(attrName);
        if ((originalAttr != null) && originalAttr.equals(a)) {
          continue;
        }
      }

      mods.add(new Modification(ModificationType.REPLACE, i.getAttributeName(), a.getRawValues()));
    }

    for (final Map.Entry<String, GetterInfo> e : getterMap.entrySet()) {
      final String attrName = toLowerCase(e.getKey());
      if ((attrSet != null) && (!attrSet.contains(attrName))) {
        continue;
      }

      final GetterInfo i = e.getValue();
      if (!i.includeInModify()) {
        continue;
      }

      final Attribute a = i.encode(o);
      if (a == null) {
        if (!deleteNullValues) {
          continue;
        }

        if ((originalEntry != null) && (!originalEntry.hasAttribute(attrName))) {
          continue;
        }

        mods.add(new Modification(ModificationType.REPLACE, i.getAttributeName()));
        continue;
      }

      if (originalEntry != null) {
        final Attribute originalAttr = originalEntry.getAttribute(attrName);
        if ((originalAttr != null) && originalAttr.equals(a)) {
          continue;
        }
      }

      mods.add(new Modification(ModificationType.REPLACE, i.getAttributeName(), a.getRawValues()));
    }

    if (superclassHandler != null) {
      final List<Modification> superMods =
          superclassHandler.getModifications(o, deleteNullValues, attributes);
      final ArrayList<Modification> modsToAdd = new ArrayList<Modification>(superMods.size());
      for (final Modification sm : superMods) {
        boolean add = true;
        for (final Modification m : mods) {
          if (m.getAttributeName().equalsIgnoreCase(sm.getAttributeName())) {
            add = false;
            break;
          }
        }
        if (add) {
          modsToAdd.add(sm);
        }
      }
      mods.addAll(modsToAdd);
    }

    return Collections.unmodifiableList(mods);
  }
  ObjectClassDefinition constructObjectClass(
      final String name, final String sup, final ObjectClassType type, final OIDAllocator a) {
    final TreeMap<String, String> requiredAttrs = new TreeMap<String, String>();
    final TreeMap<String, String> optionalAttrs = new TreeMap<String, String>();

    for (final FieldInfo i : fieldMap.values()) {
      boolean found = false;
      for (final String s : i.getObjectClasses()) {
        if (name.equalsIgnoreCase(s)) {
          found = true;
          break;
        }
      }

      if (!found) {
        continue;
      }

      final String attrName = i.getAttributeName();
      final String lowerName = toLowerCase(attrName);
      if (i.includeInRDN() || (i.isRequiredForDecode() && i.isRequiredForEncode())) {
        requiredAttrs.put(lowerName, attrName);
      } else {
        optionalAttrs.put(lowerName, attrName);
      }
    }

    for (final GetterInfo i : getterMap.values()) {
      boolean found = false;
      for (final String s : i.getObjectClasses()) {
        if (name.equalsIgnoreCase(s)) {
          found = true;
          break;
        }
      }

      if (!found) {
        continue;
      }

      final String attrName = i.getAttributeName();
      final String lowerName = toLowerCase(attrName);
      if (i.includeInRDN()) {
        requiredAttrs.put(lowerName, attrName);
      } else {
        optionalAttrs.put(lowerName, attrName);
      }
    }

    if (name.equalsIgnoreCase(structuralClass)) {
      for (final SetterInfo i : setterMap.values()) {
        final String attrName = i.getAttributeName();
        final String lowerName = toLowerCase(attrName);
        if (requiredAttrs.containsKey(lowerName) || optionalAttrs.containsKey(lowerName)) {
          continue;
        }

        optionalAttrs.put(lowerName, attrName);
      }
    }

    final String[] reqArray = new String[requiredAttrs.size()];
    requiredAttrs.values().toArray(reqArray);

    final String[] optArray = new String[optionalAttrs.size()];
    optionalAttrs.values().toArray(optArray);

    return new ObjectClassDefinition(
        a.allocateObjectClassOID(name),
        new String[] {name},
        null,
        false,
        new String[] {sup},
        type,
        reqArray,
        optArray,
        null);
  }
  public static String generateProxy(Class interfaceClass) throws Exception {
    StringBuilder b = new StringBuilder();
    b.append("#include <jni.h>\n");
    b.append("#ifdef _WIN32\n");
    b.append("#define PROXY_EXPORT __declspec(dllexport)\n");
    b.append("#else\n");
    b.append("#define PROXY_EXPORT\n");
    b.append("#endif\n");
    b.append(
        "#define FIND_GLOBAL_CLASS(name) (*env)->NewGlobalRef(env, (*env)->FindClass(env, name))\n");

    List<ProxiedMethod> methods = new ArrayList<ProxiedMethod>();
    int iClassName = 0, iMethodName = 0;
    Map<Class, String> classVarNames = new HashMap<Class, String>();

    for (Method m : interfaceClass.getDeclaredMethods()) {
      try {
        ProxiedMethod pm = getProxiedMethod(m);
        String classVarName = classVarNames.get(pm.owner);
        if (classVarName == null)
          classVarNames.put(pm.owner, classVarName = "gClass" + (++iClassName));
        pm.classVarName = classVarName;
        pm.methodVarName = "gMethod" + (++iMethodName);
        methods.add(pm);
      } catch (Throwable th) {
        // th.printStackTrace();
      }
    }

    b.append("jboolean inited = JNI_FALSE;\n");
    String instanceVarName = "gProxiedInstance";
    b.append("JNIEnv* env = NULL;\n");
    b.append("JavaVM* jvm = NULL;\n");
    b.append("jobject ").append(instanceVarName).append(" = NULL;\n");
    for (String n : classVarNames.values()) b.append("jclass ").append(n).append(" = NULL;\n");

    for (ProxiedMethod pm : methods)
      b.append("jmethodID ").append(pm.methodVarName).append(" = NULL;\n");

    String jniInit = "jni_init";
    b.append("void ").append(jniInit).append("(JNIEnv* env) {\n");
    b.append("\tif (inited) return; else inited = JNI_TRUE;\n");

    for (Map.Entry<Class, String> e : classVarNames.entrySet()) {
      String n = e.getValue();
      Class c = e.getKey();
      b.append("\t")
          .append(n)
          .append(" = ")
          .append("FIND_GLOBAL_CLASS(\"")
          .append(name(c))
          .append("\");\n");
    }
    for (ProxiedMethod pm : methods) {
      int mods = pm.method.getModifiers();
      b.append("\t")
          .append(pm.methodVarName)
          .append(" = ")
          .append("(*env)->")
          .append(Modifier.isStatic(mods) ? "GetStaticMethodID" : "GetMethodID")
          .append("(env, ")
          .append(pm.classVarName)
          .append(", \"")
          .append(pm.name)
          .append("\", \"")
          .append(pm.jni_signature)
          .append("\");\n");
    }
    b.append("}\n");

    for (ProxiedMethod pm : methods) {
      b.append("PROXY_EXPORT ").append(pm.c_signature).append(" {\n");
      int mods = pm.method.getModifiers();

      b.append("\t").append(jniInit).append("();\n");
      b.append("\t");
      if (pm.method.getReturnType() != null && !pm.method.getReturnType().equals(void.class))
        b.append("return ");

      StringBuilder r = new StringBuilder();

      boolean stat = Modifier.isStatic(mods);
      r.append("(*env)->")
          .append("Call" + (stat ? "Static" : "") + pm.retCapitalized + "Method")
          .append("(env, ");
      if (stat) r.append(pm.classVarName);
      else r.append(instanceVarName);
      for (String argValue : pm.argValues) {
        r.append(", \n\t\t");
        r.append(argValue);
      }

      // TODO...
      r.append("\n\t)");
      b.append(c_signature(pm.method.getReturnType(), r.toString())[2]);

      b.append(";\n");

      b.append("}\n");
    }

    return b.toString();
  }
 /** @return All plugin providers. */
 public Collection<PluginProvider> allProviders() {
   return plugins.values();
 }
示例#15
0
 /**
  * Retrieves mapping of methods to accessible methods for a class. In case the class is not
  * public, retrieves methods with same signature as its public methods from public superclasses
  * and interfaces (if they exist). Basically upcasts every method to the nearest accessible
  * method.
  */
 private static Method[] discoverAccessibleMethods(
     Class<?> clazz, boolean includeProtected, boolean includePrivate) {
   Map<MethodSignature, Method> map = new HashMap<MethodSignature, Method>();
   discoverAccessibleMethods(clazz, map, includeProtected, includePrivate);
   return map.values().toArray(new Method[map.size()]);
 }
示例#16
0
  /**
   * Process each package and the classes/interfaces within it.
   *
   * @param pd an array of PackageDoc objects
   */
  public void processPackages(RootDoc root) {
    PackageDoc[] specified_pd = root.specifiedPackages();
    Map pdl = new TreeMap();
    for (int i = 0; specified_pd != null && i < specified_pd.length; i++) {
      pdl.put(specified_pd[i].name(), specified_pd[i]);
    }

    // Classes may be specified separately, so merge their packages into the
    // list of specified packages.
    ClassDoc[] cd = root.specifiedClasses();
    // This is lists of the specific classes to document
    Map classesToUse = new HashMap();
    for (int i = 0; cd != null && i < cd.length; i++) {
      PackageDoc cpd = cd[i].containingPackage();
      if (cpd == null && !packagesOnly) {
        // If the RootDoc object has been created from a jar file
        // this duplicates classes, so we have to be able to disable it.
        // TODO this is still null?
        cpd = root.packageNamed("anonymous");
      }
      String pkgName = cpd.name();
      String className = cd[i].name();
      if (trace) System.out.println("Found package " + pkgName + " for class " + className);
      if (!pdl.containsKey(pkgName)) {
        if (trace) System.out.println("Adding new package " + pkgName);
        pdl.put(pkgName, cpd);
      }

      // Keep track of the specific classes to be used for this package
      List classes;
      if (classesToUse.containsKey(pkgName)) {
        classes = (ArrayList) classesToUse.get(pkgName);
      } else {
        classes = new ArrayList();
      }
      classes.add(cd[i]);
      classesToUse.put(pkgName, classes);
    }

    PackageDoc[] pd = (PackageDoc[]) pdl.values().toArray(new PackageDoc[0]);
    for (int i = 0; pd != null && i < pd.length; i++) {
      String pkgName = pd[i].name();

      // Check for an exclude tag in the package doc block, but not
      // in the package.htm[l] file.
      if (!shownElement(pd[i], null)) continue;

      if (trace) System.out.println("PROCESSING PACKAGE: " + pkgName);
      outputFile.println("<package name=\"" + pkgName + "\">");

      int tagCount = pd[i].tags().length;
      if (trace) System.out.println("#tags: " + tagCount);

      List classList;
      if (classesToUse.containsKey(pkgName)) {
        // Use only the specified classes in the package
        System.out.println("Using the specified classes");
        classList = (ArrayList) classesToUse.get(pkgName);
      } else {
        // Use all classes in the package
        classList = new LinkedList(Arrays.asList(pd[i].allClasses()));
      }
      Collections.sort(classList);
      ClassDoc[] classes = new ClassDoc[classList.size()];
      classes = (ClassDoc[]) classList.toArray(classes);
      processClasses(classes, pkgName);

      addPkgDocumentation(root, pd[i], 2);

      outputFile.println("</package>");
    }
  } // processPackages