buildframework/helium/sf/java/antdata/src/com/nokia/helium/ant/data/AntObjectMeta.java
changeset 628 7c4a911dc066
parent 587 85df38eb4012
child 645 b8d81fa19e7d
equal deleted inserted replaced
588:c7c26511138f 628:7c4a911dc066
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 package com.nokia.helium.ant.data;
    18 package com.nokia.helium.ant.data;
    19 
    19 
    20 import java.io.IOException;
    20 import java.util.Collections;
    21 import java.util.HashMap;
    21 import java.util.HashMap;
    22 import java.util.List;
    22 import java.util.List;
    23 import java.util.Map;
    23 import java.util.Map;
    24 
    24 
    25 import org.apache.tools.ant.Project;
    25 import org.apache.tools.ant.Project;
    31  * Base class for all Ant Meta objects. Each Ant object is represented by a meta
    31  * Base class for all Ant Meta objects. Each Ant object is represented by a meta
    32  * object that provides core and additional data about it.
    32  * object that provides core and additional data about it.
    33  */
    33  */
    34 public class AntObjectMeta {
    34 public class AntObjectMeta {
    35 
    35 
    36     public static final Map<String, Integer> SCOPES = new HashMap<String, Integer>() {
    36     public static final Map<String, Integer> SCOPES;
    37         {
    37     
    38             put("public", new Integer(1));
    38     static {
    39             put("protected", new Integer(2));
    39         Map<String, Integer> tempMap = new HashMap<String, Integer>();
    40             put("private", new Integer(3));
    40         tempMap.put("public", new Integer(1));
    41         }
    41         tempMap.put("protected", new Integer(2));
    42     };
    42         tempMap.put("private", new Integer(3));
       
    43         SCOPES = Collections.unmodifiableMap(tempMap);
       
    44     }
       
    45     
    43     /** The default scope if an element does not have a defined scope. */
    46     /** The default scope if an element does not have a defined scope. */
    44     public static final String DEFAULT_SCOPE = "public";
    47     public static final String DEFAULT_SCOPE = "public";
    45 
    48 
    46     private static AntComment emptyComment;
    49     private static AntComment emptyComment;
    47 
    50 
    48     private Project rootProject;
    51     private Project runtimeProject;
    49 
    52 
    50     /** The parent meta object. */
    53     /** The parent meta object. */
    51     private AntObjectMeta parent;
    54     private AntObjectMeta parent;
    52     /** The dom4j XML Element of the Ant object represented by this meta object. */
    55     /** The dom4j XML Element of the Ant object represented by this meta object. */
    53     private Node node;
    56     private Node node;
    54     /** The AntComment of any preceeding comment block. */
    57     /** The AntComment of any preceeding comment block. */
    55     private AntComment comment = emptyComment;
    58     private AntComment comment = emptyComment;
    56 
    59 
    57     static {
    60     static {
    58         try {
    61         emptyComment = new AntComment();
    59             emptyComment = new AntComment();
       
    60         }
       
    61         catch (IOException e) {
       
    62             e.printStackTrace();
       
    63         }
       
    64     }
    62     }
    65 
    63 
    66     /**
    64     /**
    67      * Constructor.
    65      * Constructor.
    68      * 
    66      * 
    69      * @param parent The parent meta object.
    67      * @param parent The parent meta object.
    70      * @param node The XML node of the Ant object.
    68      * @param node The XML node of the Ant object.
    71      * @throws IOException
    69      */
    72      */
    70     public AntObjectMeta(AntObjectMeta parent, Node node) {
    73     public AntObjectMeta(AntObjectMeta parent, Node node) throws IOException {
       
    74         this.parent = parent;
    71         this.parent = parent;
    75         this.node = node;
    72         this.node = node;
    76         processComment();
    73         processComment();
    77     }
    74     }
    78 
    75 
    79     public Project getRuntimeProject() {
    76     public Project getRuntimeProject() {
    80         return rootProject;
    77         return runtimeProject;
    81     }
    78     }
    82 
    79 
    83     public void setRuntimeProject(Project project) {
    80     public void setRuntimeProject(Project project) {
    84         this.rootProject = project;
    81         this.runtimeProject = project;
    85     }
    82     }
    86 
    83 
    87     /**
    84     /**
    88      * Gets an attribute if a value is available, otherwise returns an emtpy
    85      * Gets an attribute if a value is available, otherwise returns an emtpy
    89      * string.
    86      * string.
   140      */
   137      */
   141     public String getName() {
   138     public String getName() {
   142         String name = getAttr("name");
   139         String name = getAttr("name");
   143         if (name.length() == 0) {
   140         if (name.length() == 0) {
   144             name = getComment().getObjectName();
   141             name = getComment().getObjectName();
   145 //            if (name.length() == 0) {
       
   146 //                try {
       
   147 //                    System.out.println("name is 0 length: " + getLocation());
       
   148 //                    // System.out.println(node.toString());
       
   149 //                }
       
   150 //                catch (IOException e) {
       
   151 //                    e.printStackTrace();
       
   152 //                }
       
   153 //            }
       
   154         }
   142         }
   155         return name;
   143         return name;
   156     }
   144     }
   157 
   145 
   158     /**
   146     /**
   159      * Returns the location path of the object.
   147      * Returns the location path of the object.
   160      * 
   148      * 
   161      * @return Location path string.
   149      * @return Location path string.
   162      * @throws IOException
   150      */
   163      */
   151     public String getLocation() {
   164     public String getLocation() throws IOException {
       
   165         RootAntObjectMeta rootMeta = getRootMeta();
   152         RootAntObjectMeta rootMeta = getRootMeta();
   166         return rootMeta.getFile().getCanonicalPath();
   153         String location = rootMeta.getFilePath();
       
   154         if (node instanceof ElementWithLocation) {
       
   155             location += ":" + ((ElementWithLocation)node).getLineNumber();
       
   156         }
       
   157         return location;
   167     }
   158     }
   168 
   159 
   169     /**
   160     /**
   170      * Returns the first line summary from a doc comment.
   161      * Returns the first line summary from a doc comment.
   171      * 
   162      * 
   201     public boolean matchesScope(String scopeFilter) {
   192     public boolean matchesScope(String scopeFilter) {
   202         if (!SCOPES.containsKey(scopeFilter)) {
   193         if (!SCOPES.containsKey(scopeFilter)) {
   203             throw new IllegalArgumentException("Invalid scope filter: " + scopeFilter);
   194             throw new IllegalArgumentException("Invalid scope filter: " + scopeFilter);
   204         }
   195         }
   205         String scope = getScope();
   196         String scope = getScope();
   206         if (!SCOPES.containsKey(scope)) {
   197         if (scope.length() > 0 && !SCOPES.containsKey(scope)) {
   207             log("Invalid scope: " + scope + ", " + toString(), Project.MSG_WARN);
   198             log("Invalid scope: " + scope + ", " + toString(), Project.MSG_WARN);
   208             return false;
   199             return false;
   209         }
   200         }
   210         return SCOPES.get(scope).compareTo(SCOPES.get(scopeFilter)) <= 0;
   201         return SCOPES.get(scope).compareTo(SCOPES.get(scopeFilter)) <= 0;
   211     }
   202     }
   216      * 
   207      * 
   217      * @return Deprecated descripion.
   208      * @return Deprecated descripion.
   218      */
   209      */
   219     public String getDeprecated() {
   210     public String getDeprecated() {
   220         return comment.getTagValue("deprecated");
   211         return comment.getTagValue("deprecated");
       
   212     }
       
   213     
       
   214     /**
       
   215      * Returns the content of the "since" tag that should indicate which release this feature
       
   216      * was first added.
       
   217      * 
       
   218      * @return Since release number.
       
   219      */
       
   220     public String getSince() {
       
   221         return comment.getTagValue("since");
   221     }
   222     }
   222 
   223 
   223     /**
   224     /**
   224      * Returns the source XML of the object.
   225      * Returns the source XML of the object.
   225      * 
   226      * 
   244 
   245 
   245     protected void setComment(AntComment comment) {
   246     protected void setComment(AntComment comment) {
   246         this.comment = comment;
   247         this.comment = comment;
   247     }
   248     }
   248 
   249 
   249     private void processComment() throws IOException {
   250     private void processComment()  {
   250         Comment commentNode = getCommentNode();
   251         Comment commentNode = getCommentNode();
   251         if (commentNode != null) {
   252         if (commentNode != null) {
   252             comment = new AntComment(commentNode);
   253             comment = new AntComment(commentNode);
   253         }
   254         }
   254     }
   255     }
   287         Project project = getRuntimeProject();
   288         Project project = getRuntimeProject();
   288         if (project != null) {
   289         if (project != null) {
   289             project.log(text, level);
   290             project.log(text, level);
   290         }
   291         }
   291     }
   292     }
       
   293     
       
   294     public String toString() {
       
   295         return getName();
       
   296     }
   292 }
   297 }