litesoft
@ 950
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 |
// This Source Code is in the Public Domain per: http://unlicense.org package org.litesoft.aokeyhole.objects.factories; import org.litesoft.aokeyhole.objects.*; import org.litesoft.aokeyhole.objects.attributes.*; import org.litesoft.aokeyhole.objects.support.*; import org.litesoft.aokeyhole.toolkit.*; import java.util.*; public class AttributeFactoryImpl implements AttributeFactory { private PropertyMetaDataDefinitionAccessor mPropertyMetaDataDefinitionAccessor; private IdentifierValidator mAttributeIdentifierValidator; private String mTypesForError; private Map<String, AttributeSet> mSetsByType = new HashMap<String, AttributeSet>(); public AttributeFactoryImpl( PropertyMetaDataDefinitionAccessor pPropertyMetaDataDefinitionAccessor, IdentifierValidator pAttributeIdentifierValidator ) { mPropertyMetaDataDefinitionAccessor = pPropertyMetaDataDefinitionAccessor; mAttributeIdentifierValidator = pAttributeIdentifierValidator; List<String> zTypes = new ArrayList<String>(); for ( AttributeSet zSet : getAttributeSets() ) { zSet.addTypeOptions( zTypes ); mSetsByType.put( zSet.getType().toString(), zSet ); } if ( zTypes.size() == 1 ) { mTypesForError = ": " + zTypes.get( 0 ); } else { mTypesForError = " one of: " + zTypes.get( 0 ); for ( int i = 1; i < zTypes.size(); i++ ) { mTypesForError += ", " + zTypes.get( i ); } } } @Override public String getTypesForError() { return mTypesForError; } @Override public AttributeSet[] getAttributeSets() { return mPropertyMetaDataDefinitionAccessor.getAttributeSets(); } @Override public AttributeMetaData createAttributeMetaDataSimple( ObjectSet pObjectSet, Mode pMode, boolean pEditable, AttributeType pType, boolean pVirtual, String pName ) { AttributeSet zAttributeSet = mSetsByType.get( pType.toString() ); ASet zASet = pVirtual ? zAttributeSet.getVirtual() : zAttributeSet.getPersisted(); AttributeMetaDataSimple zAMD = new AttributeMetaDataSimple( zAttributeSet, pMode, pEditable, pVirtual, adjust( pObjectSet, pType, zASet ), mAttributeIdentifierValidator, pName ); handleCallBack( zASet, zAMD ); return zAMD; } @Override public AttributeMetaData createAttributeMetaDataID( ObjectSet pObjectSet, Mode pMode, boolean pEditable, String pName ) { AttributeType zType = A_ID.TYPE; AttributeSet zAttributeSet = mSetsByType.get( zType.toString() ); ASet zASet = zAttributeSet.getPersisted(); AttributeMetaData zAMD = new AttributeMetaDataSimpleID( zAttributeSet, pMode, pEditable, adjust( pObjectSet, zType, zASet ), mAttributeIdentifierValidator, pName ); handleCallBack( zASet, zAMD ); return zAMD; } @Override public AttributeMetaData createAttributeMetaDataValidOptions( ObjectSet pObjectSet, Mode pMode, boolean pEditable, AttributeType pType, boolean pVirtual, String pName, String... pOptions ) { AttributeSet zAttributeSet = mSetsByType.get( pType.toString() ); ASet zASet = pVirtual ? zAttributeSet.getVirtual() : zAttributeSet.getPersisted(); AttributeMetaData zAMD = new AttributeMetaDataValidOptions( zAttributeSet, pMode, pEditable, pVirtual, adjust( pObjectSet, pType, zASet ), mAttributeIdentifierValidator, pName, pOptions ); handleCallBack( zASet, zAMD ); return zAMD; } @Override public AttributeMetaDataRelatedPersisted createAttributeMetaDataRelatedPersisted( ObjectSet pObjectSet, Mode pMode, boolean pEditable, AttributeType pType, String pName ) { AttributeSet zAttributeSet = mSetsByType.get( pType.toString() ); ASet zASet = zAttributeSet.getPersisted(); AttributeMetaDataRelatedPersisted zAMD = new AttributeMetaDataRelatedPersisted( zAttributeSet, pMode, pEditable, adjust( pObjectSet, pType, zASet ), mAttributeIdentifierValidator, pName ); handleCallBack( zASet, zAMD ); return zAMD; } @Override public AttributeMetaDataRelatedVirtual createAttributeMetaDataRelatedVirtual( ObjectSet pObjectSet, Mode pMode, boolean pEditable, AttributeType pType, String pName ) { AttributeSet zAttributeSet = mSetsByType.get( pType.toString() ); ASet zASet = zAttributeSet.getVirtual(); AttributeMetaDataRelatedVirtual zAMD = new AttributeMetaDataRelatedVirtual( zAttributeSet, pMode, pEditable, adjust( pObjectSet, pType, zASet ), mAttributeIdentifierValidator, pName ); handleCallBack( zASet, zAMD ); return zAMD; } private void handleCallBack( ASet pASet, AttributeMetaData pAMD ) { AttributeCreationCallBack zCallBack = pASet.getCreationCallBack(); if ( zCallBack != null ) { zCallBack.justCreated( pAMD ); } } protected PropertyMetaData[] adjust( ObjectSet pObjectSet, AttributeType pType, ASet pASet ) { List<PropertyMetaData> rv = new ArrayList<PropertyMetaData>(); addAll( rv, pObjectSet, pASet.getPMDs() ); addAll( rv, pObjectSet, pObjectSet.getAdditionalAttributePMDs( pType ) ); return rv.toArray( new PropertyMetaData[rv.size()] ); } private void addAll( List<PropertyMetaData> pCollector, ObjectSet pObjectSet, PropertyMetaData[] pPMDs ) { if ( pPMDs != null ) { for ( PropertyMetaData zPMD : pPMDs ) { if ( pObjectSet.acceptableAttributePMD( zPMD ) ) { pCollector.add( zPMD ); } } } } } |
Commits for litesoft/trunk/Java/KeyHole/src/org/litesoft/aokeyhole/objects/factories/AttributeFactoryImpl.java
Revision | Author | Commited | Message |
---|---|---|---|
950 Diff | GeorgeS | Thu 19 Jun, 2014 17:57:04 +0000 | New Lines |
948 Diff | GeorgeS | Sat 07 Jun, 2014 23:42:39 +0000 | Jusefuls Formatter Updated to New Code Format |
947 Diff | GeorgeS | Fri 06 Jun, 2014 23:36:56 +0000 | Correct Spelling of package! |
787 Diff | GeorgeS | Mon 30 Jul, 2012 03:00:12 +0000 | |
49 Diff | GeorgeS | Mon 12 Apr, 2010 02:59:10 +0000 | License Text |
17 Diff | GeorgeS | Thu 18 Feb, 2010 23:54:44 +0000 | |
6 Diff | GeorgeS | Tue 09 Feb, 2010 00:10:56 +0000 | Open Options |
2 | GeorgeS | Sun 07 Feb, 2010 12:50:58 +0000 |