Subversion Repository Public Repository

litesoft

Diff Revisions 949 vs 950 for /trunk/GWT_Sandbox/NAS-Video/src/org/litesoft/nasvideo/server/CurrentRestrictedResourceAccessor.java

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