package org.yamcs.xtce;


/**
 * Parameters made on the fly.
 * 
 * DataSource should be one of SYSTEM, COMMAND or COMMAND_HISTORY (so the class name is a misnomer);
 * 
 * @author nm
 * 
 */
public class SystemParameter extends Parameter {
    private static final long serialVersionUID = 2L;
    
    private SystemParameter(String spaceSystemName, String name, DataSource ds) {
        super(name);
        setQualifiedName(spaceSystemName+"/"+name);
        addAlias(spaceSystemName, name);
        setDataSource(ds);
    }

    public static SystemParameter getForFullyQualifiedName(String fqname) {
        DataSource ds = getSystemParameterDataSource(fqname);
        SystemParameter sp = new SystemParameter(NameDescription.getSubsystemName(fqname), NameDescription.getName(fqname), ds);
        //set the recording name "/yamcs/a/b/c" -> "/yamcs/a"
        int pos = fqname.indexOf(PATH_SEPARATOR, 0);
        pos = fqname.indexOf(PATH_SEPARATOR, pos+1);
        pos = fqname.indexOf(PATH_SEPARATOR, pos+1);
        sp.setRecordingGroup(fqname.substring(0, pos));
        
        return sp;
    }
    
    private static DataSource getSystemParameterDataSource(String fqname) {
        if(fqname.startsWith(XtceDb.YAMCS_CMD_SPACESYSTEM_NAME)) return DataSource.COMMAND;
        else if(fqname.startsWith(XtceDb.YAMCS_CMDHIST_SPACESYSTEM_NAME)) return DataSource.COMMAND_HISTORY;
        else return DataSource.SYSTEM;
    }

    
    @Override
    public String toString() {
        return "SysParam(qname=" + getQualifiedName() + ")";
    }
}
@@ -18,17 +18,16 @@
 .xtce;%0A%0A
-%0A
 /**%0A * P
@@ -286,20 +286,16 @@
 D = 2L;%0A
-    
 %0A    pri
@@ -434,53 +434,16 @@
 Name
-+%22/%22+name);%0A        addAlias(spaceSystemName,
+ + %22/%22 +
  nam
@@ -708,16 +708,32 @@
 fqname),
+%0A               
  NameDes
@@ -773,16 +773,17 @@
       //
+ 
 set the 
@@ -919,33 +919,35 @@
 H_SEPARATOR, pos
-+
+ + 
 1);%0A        pos 
@@ -982,17 +982,19 @@
 TOR, pos
-+
+ + 
 1);%0A    
@@ -1045,24 +1045,16 @@
  pos));%0A
-        
 %0A       
@@ -1071,20 +1071,16 @@
 ;%0A    %7D%0A
-    
 %0A    pri
@@ -1158,16 +1158,17 @@
       if
+ 
 (fqname.
@@ -1205,32 +1205,46 @@
 ACESYSTEM_NAME))
+ %7B%0A           
  return DataSour
@@ -1266,16 +1266,18 @@
     
+ %7D
  else if
 (fqn
@@ -1272,16 +1272,17 @@
  else if
+ 
 (fqname.
@@ -1331,16 +1331,30 @@
 M_NAME))
+ %7B%0A           
  return 
@@ -1388,22 +1388,38 @@
 %0A       
+ %7D
  else 
+%7B%0A            
 return D
@@ -1440,20 +1440,25 @@
 EM;%0A
+        %7D%0A
     %7D%0A%0A
-    %0A
     
@@ -1566,8 +1566,9 @@
 %0A    %7D%0A%7D
+%0A

Remove unnecessary alias for system parameters