public static Set toSet(Model m) throws ModelException { Set s = new HashSet(); Enumeration en = m.elements(); while (en.hasMoreElements()) s.add(en.nextElement()); return s; }
protected void finished() { logger.log(LogService.LOG_DEBUG, "Here is OcdHandler():finished()"); // $NON-NLS-1$ if (!_isParsedDataValid) return; if (_ad_vector.size() == 0) { // Schema defines at least one AD is required. _isParsedDataValid = false; logger.log( LogService.LOG_ERROR, NLS.bind( MetaTypeMsg.MISSING_ELEMENT, new Object[] { AD, OCD, elementId, _dp_url, _dp_bundle.getBundleId(), _dp_bundle.getSymbolicName() })); return; } // OCD gets all parsed ADs. Enumeration<AttributeDefinitionImpl> adKey = _ad_vector.elements(); while (adKey.hasMoreElements()) { AttributeDefinitionImpl ad = adKey.nextElement(); _ocd.addAttributeDefinition(ad, ad._isRequired); } _ocd.setIcons(icons); _parent_OCDs_hashtable.put(_refID, _ocd); }
/** Prints the triples of a model to the given PrintStream. */ public static void printStatements(Model m, PrintStream ps) throws ModelException { for (Enumeration en = m.elements(); en.hasMoreElements(); ) { Statement t = (Statement) en.nextElement(); ps.println(t); // "triple(\""+t.subject()+"\",\""+t.predicate()+"\",\""+t.object()+"\")."); } }
public static void collectLiterals(Model m, Collection target) throws ModelException { for (Enumeration en = m.elements(); en.hasMoreElements(); ) { Statement st = (Statement) en.nextElement(); if (st.object() instanceof Literal) target.add(st.object()); } }
public static void collectNamespaces(Model m, Collection target) throws ModelException { for (Enumeration en = m.elements(); en.hasMoreElements(); ) { Statement st = (Statement) en.nextElement(); collectNamespaces(st, target); } }
public static void collectPredicates(Model m, Collection target) throws ModelException { for (Enumeration en = m.elements(); en.hasMoreElements(); ) { Statement st = (Statement) en.nextElement(); target.add(st.predicate()); } }
/** Collects the triples of a model in a vector. */ public static Vector getStatementVector(Model m) throws ModelException { Vector v = new Vector(); for (Enumeration en = m.elements(); en.hasMoreElements(); ) { Statement t = (Statement) en.nextElement(); v.addElement(t); } return v; }
public static Hashtable getNodes(Model m) throws ModelException { Hashtable t = new Hashtable(); for (Enumeration en = m.elements(); en.hasMoreElements(); ) { Statement s = (Statement) en.nextElement(); t.put(s.subject(), s.subject()); t.put(s.object(), s.object()); } return t; }
public void save(PrintStream stream) { saved = true; stream.println("<?xml version=\"1.0\"?>"); stream.println("<scale>"); stream.println(" <name>" + nameTF.getText() + "</name>"); for (Enumeration en = sp.notes.elements(); en.hasMoreElements(); ) { ScalePanel.Notik cur = (ScalePanel.Notik) en.nextElement(); stream.println(" <note>" + cur.n + "</note>"); } stream.println("</scale>"); }
public static void collectResources(Model m, Collection target) throws ModelException { for (Enumeration en = m.elements(); en.hasMoreElements(); ) { Statement st = (Statement) en.nextElement(); if (!(st.object() instanceof Literal) && !(st.object() instanceof Statement)) target.add(st.object()); target.add(st.subject()); target.add(st.predicate()); } }
// FIXME: use digest instead of size static void getReachable(Resource r, Model m, Model result) throws ModelException { int oldSize = result.size(); Model directlyReachable = m.find(r, null, null); SetOperations.unite(result, directlyReachable); if (result.size() == oldSize) return; for (Enumeration en = directlyReachable.elements(); en.hasMoreElements(); ) { Statement t = (Statement) en.nextElement(); if (t.object() instanceof Resource) getReachable((Resource) t.object(), m, result); } }
/** Collects the triples of a model into an array. */ public static Statement[] getStatementArray(Model m) throws ModelException { Statement[] v = new Statement[m.size()]; int i = 0; for (Enumeration en = m.elements(); en.hasMoreElements(); ) { Statement t = (Statement) en.nextElement(); v[i++] = t; } return v; }
/** * @return a new model in which all occurrences of the old namespace are replaced by the new one. * All replaced resources are summarized in the map if not null. If resourcesToIgnore != null, * ignore resources listed there. */ public static Model replaceNamespace(Model m, String o, String n, Map o2n, Set resourcesToIgnore) throws ModelException { Model res = m.create(); NodeFactory f = m.getNodeFactory(); Enumeration en = m.elements(); while (en.hasMoreElements()) { Statement st = (Statement) en.nextElement(); res.add(replaceNamespace(st, o, n, f, o2n, resourcesToIgnore)); } return res; }
protected void finished() { logger.log(LogService.LOG_DEBUG, "Here is MetaDataHandler():finished()"); // $NON-NLS-1$ if (_dp_designateHandlers.size() == 0) { // Schema defines at least one DESIGNATE is required. _isParsedDataValid = false; logger.log( LogService.LOG_WARNING, NLS.bind( MetaTypeMsg.MISSING_ELEMENT, new Object[] { DESIGNATE, METADATA, elementId, _dp_url, _dp_bundle.getBundleId(), _dp_bundle.getSymbolicName() })); return; } Enumeration<DesignateHandler> designateHandlerKeys = _dp_designateHandlers.elements(); while (designateHandlerKeys.hasMoreElements()) { DesignateHandler dh = designateHandlerKeys.nextElement(); ObjectClassDefinitionImpl ocd = _dp_OCDs.get(dh._ocdref); if (ocd != null) { designates.add( new Designate.Builder(ocd) .bundle(dh._bundle_val) .factoryPid(dh._factory_val) .merge(dh._merge_val) .pid(dh._pid_val) .optional(dh._optional_val) .build()); } else { logger.log( LogService.LOG_ERROR, NLS.bind( MetaTypeMsg.OCD_REF_NOT_FOUND, new Object[] { dh._pid_val, dh._factory_val, dh._ocdref, _dp_url, _dp_bundle.getBundleId(), _dp_bundle.getSymbolicName() })); } } }
public static List getObjects(Model m, Resource subject, Resource predicate) throws ModelException { List result = new ArrayList(); if (m == null || m.size() == 0) return result; for (Enumeration en = m.find(subject, predicate, null).elements(); en.hasMoreElements(); ) { Statement st = (Statement) en.nextElement(); result.add(st.object()); } return result; }
/** Removes all triples which have something to do with the given namespace */ public static Model removeNamespace(String ns, Model m) throws ModelException { Model res = m.duplicate(); for (Enumeration en = m.duplicate().elements(); en.hasMoreElements(); ) { Statement t = (Statement) en.nextElement(); if (t.subject().toString().startsWith(ns) || t.predicate().toString().startsWith(ns) || t.object().toString().startsWith(ns)) { // System.err.println("REMOVING TRIPLE: " + t); res.remove(t); } } return res; }
/** * @return a new model in which all occurrences of the old resources are replaced by the new ones. * Returns number replacements done. */ public static int replaceResources(Model src, Model dest, Map o2n) throws ModelException { NodeFactory f = src.getNodeFactory(); Enumeration en = src.elements(); int replaced = 0; while (en.hasMoreElements()) { Statement st = (Statement) en.nextElement(); Statement st_n = replaceResources(st, f, o2n); dest.add(st_n); if (st_n != st) // yes, pointer comparison replaced++; } return replaced; }
/** * @return a new model in which all occurrences of the old resources are replaced by the new ones. * Returns number replacements done. */ public static int replaceResources(Model m, Map o2n) throws ModelException { NodeFactory f = m.getNodeFactory(); Enumeration en = m.elements(); Model toRemove = m.create(); Model toAdd = m.create(); while (en.hasMoreElements()) { Statement st = (Statement) en.nextElement(); Statement st_n = replaceResources(st, f, o2n); if (st_n != st) { // yes, pointer comparison toAdd.add(st_n); toRemove.add(st); } } SetOperations.subtract(m, toRemove); SetOperations.unite(m, toAdd); return toAdd.size(); }