/* File: AccessLevelBeanInfo.java * Copyright (C) 2002-2003 The University of Iowa * Created by: Jeremy Faden * Jessica Swanner * Edward E. West * * This file is part of the das2 library. * * das2 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package org.das2.beans; import org.das2.DasApplication; import java.beans.*; import java.util.ArrayList; import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; import org.das2.util.LoggerManager; /** * This class is designed to implement access levels for bean properties. * The system property "edu.uiowa.physics.das.beans.AccessLevelBeanInfo.AccessLevel" will * determine the access level of the bean. The access levels that are currently supported * are "ALL" and "END_USER". The access level must be set prior to this class being loaded. * * @author Edward West */ public abstract class AccessLevelBeanInfo extends SimpleBeanInfo { private static final Logger logger= LoggerManager.getLogger("das2.system"); /** * Type-safe enumeration class used to specify access levels * for bean properties. * * **NOTE TO DEVELOPERS** * The order parameter for the constructor should not be specified as a negative number */ public static class AccessLevel implements Comparable { public static final AccessLevel ALL = new AccessLevel("ALL", 0); public static final AccessLevel DASML = new AccessLevel("DASML", 1000); public static final AccessLevel END_USER = new AccessLevel("END_USER", 0x7FFF0000); private String str; private int order; private AccessLevel(String str, int order) { this.str = str; this.order = order; } public int compareTo(Object o) { return order - ((AccessLevel)o).order; } @Override public boolean equals(Object o) { if ( !( o instanceof AccessLevel ) ) return false; return order==((AccessLevel)o).order; } @Override public int hashCode() { return this.order; } @Override public String toString() { return str; } } /** * this level indicates what persistence is allowed. */ public static class PersistenceLevel implements Comparable { public static final PersistenceLevel NONE = new PersistenceLevel( "NONE", 0); public static final PersistenceLevel TRANSIENT = new PersistenceLevel( "TRANSIENT", 1000 ); public static final PersistenceLevel PERSISTENT = new PersistenceLevel( "PERSISTENT", 2000); private String str; private int order; private PersistenceLevel(String str, int order) { this.str = str; this.order = order; } public int compareTo(Object o) { return order - ((PersistenceLevel)o).order; } @Override public boolean equals(Object o) { if ( !( o instanceof PersistenceLevel ) ) return false; return order==((PersistenceLevel)o).order; } @Override public int hashCode() { return this.order; } @Override public String toString() { return str; } } private Property[] properties; private Class beanClass; private static AccessLevel accessLevel; private static final Object lockObject = new Object(); static { String level = DasApplication.getProperty("edu.uiowa.physics.das.beans.AccessLevelBeanInfo.AccessLevel",null); if (level==null) { accessLevel = AccessLevel.ALL; } else if (level.equals("ALL")) { accessLevel = AccessLevel.ALL; } else if (level.equals("DASML")) { accessLevel = AccessLevel.DASML; } else if (level.equals("END_USER")) { accessLevel = AccessLevel.END_USER; } else { accessLevel = AccessLevel.ALL; } } /** * Returns the access level for AccessLevelBeanInfo objects. */ public static AccessLevel getAccessLevel() { return accessLevel; } /** * Sets the access level for AccessLevelBeanInfo objects. */ public static void setAccessLevel(AccessLevel level) { synchronized (lockObject) { accessLevel = level; } } public static Object getLock() { return lockObject; } /** * Creates and instance of AccessLevelBeanInfo. * Each element of the properties array must be of the type * Object[] with the following format: * { propertyName, accessorMethod, mutatorMethod, accessLevel} * where the elements have the following meaning. *
    *
  • propertyName - A String naming the property being specified.
  • *
  • accessorMethod - A String specifying the name of the read method * for this property.
  • *
  • mutatorMethod - A String specifying the name of the write method * for this property
  • *
  • accessLevel - A org.das2.beans.AccessLevelBeanInfo.AccessLevel instance specifying * the access level for this property.
  • *
*/ protected AccessLevelBeanInfo(Property[] properties, Class beanClass) { this.properties = properties; this.beanClass = beanClass; } /** * convenient method that only returns the descriptors for the specified persistence level. * Also implements the property inheritance. */ public PropertyDescriptor[] getPropertyDescriptors( PersistenceLevel persistenceLevel ) { synchronized (lockObject) { try { ArrayList result= new ArrayList(); for (int index = 0; index < properties.length; index++) { if (persistenceLevel.compareTo(properties[index].getPersistenceLevel()) <= 0) { result.add( properties[index].getPropertyDescriptor(beanClass) ); } } BeanInfo[] moreBeanInfos= getAdditionalBeanInfo() ; if ( moreBeanInfos!=null ) { for ( int i=0; i0) { for ( int i=0; i