001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.commons.scxml2.env; 018 019import org.apache.commons.scxml2.model.Transition; 020import org.apache.commons.scxml2.model.TransitionTarget; 021 022/** 023 * Helper methods for Commons SCXML logging. 024 * 025 */ 026public final class LogUtils { 027 028 /** 029 * Create a human readable log view of this transition. 030 * 031 * @param from The source TransitionTarget 032 * @param to The destination TransitionTarget 033 * @param transition The Transition that is taken 034 * @return String The human readable log entry 035 */ 036 public static String transToString(final TransitionTarget from, 037 final TransitionTarget to, final Transition transition, String event) { 038 StringBuffer buf = new StringBuffer("("); 039 buf.append("event = ").append(event); 040 buf.append(", cond = ").append(transition.getCond()); 041 buf.append(", from = ").append(getTTPath(from)); 042 buf.append(", to = ").append(getTTPath(to)); 043 buf.append(')'); 044 return buf.toString(); 045 } 046 047 /** 048 * Write out this TransitionTarget location in a XPath style format. 049 * 050 * @param tt The TransitionTarget whose "path" is to needed 051 * @return String The XPath style location of the TransitionTarget within 052 * the SCXML document 053 */ 054 public static String getTTPath(final TransitionTarget tt) { 055 StringBuilder sb = new StringBuilder("/"); 056 for (int i = 0; i < tt.getNumberOfAncestors(); i++) { 057 sb.append(tt.getAncestor(i).getId()); 058 sb.append("/"); 059 } 060 sb.append(tt.getId()); 061 return sb.toString(); 062 } 063 064 /** 065 * Discourage instantiation since this is a utility class. 066 */ 067 private LogUtils() { 068 super(); 069 } 070 071}