makestruct revision 883
883N/A#!/bin/ksh -p
883N/A#
883N/A# CDDL HEADER START
883N/A#
883N/A# The contents of this file are subject to the terms of the
883N/A# Common Development and Distribution License (the "License").
883N/A# You may not use this file except in compliance with the License.
883N/A#
883N/A# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
883N/A# or http://www.opensolaris.org/os/licensing.
883N/A# See the License for the specific language governing permissions
883N/A# and limitations under the License.
883N/A#
883N/A# When distributing Covered Code, include this CDDL HEADER in each
883N/A# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
883N/A# If applicable, add the following below this CDDL HEADER, with the
883N/A# fields enclosed by brackets "[]" replaced with your own identifying
883N/A# information: Portions Copyright [yyyy] [name of copyright owner]
883N/A#
883N/A# CDDL HEADER END
883N/A#
883N/A
883N/A#
883N/A# Copyright (c) 2008, 2012, Oracle and/or its affiliates. All rights reserved.
883N/A#
883N/A
883N/Aexport LC_ALL=C
883N/A
883N/Aset -A types
883N/Aset -A props
883N/Aset -A range
883N/A
883N/Apkg=
883N/A
883N/Awhile getopts i:o: x; do
883N/A case $x in
883N/A i) pkg=`echo ${OPTARG%/*} | sed -e s,/,.,g`
883N/A class=`basename $OPTARG .in`
883N/A exec < $OPTARG
883N/A ;;
883N/A o) mkdir -p `dirname $OPTARG`
883N/A exec > $OPTARG
883N/A ;;
883N/A esac
883N/Adone
883N/Ashift $(($OPTIND - 1))
883N/A
883N/Aif [[ -z "$pkg" ]]; then
883N/A pkg=$1
883N/A class=$2
883N/Afi
883N/A
883N/Aecho "package $pkg;"
883N/Aecho
883N/Aecho "import java.beans.*;"
883N/Aecho "import java.io.Serializable;"
883N/A
883N/Ainteger i=0
883N/Awhile read type prop cmt ; do
883N/A test -z "$type" && break
883N/A
883N/A if [[ "$type" = "import" ]]; then
883N/A echo "$type $prop"
883N/A continue;
883N/A fi
883N/A types[${#types[*]}]=$type
883N/A props[${#props[*]}]=$prop
883N/A cmts[${#cmts[*]}]=$cmt
883N/A range[$i]=$i
883N/A i=$((i+1))
883N/Adone
883N/A
883N/Aecho
883N/Aecho "public class $class implements Serializable"
883N/Aecho "{"
883N/Aecho "\tprivate static final long serialVersionUID = 1;"
883N/A
883N/A# instance variables
883N/Afor i in ${range[*]}; do
883N/A echo "\tprivate ${types[$i]} ${props[$i]}_;"
883N/Adone
883N/Aecho
883N/A
883N/A# constructor properties
883N/Aecho "\t@ConstructorProperties({\c"
883N/Afor i in ${range[*]}; do
883N/A [[ $i -ne 0 ]] && echo ", \c"
883N/A echo "\"${props[$i]}\"\c"
883N/Adone
883N/Aecho "})"
883N/A
883N/A# constructor
883N/Aecho "\tpublic $class(\c"
883N/Afor i in ${range[*]}; do
883N/A [[ $i -ne 0 ]] && echo ", \c"
883N/A echo "${types[$i]} ${props[$i]}\c"
883N/Adone
883N/Aecho ") {"
883N/Afor i in ${range[*]}; do
883N/A echo "\t\t${props[$i]}_ = ${props[$i]};"
883N/Adone
883N/Aecho "\t}"
883N/A
883N/A# methods
883N/Afor i in ${range[*]}; do
883N/A prop=${props[$i]}
883N/A type=${types[$i]}
883N/A cmt=${cmts[$i]}
883N/A cap=`echo $prop | cut -c1 | tr '[:lower:]' '[:upper:]'`
883N/A cprop="$cap"`echo $prop | cut -c2-`
883N/A
883N/A # accessor
883N/A echo
883N/A if [[ -n $cmt ]]; then
883N/A echo "\t/**"
883N/A echo "\t * $cmt"
883N/A echo "\t */"
883N/A fi
883N/A if [[ $type = "boolean" ]] || [[ $type = "Boolean" ]]; then
883N/A echo "\tpublic $type is$cprop()"
883N/A else
883N/A echo "\tpublic $type get$cprop()"
883N/A fi
883N/A echo "\t{"
883N/A echo "\t\treturn (${prop}_);"
883N/A echo "\t}"
883N/A
883N/A # mutator
883N/A echo
883N/A echo "\tpublic void set$cprop($type $prop)"
883N/A echo "\t{"
883N/A echo "\t\t${prop}_ = $prop;"
883N/A echo "\t}"
883N/Adone
883N/A
883N/A# verbatim additions
883N/Acat
883N/A
883N/Aecho "}"