📄 modelbinding.java
字号:
/*******************************************************************************
* Copyright (c) 2004 Stefan Zeiger and others.
* 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.novocode.com/legal/epl-v10.html
*
* Contributors:
* Stefan Zeiger (szeiger@novocode.com) - initial API and implementation
*******************************************************************************/
package com.novocode.naf.data;
import java.util.*;
import java.util.Map;
import org.w3c.dom.*;
import com.novocode.naf.app.NAFException;
/**
* A model binding with parameters.
*
* @author Stefan Zeiger (szeiger@novocode.com)
* @since Jan 29, 2004
*/
public final class ModelBinding
{
public enum Create { DEFAULT, NO, WIDGET };
public final String id;
public final String type;
public final Create create;
public final boolean persist;
public final int widgetListIdx;
private Map<String, String> attributes;
public ModelBinding(Element modelE, int idx) throws NAFException
{
widgetListIdx = idx;
id = modelE.getAttribute("id");
if(id.length() == 0) throw new NAFException("No model ID given for a model binding");
create = DataDecoder.decodeEnum(modelE.getAttributeNode("create"), Create.class, Create.DEFAULT);
type = modelE.getAttribute("type");
if(type.length() == 0) throw new NAFException("No model type given for a model binding");
persist = DataDecoder.decodeBoolean(modelE.getAttributeNode("persist"), false);
NamedNodeMap attrs = modelE.getAttributes();
if(attrs != null)
{
int attrsLength = attrs.getLength();
for(int i=0; i<attrsLength; i++)
{
Node attrN = attrs.item(i);
String aname = attrN.getLocalName();
String avalue = attrN.getNodeValue();
//System.out.println(attrN.getLocalName()+" = "+attrN.getNodeValue());
if(!"id".equals(aname) && !"type".equals(aname))
{
if(attributes == null) attributes = new HashMap<String, String>();
attributes.put(aname, avalue);
}
}
}
}
public ModelBinding(Attr modelA) throws NAFException
{
id = modelA.getValue();
if(id.length() == 0) throw new NAFException("No model ID given for a model binding");
type = modelA.getName().substring(2);
if(type.length() == 0) throw new NAFException("No model type given for a model binding");
widgetListIdx = 0;
create = Create.DEFAULT;
persist = false;
}
public String getAttribute(String key)
{
if(attributes == null) return null;
else return attributes.get(key);
}
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append("[ModelBinding: type="+type+" id="+id+" create="+create+" persist="+persist+" widgetListIdx="+widgetListIdx);
if(attributes != null)
{
for(Map.Entry<String, String> me : attributes.entrySet())
sb.append(' ').append(me.getKey()).append('=').append(me.getValue());
}
sb.append(']');
return sb.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -