Subversion Repository Public Repository

litesoft

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
// This Source Code is in the Public Domain per: http://litesoft.org/License.txt
package org.litesoft.orsup.otherattributeaccessors;

import org.litesoft.commonfoundation.typeutils.*;
import org.litesoft.logger.*;
import org.litesoft.orsup.base.*;

public abstract class AttributeAccessorSCDpath
{
    protected static final Logger LOGGER = LoggerFactory.getLogger( AttributeAccessorSCDpath.class );

    public static class Node
    {
        private MetaDataForPO mPOmd;
        private AttributeAccessorSCD mAttributeAccessor;

        public Node( MetaDataForPO pPOmd, AttributeAccessorSCD pAttributeAccessor )
        {
            mPOmd = pPOmd;
            mAttributeAccessor = pAttributeAccessor;
        }

        public MetaDataForPO getPOmd()
        {
            return mPOmd;
        }

        public AttributeAccessorSCD getAttributeAccessor()
        {
            return mAttributeAccessor;
        }
    }

    private Finder mFinder;
    private MetaDataForPO mPOmd;

    /**
     * @param pFinder Finder to support look-up and ...
     * @param pPOmd   Starting PO metadata
     */
    public AttributeAccessorSCDpath( Finder pFinder, MetaDataForPO pPOmd )
    {
        mFinder = pFinder;
        mPOmd = pPOmd;
    }

    /**
     * Create a path of AttributeAccessorSCDpathNode, where if any attribute reference(s) does not resolve, null is returned!
     *
     * @param pDottedAttributereference Attribute reference(s) (separated by dots ('.'))
     *
     * @return [0...n] nodes of the path.  [0] is the start (will have the pPOmd in it) and [n] will be the end. OR null if any attribute reference(s) do not resolve.
     */
    public Node[] createPath( String pDottedAttributereference )
    {
        MetaDataForPO zPOmd = mPOmd;
        String[] zReferences = parseDottedAttributeReference( pDottedAttributereference );
        Node[] rv = new Node[zReferences.length];
        AttributeAccessorSCD zSCD;
        int zLastIndex = zReferences.length - 1;
        for ( int i = 0; i < zLastIndex; i++ )
        {
            if ( null == (zSCD = getAccessorSCD( rv, i, pDottedAttributereference, zPOmd, zReferences[i] )) )
            {
                return null;
            }
            if ( null == (zPOmd = getAcceptableRelationship( zSCD )) )
            {
                unacceptableRelationship( rv, i, pDottedAttributereference );
                return null;
            }
        }
        if ( null == (zSCD = getAccessorSCD( rv, zLastIndex, pDottedAttributereference, zPOmd, zReferences[zLastIndex] )) )
        {
            return null;
        }
        if ( !isAcceptableLeaf( zSCD ) )
        {
            unacceptableLeaf( rv, zLastIndex, pDottedAttributereference );
            return null;
        }
        return rv;
    }

    protected static void unacceptableLeaf( Node[] pTarget, int pIndex, String pDottedAttributereference )
    {
        if ( pTarget.length == 1 )
        {
            LOGGER.error.log( "Unacceptable Attribute (", pTarget[pIndex].getAttributeAccessor().getName(), ") type on PO: ", pTarget[pIndex].getPOmd().getPOregistrationName() );
        }
        else
        {
            LOGGER.error.log( unacceptable( pTarget, pIndex, "Last" ), " type", tail( pTarget, pIndex, pDottedAttributereference ) );
        }
    }

    protected static void unacceptableRelationship( Node[] pTarget, int pIndex, String pDottedAttributereference )
    {
        LOGGER.error.log( unacceptable( pTarget, pIndex, Integers.toNth( pIndex + 1 ) + " 'pre-dot'" ), tail( pTarget, pIndex, pDottedAttributereference ) );
    }

    protected static String unacceptable( Node[] pTarget, int pIndex, String pWhat )
    {
        return "Unacceptable " + pWhat + " Attribute (" + pTarget[pIndex].getAttributeAccessor().getName() + " on PO: " + pTarget[pIndex].getPOmd().getPOregistrationName() + ")";
    }

    protected AttributeAccessorSCD getAccessorSCD( Node[] pTarget, int pIndex, String pDottedAttributereference, MetaDataForPO pPOmd, String pReference )
    {
        AttributeAccessorSCD zSCD = pPOmd.getAccessorSCDoptional( pReference );
        if ( zSCD != null )
        {
            pTarget[pIndex] = new Node( pPOmd, zSCD );
            return zSCD;
        }
        if ( pTarget.length == 1 )
        {
            LOGGER.error.log( "Unknown Attribute (", pReference, ") on PO: ", pPOmd.getPOregistrationName() );
        }
        else
        {
            LOGGER.error.log( "Unknown ", Integers.toNth( pIndex + 1 ), " Attribute (", pReference, " on PO: ", pPOmd.getPOregistrationName(), ")", tail( pTarget, pIndex, pDottedAttributereference ) );
        }
        return null;
    }

    protected static String tail( Node[] pTarget, int pIndex, String pDottedAttributereference )
    {
        return " from Reference '" + pDottedAttributereference + ((pIndex == 0) ? "'" : "' from PO: " + pTarget[0].getPOmd().getPOregistrationName());
    }

    protected static String[] parseDottedAttributeReference( String pDottedAttributereference )
    {
        pDottedAttributereference = Strings.assertNotNullNotEmpty( "DottedAttributereference", pDottedAttributereference );
        String[] zReferences = Strings.parseChar( pDottedAttributereference, '.' );
        for ( int i = 0; i < zReferences.length; i++ )
        {
            if ( null == (zReferences[i] = Strings.noEmpty( zReferences[i] )) )
            {
                throw new IllegalArgumentException( Integers.toNth( i + 1 ) + " Reference empty!" );
            }
        }
        return zReferences;
    }

    protected MetaDataForPO getAcceptableRelationship( AttributeAccessorSCD pSCD )
    {
        if ( pSCD instanceof AbstractAttributeAccessorSCDtoPO )
        {
            String zToThemName = ((AbstractAttributeAccessorSCDtoPO) pSCD).getToThemName();
            if ( zToThemName != null )
            {
                return mFinder.getOptionalMetaDataForPO( zToThemName );
            }
        }
        return null;
    }

    abstract protected boolean isAcceptableLeaf( AttributeAccessorSCD pSCD );
}

Commits for litesoft/trunk/Java/core/Server/src/org/litesoft/orsup/otherattributeaccessors/AttributeAccessorSCDpath.java

Diff revisions: vs.
Revision Author Commited Message
939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

821 Diff Diff GeorgeS picture GeorgeS Sun 19 Aug, 2012 00:08:41 +0000
819 Diff Diff GeorgeS picture GeorgeS Sat 18 Aug, 2012 18:09:40 +0000
802 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 04:04:47 +0000
801 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 03:59:02 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000