001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.dto.cognos; 014 015import org.apache.juneau.annotation.*; 016import org.apache.juneau.transform.*; 017import org.apache.juneau.xml.annotation.*; 018 019/** 020 * Represents a meta-data column in a Cognos dataset. 021 * 022 * <p> 023 * When serialized to XML, creates the following construct: 024 * <p class='bcode'> 025 * <xt><item</xt> <xa>name</xa>=<xs>'name'</xs> <xa>type</xa>=<xs>'xs:String'</xs> <xa>length</xa>=<xs>'255'</xs>/> 026 * </p> 027 */ 028@SuppressWarnings({"rawtypes"}) 029@Bean(typeName="item", properties="name,type,length") 030public class Column { 031 032 private String name, type; 033 private Integer length; 034 PojoSwap pojoSwap; 035 036 /** Bean constructor. */ 037 public Column() {} 038 039 /** 040 * Constructor. 041 * 042 * @param name The column name. 043 * @param type The column type (e.g. <js>"xs:String"</js>). 044 */ 045 public Column(String name, String type) { 046 this(name, type, null); 047 } 048 049 /** 050 * Constructor. 051 * 052 * @param name The column name. 053 * @param type The column type (e.g. <js>"xs:String"</js>). 054 * @param length The column length (e.g. <code>255</code>). 055 */ 056 public Column(String name, String type, Integer length) { 057 this.name = name; 058 this.type = type; 059 this.length = length; 060 } 061 062 /** 063 * Associates a POJO swap with this column. 064 * 065 * <p> 066 * Typically used to define columns that don't exist on the underlying beans being serialized. 067 * 068 * <p> 069 * For example, the <code>AddressBookResource</code> sample defined the following POJO swap to define an additional 070 * <js>"numAddresses"</js> column even though no such property exists on the serialized beans. 071 * <p class='bcode'> 072 * Column c = <jk>new</jk> Column(<js>"numAddresses"</js>, <js>"xs:int"</js>) 073 * .addPojoSwaps( 074 * <jk>new</jk> PojoSwap<Person,Integer>() { 075 * <ja>@Override</ja> 076 * <jk>public</jk> Integer swap(Person p) { 077 * <jk>return</jk> p.<jf>addresses</jf>.size(); 078 * } 079 * } 080 * ); 081 * </p> 082 * 083 * @param pojoSwap The POJO swap to associate with the column. 084 * @return This object (for method chaining). 085 */ 086 public Column addPojoSwap(PojoSwap pojoSwap) { 087 this.pojoSwap = pojoSwap; 088 return this; 089 } 090 091 092 //-------------------------------------------------------------------------------- 093 // Bean properties 094 //-------------------------------------------------------------------------------- 095 096 /** 097 * Bean property getter: <property>name</property>. 098 * 099 * @return The value of the <property>name</property> property on this bean, or <jk>null</jk> if it is not set. 100 */ 101 @Xml(format=XmlFormat.ATTR) 102 public String getName() { 103 return name; 104 } 105 106 /** 107 * Bean property setter: <property>name</property>. 108 * 109 * @param name The new value for the <property>name</property> property on this bean. 110 * @return This object (for method chaining). 111 */ 112 public Column setName(String name) { 113 this.name = name; 114 return this; 115 } 116 117 /** 118 * Bean property getter: <property>type</property>. 119 * 120 * @return The value of the <property>type</property> property on this bean, or <jk>null</jk> if it is not set. 121 */ 122 @Xml(format=XmlFormat.ATTR) 123 public String getType() { 124 return type; 125 } 126 127 /** 128 * Bean property setter: <property>type</property>. 129 * 130 * @param type The new value for the <property>type</property> property on this bean. 131 * @return This object (for method chaining). 132 */ 133 public Column setType(String type) { 134 this.type = type; 135 return this; 136 } 137 138 /** 139 * Bean property getter: <property>length</property>. 140 * 141 * @return The value of the <property>length</property> property on this bean, or <jk>null</jk> if length is not 142 * applicable for the specified type. 143 */ 144 @Xml(format=XmlFormat.ATTR) 145 public Integer getLength() { 146 return length; 147 } 148 149 /** 150 * Bean property setter: <property>length</property>. 151 * 152 * @param length The new value for the <property>length</property> property on this bean. 153 * Can be <jk>null</jk> if length is not applicable for the specified type. 154 * @return This object (for method chaining). 155 */ 156 public Column setLength(Integer length) { 157 this.length = length; 158 return this; 159 } 160} 161