⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xerces2regpopulator.java

📁 JavaPOS的最新版本!这是源代码!零售业的请看!
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
     * @author E. Michael Maximilien
     */
    protected class JposContentHandler extends DefaultHandler 
    									 implements ContentHandler
    {
	    //----------------------------------------------------------------------
	    // Public methods
	    //
	    
	    public void startDocument() throws SAXException
	    {
	    	tracer.println( "<startDocument/>" );
	    }

	    public void endDocument() throws SAXException
	    {
	    	tracer.println( "<endDocument/>" );
	    }
	    
		public void startElement( String namespaceUri, String localName, 
	                               String qName, Attributes attributes ) 
	                 throws SAXException
	    {
	    	tracer.println( "<startElement qName=\"" + qName + "\"/>" );

	    	if( qName.equals( "JposEntries" ) )
	    	{
 				jposEntryList.clear();    	
	    		currentEntry = null;
	    	}
	    	else	    	
	    	if( qName.equals( "JposEntry" ) )
	    		currentEntry = createEntry( attributes );
	    	else
	    	if( qName.equals( "creation" ) )
	    		addCreationProp( currentEntry, attributes );
	    	else
	    	if( qName.equals( "vendor" ) )
	    		addVendorProp( currentEntry, attributes );
	    	else
	    	if( qName.equals( "jpos" ) )
	    		addJposProp( currentEntry, attributes );
	    	else
	    	if( qName.equals( "product" ) )
	    		addProductProp( currentEntry, attributes );
	    	else
	    	if( qName.equals( "prop" ) )
	    		addProp( currentEntry, attributes );
	    	else
	    	{
	    		tracer.println( "Invalid qName=" + qName );
	    		throw new SAXException( "Invalid qName=" + qName );
	    	}

	    }

	    public void endElement( String namespaceUri, String localName, 
	                             String qName ) throws SAXException
	    {
	    	tracer.println( "<endElement qName=\"" + qName + "\"/>" );
	    	
	    	if( qName.equals( "JposEntry" ) )
	    		jposEntryList.add( currentEntry );
	    }

	    //----------------------------------------------------------------------
	    // Protected methods
	    //

	    protected JposEntry createEntry( Attributes attributes )
	    throws SAXException
	    {
	    	String logicalName = attributes.getValue( "logicalName" );
	    	
	    	return new SimpleEntry( logicalName, Xerces2RegPopulator.this );
	    }
	    
	    protected void addCreationProp( JposEntry entry, 
	    								  Attributes attributes )
		throws SAXException
		{
			String factoryClass = attributes.getValue( "factoryClass" );
			String serviceClass = attributes.getValue( "serviceClass" );

			//TODO: Check values
			
			currentEntry.addProperty( JposEntry.SI_FACTORY_CLASS_PROP_NAME, 
									  factoryClass );
			currentEntry.addProperty( JposEntry.SERVICE_CLASS_PROP_NAME, 
									  serviceClass );
		}	    								
		
		protected void addVendorProp( JposEntry entry, 
	    								Attributes attributes )
		throws SAXException
		{
			String factoryClass = attributes.getValue( "name" );
			String serviceClass = attributes.getValue( "url" );

			//TODO: Check values
			
			currentEntry.addProperty( JposEntry.VENDOR_NAME_PROP_NAME, 
									  factoryClass );
									  
			currentEntry.addProperty( JposEntry.VENDOR_URL_PROP_NAME, 
									  serviceClass );			
		}	    								
		
	    protected void addJposProp( JposEntry entry, 
	    							  Attributes attributes ) 
	 	throws SAXException
		{
			String category = attributes.getValue( "category" );
			String version = attributes.getValue( "version" );
			
			//TODO: Check values
			
			currentEntry.addProperty( JposEntry.DEVICE_CATEGORY_PROP_NAME,
									  category );
									  
			currentEntry.addProperty( JposEntry.JPOS_VERSION_PROP_NAME, 
									  version );						
		}
			    								
	    protected void addProductProp( JposEntry entry, 
	    								 Attributes attributes )
		throws SAXException
		{
			String description = attributes.getValue( "description" );
			String name = attributes.getValue( "name" );
			String url = attributes.getValue( "url" );
			
			//TODO: Check values
			
			currentEntry.addProperty( JposEntry.PRODUCT_DESCRIPTION_PROP_NAME,
									  description );
									  
			currentEntry.addProperty( JposEntry.PRODUCT_NAME_PROP_NAME,
									  name );						
			
			currentEntry.addProperty( JposEntry.PRODUCT_URL_PROP_NAME,
						  			  url );						
		}
			    								
	    protected void addProp( JposEntry entry, 
	    					      Attributes attributes )
		throws SAXException
		{
			String name = attributes.getValue( "name" );
			String valueString = attributes.getValue( "value" );
			String typeString = attributes.getValue( "type" );
			
			if( typeString == null || typeString.equals( "" ) )
				typeString = "String";

			try
			{
			
				Class typeClass = JposEntryUtility.
				propTypeFromString( attributes.getValue( "type" ) );
				
				Object value = JposEntryUtility.parsePropValue( valueString, typeClass );
				
				//TODO: Check values
			
				JposEntry.Prop prop = currentEntry.
									  createProp( name, value, typeClass );										      
				currentEntry.add( prop );
			}
			catch( JposConfigException jce )
			{
				String msg = "Invalid prop: name=" + name + ":value=" + 
							 valueString;
				tracer.println( msg );
				throw new SAXException( msg );
			}
		}	    								
	    
	    //----------------------------------------------------------------------
	    // Instance variables
	    //

		private JposEntry currentEntry = null;	    
    }
    
    /**
     * JposEntityResolver to resolve XML schema
     * @author E. Michael Maximilien
     * @version 2.1.0
     */
	public class JposEntityResolver implements EntityResolver 
	{
		/**
		 * @return the XML schema as an InputSource if it is found in a JAR
		 * file in the CLASSPATH otherwise
		 * return null
		 */
		public InputSource resolveEntity( String publicId, String systemId )
   		{
   			tracer.println( "JposEntityResolver:resolveEntity:publicId=" + 
   							publicId );
   							   			
   			tracer.println( "JposEntityResolver:resolveEntity:systemId=" + 
   							systemId );
   		
   			if( publicId.equals( getDoctypeValue() ) )
   			{
				InputStream is = 
				getClass().getResourceAsStream( getDoctypeValue() );
			
				if( is != null ) 
					return new InputSource( new InputStreamReader( is ) );
   			}
   			
   			return null;
     	}
   }
    
    /**
     * SAX XML Handler interface
     * @author E. Michael Maximilien
     */
    protected class JposErrorHandler extends Object implements ErrorHandler
    {
	    //----------------------------------------------------------------------
	    // Private/protected methods
	    //
	    
	    private String createMessage( String header, SAXParseException spe )
	    {
			return header + "parsing XML file:SAXParseException.message = " + 
	    	        spe.getMessage();
	    }
	    
	    //----------------------------------------------------------------------
	    // Public methods
	    //
	    
	    public void error( SAXParseException spe ) throws SAXException
	    {
	    	String message = createMessage( "JposErrorHandler:Error:", spe );
			tracer.print( message );
			
			throw new SAXException( message );	    	
	    }
	    
	    public void fatalError( SAXParseException spe ) throws SAXException
	    {
	    	String message = createMessage( "JposErrorHandler:FatalError:", spe );
			tracer.print( message );
			
			throw new SAXException( message );	    	
	    }
	    
	    public void warning( SAXParseException spe ) throws SAXException
	    {
	    	String message = createMessage( "JposErrorHandler:Warning:", spe );
			tracer.print( message );
			
			throw new SAXException( message );	    	
	    }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -