1 19 20 package org.netbeans.modules.dbschema.util; 21 22 public class NameUtil { 23 24 25 private static final char columnPairSeparator = ';'; 26 27 28 public static final char dbElementSeparator = '.'; 29 30 33 public static String getSchemaResourceName(String schemaName) { 34 return (schemaName + ".dbschema"); } 36 37 43 public static String getTableName (String memberName) { 44 int index = memberName.indexOf(columnPairSeparator); 45 String tempString = ((index != -1) ? memberName.substring(0, index) : memberName); 46 47 return tempString.substring(0, tempString.lastIndexOf(dbElementSeparator)); 48 } 49 50 56 public static String getSchemaName(String memberName) 57 { 58 if (memberName == null) 59 return null; 60 int index = memberName.indexOf(columnPairSeparator); 61 String tempString = ((index != -1) ? memberName.substring(0, index) : memberName); 62 63 return tempString.substring(0, tempString.indexOf(dbElementSeparator)); 64 } 65 66 73 public static String getRelativeTableName(String tableName) 74 { 75 if (tableName == null) 76 return null; 77 78 if (isRelativeTableName(tableName)) 79 return tableName; 80 81 return tableName.substring(tableName.indexOf(dbElementSeparator) + 1); 82 } 83 84 93 public static String getRelativeMemberName(String memberName) 94 { 95 if (memberName == null) 96 return null; 97 98 int semicolonIndex = memberName.indexOf(columnPairSeparator); 99 if (semicolonIndex != -1) 100 { 101 String firstColumn = memberName.substring(0, semicolonIndex); 102 String secondColumn = memberName.substring(semicolonIndex + 1); 103 return getRelativeMemberNameInternal(firstColumn) + columnPairSeparator + 104 getRelativeMemberNameInternal(secondColumn); 105 } 106 else 107 { 108 return getRelativeMemberNameInternal(memberName); 109 } 110 } 111 112 121 private static String getRelativeMemberNameInternal(String memberName) 122 { 123 if (memberName == null) 124 return null; 125 126 if (isRelativeMemberName(memberName)) 127 return memberName; 128 129 return memberName.substring(memberName.indexOf(dbElementSeparator) + 1); 130 } 131 132 141 public static String getAbsoluteTableName(String schemaName, String tableName) 142 { 143 if (tableName == null) 144 return null; 145 146 if (!isRelativeTableName(tableName)) 147 return tableName; 148 149 return schemaName + dbElementSeparator + tableName; 150 } 151 152 162 public static String getAbsoluteMemberName(String schemaName, String memberName) 163 { 164 if (memberName == null) 165 return null; 166 167 int semicolonIndex = memberName.indexOf(columnPairSeparator); 168 if (semicolonIndex != -1) 169 { 170 String firstColumn = memberName.substring(0, semicolonIndex); 171 String secondColumn = memberName.substring(semicolonIndex + 1); 172 return getAbsoluteMemberNameInternal(schemaName, firstColumn) + 173 columnPairSeparator + 174 getAbsoluteMemberNameInternal(schemaName, secondColumn); 175 } 176 else 177 { 178 return getAbsoluteMemberNameInternal(schemaName, memberName); 179 } 180 } 181 182 193 private static String getAbsoluteMemberNameInternal(String schemaName, String memberName) 194 { 195 if (memberName == null) 196 return null; 197 if (!isRelativeMemberName(memberName)) 198 return memberName; 199 200 return schemaName + dbElementSeparator + memberName; 201 } 202 203 211 private static boolean isRelativeTableName(String tableName) 212 { 213 return tableName.indexOf(dbElementSeparator) == -1; 215 } 216 217 226 private static boolean isRelativeMemberName(String columnName) 227 { 228 int first = columnName.indexOf(dbElementSeparator); 230 return columnName.indexOf(dbElementSeparator, first + 1) == -1; 231 } 232 } 233 | Popular Tags |