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); }
public void startElement(String uri, String localName, String qName, Attributes atts) { logger.log( LogService.LOG_DEBUG, "Here is AttributeDefinitionHandler:startElement():" //$NON-NLS-1$ + qName); if (!_isParsedDataValid) return; String name = getName(localName, qName); if (name.equalsIgnoreCase(OPTION)) { OptionHandler optionHandler = new OptionHandler(this); optionHandler.init(name, atts); if (optionHandler._isParsedDataValid) { // Only add valid Option _optionLabel_vector.addElement(optionHandler._label_val); _optionValue_vector.addElement(optionHandler._value_val); } } else { logger.log( LogService.LOG_WARNING, NLS.bind( MetaTypeMsg.UNEXPECTED_ELEMENT, new Object[] { name, atts.getValue(ID), _dp_url, _dp_bundle.getBundleId(), _dp_bundle.getSymbolicName() })); } }
/** 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 void remove(Track track) { synchronized (this) { docElt.removeChild(track.getElement()); tracks.remove(track); hash.remove(track.getKey()); } }
/** * A nice ol' bubble sort. This is used because it has a passable performance when the list starts * off sorted. */ public void sort() { synchronized (this) { boolean swap; do { swap = false; for (int i = 1; i < tracks.size(); i++) { Track lastTrack = (Track) tracks.elementAt(i - 1); Track track = (Track) tracks.elementAt(i); if (compare(lastTrack, track) > 0) { tracks.setElementAt(track, i - 1); tracks.setElementAt(lastTrack, i); swap = true; } } } while (swap); } }
// 응용프로그램에서 이미지 출력을 하기 위한 메소드 public void showImage() throws Exception { for (int i = 0; i < vUnparsedEntityDecl.size(); i++) { UnparsedEntityDecl ued = (UnparsedEntityDecl) vUnparsedEntityDecl.elementAt(i); URL urlImageFile = new URL(ued.systemId); String imageFile = URLDecoder.decode(urlImageFile.getFile(), "euc-kr"); imageFile = imageFile.replaceAll("/C:", "C:"); NotationDecl nd = (NotationDecl) hNotationDecl.get(ued.notationName); URL urlHelperProgram = new URL(nd.systemId); String helperProgram = URLDecoder.decode(urlHelperProgram.getFile(), "euc-kr"); helperProgram = helperProgram.replaceAll("/C:", "C:"); String command = helperProgram + " " + imageFile; System.out.println(command); Process process = Runtime.getRuntime().exec(command); } }
public Track add(Track track) { synchronized (this) { Track copy; if ((copy = getTrack(track)) == null) { copy = new Track((Element) doc.importNode(track.getElement(), false)); docElt.appendChild(copy.getElement()); tracks.add(copy); hash.put(copy.getKey(), copy); } return copy; } }
public void load(InputStream is) throws IOException, ParserConfigurationException, SAXException { doc = db.parse(is); docElt = doc.getDocumentElement(); if (docElt.getTagName().equals(docElementName)) { NodeList nl = docElt.getElementsByTagName(trackElementName); for (int i = 0; i < nl.getLength(); i++) { Element elt = (Element) nl.item(i); Track track = new Track(elt); tracks.add(track); hash.put(track.getKey(), track); } } }
private Vector<String> splitFields(String s) { Vector<String> fields = new Vector<String>(); boolean inQuote = false; StringBuffer buf = new StringBuffer(); for (int i = 0; i < s.length(); i++) { if (!inQuote && s.charAt(i) == csvQuotes) { inQuote = true; continue; } if (inQuote && s.charAt(i) == csvQuotes) { inQuote = false; continue; } if (!inQuote && s.charAt(i) == csvSeparator) { fields.add(buf.toString()); buf = new StringBuffer(); continue; } buf.append(s.charAt(i)); } fields.add(buf.toString()); return fields; }
protected void finished() { logger.log( LogService.LOG_DEBUG, "Here is AttributeDefinitionHandler():finished()"); // $NON-NLS-1$ if (!_isParsedDataValid) return; int numOfValues = _optionValue_vector.size(); _ad.setOption(_optionLabel_vector, _optionValue_vector, true); String[] values = _ad.getOptionValues(); if (values == null) values = new String[0]; if (numOfValues != values.length) logger.log( LogService.LOG_WARNING, NLS.bind( MetaTypeMsg.INVALID_OPTIONS_XML, new Object[] { elementId, _dp_url, _dp_bundle.getBundleId(), _dp_bundle.getSymbolicName() })); if (ad_defaults_str != null) { _ad.setDefaultValue(ad_defaults_str, true); if (_ad.getDefaultValue() == null) logger.log( LogService.LOG_WARNING, NLS.bind( MetaTypeMsg.INVALID_DEFAULTS_XML, new Object[] { ad_defaults_str, elementId, _dp_url, _dp_bundle.getBundleId(), _dp_bundle.getSymbolicName() })); } _parent_ADs_vector.addElement(_ad); }
private void applyUpdates() throws SAXException { // now handle any updates if (updates.size() > 0) { try { Object upd[]; Iterator<?> i = updates.iterator(); while (i.hasNext()) { upd = (Object[]) i.next(); idx = ((Integer) upd[0]).intValue(); if (!(lastval.equals(upd[1]))) { insertValue((String) (upd[1])); } } rs.updateRow(); } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errupdrow").toString(), ex.getMessage())); } updates.removeAllElements(); } }
public int runCsvImport() { int count = 0; try { int linecnt = 0; String[] header = null; ArrayList<String> fieldsInImport = new ArrayList<String>(); BufferedReader f = new BufferedReader(new InputStreamReader(new FileInputStream(filename), encoding)); String s; DataRecord dummyRecord = storageObject.createNewRecord(); while ((s = f.readLine()) != null) { s = s.trim(); if (s.length() == 0) { continue; } Vector<String> fields = splitFields(s); if (fields.size() > 0) { if (linecnt == 0) { // header header = new String[fields.size()]; for (int i = 0; i < fields.size(); i++) { header[i] = fields.get(i); if (header[i].startsWith("#") && header[i].endsWith("#") && header.length > 2) { header[i] = header[i].substring(1, header[i].length() - 1).trim(); overrideKeyField = header[i]; } String[] equivFields = dummyRecord.getEquivalentFields(header[i]); for (String ef : equivFields) { fieldsInImport.add(ef); } } } else { // fields DataRecord r = storageObject.createNewRecord(); for (int i = 0; i < header.length; i++) { String value = (fields.size() > i ? fields.get(i) : null); if (value != null && value.length() > 0) { try { if (!r.setFromText(header[i], value.trim())) { logImportWarning( r, "Value '" + value + "' for Field '" + header[i] + "' corrected to '" + r.getAsText(header[i]) + "'"); } } catch (Exception esetvalue) { logImportWarning( r, "Cannot set value '" + value + "' for Field '" + header[i] + "': " + esetvalue.toString()); } } } if (importRecord(r, fieldsInImport)) { count++; } } } linecnt++; } f.close(); } catch (Exception e) { logInfo(e.toString()); errorCount++; Logger.log(e); if (Daten.isGuiAppl()) { Dialog.error(e.toString()); } } return count; }
public int getNoOfTracks() { return tracks.size(); }
/** * Sets the value for the given element if <code>name</code> is one of the array elements in the * fields <code>properties</code>, <code>colDef</code>, or <code>data</code> and this <code> * XmlReaderContentHandler</code> object's state is not <code>INITIAL</code>. If the state is * <code>INITIAL</code>, this method does nothing. * * <p>If the state is <code>METADATA</code> and the argument supplied is <code>"metadata"</code>, * the rowset's metadata is set. If the state is <code>PROPERTIES</code>, the appropriate property * is set using the given name to determine the appropriate value. If the state is <code>DATA * </code> and the argument supplied is <code>"data"</code>, this method sets the state to <code> * INITIAL</code> and returns. If the argument supplied is one of the elements in the field <code> * data</code>, this method makes the appropriate changes to the rowset's data. * * @param lName the name of the element; either (1) one of the array elements in the fields <code> * properties</code>, <code>colDef</code>, or <code>data</code> or (2) one of the <code>RowSet * </code> elements <code>"properties"</code>, <code>"metadata"</code>, or <code>"data"</code> * @exception SAXException if a general SAX error occurs */ @SuppressWarnings("fallthrough") public void endElement(String uri, String lName, String qName) throws SAXException { int tag; String name = ""; name = lName; switch (getState()) { case PROPERTIES: if (name.equals("properties")) { state = INITIAL; break; } try { tag = propMap.get(name); switch (tag) { case KeycolsTag: if (keyCols != null) { int i[] = new int[keyCols.size()]; for (int j = 0; j < i.length; j++) i[j] = Integer.parseInt(keyCols.elementAt(j)); rs.setKeyColumns(i); } break; case PropClassTag: // Added the handling for Class tags to take care of maps // Makes an entry into the map upon end of class tag try { typeMap.put(Key_map, j86.sun.reflect.misc.ReflectUtil.forName(Value_map)); } catch (ClassNotFoundException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errmap").toString(), ex.getMessage())); } break; case MapTag: // Added the handling for Map to take set the typeMap rs.setTypeMap(typeMap); break; default: break; } if (getNullValue()) { setPropertyValue(null); setNullValue(false); } else { setPropertyValue(propertyValue); } } catch (SQLException ex) { throw new SAXException(ex.getMessage()); } // propertyValue need to be reset to an empty string propertyValue = ""; setTag(-1); break; case METADATA: if (name.equals("metadata")) { try { rs.setMetaData(md); state = INITIAL; } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errmetadata").toString(), ex.getMessage())); } } else { try { if (getNullValue()) { setMetaDataValue(null); setNullValue(false); } else { setMetaDataValue(metaDataValue); } } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errmetadata").toString(), ex.getMessage())); } // metaDataValue needs to be reset to an empty string metaDataValue = ""; } setTag(-1); break; case DATA: if (name.equals("data")) { state = INITIAL; return; } if (dataMap.get(name) == null) { tag = NullTag; } else { tag = dataMap.get(name); } switch (tag) { case ColTag: try { idx++; if (getNullValue()) { insertValue(null); setNullValue(false); } else { insertValue(tempStr); } // columnValue now need to be reset to the empty string columnValue = ""; } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errinsertval").toString(), ex.getMessage())); } break; case RowTag: try { rs.insertRow(); rs.moveToCurrentRow(); rs.next(); // Making this as the original to turn off the // rowInserted flagging rs.setOriginalRow(); applyUpdates(); } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errconstr").toString(), ex.getMessage())); } break; case DelTag: try { rs.insertRow(); rs.moveToCurrentRow(); rs.next(); rs.setOriginalRow(); applyUpdates(); rs.deleteRow(); } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errdel").toString(), ex.getMessage())); } break; case InsTag: try { rs.insertRow(); rs.moveToCurrentRow(); rs.next(); applyUpdates(); } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errinsert").toString(), ex.getMessage())); } break; case InsDelTag: try { rs.insertRow(); rs.moveToCurrentRow(); rs.next(); rs.setOriginalRow(); applyUpdates(); } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errinsdel").toString(), ex.getMessage())); } break; case UpdTag: try { if (getNullValue()) { insertValue(null); setNullValue(false); } else if (getEmptyStringValue()) { insertValue(""); setEmptyStringValue(false); } else { updates.add(upd); } } catch (SQLException ex) { throw new SAXException( MessageFormat.format( resBundle.handleGetObject("xmlrch.errupdate").toString(), ex.getMessage())); } break; default: break; } default: break; } }
private void setPropertyValue(String s) throws SQLException { // find out if we are going to be dealing with a null boolean nullValue = getNullValue(); switch (getTag()) { case CommandTag: if (nullValue) ; // rs.setCommand(null); else rs.setCommand(s); break; case ConcurrencyTag: if (nullValue) throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); else rs.setConcurrency(getIntegerValue(s)); break; case DatasourceTag: if (nullValue) rs.setDataSourceName(null); else rs.setDataSourceName(s); break; case EscapeProcessingTag: if (nullValue) throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); else rs.setEscapeProcessing(getBooleanValue(s)); break; case FetchDirectionTag: if (nullValue) throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); else rs.setFetchDirection(getIntegerValue(s)); break; case FetchSizeTag: if (nullValue) throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); else rs.setFetchSize(getIntegerValue(s)); break; case IsolationLevelTag: if (nullValue) throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); else rs.setTransactionIsolation(getIntegerValue(s)); break; case KeycolsTag: break; case PropColumnTag: if (keyCols == null) keyCols = new Vector<>(); keyCols.add(s); break; case MapTag: break; case MaxFieldSizeTag: if (nullValue) throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); else rs.setMaxFieldSize(getIntegerValue(s)); break; case MaxRowsTag: if (nullValue) throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); else rs.setMaxRows(getIntegerValue(s)); break; case QueryTimeoutTag: if (nullValue) throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); else rs.setQueryTimeout(getIntegerValue(s)); break; case ReadOnlyTag: if (nullValue) throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); else rs.setReadOnly(getBooleanValue(s)); break; case RowsetTypeTag: if (nullValue) { throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); } else { // rs.setType(getIntegerValue(s)); String strType = getStringValue(s); int iType = 0; if (strType.trim().equals("ResultSet.TYPE_SCROLL_INSENSITIVE")) { iType = 1004; } else if (strType.trim().equals("ResultSet.TYPE_SCROLL_SENSITIVE")) { iType = 1005; } else if (strType.trim().equals("ResultSet.TYPE_FORWARD_ONLY")) { iType = 1003; } rs.setType(iType); } break; case ShowDeletedTag: if (nullValue) throw new SQLException(resBundle.handleGetObject("xmlrch.badvalue").toString()); else rs.setShowDeleted(getBooleanValue(s)); break; case TableNameTag: if (nullValue) // rs.setTableName(null); ; else rs.setTableName(s); break; case UrlTag: if (nullValue) rs.setUrl(null); else rs.setUrl(s); break; case SyncProviderNameTag: if (nullValue) { rs.setSyncProvider(null); } else { String str = s.substring(0, s.indexOf("@") + 1); rs.setSyncProvider(str); } break; case SyncProviderVendorTag: // to be implemented break; case SyncProviderVersionTag: // to be implemented break; case SyncProviderGradeTag: // to be implemented break; case DataSourceLock: // to be implemented break; default: break; } }
/** * Reads XML element(s) into an indexed bean property by first locating the XML element(s) * corresponding to this property. * * @param ob The bean whose property is being set * @param desc The property that will be set * @param nodes The list of XML items that may contain the property * @throws IOException If there is an error reading the document */ public void readIndexedProperty( Object ob, IndexedPropertyDescriptor desc, NodeList nodes, NamedNodeMap attrs) throws IOException { // Create a vector to hold the property values Vector v = new Vector(); int numAttrs = attrs.getLength(); for (int i = 0; i < numAttrs; i++) { // See if this attribute matches the property name if (namesMatch(desc.getName(), attrs.item(i).getNodeName())) { // Get the property value Object obValue = getObjectValue(desc, attrs.item(i).getNodeValue()); if (obValue != null) { // Add the value to the list of values to be set v.addElement(obValue); } } } int numNodes = nodes.getLength(); for (int i = 0; i < numNodes; i++) { Node node = nodes.item(i); // Skip non-element nodes if (!(node instanceof Element)) continue; Element element = (Element) node; // See if this element tag matches the property name if (namesMatch(desc.getName(), element.getTagName())) { // Get the property value Object obValue = getObjectValue(desc, element); if (obValue != null) { // Add the value to the list of values to be set v.addElement(obValue); } } } // Get the method used to set the property value Method setter = desc.getWriteMethod(); // If this property has no setter, don't write it if (setter == null) return; // Create a new array of property values Object propArray = Array.newInstance(desc.getPropertyType().getComponentType(), v.size()); // Copy the vector into the array v.copyInto((Object[]) propArray); try { // Store the array of property values setter.invoke(ob, new Object[] {propArray}); } catch (InvocationTargetException exc) { throw new IOException("Error setting property " + desc.getName() + ": " + exc.toString()); } catch (IllegalAccessException exc) { throw new IOException("Error setting property " + desc.getName() + ": " + exc.toString()); } }
// 외부 언파스드 엔티티 선언을 만났을 때 발생하는 이벤트를 처리하는 메소드 public void unparsedEntityDecl(String name, String publicId, String systemId, String notationName) throws SAXException { UnparsedEntityDecl ued = new UnparsedEntityDecl(name, publicId, systemId, notationName); vUnparsedEntityDecl.addElement(ued); }
public void purge() { for (int i = tracks.size() - 1; i >= 0; i--) { Track track = (Track) tracks.elementAt(i); if (track.isHidden()) tracks.remove(i); } }
/** * Reads an XML element into a bean property by first locating the XML element corresponding to * this property. * * @param ob The bean whose property is being set * @param desc The property that will be set * @param nodes The list of XML items that may contain the property * @throws IOException If there is an error reading the document */ public void readProperty(Object ob, PropertyDescriptor desc, NodeList nodes, NamedNodeMap attrs) throws IOException { int numAttrs = attrs.getLength(); for (int i = 0; i < numAttrs; i++) { // See if the attribute name matches the property name if (namesMatch(desc.getName(), attrs.item(i).getNodeName())) { // Get the method used to set this property Method setter = desc.getWriteMethod(); // If this object has no setter, don't bother writing it if (setter == null) continue; // Get the value of the property Object obValue = getObjectValue(desc, attrs.item(i).getNodeValue()); if (obValue != null) { try { // Set the property value setter.invoke(ob, new Object[] {obValue}); } catch (InvocationTargetException exc) { throw new IOException( "Error setting property " + desc.getName() + ": " + exc.toString()); } catch (IllegalAccessException exc) { throw new IOException( "Error setting property " + desc.getName() + ": " + exc.toString()); } } return; } } int numNodes = nodes.getLength(); Vector arrayBuild = null; for (int i = 0; i < numNodes; i++) { Node node = nodes.item(i); // If this node isn't an element, skip it if (!(node instanceof Element)) continue; Element element = (Element) node; // See if the tag name matches the property name if (namesMatch(desc.getName(), element.getTagName())) { // Get the method used to set this property Method setter = desc.getWriteMethod(); // If this object has no setter, don't bother writing it if (setter == null) continue; // Get the value of the property Object obValue = getObjectValue(desc, element); // 070201 MAW: Modified from change submitted by Steve Poulson if (setter.getParameterTypes()[0].isArray()) { if (arrayBuild == null) { arrayBuild = new Vector(); } arrayBuild.addElement(obValue); // 070201 MAW: Go ahead and read through the rest of the nodes in case // another one matches the array. This has the effect of skipping // over the "return" statement down below continue; } if (obValue != null) { try { // Set the property value setter.invoke(ob, new Object[] {obValue}); } catch (InvocationTargetException exc) { throw new IOException( "Error setting property " + desc.getName() + ": " + exc.toString()); } catch (IllegalAccessException exc) { throw new IOException( "Error setting property " + desc.getName() + ": " + exc.toString()); } } return; } } // If we build a vector of array members, convert the vector into // an array and save it in the property if (arrayBuild != null) { // Get the method used to set this property Method setter = desc.getWriteMethod(); if (setter == null) return; Object[] obValues = (Object[]) Array.newInstance(desc.getPropertyType(), arrayBuild.size()); arrayBuild.copyInto(obValues); try { setter.invoke(ob, new Object[] {obValues}); } catch (InvocationTargetException exc) { throw new IOException("Error setting property " + desc.getName() + ": " + exc.toString()); } catch (IllegalAccessException exc) { throw new IOException("Error setting property " + desc.getName() + ": " + exc.toString()); } return; } }