litesoft
@ 939
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 |
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt package org.litesoft.bo.views; import org.litesoft.bo.*; import org.litesoft.bo.attributes.*; import org.litesoft.commonfoundation.typeutils.Objects; import org.litesoft.core.util.*; import java.io.*; import java.util.*; public abstract class AbstractVoMetaData<V extends ViewObject> implements VoMetaData<V>, VoNames, BuildAMDs { private final Class<V> mViewObjectClass; private final String mObjectName; private final VAMap<V> mAttributesByName = new VAMap<V>(); private final BoAttribute[] mAttributes; private final String[] mAttributeNames; protected AbstractVoMetaData( Class<V> pViewObjectClass, VoAttributeList<V> pAttributes ) { mObjectName = Objects.justClassName( mViewObjectClass = pViewObjectClass ); List<BoAttribute> zAttributes = new ArrayList<BoAttribute>(); List<String> zNames = new ArrayList<String>(); add( zAttributes, zNames, getAttrNewID() ); if ( pAttributes != null ) { for ( VoAttribute<V> zAttribute : pAttributes ) { if ( zAttribute != null ) { add( zAttributes, zNames, zAttribute ); } } } if ( zAttributes.size() == 1 ) { throw new IllegalStateException( "ViewObject Meta Data, with NO Attributes" ); } mAttributes = zAttributes.toArray( new BoAttribute[zAttributes.size()] ); mAttributeNames = zNames.toArray( new String[zNames.size()] ); } private void add( List<BoAttribute> pAttributes, List<String> pNames, VoAttribute<V> zAttribute ) { String zName = zAttribute.getName(); pNames.add( zName ); pAttributes.add( zAttribute ); mAttributesByName.put( zName, zAttribute ); } public Class<V> getViewObjectClass() { return mViewObjectClass; } // BoMetaData... public final String[] getAttributeNames() { return mAttributeNames; } public final BoAttribute getBoAttribute( String pAttributeName ) throws NoSuchElementException { return getVoAttribute( pAttributeName ); } public final BoAttribute[] getBoAttributes() { return mAttributes; } // ExtendedBoMetaData... public final VoAttribute<V> getVoAttribute( String pAttributeName ) throws NoSuchElementException { VoAttribute<V> zAttribute = mAttributesByName.get( pAttributeName ); if ( zAttribute != null ) { return zAttribute; } throw new NoSuchElementException( "No Attribute for name '" + pAttributeName + "'" ); } public String getDerivedFromAttributePath( String pAttributeName ) { VoAttribute<V> zAttribute = mAttributesByName.get( pAttributeName ); return (zAttribute != null) ? zAttribute.getDerivedFromAttributePath() : null; } public final String getObjectName() { return mObjectName; } public ObjectUniqueKey createObjectUniqueKey( BoAccessor pBoAccessor ) { return createNewObjectUniqueKey( pBoAccessor ); } protected ObjectUniqueKey createNewObjectUniqueKey( BoAccessor pBoAccessor ) { return ObjectUniqueKey.createNew( ((IViewObject) pBoAccessor).getNewID() ); } private static class VAMap<X extends ViewObject> extends HashMap<String, VoAttribute<X>> implements Serializable { private static final long serialVersionUID = 1L; } @SuppressWarnings({"unchecked"}) private VoAttribute<V> getAttrNewID() { return (VoAttribute<V>) ATTR_NewID; } private static final VoAttribute<ViewObject> ATTR_NewID = new SimpleVoAttribute<ViewObject>( aNewID, false, _Long.RO() ) { public String getDerivedFromAttributePath() { return null; } public boolean isQueryViewAttribute() { return false; } protected Object LLgetAttributeValue( ViewObject pVO ) { return pVO.getNewID(); } public void setAttributeValue( ViewObject pVO, Object pValue ) throws AttributeIllegalArgumentException { pVO.setNewID( TypeConverter.to_Long( pValue ) ); } }; protected UnsupportedOperationException unavailableMethod() { return new UnsupportedOperationException( "Method unavailable on Parent MetaData - should have been overiden / use appropriate child/leaf" ); } protected static class VoAttributeList<T extends IViewObject> extends ArrayList<VoAttribute<T>> { public VoAttributeList( VoAttribute... pAttributes ) { if ( pAttributes != null ) { for ( VoAttribute zAttribute : pAttributes ) { if ( zAttribute != null ) { addAttribute( zAttribute ); } } } } public VoAttributeList<T> augment( VoAttributeList<? extends T> pParentList ) { for ( VoAttribute<? extends T> zAttribute : pParentList ) { if ( "ID".equals( zAttribute.getName() ) ) { insertIDAttribute( zAttribute ); } else { addAttribute( zAttribute ); } } return this; } @SuppressWarnings({"unchecked"}) private void addAttribute( VoAttribute zAttribute ) { add( zAttribute ); } @SuppressWarnings({"unchecked"}) private void insertIDAttribute( VoAttribute zAttribute ) { add( 0, zAttribute ); } } } |
Commits for litesoft/trunk/Java/core/Anywhere/src/org/litesoft/bo/views/AbstractVoMetaData.java
Revision | Author | Commited | Message |
---|---|---|---|
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
917 Diff | GeorgeS | Sun 08 Dec, 2013 20:49:56 +0000 | 1.7 prep & VersionedStaticContentFilter upgrade to new “/ver” model! |
849 Diff | GeorgeS | Tue 11 Sep, 2012 17:11:59 +0000 | Clean up serialization |
811 Diff | GeorgeS | Sat 18 Aug, 2012 13:45:18 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |