/*
* Copyright 2004 The Apache Software Foundation.
*
* 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.
*
* $Header:$
*/
package org.apache.beehive.netui.compiler.model;
import org.w3c.dom.Node;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlCursor;
import java.util.HashMap;
/**
* Defines general support for elements that
*/
public abstract class StrutsElementSupport
{
private String _description;
private HashMap _properties = new HashMap();
private String _displayName;
private Icon _icon;
private StrutsApp _parentApp;
private String _comment;
private String _className;
public StrutsElementSupport( StrutsApp parentApp )
{
_parentApp = parentApp;
}
protected StrutsApp getParentApp()
{
return _parentApp;
}
public void setDescription( String description )
{ _description = description; }
public String getDescription()
{ return _description; }
public void setProperty( String name, String value )
{ _properties.put( name, value ); }
public String getProperty( String name )
{ return ( String ) _properties.get( name ); }
public void setDisplayName( String displayName )
{ _displayName = displayName; }
public String getDisplayName()
{ return _displayName; }
public void setIcon( Icon icon )
{ _icon = icon; }
public Icon getIcon()
{ return _icon; }
public String getClassName()
{
return _className;
}
public void setClassName( String className )
{
_className = className;
}
public void setComment( String comment )
{
_comment = comment;
}
public String getComment()
{
return _comment;
}
class Icon
{
String smallIconLocation;
String largeIconLocation;
/**
* Creates an object representing icon locations for certain types of
* elements in the struts-config.xml file.
* @param smallIconLocation the location of a small icon
* relative to the stuts config file
*/
public Icon( String smallIconLocation )
{
this( smallIconLocation, null );
}
/**
* Creates an object representing icon locations for certain types of
* elements in the struts-config.xml file.
* @param smallIconLocation the location of a small icon
* relative to the stuts config file
* @param largeIconLocation the location of a large (32x32) icon
* relative to the stuts-config.xml file.
*/
public Icon( String smallIconLocation, String largeIconLocation )
{
this.smallIconLocation = smallIconLocation;
this.largeIconLocation = largeIconLocation;
}
}
public static String getAttr( Node node, String name )
{
Node attr = node.getAttributes().getNamedItem( name );
return ( attr != null ? attr.getNodeValue() : null );
}
public static boolean getAttrBool( Node node, String name )
{
String val = getAttr( node, name );
return ( val != null && val.equalsIgnoreCase( "true" ) ); // NOI18N
}
protected void addComment( XmlObject xb )
{
if ( _comment != null )
{
XmlCursor curs = xb.newCursor();
curs.insertComment( " " + _comment + " " );
}
}
protected void setParentApp( StrutsApp parentApp )
{
_parentApp = parentApp;
}
}