blob: 0b0e8c1f6d27ea71732301b3bc0eb281f4a90981 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2002-2006 Innoopract Informationssysteme GmbH.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Innoopract Informationssysteme GmbH - initial API and implementation
******************************************************************************/
package org.eclipse.swt.lifecycle;
import com.w4t.ParamCheck;
import com.w4t.engine.service.ContextProvider;
import com.w4t.engine.service.IServiceStateInfo;
/**
* TODO [rh] JavaDoc
*/
public final class JSVar {
private static final String UNIQUE_NUMBER
= JSVar.class.getName() + "#uniqueNumber";
private final String name;
public JSVar() {
name = uniqueVarName();
}
public JSVar( final String name ) {
ParamCheck.notNull( name, "name" );
if( name.length() == 0 ) {
String msg = "The argument 'name' must not be empty.";
throw new IllegalArgumentException( msg );
}
this.name = name;
}
public String toString() {
return name;
}
private static String uniqueVarName() {
IServiceStateInfo stateInfo = ContextProvider.getStateInfo();
Object attribute = stateInfo.getAttribute( UNIQUE_NUMBER );
Integer lastUniqueNumber = ( Integer )attribute;
if( lastUniqueNumber == null ) {
lastUniqueNumber = new Integer( -1 );
}
int uniqueNumber = lastUniqueNumber.intValue() + 1;
stateInfo.setAttribute( UNIQUE_NUMBER, new Integer( uniqueNumber ) );
return "v" + uniqueNumber;
}
}