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

📄 simplepropertybeangenerator.java

📁 c3p0数据库连接池实现源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	iw.println("{ pcs.removePropertyChangeListener( propName, pcl ); }");	iw.println();	if (java_version >= 140)	    {		iw.println("public PropertyChangeListener[] getPropertyChangeListeners()");		iw.println("{ return pcs.getPropertyChangeListeners(); }");	    }    }    protected void writeJavaBeansChangeSupport() throws IOException    {	if ( boundProperties() )	    {		iw.println("protected PropertyChangeSupport pcs = new PropertyChangeSupport( this );");		iw.println();		iw.println("protected PropertyChangeSupport getPropertyChangeSupport()");		iw.println("{ return pcs; }");			    }	if ( constrainedProperties() )	    {		iw.println("protected VetoableChangeSupport vcs = new VetoableChangeSupport( this );");		iw.println();		iw.println("protected VetoableChangeSupport getVetoableChangeSupport()");		iw.println("{ return vcs; }");	    }    }    protected void writeOtherVariables() throws IOException //hook method for subclasses    {}    protected void writeOtherFunctions() throws IOException //hook method for subclasses    {}    protected void writeOtherClasses() throws IOException //hook method for subclasses    {}    protected void writePropertyVariables() throws IOException    {	for (int i = 0, len = props.length; i < len; ++i)	    writePropertyVariable( props[i] );    }    protected void writePropertyVariable( Property prop ) throws IOException    {	BeangenUtils.writePropertyVariable( prop, iw );// 	iw.print( CodegenUtils.getModifierString( prop.getVariableModifiers() ) );// 	iw.print( ' ' + prop.getSimpleTypeName() + ' ' + prop.getName());// 	String dflt = prop.getDefaultValueExpression();// 	if (dflt != null)// 	    iw.print( " = " + dflt );// 	iw.println(';');    }    /**     * @deprecated     */    protected void writePropertyMembers() throws IOException     { throw new InternalError("writePropertyMembers() deprecated and removed. please us writePropertyVariables()."); }    /**     * @deprecated     */    protected void writePropertyMember( Property prop ) throws IOException    { throw new InternalError("writePropertyMember() deprecated and removed. please us writePropertyVariable()."); }    protected void writeGetterSetterPairs() throws IOException    {	for (int i = 0, len = props.length; i < len; ++i)	    {		writeGetterSetterPair( props[i], propertyTypes[i] );		if ( i != len - 1) iw.println();	    }    }    protected void writeGetterSetterPair( Property prop, Class propType ) throws IOException    {	writePropertyGetter( prop, propType );		if (! prop.isReadOnly() && ! force_unmodifiable)	    {		iw.println();		writePropertySetter( prop, propType );	    }    }    protected void writePropertyGetter( Property prop, Class propType ) throws IOException    { 	BeangenUtils.writePropertyGetter( prop, this.getGetterDefensiveCopyExpression( prop, propType ), iw );// 	String pfx = ("boolean".equals( prop.getSimpleTypeName() ) ? "is" : "get" );// 	iw.print( CodegenUtils.getModifierString( prop.getGetterModifiers() ) );// 	iw.println(' ' + prop.getSimpleTypeName() + ' ' + pfx + BeangenUtils.capitalize( prop.getName() ) + "()");// 	String retVal = getGetterDefensiveCopyExpression( prop, propType );// 	if (retVal == null) retVal = prop.getName();// 	iw.println("{ return " + retVal + "; }");    }//     boolean changeMarked( Property prop )//     { return prop.isBound() || prop.isConstrained(); }    protected void writePropertySetter( Property prop, Class propType ) throws IOException    {	BeangenUtils.writePropertySetter( prop, this.getSetterDefensiveCopyExpression( prop, propType ), iw );// 	iw.print( CodegenUtils.getModifierString( prop.getSetterModifiers() ) );// 	iw.print(" void set" + BeangenUtils.capitalize( prop.getName() ) + "( " + prop.getSimpleTypeName() + ' ' + prop.getName() + " )");// 	if ( prop.isConstrained() )// 	    iw.println(" throws PropertyVetoException");// 	else// 	    iw.println();// 	String setVal = getSetterDefensiveCopyExpression( prop, propType );// 	if (setVal == null) setVal = prop.getName();// 	iw.println('{');// 	iw.upIndent();// 	if ( changeMarked( prop ) )// 	    {// 		iw.println( prop.getSimpleTypeName() + " oldVal = this." + prop.getName() + ';');// 		String oldValExpr = "oldVal";// 		String newValExpr = prop.getName();// 		String changeCheck;// 		if ( propType != null && propType.isPrimitive() ) //sometimes the type can't be resolved. if so, it ain't primitive.// 		    {// 			// PropertyChange support already has overrides// 			// for boolean and int // 			if (propType == byte.class)// 			    {// 				oldValExpr  = "new Byte( "+ oldValExpr +" )";// 				newValExpr  = "new Byte( "+ newValExpr +" )";// 			    }// 			else if (propType == char.class)// 			    {// 				oldValExpr  = "new Character( "+ oldValExpr +" )";// 				newValExpr  = "new Character( "+ newValExpr +" )";// 			    }// 			else if (propType == short.class)// 			    {// 				oldValExpr  = "new Short( "+ oldValExpr +" )";// 				newValExpr  = "new Short( "+ newValExpr +" )";// 			    }// 			else if (propType == float.class)// 			    {// 				oldValExpr  = "new Float( "+ oldValExpr +" )";// 				newValExpr  = "new Float( "+ newValExpr +" )";// 			    }// 			else if (propType == double.class)// 			    {// 				oldValExpr  = "new Double( "+ oldValExpr +" )";// 				newValExpr  = "new Double( "+ newValExpr +" )";// 			    }// 			changeCheck = "oldVal != " + prop.getName();// 		    }// 		else// 		    changeCheck = "! eqOrBothNull( oldVal, " + prop.getName() + " )";			// 		if ( prop.isConstrained() )// 		    {// 			iw.println("if ( " + changeCheck + " )");// 			iw.upIndent();// 			iw.println("vcs.fireVetoableChange( \"" + prop.getName() + "\", " + oldValExpr + ", " + newValExpr + " );");// 			iw.downIndent();// 		    }// 		iw.println("this." + prop.getName() + " = " + setVal + ';');				// 		if ( prop.isBound() )// 		    {// 			iw.println("if ( " + changeCheck + " )");// 			iw.upIndent();// 			iw.println("pcs.firePropertyChange( \"" + prop.getName() + "\", " + oldValExpr + ", " + newValExpr + " );");// 			iw.downIndent();// 		    }// 	    }// 	else// 	    	iw.println("this." + prop.getName() + " = " + setVal + ';');// 	iw.downIndent();// 	iw.println('}');    }    protected String getGetterDefensiveCopyExpression( Property prop, Class propType )    { return prop.getDefensiveCopyExpression(); }        protected String getSetterDefensiveCopyExpression( Property prop, Class propType )    { return prop.getDefensiveCopyExpression(); }        protected String getConstructorDefensiveCopyExpression( Property prop, Class propType )    { return prop.getDefensiveCopyExpression(); }    protected void writeHeader() throws IOException    {	writeBannerComments();	iw.println();	iw.println("package " + info.getPackageName() + ';');	iw.println();	writeImports();    }    protected void writeBannerComments() throws IOException    {	iw.println("/*");	iw.println(" * This class autogenerated by " + generatorName + '.');	iw.println(" * DO NOT HAND EDIT!");	iw.println(" */");    }    protected void writeImports() throws IOException    {	for ( Iterator ii = generalImports.iterator(); ii.hasNext(); )	    iw.println("import " + ii.next() + ".*;");	for ( Iterator ii = specificImports.iterator(); ii.hasNext(); )	    iw.println("import " + ii.next() + ";");    }    protected void writeClassDeclaration() throws IOException    {	iw.print( CodegenUtils.getModifierString( info.getModifiers() ) + " class " + info.getClassName() );	String superclassName = info.getSuperclassName();	if (superclassName != null)	    iw.print( " extends " + superclassName );	if (interfaceNames.size() > 0)	    {		iw.print(" implements ");		boolean first = true;		for (Iterator ii = interfaceNames.iterator(); ii.hasNext(); )		    {			if (first) 			    first = false;			else			    iw.print(", ");							iw.print( (String) ii.next() );		    }	    }	iw.println();    }    boolean boundProperties()    {	for (int i = 0, len = props.length; i < len; ++i)	    if (props[i].isBound()) return true;	return false;    }    boolean constrainedProperties()    {	for (int i = 0, len = props.length; i < len; ++i)	    if (props[i].isConstrained()) return true;	return false;    }    public static void main( String[] argv )    {	try	    {		ClassInfo info = new SimpleClassInfo("test",						     Modifier.PUBLIC,						     argv[0],						     null,						     null,						     new String[] {"java.awt"},						     null);				Property[] props = 		    {			new SimpleProperty( "number",					    "int",					    null,					    "7",					    false,					    true,					    false					    ),			new SimpleProperty( "fpNumber",					    "float",					    null,					    null,					    true,					    true,					    false					    ),			new SimpleProperty( "location",					    "Point",					    "new Point( location.x, location.y )",					    "new Point( 0, 0 )",					    false,					    true,					    true					    )		    };		FileWriter fw = new FileWriter( argv[0] + ".java" );		SimplePropertyBeanGenerator g = new SimplePropertyBeanGenerator();		g.addExtension( new SerializableExtension() );		g.generate(info, props, fw );		fw.flush();		fw.close();	    }	catch ( Exception e )	    { e.printStackTrace(); }    }}

⌨️ 快捷键说明

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