org.jvnet.hk2.component.MultiMap.getOne()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(69)

本文整理了Java中org.jvnet.hk2.component.MultiMap.getOne()方法的一些代码示例,展示了MultiMap.getOne()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MultiMap.getOne()方法的具体详情如下:
包路径:org.jvnet.hk2.component.MultiMap
类名称:MultiMap
方法名:getOne

MultiMap.getOne介绍

[英]Gets the first value if any, or null.

This is useful when you know the given key only has one value and you'd like to get to that value.
[中]如果有,则返回null。
当您知道给定的键只有一个值并且希望获得该值时,这非常有用。

代码示例

代码示例来源:origin: javaee/glassfish

private void addXRef(Class type, ConfigModel cm) {
  List<ConfigModel> models = implementorsOf.getOne(type);
  if (models==null) {
    models= new ArrayList<ConfigModel>();
    implementorsOf.add(type, models);
  }
  models.add(cm);
}

代码示例来源:origin: javaee/glassfish

/**
 * Calculates all @Configured interfaces subclassing the passed interface type.
 *
 * @param intf a @Configured interface
 * @return List of all @Configured subclasses
 * @throws ClassNotFoundException
 */
public synchronized List<ConfigModel> getAllModelsImplementing(Class intf) throws ClassNotFoundException {
  if (implementorsOf.size()==0) {
    initXRef();
  }
  return implementorsOf.getOne(intf);   
}

代码示例来源:origin: org.glassfish.hk2/auto-depends

public String getImplName() {
  return metadata.getOne(CLASS_KEY);
}

代码示例来源:origin: com.sun.enterprise/auto-depends

public String getImplName() {
  return metadata.getOne(CLASS_KEY);
}

代码示例来源:origin: com.sun.enterprise/auto-depends

protected static Long getServiceRanking(Inhabitant<?> i, boolean wantNonNull) {
  MultiMap<String, String> meta = i.metadata();
  String sr = meta.getOne(Constants.SERVICE_RANKING);
  if (null == sr) {
    return (wantNonNull) ? 0L : null;
  }
  return Long.valueOf(sr);
}

代码示例来源:origin: org.glassfish.hk2/hk2-config

private void addXRef(Class type, ConfigModel cm) {
  List<ConfigModel> models = implementorsOf.getOne(type);
  if (models==null) {
    models= new ArrayList<ConfigModel>();
    implementorsOf.add(type, models);
  }
  models.add(cm);
}

代码示例来源:origin: org.glassfish.hk2/config

private void addXRef(Class type, ConfigModel cm) {
  List<ConfigModel> models = implementorsOf.getOne(type);
  if (models==null) {
    models= new ArrayList<ConfigModel>();
    implementorsOf.add(type, models);
  }
  models.add(cm);
}

代码示例来源:origin: org.glassfish.main.common/common-util

/**
 * Returns the path to the uploaded file if the specified field is of type
 * File and if the field name is the same as one of the option names that
 * was associated with an uploaded File in the incoming command request.
 *
 * @param fieldName name of the field being injected
 * @param fieldType type of the field being injected
 * @param optionNameToFileMap map of field names to uploaded Files
 * @return absolute path of the uploaded file for the field;
 *          null if no file uploaded for this field
 */
public static String getUploadedFileParamValue(final String fieldName,
      final Class fieldType,
      final MultiMap<String,File> optionNameToFileMap) {
  if (optionNameToFileMap == null) {
    return null;
  }
  final File uploadedFile = optionNameToFileMap.getOne(fieldName);
  if (uploadedFile != null && fieldType.isAssignableFrom(File.class)) {
    return uploadedFile.getAbsolutePath();
  } else {
    return null;
  }
}

代码示例来源:origin: org.glassfish.hk2/auto-depends

protected static Long getServiceRanking(Inhabitant<?> i, boolean wantNonNull) {
  MultiMap<String, String> meta = i.metadata();
  String sr = meta.getOne(Constants.SERVICE_RANKING);
  if (null == sr) {
    return (wantNonNull) ? 0L : null;
  }
  return Long.valueOf(sr);
}

代码示例来源:origin: eclipse-ee4j/glassfish

private void addXRef(Class type, ConfigModel cm) {
  List<ConfigModel> models = implementorsOf.getOne(type);
  if (models==null) {
    models= new ArrayList<ConfigModel>();
    implementorsOf.add(type, models);
  }
  models.add(cm);
}

代码示例来源:origin: eclipse-ee4j/glassfish

/**
 * Returns the path to the uploaded file if the specified field is of type
 * File and if the field name is the same as one of the option names that
 * was associated with an uploaded File in the incoming command request.
 *
 * @param fieldName name of the field being injected
 * @param fieldType type of the field being injected
 * @param optionNameToFileMap map of field names to uploaded Files
 * @return absolute path of the uploaded file for the field;
 *          null if no file uploaded for this field
 */
public static String getUploadedFileParamValue(final String fieldName,
      final Class fieldType,
      final MultiMap<String,File> optionNameToFileMap) {
  if (optionNameToFileMap == null) {
    return null;
  }
  final File uploadedFile = optionNameToFileMap.getOne(fieldName);
  if (uploadedFile != null && fieldType.isAssignableFrom(File.class)) {
    return uploadedFile.getAbsolutePath();
  } else {
    return null;
  }
}

代码示例来源:origin: org.glassfish.cluster/cluster-admin

/**
 * Get list of all supplemental commands, map it to various commands and cache htis list
 */
private Map<String, List<Inhabitant<? extends Supplemental>>> getSupplementalCommandsList() {
  if(supplementalCommandsMap == null) {
    synchronized(this) {
      if(supplementalCommandsMap == null) {
        supplementalCommandsMap = new ConcurrentHashMap<String, List<Inhabitant<? extends Supplemental>>>();
        Collection<Inhabitant<? extends Supplemental>> supplementals = habitat.getInhabitants(Supplemental.class);
        if(!supplementals.isEmpty()) {
          Iterator<Inhabitant<? extends Supplemental>> iter = supplementals.iterator();
          while(iter.hasNext()) {
            Inhabitant<? extends Supplemental> inh = iter.next();
            String commandName = inh.metadata().getOne("target");
            if(supplementalCommandsMap.containsKey(commandName)) {
              supplementalCommandsMap.get(commandName).add(inh);
            } else {
              ArrayList<Inhabitant<? extends Supplemental>> inhList =
                  new ArrayList<Inhabitant<? extends Supplemental>>();
              inhList.add(inh);
              supplementalCommandsMap.put(commandName, inhList);
            }
          }
        }
      }
    }
  }
  return supplementalCommandsMap;
}

代码示例来源:origin: org.glassfish.hk2/config

/**
 * Calculates all @Configured interfaces subclassing the passed interface type.
 *
 * @param intf a @Configured interface
 * @return List of all @Configured subclasses
 * @throws ClassNotFoundException
 */
public synchronized List<ConfigModel> getAllModelsImplementing(Class intf) throws ClassNotFoundException {
  if (implementorsOf.size()==0) {
    initXRef();
  }
  return implementorsOf.getOne(intf);   
}

代码示例来源:origin: org.glassfish.hk2/hk2-config

/**
 * Calculates all @Configured interfaces subclassing the passed interface type.
 *
 * @param intf a @Configured interface
 * @return List of all @Configured subclasses
 * @throws ClassNotFoundException
 */
public synchronized List<ConfigModel> getAllModelsImplementing(Class intf) throws ClassNotFoundException {
  if (implementorsOf.size()==0) {
    initXRef();
  }
  return implementorsOf.getOne(intf);   
}

代码示例来源:origin: eclipse-ee4j/glassfish

/**
 * Calculates all @Configured interfaces subclassing the passed interface type.
 *
 * @param intf a @Configured interface
 * @return List of all @Configured subclasses
 * @throws ClassNotFoundException
 */
public synchronized List<ConfigModel> getAllModelsImplementing(Class intf) throws ClassNotFoundException {
  if (implementorsOf.size()==0) {
    initXRef();
  }
  return implementorsOf.getOne(intf);   
}

代码示例来源:origin: com.sun.enterprise/config

/**
 * Calculates all @Configured interfaces subclassing the passed interface type.
 *
 * @param intf a @Configured interface
 * @return List of all @Configured subclasses
 * @throws ClassNotFoundException
 */
public synchronized List<ConfigModel> getAllModelsImplementing(Class intf) throws ClassNotFoundException {
  if (implementorsOf.size()==0) {
    initXRef();
  }
  return implementorsOf.getOne(intf);   
}

代码示例来源:origin: com.sun.enterprise/auto-depends

/**
 * Attempts to obtain the RunLevel value from the metadata() instead of from the annotation
 * which requires a class load.  If it can't get it from the metadata() it will default to
 * load the class to obtain the RunLevel value.
 *  
 * @param i the inhabitant to get the runLevel for
 * 
 * @return
 */
protected Integer getRunLevel(AbstractInhabitantImpl<?> i) {
 Integer activeRunLevel;
 
 String runlevel = i.metadata().getOne(RunLevel.META_VAL_TAG);
 if (null != runlevel && runlevel.length() > 0) {
  activeRunLevel = Integer.valueOf(runlevel);
 } else {
  RunLevel rl = i.getAnnotation(RunLevel.class);
  activeRunLevel = (null == rl) ? null : rl.value();
 }
 return activeRunLevel;
}

代码示例来源:origin: com.sun.enterprise/config

/**
 * probably a bit slow, calculates all the @Configured interfaces subclassing, useful
 * to find all possible subclasses of a type.
 * 
 * @throws ClassNotFoundException
 */
private void initXRef() throws ClassNotFoundException {
  // force initialization of all the config models.
  for (Inhabitant<? extends ConfigInjector> i : habitat.getInhabitants(ConfigInjector.class)) {
    buildModel(i);
  }
  for (ConfigModel cm : models.values()) {
    Class targetType = cm.classLoaderHolder.get().loadClass(cm.targetTypeName);
    do {
      Class[] intfs = targetType.getInterfaces();
      for (Class intf : intfs) {
        if (intf.isAnnotationPresent(Configured.class)) {
          List<ConfigModel> models = implementorsOf.getOne(intf);
          if (models==null) {
            models = new ArrayList<ConfigModel>();
            implementorsOf.add(intf, models);
          }
          models.add(cm);
        }
      }
      targetType = targetType.getSuperclass();
    } while (targetType!=null);
  }
}

代码示例来源:origin: org.glassfish.hk2/auto-depends

/**
 * Attempts to obtain the RunLevel value from the metadata() instead of from
 * the annotation which requires a class load. If it can't get it from the
 * metadata() it will default to load the class to obtain the RunLevel
 * value.
 * 
 * @param i
 *            the inhabitant to get the runLevel for
 * 
 * @return
 */
protected Integer getRunLevel(AbstractInhabitantImpl<?> i) {
  Integer activeRunLevel;
  
  String runlevel = i.metadata().getOne(RunLevel.META_VAL_TAG);
  if (null != runlevel && runlevel.length() > 0) {
    activeRunLevel = Integer.valueOf(runlevel);
  } else {
    RunLevel rl = i.getAnnotation(RunLevel.class);
    activeRunLevel = (null == rl) ? null : rl.value();
  }
  
  return activeRunLevel;
}

代码示例来源:origin: com.sun.enterprise/auto-depends

@Override
public <T> T getSerializedMetadata(final Class<T> type, String key) {
  String v = metadata().getOne(key);
  if (v==null) {
    return null;
  }
  try {
    ObjectInputStream is = new ObjectInputStream(new ByteArrayInputStream(new BASE64Decoder().decodeBuffer(v))) {
      final ClassLoader cl = type.getClassLoader();
      /**
       * Use ClassLoader of the given type. Otherwise by default we end up using the classloader
       * that loaded HK2, which won't be able to see most of the user classes.
       */
      protected Class<?> resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException {
        String name = desc.getName();
        try {
          return Class.forName(name,false,cl);
        } catch (ClassNotFoundException ex) {
          return super.resolveClass(desc);
        }
      }
    };
    return type.cast(is.readObject());
  } catch (ClassNotFoundException e) {
    throw new Error(e);
  } catch (IOException e) {
    throw new Error(e);
  }
}

相关文章