View Javadoc

1   /*
2    * Copyright 2007-2008 the original author or authors.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.gwe.integration.slicer.model;
18  
19  import org.gwe.utils.cmd.OptionTemplate;
20  
21  /**
22   * @author Marco Ruiz
23   * @since Dec 14, 2007
24   */
25  public class ParameterModel extends OptionTemplate {
26  	
27  	private String valueType; // returns the parameter's tag, e.g. <integer>, <image>, etc.
28  	private String name = "";
29  	private String longFlag = null;
30  	private String label = "";
31  	private int index = -1;
32  	private String channel = null;
33  	private String filler = "";
34  	
35  	public ParameterModel(String valueType, String label, String longFlag, String description, String defaultValue) {
36  		super(longFlag, description, defaultValue);
37  		this.valueType = valueType;
38  		this.label = label;
39  		setLongFlag(longFlag);
40  	}
41  
42  	public String getValueType() {
43  		return valueType;
44  	}
45  	
46  	public void setValueType(String tag) {
47  		this.valueType = tag;
48  	}
49  	
50  	public String getName() {
51  		return name;
52  	}
53  	
54  	public void setName(String name) {
55  		this.name = name;
56  		if (longFlag == null || longFlag.equals("")) 
57  			setLongFlag(name);
58  	}
59  	
60  	public String getLongFlag() {
61      	return longFlag;
62      }
63  
64  	public void setLongFlag(String longFlag) {
65  		while (longFlag != null && longFlag.startsWith("-")) longFlag = longFlag.substring(1);
66      	this.longFlag = longFlag;
67      }
68  
69  	public String getLabel() {
70  		return label;
71  	}
72  	
73  	public void setLabel(String label) {
74  		this.label = label;
75  	}
76  
77  	public int getIndex() {
78      	return index;
79      }
80  
81  	public void setIndex(int index) {
82      	this.index = index;
83      }
84  
85  	public String getFlag() {
86  		return "";
87  	}
88  	
89  	public void setFlag(String flag) {
90  //		setShortFlag();
91  	}
92  	
93  	public String getChannel() {
94      	return channel;
95      }
96  
97  	public void setChannel(String channel) {
98      	this.channel = channel;
99      }
100 
101 	public String getFiller() {
102 		return getFiller(true, true);
103     }
104 
105 	public String getFiller(boolean includeIndexIfPresent, boolean includeChannelIfPresent) {
106 		String result = (includeIndexIfPresent && index != -1) ? "<index>" + index + "</index>\n" : "";
107 		if (includeChannelIfPresent && channel != null) 
108 			result += "<channel>" + channel + "</channel>\n";
109 		
110     	return result + filler;
111     }
112 
113 	public void setFiller(String filler) {
114 		if (filler != null) this.filler = filler;
115     }
116 }
117 
118