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

📄 xmlpropertymanager.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.Introspector;
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;


/**
 * Manages the set of XML properties for a class.
 *
 * @author Stefan Zeiger (szeiger@novocode.com)
 * @since Dec 8, 2004
 * @version $Id: XMLPropertyManager.java,v 1.7 2004/12/19 00:11:20 szeiger Exp $
 */

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

  private final HashMap<String, XMLPropertyDescriptor> properties = new HashMap<String, XMLPropertyDescriptor>();
  
  protected final Class clazz;
  

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


  protected XMLPropertyManager(Class<?> clazz)
  {
    this.clazz = clazz;
  }
  
  
  protected final void init() throws IntrospectionException
  {
    for(PropertyDescriptor pd : Introspector.getBeanInfo(clazz).getPropertyDescriptors())
    {
      handleProperty(pd);
    }
  }
  
  
  protected void handleProperty(PropertyDescriptor pd)
  {
    Method wm = pd.getWriteMethod();
    if(wm == null) return;
    XMLProperty p = wm.getAnnotation(XMLProperty.class);
    if(p != null)
    {
      if(LogSettings.XMLPROPERTYMANAGER_DEBUG_STDOUT)
        System.out.println("Found XMLProperty in "+clazz.getName()+" for property "+pd.getName());
      XMLPropertyDescriptor mp = new XMLPropertyDescriptor(pd, p);
      properties.put(mp.getXMLPropertyName(), mp);
    }
  }
  
  
  public Collection<XMLPropertyDescriptor> getXMLPropertyDescriptors()
  {
    return properties.values();
  }


  public XMLPropertyDescriptor getXMLPropertyDescriptor(String name)
  {
    return properties.get(name);
  }
}

⌨️ 快捷键说明

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