1 22 23 package org.xquark.mapper.mapping; 24 25 import java.math.BigDecimal ; 26 27 import org.xquark.mapping.StorageContext; 28 import org.xquark.mapping.UserGenerator; 29 import org.xquark.mapper.metadata.RepositoryConstants; 30 31 public abstract class SystemVariableGenerator implements UserGenerator, MappingConstants 32 { 33 private static final String RCSRevision = "$Revision: 1.2 $"; 34 private static final String RCSName = "$Name: $"; 35 36 public abstract Object getValue(StorageContext context); 37 public abstract String getXMLType(); 38 public abstract short getType(); 39 40 static SystemVariableGenerator createGenerator(String sysvar) 41 { 42 if (DOCID_VALUE.equals(sysvar)) 43 return new SystemVariableGenerator() 44 { 45 public Object getValue(StorageContext context) 46 { 47 return context.getDocumentID(); 48 } 49 public String getXMLType() 50 { 51 return "<simpleType><restriction base=\"string\"><maxLength value=\"" 52 + String.valueOf(RepositoryConstants.ID_LENGTH) 53 + "\"/></restriction></simpleType>"; 54 } 55 public short getType() 56 { 57 return DOCID_CODE; 58 } 59 }; 60 else if (DOCOID_VALUE.equals(sysvar)) 61 return new SystemVariableGenerator() 62 { 63 public Object getValue(StorageContext context) 64 { 65 return new Long (context.getDocumentOID()); 66 } 67 public String getXMLType() 68 { 69 return "int"; 70 } 71 public short getType() 72 { 73 return DOCOID_CODE; 74 } 75 }; 76 else if (UOID_VALUE.equals(sysvar)) 93 return new SystemVariableGenerator() 94 { 95 public Object getValue(StorageContext context) 96 { 97 return new Long (context.getUOID()); 98 } 99 public String getXMLType() 100 { 101 return "long"; 102 } 103 public short getType() 104 { 105 return UOID_CODE; 106 } 107 }; 108 else if (PATHID_VALUE.equals(sysvar)) 109 return new SystemVariableGenerator() 110 { 111 public Object getValue(StorageContext context) 112 { 113 return new Integer (context.getPathOID()); 114 } 115 public String getXMLType() 116 { 117 return "short"; 118 } 119 public short getType() 120 { 121 return PATHID_CODE; 122 } 123 }; 124 else if (TAG_VALUE.equals(sysvar)) 125 return new SystemVariableGenerator() 126 { 127 public Object getValue(StorageContext context) 128 { 129 return context.getQName(); 130 } 131 public String getXMLType() 132 { 133 return "<simpleType><restriction base=\"string\"><maxLength value=\"255\"/></restriction></simpleType>"; 134 } 135 public short getType() 136 { 137 return TAG_CODE; 138 } 139 }; 140 else if (RANK_VALUE.equals(sysvar)) 141 return new SystemVariableGenerator() 142 { 143 public Object getValue(StorageContext context) 144 { 145 return BigDecimal.valueOf(context.getNodeRank()); 146 } 147 public String getXMLType() 148 { 149 return "int"; 150 } 151 public short getType() 152 { 153 return RANK_CODE; 154 } 155 }; 156 else if (LOCAL_VALUE.equals(sysvar)) 157 return new SystemVariableGenerator() 158 { 159 public Object getValue(StorageContext context) 160 { 161 return context.getLocalName(); 162 } 163 public String getXMLType() 164 { 165 return "<simpleType><restriction base=\"string\"><maxLength value=\"255\"/></restriction></simpleType>"; 166 } 167 public short getType() 168 { 169 return LOCAL_CODE; 170 } 171 }; 172 else if (URI_VALUE.equals(sysvar)) 173 return new SystemVariableGenerator() 174 { 175 public Object getValue(StorageContext context) { 176 return context.getNamespaceURI(); 177 } 178 public String getXMLType() 179 { 180 return "<simpleType><restriction base=\"string\"><maxLength value=\"255\"/></restriction></simpleType>"; 181 } 182 public short getType() 183 { 184 return URI_CODE; 185 } 186 }; 187 else return null; 188 } 189 } 190 | Popular Tags |