Beispiel #1
0
 /**
  * Return ignored set of attributes.
  *
  * @param tag the tag
  * @param context the context
  * @return the ignored attr name set, or null.
  */
 protected Set<String> getIgnoredAttributes(T tag, IParserContext context) {
   Conditional cond = ReflectUtils.getAnnotation(tag.getClass(), Conditional.class);
   if (cond == null) {
     return null;
   }
   return new HashSet<String>(Arrays.asList(cond.ifAttribute(), cond.unlessAttribute()));
 }
    /** {@inheritDoc} */
    @Override
    protected Map<String, Object> getDataMap(Context context) {

      final ApplicationContext factory = getApplicationContext(targetResource);

      Map<String, Object> map = new HashMap<String, Object>();

      Object value = context.getDefaultParameter();
      Map<String, String> idMap = new HashMap<String, String>();

      if (value instanceof Map) {
        for (Map.Entry<?, ?> entry : ((Map<?, ?>) value).entrySet()) {
          Object k = entry.getKey();
          Object v = entry.getValue();
          if (v == null) {
            v = k;
          }
          idMap.put(k.toString(), v.toString());
        }
      } else {
        for (String part : parseDelimitedString(value, null)) {
          final int pos = part.indexOf('=');
          if (pos < 0) {
            throw new PaxmlRuntimeException("No '=' sign found for id mapping from line: " + part);
          }
          idMap.put(part.substring(0, pos), part.substring(pos + 1));
        }
      }
      Set<String> exclude =
          new HashSet<String>(parseDelimitedString(context.getConst(EXCLUDE, false), DELEMITER));
      Set<String> include =
          new HashSet<String>(parseDelimitedString(context.getConst(INCLUDE, false), DELEMITER));

      Set<String> excludeType =
          new HashSet<String>(
              parseDelimitedString(context.getConst(EXCLUDE_TYPE, false), DELEMITER));
      Set<String> includeType =
          new HashSet<String>(
              parseDelimitedString(context.getConst(INCLUDE_TYPE, false), DELEMITER));

      if (include.size() <= 0 && includeType.size() <= 0) {
        include.addAll(Arrays.asList(factory.getBeanDefinitionNames()));
      }

      for (String className : includeType) {
        for (String id :
            factory.getBeanNamesForType(ReflectUtils.loadClassStrict(className, null))) {
          include.add(id);
        }
      }
      for (String className : excludeType) {
        for (String id :
            factory.getBeanNamesForType(ReflectUtils.loadClassStrict(className, null))) {
          exclude.add(id);
        }
      }

      include.removeAll(exclude);

      for (String name : include) {

        Object bean = factory.getBean(name);
        if (bean != null) {
          String id = idMap.get(name);
          if (id == null) {
            id = name;
          }
          map.put(id, bean);
        }
      }

      return map;
    }