001: //** Copyright Statement ***************************************************
002: //The Salmon Open Framework for Internet Applications (SOFIA)
003: // Copyright (C) 1999 - 2002, Salmon LLC
004: //
005: // This program is free software; you can redistribute it and/or
006: // modify it under the terms of the GNU General Public License version 2
007: // as published by the Free Software Foundation;
008: //
009: // This program is distributed in the hope that it will be useful,
010: // but WITHOUT ANY WARRANTY; without even the implied warranty of
011: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: // GNU General Public License for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // along with this program; if not, write to the Free Software
016: // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: //
018: // For more information please visit http://www.salmonllc.com
019: //** End Copyright Statement ***************************************************
020: package com.salmonllc.properties;
021:
022: import com.salmonllc.util.MessageLog;
023: import com.salmonllc.util.Util;
024:
025: /////////////////////////
026: //$Archive: /SOFIA/SourceCode/com/salmonllc/properties/PropsDescriptor.java $
027: //$Author: Matt $
028: //$Revision: 14 $
029: //$Modtime: 5/19/04 4:07p $
030: /////////////////////////
031: import java.util.*;
032:
033: class PropsDescriptor {
034: private Properties _props;
035: private String _name;
036: private Vector _subProps;
037: private long _lastMod;
038:
039: PropsDescriptor(Properties p, String name, long lastMod) {
040: _name = name;
041: _props = p;
042: _lastMod = lastMod;
043:
044: if (!Util.isFilled(name)) {
045: MessageLog.writeErrorMessage(" PropsDescriptor Constuctor",
046: new Exception("name not filled"), this );
047: }
048: }
049:
050: void setLastMod(long lastMod) {
051: _lastMod = lastMod;
052: }
053:
054: long getLastMod() {
055: return _lastMod;
056: }
057:
058: String getName() {
059: return _name;
060: }
061:
062: void setProperties(Properties p) {
063: _props = p;
064: }
065:
066: Properties getProperties() {
067: return _props;
068: }
069:
070: void setSubProperty(PropsDescriptor p) {
071: if (_subProps == null) {
072: _subProps = new Vector();
073: }
074:
075: /*
076: * srufle : May 17, 2004 7 : 13 : 40 PM
077: * Added a check for PropsDescriptor._name
078: * - name field must have a value otherwise PropsDescriptor getSubProperty(String name) will throw a NullPointer exception
079: *
080: */
081: if (Util.isFilled(p.getName())) {
082: for (int i = 0; i < _subProps.size(); i++) {
083: PropsDescriptor p1 = (PropsDescriptor) _subProps
084: .elementAt(i);
085:
086: if (p1.getName().equals(p.getName())) {
087: _subProps.setElementAt(p, i);
088:
089: return;
090: }
091: }
092:
093: _subProps.addElement(p);
094: } else {
095: String msg = "p.getName()='" + p.getName() + "'";
096:
097: MessageLog.writeErrorMessage(msg, new Exception(msg), this );
098: }
099: }
100:
101: PropsDescriptor getSubProperty(String name) {
102: if (_subProps == null) {
103: return null;
104: }
105:
106: if (name == null) {
107: return null;
108: }
109:
110: for (int i = 0; i < _subProps.size(); i++) {
111: PropsDescriptor propDescTest = (PropsDescriptor) _subProps
112: .elementAt(i);
113: String propDescTestName = propDescTest.getName();
114:
115: if (Util.isNull(propDescTestName)) {
116: MessageLog.writeErrorMessage(
117: " propDescTestName=null passed name=" + name,
118: null, this );
119:
120: for (int errI = 0; errI < _subProps.size(); errI++) {
121: PropsDescriptor propDescTestErr = (PropsDescriptor) _subProps
122: .elementAt(errI);
123: String propDescTestNameErr = propDescTestErr
124: .getName();
125: MessageLog.writeErrorMessage(" errI=" + errI, null,
126: this );
127: MessageLog.writeErrorMessage(
128: " propDescTestNameErr="
129: + propDescTestNameErr, null, this );
130: }
131: }
132:
133: if ((propDescTest != null) && propDescTestName != null
134: && propDescTestName.equals(name)) {
135: return (PropsDescriptor) _subProps.elementAt(i);
136: }
137: }
138:
139: return null;
140: }
141: }
|