⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modelpropertymanager.java

📁 Novocode的 SWT 控件框架 丰富了MDI功能
💻 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.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashMap;

import com.novocode.naf.LogSettings;
import com.novocode.naf.app.NAFException;


/**
 * An extension of the default XMLPropertyManager which can also handle
 * model properties.
 *
 * @author Stefan Zeiger (szeiger@novocode.com)
 * @since Dec 18, 2004
 * @version $Id: ModelPropertyManager.java,v 1.1 2004/12/19 00:11:19 szeiger Exp $
 */

public class ModelPropertyManager extends XMLPropertyManager
{
  private static final HashMap<Class, ModelPropertyManager> modelPropertyManagers = new HashMap<Class, ModelPropertyManager>();

  private final HashMap<String, ModelPropertyDescriptor> modelProperties = new HashMap<String, ModelPropertyDescriptor>();


  public static ModelPropertyManager forClass(Class clazz) throws NAFException
  {
    ModelPropertyManager xpm = modelPropertyManagers.get(clazz);
    if(xpm == null)
    {
      try
      {
        xpm = new ModelPropertyManager(clazz);
        xpm.init();
      }
      catch(IntrospectionException ex) { throw new NAFException("Error introspecting "+clazz.getName()+" for XML properties", ex); }
      modelPropertyManagers.put(clazz, xpm);
    }
    return xpm;
  }

  
  protected ModelPropertyManager(Class clazz)
  {
    super(clazz);
  }


  protected void handleProperty(PropertyDescriptor pd)
  {
    super.handleProperty(pd);

    Method wm = pd.getWriteMethod();
    if(wm == null) return;
    ModelProperty p = wm.getAnnotation(ModelProperty.class);
    if(p != null)
    {
      if(LogSettings.MODELPROPERTYMANAGER_DEBUG_STDOUT)
        System.out.println("Found ModelProperty in "+clazz.getName()+" for property "+pd.getName());
      ModelPropertyDescriptor mp = new ModelPropertyDescriptor(pd, p);
      modelProperties.put(mp.getXMLPropertyName(), mp);
    }
  }


  public Collection<ModelPropertyDescriptor> getModelPropertyDescriptors()
  {
    return modelProperties.values();
  }
  
  
  public ModelPropertyDescriptor getModelPropertyDescriptor(String name)
  {
    return modelProperties.get(name);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -