Home » struts-2.1.8.1-src » org.apache » struts2 » sitegraph » model » [javadoc | source]

    1   /*
    2    * $Id: Link.java 651946 2008-04-27 13:41:38Z apetrelli $
    3    *
    4    * Licensed to the Apache Software Foundation (ASF) under one
    5    * or more contributor license agreements.  See the NOTICE file
    6    * distributed with this work for additional information
    7    * regarding copyright ownership.  The ASF licenses this file
    8    * to you under the Apache License, Version 2.0 (the
    9    * "License"); you may not use this file except in compliance
   10    * with the License.  You may obtain a copy of the License at
   11    *
   12    *  http://www.apache.org/licenses/LICENSE-2.0
   13    *
   14    * Unless required by applicable law or agreed to in writing,
   15    * software distributed under the License is distributed on an
   16    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   17    * KIND, either express or implied.  See the License for the
   18    * specific language governing permissions and limitations
   19    * under the License.
   20    */
   21   
   22   package org.apache.struts2.sitegraph.model;
   23   
   24   import java.io.IOException;
   25   
   26   /**
   27    */
   28   public class Link implements Render, Comparable {
   29       public static final int TYPE_FORM = 0;
   30       public static final int TYPE_ACTION = 1;
   31       public static final int TYPE_HREF = 2;
   32       public static final int TYPE_RESULT = 3;
   33       public static final int TYPE_REDIRECT = 4;
   34   
   35       private SiteGraphNode from;
   36       private SiteGraphNode to;
   37       private int type;
   38       private String label;
   39   
   40       public Link(SiteGraphNode from, SiteGraphNode to, int type, String label) {
   41           this.from = from;
   42           this.to = to;
   43           this.type = type;
   44           this.label = label;
   45       }
   46   
   47       public void render(IndentWriter writer) throws IOException {
   48           writer.write(from.getFullName() + " -> " + to.getFullName() + " [label=\"" + getRealLabel() + "\"" + getColor() + "];");
   49       }
   50   
   51       private String getRealLabel() {
   52           switch (type) {
   53               case TYPE_ACTION:
   54                   return "action" + label;
   55               case TYPE_FORM:
   56                   return "form" + label;
   57               case TYPE_HREF:
   58                   return "href" + label;
   59               case TYPE_REDIRECT:
   60                   return "redirect: " + label;
   61               case TYPE_RESULT:
   62                   return label;
   63           }
   64   
   65           return "";
   66       }
   67   
   68       private String getColor() {
   69           if (type == TYPE_RESULT || type == TYPE_ACTION) {
   70               return ",color=\"darkseagreen2\"";
   71           } else {
   72               return "";
   73           }
   74       }
   75   
   76       public int compareTo(Object o) {
   77           Link other = (Link) o;
   78           int result = from.compareTo(other.from);
   79           if (result != 0) {
   80               return result;
   81           }
   82   
   83           result = to.compareTo(other.to);
   84           if (result != 0) {
   85               return result;
   86           }
   87   
   88           result = label.compareTo(other.label);
   89           if (result != 0) {
   90               return result;
   91           }
   92   
   93           return new Integer(type).compareTo(new Integer(other.type));
   94       }
   95   }

Home » struts-2.1.8.1-src » org.apache » struts2 » sitegraph » model » [javadoc | source]