Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[json-lib] updates for 1.0

  • Loading branch information...
commit de0a2671f07f1a57b1ca78254e3f33130be18be0 1 parent 9834999
aalmiray authored
View
44 build.xml
@@ -10,7 +10,7 @@
<property name="project.src.jdk15.dir" value="${basedir}/src/main/jdk15" />
<property name="project.test.jdk13.dir" value="${basedir}/src/test/java" />
<property name="project.test.jdk15.dir" value="${basedir}/src/test/jdk15" />
- <property name="javadoc.jdk13.dir" value="$maven.build.directory}/site/apidocs" />
+ <property name="javadoc.jdk13.dir" value="${maven.build.directory}/site/apidocs" />
<property name="javadoc.jdk15.dir" value="${maven.build.directory}/site/apidocs/jdk15" />
<typedef resource="org/apache/maven/artifact/ant/antlib.xml" uri="urn:maven-artifact-ant">
@@ -150,7 +150,7 @@
<include name="**/*.java" />
</fileset>
</copy>
- <jar jarfile="${maven.build.directory}/${maven.project.build.finalName}-sources-jdk13.jar" basedir="${maven.build.directory}/source/jdk13" />
+ <jar jarfile="${maven.build.directory}/${maven.project.build.finalName}-jdk13-sources.jar" basedir="${maven.build.directory}/source/jdk13" />
</target>
<target name="source.jar.jdk15" depends="clean" description="Source jar (jdk15)">
@@ -163,7 +163,34 @@
<include name="**/*.java" />
</fileset>
</copy>
- <jar jarfile="${maven.build.directory}/${maven.project.build.finalName}-sources-jdk15.jar" basedir="${maven.build.directory}/source/jdk15" />
+ <jar jarfile="${maven.build.directory}/${maven.project.build.finalName}-jdk15-sources.jar" basedir="${maven.build.directory}/source/jdk15" />
+ </target>
+
+ <target name="javadoc" description="Build javadocs (jdk13)" depends="setup">
+ <mkdir dir="${javadoc.jdk13.dir}" />
+ <mkdir dir="${maven.build.directory}/source/jdk13" />
+ <copy todir="${maven.build.directory}/source/jdk13">
+ <fileset dir="src/main/java">
+ <include name="**/*" />
+ </fileset>
+ </copy>
+ <javadoc destdir="${javadoc.jdk13.dir}" windowtitle="Overview (json-lib jdk13 API)" useexternalfile="true">
+
+ <packageset dir="${maven.build.directory}/source/jdk13">
+ <include name="**/*" />
+ </packageset>
+
+ <classpath>
+ <path refid="build.classpath" />
+ </classpath>
+
+ <link href="http://java.sun.com/j2se/1.5.0/docs/api/" />
+ <link href="http://www.junit.org/junit/javadoc/" />
+ <link href="http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.7.0/docs/api/" />
+ <link href="http://jakarta.apache.org/commons/lang/api-2.2/" />
+ <link href="http://ezmorph.sourceforge.net/apidocs/" />
+ </javadoc>
+ <jar jarfile="${maven.build.directory}/${maven.project.build.finalName}-jdk13-javadoc.jar" basedir="${javadoc.jdk13.dir}" />
</target>
<target name="javadoc.jdk15" description="Build javadocs (jdk15)" depends="setup">
@@ -193,15 +220,12 @@
<link href="http://jakarta.apache.org/commons/lang/api-2.2/" />
<link href="http://ezmorph.sourceforge.net/apidocs/" />
</javadoc>
- <jar jarfile="${maven.build.directory}/${maven.project.build.finalName}-javadoc-jdk15.jar" basedir="${javadoc.jdk15.dir}" />
+ <jar jarfile="${maven.build.directory}/${maven.project.build.finalName}-jdk15-javadoc.jar" basedir="${javadoc.jdk15.dir}" />
</target>
<target name="setup" if="use.proxy">
- <echo message="Setting proxy values [${maven.proxy.host}:${maven.proxy.port}]"/>
- <setproxy proxyhost="${maven.proxy.host}"
- proxyport="${maven.proxy.port}"
- proxyuser="${maven.proxy.username}"
- proxypassword="${maven.proxy.password}" />
+ <echo message="Setting proxy values [${maven.proxy.host}:${maven.proxy.port}]" />
+ <setproxy proxyhost="${maven.proxy.host}" proxyport="${maven.proxy.port}" proxyuser="${maven.proxy.username}" proxypassword="${maven.proxy.password}" />
</target>
-</project>
+</project>
View
87 deploy.sh
@@ -0,0 +1,87 @@
+#!/bin/sh
+VERSION="1.0"
+GROUPID="net.sf.json-lib"
+ARTIFACTID="json-lib"
+REPO_URL="scp://ssh.sf.net/home/groups/j/js/json-lib/htdocs/m2/repo/release"
+REPOSITORYID="sf_release"
+
+mkdir build
+ant source.jar
+mv target/json-lib-${VERSION}-jdk13-sources.jar build
+ant source.jar.jdk15
+mv target/json-lib-${VERSION}-jdk15-sources.jar build
+ant javadoc
+mv target/json-lib-${VERSION}-jdk13-javadoc.jar build
+ant javadoc.jdk15
+mv target/json-lib-${VERSION}-jdk15-javadoc.jar build
+ant jar
+mv target/json-lib-${VERSION}-jdk13.jar build
+ant jar.jdk15
+mv target/json-lib-${VERSION}-jdk15.jar build
+
+mvn deploy:deploy-file -DrepositoryId=${REPOSITORYID} \
+ -Durl=${REPO_URL} \
+ -DgroupId=${GROUPID} \
+ -DartifactId=${ARTIFACTID} \
+ -Dversion=${VERSION} \
+ -Dpackaging=jar \
+ -DgeneratePom=false \
+ -Dclassifier=jdk13-javadoc \
+ -Dfile=build/json-lib-${VERSION}-jdk13-javadoc.jar
+
+mvn deploy:deploy-file -DrepositoryId=${REPOSITORYID} \
+ -Durl=${REPO_URL} \
+ -DgroupId=${GROUPID} \
+ -DartifactId=${ARTIFACTID} \
+ -Dversion=${VERSION} \
+ -Dpackaging=jar \
+ -DgeneratePom=false \
+ -Dclassifier=jdk15-javadoc \
+ -Dfile=build/json-lib-${VERSION}-jdk15-javadoc.jar
+
+mvn deploy:deploy-file -DrepositoryId=${REPOSITORYID} \
+ -Durl=${REPO_URL} \
+ -DgroupId=${GROUPID} \
+ -DartifactId=${ARTIFACTID} \
+ -Dversion=${VERSION} \
+ -Dpackaging=jar \
+ -DgeneratePom=false \
+ -Dclassifier=jdk13-sources \
+ -Dfile=build/json-lib-${VERSION}-jdk13-sources.jar
+
+mvn deploy:deploy-file -DrepositoryId=${REPOSITORYID} \
+ -Durl=${REPO_URL} \
+ -DgroupId=${GROUPID} \
+ -DartifactId=${ARTIFACTID} \
+ -Dversion=${VERSION} \
+ -Dpackaging=jar \
+ -DgeneratePom=false \
+ -Dclassifier=jdk15-sources \
+ -Dfile=build/json-lib-${VERSION}-jdk15-sources.jar
+
+mvn deploy:deploy-file -DrepositoryId=${REPOSITORYID} \
+ -Durl=${REPO_URL} \
+ -DgroupId=${GROUPID} \
+ -DartifactId=${ARTIFACTID} \
+ -Dversion=${VERSION} \
+ -Dpackaging=jar \
+ -Dclassifier=jdk15 \
+ -Dfile=build/json-lib-${VERSION}-jdk15.jar
+
+mvn deploy:deploy-file -DrepositoryId=${REPOSITORYID} \
+ -Durl=${REPO_URL} \
+ -DgroupId=${GROUPID} \
+ -DartifactId=${ARTIFACTID} \
+ -Dversion=${VERSION} \
+ -Dpackaging=jar \
+ -Dclassifier=jdk13 \
+ -Dfile=build/json-lib-${VERSION}-jdk13.jar
+
+mvn deploy:deploy-file -DrepositoryId=${REPOSITORYID} \
+ -Durl=${REPO_URL} \
+ -DgroupId=${GROUPID} \
+ -DartifactId=${ARTIFACTID} \
+ -Dversion=${VERSION} \
+ -Dpackaging=pom \
+ -DgeneratePom=false \
+ -Dfile=pom.xml
View
7 net.sf.json-lib.sh
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+CONTACTS="Andres Almiray <aalmiray@users.sourceforge.net>"
+MODE=rsync_ssh
+
+FROM=mavensync@shell.sourceforge.net:/home/groups/j/js/json-lib/htdocs/m2/repo/release
+GROUP_DIR=net/sf/json-lib/
View
53 pom.xml
@@ -7,7 +7,7 @@
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<packaging>jar</packaging>
- <version>1.0b3</version>
+ <version>1.0</version>
<name>json-lib</name>
<url>http://json-lib.sourceforge.net</url>
@@ -110,6 +110,24 @@
<artifactId>commons-logging</artifactId>
<version>1.1</version>
<scope>compile</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>logkit</groupId>
+ <artifactId>logkit</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>avalon-framework</groupId>
+ <artifactId>avalon-framework</artifactId>
+ </exclusion>
+ <exclusion>
+ <groupId>javax.servlet</groupId>
+ <artifactId>servlet-api</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
<groupId>xom</groupId>
@@ -146,18 +164,6 @@
<build>
<defaultGoal>install</defaultGoal>
- <!--
- <pluginManagement>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-javadoc-plugin</artifactId>
- <version>2.0</version>
- </plugin>
- </plugins>
- </pluginManagement>
- -->
-
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
@@ -215,8 +221,12 @@
<links>
<link>http://java.sun.com/j2se/1.5.0/docs/api/</link>
<link>http://www.junit.org/junit/javadoc/</link>
- <link>http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.7.0/docs/api/</link>
- <link>http://jakarta.apache.org/commons/lang/api-2.2/</link>
+ <link>
+ http://jakarta.apache.org/commons/beanutils/commons-beanutils-1.7.0/docs/api/
+ </link>
+ <link>
+ http://jakarta.apache.org/commons/lang/api-2.2/
+ </link>
<link>http://ezmorph.sourceforge.net/apidocs/</link>
</links>
</configuration>
@@ -278,16 +288,23 @@
</pluginRepositories>
<distributionManagement>
+ <repository>
+ <id>sf_release</id>
+ <name>Json-lib repo @ sourceforge.net</name>
+ <url>
+ scp://ssh.sf.net/home/groups/j/js/json-lib/htdocs/m2/repo/release
+ </url>
+ </repository>
<snapshotRepository>
- <id>sf_snapshots</id>
+ <id>sf_snapshot</id>
<name>SourceForge Snapshot</name>
<url>
- scpexe://ssh.sf.net/home/groups/j/js/json-lib/htdocs/m2/repo
+ scp://ssh.sf.net/home/groups/j/js/json-lib/htdocs/m2/repo/snapshot
</url>
</snapshotRepository>
<site>
<id>sf_website</id>
- <url>scpexe://ssh.sf.net/home/groups/j/js/json-lib/htdocs</url>
+ <url>scp://ssh.sf.net/home/groups/j/js/json-lib/htdocs</url>
</site>
</distributionManagement>
View
11 src/changes/changes.xml
@@ -8,9 +8,14 @@
</properties>
<body>
<release
- version="N/A"
- date="2007-02-02"
- desc="Current development version">
+ version="1.0"
+ date="2007-02-11"
+ desc="The _1.0_ release">
+ <action
+ dev="Andres Almiray"
+ type="delete">
+ Removed deprecated classes.
+ </action>
<action
dev="Andres Almiray"
type="fix"
View
138 src/main/java/net/sf/json/util/DynaBeanToBeanMorpher.java
@@ -1,138 +0,0 @@
-/*
- * Copyright 2002-2006 the original author or authors.
- *
- * Licensed 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 net.sf.json.util;
-
-import java.beans.PropertyDescriptor;
-import java.util.Collection;
-import java.util.Map;
-
-import net.sf.ezmorph.MorphException;
-import net.sf.ezmorph.MorpherRegistry;
-import net.sf.ezmorph.ObjectMorpher;
-import net.sf.ezmorph.object.IdentityObjectMorpher;
-
-import org.apache.commons.beanutils.DynaBean;
-import org.apache.commons.beanutils.DynaClass;
-import org.apache.commons.beanutils.DynaProperty;
-import org.apache.commons.beanutils.PropertyUtils;
-
-/**
- * Converts a DynaBean into an specific bean.<br>
- * This Morpher will try to match every property from the target bean's class to
- * the properties of the source DynaBean. If a bean property and the dyna
- * property differ in type, it will try to morph it. If a Morpher is not found
- * for that type, the conversion will be aborted with a MorphException.
- *
- * @author Andres Almiray <aalmiray@users.sourceforge.net>
- * @deprecated Use BeanMorpher (from EZMorph). Will be removed in 1.0
- */
-public class DynaBeanToBeanMorpher implements ObjectMorpher
-{
- private final Class beanClass;
- private final MorpherRegistry morpherRegistry;
-
- public DynaBeanToBeanMorpher( Class beanClass, MorpherRegistry morpherRegistry )
- {
- validateClass( beanClass );
- if( morpherRegistry == null ){
- throw new IllegalArgumentException( "morpherRegistry is null" );
- }
- this.beanClass = beanClass;
- this.morpherRegistry = morpherRegistry;
- }
-
- public Object morph( Object value )
- {
- if( value == null ){
- return null;
- }
- if( !supports( value.getClass() ) ){
- throw new MorphException( "value is not a DynaBean" );
- }
-
- Object bean = null;
-
- try{
- bean = beanClass.newInstance();
-
- DynaBean dynaBean = (DynaBean) value;
- DynaClass dynaClass = dynaBean.getDynaClass();
- PropertyDescriptor[] pds = PropertyUtils.getPropertyDescriptors( beanClass );
- for( int i = 0; i < pds.length; i++ ){
- PropertyDescriptor pd = pds[i];
- String name = pd.getName();
- DynaProperty dynaProperty = dynaClass.getDynaProperty( name );
- if( dynaProperty != null ){
- Class dynaType = dynaProperty.getType();
- Class type = pd.getPropertyType();
- if( type.isAssignableFrom( dynaType ) ){
- PropertyUtils.setProperty( bean, name, dynaBean.get( name ) );
- }else{
- if( IdentityObjectMorpher.getInstance() == morpherRegistry.getMorpherFor( type ) ){
- throw new MorphException( "Can't find a morpher for target class " + type );
- }else{
- PropertyUtils.setProperty( bean, name, morpherRegistry.morph( type,
- dynaBean.get( name ) ) );
- }
- }
- }
- }
- }
- catch( MorphException me ){
- throw me;
- }
- catch( Exception e ){
- throw new MorphException( e );
- }
-
- return bean;
- }
-
- public Class morphsTo()
- {
- return beanClass;
- }
-
- public boolean supports( Class clazz )
- {
- return DynaBean.class.isAssignableFrom( clazz );
- }
-
- private void validateClass( Class clazz )
- {
- if( clazz == null ){
- throw new IllegalArgumentException( "target class is null" );
- }else if( clazz.isPrimitive() ){
- throw new IllegalArgumentException( "target class is a primitive" );
- }else if( clazz.isArray() ){
- throw new IllegalArgumentException( "target class is an array" );
- }else if( clazz.isInterface() ){
- throw new IllegalArgumentException( "target class is an interface" );
- }else if( DynaBean.class.isAssignableFrom( clazz ) ){
- throw new IllegalArgumentException( "target class is a DynaBean" );
- }else if( Number.class.isAssignableFrom( clazz ) || Boolean.class.isAssignableFrom( clazz )
- || Character.class.isAssignableFrom( clazz ) ){
- throw new IllegalArgumentException( "target class is a wrapper" );
- }else if( String.class.isAssignableFrom( clazz ) ){
- throw new IllegalArgumentException( "target class is a String" );
- }else if( Collection.class.isAssignableFrom( clazz ) ){
- throw new IllegalArgumentException( "target class is a Collection" );
- }else if( Map.class.isAssignableFrom( clazz ) ){
- throw new IllegalArgumentException( "target class is a Map" );
- }
- }
-}
View
332 src/main/java/net/sf/json/util/JSONDynaBean.java
@@ -1,332 +0,0 @@
-/*
- * Copyright 2002-2006 the original author or authors.
- *
- * Licensed 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 net.sf.json.util;
-
-import java.io.Serializable;
-import java.lang.reflect.Array;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import net.sf.json.JSONException;
-
-import org.apache.commons.beanutils.DynaBean;
-import org.apache.commons.beanutils.DynaClass;
-import org.apache.commons.beanutils.DynaProperty;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.commons.lang.builder.ToStringBuilder;
-import org.apache.commons.lang.builder.ToStringStyle;
-
-/**
- * @author Andres Almiray <aalmiray@users.sourceforge.net>
- * @deprecated Use MorphDynaBean (from EZMorph). Will be removed in 1.0
- */
-public class JSONDynaBean implements DynaBean, Serializable
-{
- private static final long serialVersionUID = -8287401671998903440L;
- protected JSONDynaClass dynaClass;
- protected Map dynaValues = new HashMap();
-
- public JSONDynaBean()
- {
- super();
- }
-
- public boolean contains( String name, String key )
- {
- DynaProperty dynaProperty = getDynaProperty( name );
-
- Class type = dynaProperty.getType();
- if( !Map.class.isAssignableFrom( type ) ){
- throw new JSONException( "Non-Mapped property name: " + name + " key: " + key );
- }
-
- Object value = dynaValues.get( name );
- if( value == null ){
- value = new HashMap();
- dynaValues.put( name, value );
- }
- return ((Map) value).containsKey( key );
- }
-
- public boolean equals( Object obj )
- {
- if( this == obj ){
- return true;
- }
-
- if( obj == null ){
- return false;
- }
-
- if( !(obj instanceof JSONDynaBean) ){
- return false;
- }
-
- JSONDynaBean other = (JSONDynaBean) obj;
- EqualsBuilder builder = new EqualsBuilder().append( this.dynaClass, other.dynaClass );
- DynaProperty[] props = dynaClass.getDynaProperties();
- for( int i = 0; i < props.length; i++ ){
- DynaProperty prop = props[i];
- builder.append( dynaValues.get( prop.getName() ), dynaValues.get( prop.getName() ) );
- }
- return builder.isEquals();
- }
-
- public Object get( String name )
- {
- Object value = dynaValues.get( name );
-
- if( value != null ){
- return value;
- }
-
- Class type = getDynaProperty( name ).getType();
- if( !type.isPrimitive() ){
- return value;
- }else{
- return JSONUtils.getMorpherRegistry()
- .morph( type, value );
- }
- }
-
- public Object get( String name, int index )
- {
- DynaProperty dynaProperty = getDynaProperty( name );
-
- Class type = dynaProperty.getType();
- if( !type.isArray() && !List.class.isAssignableFrom( type ) ){
- throw new JSONException( "Non-Indexed property name: " + name + " index: "
- + index );
- }
-
- Object value = dynaValues.get( name );
-
- if( value.getClass()
- .isArray() ){
- value = Array.get( value, index );
- }else if( value instanceof List ){
- value = ((List) value).get( index );
- }
-
- return value;
- }
-
- public Object get( String name, String key )
- {
- DynaProperty dynaProperty = getDynaProperty( name );
-
- Class type = dynaProperty.getType();
- if( !Map.class.isAssignableFrom( type ) ){
- throw new JSONException( "Non-Mapped property name: " + name + " key: " + key );
- }
-
- Object value = dynaValues.get( name );
- if( value == null ){
- value = new HashMap();
- dynaValues.put( name, value );
- }
- return ((Map) value).get( key );
- }
-
- public DynaClass getDynaClass()
- {
- return this.dynaClass;
- }
-
- public int hashCode()
- {
- HashCodeBuilder builder = new HashCodeBuilder().append( dynaClass );
- DynaProperty[] props = dynaClass.getDynaProperties();
- for( int i = 0; i < props.length; i++ ){
- DynaProperty prop = props[i];
- builder.append( dynaValues.get( prop.getName() ) );
- }
- return builder.toHashCode();
- }
-
- public void remove( String name, String key )
- {
- DynaProperty dynaProperty = getDynaProperty( name );
-
- Class type = dynaProperty.getType();
- if( !Map.class.isAssignableFrom( type ) ){
- throw new JSONException( "Non-Mapped property name: " + name + " key: " + key );
- }
-
- Object value = dynaValues.get( name );
- if( value == null ){
- value = new HashMap();
- dynaValues.put( name, value );
- }
- ((Map) value).remove( key );
- }
-
- public void set( String name, int index, Object value )
- {
- DynaProperty dynaProperty = getDynaProperty( name );
-
- Class type = dynaProperty.getType();
- if( !type.isArray() && !List.class.isAssignableFrom( type ) ){
- throw new JSONException( "Non-Indexed property name: " + name + " index: "
- + index );
- }
-
- Object prop = dynaValues.get( name );
- if( prop == null ){
- if( List.class.isAssignableFrom( type ) ){
- prop = new ArrayList();
- }else{
- prop = Array.newInstance( type.getComponentType(), index + 1 );
- }
- dynaValues.put( name, prop );
- }
-
- if( prop.getClass()
- .isArray() ){
- if( index >= Array.getLength( prop ) ){
- Object tmp = Array.newInstance( type.getComponentType(), index + 1 );
- System.arraycopy( prop, 0, tmp, 0, Array.getLength( prop ) );
- prop = tmp;
- dynaValues.put( name, tmp );
- }
- Array.set( prop, index, value );
- }else if( prop instanceof List ){
- List l = (List) prop;
- if( index >= l.size() ){
- for( int i = l.size(); i <= index + 1; i++ ){
- l.add( null );
- }
- }
- ((List) prop).set( index, value );
- }
- }
-
- public void set( String name, Object value )
- {
- DynaProperty property = getDynaProperty( name );
-
- if( value == null || !isDynaAssignable( property.getType(), value.getClass() ) ){
- value = JSONUtils.getMorpherRegistry()
- .morph( property.getType(), value );
- }
-
- dynaValues.put( name, value );
- }
-
- public void set( String name, String key, Object value )
- {
- DynaProperty dynaProperty = getDynaProperty( name );
-
- Class type = dynaProperty.getType();
- if( !Map.class.isAssignableFrom( type ) ){
- throw new JSONException( "Non-Mapped property name: " + name + " key: " + key );
- }
-
- Object prop = dynaValues.get( name );
- if( prop == null ){
- prop = new HashMap();
- dynaValues.put( name, prop );
- }
- ((Map) prop).put( key, value );
- }
-
- public synchronized void setDynaBeanClass( JSONDynaClass dynaClass )
- {
- if( this.dynaClass == null ){
- this.dynaClass = dynaClass;
- }
- }
-
- public String toString()
- {
- return new ToStringBuilder( this, ToStringStyle.MULTI_LINE_STYLE ).append( dynaValues )
- .toString();
- }
-
- protected DynaProperty getDynaProperty( String name )
- {
- DynaProperty property = getDynaClass().getDynaProperty( name );
- if( property == null ){
- throw new JSONException( "Unspecified property for " + name );
- }
- return property;
- }
-
- protected boolean isDynaAssignable( Class dest, Class src )
- {
- boolean assignable = dest.isAssignableFrom( src );
- if( assignable ){
- return true;
- }
- assignable = (dest == Boolean.TYPE && src == Boolean.class) ? true : assignable;
- assignable = (dest == Byte.TYPE && src == Byte.class) ? true : assignable;
- assignable = (dest == Character.TYPE && src == Character.class) ? true : assignable;
- assignable = (dest == Short.TYPE && src == Short.class) ? true : assignable;
- assignable = (dest == Integer.TYPE && src == Integer.class) ? true : assignable;
- assignable = (dest == Long.TYPE && src == Long.class) ? true : assignable;
- assignable = (dest == Float.TYPE && src == Float.class) ? true : assignable;
- assignable = (dest == Double.TYPE && src == Double.class) ? true : assignable;
-
- if( src == Double.TYPE || Double.class.isAssignableFrom( src ) ){
- assignable = (isByte( dest ) || isShort( dest ) || isInteger( dest ) || isLong( dest ) || isFloat( dest )) ? true
- : assignable;
- }
- if( src == Float.TYPE || Float.class.isAssignableFrom( src ) ){
- assignable = (isByte( dest ) || isShort( dest ) || isInteger( dest ) || isLong( dest )) ? true
- : assignable;
- }
- if( src == Long.TYPE || Long.class.isAssignableFrom( src ) ){
- assignable = (isByte( dest ) || isShort( dest ) || isInteger( dest )) ? true : assignable;
- }
- if( src == Integer.TYPE || Integer.class.isAssignableFrom( src ) ){
- assignable = (isByte( dest ) || isShort( dest )) ? true : assignable;
- }
- if( src == Short.TYPE || Short.class.isAssignableFrom( src ) ){
- assignable = (isByte( dest )) ? true : assignable;
- }
-
- return assignable;
- }
-
- private boolean isByte( Class clazz )
- {
- return Byte.class.isAssignableFrom( clazz ) || clazz == Byte.TYPE;
- }
-
- private boolean isFloat( Class clazz )
- {
- return Float.class.isAssignableFrom( clazz ) || clazz == Float.TYPE;
- }
-
- private boolean isInteger( Class clazz )
- {
- return Integer.class.isAssignableFrom( clazz ) || clazz == Integer.TYPE;
- }
-
- private boolean isLong( Class clazz )
- {
- return Long.class.isAssignableFrom( clazz ) || clazz == Long.TYPE;
- }
-
- private boolean isShort( Class clazz )
- {
- return Short.class.isAssignableFrom( clazz ) || clazz == Short.TYPE;
- }
-}
View
205 src/main/java/net/sf/json/util/JSONDynaClass.java
@@ -1,205 +0,0 @@
-/*
- * Copyright 2002-2006 the original author or authors.
- *
- * Licensed 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 net.sf.json.util;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import net.sf.json.JSONException;
-
-import org.apache.commons.beanutils.DynaBean;
-import org.apache.commons.beanutils.DynaClass;
-import org.apache.commons.beanutils.DynaProperty;
-import org.apache.commons.lang.builder.EqualsBuilder;
-import org.apache.commons.lang.builder.HashCodeBuilder;
-import org.apache.commons.lang.builder.ToStringBuilder;
-
-/**
- * @author Andres Almiray <aalmiray@users.sourceforge.net>
- * @deprecated Use MorphDynaClass (from EZMorph). Will be removed in 1.0
- */
-public class JSONDynaClass implements DynaClass, Serializable
-{
- private static final Comparator dynaPropertyComparator = new Comparator(){
- public int compare( Object a, Object b )
- {
- if( a instanceof DynaProperty && b instanceof DynaProperty ){
- DynaProperty p1 = (DynaProperty) a;
- DynaProperty p2 = (DynaProperty) b;
- return p1.getName()
- .compareTo( p2.getName() );
- }
- return -1;
- }
- };
-
- private static final long serialVersionUID = 7621696882809002180L;
-
- protected Map attributes;
- protected DynaProperty dynaProperties[];
- protected Class jsonBeanClass;
- protected String name;
- protected Map properties = new HashMap();
- protected Class type;
-
- public JSONDynaClass( String name, Class type, Map attributes )
- {
- this.name = name;
- this.type = type;
- this.attributes = attributes;
- process();
- }
-
- public boolean equals( Object obj )
- {
- if( this == obj ){
- return true;
- }
-
- if( obj == null ){
- return false;
- }
-
- if( !(obj instanceof JSONDynaClass) ){
- return false;
- }
-
- JSONDynaClass other = (JSONDynaClass) obj;
- EqualsBuilder builder = new EqualsBuilder().append( this.name, other.name )
- .append( this.type, other.type );
- if( dynaProperties.length != other.dynaProperties.length ){
- return false;
- }
- for( int i = 0; i < dynaProperties.length; i++ ){
- DynaProperty a = this.dynaProperties[i];
- DynaProperty b = other.dynaProperties[i];
- builder.append( a.getName(), b.getName() );
- builder.append( a.getType(), b.getType() );
- }
- return builder.isEquals();
- }
-
- public DynaProperty[] getDynaProperties()
- {
- return dynaProperties;
- }
-
- public DynaProperty getDynaProperty( String propertyName )
- {
- if( propertyName == null ){
- throw new JSONException( "Unnespecified bean property name" );
-
- }
- return (DynaProperty) properties.get( propertyName );
- }
-
- public String getName()
- {
- return this.name;
- }
-
- public int hashCode()
- {
- HashCodeBuilder builder = new HashCodeBuilder().append( name )
- .append( type );
- for( int i = 0; i < dynaProperties.length; i++ ){
- builder.append( this.dynaProperties[i].getName() );
- builder.append( this.dynaProperties[i].getType() );
- }
- return builder.toHashCode();
- }
-
- public DynaBean newInstance() throws IllegalAccessException, InstantiationException
- {
- JSONDynaBean dynaBean = (JSONDynaBean) getJsonBeanClass().newInstance();
- dynaBean.setDynaBeanClass( this );
- Iterator keys = attributes.keySet()
- .iterator();
- while( keys.hasNext() ){
- String key = (String) keys.next();
- dynaBean.set( key, null );
- }
- return dynaBean;
- }
-
- public String toString()
- {
- return new ToStringBuilder( this ).append( "name", this.name )
- .append( "type", this.type )
- .append( "attributes", this.attributes )
- .toString();
- }
-
- protected Class getJsonBeanClass()
- {
- if( this.jsonBeanClass == null ){
- process();
- }
- return this.jsonBeanClass;
- }
-
- private void process()
- {
- this.jsonBeanClass = this.type;
-
- if( !JSONDynaBean.class.isAssignableFrom( this.jsonBeanClass ) ){
- throw new JSONException( "Unnasignable dynaClass " + jsonBeanClass );
- }
-
- try{
- Iterator entries = attributes.entrySet()
- .iterator();
- dynaProperties = new DynaProperty[attributes.size()];
- int i = 0;
- while( entries.hasNext() ){
- Map.Entry entry = (Map.Entry) entries.next();
- String pname = (String) entry.getKey();
- Object pclass = entry.getValue();
- DynaProperty dynaProperty = null;
- if( pclass instanceof String ){
- Class klass = (Class) Class.forName( (String) pclass );
- if( klass.isArray() && klass.getComponentType()
- .isArray() ){
- throw new JSONException( "Multidimensional arrays are not supported" );
- }
- dynaProperty = new DynaProperty( pname, klass );
- }else if( pclass instanceof Class ){
- Class klass = (Class) pclass;
- if( klass.isArray() && klass.getComponentType()
- .isArray() ){
- throw new JSONException( "Multidimensional arrays are not supported" );
- }
- dynaProperty = new DynaProperty( pname, klass );
- }else{
- throw new JSONException( "Type must be String or Class" );
- }
- properties.put( dynaProperty.getName(), dynaProperty );
- dynaProperties[i++] = dynaProperty;
- }
- }
- catch( ClassNotFoundException cnfe ){
- throw new JSONException( cnfe );
- }
-
- // keep properties sorted by name
- Arrays.sort( dynaProperties, 0, dynaProperties.length, dynaPropertyComparator );
- }
-}
Please sign in to comment.
Something went wrong with that request. Please try again.