|
Commons Beanutils example source code file (DynaProperty.java)
The Commons Beanutils DynaProperty.java source code
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.beanutils;
import java.io.IOException;
import java.io.Serializable;
import java.io.ObjectOutputStream;
import java.io.ObjectInputStream;
import java.io.StreamCorruptedException;
import java.util.List;
import java.util.Map;
/**
* <p>The metadata describing an individual property of a DynaBean.
*
* <p>The meta contains an optional content type property ({@link #getContentType})
* for use by mapped and iterated properties.
* A mapped or iterated property may choose to indicate the type it expects.
* The DynaBean implementation may choose to enforce this type on its entries.
* Alternatively, an implementatin may choose to ignore this property.
* All keys for maps must be of type String so no meta data is needed for map keys.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 926529 $ $Date: 2010-03-23 11:44:24 +0000 (Tue, 23 Mar 2010) $
*/
public class DynaProperty implements Serializable {
// ----------------------------------------------------------- Constants
/*
* There are issues with serializing primitive class types on certain JVM versions
* (including java 1.3).
* This class uses a custom serialization implementation that writes an integer
* for these primitive class.
* This list of constants are the ones used in serialization.
* If these values are changed, then older versions will no longer be read correctly
*/
private static final int BOOLEAN_TYPE = 1;
private static final int BYTE_TYPE = 2;
private static final int CHAR_TYPE = 3;
private static final int DOUBLE_TYPE = 4;
private static final int FLOAT_TYPE = 5;
private static final int INT_TYPE = 6;
private static final int LONG_TYPE = 7;
private static final int SHORT_TYPE = 8;
// ----------------------------------------------------------- Constructors
/**
* Construct a property that accepts any data type.
*
* @param name Name of the property being described
*/
public DynaProperty(String name) {
this(name, Object.class);
}
/**
* Construct a property of the specified data type.
*
* @param name Name of the property being described
* @param type Java class representing the property data type
*/
public DynaProperty(String name, Class type) {
super();
this.name = name;
this.type = type;
if (type != null && type.isArray()) {
this.contentType = type.getComponentType();
}
}
/**
* Construct an indexed or mapped <code>DynaProperty that supports (pseudo)-introspection
* of the content type.
*
* @param name Name of the property being described
* @param type Java class representing the property data type
* @param contentType Class that all indexed or mapped elements are instances of
*/
public DynaProperty(String name, Class type, Class contentType) {
super();
this.name = name;
this.type = type;
this.contentType = contentType;
}
// ------------------------------------------------------------- Properties
/** Property name */
protected String name = null;
/**
* Get the name of this property.
* @return the name of the property
*/
public String getName() {
return (this.name);
}
/** Property type */
protected transient Class type = null;
/**
* <p>Gets the Java class representing the data type of the underlying property
* values.</p>
*
* <p>There are issues with serializing primitive class types on certain JVM versions
* (including java 1.3).
* Therefore, this field <strong>must not be serialized using the standard methods.
*
* <p>Please leave this field as
Other Commons Beanutils examples (source code examples)Here is a short list of links related to this Commons Beanutils DynaProperty.java source code file: |
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.