예제 #1
0
  /**
   * Computes the difference between two attributes using the given distance metric. This function
   * takes care of things like dynamic attributes and null values. This one allows reclamation of a
   * difference object.
   *
   * @param alpha the target attribute
   * @param alphaSpan the target attribute's span
   * @param beta the candidate attribute
   * @param betaSpan the candidate attribute's framespan
   * @param blackout the blackout data
   * @param blackoutSpan when the blackout is defined
   * @param ignore the don't-care data
   * @param ignoreSpan the don't-care framespan
   * @param frame the frame to compare
   * @param cfd information about the media
   * @param old cached difference object
   * @return the new difference object, or the same one, changed
   * @throws IgnoredValueException if the whole of the data on the frame was ignored
   */
  public static Measurable.Difference helpGetDiff(
      Attribute alpha,
      FrameSpan alphaSpan,
      Attribute beta,
      FrameSpan betaSpan,
      Attribute blackout,
      FrameSpan blackoutSpan,
      Attribute ignore,
      FrameSpan ignoreSpan,
      int frame,
      CanonicalFileDescriptor cfd,
      Measurable.Difference old)
      throws IgnoredValueException {
    if (alpha == null || alpha.getValue(alphaSpan, frame) == null) {
      return new Distances.DefaultDifference(
          null,
          (beta != null) ? beta.getValue(betaSpan, frame) : null,
          (blackout != null) ? blackout.getValue(blackoutSpan, frame) : null,
          (ignore != null) ? ignore.getValue(ignoreSpan, frame) : null,
          cfd);

    } else {
      Measurable a = alpha.getValue(alphaSpan, frame);
      return a.getDifference(
          (beta != null) ? beta.getValue(betaSpan, frame) : null,
          (blackout != null) ? blackout.getValue(blackoutSpan, frame) : null,
          (ignore != null) ? ignore.getValue(ignoreSpan, frame) : null,
          cfd,
          old);
    }
  }
예제 #2
0
파일: MetaK.java 프로젝트: TomGebhardt/k
 public static boolean isAnywhere(Rule r) {
   if (null == r.getAttributes()) return false;
   for (Attribute any : anywheres) {
     if (any.getValue() == r.getAttribute(any.getKey())) return true;
   }
   return false;
 }
예제 #3
0
  /**
   * This will invoke the <code>startElement</code> callback in the <code>ContentHandler</code>.
   *
   * @param element <code>Element</code> used in callbacks.
   * @param nsAtts <code>List</code> of namespaces to declare with the element or <code>null</code>.
   */
  private void startElement(Element element, Attributes nsAtts) throws JDOMException {
    String namespaceURI = element.getNamespaceURI();
    String localName = element.getName();
    String rawName = element.getQualifiedName();

    // Allocate attribute list.
    AttributesImpl atts = (nsAtts != null) ? new AttributesImpl(nsAtts) : new AttributesImpl();

    List attributes = element.getAttributes();
    Iterator i = attributes.iterator();
    while (i.hasNext()) {
      Attribute a = (Attribute) i.next();
      atts.addAttribute(
          a.getNamespaceURI(),
          a.getName(),
          a.getQualifiedName(),
          getAttributeTypeName(a.getAttributeType()),
          a.getValue());
    }

    try {
      contentHandler.startElement(namespaceURI, localName, rawName, atts);
    } catch (SAXException se) {
      throw new JDOMException("Exception in startElement", se);
    }
  }
예제 #4
0
 /** Convert the attributes in the given XML Element into a Map of name/value pairs. */
 protected static Map createAttributeMap(Element el) {
   Log.debug("Creating attribute map for " + el);
   Map attributes = new HashMap();
   Iterator iter = el.getAttributes().iterator();
   while (iter.hasNext()) {
     Attribute att = (Attribute) iter.next();
     attributes.put(att.getName(), att.getValue());
   }
   return attributes;
 }
  /* ------------------------------------------------------------ */
  public void setAttribute(Attribute attr)
      throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException,
          ReflectionException {
    if (attr == null) return;

    if (log.isDebugEnabled()) log.debug("setAttribute " + attr.getName() + "=" + attr.getValue());
    Method setter = (Method) _setter.get(attr.getName());
    if (setter == null) throw new AttributeNotFoundException(attr.getName());
    try {
      Object o = _object;
      if (setter.getDeclaringClass().isInstance(this)) o = this;
      setter.invoke(o, new Object[] {attr.getValue()});
    } catch (IllegalAccessException e) {
      log.warn(LogSupport.EXCEPTION, e);
      throw new AttributeNotFoundException(e.toString());
    } catch (InvocationTargetException e) {
      log.warn(LogSupport.EXCEPTION, e);
      throw new ReflectionException((Exception) e.getTargetException());
    }
  }
예제 #6
0
 /** @inheritDoc */
 public Number getDistance(
     Attribute alpha,
     FrameSpan alphaSpan,
     Attribute beta,
     FrameSpan betaSpan,
     int frame,
     CanonicalFileDescriptor cfd) {
   Object a = alpha.getValue(alphaSpan, frame);
   Object b = beta.getValue(betaSpan, frame);
   if (a == null || b == null) {
     return a == b ? new Integer(0) : new Integer(1);
   } else if ((a instanceof Object[]) && (b instanceof Object[])) {
     return Arrays.equals((Object[]) a, (Object[]) b) ? new Integer(0) : new Integer(1);
   } else if ((a instanceof int[]) && (b instanceof int[])) {
     return Arrays.equals((int[]) a, (int[]) b) ? new Integer(0) : new Integer(1);
   } else if ((a instanceof double[]) && (b instanceof double[])) {
     return Arrays.equals((double[]) a, (double[]) b) ? new Integer(0) : new Integer(1);
   } else if ((a instanceof boolean[]) && (b instanceof boolean[])) {
     return Arrays.equals((boolean[]) a, (boolean[]) b) ? new Integer(0) : new Integer(1);
   } else {
     return a.equals(b) ? new Integer(0) : new Integer(1);
   }
 }
예제 #7
0
 /** @inheritDoc */
 public Number getDistance(
     Attribute alpha,
     FrameSpan alphaSpan,
     Attribute beta,
     FrameSpan betaSpan,
     Attribute blackout,
     FrameSpan blackoutSpan,
     Attribute ignore,
     FrameSpan ignoreSpan,
     int frame,
     CanonicalFileDescriptor cfd) {
   if (blackout != null && blackout.getValue(blackoutSpan, frame) != null) {
     return new Integer(1);
   } else {
     return getDistance(alpha, alphaSpan, beta, betaSpan, frame, cfd);
   }
 }
예제 #8
0
 private synchronized NameValueMap getCachedAttributes(ObjectName objName, Set<String> attrNames)
     throws InstanceNotFoundException, ReflectionException, IOException {
   NameValueMap values = cachedValues.get(objName);
   if (values != null && values.keySet().containsAll(attrNames)) {
     return values;
   }
   attrNames = new TreeSet<String>(attrNames);
   Set<String> oldNames = cachedNames.get(objName);
   if (oldNames != null) {
     attrNames.addAll(oldNames);
   }
   values = new NameValueMap();
   final AttributeList attrs =
       conn.getAttributes(objName, attrNames.toArray(new String[attrNames.size()]));
   for (Attribute attr : attrs.asList()) {
     values.put(attr.getName(), attr.getValue());
   }
   cachedValues.put(objName, values);
   cachedNames.put(objName, attrNames);
   return values;
 }
예제 #9
0
  /**
   * Convert RichUsers to Identity objects with obfuscated email address and limited set of ext
   * sources. Service users are removed from the list.
   *
   * @param list RichUsers to convert
   * @return list of Identities without service ones
   * @throws PerunException
   */
  private List<Identity> convertToIdentities(List<RichUser> list) throws PerunException {

    List<Identity> result = new ArrayList<Identity>();

    if (list != null && !list.isEmpty()) {

      for (RichUser u : list) {

        // skip service users
        if (u.isServiceUser()) continue;

        Identity identity = new Identity();
        identity.setName(u.getDisplayName());
        identity.setId(u.getId());

        for (Attribute a : u.getUserAttributes()) {

          if (MailManagerImpl.URN_USER_PREFERRED_MAIL.equals(a.getName())) {
            if (a.getValue() != null && !((String) a.getValue()).isEmpty()) {

              String safeMail = ((String) a.getValue()).split("@")[0];

              if (safeMail.length() > 2) {
                safeMail =
                    safeMail.substring(0, 1)
                        + "****"
                        + safeMail.substring(safeMail.length() - 1, safeMail.length());
              }

              safeMail += "@" + ((String) a.getValue()).split("@")[1];

              identity.setEmail(safeMail);
            }
          } else if ("urn:perun:user:attribute-def:def:organization".equals(a.getName())) {
            if (a.getValue() != null) {
              identity.setOrganization((String) a.getValue());
            }
          }
        }

        List<ExtSource> es = new ArrayList<ExtSource>();
        for (UserExtSource ues : u.getUserExtSources()) {
          if (ues.getExtSource().getType().equals(ExtSourcesManagerEntry.EXTSOURCE_X509)) {
            es.add(ues.getExtSource());
          } else if (ues.getExtSource().getType().equals(ExtSourcesManagerEntry.EXTSOURCE_IDP)) {
            if (ues.getExtSource().getName().equals("https://extidp.cesnet.cz/idp/shibboleth")) {
              // FIXME - hack Social IdP to let us know proper identity source
              String type = ues.getLogin().split("@")[1].split("\\.")[0];
              ues.getExtSource()
                  .setName(
                      "https://extidp.cesnet.cz/idp/shibboleth&authnContextClassRef=urn:cesnet:extidp:authn:"
                          + type);
            } else if (ues.getExtSource().getName().equals("https://login.elixir-czech.org/idp/")) {
              // FIXME - hack Elixir proxy IdP to let us know proper identity source
              String type = ues.getLogin().split("@")[1];
              ues.getExtSource().setName("https://login.elixir-czech.org/idp/@" + type);
            }
            es.add(ues.getExtSource());
          } else if (ues.getExtSource()
              .getType()
              .equals(ExtSourcesManagerEntry.EXTSOURCE_KERBEROS)) {
            es.add(ues.getExtSource());
          }
        }
        identity.setIdentities(es);

        result.add(identity);
      }
    }

    return result;
  }