[jboss-cvs] jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl ...

Max Rydahl Andersen mandersen at jboss.com
Thu Aug 10 03:01:51 EDT 2006


  User: mandersen
  Date: 06/08/10 03:01:51

  Modified:    hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl    
                        ExporterProperty.java ExporterDefinition.java
  Added:       hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl    
                        ExporterFactory.java
  Removed:     hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl    
                        ExporterInstance.java
  Log:
  customizing properties for exporter
  
  Revision  Changes    Path
  1.3       +7 -0      jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterProperty.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExporterProperty.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterProperty.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -b -r1.2 -r1.3
  --- ExporterProperty.java	7 Jul 2006 13:51:11 -0000	1.2
  +++ ExporterProperty.java	10 Aug 2006 07:01:51 -0000	1.3
  @@ -87,4 +87,11 @@
   	public void setRequired(boolean required) {
   		this.required = required;
   	}
  +	public String getDescriptionForLabel() {
  +		if(description==null) {
  +			return name;
  +		} else {
  +			return description + " [" + name + "]";
  +		}		
  +	}
   }
  \ No newline at end of file
  
  
  
  1.5       +40 -38    jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterDefinition.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ExporterDefinition.java
  ===================================================================
  RCS file: /cvsroot/jboss/jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterDefinition.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- ExporterDefinition.java	7 Jul 2006 13:51:11 -0000	1.4
  +++ ExporterDefinition.java	10 Aug 2006 07:01:51 -0000	1.5
  @@ -41,6 +41,7 @@
   package org.hibernate.eclipse.console.model.impl;
   
   import java.util.HashMap;
  +import java.util.Map;
   
   import org.eclipse.core.runtime.CoreException;
   import org.eclipse.core.runtime.IConfigurationElement;
  @@ -48,7 +49,9 @@
   import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
   import org.eclipse.jface.resource.ImageDescriptor;
   import org.eclipse.ui.plugin.AbstractUIPlugin;
  +import org.hibernate.console.HibernateConsoleRuntimeException;
   import org.hibernate.tool.hbm2x.Exporter;
  +import org.hibernate.util.ReflectHelper;
   
   public class ExporterDefinition {
   	final private String classname;
  @@ -57,27 +60,37 @@
   
   	final private String id;
   
  -	private ImageDescriptor iconDescriptor;
  +	final private ImageDescriptor iconDescriptor;
   
  -	private HashMap properties;
  +	final private Map properties;
   
   	public ExporterDefinition(IConfigurationElement element) {
  -		this.classname = element.getAttribute( "classname" );
  -		this.description = element.getAttribute( "description" );
  -		this.id = element.getAttribute( "id" );
  -		createIcon( element );
  -		createProperties( element );
  +		this(element.getAttribute( "classname" ),
  +			    element.getAttribute( "description" ),
  +				element.getAttribute( "id" ),
  +				createProperties( element ),
  +				createIcon( element ));			
  +	}
  +
  +	public ExporterDefinition(String className, String description, String id, Map properties, ImageDescriptor icon) {
  +		this.classname = className;
  +		this.description = description;
  +		this.id = id;
  +		this.properties = properties;
  +		this.iconDescriptor = icon;
   	}
   
  -	private void createIcon(IConfigurationElement element) {
  +	static private ImageDescriptor createIcon(IConfigurationElement element) {
   		if ( element.getAttribute( "icon" ) != null ) {
  -			this.iconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
  +			return AbstractUIPlugin.imageDescriptorFromPlugin(
   					element.getNamespace(), element.getAttribute( "icon" ) );
  +		} else {
  +			return null;
   		}
   	}
   
  -	private void createProperties(IConfigurationElement element) {
  -		properties = new HashMap();
  +	static private Map createProperties(IConfigurationElement element) {
  +		Map properties = new HashMap();
   
   		IConfigurationElement propertyElements[] = element
   				.getChildren( "property" );
  @@ -87,31 +100,25 @@
   				propertyElements[i].getAttribute("description"),
   				propertyElements[i].getAttribute("value"),
   				Boolean.valueOf(propertyElements[i].getAttribute("required")).booleanValue());
  -			properties.put(property, propertyElements[i].getAttribute("value"));
  +			properties.put(property.getName(),property);
   		}
  +		return properties;
   	}
   
   	public Exporter createExporterInstance() {
   	   Exporter exporter = null;
   
  -      try
  -      {
  -         Class exporterClass = Class.forName( classname );
  -         exporter = (Exporter) exporterClass.newInstance();
  -      }
  -      catch (ClassNotFoundException e)
  -      {
  -         e.printStackTrace();
  -      }
  -      catch (InstantiationException e)
  -      {
  -         e.printStackTrace();
  -      }
  -      catch (IllegalAccessException e)
  -      {
  -         e.printStackTrace();
  +	   try {
  +		   exporter = (Exporter) ReflectHelper.classForName( classname ).newInstance();
  +	   }
  +	   catch (InstantiationException e) {
  +		   throw new HibernateConsoleRuntimeException("Problem while creating exporter class " + classname);
  +	   }
  +	   catch (IllegalAccessException e) {
  +		   throw new HibernateConsoleRuntimeException("Problem while creating exporter class " + classname);	}
  +	   catch (ClassNotFoundException e) {
  +		   throw new HibernateConsoleRuntimeException("Problem while creating exporter class " + classname);
         }
  -
   
   		return exporter;
   	}
  @@ -124,7 +131,7 @@
   		return iconDescriptor;
   	}
   
  -	public HashMap getProperties() {
  +	public Map getProperties() {
   		return properties;
   	}
   
  @@ -143,11 +150,6 @@
   		return enabled;
   	}
   
  -	public void setEnabled(ILaunchConfigurationWorkingCopy configuration,
  -			boolean enabled) {
  -		configuration.setAttribute( id, enabled );
  -	}
  -
   	public String getId() {
   		return id;
   	}
  
  
  
  1.1      date: 2006/08/10 07:01:51;  author: mandersen;  state: Exp;jbosside/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/model/impl/ExporterFactory.java
  
  Index: ExporterFactory.java
  ===================================================================
  package org.hibernate.eclipse.console.model.impl;
  
  import java.util.HashMap;
  import java.util.Map;
  import java.util.Properties;
  
  import org.eclipse.core.runtime.CoreException;
  import org.eclipse.debug.core.ILaunchConfiguration;
  import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
  
  
  public class ExporterFactory {
  
  	private ExporterDefinition definition;
  
  	final Map inputProperties;
  
  	private boolean enabled = true;
  	
  	public ExporterFactory(ExporterDefinition definition) {
  		this.definition = definition;
  		inputProperties = new HashMap();
  	}
  
  	public Map getDefaultExporterProperties() {
  		return definition.getProperties();
  	}
  	
  
  	public String setProperty(String key, String value) {
  		return (String) inputProperties.put( key, value );		
  	}
  
  	public void removeProperty(String propertyName) {
  		inputProperties.remove( propertyName );
  	}
  
  	public String getPropertyValue(String key) {
  		if(inputProperties.containsKey( key )) {
  			return (String) inputProperties.get( key );
  		} else {
  			ExporterProperty ep = (ExporterProperty) definition.getProperties().get( key );
  			if(ep!=null) {
  				return ep.getDefaultValue();
  			} else {
  				return null;
  			}
  		} 
  	}
  
  	public boolean isEnabled() {
  		return enabled ;
  	}
  
  	public void setEnabled(boolean b) {
  		enabled = b;		
  	}
  
  	public ExporterDefinition getExporterDefinition() {
  		return definition;
  	}
  
  	public boolean isEnabled(ILaunchConfiguration configuration) {
  		boolean enabled = false;
  
  		try {
  			// if we put this in some "namespace" we should have a way to either
  			// migrate an existing one...
  			enabled = configuration.getAttribute( definition.getId(), false );
  		}
  		catch (CoreException e) {
  			e.printStackTrace(); // TODO-marshall: bad!
  		}
  
  		setEnabled( enabled );
  		return isEnabled();
  	}
  
  	public void setEnabled(ILaunchConfigurationWorkingCopy configuration, boolean enabled) {
  		setEnabled( enabled );
  		configuration.setAttribute( definition.getId(), isEnabled() );		
  	}
  
  	public Map getProperties() {
  		return inputProperties;
  	}
  
  	public String getId() {
  		return getExporterDefinition().getId(); // TODO: namespacing
  	}
  
  	public void setProperties(Map props) {
  		inputProperties.clear();
  		inputProperties.putAll( props );				
  	}
  
  	public ExporterProperty getExporterProperty(String key) {
  		return (ExporterProperty) definition.getProperties().get( key );
  	}
  
  	public boolean hasLocalValueFor(String string) {
  		return inputProperties.containsKey( string );
  	}
  
  }
  
  
  



More information about the jboss-cvs-commits mailing list