litesoft
@ 821
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 |
package org.litesoft.aokeyhole.swing.mains.mementobeans; import org.litesoft.aokeyhole.objects.factories.*; import org.litesoft.aokeyhole.objects.factories.mementobean.*; import org.litesoft.core.typeutils.*; public class AttributeData implements BeanMagicStrings { private static final String[] VALID_TYPES = extractValidTypes( MementoBeanPropertyMetaDataDefinitionAccessor.INSTANCE ); private int mID; private String mName; private String mType; private boolean mMementoableType; private boolean mRepeating; private String[] mNotes; public int getID() { return mID; } public String getName() { return mName; } public String getType() { return mType; } public boolean isMementoableType() { return mMementoableType; } public boolean isRepeating() { return mRepeating; } public String[] getNotes() { return mNotes; } public void setNotes( String[] pNotes ) { mNotes = pNotes; } /** * An ID is a 2 digit value (with leading zeros) between 0 & 99 */ private void parseID( String pID ) { mID = Integer.parseInt( pID ); } /** * Parse the Pre & Post type indicators. * * @param pPreType an AttributeProxy type: Mementoable, String, Integer, ... * @param pBracketedPostType Either an empty String of the class name of the Mementoable surrounded by generic type indicators ('<' & '>'). */ private void parseType( String pPreType, String pBracketedPostType ) { // "String" & "" || "Mementoable" & "<DetailBean>" if ( !MEMENTOABLE_ATTRIBUTE_PROXY_TYPE.equals( pPreType ) ) { // Strings.assertEmpty( "BracketedPostType", pBracketedPostType ); // mType = Objects.assertOneOf( pPreType, VALID_TYPES ); return; } mMementoableType = true; if ( pBracketedPostType.startsWith( "<" ) && pBracketedPostType.endsWith( ">" ) ) { mType = pBracketedPostType.substring( 1, pBracketedPostType.length() - 1 ); if ( Strings.isValidAttributeIdentifier( mType ) ) { return; } } throw new IllegalArgumentException( "Unacceptable BracketedPostType: " + pBracketedPostType ); } /** * Parse the name from the Attribute Proxy's Parameters. */ private void parseName( String pAttributeProxyParameters ) { // A string of 'null' which indicates that this is a legacy place holder // Single (double quoted) Names, e.g.: "FirstName", "Name", "Description" // or the above followed by a default instance, like: // "SpecialDetail", DetailBean.DEFAULT_INSTANCE // "Details", DetailBean.DEFAULT_INSTANCE String zName = pAttributeProxyParameters; if ( mMementoableType ) { String zDefaultInstanceTail = ", " + mType + ".DEFAULT_INSTANCE"; if ( !pAttributeProxyParameters.endsWith( zDefaultInstanceTail ) ) { throw new IllegalArgumentException( "Mementoable attribute proxy, but not default instance in the parameter section: " + pAttributeProxyParameters ); } zName = pAttributeProxyParameters.substring( 0, pAttributeProxyParameters.length() - zDefaultInstanceTail.length() ); } // TODO: !!!!! } // /* 00 */ new StringAttributeProxy( "FirstName" ), // // /* 00 */ new StringAttributeProxy( "Name" ).nullEmpties(), // // /* 01 */ new StringAttributeProxy( null ), // // /* 02 */ new StringAttributeProxy( "Description" ).nullEmpties().repeating(), // // /* 03 */ new MementoableAttributeProxy<DetailBean>( "SpecialDetail", DetailBean.DEFAULT_INSTANCE ).nullEmpties(), // // 01234567-10123 // /* 04 */ new MementoableAttributeProxy<DetailBean>( "Details", DetailBean.DEFAULT_INSTANCE ).nullEmpties().repeating(), // // 123 12345678 12345678901234 12 12 1234 // 0 1 2 3 4 5 6 7 8 9 10 private void parseFlags( String pSubstring ) { //To change body of created methods use File | Settings | File Templates. // TODO: !!!!! } public static AttributeData parseLine( String pLine ) { // /* 00 */ new StringAttributeProxy( "FirstName" ), // // /* 00 */ new StringAttributeProxy( "Name" ).nullEmpties(), // // /* 01 */ new StringAttributeProxy( null ), // // /* 02 */ new StringAttributeProxy( "Description" ).nullEmpties().repeating(), // // /* 03 */ new MementoableAttributeProxy<DetailBean>( "SpecialDetail", DetailBean.DEFAULT_INSTANCE ).nullEmpties(), // // 01234567-10123 // /* 04 */ new MementoableAttributeProxy<DetailBean>( "Details", DetailBean.DEFAULT_INSTANCE ).nullEmpties().repeating(), // // 123 12345678 12345678901234 12 12 1234 // 0 1 2 3 4 5 6 7 8 9 10 int atPart2 = pLine.indexOf( ATTR_PART2 ); int atPart4 = pLine.indexOf( ATTR_PART4, atPart2 + 1 ); int atPart6 = pLine.indexOf( ATTR_PART6, atPart4 + 1 ); int atPart8 = pLine.indexOf( ATTR_PART8, atPart6 + 1 ); if ( pLine.startsWith( ATTR_PART0 ) && // (atPart2 != -1) && (atPart4 != -1) && (atPart6 != -1) && (atPart8 != -1) && // pLine.endsWith( ATTR_PART10 ) ) { AttributeData zAttribute = new AttributeData(); try { zAttribute.parseID( pLine.substring( 3, atPart2 ) ); zAttribute.parseType( pLine.substring( 13, atPart4 ), pLine.substring( atPart4 + 14, atPart6 ) ); zAttribute.parseName( pLine.substring( atPart6 + 2, atPart8 ) ); zAttribute.parseFlags( pLine.substring( atPart8 + 2, pLine.length() - 4 ) ); return zAttribute; } catch ( IllegalArgumentException e ) { // Fall thru... } } return null; } private static String[] extractValidTypes( PropertyMetaDataDefinitionAccessor pAccessor ) { return new String[0]; //To change body of created methods use File | Settings | File Templates. } } |