Source Code Cross Referenced for MOTableRelation.java in  » Net » snmp4j » org » snmp4j » agent » mo » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Net » snmp4j » org.snmp4j.agent.mo 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*_############################################################################
002:          _## 
003:          _##  SNMP4J-Agent - MOTableRelation.java  
004:          _## 
005:          _##  Copyright (C) 2005-2007  Frank Fock (SNMP4J.org)
006:          _##  
007:          _##  Licensed under the Apache License, Version 2.0 (the "License");
008:          _##  you may not use this file except in compliance with the License.
009:          _##  You may obtain a copy of the License at
010:          _##  
011:          _##      http://www.apache.org/licenses/LICENSE-2.0
012:          _##  
013:          _##  Unless required by applicable law or agreed to in writing, software
014:          _##  distributed under the License is distributed on an "AS IS" BASIS,
015:          _##  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:          _##  See the License for the specific language governing permissions and
017:          _##  limitations under the License.
018:          _##  
019:          _##########################################################################*/
020:
021:        package org.snmp4j.agent.mo;
022:
023:        import org.snmp4j.smi.OID;
024:
025:        /**
026:         * The <code>MOTableRelation</code> class models table relations like sparse
027:         * table relationship and augmentation. This class implements the augmentation
028:         * relationship. In order to implement a sparse table relationship, sub-classing
029:         * <code>MOTableRelation</code> is needed and the methods
030:         * {@link #hasDependentRow} and {@link #getDependentIndexes} must be overwritten
031:         * then.
032:         *
033:         * @author Frank Fock
034:         * @version 1.0
035:         */
036:        public class MOTableRelation {
037:
038:            private MOTable baseTable;
039:            private MOTable dependentTable;
040:
041:            /**
042:             * Creates a table relation from a base table and the dependent table.
043:             * To actually set up the relationship between those tables
044:             * {@link #createRelationShip()} needs to be called.
045:             *
046:             * @param baseTable
047:             *    the base table.
048:             * @param dependentTable
049:             *    the dependent (augmenting) table.
050:             */
051:            public MOTableRelation(MOTable baseTable, MOTable dependentTable) {
052:                this .baseTable = baseTable;
053:                this .dependentTable = dependentTable;
054:            }
055:
056:            /**
057:             * Actually sets up the relationship between base and dependent table by
058:             * adding this instance as row listener to the base table.
059:             */
060:            public void createRelationShip() {
061:                this .baseTable
062:                        .addMOTableRowListener(createRelationShipListener());
063:            }
064:
065:            protected MOTableRowListener createRelationShipListener() {
066:                return new RelationShipListener();
067:            }
068:
069:            /**
070:             * Indicates whether the specified baseTableRow has any dependent rows.
071:             * By default this method returns <code>true</code> because the default
072:             * implementation represents an augmentation relationship.
073:             * Overwrite this method in a sub-class to implement a sparse table
074:             * relationship.
075:             * @param baseTableRow
076:             *    a row of the base table.
077:             * @return
078:             *    <code>true</code> if the row has dependent rows.
079:             */
080:            public boolean hasDependentRow(MOTableRow baseTableRow) {
081:                // by default this is an augmentation
082:                // overwrite in a subclass to implement sparse relationship
083:                return true;
084:            }
085:
086:            /**
087:             * Returns the dependent indexes for the specified base row. By default, this
088:             * method returns the base rows index in a one element array, because
089:             * the default implementation represents an augmentation relationship.
090:             * Overwrite this method in a sub-class to implement a sparse table
091:             * relationship.
092:             * @param baseRow
093:             *    a row of the base table.
094:             * @return
095:             *    an array of row index values of the dependent rows.
096:             */
097:            public OID[] getDependentIndexes(MOTableRow baseRow) {
098:                // by default this is an augmentation
099:                // overwrite in a subclass to implement sparse relationship
100:                return new OID[] { baseRow.getIndex() };
101:            }
102:
103:            /**
104:             * Adds all dependent rows for the specified base table row to the dependent
105:             * table. This method is automatically called if {@link #createRelationShip()}
106:             * has been called.
107:             *
108:             * @param baseTableRow
109:             *    a row of the base table.
110:             */
111:            protected void addDependentRows(MOTableRow baseTableRow) {
112:                OID[] indexes = getDependentIndexes(baseTableRow);
113:                for (int i = 0; i < indexes.length; i++) {
114:                    MOTableRow depRow = dependentTable.createRow(indexes[i],
115:                            dependentTable.getDefaultValues());
116:                    depRow.setBaseRow(baseTableRow);
117:                    dependentTable.addRow(depRow);
118:                }
119:            }
120:
121:            /**
122:             * Removes all dependent rows for the specified base table row
123:             * from the dependent table. This method is automatically called if
124:             * {@link #createRelationShip()} has been called.
125:             *
126:             * @param baseTableRow
127:             *    a row of the base table.
128:             * @return
129:             *    an array of the removed rows.
130:             */
131:            protected MOTableRow[] removeDependentRows(MOTableRow baseTableRow) {
132:                OID[] indexes = getDependentIndexes(baseTableRow);
133:                MOTableRow[] removedRows = new MOTableRow[indexes.length];
134:                for (int i = 0; i < indexes.length; i++) {
135:                    removedRows[i] = dependentTable.removeRow(indexes[i]);
136:                }
137:                return removedRows;
138:            }
139:
140:            protected class RelationShipListener implements  MOTableRowListener {
141:
142:                public void rowChanged(MOTableRowEvent event) {
143:                    switch (event.getType()) {
144:                    case MOTableRowEvent.ADD: {
145:                        if (hasDependentRow(event.getRow())) {
146:                            addDependentRows(event.getRow());
147:                        }
148:                        break;
149:                    }
150:                    case MOTableRowEvent.DELETE: {
151:                        removeDependentRows(event.getRow());
152:                    }
153:                    }
154:                }
155:
156:            }
157:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.