scolebourne 2002/10/27 14:45:24
Added: clazz/src/java/org/apache/commons/clazz MetaUnit.java
MetaProperty.java Bean.java MetaOperation.java
Unit.java Property.java MetaBean.java
Operation.java MetaModifiers.java
Log:
Initial checkin so there's something to talk about
Revision Changes Path
1.1
jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/MetaUnit.java
Index: MetaUnit.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz;
import java.util.Map;
/**
* <code>MetaUnit</code> defines behaviour common across all meta classes.
*
* @author <a href="mailto:scolebourne@;apache.org">Stephen Colebourne</a>
* @version $Id: MetaUnit.java,v 1.1 2002/10/27 22:45:24 scolebourne Exp $
*/
public interface MetaUnit {
/**
* Gets the name of the unit.
*
* @return the unit's name
*/
public String getName();
/**
* Gets the modifiers object.
*
* @return the modifiers object
*/
public MetaModifiers getModifiers();
//--------------------------------------------------------------------------
/**
* Get the Map of string to string attributes.
*
* @return string/string attribute Map
*/
Map getAttributeMap();
/**
* Get the count of attributes.
* This should be checked rather than getAttributes().size() to
* allow for lazily instantiated attribute maps.
*
* @return the number of attributes
*/
int getAttributeCount();
/**
* Get an attribute by key.
*
* @param key the key to get
* @return attribute value by key, null if not found
*/
String getAttribute(String key);
/**
* Set an attribute key and value.
*
* @param key the key to set
* @param value the value to set
*/
void setAttribute(String key, String value);
}
1.1
jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/MetaProperty.java
Index: MetaProperty.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz;
/**
* <code>MetaProperty</code> defines a field in a Java class.
*
* @author <a href="mailto:scolebourne@;apache.org">Stephen Colebourne</a>
* @version $Id: MetaProperty.java,v 1.1 2002/10/27 22:45:24 scolebourne Exp $
*/
public interface MetaProperty extends MetaUnit {
/**
* Gets the meta bean that this meta property is contained in.
*
* @return the owning meta bean
*/
public MetaBean getMetaBean();
/**
* Gets the type of the property.
*
* @return the type of the property
*/
public MetaBean getType();
/**
* Gets the type of the item if a List, Array or Map.
*
* @return the type of the item
*/
public MetaBean getContentType();
/**
* Gets the type of the key if a Map.
*
* @return the type of the key
*/
public MetaBean getKeyType();
}
1.1
jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/Bean.java
Index: Bean.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz;
import java.util.Map;
/**
* <code>Bean</code> is an interface that should be implemented by beans, or
* classes that can make themselves appear to be beans.
*
* @author <a href="mailto:scolebourne@;apache.org">Stephen Colebourne</a>
* @version $Id: Bean.java,v 1.1 2002/10/27 22:45:24 scolebourne Exp $
*/
public interface Bean extends Unit {
/**
* Gets the MetaBean for the bean.
*
* @return the meta bean for the bean
*/
public String getMetaBean();
//--------------------------------------------------------------------------
/**
* Get the properties of the bean.
*
* @return map of Property objects
*/
public Map getPropertyMap();
/**
* Get the number of properties.
*
* @return list of Property objects
*/
public int getPropertyCount();
/**
* Gets a property of the class by name.
*
* @param name the name to retrieve
* @return a property by name
*/
public Property getProperty(String name);
}
1.1
jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/MetaOperation.java
Index: MetaOperation.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz;
import java.util.List;
/**
* <code>MetaOperation</code> defines a Java method.
*
* @author <a href="mailto:scolebourne@;apache.org">Stephen Colebourne</a>
* @version $Id: MetaOperation.java,v 1.1 2002/10/27 22:45:24 scolebourne Exp $
*/
public interface MetaOperation extends MetaUnit {
/**
* Get the return type of the method.
*
* @return the return type
*/
public MetaBean getReturnType();
/**
* Get the parameters of the method in order.
*
* @return list of MetaBean objects
*/
public List getParameters();
/**
* Gets a parameter of the method by index.
*
* @param index the index to retrieve
* @return a parameter by index
*/
public MetaBean getParameter(int index);
}
1.1
jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/Unit.java
Index: Unit.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz;
import java.util.Map;
/**
* <code>Unit</code> defines behaviour common across all meta implementations.
*
* @author <a href="mailto:scolebourne@;apache.org">Stephen Colebourne</a>
* @version $Id: Unit.java,v 1.1 2002/10/27 22:45:24 scolebourne Exp $
*/
public interface Unit {
/**
* Get the Map of string to string attributes.
*
* @return string/string attribute Map
*/
Map getAttributeMap();
/**
* Get the count of attributes.
* This should be checked rather than getAttributes().size() to
* allow for lazily instantiated attribute maps.
*
* @return the number of attributes
*/
int getAttributeCount();
/**
* Get an attribute by key.
*
* @param key the key to get
* @return attribute value by key, null if not found
*/
String getAttribute(String key);
/**
* Set an attribute key and value.
*
* @param key the key to set
* @param value the value to set
*/
void setAttribute(String key, String value);
}
1.1
jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/Property.java
Index: Property.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.commons.lang.ClassUtils;
import org.apache.commons.lang.StringUtils;
/**
* <code>Property</code> is an interface that should be implemented by properties.
*
* @author <a href="mailto:scolebourne@;apache.org">Stephen Colebourne</a>
* @version $Id: Property.java,v 1.1 2002/10/27 22:45:24 scolebourne Exp $
*/
public interface Property extends Unit {
/**
* Gets the MetaProperty for the bean.
*
* @return the meta property for the bean
*/
public MetaProperty getMetaProperty();
/**
* Gets the Bean for the property.
*
* @return the bean
*/
public Bean getBean();
//--------------------------------------------------------------------------
/**
* Gets the property value as a List.
* Simple properties return a list with fixed size 1.
* Array properties return a list wrapping the array.
* List properties return the list.
* Map properties return a list containing Map.Entry objects backed by the real
Map.
*/
public List asList();
/**
* Gets the size of this property.
* Simple properties return 1.
* Array, List and Map properties return their size.
*/
public int size();
/**
* Clears the property to an empty state.
* Simple/Array properties are set to null/0/false.
* List/Map properties are cleared.
*/
public void clear();
/**
* Is the property empty.
* Simple/Array properties return true if property == null. They may also have
* additional tests.
* List/Map properties return true if size == 0 or property == null.
*/
public void isEmpty();
/**
* Is the property null.
*/
public void isNull();
//--------------------------------------------------------------------------
/**
* Get the value of the property.
*
* @return the property value
*/
public Object get();
/**
* Get the value of the property.
*
* @param index the index to retrieve
* @return the property value at that index
*/
public Object get(int index);
/**
* Get the value of the property.
*
* @param key the key to retrieve
* @return the property value at that key
*/
public Object get(Object key);
/**
* Set the value of the property.
*
* @param value the property value
*/
public void set(Object value);
/**
* Set the value of the property.
*
* @param index the index to set
* @param value the property value
*/
public Object set(int index, Object value);
/**
* Set the value of the property.
*
* @param key the key to set
* @param value the property value
*/
public Object set(Object key, Object value);
/**
* Removes the object from the collection.
* If Array or List, removes if a match found.
* If Map, removes the key matching the object.
*
* @param obj the object to remove
*/
public Object removeObject(Object obj);
//--------------------------------------------------------------------------
/**
* Check whether the object is permanently read only.
* If this is true, then the property can never be made to
* be modifiable.
*
* @return true if the property value can never be changed
*/
boolean isReadOnly();
/**
* Set the object to be permanently read only.
* Once set the property can never be made to be modifiable again.
*/
void setReadOnly();
/**
* Check whether the object can currently be modified.
* This may change during the lifetime of a property due to the
* setModifiable(boolean) and setReadOnly() method.
*
* @return true if the property value can currently be changed
*/
boolean isModifiable();
/**
* Set the flag to indicate if the object is currently modifiable.
*
* @param modifiable true if object should be modifiable
*/
void setModifiable(boolean modifiable);
}
1.1
jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/MetaBean.java
Index: MetaBean.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz;
import java.util.List;
import java.util.Map;
/**
* <code>MetaBean</code> defines a Java class unit, either a class or interface.
*
* @author <a href="mailto:scolebourne@;apache.org">Stephen Colebourne</a>
* @version $Id: MetaBean.java,v 1.1 2002/10/27 22:45:24 scolebourne Exp $
*/
public interface MetaBean extends MetaUnit {
/**
* Gets the package name.
*
* @return the package name
*/
public String getPackageName();
/**
* Gets the class name (without the package).
*
* @return the class name (without the package)
*/
public String getShortClassName();
//--------------------------------------------------------------------------
/**
* Gets the interfaces of the type in order.
*
* @return list of AInterface objects
*/
public List getInterfaces();
/**
* Gets all the interfaces of the type in order.
*
* @return list of AInterface objects
*/
public List getAllInterfaces();
/**
* Gets the superclass of the class.
*
* @return the superclass
*/
public MetaBean getSuperClass();
/**
* Gets all the superclass of the class in order.
*
* @return the superclass
*/
public List getAllSuperClasses();
//--------------------------------------------------------------------------
/**
* Get the property map of the bean.
*
* @return map of MetaProperty objects
*/
public Map getMetaPropertyMap();
/**
* Gets the number of properties.
*
* @return the number of properties
*/
public int getMetaPropertyCount();
/**
* Gets a field of the class by name.
*
* @param name the name to retrieve
* @return a field by name
*/
public MetaProperty getMetaProperty(String name);
//--------------------------------------------------------------------------
/**
* Get the operations of the class in order.
*
* @return list of MetaOperation objects
*/
public List getMetaOperationList();
/**
* Gets the number of operations.
*
* @return the number of operations
*/
public int getMetaOperationCount();
/**
* Gets a operation of the class by index.
*
* @param index the index to retrieve
* @return a operation by index
*/
public MetaOperation getMetaOperation(int index);
//--------------------------------------------------------------------------
/**
* Creates a new instance of the bean.
*
* @return a new instance of the object, whatever that might be
*/
public Object newInstance();
/**
* Creates a new instance of the bean.
*
* @return a new instance as a Bean.
*/
public Bean newBean();
}
1.1
jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/Operation.java
Index: Operation.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang.ClassUtils;
import org.apache.commons.lang.StringUtils;
/**
* <code>Operation</code> is an interface that should be implemented by operations.
*
* @author <a href="mailto:scolebourne@;apache.org">Stephen Colebourne</a>
* @version $Id: Operation.java,v 1.1 2002/10/27 22:45:24 scolebourne Exp $
*/
public interface Operation extends Unit {
/**
* Gets the MetaOperation for the bean.
*
* @return the meta operation for the bean
*/
public MetaOperation getMetaOperation();
/**
* Gets the Bean for the property.
*
* @return the bean
*/
public Bean getBean();
//--------------------------------------------------------------------------
/**
* Invokes the operation.
*
* @return the result of the method call
*/
public Object invoke();
/**
* Invokes the operation.
*
* @param params the params to take in
* @return the result of the method call
*/
public Object invoke(Object[] params);
/**
* Invokes the operation.
*
* @param params the params to take in
* @return the result of the method call
*/
public Object invoke(List params);
}
1.1
jakarta-commons-sandbox/clazz/src/java/org/apache/commons/clazz/MetaModifiers.java
Index: MetaModifiers.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Commons", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package org.apache.commons.clazz;
import java.lang.reflect.Modifier;
import org.apache.commons.lang.StringUtils;
/**
* <code>AModifiers</code> defines the modifiers in a manipulable way.
*
* @author <a href="mailto:scolebourne@;apache.org">Stephen Colebourne</a>
* @version $Id: MetaModifiers.java,v 1.1 2002/10/27 22:45:24 scolebourne Exp $
*/
public class MetaModifiers {
/**
* The <code>int</code> value representing the <code>public</code>
* modifier.
*/
public static final int PUBLIC = Modifier.PUBLIC;
/**
* The <code>int</code> value representing the <code>private</code>
* modifier.
*/
public static final int PRIVATE = Modifier.PRIVATE;
/**
* The <code>int</code> value representing the <code>protected</code>
* modifier.
*/
public static final int PROTECTED = Modifier.PROTECTED;
/**
* The <code>int</code> value representing the <code>static</code>
* modifier.
*/
public static final int STATIC = Modifier.STATIC;
/**
* The <code>int</code> value representing the <code>final</code>
* modifier.
*/
public static final int FINAL = Modifier.FINAL;
/**
* The <code>int</code> value representing the <code>synchronized</code>
* modifier.
*/
public static final int SYNCHRONIZED = Modifier.SYNCHRONIZED;
/**
* The <code>int</code> value representing the <code>volatile</code>
* modifier.
*/
public static final int VOLATILE = Modifier.VOLATILE;
/**
* The <code>int</code> value representing the <code>transient</code>
* modifier.
*/
public static final int TRANSIENT = Modifier.TRANSIENT;
/**
* The <code>int</code> value representing the <code>native</code>
* modifier.
*/
public static final int NATIVE = Modifier.NATIVE;
/**
* The <code>int</code> value representing the <code>interface</code>
* modifier.
*/
public static final int INTERFACE = Modifier.INTERFACE;
/**
* The <code>int</code> value representing the <code>abstract</code>
* modifier.
*/
public static final int ABSTRACT = Modifier.ABSTRACT;
/**
* The <code>int</code> value representing the <code>strictfp</code>
* modifier.
*/
public static final int STRICT = Modifier.STRICT;
/** The modifiers */
private int modifiers = 0;
/**
* Constructor.
*
* @param modifiers the modifiers
*/
public MetaModifiers(int modifiers) {
super();
setFlags(modifiers);
}
/**
* Copy constructor.
*
* @param modifiers the modifiers object
* @throws IllegalArgumentException if the modifiers object is null
*/
public MetaModifiers(MetaModifiers modifiers) {
super();
if (modifiers == null) {
throw new IllegalArgumentException("The modifiers must not be null");
}
setFlags(modifiers.getFlags());
}
//--------------------------------------------------------------------------
/**
* Gets the modifier flags, which can be accessed via java.lang.reflect.Modifier.
*
* @return the modifier flags
*/
public int getFlags() {
return modifiers;
}
/**
* Sets the modifier flags.
*
* @param modifiers the modifier flags to update to
*/
public void setFlags(int modifiers) {
this.modifiers = modifiers;
}
//--------------------------------------------------------------------------
/**
* Is the object public scope.
*
* @return true if public scope
*/
public boolean isPublicScope() {
return (getFlags() & PUBLIC) != 0;
}
/**
* Set the object to be public scope.
*/
public void setPublicScope() {
setFlags(getFlags() & ~Modifier.PRIVATE & ~Modifier.PROTECTED &
Modifier.PUBLIC);
}
//--------------------------------------------------------------------------
/**
* Is the object protected scope.
*
* @return true if protected scope
*/
public boolean isProtectedScope() {
return (getFlags() & PROTECTED) != 0;
}
/**
* Set the object to be protected scope.
*/
public void setProtectedScope() {
setFlags(getFlags() & ~Modifier.PRIVATE & Modifier.PROTECTED &
~Modifier.PUBLIC);
}
//--------------------------------------------------------------------------
/**
* Is the object package scope.
*
* @return true if package scope
*/
public boolean isPackageScope() {
return ((isPublicScope() == false) &&
(isProtectedScope() == false) &&
(isPrivateScope() == false));
}
/**
* Set the object to be package scope.
*/
public void setPackageScope() {
setFlags(getFlags() & ~Modifier.PRIVATE & ~Modifier.PROTECTED &
~Modifier.PUBLIC);
}
//--------------------------------------------------------------------------
/**
* Is the object private scope.
*
* @return true if private scope
*/
public boolean isPrivateScope() {
return (getFlags() & PRIVATE) != 0;
}
/**
* Set the object to be private scope.
*/
public void setPrivateScope() {
setFlags(getFlags() & Modifier.PRIVATE & ~Modifier.PROTECTED &
~Modifier.PUBLIC);
}
//--------------------------------------------------------------------------
/**
* Is the object static.
*
* @return true if static
*/
public boolean isStatic() {
return (getFlags() & STATIC) != 0;
}
/**
* Set the object to be static.
*
* @param state true to make static
*/
public void setStatic(boolean state) {
if (state) {
setFlags(getFlags() & Modifier.STATIC);
} else {
setFlags(getFlags() & ~Modifier.STATIC);
}
}
//--------------------------------------------------------------------------
/**
* Is the object final.
*
* @return true if final
*/
public boolean isFinal() {
return (getFlags() & FINAL) != 0;
}
/**
* Set the object to be final.
*
* @param state true to make final
*/
public void setFinal(boolean state) {
if (state) {
setFlags(getFlags() & Modifier.FINAL);
} else {
setFlags(getFlags() & ~Modifier.FINAL);
}
}
//--------------------------------------------------------------------------
/**
* Is the object synchronized.
*
* @return true if synchronized
*/
public boolean isSynchronized() {
return (getFlags() & SYNCHRONIZED) != 0;
}
/**
* Set the object to be synchronized.
*
* @param state true to make synchronized
*/
public void setSynchronized(boolean state) {
if (state) {
setFlags(getFlags() & Modifier.SYNCHRONIZED);
} else {
setFlags(getFlags() & ~Modifier.SYNCHRONIZED);
}
}
//--------------------------------------------------------------------------
/**
* Is the object volatile.
*
* @return true if volatile
*/
public boolean isVolatile() {
return (getFlags() & VOLATILE) != 0;
}
/**
* Set the object to be volatile.
*
* @param state true to make volatile
*/
public void setVolatile(boolean state) {
if (state) {
setFlags(getFlags() & Modifier.VOLATILE);
} else {
setFlags(getFlags() & ~Modifier.VOLATILE);
}
}
//--------------------------------------------------------------------------
/**
* Is the object transient.
*
* @return true if transient
*/
public boolean isTransient() {
return (getFlags() & TRANSIENT) != 0;
}
/**
* Set the object to be transient.
*
* @param state true to make transient
*/
public void setTransient(boolean state) {
if (state) {
setFlags(getFlags() & TRANSIENT);
} else {
setFlags(getFlags() & ~TRANSIENT);
}
}
//--------------------------------------------------------------------------
/**
* Is the object native.
*
* @return true if native
*/
public boolean isNative() {
return (getFlags() & NATIVE) != 0;
}
/**
* Set the object to be native.
*
* @param state true to make native
*/
public void setNative(boolean state) {
if (state) {
setFlags(getFlags() & NATIVE);
} else {
setFlags(getFlags() & ~NATIVE);
}
}
//--------------------------------------------------------------------------
/**
* Is the object abstract.
*
* @return true if abstract
*/
public boolean isAbstract() {
return (getFlags() & ABSTRACT) != 0;
}
/**
* Set the object to be abstract.
*
* @param state true to make abstract
*/
public void setAbstract(boolean state) {
if (state) {
setFlags(getFlags() & ABSTRACT);
} else {
setFlags(getFlags() & ~ABSTRACT);
}
}
//--------------------------------------------------------------------------
/**
* Is the object strictfp.
*
* @return true if strictfp
*/
public boolean isStrictFP() {
return (getFlags() & STRICT) != 0;
}
/**
* Set the object to be strictfp.
*
* @param state true to make strictfp
*/
public void setStrictFP(boolean state) {
if (state) {
setFlags(getFlags() & STRICT);
} else {
setFlags(getFlags() & ~STRICT);
}
}
//--------------------------------------------------------------------------
/**
* Geta string describing the access modifier flags in
* the specified modifier. For example:
* <blockquote><pre>
* AModifiers[public final synchronized]
* AModifiers[private transient volatile]
* </pre></blockquote>
* The modifier names are return in canonical order, as
* specified by <em>The Java Language Specification</em>.
*
* @return a debug string
*/
public String toString() {
StringBuffer sb = new StringBuffer("AModifiers[");
if (isPublicScope()) {
sb.append("public ");
}
if (isPrivateScope()) {
sb.append("private ");
}
if (isProtectedScope()) {
sb.append("protected ");
}
// Canonical order
if (isAbstract()) {
sb.append("abstract ");
}
if (isStatic()) {
sb.append("static ");
}
if (isFinal()) {
sb.append("final ");
}
if (isTransient()) {
sb.append("transient ");
}
if (isVolatile()) {
sb.append("volatile ");
}
if (isNative()) {
sb.append("native ");
}
if (isSynchronized()) {
sb.append("synchronized ");
}
// if (isInterface()) {
// sb.append("interface ");
// }
if (isStrictFP()) {
sb.append("strictfp ");
}
if (sb.length() > 11) {
sb.setCharAt(sb.length() - 1, ']');
} else {
sb.append(']');
}
return sb.toString();
}
}
--
To unsubscribe, e-mail: <mailto:commons-dev-unsubscribe@;jakarta.apache.org>
For additional commands, e-mail: <mailto:commons-dev-help@;jakarta.apache.org>