Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/InitFrom/src/org/litesoft/initfrom/server/CurrentRestrictedResourceAccessor.java

Diff revisions: vs.
  @@ -8,14 +8,11 @@
8 8 import org.litesoft.initfrom.server.boviews.podataproviders.*;
9 9 import org.litesoft.initfrom.server.pos.*;
10 10
11 - public class CurrentRestrictedResourceAccessor implements ServerStateChangedListener
12 - {
13 - public static synchronized CurrentRestrictedResourceAccessor get()
14 - {
11 + public class CurrentRestrictedResourceAccessor implements ServerStateChangedListener {
12 + public static synchronized CurrentRestrictedResourceAccessor get() {
15 13 ServerStore zStore = ServerContext.get().getServerStore();
16 14 CurrentRestrictedResourceAccessor zAccessor = zStore.get( CurrentRestrictedResourceAccessor.class );
17 - if ( zAccessor == null )
18 - {
15 + if ( zAccessor == null ) {
19 16 zStore.set( CurrentRestrictedResourceAccessor.class, zAccessor = new CurrentRestrictedResourceAccessor() );
20 17 }
21 18 return zAccessor;
  @@ -25,127 +22,105 @@
25 22 private ChangeListenerManager mRegisteredWithCLM;
26 23 private RestrictedResource mPO;
27 24
28 - public RestrictedResource getRequiredRestrictedResource()
29 - {
25 + public RestrictedResource getRequiredRestrictedResource() {
30 26 RestrictedResource zRestrictedResource = getOptionalRestrictedResource();
31 - if ( zRestrictedResource == null )
32 - {
27 + if ( zRestrictedResource == null ) {
33 28 throw new SessionExpiredException( "No Current RestrictedResource" );
34 29 }
35 30 return zRestrictedResource;
36 31 }
37 32
38 - public RestrictedResource getOptionalRestrictedResource()
39 - {
33 + public RestrictedResource getOptionalRestrictedResource() {
40 34 Pair zPair = getPair();
41 - if ( zPair.getVO() == null )
42 - {
35 + if ( zPair.getVO() == null ) {
43 36 return null;
44 37 }
45 - if ( (zPair.getPO() == null) || !zPair.inSync() )
46 - {
38 + if ( (zPair.getPO() == null) || !zPair.inSync() ) {
47 39 zPair = refresh( zPair );
48 40 }
49 41 return zPair.getPO();
50 42 }
51 43
52 - public RestrictedResourceView getRestrictedResourceView()
53 - {
44 + public RestrictedResourceView getRestrictedResourceView() {
54 45 Pair zPair = getPair();
55 - if ( zPair.isStale() )
56 - {
46 + if ( zPair.isStale() ) {
57 47 zPair = refresh( zPair );
58 48 }
59 49 return zPair.getVO();
60 50 }
61 51
62 - public void logout()
63 - {
52 + public void logout() {
64 53 update( null, null );
65 54 }
66 55
67 - public RestrictedResourceView updateRestrictedResource( RestrictedResource pPO )
68 - {
56 + public RestrictedResourceView updateRestrictedResource( RestrictedResource pPO ) {
69 57 RestrictedResourceView zView = getDataProvider().createView( pPO, false );
70 58 update( zView, pPO );
71 59 return zView;
72 60 }
73 61
74 - private Pair refresh( Pair pPair )
75 - {
62 + private Pair refresh( Pair pPair ) {
76 63 RestrictedResourceViewPoServerVoDataProvider zDP = getDataProvider();
77 64 RestrictedResource zRestrictedResource = (RestrictedResource) zDP.getPO( pPair.getVO().getID() );
78 65 return update( zDP.createView( zRestrictedResource, false ), zRestrictedResource );
79 66 }
80 67
81 - private Pair update( RestrictedResourceView pView, RestrictedResource pPO )
82 - {
68 + private Pair update( RestrictedResourceView pView, RestrictedResource pPO ) {
83 69 Pair rv;
84 70 RestrictedResource zOld, zNew;
85 - synchronized ( this )
86 - {
71 + synchronized ( this ) {
87 72 rv = new Pair( mViewStale = false, pView, pPO );
88 73 ServerContext.get().getServerSession().setAttribute( RestrictedResourceView.class, pView );
89 74 zOld = mPO;
90 75 zNew = mPO = pPO;
91 76 }
92 - if ( !Objects.areNonArraysEqual( zOld, zNew ) )
93 - {
94 - if ( zOld != null )
95 - {
77 + if ( !Objects.areNonArraysEqual( zOld, zNew ) ) {
78 + if ( zOld != null ) {
96 79 mRegisteredWithCLM.removeListener( this );
97 80 mRegisteredWithCLM = null;
98 81 }
99 - if ( zNew != null )
100 - {
82 + if ( zNew != null ) {
101 83 (mRegisteredWithCLM = ChangeListenerManager.get()).addListener( this, RestrictedResource.class, zNew.getPersistentObjectUniqueKey() );
102 84 }
103 85 }
104 86 return rv;
105 87 }
106 88
107 - private synchronized Pair getPair()
108 - {
89 + private synchronized Pair getPair() {
109 90 RestrictedResourceView zRestrictedResourceView = ServerContext.get().getServerSession().getAttribute( RestrictedResourceView.class );
110 91 return new Pair( mViewStale, zRestrictedResourceView, mPO );
111 92 }
112 93
113 94 @Override
114 - public synchronized void serverStateChanged( ServerStateChangeSet pServerStateChangeSet )
115 - {
95 + public synchronized void serverStateChanged( ServerStateChangeSet pServerStateChangeSet ) {
116 96 mViewStale = true;
117 97 }
118 98
119 - private RestrictedResourceViewPoServerVoDataProvider getDataProvider()
120 - {
121 - return (RestrictedResourceViewPoServerVoDataProvider) ServerContext.getMasterServerStore().get( ServerVoDataProviderMap.class ).get( RestrictedResourceView.class );
99 + private RestrictedResourceViewPoServerVoDataProvider getDataProvider() {
100 + return (RestrictedResourceViewPoServerVoDataProvider) ServerContext.getMasterServerStore().get( ServerVoDataProviderMap.class )
101 + .get( RestrictedResourceView.class );
122 102 }
123 103
124 - private static class Pair
125 - {
104 + private static class Pair {
126 105 private boolean mStale;
127 106 private RestrictedResourceView mVO;
128 107 private RestrictedResource mPO;
129 108
130 - private Pair( boolean pStale, RestrictedResourceView pVO, RestrictedResource pPO )
131 - {
109 + private Pair( boolean pStale, RestrictedResourceView pVO, RestrictedResource pPO ) {
132 110 mStale = (pVO != null) && pStale;
133 111 mVO = pVO;
134 112 mPO = pPO;
135 113 }
136 114
137 - public boolean isStale()
138 - {
115 + public boolean isStale() {
139 116 return mStale;
140 117 }
141 118
142 - public RestrictedResourceView getVO()
143 - {
119 + public RestrictedResourceView getVO() {
144 120 return mVO;
145 121 }
146 122
147 - public RestrictedResource getPO()
148 - {
123 + public RestrictedResource getPO() {
149 124 return mPO;
150 125 }
151 126