/**
 * Copyright 2004, 2005 The Apache Software Foundation or its licensors, as applicable
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package org.apache.geronimo.st.ui.commands;

import java.lang.reflect.Method;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.wst.server.core.IServerWorkingCopy;

/**
 * @version
 */
public class SetServerInstancePropertyCommand extends ServerCommand {
	
	Object value;
	Object oldValue;
	Class valueType;
	
	String setterName;
	String getterName;
	
	Class adapterClass;
	Object adaptedClass;

	public SetServerInstancePropertyCommand(IServerWorkingCopy server, Object value, String setterName, Class valueType, Class adapterClass) {
		super(server, value.toString());
		this.value = value;
		this.setterName = setterName;
		this.getterName = "get" + setterName.split("set")[1];
		this.valueType = valueType;
		this.adapterClass = adapterClass;
	}

	/* (non-Javadoc)
	 * @see org.apache.geronimo.st.ui.commands.ServerCommand#execute()
	 */
	public void execute() {
		adaptedClass = server.getAdapter(adapterClass);
		if (adaptedClass == null) {
			adaptedClass = server.loadAdapter(adapterClass, new NullProgressMonitor());
		}
		try {
			Method getterMethod = adaptedClass.getClass().getMethod(getterName, new Class[]{});
			oldValue = getterMethod.invoke(adaptedClass, new Object[]{});

			Method setterMethod = adaptedClass.getClass().getMethod(setterName, new Class[]{valueType});
			setterMethod.invoke(adaptedClass, new Object[]{value});
		} catch (Exception e) {
			//TODO Auto-generated catch block
			e.printStackTrace();
		} 
	}

	/* (non-Javadoc)
	 * @see org.apache.geronimo.st.ui.commands.ServerCommand#undo()
	 */
	public void undo() {
		if(adaptedClass != null) {
			try {
				Method setterMethod = adaptedClass.getClass().getMethod(setterName, new Class[]{String.class});
				setterMethod.invoke(adaptedClass, new Object[]{oldValue});
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} 
		}
	}

}

@@ -4,30 +4,21 @@
 %0A * 
-Copyright 2004, 2005 T
+Licensed to t
 he A
@@ -47,55 +47,212 @@
 ion 
-or its licensors, as applicable%0A *%0A *  Licensed
+(ASF) under one or more%0A * contributor license agreements.  See the NOTICE file distributed with%0A * this work for additional information regarding copyright ownership.%0A * The ASF licenses this file to You
  und
@@ -285,16 +285,19 @@
 sion 2.0
+%0A *
  (the %22L
@@ -305,20 +305,16 @@
 cense%22);
-%0A * 
  you may
@@ -357,16 +357,19 @@
 nce with
+%0A *
  the Lic
@@ -373,19 +373,16 @@
 License.
-%0A *
   You ma
@@ -420,17 +420,16 @@
 at%0A *%0A *
- 
     http
@@ -472,17 +472,16 @@
 .0%0A *%0A *
- 
  Unless 
@@ -543,17 +543,16 @@
 tware%0A *
- 
  distrib
@@ -612,17 +612,16 @@
 ASIS,%0A *
- 
  WITHOUT
@@ -688,17 +688,16 @@
 lied.%0A *
- 
  See the
@@ -759,17 +759,16 @@
 s and%0A *
- 
  limitat

fix license