/** @return la Hashtable donnant un objet Footprint d'après son nom */ public Hashtable<String, FootprintBean> getFooprintHash() { InputStream is; ResourceSet resSet = new ResourceSet(); try { // cas où on a passé un inputstream comme constructeur if (mis != null) { is = buildInputStream(); SavotPullParser parser = new SavotPullParser(is, SavotPullEngine.FULL, null, false); votable = parser.getVOTable(); resSet = votable.getResources(); } // cas où on a passé un tableau de SavotResource else { for (int i = 0; i < resources.length; i++) resSet.addItem(resources[i]); } } catch (Exception e) { e.printStackTrace(); Aladin.warning("Problem during parsing of footprints !"); return null; } int nbRes = resSet.getItemCount(); // System.out.println(nbRes); hash = new Hashtable<String, FootprintBean>(); for (int i = 0; i < nbRes; i++) { Aladin.trace(3, "Footprint: Processing resource: " + i); processFovResource((SavotResource) resSet.getItemAt(i)); } // new Footprint(raOffset,deOffset,) return hash; }
public static void main(String[] args) throws IOException { ResourceSet r = new ResourceSet(); r.setName("test name"); r.setIconUri("http://icon.com"); final ObjectMapper mapper = ServerUtil.createJsonMapper(); mapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true); final String json = mapper.writeValueAsString(r); System.out.println(json); final String j = "{\"resourceSetStatus\":{\"_id\":1364301527462,\"_rev\":1,\"status\":\"created\"}}"; // final String j = "{\"_id\":1364301527462,\"_rev\":1,\"status\":\"created\"}"; final ResourceSetStatus newR = TUma.readJsonValue(j, ResourceSetStatus.class); System.out.println(); }
public static String[] toResourceIds(ResourceSet resources) { String[] resourceIds = new String[resources.size()]; int i = 0; for (Resource resource : resources) { resourceIds[i++] = resource.getUri(); } return resourceIds; }
/** * Main method of the example class. * * @param args (ignored) command-line arguments * @throws Exception exception */ public static void main(final String[] args) throws Exception { System.out.println("=== XMLDBQuery ===\n"); System.out.println("* Run query via XML:DB:"); // Collection instance Collection coll = null; try { // Register the database Class<?> c = Class.forName(DRIVER); Database db = (Database) c.newInstance(); DatabaseManager.registerDatabase(db); // Receive the database coll = DatabaseManager.getCollection(DBNAME); // Receive the XPath query service XPathQueryService service = (XPathQueryService) coll.getService("XPathQueryService", "1.0"); // Execute the query and receives all results ResourceSet set = service.query(QUERY); // Create a result iterator ResourceIterator iter = set.getIterator(); // Loop through all result items while (iter.hasMoreResources()) { // Receive the next results Resource res = iter.nextResource(); // Write the result to the console System.out.println(res.getContent()); } } catch (final XMLDBException ex) { // Handle exceptions System.err.println("XML:DB Exception occured " + ex.errorCode); } finally { // Close the collection if (coll != null) coll.close(); } }
public static DataTypeLists<String> getPropertiesByDataType(ResourceSet resourceSet) { if (resourceSet.isEmpty()) { return new DataTypeLists<String>(); } // no aggregation DataTypeLists<String> result = new DataTypeLists<String>(); Resource resource = resourceSet.getFirstElement(); if (resource == null) { return result; } for (Entry<String, Serializable> entry : resource.getProperties().entrySet()) { Serializable value = entry.getValue(); String propertyName = entry.getKey(); if (value instanceof String) { result.get(DataType.TEXT).add(propertyName); } if (value instanceof Double) { result.get(DataType.NUMBER).add(propertyName); } if (value instanceof Resource) { Resource r = (Resource) value; if (r.getValue(LATITUDE) != null && r.getValue(LONGITUDE) != null) { result.get(DataType.LOCATION).add(propertyName); } } if (value instanceof Date) { result.get(DataType.DATE).add(propertyName); } } return result; }
/** * This method performs an XPath query to the database and returns the results as a Vector of * Strings. * * @param collection The name of the collection to look for the document. * @param query A string containing an XPath expression which shall act as a query against the * database. * @param username The identifier of the user calling the method used for authentication. * @param password The password of the user calling the method used for authentication. * @return A Vector containing the answers to the query as Strings. */ public Vector query(String collection, String query, String username, String password) { Vector response = new Vector(); try { Class cl = Class.forName(_driver); Database database = (Database) cl.newInstance(); DatabaseManager.registerDatabase(database); Collection col = DatabaseManager.getCollection(_URI + collection, username, password); XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0"); service.setProperty("indent", "yes"); ResourceSet result = service.query(query); ResourceIterator i = result.getIterator(); while (i.hasMoreResources()) { Resource r = i.nextResource(); response.add((String) r.getContent()); } } catch (Exception e) { e.printStackTrace(); } return response; }
public GuideCertInstallPane() { super(); setLayout(new GridBagLayout()); ResourceSet resource = KeyCertUtility.getKeyCertWizardResourceSet(); setBorder( new TitledBorder( new CompoundBorder( new EtchedBorder(), new EmptyBorder( COMPONENT_SPACE, COMPONENT_SPACE, COMPONENT_SPACE, COMPONENT_SPACE)), resource.getString("GuideCertInstallPane", "title"))); int y = 0; GridBagUtil.constrain( this, new MultilineLabel(resource.getString("GuideCertInstallPane", "explain")), 0, ++y, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, 0, 0, SEPARATED_COMPONENT_SPACE, 0); GridBagUtil.constrain( this, Box.createVerticalGlue(), 0, ++y, 1, 1, 1.0, 1.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, 0, 0, 0, 0); GridBagUtil.constrain( this, new JLabel(resource.getString(null, "clickNextToContinue")), 0, ++y, 1, 1, 1.0, 0.0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, 0, 0, 0, 0); }
// XXX why isn't this using the same code as getPropertiesByDataType? public static List<String> getPropertyNamesForDataType( ResourceSet resourceSet, DataType dataType) { if (resourceSet.isEmpty()) { return Collections.emptyList(); } // no aggregation Resource resource = resourceSet.getFirstElement(); List<String> properties = new ArrayList<String>(); for (Entry<String, Serializable> entry : resource.getProperties().entrySet()) { switch (dataType) { case TEXT: { if (entry.getValue() instanceof String) { properties.add(entry.getKey()); } } break; case NUMBER: { if (entry.getValue() instanceof Double) { properties.add(entry.getKey()); } } break; case LOCATION: { if (entry.getValue() instanceof Resource) { Resource r = (Resource) entry.getValue(); if (r.getValue(LATITUDE) != null && r.getValue(LONGITUDE) != null) { properties.add(entry.getKey()); } } } break; case DATE: { if (entry.getValue() instanceof Date) { properties.add(entry.getKey()); } } break; case COLOR: { if (entry.getValue() instanceof Color) { properties.add(entry.getKey()); } } case SHAPE: { if (entry.getValue() instanceof String && isShape(entry.getValue())) { properties.add(entry.getKey()); } } } } return properties; }
/** * construit le footprint associé à une RESOURCE * * @param res la RESOURCE "racine", pouvant contenir d'autres RESOURCE */ private void processFovResource(SavotResource res) { FootprintBean fpBean = new FootprintBean(); sphericalCoordinates = false; tabIndex = 0; SubFootprintBean sub; // System.out.println("Processing resource "+res); refMem = new Hashtable<String, MarkupComment>(); String id = res.getId(); // par défaut fpBean.setInstrumentName(id); // dangereux, car c'est sur cet ID qu'on va référencer un FoV // if( id==null || id.length()==0 ) id = res.getName(); // traitement des params au niveau RESOURCE ParamSet params = res.getParams(); int nbParam = params.getItemCount(); SavotParam param; for (int i = 0; i < nbParam; i++) { param = (SavotParam) params.getItemAt(i); if (param.getUtype().trim().equalsIgnoreCase(SPHERICAL_COORDS)) { sphericalCoordinates = true; } // position RA du FoV if (param.getUcd().equalsIgnoreCase("pos.eq.ra;meta.main")) { fpBean.setRa(param.getValue()); } // position DE du FoV else if (param.getUcd().equalsIgnoreCase("pos.eq.dec;meta.main")) { fpBean.setDe(param.getValue()); } // position RA du centre de rotation du FoV (PF jan 09) if (param.getUcd().equalsIgnoreCase("pos.eq.ra")) { fpBean.setRaRot(param.getValue()); } // position DE du centre de rotation du FoV (PF jan 09) else if (param.getUcd().equalsIgnoreCase("pos.eq.dec")) { fpBean.setDeRot(param.getValue()); } // angle position du FoV else if (param.getUcd().equalsIgnoreCase("pos.posAng") || param.getUtype().equals(SIAPExtBuilder.FOV_POS_ANGLE)) { double d; try { d = Double.valueOf(param.getValue()).doubleValue(); } catch (NumberFormatException e) { continue; // d = 0.; } fpBean.setPosAngle(d); } // caractère "movable" du FoV else if (param.getName().equalsIgnoreCase("Movable")) { boolean b; try { b = Boolean.valueOf(param.getValue()).booleanValue(); } catch (NumberFormatException e) { continue; } fpBean.setMovable(b); } // caractère "rollable" du FoV else if (param.getName().equalsIgnoreCase("Rollable")) { boolean b; try { b = Boolean.valueOf(param.getValue()).booleanValue(); } catch (NumberFormatException e) { continue; } fpBean.setRollable(b); } // convention interne à Aladin pour affichage dans JTable else if (param.getId().equals("InstrumentDescription")) { fpBean.setInstrumentDesc(param.getValue()); } // convention interne à Aladin pour affichage dans JTable else if (param.getId().equals("InstrumentName")) { fpBean.setInstrumentName(param.getValue()); } // convention interne à Aladin pour affichage dans JTable else if (param.getId().equals("TelescopeName")) { fpBean.setTelescopeName(param.getValue()); } // convention interne à Aladin pour affichage dans JTable else if (param.getId().equals("Origin")) { fpBean.setOrigin(param.getValue()); } } // traitement de la RESOURCE racine sub = processResource(res); if (sub != null && sub.getNbOfSubParts() > 0) fpBean.addSubFootprintBean(sub); /* for( int i=0; i<nbTab; i++ ) { processTable((SavotTable)tables.getItemAt(i), i); } */ // traitement des RESOURCEs dans RESOURCE (Tom Donaldson) ResourceSet resources = res.getResources(); for (int i = 0; i < resources.getItemCount(); i++) { sub = processResource((SavotResource) resources.getItemAt(i)); if (sub != null) { fpBean.addSubFootprintBean(sub); // on garde en mémoire les sous-parties d'un FoV --> on les place pour cela dans un // container String subfpId = ((SavotResource) resources.getItemAt(i)).getId(); if (subfpId != null && subfpId.length() > 0) { FootprintBean container = new FootprintBean(); container.addSubFootprintBean(sub); container.setDisplayInFovList(false); // on évite d'écraser un bean existant par un sub-bean if (!hash.contains(subfpId)) { hash.put(subfpId, container); } } } } hash.put(id, fpBean); // on ne vérifie plus l'existence d'un bean avec le meme nom, on écrase if (footprintHash.get(id) != null) { Aladin.trace( 1, "Footprint with ID " + id + "already exists ...\n Existing definition will be erased"); } Aladin.trace(3, "Footprint : add to footprintHash footprint with key " + id + "**"); footprintHash.put(id, fpBean); }