View Javadoc
1   /**
2    * BSD-style license; for more info see http://pmd.sourceforge.net/license.html
3    */
4   package net.sourceforge.pmd.util.database;
5   
6   import java.util.logging.Logger;
7   
8   /**
9    * Instantiate the fields required to retrieve {@link SourceCode}.
10   *
11   * @author sturton
12   */
13  public class SourceObject {
14  
15    private static final String CLASS_NAME = SourceObject.class.getName();
16    private static final Logger LOG = Logger.getLogger(CLASS_NAME);
17  
18    /**
19     * Database Schema/Owner - SYS,SYSTEM,SCOTT 
20     * 
21     */
22  
23    String schema;
24  
25    /**
26     * Source Code Name - DBMS_METADATA 
27     * 
28     */
29  
30    String name;
31  
32    /**
33     * Source Code Type - FUNCTION,PROCEDURE,TRIGGER,PACKAGE,PACKAGE_BODY,TYPE,TYPE_BODY,JAVA_SOURCE.
34     * 
35     */
36  
37    String type;
38  
39    /**
40     * Source Code Revision - Optional revision/version 
41     * 
42     */
43  
44    String revision;
45  
46    SourceObject(String schema, String type, String name, String revision) {
47    this.schema = schema; 
48    this.type = type; 
49    this.name = name; 
50    this.revision = revision; 
51    }
52  
53    @Override
54    public String toString()
55    {
56       return String.format("schema=\"%s\",type=\"%s\",name=\"%s\",revision=\"%s\""
57                              , this.getSchema(), this.getType(), this.getName(), this.getRevision());
58    }
59  
60    /**
61     * @return the schema
62     */
63    public String getSchema() {
64      return schema;
65    }
66  
67    /**
68     * @param schema the schema to set
69     */
70    public void setSchema(String schema) {
71      this.schema = schema;
72    }
73  
74    /**
75     * @return the name
76     */
77    public String getName() {
78      return name;
79    }
80  
81    /**
82     * @param name the name to set
83     */
84    public void setName(String name) {
85      this.name = name;
86    }
87  
88    /**
89     * @return the type
90     */
91    public String getType() {
92      return type;
93    }
94  
95    /**
96     * @param type the type to set
97     */
98    public void setType(String type) {
99      this.type = type;
100   }
101 
102   /**
103    * @return the revision
104    */
105   public String getRevision() {
106     return revision;
107   }
108 
109   /**
110    * @param revision the revision to set
111    */
112   public void setRevision(String revision) {
113     this.revision = revision;
114   }
115 
116   /**
117    * Map the type to a file suffix associated with a {@link Language}
118    * 
119    * @return inferred suffix
120    */
121   public String getSuffixFromType()
122   {
123     LOG.entering(CLASS_NAME, "getSuffixFromType", this);//.entering("type="+type.toUpperCase());
124     if (null == type || type.isEmpty()) {
125       return "";
126     } else if (type.toUpperCase().indexOf("JAVA") >= 0) {
127       return ".java";
128     } else if (type.toUpperCase().indexOf("TRIGGER") >= 0) {
129       return ".trg";
130     } else if (type.toUpperCase().indexOf("FUNCTION") >= 0) {
131       return ".fnc";
132     } else if (type.toUpperCase().indexOf("PROCEDURE") >= 0) {
133       return ".prc";
134     } else if (type.toUpperCase().indexOf("PACKAGE_BODY") >= 0) {
135       return ".pkb";
136     } else if (type.toUpperCase().indexOf("PACKAGE") >= 0) {
137       return ".pks";
138     } else if (type.toUpperCase().indexOf("TYPE_BODY") >= 0) {
139       return ".tpb";
140     } else if (type.toUpperCase().indexOf("TYPE") >= 0) {
141       return ".tps";
142     } else { 
143       return "";
144     }
145   }
146 
147     /**
148      * Gets the data source as a pseudo file name (faux-file).
149      * Adding a suffix matching the source object type ensures that the appropriate
150      * language parser is used.
151      */
152     public String getPseudoFileName() {
153         String falseFilePath = String.format("/Database/%s/%s/%s%s", getSchema(), getType(), getName(),
154                 getSuffixFromType());
155         return falseFilePath;
156     }
157 }