1 36 package org.ungoverned.oscar; 37 38 import java.util.ArrayList ; 39 import java.util.List ; 40 import java.util.StringTokenizer ; 41 42 import org.osgi.framework.Constants; 43 44 public class LibraryInfo 45 { 46 private String m_name = null; 47 private String [] m_osnames = null; 48 private String [] m_osversions = null; 49 private String [] m_processors = null; 50 private String [] m_languages = null; 51 52 public LibraryInfo(String name, String [] osnames, String [] osversions, 53 String [] processors, String [] languages) 54 { 55 m_name = name; 56 m_osnames = osnames; 57 m_osversions = osversions; 58 m_processors = processors; 59 m_languages = languages; 60 } 61 62 public LibraryInfo(LibraryInfo library) 63 { 64 m_name = library.m_name; 65 m_osnames = library.m_osnames; 66 m_osversions = library.m_osversions; 67 m_processors = library.m_processors; 68 m_languages = library.m_languages; 69 } 70 71 public String getName() 72 { 73 return m_name; 74 } 75 76 public String [] getOSNames() 77 { 78 return m_osnames; 79 } 80 81 public String [] getOSVersions() 82 { 83 return m_osversions; 84 } 85 86 public String [] getProcessors() 87 { 88 return m_processors; 89 } 90 91 public static LibraryInfo[] parse(String s) 92 { 93 try 94 { 95 if ((s == null) || (s.length() == 0)) 96 { 97 return null; 98 } 99 100 StringTokenizer st = new StringTokenizer (s, ";"); 104 String [] libs = new String [st.countTokens()]; 105 List osNameList = new ArrayList (); 106 List osVersionList = new ArrayList (); 107 List processorList = new ArrayList (); 108 List languageList = new ArrayList (); 109 int libCount = 0; 110 while (st.hasMoreTokens()) 111 { 112 String token = st.nextToken().trim(); 113 if (token.indexOf('=') < 0) 114 { 115 libs[libCount] = (token.charAt(0) == '/') 117 ? token.substring(1) 118 : token; 119 libCount++; 120 } 121 else 122 { 123 StringTokenizer stProp = new StringTokenizer (token, "="); 126 if (stProp.countTokens() != 2) 127 { 128 throw new IllegalArgumentException ( 129 "Bundle manifest native library entry malformed: " + token); 130 } 131 String property = stProp.nextToken().trim().toLowerCase(); 132 String value = stProp.nextToken().trim(); 133 134 if (value.charAt(0) == '"') 136 { 137 if (value.charAt(value.length() - 1) == '"') 141 { 142 value = value.substring(1, value.length() - 1); 143 } 144 else 145 { 146 value = value.substring(1); 147 } 148 } 149 if (property.equals(Constants.BUNDLE_NATIVECODE_OSNAME)) 151 { 152 osNameList.add(value); 153 } 154 else if (property.equals(Constants.BUNDLE_NATIVECODE_OSVERSION)) 155 { 156 osVersionList.add(value); 157 } 158 else if (property.equals(Constants.BUNDLE_NATIVECODE_PROCESSOR)) 159 { 160 processorList.add(value); 161 } 162 else if (property.equals(Constants.BUNDLE_NATIVECODE_LANGUAGE)) 163 { 164 languageList.add(value); 165 } 166 } 167 } 168 169 if (libCount == 0) 170 { 171 return null; 172 } 173 174 LibraryInfo[] libraries = new LibraryInfo[libCount]; 175 for (int i = 0; i < libCount; i++) 176 { 177 libraries[i] = 178 new LibraryInfo( 179 libs[i], 180 (String []) osNameList.toArray(new String [0]), 181 (String []) osVersionList.toArray(new String [0]), 182 (String []) processorList.toArray(new String [0]), 183 (String []) languageList.toArray(new String [0])); 184 } 185 186 return libraries; 187 188 } 189 catch (RuntimeException ex) 190 { 191 ex.printStackTrace(); 192 throw ex; 193 } 194 } 195 196 public String toString() 197 { 198 return m_name; 199 } 200 } 201 | Popular Tags |