示例#1
0
  /**
   * KFSCNTRB-1682: Some of the fields contain confidential information
   *
   * @see org.kuali.rice.krad.bo.BusinessObjectBase#toString()
   */
  @Override
  public String toString() {
    class PayeeACHAccountToStringBuilder extends ReflectionToStringBuilder {
      private PayeeACHAccountToStringBuilder(Object object) {
        super(object);
      }

      @Override
      public boolean accept(Field field) {
        if (BusinessObject.class.isAssignableFrom(field.getType())) {
          return false;
        }

        DataDictionaryService dataDictionaryService =
            SpringContext.getBean(DataDictionaryService.class);
        AttributeSecurity attributeSecurity =
            dataDictionaryService.getAttributeSecurity(
                PayeeACHAccount.class.getName(), field.getName());
        if ((ObjectUtils.isNotNull(attributeSecurity)
            && (attributeSecurity.isHide()
                || attributeSecurity.isMask()
                || attributeSecurity.isPartialMask()))) {
          return false;
        }

        return super.accept(field);
      }
    };
    ReflectionToStringBuilder toStringBuilder = new PayeeACHAccountToStringBuilder(this);
    return toStringBuilder.toString();
  }
示例#2
0
 public static void showAllPorperty(List<?> items) {
   System.out.println(
       "============================集合size为:" + items.size() + "============================");
   for (Object object : items) {
     System.out.println(ReflectionToStringBuilder.toString(object));
   }
 }
示例#3
0
 /**
  * 验证当前登录的Subject
  *
  * @see 经测试:本例中该方法的调用时机为LoginController.login()方法中执行Subject.login()时
  */
 @Override
 protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authcToken)
     throws AuthenticationException {
   // 获取基于用户名和密码的令牌
   // 实际上这个authcToken是从LoginController里面currentUser.login(token)传过来的
   // 两个token的引用都是一样的
   UsernamePasswordToken token = (UsernamePasswordToken) authcToken;
   System.out.println(
       "验证当前Subject时获取到token为"
           + ReflectionToStringBuilder.toString(token, ToStringStyle.MULTI_LINE_STYLE));
   User user = userService.getByUsername(token.getUsername());
   if (user == null) {
     throw new UnknownAccountException(); // 没找到帐号
   }
   if (UserUtil.STATUS_LOCK == user.getStatus()) {
     throw new LockedAccountException(); // 帐号锁定
   }
   // 交给AuthenticatingRealm使用CredentialsMatcher进行密码匹配
   AuthenticationInfo authenticationInfo =
       new SimpleAuthenticationInfo(
           user.getAccount(), // 用户名
           user.getPassword(), // 密码
           ByteSource.Util.bytes(user.getCredentialsSalt()), // salt=username+salt
           getName() // realm name
           );
   // AuthenticationInfo authenticationInfo = new SimpleAuthenticationInfo(user.getAccount(),
   // user.getPassword().toCharArray(), getName());
   this.setSession(WebConstant.SESSION_CURRRENT_USER, user);
   return authenticationInfo;
 }
  @Test
  public void shouldFormatMessageCorrectly() {
    Object expectedObject = new Object();
    Object actualObject = new Object();

    String expectedMessage =
        "Expected <"
            + ReflectionToStringBuilder.toString(expectedObject)
            + "> to be the same as actual <"
            + ReflectionToStringBuilder.toString(actualObject)
            + ">.";

    ExpectedSameButWereNotException exception =
        new ExpectedSameButWereNotException(expectedObject, actualObject);

    // TODO: Refactor this with FluentAssertion once equality is done.
    assertEquals(expectedMessage, exception.getMessage());
  }
  /**
   * Kind of a standard method here.
   *
   * @return lots of information about this object in a String object.
   */
  public String toString() {
    StringBuilder retval = new StringBuilder();

    retval.append("Local Name = ");
    retval.append(getLocalName());
    retval.append("\n");

    retval.append("Server Name = ");
    retval.append(getServerName());
    retval.append("\n");

    if (isRequestedSessionIdFromCookie()) {
      retval.append("Requested Session Id came from Cookie\n");
    } else if (isRequestedSessionIdFromUrl()) {
      retval.append("Requested Session Id came from Url\n");
    }

    retval.append("Requested Session Valid = ");
    retval.append(isRequestedSessionIdValid());
    retval.append("\n");

    retval.append("Session = ");
    if (getSession(false) != null) {
      retval.append(ReflectionToStringBuilder.toString(getSession()));
    } else {
      retval.append("null");
    }
    retval.append("\n");

    retval.append("Protocol = ");
    retval.append(getProtocol());
    retval.append("\n");

    retval.append("Request Locale = ");
    retval.append(getLocale());
    retval.append("\n");

    retval.append("Request Character Encoding = ");
    retval.append(getCharacterEncoding());
    retval.append("\n");

    retval.append("Attribute Names = ");
    Enumeration<String> e = this.getAttributeNames();
    while (e.hasMoreElements()) {
      retval.append(e.nextElement());
      retval.append(", ");
    }
    retval.append("\n");

    return retval.toString();
  }
 /**
  * {@inheritDoc}
  *
  * @see java.lang.Object#toString()
  */
 @Override
 public String toString() {
   ReflectionToStringBuilder rsb =
       new ReflectionToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE);
   rsb.setAppendStatics(false);
   rsb.setAppendTransients(true);
   rsb.setUpToClass(this.getClass());
   rsb.setExcludeFieldNames(new String[] {"order"});
   return rsb.toString();
 }
示例#7
0
  @Test
  public void testObjectToXML() throws JAXBException {
    Person person = new Person();
    person.personId = "gtu001";
    person.personName = "Troy";

    JAXBContext context = JAXBContext.newInstance(Person.class);
    Marshaller mars = context.createMarshaller();
    mars.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    StringWriter swriter = new StringWriter();
    mars.marshal(person, swriter);
    System.out.println(swriter.getBuffer());
    System.out.println("----------------------------------------------------------");

    StringReader sreader = new StringReader(swriter.getBuffer().toString());
    Unmarshaller unmars = context.createUnmarshaller();
    Person person2 = (Person) unmars.unmarshal(sreader);
    System.out.println(ReflectionToStringBuilder.toString(person2));
  }
  @Test
  public void compareFeatureCollectionsOneDifferentId()
      throws IOException, TransformerException, XMLStreamException, FactoryConfigurationError,
          JaxenException {
    final String FEATURECOLLECTION_A = "/nl/ipo/cds/webservices/featureCollectionFlat.xml";
    final String FEATURECOLLECTION_B =
        "/nl/ipo/cds/webservices/featureCollectionInspireProtectedSiteOneDifferentId.xml";

    FeatureCollectionComparator comparator = new FeatureCollectionComparator();

    Resource featureCollectionA = new ClassPathResource(FEATURECOLLECTION_A);
    Resource featureCollectionB = new ClassPathResource(FEATURECOLLECTION_B);

    FeatureCollectionComparisonResult result =
        comparator.compareFeatureCollections(featureCollectionA, featureCollectionB);

    logger.debug(
        ReflectionToStringBuilder.toString(
            result.getMessages().toArray(), ToStringStyle.MULTI_LINE_STYLE));
    Assert.assertFalse("One inspireID should be different", result.isSuccess());
  }
示例#9
0
 public String toString() {
   return ReflectionToStringBuilder.reflectionToString(this);
 }
示例#10
0
 public String toString() {
   return ReflectionToStringBuilder.toString(this, ToStringStyle.MULTI_LINE_STYLE);
 }
  protected static <T> void parseEDISegmentFields(
      EDIMessage ediMessage, Object segment, String segmentLine)
      throws IllegalAccessException, InvocationTargetException, ClassNotFoundException,
          ConversionException, InstantiationException {
    if (LOG.isDebugEnabled()) {
      LOG.debug("Before Field Values: " + ReflectionToStringBuilder.toString(segment));
      LOG.debug("Segment Values: " + segmentLine);
    }

    // now, tokenize the line, and set the fields.
    StrTokenizer tokenizer = new StrTokenizer(segmentLine, ediMessage.elementDelimiter());

    tokenizer.setEmptyTokenAsNull(true);
    tokenizer.setIgnoreEmptyTokens(false);

    // move past the initial tag.
    tokenizer.next();

    Iterator<Field> fieldIterator =
        Arrays.asList(segment.getClass().getDeclaredFields()).iterator();
    while (tokenizer.hasNext() && fieldIterator.hasNext()) {
      Field field = fieldIterator.next();
      String val = tokenizer.nextToken();

      // check field to see if it is a component of regular field type.
      if (field.isAnnotationPresent(EDIComponent.class)) {
        EDIComponent ediComponent = field.getAnnotation(EDIComponent.class);
        Collection obj = CollectionFactory.newInstance(field.getType());
        Class objType = getCollectionType(field);

        char componentDelimiter =
            ediComponent.delimiter() == Character.UNASSIGNED
                ? ediMessage.componentDelimiter()
                : ediComponent.delimiter();

        // parse each element to the collection.
        StrTokenizer componentTokenizer = new StrTokenizer(val, componentDelimiter);
        componentTokenizer.setEmptyTokenAsNull(true);
        componentTokenizer.setIgnoreEmptyTokens(false);

        while (componentTokenizer.hasNext()) {
          String component = componentTokenizer.nextToken();
          Object fieldObj =
              objType.cast(FieldAwareConverter.convertFromString(objType, field, component));
          obj.add(fieldObj);
        }
        BeanUtils.setProperty(segment, field.getName(), obj);
      } else {
        if (val == null) {
          LOG.debug("  " + field.getName() + " -> null");
          continue;
        }

        // try and populate the field.

        try {
          Object fieldObj = FieldAwareConverter.convertFromString(field.getType(), field, val);
          LOG.debug("  " + field.getName() + " -> " + val);

          BeanUtils.setProperty(segment, field.getName(), fieldObj);
        } catch (Exception e) {
          throw new ConversionException(
              "Exception setting: "
                  + segment.getClass()
                  + "."
                  + field.getName()
                  + " with value: "
                  + val,
              e);
        }
      }
    }

    if (LOG.isDebugEnabled()) {
      LOG.debug("After Field Values: " + ReflectionToStringBuilder.toString(segment));
    }
  }
示例#12
0
  @Override
  public void process(WatchedEvent event) {
    // log if DEBUG
    if (logger.isDebugEnabled()) {
      logger.debug(
          "***** Received ZooKeeper Event:  {}",
          ReflectionToStringBuilder.toString(event, ToStringStyle.DEFAULT_STYLE));
    }

    // process events
    switch (event.getType()) {
      case NodeCreated:
      case NodeChildrenChanged:
      case NodeDataChanged:
      case NodeDeleted:
        synchronized (this) {
          this.notifyAll();

          if (logger.isDebugEnabled()) {
            logger.debug(
                "Notifying threads waiting on LockWatcher:  lockWatcher.hashcode()="
                    + this.hashCode()
                    + "; instancesOutstanding="
                    + instancesOutstanding.get()
                    + "; lockName="
                    + lockPath
                    + "; lockReservation="
                    + lockReservationPath);
          }
        }
        break;

      case None:
        Event.KeeperState eventState = event.getState();
        if (eventState == Event.KeeperState.SyncConnected) {
          // connection event: check children
          synchronized (this) {
            this.notifyAll();
          }

        } else if (eventState == Event.KeeperState.Disconnected
            || eventState == Event.KeeperState.Expired) {
          // disconnected: notifyAll so we can check children again on
          // reconnection
          synchronized (this) {
            this.notifyAll();
          }

        } else {
          logger.warn(
              "Unhandled event state:  "
                  + ReflectionToStringBuilder.toString(event, ToStringStyle.DEFAULT_STYLE));
        }
        break;

      default:
        logger.warn(
            "Unhandled event type:  "
                + ReflectionToStringBuilder.toString(event, ToStringStyle.DEFAULT_STYLE));
    }

    // }// if

  } // process()
示例#13
0
 public String toString() {
   return (this == null
       ? ""
       : ReflectionToStringBuilder.toString(this, ToStringStyle.DEFAULT_STYLE));
 }
示例#14
0
 public static void showAllPorperty(Object object) {
   System.out.println(ReflectionToStringBuilder.toString(object));
 }
示例#15
0
 @Override
 public String toString() {
   return ReflectionToStringBuilder.toString(this, ToStringStyle.SHORT_PREFIX_STYLE);
 }
示例#16
0
 @Override
 public String toString() {
   return ReflectionToStringBuilder.toString(this);
 }
  protected static <T> void processSegmentGroup(
      EDIMessage ediMessage,
      T object,
      Queue<String> lookAhead,
      SegmentIterator segmentIterator,
      FieldMatch fm)
      throws InstantiationException, IllegalAccessException, InvocationTargetException,
          ClassNotFoundException, ConversionException, EDIMessageException {

    LOG.debug("Object: " + ReflectionToStringBuilder.toString(object));
    LOG.debug("Field: " + fm.getField().getName());

    Class<?> segmentGroupClass = getEDISegmentOrGroupType(fm.getField());
    if (!segmentGroupClass.isAnnotationPresent(EDISegmentGroup.class)) {
      throw new EDIMessageException("Segment Group should have annotation.");
    }

    LOG.debug("Segment Group Type: " + segmentGroupClass);

    String line = fm.getLine();
    EDISegmentGroup es = segmentGroupClass.getAnnotation(EDISegmentGroup.class);

    if (StringUtils.equals(es.header(), line)) {
      // feed line.
    } else {
      LOG.debug("Adding to Look Ahead: " + line);
      lookAhead.add(line);
    }

    if (Collection.class.isAssignableFrom(fm.getField().getType())) {
      Collection obj = CollectionFactory.newInstance(fm.getField().getType());
      BeanUtils.setProperty(object, fm.getField().getName(), obj);

      String segmentTag = getSegmentTag(fm.getField(), true);

      while (true) {
        LOG.debug("Looping to collect Collection of Segment Groups");
        // parse the group...
        Field[] fields = segmentGroupClass.getDeclaredFields();
        final List<Field> fieldsList = Arrays.asList(fields);
        ListIterator<Field> fieldIterator = fieldsList.listIterator(0);

        Object collectionObj = segmentGroupClass.newInstance();
        while (fieldIterator.hasNext() && (segmentIterator.hasNext() || lookAhead.size() > 0)) {
          if (startOfNewRecursiveObject(fieldIterator, fieldsList, segmentGroupClass)) {
            String next = lookAhead.size() > 0 ? lookAhead.remove() : segmentIterator.next();
            lookAhead.add(next);
            if (!isSegmentHeirarchicalLevelAndDeeperLevel(
                line, next, Character.toString(ediMessage.elementDelimiter()))) {
              LOG.debug("Reaching new instance of list.");
              break;
            }
          }
          parseEDISegmentOrSegmentGroup(
              ediMessage, collectionObj, fieldIterator, lookAhead, segmentIterator);
        }

        obj.add(collectionObj);

        // look to next line...
        String nextLine = lookAhead.size() > 0 ? lookAhead.remove() : segmentIterator.next();
        // get the first element of the line.
        StrTokenizer nextLineTokenizer = new StrTokenizer(nextLine, ediMessage.elementDelimiter());

        if (StringUtils.equals(segmentTag, nextLineTokenizer.nextToken())) {
          if (!isSegmentEqual(line, nextLine, Character.toString(ediMessage.elementDelimiter()))) {
            LOG.debug("Reaching new collection");
            lookAhead.add(nextLine);
            break;
          }
          LOG.debug("Might be a repeat..");
          LOG.debug("Next line: " + line);
          lookAhead.add(nextLine);
        } else {
          lookAhead.add(nextLine);
          break;
        }

        // now, look ahead to see whether the next line is of the same
        // object type..
        if (!segmentIterator.hasNext() && lookAhead.size() == 0) {
          break;
        }
      }

    } else {
      Field[] fields = segmentGroupClass.getDeclaredFields();
      Iterator<Field> fieldIterator = Arrays.asList(fields).iterator();

      Object obj = segmentGroupClass.newInstance();
      while (fieldIterator.hasNext() && (segmentIterator.hasNext() || lookAhead.size() > 0)) {
        parseEDISegmentOrSegmentGroup(ediMessage, obj, fieldIterator, lookAhead, segmentIterator);
      }

      BeanUtils.setProperty(object, fm.getField().getName(), obj);
    }

    // look at next...
    if (StringUtils.isNotBlank(es.header())) {
      line = lookAhead.size() > 0 ? lookAhead.remove() : segmentIterator.next();

      if (StringUtils.endsWith(es.footer(), line)) {
        // feed line.
        LOG.debug("Popping footer off of the line iterator.");
      } else {
        lookAhead.add(line);
      }
    }
  }